Home | History | Annotate | Line # | Download | only in i386
      1 /* Subroutines used for code generation on IA-32.
      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
      7 it under the terms of the GNU General Public License as published by
      8 the Free Software Foundation; either version 3, or (at your option)
      9 any later version.
     10 
     11 GCC is distributed in the hope that it will be useful,
     12 but WITHOUT ANY WARRANTY; without even the implied warranty of
     13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     14 GNU General Public License 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 #define IN_TARGET_CODE 1
     21 
     22 #include "config.h"
     23 #include "system.h"
     24 #include "coretypes.h"
     25 #include "backend.h"
     26 #include "rtl.h"
     27 #include "tree.h"
     28 #include "memmodel.h"
     29 #include "gimple.h"
     30 #include "cfghooks.h"
     31 #include "cfgloop.h"
     32 #include "df.h"
     33 #include "tm_p.h"
     34 #include "stringpool.h"
     35 #include "expmed.h"
     36 #include "optabs.h"
     37 #include "regs.h"
     38 #include "emit-rtl.h"
     39 #include "recog.h"
     40 #include "cgraph.h"
     41 #include "diagnostic.h"
     42 #include "cfgbuild.h"
     43 #include "alias.h"
     44 #include "fold-const.h"
     45 #include "attribs.h"
     46 #include "calls.h"
     47 #include "stor-layout.h"
     48 #include "varasm.h"
     49 #include "output.h"
     50 #include "insn-attr.h"
     51 #include "flags.h"
     52 #include "except.h"
     53 #include "explow.h"
     54 #include "expr.h"
     55 #include "cfgrtl.h"
     56 #include "common/common-target.h"
     57 #include "langhooks.h"
     58 #include "reload.h"
     59 #include "gimplify.h"
     60 #include "dwarf2.h"
     61 #include "tm-constrs.h"
     62 #include "cselib.h"
     63 #include "sched-int.h"
     64 #include "opts.h"
     65 #include "tree-pass.h"
     66 #include "context.h"
     67 #include "pass_manager.h"
     68 #include "target-globals.h"
     69 #include "gimple-iterator.h"
     70 #include "gimple-fold.h"
     71 #include "tree-vectorizer.h"
     72 #include "shrink-wrap.h"
     73 #include "builtins.h"
     74 #include "rtl-iter.h"
     75 #include "tree-iterator.h"
     76 #include "dbgcnt.h"
     77 #include "case-cfn-macros.h"
     78 #include "dojump.h"
     79 #include "fold-const-call.h"
     80 #include "tree-vrp.h"
     81 #include "tree-ssanames.h"
     82 #include "selftest.h"
     83 #include "selftest-rtl.h"
     84 #include "print-rtl.h"
     85 #include "intl.h"
     86 #include "ifcvt.h"
     87 #include "symbol-summary.h"
     88 #include "ipa-prop.h"
     89 #include "ipa-fnsummary.h"
     90 #include "wide-int-bitmask.h"
     91 #include "tree-vector-builder.h"
     92 #include "debug.h"
     93 #include "dwarf2out.h"
     94 #include "i386-options.h"
     95 #include "i386-builtins.h"
     96 #include "i386-expand.h"
     97 #include "i386-features.h"
     98 #include "function-abi.h"
     99 
    100 /* This file should be included last.  */
    101 #include "target-def.h"
    102 
    103 static rtx legitimize_dllimport_symbol (rtx, bool);
    104 static rtx legitimize_pe_coff_extern_decl (rtx, bool);
    105 static void ix86_print_operand_address_as (FILE *, rtx, addr_space_t, bool);
    106 static void ix86_emit_restore_reg_using_pop (rtx);
    107 
    108 
    109 #ifndef CHECK_STACK_LIMIT
    110 #define CHECK_STACK_LIMIT (-1)
    111 #endif
    112 
    113 /* Return index of given mode in mult and division cost tables.  */
    114 #define MODE_INDEX(mode)					\
    115   ((mode) == QImode ? 0						\
    116    : (mode) == HImode ? 1					\
    117    : (mode) == SImode ? 2					\
    118    : (mode) == DImode ? 3					\
    119    : 4)
    120 
    121 
    122 /* Set by -mtune.  */
    123 const struct processor_costs *ix86_tune_cost = NULL;
    124 
    125 /* Set by -mtune or -Os.  */
    126 const struct processor_costs *ix86_cost = NULL;
    127 
    128 /* In case the average insn count for single function invocation is
    129    lower than this constant, emit fast (but longer) prologue and
    130    epilogue code.  */
    131 #define FAST_PROLOGUE_INSN_COUNT 20
    132 
    133 /* Names for 8 (low), 8 (high), and 16-bit registers, respectively.  */
    134 static const char *const qi_reg_name[] = QI_REGISTER_NAMES;
    135 static const char *const qi_high_reg_name[] = QI_HIGH_REGISTER_NAMES;
    136 static const char *const hi_reg_name[] = HI_REGISTER_NAMES;
    137 
    138 /* Array of the smallest class containing reg number REGNO, indexed by
    139    REGNO.  Used by REGNO_REG_CLASS in i386.h.  */
    140 
    141 enum reg_class const regclass_map[FIRST_PSEUDO_REGISTER] =
    142 {
    143   /* ax, dx, cx, bx */
    144   AREG, DREG, CREG, BREG,
    145   /* si, di, bp, sp */
    146   SIREG, DIREG, NON_Q_REGS, NON_Q_REGS,
    147   /* FP registers */
    148   FP_TOP_REG, FP_SECOND_REG, FLOAT_REGS, FLOAT_REGS,
    149   FLOAT_REGS, FLOAT_REGS, FLOAT_REGS, FLOAT_REGS,
    150   /* arg pointer, flags, fpsr, frame */
    151   NON_Q_REGS, NO_REGS, NO_REGS, NON_Q_REGS,
    152   /* SSE registers */
    153   SSE_FIRST_REG, SSE_REGS, SSE_REGS, SSE_REGS,
    154   SSE_REGS, SSE_REGS, SSE_REGS, SSE_REGS,
    155   /* MMX registers */
    156   MMX_REGS, MMX_REGS, MMX_REGS, MMX_REGS,
    157   MMX_REGS, MMX_REGS, MMX_REGS, MMX_REGS,
    158   /* REX registers */
    159   GENERAL_REGS, GENERAL_REGS, GENERAL_REGS, GENERAL_REGS,
    160   GENERAL_REGS, GENERAL_REGS, GENERAL_REGS, GENERAL_REGS,
    161   /* SSE REX registers */
    162   SSE_REGS, SSE_REGS, SSE_REGS, SSE_REGS,
    163   SSE_REGS, SSE_REGS, SSE_REGS, SSE_REGS,
    164   /* AVX-512 SSE registers */
    165   ALL_SSE_REGS, ALL_SSE_REGS, ALL_SSE_REGS, ALL_SSE_REGS,
    166   ALL_SSE_REGS, ALL_SSE_REGS, ALL_SSE_REGS, ALL_SSE_REGS,
    167   ALL_SSE_REGS, ALL_SSE_REGS, ALL_SSE_REGS, ALL_SSE_REGS,
    168   ALL_SSE_REGS, ALL_SSE_REGS, ALL_SSE_REGS, ALL_SSE_REGS,
    169   /* Mask registers.  */
    170   ALL_MASK_REGS, MASK_REGS, MASK_REGS, MASK_REGS,
    171   MASK_REGS, MASK_REGS, MASK_REGS, MASK_REGS
    172 };
    173 
    174 /* The "default" register map used in 32bit mode.  */
    175 
    176 int const dbx_register_map[FIRST_PSEUDO_REGISTER] =
    177 {
    178   /* general regs */
    179   0, 2, 1, 3, 6, 7, 4, 5,
    180   /* fp regs */
    181   12, 13, 14, 15, 16, 17, 18, 19,
    182   /* arg, flags, fpsr, frame */
    183   IGNORED_DWARF_REGNUM, IGNORED_DWARF_REGNUM,
    184   IGNORED_DWARF_REGNUM, IGNORED_DWARF_REGNUM,
    185   /* SSE */
    186   21, 22, 23, 24, 25, 26, 27, 28,
    187   /* MMX */
    188   29, 30, 31, 32, 33, 34, 35, 36,
    189   /* extended integer registers */
    190   INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM,
    191   INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM,
    192   /* extended sse registers */
    193   INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM,
    194   INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM,
    195   /* AVX-512 registers 16-23 */
    196   INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM,
    197   INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM,
    198   /* AVX-512 registers 24-31 */
    199   INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM,
    200   INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM,
    201   /* Mask registers */
    202   93, 94, 95, 96, 97, 98, 99, 100
    203 };
    204 
    205 /* The "default" register map used in 64bit mode.  */
    206 
    207 int const dbx64_register_map[FIRST_PSEUDO_REGISTER] =
    208 {
    209   /* general regs */
    210   0, 1, 2, 3, 4, 5, 6, 7,
    211   /* fp regs */
    212   33, 34, 35, 36, 37, 38, 39, 40,
    213   /* arg, flags, fpsr, frame */
    214   IGNORED_DWARF_REGNUM, IGNORED_DWARF_REGNUM,
    215   IGNORED_DWARF_REGNUM, IGNORED_DWARF_REGNUM,
    216   /* SSE */
    217   17, 18, 19, 20, 21, 22, 23, 24,
    218   /* MMX */
    219   41, 42, 43, 44, 45, 46, 47, 48,
    220   /* extended integer registers */
    221   8, 9, 10, 11, 12, 13, 14, 15,
    222   /* extended SSE registers */
    223   25, 26, 27, 28, 29, 30, 31, 32,
    224   /* AVX-512 registers 16-23 */
    225   67, 68, 69, 70, 71, 72, 73, 74,
    226   /* AVX-512 registers 24-31 */
    227   75, 76, 77, 78, 79, 80, 81, 82,
    228   /* Mask registers */
    229   118, 119, 120, 121, 122, 123, 124, 125
    230 };
    231 
    232 /* Define the register numbers to be used in Dwarf debugging information.
    233    The SVR4 reference port C compiler uses the following register numbers
    234    in its Dwarf output code:
    235 	0 for %eax (gcc regno = 0)
    236 	1 for %ecx (gcc regno = 2)
    237 	2 for %edx (gcc regno = 1)
    238 	3 for %ebx (gcc regno = 3)
    239 	4 for %esp (gcc regno = 7)
    240 	5 for %ebp (gcc regno = 6)
    241 	6 for %esi (gcc regno = 4)
    242 	7 for %edi (gcc regno = 5)
    243    The following three DWARF register numbers are never generated by
    244    the SVR4 C compiler or by the GNU compilers, but SDB on x86/svr4
    245    believed these numbers have these meanings.
    246 	8  for %eip    (no gcc equivalent)
    247 	9  for %eflags (gcc regno = 17)
    248 	10 for %trapno (no gcc equivalent)
    249    It is not at all clear how we should number the FP stack registers
    250    for the x86 architecture.  If the version of SDB on x86/svr4 were
    251    a bit less brain dead with respect to floating-point then we would
    252    have a precedent to follow with respect to DWARF register numbers
    253    for x86 FP registers, but the SDB on x86/svr4 was so completely
    254    broken with respect to FP registers that it is hardly worth thinking
    255    of it as something to strive for compatibility with.
    256    The version of x86/svr4 SDB I had does (partially)
    257    seem to believe that DWARF register number 11 is associated with
    258    the x86 register %st(0), but that's about all.  Higher DWARF
    259    register numbers don't seem to be associated with anything in
    260    particular, and even for DWARF regno 11, SDB only seemed to under-
    261    stand that it should say that a variable lives in %st(0) (when
    262    asked via an `=' command) if we said it was in DWARF regno 11,
    263    but SDB still printed garbage when asked for the value of the
    264    variable in question (via a `/' command).
    265    (Also note that the labels SDB printed for various FP stack regs
    266    when doing an `x' command were all wrong.)
    267    Note that these problems generally don't affect the native SVR4
    268    C compiler because it doesn't allow the use of -O with -g and
    269    because when it is *not* optimizing, it allocates a memory
    270    location for each floating-point variable, and the memory
    271    location is what gets described in the DWARF AT_location
    272    attribute for the variable in question.
    273    Regardless of the severe mental illness of the x86/svr4 SDB, we
    274    do something sensible here and we use the following DWARF
    275    register numbers.  Note that these are all stack-top-relative
    276    numbers.
    277 	11 for %st(0) (gcc regno = 8)
    278 	12 for %st(1) (gcc regno = 9)
    279 	13 for %st(2) (gcc regno = 10)
    280 	14 for %st(3) (gcc regno = 11)
    281 	15 for %st(4) (gcc regno = 12)
    282 	16 for %st(5) (gcc regno = 13)
    283 	17 for %st(6) (gcc regno = 14)
    284 	18 for %st(7) (gcc regno = 15)
    285 */
    286 int const svr4_dbx_register_map[FIRST_PSEUDO_REGISTER] =
    287 {
    288   /* general regs */
    289   0, 2, 1, 3, 6, 7, 5, 4,
    290   /* fp regs */
    291   11, 12, 13, 14, 15, 16, 17, 18,
    292   /* arg, flags, fpsr, frame */
    293   IGNORED_DWARF_REGNUM, 9,
    294   IGNORED_DWARF_REGNUM, IGNORED_DWARF_REGNUM,
    295   /* SSE registers */
    296   21, 22, 23, 24, 25, 26, 27, 28,
    297   /* MMX registers */
    298   29, 30, 31, 32, 33, 34, 35, 36,
    299   /* extended integer registers */
    300   INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM,
    301   INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM,
    302   /* extended sse registers */
    303   INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM,
    304   INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM,
    305   /* AVX-512 registers 16-23 */
    306   INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM,
    307   INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM,
    308   /* AVX-512 registers 24-31 */
    309   INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM,
    310   INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM, INVALID_REGNUM,
    311   /* Mask registers */
    312   93, 94, 95, 96, 97, 98, 99, 100
    313 };
    314 
    315 /* Define parameter passing and return registers.  */
    316 
    317 static int const x86_64_int_parameter_registers[6] =
    318 {
    319   DI_REG, SI_REG, DX_REG, CX_REG, R8_REG, R9_REG
    320 };
    321 
    322 static int const x86_64_ms_abi_int_parameter_registers[4] =
    323 {
    324   CX_REG, DX_REG, R8_REG, R9_REG
    325 };
    326 
    327 static int const x86_64_int_return_registers[4] =
    328 {
    329   AX_REG, DX_REG, DI_REG, SI_REG
    330 };
    331 
    332 /* Define the structure for the machine field in struct function.  */
    333 
    334 struct GTY(()) stack_local_entry {
    335   unsigned short mode;
    336   unsigned short n;
    337   rtx rtl;
    338   struct stack_local_entry *next;
    339 };
    340 
    341 /* Which cpu are we scheduling for.  */
    342 enum attr_cpu ix86_schedule;
    343 
    344 /* Which cpu are we optimizing for.  */
    345 enum processor_type ix86_tune;
    346 
    347 /* Which instruction set architecture to use.  */
    348 enum processor_type ix86_arch;
    349 
    350 /* True if processor has SSE prefetch instruction.  */
    351 unsigned char ix86_prefetch_sse;
    352 
    353 /* Preferred alignment for stack boundary in bits.  */
    354 unsigned int ix86_preferred_stack_boundary;
    355 
    356 /* Alignment for incoming stack boundary in bits specified at
    357    command line.  */
    358 unsigned int ix86_user_incoming_stack_boundary;
    359 
    360 /* Default alignment for incoming stack boundary in bits.  */
    361 unsigned int ix86_default_incoming_stack_boundary;
    362 
    363 /* Alignment for incoming stack boundary in bits.  */
    364 unsigned int ix86_incoming_stack_boundary;
    365 
    366 /* True if there is no direct access to extern symbols.  */
    367 bool ix86_has_no_direct_extern_access;
    368 
    369 /* Calling abi specific va_list type nodes.  */
    370 tree sysv_va_list_type_node;
    371 tree ms_va_list_type_node;
    372 
    373 /* Prefix built by ASM_GENERATE_INTERNAL_LABEL.  */
    374 char internal_label_prefix[16];
    375 int internal_label_prefix_len;
    376 
    377 /* Fence to use after loop using movnt.  */
    378 tree x86_mfence;
    379 
    380 /* Register class used for passing given 64bit part of the argument.
    381    These represent classes as documented by the PS ABI, with the exception
    382    of SSESF, SSEDF classes, that are basically SSE class, just gcc will
    383    use SF or DFmode move instead of DImode to avoid reformatting penalties.
    384 
    385    Similarly we play games with INTEGERSI_CLASS to use cheaper SImode moves
    386    whenever possible (upper half does contain padding).  */
    387 enum x86_64_reg_class
    388   {
    389     X86_64_NO_CLASS,
    390     X86_64_INTEGER_CLASS,
    391     X86_64_INTEGERSI_CLASS,
    392     X86_64_SSE_CLASS,
    393     X86_64_SSEHF_CLASS,
    394     X86_64_SSESF_CLASS,
    395     X86_64_SSEDF_CLASS,
    396     X86_64_SSEUP_CLASS,
    397     X86_64_X87_CLASS,
    398     X86_64_X87UP_CLASS,
    399     X86_64_COMPLEX_X87_CLASS,
    400     X86_64_MEMORY_CLASS
    401   };
    402 
    403 #define MAX_CLASSES 8
    404 
    405 /* Table of constants used by fldpi, fldln2, etc....  */
    406 static REAL_VALUE_TYPE ext_80387_constants_table [5];
    407 static bool ext_80387_constants_init;
    408 
    409 
    410 static rtx ix86_function_value (const_tree, const_tree, bool);
    412 static bool ix86_function_value_regno_p (const unsigned int);
    413 static unsigned int ix86_function_arg_boundary (machine_mode,
    414 						const_tree);
    415 static rtx ix86_static_chain (const_tree, bool);
    416 static int ix86_function_regparm (const_tree, const_tree);
    417 static void ix86_compute_frame_layout (void);
    418 static tree ix86_canonical_va_list_type (tree);
    419 static unsigned int split_stack_prologue_scratch_regno (void);
    420 static bool i386_asm_output_addr_const_extra (FILE *, rtx);
    421 
    422 static bool ix86_can_inline_p (tree, tree);
    423 static unsigned int ix86_minimum_incoming_stack_boundary (bool);
    424 
    425 
    426 /* Whether -mtune= or -march= were specified */
    428 int ix86_tune_defaulted;
    429 int ix86_arch_specified;
    430 
    431 /* Return true if a red-zone is in use.  We can't use red-zone when
    433    there are local indirect jumps, like "indirect_jump" or "tablejump",
    434    which jumps to another place in the function, since "call" in the
    435    indirect thunk pushes the return address onto stack, destroying
    436    red-zone.
    437 
    438    TODO: If we can reserve the first 2 WORDs, for PUSH and, another
    439    for CALL, in red-zone, we can allow local indirect jumps with
    440    indirect thunk.  */
    441 
    442 bool
    443 ix86_using_red_zone (void)
    444 {
    445   return (TARGET_RED_ZONE
    446 	  && !TARGET_64BIT_MS_ABI
    447 	  && (!cfun->machine->has_local_indirect_jump
    448 	      || cfun->machine->indirect_branch_type == indirect_branch_keep));
    449 }
    450 
    451 /* Return true, if profiling code should be emitted before
    453    prologue. Otherwise it returns false.
    454    Note: For x86 with "hotfix" it is sorried.  */
    455 static bool
    456 ix86_profile_before_prologue (void)
    457 {
    458   return flag_fentry != 0;
    459 }
    460 
    461 /* Update register usage after having seen the compiler flags.  */
    462 
    463 static void
    464 ix86_conditional_register_usage (void)
    465 {
    466   int i, c_mask;
    467 
    468   /* If there are no caller-saved registers, preserve all registers.
    469      except fixed_regs and registers used for function return value
    470      since aggregate_value_p checks call_used_regs[regno] on return
    471      value.  */
    472   if (cfun && cfun->machine->no_caller_saved_registers)
    473     for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
    474       if (!fixed_regs[i] && !ix86_function_value_regno_p (i))
    475 	call_used_regs[i] = 0;
    476 
    477   /* For 32-bit targets, disable the REX registers.  */
    478   if (! TARGET_64BIT)
    479     {
    480       for (i = FIRST_REX_INT_REG; i <= LAST_REX_INT_REG; i++)
    481 	CLEAR_HARD_REG_BIT (accessible_reg_set, i);
    482       for (i = FIRST_REX_SSE_REG; i <= LAST_REX_SSE_REG; i++)
    483 	CLEAR_HARD_REG_BIT (accessible_reg_set, i);
    484       for (i = FIRST_EXT_REX_SSE_REG; i <= LAST_EXT_REX_SSE_REG; i++)
    485 	CLEAR_HARD_REG_BIT (accessible_reg_set, i);
    486     }
    487 
    488   /*  See the definition of CALL_USED_REGISTERS in i386.h.  */
    489   c_mask = CALL_USED_REGISTERS_MASK (TARGET_64BIT_MS_ABI);
    490 
    491   CLEAR_HARD_REG_SET (reg_class_contents[(int)CLOBBERED_REGS]);
    492 
    493   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
    494     {
    495       /* Set/reset conditionally defined registers from
    496 	 CALL_USED_REGISTERS initializer.  */
    497       if (call_used_regs[i] > 1)
    498 	call_used_regs[i] = !!(call_used_regs[i] & c_mask);
    499 
    500       /* Calculate registers of CLOBBERED_REGS register set
    501 	 as call used registers from GENERAL_REGS register set.  */
    502       if (TEST_HARD_REG_BIT (reg_class_contents[(int)GENERAL_REGS], i)
    503 	  && call_used_regs[i])
    504 	SET_HARD_REG_BIT (reg_class_contents[(int)CLOBBERED_REGS], i);
    505     }
    506 
    507   /* If MMX is disabled, disable the registers.  */
    508   if (! TARGET_MMX)
    509     accessible_reg_set &= ~reg_class_contents[MMX_REGS];
    510 
    511   /* If SSE is disabled, disable the registers.  */
    512   if (! TARGET_SSE)
    513     accessible_reg_set &= ~reg_class_contents[ALL_SSE_REGS];
    514 
    515   /* If the FPU is disabled, disable the registers.  */
    516   if (! (TARGET_80387 || TARGET_FLOAT_RETURNS_IN_80387))
    517     accessible_reg_set &= ~reg_class_contents[FLOAT_REGS];
    518 
    519   /* If AVX512F is disabled, disable the registers.  */
    520   if (! TARGET_AVX512F)
    521     {
    522       for (i = FIRST_EXT_REX_SSE_REG; i <= LAST_EXT_REX_SSE_REG; i++)
    523 	CLEAR_HARD_REG_BIT (accessible_reg_set, i);
    524 
    525       accessible_reg_set &= ~reg_class_contents[ALL_MASK_REGS];
    526     }
    527 }
    528 
    529 /* Canonicalize a comparison from one we don't have to one we do have.  */
    530 
    531 static void
    532 ix86_canonicalize_comparison (int *code, rtx *op0, rtx *op1,
    533 			      bool op0_preserve_value)
    534 {
    535   /* The order of operands in x87 ficom compare is forced by combine in
    536      simplify_comparison () function. Float operator is treated as RTX_OBJ
    537      with a precedence over other operators and is always put in the first
    538      place. Swap condition and operands to match ficom instruction.  */
    539   if (!op0_preserve_value
    540       && GET_CODE (*op0) == FLOAT && MEM_P (XEXP (*op0, 0)) && REG_P (*op1))
    541     {
    542       enum rtx_code scode = swap_condition ((enum rtx_code) *code);
    543 
    544       /* We are called only for compares that are split to SAHF instruction.
    545 	 Ensure that we have setcc/jcc insn for the swapped condition.  */
    546       if (ix86_fp_compare_code_to_integer (scode) != UNKNOWN)
    547 	{
    548 	  std::swap (*op0, *op1);
    549 	  *code = (int) scode;
    550 	}
    551     }
    552 }
    553 
    554 
    556 /* Hook to determine if one function can safely inline another.  */
    558 
    559 static bool
    560 ix86_can_inline_p (tree caller, tree callee)
    561 {
    562   tree caller_tree = DECL_FUNCTION_SPECIFIC_TARGET (caller);
    563   tree callee_tree = DECL_FUNCTION_SPECIFIC_TARGET (callee);
    564 
    565   /* Changes of those flags can be tolerated for always inlines. Lets hope
    566      user knows what he is doing.  */
    567   unsigned HOST_WIDE_INT always_inline_safe_mask
    568 	 = (MASK_USE_8BIT_IDIV | MASK_ACCUMULATE_OUTGOING_ARGS
    569 	    | MASK_NO_ALIGN_STRINGOPS | MASK_AVX256_SPLIT_UNALIGNED_LOAD
    570 	    | MASK_AVX256_SPLIT_UNALIGNED_STORE | MASK_CLD
    571 	    | MASK_NO_FANCY_MATH_387 | MASK_IEEE_FP | MASK_INLINE_ALL_STRINGOPS
    572 	    | MASK_INLINE_STRINGOPS_DYNAMICALLY | MASK_RECIP | MASK_STACK_PROBE
    573 	    | MASK_STV | MASK_TLS_DIRECT_SEG_REFS | MASK_VZEROUPPER
    574 	    | MASK_NO_PUSH_ARGS | MASK_OMIT_LEAF_FRAME_POINTER);
    575 
    576 
    577   if (!callee_tree)
    578     callee_tree = target_option_default_node;
    579   if (!caller_tree)
    580     caller_tree = target_option_default_node;
    581   if (callee_tree == caller_tree)
    582     return true;
    583 
    584   struct cl_target_option *caller_opts = TREE_TARGET_OPTION (caller_tree);
    585   struct cl_target_option *callee_opts = TREE_TARGET_OPTION (callee_tree);
    586   bool ret = false;
    587   bool always_inline
    588     = (DECL_DISREGARD_INLINE_LIMITS (callee)
    589        && lookup_attribute ("always_inline",
    590 			    DECL_ATTRIBUTES (callee)));
    591 
    592   /* If callee only uses GPRs, ignore MASK_80387.  */
    593   if (TARGET_GENERAL_REGS_ONLY_P (callee_opts->x_ix86_target_flags))
    594     always_inline_safe_mask |= MASK_80387;
    595 
    596   cgraph_node *callee_node = cgraph_node::get (callee);
    597   /* Callee's isa options should be a subset of the caller's, i.e. a SSE4
    598      function can inline a SSE2 function but a SSE2 function can't inline
    599      a SSE4 function.  */
    600   if (((caller_opts->x_ix86_isa_flags & callee_opts->x_ix86_isa_flags)
    601        != callee_opts->x_ix86_isa_flags)
    602       || ((caller_opts->x_ix86_isa_flags2 & callee_opts->x_ix86_isa_flags2)
    603 	  != callee_opts->x_ix86_isa_flags2))
    604     ret = false;
    605 
    606   /* See if we have the same non-isa options.  */
    607   else if ((!always_inline
    608 	    && caller_opts->x_target_flags != callee_opts->x_target_flags)
    609 	   || (caller_opts->x_target_flags & ~always_inline_safe_mask)
    610 	       != (callee_opts->x_target_flags & ~always_inline_safe_mask))
    611     ret = false;
    612 
    613   /* See if arch, tune, etc. are the same.  */
    614   else if (caller_opts->arch != callee_opts->arch)
    615     ret = false;
    616 
    617   else if (!always_inline && caller_opts->tune != callee_opts->tune)
    618     ret = false;
    619 
    620   else if (caller_opts->x_ix86_fpmath != callee_opts->x_ix86_fpmath
    621 	   /* If the calle doesn't use FP expressions differences in
    622 	      ix86_fpmath can be ignored.  We are called from FEs
    623 	      for multi-versioning call optimization, so beware of
    624 	      ipa_fn_summaries not available.  */
    625 	   && (! ipa_fn_summaries
    626 	       || ipa_fn_summaries->get (callee_node) == NULL
    627 	       || ipa_fn_summaries->get (callee_node)->fp_expressions))
    628     ret = false;
    629 
    630   else if (!always_inline
    631 	   && caller_opts->branch_cost != callee_opts->branch_cost)
    632     ret = false;
    633 
    634   else
    635     ret = true;
    636 
    637   return ret;
    638 }
    639 
    640 /* Return true if this goes in large data/bss.  */
    642 
    643 static bool
    644 ix86_in_large_data_p (tree exp)
    645 {
    646   if (ix86_cmodel != CM_MEDIUM && ix86_cmodel != CM_MEDIUM_PIC)
    647     return false;
    648 
    649   if (exp == NULL_TREE)
    650     return false;
    651 
    652   /* Functions are never large data.  */
    653   if (TREE_CODE (exp) == FUNCTION_DECL)
    654     return false;
    655 
    656   /* Automatic variables are never large data.  */
    657   if (VAR_P (exp) && !is_global_var (exp))
    658     return false;
    659 
    660   if (VAR_P (exp) && DECL_SECTION_NAME (exp))
    661     {
    662       const char *section = DECL_SECTION_NAME (exp);
    663       if (strcmp (section, ".ldata") == 0
    664 	  || strcmp (section, ".lbss") == 0)
    665 	return true;
    666       return false;
    667     }
    668   else
    669     {
    670       HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
    671 
    672       /* If this is an incomplete type with size 0, then we can't put it
    673 	 in data because it might be too big when completed.  Also,
    674 	 int_size_in_bytes returns -1 if size can vary or is larger than
    675 	 an integer in which case also it is safer to assume that it goes in
    676 	 large data.  */
    677       if (size <= 0 || size > ix86_section_threshold)
    678 	return true;
    679     }
    680 
    681   return false;
    682 }
    683 
    684 /* i386-specific section flag to mark large sections.  */
    685 #define SECTION_LARGE SECTION_MACH_DEP
    686 
    687 /* Switch to the appropriate section for output of DECL.
    688    DECL is either a `VAR_DECL' node or a constant of some sort.
    689    RELOC indicates whether forming the initial value of DECL requires
    690    link-time relocations.  */
    691 
    692 ATTRIBUTE_UNUSED static section *
    693 x86_64_elf_select_section (tree decl, int reloc,
    694 			   unsigned HOST_WIDE_INT align)
    695 {
    696   if (ix86_in_large_data_p (decl))
    697     {
    698       const char *sname = NULL;
    699       unsigned int flags = SECTION_WRITE | SECTION_LARGE;
    700       switch (categorize_decl_for_section (decl, reloc))
    701 	{
    702 	case SECCAT_DATA:
    703 	  sname = ".ldata";
    704 	  break;
    705 	case SECCAT_DATA_REL:
    706 	  sname = ".ldata.rel";
    707 	  break;
    708 	case SECCAT_DATA_REL_LOCAL:
    709 	  sname = ".ldata.rel.local";
    710 	  break;
    711 	case SECCAT_DATA_REL_RO:
    712 	  sname = ".ldata.rel.ro";
    713 	  break;
    714 	case SECCAT_DATA_REL_RO_LOCAL:
    715 	  sname = ".ldata.rel.ro.local";
    716 	  break;
    717 	case SECCAT_BSS:
    718 	  sname = ".lbss";
    719 	  flags |= SECTION_BSS;
    720 	  break;
    721 	case SECCAT_RODATA:
    722 	case SECCAT_RODATA_MERGE_STR:
    723 	case SECCAT_RODATA_MERGE_STR_INIT:
    724 	case SECCAT_RODATA_MERGE_CONST:
    725 	  sname = ".lrodata";
    726 	  flags &= ~SECTION_WRITE;
    727 	  break;
    728 	case SECCAT_SRODATA:
    729 	case SECCAT_SDATA:
    730 	case SECCAT_SBSS:
    731 	  gcc_unreachable ();
    732 	case SECCAT_TEXT:
    733 	case SECCAT_TDATA:
    734 	case SECCAT_TBSS:
    735 	  /* We don't split these for medium model.  Place them into
    736 	     default sections and hope for best.  */
    737 	  break;
    738 	}
    739       if (sname)
    740 	{
    741 	  /* We might get called with string constants, but get_named_section
    742 	     doesn't like them as they are not DECLs.  Also, we need to set
    743 	     flags in that case.  */
    744 	  if (!DECL_P (decl))
    745 	    return get_section (sname, flags, NULL);
    746 	  return get_named_section (decl, sname, reloc);
    747 	}
    748     }
    749   return default_elf_select_section (decl, reloc, align);
    750 }
    751 
    752 /* Select a set of attributes for section NAME based on the properties
    753    of DECL and whether or not RELOC indicates that DECL's initializer
    754    might contain runtime relocations.  */
    755 
    756 static unsigned int ATTRIBUTE_UNUSED
    757 x86_64_elf_section_type_flags (tree decl, const char *name, int reloc)
    758 {
    759   unsigned int flags = default_section_type_flags (decl, name, reloc);
    760 
    761   if (ix86_in_large_data_p (decl))
    762     flags |= SECTION_LARGE;
    763 
    764   if (decl == NULL_TREE
    765       && (strcmp (name, ".ldata.rel.ro") == 0
    766 	  || strcmp (name, ".ldata.rel.ro.local") == 0))
    767     flags |= SECTION_RELRO;
    768 
    769   if (strcmp (name, ".lbss") == 0
    770       || startswith (name, ".lbss.")
    771       || startswith (name, ".gnu.linkonce.lb."))
    772     flags |= SECTION_BSS;
    773 
    774   return flags;
    775 }
    776 
    777 /* Build up a unique section name, expressed as a
    778    STRING_CST node, and assign it to DECL_SECTION_NAME (decl).
    779    RELOC indicates whether the initial value of EXP requires
    780    link-time relocations.  */
    781 
    782 static void ATTRIBUTE_UNUSED
    783 x86_64_elf_unique_section (tree decl, int reloc)
    784 {
    785   if (ix86_in_large_data_p (decl))
    786     {
    787       const char *prefix = NULL;
    788       /* We only need to use .gnu.linkonce if we don't have COMDAT groups.  */
    789       bool one_only = DECL_COMDAT_GROUP (decl) && !HAVE_COMDAT_GROUP;
    790 
    791       switch (categorize_decl_for_section (decl, reloc))
    792 	{
    793 	case SECCAT_DATA:
    794 	case SECCAT_DATA_REL:
    795 	case SECCAT_DATA_REL_LOCAL:
    796 	case SECCAT_DATA_REL_RO:
    797 	case SECCAT_DATA_REL_RO_LOCAL:
    798           prefix = one_only ? ".ld" : ".ldata";
    799 	  break;
    800 	case SECCAT_BSS:
    801           prefix = one_only ? ".lb" : ".lbss";
    802 	  break;
    803 	case SECCAT_RODATA:
    804 	case SECCAT_RODATA_MERGE_STR:
    805 	case SECCAT_RODATA_MERGE_STR_INIT:
    806 	case SECCAT_RODATA_MERGE_CONST:
    807           prefix = one_only ? ".lr" : ".lrodata";
    808 	  break;
    809 	case SECCAT_SRODATA:
    810 	case SECCAT_SDATA:
    811 	case SECCAT_SBSS:
    812 	  gcc_unreachable ();
    813 	case SECCAT_TEXT:
    814 	case SECCAT_TDATA:
    815 	case SECCAT_TBSS:
    816 	  /* We don't split these for medium model.  Place them into
    817 	     default sections and hope for best.  */
    818 	  break;
    819 	}
    820       if (prefix)
    821 	{
    822 	  const char *name, *linkonce;
    823 	  char *string;
    824 
    825 	  name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
    826 	  name = targetm.strip_name_encoding (name);
    827 
    828 	  /* If we're using one_only, then there needs to be a .gnu.linkonce
    829      	     prefix to the section name.  */
    830 	  linkonce = one_only ? ".gnu.linkonce" : "";
    831 
    832 	  string = ACONCAT ((linkonce, prefix, ".", name, NULL));
    833 
    834 	  set_decl_section_name (decl, string);
    835 	  return;
    836 	}
    837     }
    838   default_unique_section (decl, reloc);
    839 }
    840 
    841 #ifdef COMMON_ASM_OP
    842 
    843 #ifndef LARGECOMM_SECTION_ASM_OP
    844 #define LARGECOMM_SECTION_ASM_OP "\t.largecomm\t"
    845 #endif
    846 
    847 /* This says how to output assembler code to declare an
    848    uninitialized external linkage data object.
    849 
    850    For medium model x86-64 we need to use LARGECOMM_SECTION_ASM_OP opcode for
    851    large objects.  */
    852 void
    853 x86_elf_aligned_decl_common (FILE *file, tree decl,
    854 			const char *name, unsigned HOST_WIDE_INT size,
    855 			unsigned align)
    856 {
    857   if ((ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_MEDIUM_PIC)
    858       && size > (unsigned int)ix86_section_threshold)
    859     {
    860       switch_to_section (get_named_section (decl, ".lbss", 0));
    861       fputs (LARGECOMM_SECTION_ASM_OP, file);
    862     }
    863   else
    864     fputs (COMMON_ASM_OP, file);
    865   assemble_name (file, name);
    866   fprintf (file, "," HOST_WIDE_INT_PRINT_UNSIGNED ",%u\n",
    867 	   size, align / BITS_PER_UNIT);
    868 }
    869 #endif
    870 
    871 /* Utility function for targets to use in implementing
    872    ASM_OUTPUT_ALIGNED_BSS.  */
    873 
    874 void
    875 x86_output_aligned_bss (FILE *file, tree decl, const char *name,
    876 		       	unsigned HOST_WIDE_INT size, unsigned align)
    877 {
    878   if ((ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_MEDIUM_PIC)
    879       && size > (unsigned int)ix86_section_threshold)
    880     switch_to_section (get_named_section (decl, ".lbss", 0));
    881   else
    882     switch_to_section (bss_section);
    883   ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
    884 #ifdef ASM_DECLARE_OBJECT_NAME
    885   last_assemble_variable_decl = decl;
    886   ASM_DECLARE_OBJECT_NAME (file, name, decl);
    887 #else
    888   /* Standard thing is just output label for the object.  */
    889   ASM_OUTPUT_LABEL (file, name);
    890 #endif /* ASM_DECLARE_OBJECT_NAME */
    891   ASM_OUTPUT_SKIP (file, size ? size : 1);
    892 }
    893 
    894 /* Decide whether we must probe the stack before any space allocation
    896    on this target.  It's essentially TARGET_STACK_PROBE except when
    897    -fstack-check causes the stack to be already probed differently.  */
    898 
    899 bool
    900 ix86_target_stack_probe (void)
    901 {
    902   /* Do not probe the stack twice if static stack checking is enabled.  */
    903   if (flag_stack_check == STATIC_BUILTIN_STACK_CHECK)
    904     return false;
    905 
    906   return TARGET_STACK_PROBE;
    907 }
    908 
    909 /* Decide whether we can make a sibling call to a function.  DECL is the
    911    declaration of the function being targeted by the call and EXP is the
    912    CALL_EXPR representing the call.  */
    913 
    914 static bool
    915 ix86_function_ok_for_sibcall (tree decl, tree exp)
    916 {
    917   tree type, decl_or_type;
    918   rtx a, b;
    919   bool bind_global = decl && !targetm.binds_local_p (decl);
    920 
    921   if (ix86_function_naked (current_function_decl))
    922     return false;
    923 
    924   /* Sibling call isn't OK if there are no caller-saved registers
    925      since all registers must be preserved before return.  */
    926   if (cfun->machine->no_caller_saved_registers)
    927     return false;
    928 
    929   /* If we are generating position-independent code, we cannot sibcall
    930      optimize direct calls to global functions, as the PLT requires
    931      %ebx be live. (Darwin does not have a PLT.)  */
    932   if (!TARGET_MACHO
    933       && !TARGET_64BIT
    934       && flag_pic
    935       && flag_plt
    936       && bind_global)
    937     return false;
    938 
    939   /* If we need to align the outgoing stack, then sibcalling would
    940      unalign the stack, which may break the called function.  */
    941   if (ix86_minimum_incoming_stack_boundary (true)
    942       < PREFERRED_STACK_BOUNDARY)
    943     return false;
    944 
    945   if (decl)
    946     {
    947       decl_or_type = decl;
    948       type = TREE_TYPE (decl);
    949     }
    950   else
    951     {
    952       /* We're looking at the CALL_EXPR, we need the type of the function.  */
    953       type = CALL_EXPR_FN (exp);		/* pointer expression */
    954       type = TREE_TYPE (type);			/* pointer type */
    955       type = TREE_TYPE (type);			/* function type */
    956       decl_or_type = type;
    957     }
    958 
    959   /* If outgoing reg parm stack space changes, we cannot do sibcall.  */
    960   if ((OUTGOING_REG_PARM_STACK_SPACE (type)
    961        != OUTGOING_REG_PARM_STACK_SPACE (TREE_TYPE (current_function_decl)))
    962       || (REG_PARM_STACK_SPACE (decl_or_type)
    963 	  != REG_PARM_STACK_SPACE (current_function_decl)))
    964     {
    965       maybe_complain_about_tail_call (exp,
    966 				      "inconsistent size of stack space"
    967 				      " allocated for arguments which are"
    968 				      " passed in registers");
    969       return false;
    970     }
    971 
    972   /* Check that the return value locations are the same.  Like
    973      if we are returning floats on the 80387 register stack, we cannot
    974      make a sibcall from a function that doesn't return a float to a
    975      function that does or, conversely, from a function that does return
    976      a float to a function that doesn't; the necessary stack adjustment
    977      would not be executed.  This is also the place we notice
    978      differences in the return value ABI.  Note that it is ok for one
    979      of the functions to have void return type as long as the return
    980      value of the other is passed in a register.  */
    981   a = ix86_function_value (TREE_TYPE (exp), decl_or_type, false);
    982   b = ix86_function_value (TREE_TYPE (DECL_RESULT (cfun->decl)),
    983 			   cfun->decl, false);
    984   if (STACK_REG_P (a) || STACK_REG_P (b))
    985     {
    986       if (!rtx_equal_p (a, b))
    987 	return false;
    988     }
    989   else if (VOID_TYPE_P (TREE_TYPE (DECL_RESULT (cfun->decl))))
    990     ;
    991   else if (!rtx_equal_p (a, b))
    992     return false;
    993 
    994   if (TARGET_64BIT)
    995     {
    996       /* The SYSV ABI has more call-clobbered registers;
    997 	 disallow sibcalls from MS to SYSV.  */
    998       if (cfun->machine->call_abi == MS_ABI
    999 	  && ix86_function_type_abi (type) == SYSV_ABI)
   1000 	return false;
   1001     }
   1002   else
   1003     {
   1004       /* If this call is indirect, we'll need to be able to use a
   1005 	 call-clobbered register for the address of the target function.
   1006 	 Make sure that all such registers are not used for passing
   1007 	 parameters.  Note that DLLIMPORT functions and call to global
   1008 	 function via GOT slot are indirect.  */
   1009       if (!decl
   1010 	  || (bind_global && flag_pic && !flag_plt)
   1011 	  || (TARGET_DLLIMPORT_DECL_ATTRIBUTES && DECL_DLLIMPORT_P (decl))
   1012 	  || flag_force_indirect_call)
   1013 	{
   1014 	  /* Check if regparm >= 3 since arg_reg_available is set to
   1015 	     false if regparm == 0.  If regparm is 1 or 2, there is
   1016 	     always a call-clobbered register available.
   1017 
   1018 	     ??? The symbol indirect call doesn't need a call-clobbered
   1019 	     register.  But we don't know if this is a symbol indirect
   1020 	     call or not here.  */
   1021 	  if (ix86_function_regparm (type, decl) >= 3
   1022 	      && !cfun->machine->arg_reg_available)
   1023 	    return false;
   1024 	}
   1025     }
   1026 
   1027   if (decl && ix86_use_pseudo_pic_reg ())
   1028     {
   1029       /* When PIC register is used, it must be restored after ifunc
   1030 	 function returns.  */
   1031        cgraph_node *node = cgraph_node::get (decl);
   1032        if (node && node->ifunc_resolver)
   1033 	 return false;
   1034     }
   1035 
   1036   /* Otherwise okay.  That also includes certain types of indirect calls.  */
   1037   return true;
   1038 }
   1039 
   1040 /* This function determines from TYPE the calling-convention.  */
   1041 
   1042 unsigned int
   1043 ix86_get_callcvt (const_tree type)
   1044 {
   1045   unsigned int ret = 0;
   1046   bool is_stdarg;
   1047   tree attrs;
   1048 
   1049   if (TARGET_64BIT)
   1050     return IX86_CALLCVT_CDECL;
   1051 
   1052   attrs = TYPE_ATTRIBUTES (type);
   1053   if (attrs != NULL_TREE)
   1054     {
   1055       if (lookup_attribute ("cdecl", attrs))
   1056 	ret |= IX86_CALLCVT_CDECL;
   1057       else if (lookup_attribute ("stdcall", attrs))
   1058 	ret |= IX86_CALLCVT_STDCALL;
   1059       else if (lookup_attribute ("fastcall", attrs))
   1060 	ret |= IX86_CALLCVT_FASTCALL;
   1061       else if (lookup_attribute ("thiscall", attrs))
   1062 	ret |= IX86_CALLCVT_THISCALL;
   1063 
   1064       /* Regparam isn't allowed for thiscall and fastcall.  */
   1065       if ((ret & (IX86_CALLCVT_THISCALL | IX86_CALLCVT_FASTCALL)) == 0)
   1066 	{
   1067 	  if (lookup_attribute ("regparm", attrs))
   1068 	    ret |= IX86_CALLCVT_REGPARM;
   1069 	  if (lookup_attribute ("sseregparm", attrs))
   1070 	    ret |= IX86_CALLCVT_SSEREGPARM;
   1071 	}
   1072 
   1073       if (IX86_BASE_CALLCVT(ret) != 0)
   1074 	return ret;
   1075     }
   1076 
   1077   is_stdarg = stdarg_p (type);
   1078   if (TARGET_RTD && !is_stdarg)
   1079     return IX86_CALLCVT_STDCALL | ret;
   1080 
   1081   if (ret != 0
   1082       || is_stdarg
   1083       || TREE_CODE (type) != METHOD_TYPE
   1084       || ix86_function_type_abi (type) != MS_ABI)
   1085     return IX86_CALLCVT_CDECL | ret;
   1086 
   1087   return IX86_CALLCVT_THISCALL;
   1088 }
   1089 
   1090 /* Return 0 if the attributes for two types are incompatible, 1 if they
   1091    are compatible, and 2 if they are nearly compatible (which causes a
   1092    warning to be generated).  */
   1093 
   1094 static int
   1095 ix86_comp_type_attributes (const_tree type1, const_tree type2)
   1096 {
   1097   unsigned int ccvt1, ccvt2;
   1098 
   1099   if (TREE_CODE (type1) != FUNCTION_TYPE
   1100       && TREE_CODE (type1) != METHOD_TYPE)
   1101     return 1;
   1102 
   1103   ccvt1 = ix86_get_callcvt (type1);
   1104   ccvt2 = ix86_get_callcvt (type2);
   1105   if (ccvt1 != ccvt2)
   1106     return 0;
   1107   if (ix86_function_regparm (type1, NULL)
   1108       != ix86_function_regparm (type2, NULL))
   1109     return 0;
   1110 
   1111   return 1;
   1112 }
   1113 
   1114 /* Return the regparm value for a function with the indicated TYPE and DECL.
   1116    DECL may be NULL when calling function indirectly
   1117    or considering a libcall.  */
   1118 
   1119 static int
   1120 ix86_function_regparm (const_tree type, const_tree decl)
   1121 {
   1122   tree attr;
   1123   int regparm;
   1124   unsigned int ccvt;
   1125 
   1126   if (TARGET_64BIT)
   1127     return (ix86_function_type_abi (type) == SYSV_ABI
   1128 	    ? X86_64_REGPARM_MAX : X86_64_MS_REGPARM_MAX);
   1129   ccvt = ix86_get_callcvt (type);
   1130   regparm = ix86_regparm;
   1131 
   1132   if ((ccvt & IX86_CALLCVT_REGPARM) != 0)
   1133     {
   1134       attr = lookup_attribute ("regparm", TYPE_ATTRIBUTES (type));
   1135       if (attr)
   1136 	{
   1137 	  regparm = TREE_INT_CST_LOW (TREE_VALUE (TREE_VALUE (attr)));
   1138 	  return regparm;
   1139 	}
   1140     }
   1141   else if ((ccvt & IX86_CALLCVT_FASTCALL) != 0)
   1142     return 2;
   1143   else if ((ccvt & IX86_CALLCVT_THISCALL) != 0)
   1144     return 1;
   1145 
   1146   /* Use register calling convention for local functions when possible.  */
   1147   if (decl
   1148       && TREE_CODE (decl) == FUNCTION_DECL)
   1149     {
   1150       cgraph_node *target = cgraph_node::get (decl);
   1151       if (target)
   1152 	target = target->function_symbol ();
   1153 
   1154       /* Caller and callee must agree on the calling convention, so
   1155 	 checking here just optimize means that with
   1156 	 __attribute__((optimize (...))) caller could use regparm convention
   1157 	 and callee not, or vice versa.  Instead look at whether the callee
   1158 	 is optimized or not.  */
   1159       if (target && opt_for_fn (target->decl, optimize)
   1160 	  && !(profile_flag && !flag_fentry))
   1161 	{
   1162 	  if (target->local && target->can_change_signature)
   1163 	    {
   1164 	      int local_regparm, globals = 0, regno;
   1165 
   1166 	      /* Make sure no regparm register is taken by a
   1167 		 fixed register variable.  */
   1168 	      for (local_regparm = 0; local_regparm < REGPARM_MAX;
   1169 		   local_regparm++)
   1170 		if (fixed_regs[local_regparm])
   1171 		  break;
   1172 
   1173 	      /* We don't want to use regparm(3) for nested functions as
   1174 		 these use a static chain pointer in the third argument.  */
   1175 	      if (local_regparm == 3 && DECL_STATIC_CHAIN (target->decl))
   1176 		local_regparm = 2;
   1177 
   1178 	      /* Save a register for the split stack.  */
   1179 	      if (flag_split_stack)
   1180 		{
   1181 		  if (local_regparm == 3)
   1182 		    local_regparm = 2;
   1183 		  else if (local_regparm == 2
   1184 			   && DECL_STATIC_CHAIN (target->decl))
   1185 		    local_regparm = 1;
   1186 		}
   1187 
   1188 	      /* Each fixed register usage increases register pressure,
   1189 		 so less registers should be used for argument passing.
   1190 		 This functionality can be overriden by an explicit
   1191 		 regparm value.  */
   1192 	      for (regno = AX_REG; regno <= DI_REG; regno++)
   1193 		if (fixed_regs[regno])
   1194 		  globals++;
   1195 
   1196 	      local_regparm
   1197 		= globals < local_regparm ? local_regparm - globals : 0;
   1198 
   1199 	      if (local_regparm > regparm)
   1200 		regparm = local_regparm;
   1201 	    }
   1202 	}
   1203     }
   1204 
   1205   return regparm;
   1206 }
   1207 
   1208 /* Return 1 or 2, if we can pass up to SSE_REGPARM_MAX SFmode (1) and
   1209    DFmode (2) arguments in SSE registers for a function with the
   1210    indicated TYPE and DECL.  DECL may be NULL when calling function
   1211    indirectly or considering a libcall.  Return -1 if any FP parameter
   1212    should be rejected by error.  This is used in siutation we imply SSE
   1213    calling convetion but the function is called from another function with
   1214    SSE disabled. Otherwise return 0.  */
   1215 
   1216 static int
   1217 ix86_function_sseregparm (const_tree type, const_tree decl, bool warn)
   1218 {
   1219   gcc_assert (!TARGET_64BIT);
   1220 
   1221   /* Use SSE registers to pass SFmode and DFmode arguments if requested
   1222      by the sseregparm attribute.  */
   1223   if (TARGET_SSEREGPARM
   1224       || (type && lookup_attribute ("sseregparm", TYPE_ATTRIBUTES (type))))
   1225     {
   1226       if (!TARGET_SSE)
   1227 	{
   1228 	  if (warn)
   1229 	    {
   1230 	      if (decl)
   1231 		error ("calling %qD with attribute sseregparm without "
   1232 		       "SSE/SSE2 enabled", decl);
   1233 	      else
   1234 		error ("calling %qT with attribute sseregparm without "
   1235 		       "SSE/SSE2 enabled", type);
   1236 	    }
   1237 	  return 0;
   1238 	}
   1239 
   1240       return 2;
   1241     }
   1242 
   1243   if (!decl)
   1244     return 0;
   1245 
   1246   cgraph_node *target = cgraph_node::get (decl);
   1247   if (target)
   1248     target = target->function_symbol ();
   1249 
   1250   /* For local functions, pass up to SSE_REGPARM_MAX SFmode
   1251      (and DFmode for SSE2) arguments in SSE registers.  */
   1252   if (target
   1253       /* TARGET_SSE_MATH */
   1254       && (target_opts_for_fn (target->decl)->x_ix86_fpmath & FPMATH_SSE)
   1255       && opt_for_fn (target->decl, optimize)
   1256       && !(profile_flag && !flag_fentry))
   1257     {
   1258       if (target->local && target->can_change_signature)
   1259 	{
   1260 	  /* Refuse to produce wrong code when local function with SSE enabled
   1261 	     is called from SSE disabled function.
   1262 	     FIXME: We need a way to detect these cases cross-ltrans partition
   1263 	     and avoid using SSE calling conventions on local functions called
   1264 	     from function with SSE disabled.  For now at least delay the
   1265 	     warning until we know we are going to produce wrong code.
   1266 	     See PR66047  */
   1267 	  if (!TARGET_SSE && warn)
   1268 	    return -1;
   1269 	  return TARGET_SSE2_P (target_opts_for_fn (target->decl)
   1270 				->x_ix86_isa_flags) ? 2 : 1;
   1271 	}
   1272     }
   1273 
   1274   return 0;
   1275 }
   1276 
   1277 /* Return true if EAX is live at the start of the function.  Used by
   1278    ix86_expand_prologue to determine if we need special help before
   1279    calling allocate_stack_worker.  */
   1280 
   1281 static bool
   1282 ix86_eax_live_at_start_p (void)
   1283 {
   1284   /* Cheat.  Don't bother working forward from ix86_function_regparm
   1285      to the function type to whether an actual argument is located in
   1286      eax.  Instead just look at cfg info, which is still close enough
   1287      to correct at this point.  This gives false positives for broken
   1288      functions that might use uninitialized data that happens to be
   1289      allocated in eax, but who cares?  */
   1290   return REGNO_REG_SET_P (df_get_live_out (ENTRY_BLOCK_PTR_FOR_FN (cfun)), 0);
   1291 }
   1292 
   1293 static bool
   1294 ix86_keep_aggregate_return_pointer (tree fntype)
   1295 {
   1296   tree attr;
   1297 
   1298   if (!TARGET_64BIT)
   1299     {
   1300       attr = lookup_attribute ("callee_pop_aggregate_return",
   1301 			       TYPE_ATTRIBUTES (fntype));
   1302       if (attr)
   1303 	return (TREE_INT_CST_LOW (TREE_VALUE (TREE_VALUE (attr))) == 0);
   1304 
   1305       /* For 32-bit MS-ABI the default is to keep aggregate
   1306          return pointer.  */
   1307       if (ix86_function_type_abi (fntype) == MS_ABI)
   1308 	return true;
   1309     }
   1310   return KEEP_AGGREGATE_RETURN_POINTER != 0;
   1311 }
   1312 
   1313 /* Value is the number of bytes of arguments automatically
   1314    popped when returning from a subroutine call.
   1315    FUNDECL is the declaration node of the function (as a tree),
   1316    FUNTYPE is the data type of the function (as a tree),
   1317    or for a library call it is an identifier node for the subroutine name.
   1318    SIZE is the number of bytes of arguments passed on the stack.
   1319 
   1320    On the 80386, the RTD insn may be used to pop them if the number
   1321      of args is fixed, but if the number is variable then the caller
   1322      must pop them all.  RTD can't be used for library calls now
   1323      because the library is compiled with the Unix compiler.
   1324    Use of RTD is a selectable option, since it is incompatible with
   1325    standard Unix calling sequences.  If the option is not selected,
   1326    the caller must always pop the args.
   1327 
   1328    The attribute stdcall is equivalent to RTD on a per module basis.  */
   1329 
   1330 static poly_int64
   1331 ix86_return_pops_args (tree fundecl, tree funtype, poly_int64 size)
   1332 {
   1333   unsigned int ccvt;
   1334 
   1335   /* None of the 64-bit ABIs pop arguments.  */
   1336   if (TARGET_64BIT)
   1337     return 0;
   1338 
   1339   ccvt = ix86_get_callcvt (funtype);
   1340 
   1341   if ((ccvt & (IX86_CALLCVT_STDCALL | IX86_CALLCVT_FASTCALL
   1342 	       | IX86_CALLCVT_THISCALL)) != 0
   1343       && ! stdarg_p (funtype))
   1344     return size;
   1345 
   1346   /* Lose any fake structure return argument if it is passed on the stack.  */
   1347   if (aggregate_value_p (TREE_TYPE (funtype), fundecl)
   1348       && !ix86_keep_aggregate_return_pointer (funtype))
   1349     {
   1350       int nregs = ix86_function_regparm (funtype, fundecl);
   1351       if (nregs == 0)
   1352 	return GET_MODE_SIZE (Pmode);
   1353     }
   1354 
   1355   return 0;
   1356 }
   1357 
   1358 /* Implement the TARGET_LEGITIMATE_COMBINED_INSN hook.  */
   1359 
   1360 static bool
   1361 ix86_legitimate_combined_insn (rtx_insn *insn)
   1362 {
   1363   int i;
   1364 
   1365   /* Check operand constraints in case hard registers were propagated
   1366      into insn pattern.  This check prevents combine pass from
   1367      generating insn patterns with invalid hard register operands.
   1368      These invalid insns can eventually confuse reload to error out
   1369      with a spill failure.  See also PRs 46829 and 46843.  */
   1370 
   1371   gcc_assert (INSN_CODE (insn) >= 0);
   1372 
   1373   extract_insn (insn);
   1374   preprocess_constraints (insn);
   1375 
   1376   int n_operands = recog_data.n_operands;
   1377   int n_alternatives = recog_data.n_alternatives;
   1378   for (i = 0; i < n_operands; i++)
   1379     {
   1380       rtx op = recog_data.operand[i];
   1381       machine_mode mode = GET_MODE (op);
   1382       const operand_alternative *op_alt;
   1383       int offset = 0;
   1384       bool win;
   1385       int j;
   1386 
   1387       /* A unary operator may be accepted by the predicate, but it
   1388 	 is irrelevant for matching constraints.  */
   1389       if (UNARY_P (op))
   1390 	op = XEXP (op, 0);
   1391 
   1392       if (SUBREG_P (op))
   1393 	{
   1394 	  if (REG_P (SUBREG_REG (op))
   1395 	      && REGNO (SUBREG_REG (op)) < FIRST_PSEUDO_REGISTER)
   1396 	    offset = subreg_regno_offset (REGNO (SUBREG_REG (op)),
   1397 					  GET_MODE (SUBREG_REG (op)),
   1398 					  SUBREG_BYTE (op),
   1399 					  GET_MODE (op));
   1400 	  op = SUBREG_REG (op);
   1401 	}
   1402 
   1403       if (!(REG_P (op) && HARD_REGISTER_P (op)))
   1404 	continue;
   1405 
   1406       op_alt = recog_op_alt;
   1407 
   1408       /* Operand has no constraints, anything is OK.  */
   1409       win = !n_alternatives;
   1410 
   1411       alternative_mask preferred = get_preferred_alternatives (insn);
   1412       for (j = 0; j < n_alternatives; j++, op_alt += n_operands)
   1413 	{
   1414 	  if (!TEST_BIT (preferred, j))
   1415 	    continue;
   1416 	  if (op_alt[i].anything_ok
   1417 	      || (op_alt[i].matches != -1
   1418 		  && operands_match_p
   1419 		  (recog_data.operand[i],
   1420 		   recog_data.operand[op_alt[i].matches]))
   1421 	      || reg_fits_class_p (op, op_alt[i].cl, offset, mode))
   1422 	    {
   1423 	      win = true;
   1424 	      break;
   1425 	    }
   1426 	}
   1427 
   1428       if (!win)
   1429 	return false;
   1430     }
   1431 
   1432   return true;
   1433 }
   1434 
   1435 /* Implement the TARGET_ASAN_SHADOW_OFFSET hook.  */
   1437 
   1438 static unsigned HOST_WIDE_INT
   1439 ix86_asan_shadow_offset (void)
   1440 {
   1441   return SUBTARGET_SHADOW_OFFSET;
   1442 }
   1443 
   1444 /* Argument support functions.  */
   1446 
   1447 /* Return true when register may be used to pass function parameters.  */
   1448 bool
   1449 ix86_function_arg_regno_p (int regno)
   1450 {
   1451   int i;
   1452   enum calling_abi call_abi;
   1453   const int *parm_regs;
   1454 
   1455   if (TARGET_SSE && SSE_REGNO_P (regno)
   1456       && regno < FIRST_SSE_REG + SSE_REGPARM_MAX)
   1457     return true;
   1458 
   1459    if (!TARGET_64BIT)
   1460      return (regno < REGPARM_MAX
   1461 	     || (TARGET_MMX && MMX_REGNO_P (regno)
   1462 		 && regno < FIRST_MMX_REG + MMX_REGPARM_MAX));
   1463 
   1464   /* TODO: The function should depend on current function ABI but
   1465      builtins.cc would need updating then. Therefore we use the
   1466      default ABI.  */
   1467   call_abi = ix86_cfun_abi ();
   1468 
   1469   /* RAX is used as hidden argument to va_arg functions.  */
   1470   if (call_abi == SYSV_ABI && regno == AX_REG)
   1471     return true;
   1472 
   1473   if (call_abi == MS_ABI)
   1474     parm_regs = x86_64_ms_abi_int_parameter_registers;
   1475   else
   1476     parm_regs = x86_64_int_parameter_registers;
   1477 
   1478   for (i = 0; i < (call_abi == MS_ABI
   1479 		   ? X86_64_MS_REGPARM_MAX : X86_64_REGPARM_MAX); i++)
   1480     if (regno == parm_regs[i])
   1481       return true;
   1482   return false;
   1483 }
   1484 
   1485 /* Return if we do not know how to pass ARG solely in registers.  */
   1486 
   1487 static bool
   1488 ix86_must_pass_in_stack (const function_arg_info &arg)
   1489 {
   1490   if (must_pass_in_stack_var_size_or_pad (arg))
   1491     return true;
   1492 
   1493   /* For 32-bit, we want TImode aggregates to go on the stack.  But watch out!
   1494      The layout_type routine is crafty and tries to trick us into passing
   1495      currently unsupported vector types on the stack by using TImode.  */
   1496   return (!TARGET_64BIT && arg.mode == TImode
   1497 	  && arg.type && TREE_CODE (arg.type) != VECTOR_TYPE);
   1498 }
   1499 
   1500 /* It returns the size, in bytes, of the area reserved for arguments passed
   1501    in registers for the function represented by fndecl dependent to the used
   1502    abi format.  */
   1503 int
   1504 ix86_reg_parm_stack_space (const_tree fndecl)
   1505 {
   1506   enum calling_abi call_abi = SYSV_ABI;
   1507   if (fndecl != NULL_TREE && TREE_CODE (fndecl) == FUNCTION_DECL)
   1508     call_abi = ix86_function_abi (fndecl);
   1509   else
   1510     call_abi = ix86_function_type_abi (fndecl);
   1511   if (TARGET_64BIT && call_abi == MS_ABI)
   1512     return 32;
   1513   return 0;
   1514 }
   1515 
   1516 /* We add this as a workaround in order to use libc_has_function
   1517    hook in i386.md.  */
   1518 bool
   1519 ix86_libc_has_function (enum function_class fn_class)
   1520 {
   1521   return targetm.libc_has_function (fn_class, NULL_TREE);
   1522 }
   1523 
   1524 /* Returns value SYSV_ABI, MS_ABI dependent on fntype,
   1525    specifying the call abi used.  */
   1526 enum calling_abi
   1527 ix86_function_type_abi (const_tree fntype)
   1528 {
   1529   enum calling_abi abi = ix86_abi;
   1530 
   1531   if (fntype == NULL_TREE || TYPE_ATTRIBUTES (fntype) == NULL_TREE)
   1532     return abi;
   1533 
   1534   if (abi == SYSV_ABI
   1535       && lookup_attribute ("ms_abi", TYPE_ATTRIBUTES (fntype)))
   1536     {
   1537       static int warned;
   1538       if (TARGET_X32 && !warned)
   1539 	{
   1540 	  error ("X32 does not support %<ms_abi%> attribute");
   1541 	  warned = 1;
   1542 	}
   1543 
   1544       abi = MS_ABI;
   1545     }
   1546   else if (abi == MS_ABI
   1547 	   && lookup_attribute ("sysv_abi", TYPE_ATTRIBUTES (fntype)))
   1548     abi = SYSV_ABI;
   1549 
   1550   return abi;
   1551 }
   1552 
   1553 enum calling_abi
   1554 ix86_function_abi (const_tree fndecl)
   1555 {
   1556   return fndecl ? ix86_function_type_abi (TREE_TYPE (fndecl)) : ix86_abi;
   1557 }
   1558 
   1559 /* Returns value SYSV_ABI, MS_ABI dependent on cfun,
   1560    specifying the call abi used.  */
   1561 enum calling_abi
   1562 ix86_cfun_abi (void)
   1563 {
   1564   return cfun ? cfun->machine->call_abi : ix86_abi;
   1565 }
   1566 
   1567 bool
   1568 ix86_function_ms_hook_prologue (const_tree fn)
   1569 {
   1570   if (fn && lookup_attribute ("ms_hook_prologue", DECL_ATTRIBUTES (fn)))
   1571     {
   1572       if (decl_function_context (fn) != NULL_TREE)
   1573 	error_at (DECL_SOURCE_LOCATION (fn),
   1574 		  "%<ms_hook_prologue%> attribute is not compatible "
   1575 		  "with nested function");
   1576       else
   1577         return true;
   1578     }
   1579   return false;
   1580 }
   1581 
   1582 bool
   1583 ix86_function_naked (const_tree fn)
   1584 {
   1585   if (fn && lookup_attribute ("naked", DECL_ATTRIBUTES (fn)))
   1586     return true;
   1587 
   1588   return false;
   1589 }
   1590 
   1591 /* Write the extra assembler code needed to declare a function properly.  */
   1592 
   1593 void
   1594 ix86_asm_output_function_label (FILE *out_file, const char *fname,
   1595 				tree decl)
   1596 {
   1597   bool is_ms_hook = ix86_function_ms_hook_prologue (decl);
   1598 
   1599   if (cfun)
   1600     cfun->machine->function_label_emitted = true;
   1601 
   1602   if (is_ms_hook)
   1603     {
   1604       int i, filler_count = (TARGET_64BIT ? 32 : 16);
   1605       unsigned int filler_cc = 0xcccccccc;
   1606 
   1607       for (i = 0; i < filler_count; i += 4)
   1608 	fprintf (out_file, ASM_LONG " %#x\n", filler_cc);
   1609     }
   1610 
   1611 #ifdef SUBTARGET_ASM_UNWIND_INIT
   1612   SUBTARGET_ASM_UNWIND_INIT (out_file);
   1613 #endif
   1614 
   1615   ASM_OUTPUT_LABEL (out_file, fname);
   1616 
   1617   /* Output magic byte marker, if hot-patch attribute is set.  */
   1618   if (is_ms_hook)
   1619     {
   1620       if (TARGET_64BIT)
   1621 	{
   1622 	  /* leaq [%rsp + 0], %rsp  */
   1623 	  fputs (ASM_BYTE "0x48, 0x8d, 0xa4, 0x24, 0x00, 0x00, 0x00, 0x00\n",
   1624 		 out_file);
   1625 	}
   1626       else
   1627 	{
   1628           /* movl.s %edi, %edi
   1629 	     push   %ebp
   1630 	     movl.s %esp, %ebp */
   1631 	  fputs (ASM_BYTE "0x8b, 0xff, 0x55, 0x8b, 0xec\n", out_file);
   1632 	}
   1633     }
   1634 }
   1635 
   1636 /* Implementation of call abi switching target hook. Specific to FNDECL
   1637    the specific call register sets are set.  See also
   1638    ix86_conditional_register_usage for more details.  */
   1639 void
   1640 ix86_call_abi_override (const_tree fndecl)
   1641 {
   1642   cfun->machine->call_abi = ix86_function_abi (fndecl);
   1643 }
   1644 
   1645 /* Return 1 if pseudo register should be created and used to hold
   1646    GOT address for PIC code.  */
   1647 bool
   1648 ix86_use_pseudo_pic_reg (void)
   1649 {
   1650   if ((TARGET_64BIT
   1651        && (ix86_cmodel == CM_SMALL_PIC
   1652 	   || TARGET_PECOFF))
   1653       || !flag_pic)
   1654     return false;
   1655   return true;
   1656 }
   1657 
   1658 /* Initialize large model PIC register.  */
   1659 
   1660 static void
   1661 ix86_init_large_pic_reg (unsigned int tmp_regno)
   1662 {
   1663   rtx_code_label *label;
   1664   rtx tmp_reg;
   1665 
   1666   gcc_assert (Pmode == DImode);
   1667   label = gen_label_rtx ();
   1668   emit_label (label);
   1669   LABEL_PRESERVE_P (label) = 1;
   1670   tmp_reg = gen_rtx_REG (Pmode, tmp_regno);
   1671   gcc_assert (REGNO (pic_offset_table_rtx) != tmp_regno);
   1672   emit_insn (gen_set_rip_rex64 (pic_offset_table_rtx,
   1673 				label));
   1674   emit_insn (gen_set_got_offset_rex64 (tmp_reg, label));
   1675   emit_insn (gen_add2_insn (pic_offset_table_rtx, tmp_reg));
   1676   const char *name = LABEL_NAME (label);
   1677   PUT_CODE (label, NOTE);
   1678   NOTE_KIND (label) = NOTE_INSN_DELETED_LABEL;
   1679   NOTE_DELETED_LABEL_NAME (label) = name;
   1680 }
   1681 
   1682 /* Create and initialize PIC register if required.  */
   1683 static void
   1684 ix86_init_pic_reg (void)
   1685 {
   1686   edge entry_edge;
   1687   rtx_insn *seq;
   1688 
   1689   if (!ix86_use_pseudo_pic_reg ())
   1690     return;
   1691 
   1692   start_sequence ();
   1693 
   1694   if (TARGET_64BIT)
   1695     {
   1696       if (ix86_cmodel == CM_LARGE_PIC)
   1697 	ix86_init_large_pic_reg (R11_REG);
   1698       else
   1699 	emit_insn (gen_set_got_rex64 (pic_offset_table_rtx));
   1700     }
   1701   else
   1702     {
   1703       /*  If there is future mcount call in the function it is more profitable
   1704 	  to emit SET_GOT into ABI defined REAL_PIC_OFFSET_TABLE_REGNUM.  */
   1705       rtx reg = crtl->profile
   1706 		? gen_rtx_REG (Pmode, REAL_PIC_OFFSET_TABLE_REGNUM)
   1707 		: pic_offset_table_rtx;
   1708       rtx_insn *insn = emit_insn (gen_set_got (reg));
   1709       RTX_FRAME_RELATED_P (insn) = 1;
   1710       if (crtl->profile)
   1711         emit_move_insn (pic_offset_table_rtx, reg);
   1712       add_reg_note (insn, REG_CFA_FLUSH_QUEUE, NULL_RTX);
   1713     }
   1714 
   1715   seq = get_insns ();
   1716   end_sequence ();
   1717 
   1718   entry_edge = single_succ_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun));
   1719   insert_insn_on_edge (seq, entry_edge);
   1720   commit_one_edge_insertion (entry_edge);
   1721 }
   1722 
   1723 /* Initialize a variable CUM of type CUMULATIVE_ARGS
   1724    for a call to a function whose data type is FNTYPE.
   1725    For a library call, FNTYPE is 0.  */
   1726 
   1727 void
   1728 init_cumulative_args (CUMULATIVE_ARGS *cum,  /* Argument info to initialize */
   1729 		      tree fntype,	/* tree ptr for function decl */
   1730 		      rtx libname,	/* SYMBOL_REF of library name or 0 */
   1731 		      tree fndecl,
   1732 		      int caller)
   1733 {
   1734   struct cgraph_node *local_info_node = NULL;
   1735   struct cgraph_node *target = NULL;
   1736 
   1737   /* Set silent_p to false to raise an error for invalid calls when
   1738      expanding function body.  */
   1739   cfun->machine->silent_p = false;
   1740 
   1741   memset (cum, 0, sizeof (*cum));
   1742 
   1743   if (fndecl)
   1744     {
   1745       target = cgraph_node::get (fndecl);
   1746       if (target)
   1747 	{
   1748 	  target = target->function_symbol ();
   1749 	  local_info_node = cgraph_node::local_info_node (target->decl);
   1750 	  cum->call_abi = ix86_function_abi (target->decl);
   1751 	}
   1752       else
   1753 	cum->call_abi = ix86_function_abi (fndecl);
   1754     }
   1755   else
   1756     cum->call_abi = ix86_function_type_abi (fntype);
   1757 
   1758   cum->caller = caller;
   1759 
   1760   /* Set up the number of registers to use for passing arguments.  */
   1761   cum->nregs = ix86_regparm;
   1762   if (TARGET_64BIT)
   1763     {
   1764       cum->nregs = (cum->call_abi == SYSV_ABI
   1765                    ? X86_64_REGPARM_MAX
   1766                    : X86_64_MS_REGPARM_MAX);
   1767     }
   1768   if (TARGET_SSE)
   1769     {
   1770       cum->sse_nregs = SSE_REGPARM_MAX;
   1771       if (TARGET_64BIT)
   1772         {
   1773           cum->sse_nregs = (cum->call_abi == SYSV_ABI
   1774                            ? X86_64_SSE_REGPARM_MAX
   1775                            : X86_64_MS_SSE_REGPARM_MAX);
   1776         }
   1777     }
   1778   if (TARGET_MMX)
   1779     cum->mmx_nregs = MMX_REGPARM_MAX;
   1780   cum->warn_avx512f = true;
   1781   cum->warn_avx = true;
   1782   cum->warn_sse = true;
   1783   cum->warn_mmx = true;
   1784 
   1785   /* Because type might mismatch in between caller and callee, we need to
   1786      use actual type of function for local calls.
   1787      FIXME: cgraph_analyze can be told to actually record if function uses
   1788      va_start so for local functions maybe_vaarg can be made aggressive
   1789      helping K&R code.
   1790      FIXME: once typesytem is fixed, we won't need this code anymore.  */
   1791   if (local_info_node && local_info_node->local
   1792       && local_info_node->can_change_signature)
   1793     fntype = TREE_TYPE (target->decl);
   1794   cum->stdarg = stdarg_p (fntype);
   1795   cum->maybe_vaarg = (fntype
   1796 		      ? (!prototype_p (fntype) || stdarg_p (fntype))
   1797 		      : !libname);
   1798 
   1799   cum->decl = fndecl;
   1800 
   1801   cum->warn_empty = !warn_abi || cum->stdarg;
   1802   if (!cum->warn_empty && fntype)
   1803     {
   1804       function_args_iterator iter;
   1805       tree argtype;
   1806       bool seen_empty_type = false;
   1807       FOREACH_FUNCTION_ARGS (fntype, argtype, iter)
   1808 	{
   1809 	  if (argtype == error_mark_node || VOID_TYPE_P (argtype))
   1810 	    break;
   1811 	  if (TYPE_EMPTY_P (argtype))
   1812 	    seen_empty_type = true;
   1813 	  else if (seen_empty_type)
   1814 	    {
   1815 	      cum->warn_empty = true;
   1816 	      break;
   1817 	    }
   1818 	}
   1819     }
   1820 
   1821   if (!TARGET_64BIT)
   1822     {
   1823       /* If there are variable arguments, then we won't pass anything
   1824          in registers in 32-bit mode. */
   1825       if (stdarg_p (fntype))
   1826 	{
   1827 	  cum->nregs = 0;
   1828 	  /* Since in 32-bit, variable arguments are always passed on
   1829 	     stack, there is scratch register available for indirect
   1830 	     sibcall.  */
   1831 	  cfun->machine->arg_reg_available = true;
   1832 	  cum->sse_nregs = 0;
   1833 	  cum->mmx_nregs = 0;
   1834 	  cum->warn_avx512f = false;
   1835 	  cum->warn_avx = false;
   1836 	  cum->warn_sse = false;
   1837 	  cum->warn_mmx = false;
   1838 	  return;
   1839 	}
   1840 
   1841       /* Use ecx and edx registers if function has fastcall attribute,
   1842 	 else look for regparm information.  */
   1843       if (fntype)
   1844 	{
   1845 	  unsigned int ccvt = ix86_get_callcvt (fntype);
   1846 	  if ((ccvt & IX86_CALLCVT_THISCALL) != 0)
   1847 	    {
   1848 	      cum->nregs = 1;
   1849 	      cum->fastcall = 1; /* Same first register as in fastcall.  */
   1850 	    }
   1851 	  else if ((ccvt & IX86_CALLCVT_FASTCALL) != 0)
   1852 	    {
   1853 	      cum->nregs = 2;
   1854 	      cum->fastcall = 1;
   1855 	    }
   1856 	  else
   1857 	    cum->nregs = ix86_function_regparm (fntype, fndecl);
   1858 	}
   1859 
   1860       /* Set up the number of SSE registers used for passing SFmode
   1861 	 and DFmode arguments.  Warn for mismatching ABI.  */
   1862       cum->float_in_sse = ix86_function_sseregparm (fntype, fndecl, true);
   1863     }
   1864 
   1865   cfun->machine->arg_reg_available = (cum->nregs > 0);
   1866 }
   1867 
   1868 /* Return the "natural" mode for TYPE.  In most cases, this is just TYPE_MODE.
   1869    But in the case of vector types, it is some vector mode.
   1870 
   1871    When we have only some of our vector isa extensions enabled, then there
   1872    are some modes for which vector_mode_supported_p is false.  For these
   1873    modes, the generic vector support in gcc will choose some non-vector mode
   1874    in order to implement the type.  By computing the natural mode, we'll
   1875    select the proper ABI location for the operand and not depend on whatever
   1876    the middle-end decides to do with these vector types.
   1877 
   1878    The midde-end can't deal with the vector types > 16 bytes.  In this
   1879    case, we return the original mode and warn ABI change if CUM isn't
   1880    NULL.
   1881 
   1882    If INT_RETURN is true, warn ABI change if the vector mode isn't
   1883    available for function return value.  */
   1884 
   1885 static machine_mode
   1886 type_natural_mode (const_tree type, const CUMULATIVE_ARGS *cum,
   1887 		   bool in_return)
   1888 {
   1889   machine_mode mode = TYPE_MODE (type);
   1890 
   1891   if (TREE_CODE (type) == VECTOR_TYPE && !VECTOR_MODE_P (mode))
   1892     {
   1893       HOST_WIDE_INT size = int_size_in_bytes (type);
   1894       if ((size == 8 || size == 16 || size == 32 || size == 64)
   1895 	  /* ??? Generic code allows us to create width 1 vectors.  Ignore.  */
   1896 	  && TYPE_VECTOR_SUBPARTS (type) > 1)
   1897 	{
   1898 	  machine_mode innermode = TYPE_MODE (TREE_TYPE (type));
   1899 
   1900 	  /* There are no XFmode vector modes ...  */
   1901 	  if (innermode == XFmode)
   1902 	    return mode;
   1903 
   1904 	  /* ... and no decimal float vector modes.  */
   1905 	  if (DECIMAL_FLOAT_MODE_P (innermode))
   1906 	    return mode;
   1907 
   1908 	  if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
   1909 	    mode = MIN_MODE_VECTOR_FLOAT;
   1910 	  else
   1911 	    mode = MIN_MODE_VECTOR_INT;
   1912 
   1913 	  /* Get the mode which has this inner mode and number of units.  */
   1914 	  FOR_EACH_MODE_FROM (mode, mode)
   1915 	    if (GET_MODE_NUNITS (mode) == TYPE_VECTOR_SUBPARTS (type)
   1916 		&& GET_MODE_INNER (mode) == innermode)
   1917 	      {
   1918 		if (size == 64 && !TARGET_AVX512F && !TARGET_IAMCU)
   1919 		  {
   1920 		    static bool warnedavx512f;
   1921 		    static bool warnedavx512f_ret;
   1922 
   1923 		    if (cum && cum->warn_avx512f && !warnedavx512f)
   1924 		      {
   1925 			if (warning (OPT_Wpsabi, "AVX512F vector argument "
   1926 				     "without AVX512F enabled changes the ABI"))
   1927 			  warnedavx512f = true;
   1928 		      }
   1929 		    else if (in_return && !warnedavx512f_ret)
   1930 		      {
   1931 			if (warning (OPT_Wpsabi, "AVX512F vector return "
   1932 				     "without AVX512F enabled changes the ABI"))
   1933 			  warnedavx512f_ret = true;
   1934 		      }
   1935 
   1936 		    return TYPE_MODE (type);
   1937 		  }
   1938 		else if (size == 32 && !TARGET_AVX && !TARGET_IAMCU)
   1939 		  {
   1940 		    static bool warnedavx;
   1941 		    static bool warnedavx_ret;
   1942 
   1943 		    if (cum && cum->warn_avx && !warnedavx)
   1944 		      {
   1945 			if (warning (OPT_Wpsabi, "AVX vector argument "
   1946 				     "without AVX enabled changes the ABI"))
   1947 			  warnedavx = true;
   1948 		      }
   1949 		    else if (in_return && !warnedavx_ret)
   1950 		      {
   1951 			if (warning (OPT_Wpsabi, "AVX vector return "
   1952 				     "without AVX enabled changes the ABI"))
   1953 			  warnedavx_ret = true;
   1954 		      }
   1955 
   1956 		    return TYPE_MODE (type);
   1957 		  }
   1958 		else if (((size == 8 && TARGET_64BIT) || size == 16)
   1959 			 && !TARGET_SSE
   1960 			 && !TARGET_IAMCU)
   1961 		  {
   1962 		    static bool warnedsse;
   1963 		    static bool warnedsse_ret;
   1964 
   1965 		    if (cum && cum->warn_sse && !warnedsse)
   1966 		      {
   1967 			if (warning (OPT_Wpsabi, "SSE vector argument "
   1968 				     "without SSE enabled changes the ABI"))
   1969 			  warnedsse = true;
   1970 		      }
   1971 		    else if (!TARGET_64BIT && in_return && !warnedsse_ret)
   1972 		      {
   1973 			if (warning (OPT_Wpsabi, "SSE vector return "
   1974 				     "without SSE enabled changes the ABI"))
   1975 			  warnedsse_ret = true;
   1976 		      }
   1977 		  }
   1978 		else if ((size == 8 && !TARGET_64BIT)
   1979 			 && (!cfun
   1980 			     || cfun->machine->func_type == TYPE_NORMAL)
   1981 			 && !TARGET_MMX
   1982 			 && !TARGET_IAMCU)
   1983 		  {
   1984 		    static bool warnedmmx;
   1985 		    static bool warnedmmx_ret;
   1986 
   1987 		    if (cum && cum->warn_mmx && !warnedmmx)
   1988 		      {
   1989 			if (warning (OPT_Wpsabi, "MMX vector argument "
   1990 				     "without MMX enabled changes the ABI"))
   1991 			  warnedmmx = true;
   1992 		      }
   1993 		    else if (in_return && !warnedmmx_ret)
   1994 		      {
   1995 			if (warning (OPT_Wpsabi, "MMX vector return "
   1996 				     "without MMX enabled changes the ABI"))
   1997 			  warnedmmx_ret = true;
   1998 		      }
   1999 		  }
   2000 		return mode;
   2001 	      }
   2002 
   2003 	  gcc_unreachable ();
   2004 	}
   2005     }
   2006 
   2007   return mode;
   2008 }
   2009 
   2010 /* We want to pass a value in REGNO whose "natural" mode is MODE.  However,
   2011    this may not agree with the mode that the type system has chosen for the
   2012    register, which is ORIG_MODE.  If ORIG_MODE is not BLKmode, then we can
   2013    go ahead and use it.  Otherwise we have to build a PARALLEL instead.  */
   2014 
   2015 static rtx
   2016 gen_reg_or_parallel (machine_mode mode, machine_mode orig_mode,
   2017 		     unsigned int regno)
   2018 {
   2019   rtx tmp;
   2020 
   2021   if (orig_mode != BLKmode)
   2022     tmp = gen_rtx_REG (orig_mode, regno);
   2023   else
   2024     {
   2025       tmp = gen_rtx_REG (mode, regno);
   2026       tmp = gen_rtx_EXPR_LIST (VOIDmode, tmp, const0_rtx);
   2027       tmp = gen_rtx_PARALLEL (orig_mode, gen_rtvec (1, tmp));
   2028     }
   2029 
   2030   return tmp;
   2031 }
   2032 
   2033 /* x86-64 register passing implementation.  See x86-64 ABI for details.  Goal
   2034    of this code is to classify each 8bytes of incoming argument by the register
   2035    class and assign registers accordingly.  */
   2036 
   2037 /* Return the union class of CLASS1 and CLASS2.
   2038    See the x86-64 PS ABI for details.  */
   2039 
   2040 static enum x86_64_reg_class
   2041 merge_classes (enum x86_64_reg_class class1, enum x86_64_reg_class class2)
   2042 {
   2043   /* Rule #1: If both classes are equal, this is the resulting class.  */
   2044   if (class1 == class2)
   2045     return class1;
   2046 
   2047   /* Rule #2: If one of the classes is NO_CLASS, the resulting class is
   2048      the other class.  */
   2049   if (class1 == X86_64_NO_CLASS)
   2050     return class2;
   2051   if (class2 == X86_64_NO_CLASS)
   2052     return class1;
   2053 
   2054   /* Rule #3: If one of the classes is MEMORY, the result is MEMORY.  */
   2055   if (class1 == X86_64_MEMORY_CLASS || class2 == X86_64_MEMORY_CLASS)
   2056     return X86_64_MEMORY_CLASS;
   2057 
   2058   /* Rule #4: If one of the classes is INTEGER, the result is INTEGER.  */
   2059   if ((class1 == X86_64_INTEGERSI_CLASS
   2060        && (class2 == X86_64_SSESF_CLASS || class2 == X86_64_SSEHF_CLASS))
   2061       || (class2 == X86_64_INTEGERSI_CLASS
   2062 	  && (class1 == X86_64_SSESF_CLASS || class1 == X86_64_SSEHF_CLASS)))
   2063     return X86_64_INTEGERSI_CLASS;
   2064   if (class1 == X86_64_INTEGER_CLASS || class1 == X86_64_INTEGERSI_CLASS
   2065       || class2 == X86_64_INTEGER_CLASS || class2 == X86_64_INTEGERSI_CLASS)
   2066     return X86_64_INTEGER_CLASS;
   2067 
   2068   /* Rule #5: If one of the classes is X87, X87UP, or COMPLEX_X87 class,
   2069      MEMORY is used.  */
   2070   if (class1 == X86_64_X87_CLASS
   2071       || class1 == X86_64_X87UP_CLASS
   2072       || class1 == X86_64_COMPLEX_X87_CLASS
   2073       || class2 == X86_64_X87_CLASS
   2074       || class2 == X86_64_X87UP_CLASS
   2075       || class2 == X86_64_COMPLEX_X87_CLASS)
   2076     return X86_64_MEMORY_CLASS;
   2077 
   2078   /* Rule #6: Otherwise class SSE is used.  */
   2079   return X86_64_SSE_CLASS;
   2080 }
   2081 
   2082 /* Classify the argument of type TYPE and mode MODE.
   2083    CLASSES will be filled by the register class used to pass each word
   2084    of the operand.  The number of words is returned.  In case the parameter
   2085    should be passed in memory, 0 is returned. As a special case for zero
   2086    sized containers, classes[0] will be NO_CLASS and 1 is returned.
   2087 
   2088    BIT_OFFSET is used internally for handling records and specifies offset
   2089    of the offset in bits modulo 512 to avoid overflow cases.
   2090 
   2091    See the x86-64 PS ABI for details.
   2092 */
   2093 
   2094 static int
   2095 classify_argument (machine_mode mode, const_tree type,
   2096 		   enum x86_64_reg_class classes[MAX_CLASSES], int bit_offset,
   2097 		   int &zero_width_bitfields)
   2098 {
   2099   HOST_WIDE_INT bytes
   2100     = mode == BLKmode ? int_size_in_bytes (type) : (int) GET_MODE_SIZE (mode);
   2101   int words = CEIL (bytes + (bit_offset % 64) / 8, UNITS_PER_WORD);
   2102 
   2103   /* Variable sized entities are always passed/returned in memory.  */
   2104   if (bytes < 0)
   2105     return 0;
   2106 
   2107   if (mode != VOIDmode)
   2108     {
   2109       /* The value of "named" doesn't matter.  */
   2110       function_arg_info arg (const_cast<tree> (type), mode, /*named=*/true);
   2111       if (targetm.calls.must_pass_in_stack (arg))
   2112 	return 0;
   2113     }
   2114 
   2115   if (type && AGGREGATE_TYPE_P (type))
   2116     {
   2117       int i;
   2118       tree field;
   2119       enum x86_64_reg_class subclasses[MAX_CLASSES];
   2120 
   2121       /* On x86-64 we pass structures larger than 64 bytes on the stack.  */
   2122       if (bytes > 64)
   2123 	return 0;
   2124 
   2125       for (i = 0; i < words; i++)
   2126 	classes[i] = X86_64_NO_CLASS;
   2127 
   2128       /* Zero sized arrays or structures are NO_CLASS.  We return 0 to
   2129 	 signalize memory class, so handle it as special case.  */
   2130       if (!words)
   2131 	{
   2132 	  classes[0] = X86_64_NO_CLASS;
   2133 	  return 1;
   2134 	}
   2135 
   2136       /* Classify each field of record and merge classes.  */
   2137       switch (TREE_CODE (type))
   2138 	{
   2139 	case RECORD_TYPE:
   2140 	  /* And now merge the fields of structure.  */
   2141 	  for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
   2142 	    {
   2143 	      if (TREE_CODE (field) == FIELD_DECL)
   2144 		{
   2145 		  int num;
   2146 
   2147 		  if (TREE_TYPE (field) == error_mark_node)
   2148 		    continue;
   2149 
   2150 		  /* Bitfields are always classified as integer.  Handle them
   2151 		     early, since later code would consider them to be
   2152 		     misaligned integers.  */
   2153 		  if (DECL_BIT_FIELD (field))
   2154 		    {
   2155 		      if (integer_zerop (DECL_SIZE (field)))
   2156 			{
   2157 			  if (DECL_FIELD_CXX_ZERO_WIDTH_BIT_FIELD (field))
   2158 			    continue;
   2159 			  if (zero_width_bitfields != 2)
   2160 			    {
   2161 			      zero_width_bitfields = 1;
   2162 			      continue;
   2163 			    }
   2164 			}
   2165 		      for (i = (int_bit_position (field)
   2166 				+ (bit_offset % 64)) / 8 / 8;
   2167 			   i < ((int_bit_position (field) + (bit_offset % 64))
   2168 			        + tree_to_shwi (DECL_SIZE (field))
   2169 				+ 63) / 8 / 8; i++)
   2170 			classes[i]
   2171 			  = merge_classes (X86_64_INTEGER_CLASS, classes[i]);
   2172 		    }
   2173 		  else
   2174 		    {
   2175 		      int pos;
   2176 
   2177 		      type = TREE_TYPE (field);
   2178 
   2179 		      /* Flexible array member is ignored.  */
   2180 		      if (TYPE_MODE (type) == BLKmode
   2181 			  && TREE_CODE (type) == ARRAY_TYPE
   2182 			  && TYPE_SIZE (type) == NULL_TREE
   2183 			  && TYPE_DOMAIN (type) != NULL_TREE
   2184 			  && (TYPE_MAX_VALUE (TYPE_DOMAIN (type))
   2185 			      == NULL_TREE))
   2186 			{
   2187 			  static bool warned;
   2188 
   2189 			  if (!warned && warn_psabi)
   2190 			    {
   2191 			      warned = true;
   2192 			      inform (input_location,
   2193 				      "the ABI of passing struct with"
   2194 				      " a flexible array member has"
   2195 				      " changed in GCC 4.4");
   2196 			    }
   2197 			  continue;
   2198 			}
   2199 		      num = classify_argument (TYPE_MODE (type), type,
   2200 					       subclasses,
   2201 					       (int_bit_position (field)
   2202 						+ bit_offset) % 512,
   2203 					       zero_width_bitfields);
   2204 		      if (!num)
   2205 			return 0;
   2206 		      pos = (int_bit_position (field)
   2207 			     + (bit_offset % 64)) / 8 / 8;
   2208 		      for (i = 0; i < num && (i + pos) < words; i++)
   2209 			classes[i + pos]
   2210 			  = merge_classes (subclasses[i], classes[i + pos]);
   2211 		    }
   2212 		}
   2213 	    }
   2214 	  break;
   2215 
   2216 	case ARRAY_TYPE:
   2217 	  /* Arrays are handled as small records.  */
   2218 	  {
   2219 	    int num;
   2220 	    num = classify_argument (TYPE_MODE (TREE_TYPE (type)),
   2221 				     TREE_TYPE (type), subclasses, bit_offset,
   2222 				     zero_width_bitfields);
   2223 	    if (!num)
   2224 	      return 0;
   2225 
   2226 	    /* The partial classes are now full classes.  */
   2227 	    if (subclasses[0] == X86_64_SSESF_CLASS && bytes != 4)
   2228 	      subclasses[0] = X86_64_SSE_CLASS;
   2229 	    if (subclasses[0] == X86_64_SSEHF_CLASS && bytes != 2)
   2230 	      subclasses[0] = X86_64_SSE_CLASS;
   2231 	    if (subclasses[0] == X86_64_INTEGERSI_CLASS
   2232 		&& !((bit_offset % 64) == 0 && bytes == 4))
   2233 	      subclasses[0] = X86_64_INTEGER_CLASS;
   2234 
   2235 	    for (i = 0; i < words; i++)
   2236 	      classes[i] = subclasses[i % num];
   2237 
   2238 	    break;
   2239 	  }
   2240 	case UNION_TYPE:
   2241 	case QUAL_UNION_TYPE:
   2242 	  /* Unions are similar to RECORD_TYPE but offset is always 0.
   2243 	     */
   2244 	  for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
   2245 	    {
   2246 	      if (TREE_CODE (field) == FIELD_DECL)
   2247 		{
   2248 		  int num;
   2249 
   2250 		  if (TREE_TYPE (field) == error_mark_node)
   2251 		    continue;
   2252 
   2253 		  num = classify_argument (TYPE_MODE (TREE_TYPE (field)),
   2254 					   TREE_TYPE (field), subclasses,
   2255 					   bit_offset, zero_width_bitfields);
   2256 		  if (!num)
   2257 		    return 0;
   2258 		  for (i = 0; i < num && i < words; i++)
   2259 		    classes[i] = merge_classes (subclasses[i], classes[i]);
   2260 		}
   2261 	    }
   2262 	  break;
   2263 
   2264 	default:
   2265 	  gcc_unreachable ();
   2266 	}
   2267 
   2268       if (words > 2)
   2269 	{
   2270 	  /* When size > 16 bytes, if the first one isn't
   2271 	     X86_64_SSE_CLASS or any other ones aren't
   2272 	     X86_64_SSEUP_CLASS, everything should be passed in
   2273 	     memory.  */
   2274 	  if (classes[0] != X86_64_SSE_CLASS)
   2275 	    return 0;
   2276 
   2277 	  for (i = 1; i < words; i++)
   2278 	    if (classes[i] != X86_64_SSEUP_CLASS)
   2279 	      return 0;
   2280 	}
   2281 
   2282       /* Final merger cleanup.  */
   2283       for (i = 0; i < words; i++)
   2284 	{
   2285 	  /* If one class is MEMORY, everything should be passed in
   2286 	     memory.  */
   2287 	  if (classes[i] == X86_64_MEMORY_CLASS)
   2288 	    return 0;
   2289 
   2290 	  /* The X86_64_SSEUP_CLASS should be always preceded by
   2291 	     X86_64_SSE_CLASS or X86_64_SSEUP_CLASS.  */
   2292 	  if (classes[i] == X86_64_SSEUP_CLASS
   2293 	      && classes[i - 1] != X86_64_SSE_CLASS
   2294 	      && classes[i - 1] != X86_64_SSEUP_CLASS)
   2295 	    {
   2296 	      /* The first one should never be X86_64_SSEUP_CLASS.  */
   2297 	      gcc_assert (i != 0);
   2298 	      classes[i] = X86_64_SSE_CLASS;
   2299 	    }
   2300 
   2301 	  /* If X86_64_X87UP_CLASS isn't preceded by X86_64_X87_CLASS,
   2302 	     everything should be passed in memory.  */
   2303 	  if (classes[i] == X86_64_X87UP_CLASS
   2304 	      && (classes[i - 1] != X86_64_X87_CLASS))
   2305 	    {
   2306 	      static bool warned;
   2307 
   2308 	      /* The first one should never be X86_64_X87UP_CLASS.  */
   2309 	      gcc_assert (i != 0);
   2310 	      if (!warned && warn_psabi)
   2311 		{
   2312 		  warned = true;
   2313 		  inform (input_location,
   2314 			  "the ABI of passing union with %<long double%>"
   2315 			  " has changed in GCC 4.4");
   2316 		}
   2317 	      return 0;
   2318 	    }
   2319 	}
   2320       return words;
   2321     }
   2322 
   2323   /* Compute alignment needed.  We align all types to natural boundaries with
   2324      exception of XFmode that is aligned to 64bits.  */
   2325   if (mode != VOIDmode && mode != BLKmode)
   2326     {
   2327       int mode_alignment = GET_MODE_BITSIZE (mode);
   2328 
   2329       if (mode == XFmode)
   2330 	mode_alignment = 128;
   2331       else if (mode == XCmode)
   2332 	mode_alignment = 256;
   2333       if (COMPLEX_MODE_P (mode))
   2334 	mode_alignment /= 2;
   2335       /* Misaligned fields are always returned in memory.  */
   2336       if (bit_offset % mode_alignment)
   2337 	return 0;
   2338     }
   2339 
   2340   /* for V1xx modes, just use the base mode */
   2341   if (VECTOR_MODE_P (mode) && mode != V1DImode && mode != V1TImode
   2342       && GET_MODE_UNIT_SIZE (mode) == bytes)
   2343     mode = GET_MODE_INNER (mode);
   2344 
   2345   /* Classification of atomic types.  */
   2346   switch (mode)
   2347     {
   2348     case E_SDmode:
   2349     case E_DDmode:
   2350       classes[0] = X86_64_SSE_CLASS;
   2351       return 1;
   2352     case E_TDmode:
   2353       classes[0] = X86_64_SSE_CLASS;
   2354       classes[1] = X86_64_SSEUP_CLASS;
   2355       return 2;
   2356     case E_DImode:
   2357     case E_SImode:
   2358     case E_HImode:
   2359     case E_QImode:
   2360     case E_CSImode:
   2361     case E_CHImode:
   2362     case E_CQImode:
   2363       {
   2364 	int size = bit_offset + (int) GET_MODE_BITSIZE (mode);
   2365 
   2366 	/* Analyze last 128 bits only.  */
   2367 	size = (size - 1) & 0x7f;
   2368 
   2369 	if (size < 32)
   2370 	  {
   2371 	    classes[0] = X86_64_INTEGERSI_CLASS;
   2372 	    return 1;
   2373 	  }
   2374 	else if (size < 64)
   2375 	  {
   2376 	    classes[0] = X86_64_INTEGER_CLASS;
   2377 	    return 1;
   2378 	  }
   2379 	else if (size < 64+32)
   2380 	  {
   2381 	    classes[0] = X86_64_INTEGER_CLASS;
   2382 	    classes[1] = X86_64_INTEGERSI_CLASS;
   2383 	    return 2;
   2384 	  }
   2385 	else if (size < 64+64)
   2386 	  {
   2387 	    classes[0] = classes[1] = X86_64_INTEGER_CLASS;
   2388 	    return 2;
   2389 	  }
   2390 	else
   2391 	  gcc_unreachable ();
   2392       }
   2393     case E_CDImode:
   2394     case E_TImode:
   2395       classes[0] = classes[1] = X86_64_INTEGER_CLASS;
   2396       return 2;
   2397     case E_COImode:
   2398     case E_OImode:
   2399       /* OImode shouldn't be used directly.  */
   2400       gcc_unreachable ();
   2401     case E_CTImode:
   2402       return 0;
   2403     case E_HFmode:
   2404       if (!(bit_offset % 64))
   2405 	classes[0] = X86_64_SSEHF_CLASS;
   2406       else
   2407 	classes[0] = X86_64_SSE_CLASS;
   2408       return 1;
   2409     case E_SFmode:
   2410       if (!(bit_offset % 64))
   2411 	classes[0] = X86_64_SSESF_CLASS;
   2412       else
   2413 	classes[0] = X86_64_SSE_CLASS;
   2414       return 1;
   2415     case E_DFmode:
   2416       classes[0] = X86_64_SSEDF_CLASS;
   2417       return 1;
   2418     case E_XFmode:
   2419       classes[0] = X86_64_X87_CLASS;
   2420       classes[1] = X86_64_X87UP_CLASS;
   2421       return 2;
   2422     case E_TFmode:
   2423       classes[0] = X86_64_SSE_CLASS;
   2424       classes[1] = X86_64_SSEUP_CLASS;
   2425       return 2;
   2426     case E_HCmode:
   2427       classes[0] = X86_64_SSE_CLASS;
   2428       if (!(bit_offset % 64))
   2429 	return 1;
   2430       else
   2431 	{
   2432 	  classes[1] = X86_64_SSEHF_CLASS;
   2433 	  return 2;
   2434 	}
   2435     case E_SCmode:
   2436       classes[0] = X86_64_SSE_CLASS;
   2437       if (!(bit_offset % 64))
   2438 	return 1;
   2439       else
   2440 	{
   2441 	  static bool warned;
   2442 
   2443 	  if (!warned && warn_psabi)
   2444 	    {
   2445 	      warned = true;
   2446 	      inform (input_location,
   2447 		      "the ABI of passing structure with %<complex float%>"
   2448 		      " member has changed in GCC 4.4");
   2449 	    }
   2450 	  classes[1] = X86_64_SSESF_CLASS;
   2451 	  return 2;
   2452 	}
   2453     case E_DCmode:
   2454       classes[0] = X86_64_SSEDF_CLASS;
   2455       classes[1] = X86_64_SSEDF_CLASS;
   2456       return 2;
   2457     case E_XCmode:
   2458       classes[0] = X86_64_COMPLEX_X87_CLASS;
   2459       return 1;
   2460     case E_TCmode:
   2461       /* This modes is larger than 16 bytes.  */
   2462       return 0;
   2463     case E_V8SFmode:
   2464     case E_V8SImode:
   2465     case E_V32QImode:
   2466     case E_V16HFmode:
   2467     case E_V16HImode:
   2468     case E_V4DFmode:
   2469     case E_V4DImode:
   2470       classes[0] = X86_64_SSE_CLASS;
   2471       classes[1] = X86_64_SSEUP_CLASS;
   2472       classes[2] = X86_64_SSEUP_CLASS;
   2473       classes[3] = X86_64_SSEUP_CLASS;
   2474       return 4;
   2475     case E_V8DFmode:
   2476     case E_V16SFmode:
   2477     case E_V32HFmode:
   2478     case E_V8DImode:
   2479     case E_V16SImode:
   2480     case E_V32HImode:
   2481     case E_V64QImode:
   2482       classes[0] = X86_64_SSE_CLASS;
   2483       classes[1] = X86_64_SSEUP_CLASS;
   2484       classes[2] = X86_64_SSEUP_CLASS;
   2485       classes[3] = X86_64_SSEUP_CLASS;
   2486       classes[4] = X86_64_SSEUP_CLASS;
   2487       classes[5] = X86_64_SSEUP_CLASS;
   2488       classes[6] = X86_64_SSEUP_CLASS;
   2489       classes[7] = X86_64_SSEUP_CLASS;
   2490       return 8;
   2491     case E_V4SFmode:
   2492     case E_V4SImode:
   2493     case E_V16QImode:
   2494     case E_V8HImode:
   2495     case E_V8HFmode:
   2496     case E_V2DFmode:
   2497     case E_V2DImode:
   2498       classes[0] = X86_64_SSE_CLASS;
   2499       classes[1] = X86_64_SSEUP_CLASS;
   2500       return 2;
   2501     case E_V1TImode:
   2502     case E_V1DImode:
   2503     case E_V2SFmode:
   2504     case E_V2SImode:
   2505     case E_V4HImode:
   2506     case E_V4HFmode:
   2507     case E_V2HFmode:
   2508     case E_V8QImode:
   2509       classes[0] = X86_64_SSE_CLASS;
   2510       return 1;
   2511     case E_BLKmode:
   2512     case E_VOIDmode:
   2513       return 0;
   2514     default:
   2515       gcc_assert (VECTOR_MODE_P (mode));
   2516 
   2517       if (bytes > 16)
   2518 	return 0;
   2519 
   2520       gcc_assert (GET_MODE_CLASS (GET_MODE_INNER (mode)) == MODE_INT);
   2521 
   2522       if (bit_offset + GET_MODE_BITSIZE (mode) <= 32)
   2523 	classes[0] = X86_64_INTEGERSI_CLASS;
   2524       else
   2525 	classes[0] = X86_64_INTEGER_CLASS;
   2526       classes[1] = X86_64_INTEGER_CLASS;
   2527       return 1 + (bytes > 8);
   2528     }
   2529 }
   2530 
   2531 /* Wrapper around classify_argument with the extra zero_width_bitfields
   2532    argument, to diagnose GCC 12.1 ABI differences for C.  */
   2533 
   2534 static int
   2535 classify_argument (machine_mode mode, const_tree type,
   2536 		   enum x86_64_reg_class classes[MAX_CLASSES], int bit_offset)
   2537 {
   2538   int zero_width_bitfields = 0;
   2539   static bool warned = false;
   2540   int n = classify_argument (mode, type, classes, bit_offset,
   2541 			     zero_width_bitfields);
   2542   if (!zero_width_bitfields || warned || !warn_psabi)
   2543     return n;
   2544   enum x86_64_reg_class alt_classes[MAX_CLASSES];
   2545   zero_width_bitfields = 2;
   2546   if (classify_argument (mode, type, alt_classes, bit_offset,
   2547 			 zero_width_bitfields) != n)
   2548     zero_width_bitfields = 3;
   2549   else
   2550     for (int i = 0; i < n; i++)
   2551       if (classes[i] != alt_classes[i])
   2552 	{
   2553 	  zero_width_bitfields = 3;
   2554 	  break;
   2555 	}
   2556   if (zero_width_bitfields == 3)
   2557     {
   2558       warned = true;
   2559       const char *url
   2560 	= CHANGES_ROOT_URL "gcc-12/changes.html#zero_width_bitfields";
   2561 
   2562       inform (input_location,
   2563 	      "the ABI of passing C structures with zero-width bit-fields"
   2564 	      " has changed in GCC %{12.1%}", url);
   2565     }
   2566   return n;
   2567 }
   2568 
   2569 /* Examine the argument and return set number of register required in each
   2570    class.  Return true iff parameter should be passed in memory.  */
   2571 
   2572 static bool
   2573 examine_argument (machine_mode mode, const_tree type, int in_return,
   2574 		  int *int_nregs, int *sse_nregs)
   2575 {
   2576   enum x86_64_reg_class regclass[MAX_CLASSES];
   2577   int n = classify_argument (mode, type, regclass, 0);
   2578 
   2579   *int_nregs = 0;
   2580   *sse_nregs = 0;
   2581 
   2582   if (!n)
   2583     return true;
   2584   for (n--; n >= 0; n--)
   2585     switch (regclass[n])
   2586       {
   2587       case X86_64_INTEGER_CLASS:
   2588       case X86_64_INTEGERSI_CLASS:
   2589 	(*int_nregs)++;
   2590 	break;
   2591       case X86_64_SSE_CLASS:
   2592       case X86_64_SSEHF_CLASS:
   2593       case X86_64_SSESF_CLASS:
   2594       case X86_64_SSEDF_CLASS:
   2595 	(*sse_nregs)++;
   2596 	break;
   2597       case X86_64_NO_CLASS:
   2598       case X86_64_SSEUP_CLASS:
   2599 	break;
   2600       case X86_64_X87_CLASS:
   2601       case X86_64_X87UP_CLASS:
   2602       case X86_64_COMPLEX_X87_CLASS:
   2603 	if (!in_return)
   2604 	  return true;
   2605 	break;
   2606       case X86_64_MEMORY_CLASS:
   2607 	gcc_unreachable ();
   2608       }
   2609 
   2610   return false;
   2611 }
   2612 
   2613 /* Construct container for the argument used by GCC interface.  See
   2614    FUNCTION_ARG for the detailed description.  */
   2615 
   2616 static rtx
   2617 construct_container (machine_mode mode, machine_mode orig_mode,
   2618 		     const_tree type, int in_return, int nintregs, int nsseregs,
   2619 		     const int *intreg, int sse_regno)
   2620 {
   2621   /* The following variables hold the static issued_error state.  */
   2622   static bool issued_sse_arg_error;
   2623   static bool issued_sse_ret_error;
   2624   static bool issued_x87_ret_error;
   2625 
   2626   machine_mode tmpmode;
   2627   int bytes
   2628     = mode == BLKmode ? int_size_in_bytes (type) : (int) GET_MODE_SIZE (mode);
   2629   enum x86_64_reg_class regclass[MAX_CLASSES];
   2630   int n;
   2631   int i;
   2632   int nexps = 0;
   2633   int needed_sseregs, needed_intregs;
   2634   rtx exp[MAX_CLASSES];
   2635   rtx ret;
   2636 
   2637   n = classify_argument (mode, type, regclass, 0);
   2638   if (!n)
   2639     return NULL;
   2640   if (examine_argument (mode, type, in_return, &needed_intregs,
   2641 			&needed_sseregs))
   2642     return NULL;
   2643   if (needed_intregs > nintregs || needed_sseregs > nsseregs)
   2644     return NULL;
   2645 
   2646   /* We allowed the user to turn off SSE for kernel mode.  Don't crash if
   2647      some less clueful developer tries to use floating-point anyway.  */
   2648   if (needed_sseregs && !TARGET_SSE)
   2649     {
   2650       /* Return early if we shouldn't raise an error for invalid
   2651 	 calls.  */
   2652       if (cfun != NULL && cfun->machine->silent_p)
   2653 	return NULL;
   2654       if (in_return)
   2655 	{
   2656 	  if (!issued_sse_ret_error)
   2657 	    {
   2658 	      error ("SSE register return with SSE disabled");
   2659 	      issued_sse_ret_error = true;
   2660 	    }
   2661 	}
   2662       else if (!issued_sse_arg_error)
   2663 	{
   2664 	  error ("SSE register argument with SSE disabled");
   2665 	  issued_sse_arg_error = true;
   2666 	}
   2667       return NULL;
   2668     }
   2669 
   2670   /* Likewise, error if the ABI requires us to return values in the
   2671      x87 registers and the user specified -mno-80387.  */
   2672   if (!TARGET_FLOAT_RETURNS_IN_80387 && in_return)
   2673     for (i = 0; i < n; i++)
   2674       if (regclass[i] == X86_64_X87_CLASS
   2675 	  || regclass[i] == X86_64_X87UP_CLASS
   2676 	  || regclass[i] == X86_64_COMPLEX_X87_CLASS)
   2677 	{
   2678 	  /* Return early if we shouldn't raise an error for invalid
   2679 	     calls.  */
   2680 	  if (cfun != NULL && cfun->machine->silent_p)
   2681 	    return NULL;
   2682 	  if (!issued_x87_ret_error)
   2683 	    {
   2684 	      error ("x87 register return with x87 disabled");
   2685 	      issued_x87_ret_error = true;
   2686 	    }
   2687 	  return NULL;
   2688 	}
   2689 
   2690   /* First construct simple cases.  Avoid SCmode, since we want to use
   2691      single register to pass this type.  */
   2692   if (n == 1 && mode != SCmode && mode != HCmode)
   2693     switch (regclass[0])
   2694       {
   2695       case X86_64_INTEGER_CLASS:
   2696       case X86_64_INTEGERSI_CLASS:
   2697 	return gen_rtx_REG (mode, intreg[0]);
   2698       case X86_64_SSE_CLASS:
   2699       case X86_64_SSEHF_CLASS:
   2700       case X86_64_SSESF_CLASS:
   2701       case X86_64_SSEDF_CLASS:
   2702 	if (mode != BLKmode)
   2703 	  return gen_reg_or_parallel (mode, orig_mode,
   2704 				      GET_SSE_REGNO (sse_regno));
   2705 	break;
   2706       case X86_64_X87_CLASS:
   2707       case X86_64_COMPLEX_X87_CLASS:
   2708 	return gen_rtx_REG (mode, FIRST_STACK_REG);
   2709       case X86_64_NO_CLASS:
   2710 	/* Zero sized array, struct or class.  */
   2711 	return NULL;
   2712       default:
   2713 	gcc_unreachable ();
   2714       }
   2715   if (n == 2
   2716       && regclass[0] == X86_64_SSE_CLASS
   2717       && regclass[1] == X86_64_SSEUP_CLASS
   2718       && mode != BLKmode)
   2719     return gen_reg_or_parallel (mode, orig_mode,
   2720 				GET_SSE_REGNO (sse_regno));
   2721   if (n == 4
   2722       && regclass[0] == X86_64_SSE_CLASS
   2723       && regclass[1] == X86_64_SSEUP_CLASS
   2724       && regclass[2] == X86_64_SSEUP_CLASS
   2725       && regclass[3] == X86_64_SSEUP_CLASS
   2726       && mode != BLKmode)
   2727     return gen_reg_or_parallel (mode, orig_mode,
   2728 				GET_SSE_REGNO (sse_regno));
   2729   if (n == 8
   2730       && regclass[0] == X86_64_SSE_CLASS
   2731       && regclass[1] == X86_64_SSEUP_CLASS
   2732       && regclass[2] == X86_64_SSEUP_CLASS
   2733       && regclass[3] == X86_64_SSEUP_CLASS
   2734       && regclass[4] == X86_64_SSEUP_CLASS
   2735       && regclass[5] == X86_64_SSEUP_CLASS
   2736       && regclass[6] == X86_64_SSEUP_CLASS
   2737       && regclass[7] == X86_64_SSEUP_CLASS
   2738       && mode != BLKmode)
   2739     return gen_reg_or_parallel (mode, orig_mode,
   2740 				GET_SSE_REGNO (sse_regno));
   2741   if (n == 2
   2742       && regclass[0] == X86_64_X87_CLASS
   2743       && regclass[1] == X86_64_X87UP_CLASS)
   2744     return gen_rtx_REG (XFmode, FIRST_STACK_REG);
   2745 
   2746   if (n == 2
   2747       && regclass[0] == X86_64_INTEGER_CLASS
   2748       && regclass[1] == X86_64_INTEGER_CLASS
   2749       && (mode == CDImode || mode == TImode || mode == BLKmode)
   2750       && intreg[0] + 1 == intreg[1])
   2751     {
   2752       if (mode == BLKmode)
   2753 	{
   2754 	  /* Use TImode for BLKmode values in 2 integer registers.  */
   2755 	  exp[0] = gen_rtx_EXPR_LIST (VOIDmode,
   2756 				      gen_rtx_REG (TImode, intreg[0]),
   2757 				      GEN_INT (0));
   2758 	  ret = gen_rtx_PARALLEL (mode, rtvec_alloc (1));
   2759 	  XVECEXP (ret, 0, 0) = exp[0];
   2760 	  return ret;
   2761 	}
   2762       else
   2763 	return gen_rtx_REG (mode, intreg[0]);
   2764     }
   2765 
   2766   /* Otherwise figure out the entries of the PARALLEL.  */
   2767   for (i = 0; i < n; i++)
   2768     {
   2769       int pos;
   2770 
   2771       switch (regclass[i])
   2772         {
   2773 	  case X86_64_NO_CLASS:
   2774 	    break;
   2775 	  case X86_64_INTEGER_CLASS:
   2776 	  case X86_64_INTEGERSI_CLASS:
   2777 	    /* Merge TImodes on aligned occasions here too.  */
   2778 	    if (i * 8 + 8 > bytes)
   2779 	      {
   2780 		unsigned int tmpbits = (bytes - i * 8) * BITS_PER_UNIT;
   2781 		if (!int_mode_for_size (tmpbits, 0).exists (&tmpmode))
   2782 		  /* We've requested 24 bytes we
   2783 		     don't have mode for.  Use DImode.  */
   2784 		  tmpmode = DImode;
   2785 	      }
   2786 	    else if (regclass[i] == X86_64_INTEGERSI_CLASS)
   2787 	      tmpmode = SImode;
   2788 	    else
   2789 	      tmpmode = DImode;
   2790 	    exp [nexps++]
   2791 	      = gen_rtx_EXPR_LIST (VOIDmode,
   2792 				   gen_rtx_REG (tmpmode, *intreg),
   2793 				   GEN_INT (i*8));
   2794 	    intreg++;
   2795 	    break;
   2796 	  case X86_64_SSEHF_CLASS:
   2797 	    exp [nexps++]
   2798 	      = gen_rtx_EXPR_LIST (VOIDmode,
   2799 				   gen_rtx_REG (HFmode,
   2800 						GET_SSE_REGNO (sse_regno)),
   2801 				   GEN_INT (i*8));
   2802 	    sse_regno++;
   2803 	    break;
   2804 	  case X86_64_SSESF_CLASS:
   2805 	    exp [nexps++]
   2806 	      = gen_rtx_EXPR_LIST (VOIDmode,
   2807 				   gen_rtx_REG (SFmode,
   2808 						GET_SSE_REGNO (sse_regno)),
   2809 				   GEN_INT (i*8));
   2810 	    sse_regno++;
   2811 	    break;
   2812 	  case X86_64_SSEDF_CLASS:
   2813 	    exp [nexps++]
   2814 	      = gen_rtx_EXPR_LIST (VOIDmode,
   2815 				   gen_rtx_REG (DFmode,
   2816 						GET_SSE_REGNO (sse_regno)),
   2817 				   GEN_INT (i*8));
   2818 	    sse_regno++;
   2819 	    break;
   2820 	  case X86_64_SSE_CLASS:
   2821 	    pos = i;
   2822 	    switch (n)
   2823 	      {
   2824 	      case 1:
   2825 		tmpmode = DImode;
   2826 		break;
   2827 	      case 2:
   2828 		if (i == 0 && regclass[1] == X86_64_SSEUP_CLASS)
   2829 		  {
   2830 		    tmpmode = TImode;
   2831 		    i++;
   2832 		  }
   2833 		else
   2834 		  tmpmode = DImode;
   2835 		break;
   2836 	      case 4:
   2837 		gcc_assert (i == 0
   2838 			    && regclass[1] == X86_64_SSEUP_CLASS
   2839 			    && regclass[2] == X86_64_SSEUP_CLASS
   2840 			    && regclass[3] == X86_64_SSEUP_CLASS);
   2841 		tmpmode = OImode;
   2842 		i += 3;
   2843 		break;
   2844 	      case 8:
   2845 		gcc_assert (i == 0
   2846 			    && regclass[1] == X86_64_SSEUP_CLASS
   2847 			    && regclass[2] == X86_64_SSEUP_CLASS
   2848 			    && regclass[3] == X86_64_SSEUP_CLASS
   2849 			    && regclass[4] == X86_64_SSEUP_CLASS
   2850 			    && regclass[5] == X86_64_SSEUP_CLASS
   2851 			    && regclass[6] == X86_64_SSEUP_CLASS
   2852 			    && regclass[7] == X86_64_SSEUP_CLASS);
   2853 		tmpmode = XImode;
   2854 		i += 7;
   2855 		break;
   2856 	      default:
   2857 		gcc_unreachable ();
   2858 	      }
   2859 	    exp [nexps++]
   2860 	      = gen_rtx_EXPR_LIST (VOIDmode,
   2861 				   gen_rtx_REG (tmpmode,
   2862 						GET_SSE_REGNO (sse_regno)),
   2863 				   GEN_INT (pos*8));
   2864 	    sse_regno++;
   2865 	    break;
   2866 	  default:
   2867 	    gcc_unreachable ();
   2868 	}
   2869     }
   2870 
   2871   /* Empty aligned struct, union or class.  */
   2872   if (nexps == 0)
   2873     return NULL;
   2874 
   2875   ret =  gen_rtx_PARALLEL (mode, rtvec_alloc (nexps));
   2876   for (i = 0; i < nexps; i++)
   2877     XVECEXP (ret, 0, i) = exp [i];
   2878   return ret;
   2879 }
   2880 
   2881 /* Update the data in CUM to advance over an argument of mode MODE
   2882    and data type TYPE.  (TYPE is null for libcalls where that information
   2883    may not be available.)
   2884 
   2885    Return a number of integer regsiters advanced over.  */
   2886 
   2887 static int
   2888 function_arg_advance_32 (CUMULATIVE_ARGS *cum, machine_mode mode,
   2889 			 const_tree type, HOST_WIDE_INT bytes,
   2890 			 HOST_WIDE_INT words)
   2891 {
   2892   int res = 0;
   2893   bool error_p = false;
   2894 
   2895   if (TARGET_IAMCU)
   2896     {
   2897       /* Intel MCU psABI passes scalars and aggregates no larger than 8
   2898 	 bytes in registers.  */
   2899       if (!VECTOR_MODE_P (mode) && bytes <= 8)
   2900 	goto pass_in_reg;
   2901       return res;
   2902     }
   2903 
   2904   switch (mode)
   2905     {
   2906     default:
   2907       break;
   2908 
   2909     case E_BLKmode:
   2910       if (bytes < 0)
   2911 	break;
   2912       /* FALLTHRU */
   2913 
   2914     case E_DImode:
   2915     case E_SImode:
   2916     case E_HImode:
   2917     case E_QImode:
   2918 pass_in_reg:
   2919       cum->words += words;
   2920       cum->nregs -= words;
   2921       cum->regno += words;
   2922       if (cum->nregs >= 0)
   2923 	res = words;
   2924       if (cum->nregs <= 0)
   2925 	{
   2926 	  cum->nregs = 0;
   2927 	  cfun->machine->arg_reg_available = false;
   2928 	  cum->regno = 0;
   2929 	}
   2930       break;
   2931 
   2932     case E_OImode:
   2933       /* OImode shouldn't be used directly.  */
   2934       gcc_unreachable ();
   2935 
   2936     case E_DFmode:
   2937       if (cum->float_in_sse == -1)
   2938 	error_p = true;
   2939       if (cum->float_in_sse < 2)
   2940 	break;
   2941       /* FALLTHRU */
   2942     case E_SFmode:
   2943       if (cum->float_in_sse == -1)
   2944 	error_p = true;
   2945       if (cum->float_in_sse < 1)
   2946 	break;
   2947       /* FALLTHRU */
   2948 
   2949     case E_V16HFmode:
   2950     case E_V8SFmode:
   2951     case E_V8SImode:
   2952     case E_V64QImode:
   2953     case E_V32HImode:
   2954     case E_V16SImode:
   2955     case E_V8DImode:
   2956     case E_V32HFmode:
   2957     case E_V16SFmode:
   2958     case E_V8DFmode:
   2959     case E_V32QImode:
   2960     case E_V16HImode:
   2961     case E_V4DFmode:
   2962     case E_V4DImode:
   2963     case E_TImode:
   2964     case E_V16QImode:
   2965     case E_V8HImode:
   2966     case E_V4SImode:
   2967     case E_V2DImode:
   2968     case E_V8HFmode:
   2969     case E_V4SFmode:
   2970     case E_V2DFmode:
   2971       if (!type || !AGGREGATE_TYPE_P (type))
   2972 	{
   2973 	  cum->sse_words += words;
   2974 	  cum->sse_nregs -= 1;
   2975 	  cum->sse_regno += 1;
   2976 	  if (cum->sse_nregs <= 0)
   2977 	    {
   2978 	      cum->sse_nregs = 0;
   2979 	      cum->sse_regno = 0;
   2980 	    }
   2981 	}
   2982       break;
   2983 
   2984     case E_V8QImode:
   2985     case E_V4HImode:
   2986     case E_V4HFmode:
   2987     case E_V2SImode:
   2988     case E_V2SFmode:
   2989     case E_V1TImode:
   2990     case E_V1DImode:
   2991       if (!type || !AGGREGATE_TYPE_P (type))
   2992 	{
   2993 	  cum->mmx_words += words;
   2994 	  cum->mmx_nregs -= 1;
   2995 	  cum->mmx_regno += 1;
   2996 	  if (cum->mmx_nregs <= 0)
   2997 	    {
   2998 	      cum->mmx_nregs = 0;
   2999 	      cum->mmx_regno = 0;
   3000 	    }
   3001 	}
   3002       break;
   3003     }
   3004   if (error_p)
   3005     {
   3006       cum->float_in_sse = 0;
   3007       error ("calling %qD with SSE calling convention without "
   3008 	     "SSE/SSE2 enabled", cum->decl);
   3009       sorry ("this is a GCC bug that can be worked around by adding "
   3010 	     "attribute used to function called");
   3011     }
   3012 
   3013   return res;
   3014 }
   3015 
   3016 static int
   3017 function_arg_advance_64 (CUMULATIVE_ARGS *cum, machine_mode mode,
   3018 			 const_tree type, HOST_WIDE_INT words, bool named)
   3019 {
   3020   int int_nregs, sse_nregs;
   3021 
   3022   /* Unnamed 512 and 256bit vector mode parameters are passed on stack.  */
   3023   if (!named && (VALID_AVX512F_REG_MODE (mode)
   3024 		 || VALID_AVX256_REG_MODE (mode)))
   3025     return 0;
   3026 
   3027   if (!examine_argument (mode, type, 0, &int_nregs, &sse_nregs)
   3028       && sse_nregs <= cum->sse_nregs && int_nregs <= cum->nregs)
   3029     {
   3030       cum->nregs -= int_nregs;
   3031       cum->sse_nregs -= sse_nregs;
   3032       cum->regno += int_nregs;
   3033       cum->sse_regno += sse_nregs;
   3034       return int_nregs;
   3035     }
   3036   else
   3037     {
   3038       int align = ix86_function_arg_boundary (mode, type) / BITS_PER_WORD;
   3039       cum->words = ROUND_UP (cum->words, align);
   3040       cum->words += words;
   3041       return 0;
   3042     }
   3043 }
   3044 
   3045 static int
   3046 function_arg_advance_ms_64 (CUMULATIVE_ARGS *cum, HOST_WIDE_INT bytes,
   3047 			    HOST_WIDE_INT words)
   3048 {
   3049   /* Otherwise, this should be passed indirect.  */
   3050   gcc_assert (bytes == 1 || bytes == 2 || bytes == 4 || bytes == 8);
   3051 
   3052   cum->words += words;
   3053   if (cum->nregs > 0)
   3054     {
   3055       cum->nregs -= 1;
   3056       cum->regno += 1;
   3057       return 1;
   3058     }
   3059   return 0;
   3060 }
   3061 
   3062 /* Update the data in CUM to advance over argument ARG.  */
   3063 
   3064 static void
   3065 ix86_function_arg_advance (cumulative_args_t cum_v,
   3066 			   const function_arg_info &arg)
   3067 {
   3068   CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
   3069   machine_mode mode = arg.mode;
   3070   HOST_WIDE_INT bytes, words;
   3071   int nregs;
   3072 
   3073   /* The argument of interrupt handler is a special case and is
   3074      handled in ix86_function_arg.  */
   3075   if (!cum->caller && cfun->machine->func_type != TYPE_NORMAL)
   3076     return;
   3077 
   3078   bytes = arg.promoted_size_in_bytes ();
   3079   words = CEIL (bytes, UNITS_PER_WORD);
   3080 
   3081   if (arg.type)
   3082     mode = type_natural_mode (arg.type, NULL, false);
   3083 
   3084   if (TARGET_64BIT)
   3085     {
   3086       enum calling_abi call_abi = cum ? cum->call_abi : ix86_abi;
   3087 
   3088       if (call_abi == MS_ABI)
   3089 	nregs = function_arg_advance_ms_64 (cum, bytes, words);
   3090       else
   3091 	nregs = function_arg_advance_64 (cum, mode, arg.type, words,
   3092 					 arg.named);
   3093     }
   3094   else
   3095     nregs = function_arg_advance_32 (cum, mode, arg.type, bytes, words);
   3096 
   3097   if (!nregs)
   3098     {
   3099       /* Track if there are outgoing arguments on stack.  */
   3100       if (cum->caller)
   3101 	cfun->machine->outgoing_args_on_stack = true;
   3102     }
   3103 }
   3104 
   3105 /* Define where to put the arguments to a function.
   3106    Value is zero to push the argument on the stack,
   3107    or a hard register in which to store the argument.
   3108 
   3109    MODE is the argument's machine mode.
   3110    TYPE is the data type of the argument (as a tree).
   3111     This is null for libcalls where that information may
   3112     not be available.
   3113    CUM is a variable of type CUMULATIVE_ARGS which gives info about
   3114     the preceding args and about the function being called.
   3115    NAMED is nonzero if this argument is a named parameter
   3116     (otherwise it is an extra parameter matching an ellipsis).  */
   3117 
   3118 static rtx
   3119 function_arg_32 (CUMULATIVE_ARGS *cum, machine_mode mode,
   3120 		 machine_mode orig_mode, const_tree type,
   3121 		 HOST_WIDE_INT bytes, HOST_WIDE_INT words)
   3122 {
   3123   bool error_p = false;
   3124 
   3125   /* Avoid the AL settings for the Unix64 ABI.  */
   3126   if (mode == VOIDmode)
   3127     return constm1_rtx;
   3128 
   3129   if (TARGET_IAMCU)
   3130     {
   3131       /* Intel MCU psABI passes scalars and aggregates no larger than 8
   3132 	 bytes in registers.  */
   3133       if (!VECTOR_MODE_P (mode) && bytes <= 8)
   3134 	goto pass_in_reg;
   3135       return NULL_RTX;
   3136     }
   3137 
   3138   switch (mode)
   3139     {
   3140     default:
   3141       break;
   3142 
   3143     case E_BLKmode:
   3144       if (bytes < 0)
   3145 	break;
   3146       /* FALLTHRU */
   3147     case E_DImode:
   3148     case E_SImode:
   3149     case E_HImode:
   3150     case E_QImode:
   3151 pass_in_reg:
   3152       if (words <= cum->nregs)
   3153 	{
   3154 	  int regno = cum->regno;
   3155 
   3156 	  /* Fastcall allocates the first two DWORD (SImode) or
   3157             smaller arguments to ECX and EDX if it isn't an
   3158             aggregate type .  */
   3159 	  if (cum->fastcall)
   3160 	    {
   3161 	      if (mode == BLKmode
   3162 		  || mode == DImode
   3163 		  || (type && AGGREGATE_TYPE_P (type)))
   3164 	        break;
   3165 
   3166 	      /* ECX not EAX is the first allocated register.  */
   3167 	      if (regno == AX_REG)
   3168 		regno = CX_REG;
   3169 	    }
   3170 	  return gen_rtx_REG (mode, regno);
   3171 	}
   3172       break;
   3173 
   3174     case E_DFmode:
   3175       if (cum->float_in_sse == -1)
   3176 	error_p = true;
   3177       if (cum->float_in_sse < 2)
   3178 	break;
   3179       /* FALLTHRU */
   3180     case E_SFmode:
   3181       if (cum->float_in_sse == -1)
   3182 	error_p = true;
   3183       if (cum->float_in_sse < 1)
   3184 	break;
   3185       /* FALLTHRU */
   3186     case E_TImode:
   3187       /* In 32bit, we pass TImode in xmm registers.  */
   3188     case E_V16QImode:
   3189     case E_V8HImode:
   3190     case E_V4SImode:
   3191     case E_V2DImode:
   3192     case E_V8HFmode:
   3193     case E_V4SFmode:
   3194     case E_V2DFmode:
   3195       if (!type || !AGGREGATE_TYPE_P (type))
   3196 	{
   3197 	  if (cum->sse_nregs)
   3198 	    return gen_reg_or_parallel (mode, orig_mode,
   3199 				        cum->sse_regno + FIRST_SSE_REG);
   3200 	}
   3201       break;
   3202 
   3203     case E_OImode:
   3204     case E_XImode:
   3205       /* OImode and XImode shouldn't be used directly.  */
   3206       gcc_unreachable ();
   3207 
   3208     case E_V64QImode:
   3209     case E_V32HImode:
   3210     case E_V16SImode:
   3211     case E_V8DImode:
   3212     case E_V32HFmode:
   3213     case E_V16SFmode:
   3214     case E_V8DFmode:
   3215     case E_V16HFmode:
   3216     case E_V8SFmode:
   3217     case E_V8SImode:
   3218     case E_V32QImode:
   3219     case E_V16HImode:
   3220     case E_V4DFmode:
   3221     case E_V4DImode:
   3222       if (!type || !AGGREGATE_TYPE_P (type))
   3223 	{
   3224 	  if (cum->sse_nregs)
   3225 	    return gen_reg_or_parallel (mode, orig_mode,
   3226 				        cum->sse_regno + FIRST_SSE_REG);
   3227 	}
   3228       break;
   3229 
   3230     case E_V8QImode:
   3231     case E_V4HImode:
   3232     case E_V4HFmode:
   3233     case E_V2SImode:
   3234     case E_V2SFmode:
   3235     case E_V1TImode:
   3236     case E_V1DImode:
   3237       if (!type || !AGGREGATE_TYPE_P (type))
   3238 	{
   3239 	  if (cum->mmx_nregs)
   3240 	    return gen_reg_or_parallel (mode, orig_mode,
   3241 				        cum->mmx_regno + FIRST_MMX_REG);
   3242 	}
   3243       break;
   3244     }
   3245   if (error_p)
   3246     {
   3247       cum->float_in_sse = 0;
   3248       error ("calling %qD with SSE calling convention without "
   3249 	     "SSE/SSE2 enabled", cum->decl);
   3250       sorry ("this is a GCC bug that can be worked around by adding "
   3251 	     "attribute used to function called");
   3252     }
   3253 
   3254   return NULL_RTX;
   3255 }
   3256 
   3257 static rtx
   3258 function_arg_64 (const CUMULATIVE_ARGS *cum, machine_mode mode,
   3259 		 machine_mode orig_mode, const_tree type, bool named)
   3260 {
   3261   /* Handle a hidden AL argument containing number of registers
   3262      for varargs x86-64 functions.  */
   3263   if (mode == VOIDmode)
   3264     return GEN_INT (cum->maybe_vaarg
   3265 		    ? (cum->sse_nregs < 0
   3266 		       ? X86_64_SSE_REGPARM_MAX
   3267 		       : cum->sse_regno)
   3268 		    : -1);
   3269 
   3270   switch (mode)
   3271     {
   3272     default:
   3273       break;
   3274 
   3275     case E_V16HFmode:
   3276     case E_V8SFmode:
   3277     case E_V8SImode:
   3278     case E_V32QImode:
   3279     case E_V16HImode:
   3280     case E_V4DFmode:
   3281     case E_V4DImode:
   3282     case E_V32HFmode:
   3283     case E_V16SFmode:
   3284     case E_V16SImode:
   3285     case E_V64QImode:
   3286     case E_V32HImode:
   3287     case E_V8DFmode:
   3288     case E_V8DImode:
   3289       /* Unnamed 256 and 512bit vector mode parameters are passed on stack.  */
   3290       if (!named)
   3291 	return NULL;
   3292       break;
   3293     }
   3294 
   3295   return construct_container (mode, orig_mode, type, 0, cum->nregs,
   3296 			      cum->sse_nregs,
   3297 			      &x86_64_int_parameter_registers [cum->regno],
   3298 			      cum->sse_regno);
   3299 }
   3300 
   3301 static rtx
   3302 function_arg_ms_64 (const CUMULATIVE_ARGS *cum, machine_mode mode,
   3303 		    machine_mode orig_mode, bool named, const_tree type,
   3304 		    HOST_WIDE_INT bytes)
   3305 {
   3306   unsigned int regno;
   3307 
   3308   /* We need to add clobber for MS_ABI->SYSV ABI calls in expand_call.
   3309      We use value of -2 to specify that current function call is MSABI.  */
   3310   if (mode == VOIDmode)
   3311     return GEN_INT (-2);
   3312 
   3313   /* If we've run out of registers, it goes on the stack.  */
   3314   if (cum->nregs == 0)
   3315     return NULL_RTX;
   3316 
   3317   regno = x86_64_ms_abi_int_parameter_registers[cum->regno];
   3318 
   3319   /* Only floating point modes are passed in anything but integer regs.  */
   3320   if (TARGET_SSE && (mode == SFmode || mode == DFmode))
   3321     {
   3322       if (named)
   3323 	{
   3324 	  if (type == NULL_TREE || !AGGREGATE_TYPE_P (type))
   3325 	    regno = cum->regno + FIRST_SSE_REG;
   3326 	}
   3327       else
   3328 	{
   3329 	  rtx t1, t2;
   3330 
   3331 	  /* Unnamed floating parameters are passed in both the
   3332 	     SSE and integer registers.  */
   3333 	  t1 = gen_rtx_REG (mode, cum->regno + FIRST_SSE_REG);
   3334 	  t2 = gen_rtx_REG (mode, regno);
   3335 	  t1 = gen_rtx_EXPR_LIST (VOIDmode, t1, const0_rtx);
   3336 	  t2 = gen_rtx_EXPR_LIST (VOIDmode, t2, const0_rtx);
   3337 	  return gen_rtx_PARALLEL (mode, gen_rtvec (2, t1, t2));
   3338 	}
   3339     }
   3340   /* Handle aggregated types passed in register.  */
   3341   if (orig_mode == BLKmode)
   3342     {
   3343       if (bytes > 0 && bytes <= 8)
   3344         mode = (bytes > 4 ? DImode : SImode);
   3345       if (mode == BLKmode)
   3346         mode = DImode;
   3347     }
   3348 
   3349   return gen_reg_or_parallel (mode, orig_mode, regno);
   3350 }
   3351 
   3352 /* Return where to put the arguments to a function.
   3353    Return zero to push the argument on the stack, or a hard register in which to store the argument.
   3354 
   3355    ARG describes the argument while CUM gives information about the
   3356    preceding args and about the function being called.  */
   3357 
   3358 static rtx
   3359 ix86_function_arg (cumulative_args_t cum_v, const function_arg_info &arg)
   3360 {
   3361   CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
   3362   machine_mode mode = arg.mode;
   3363   HOST_WIDE_INT bytes, words;
   3364   rtx reg;
   3365 
   3366   if (!cum->caller && cfun->machine->func_type != TYPE_NORMAL)
   3367     {
   3368       gcc_assert (arg.type != NULL_TREE);
   3369       if (POINTER_TYPE_P (arg.type))
   3370 	{
   3371 	  /* This is the pointer argument.  */
   3372 	  gcc_assert (TYPE_MODE (arg.type) == ptr_mode);
   3373 	  /* It is at -WORD(AP) in the current frame in interrupt and
   3374 	     exception handlers.  */
   3375 	  reg = plus_constant (Pmode, arg_pointer_rtx, -UNITS_PER_WORD);
   3376 	}
   3377       else
   3378 	{
   3379 	  gcc_assert (cfun->machine->func_type == TYPE_EXCEPTION
   3380 		      && TREE_CODE (arg.type) == INTEGER_TYPE
   3381 		      && TYPE_MODE (arg.type) == word_mode);
   3382 	  /* The error code is the word-mode integer argument at
   3383 	     -2 * WORD(AP) in the current frame of the exception
   3384 	     handler.  */
   3385 	  reg = gen_rtx_MEM (word_mode,
   3386 			     plus_constant (Pmode,
   3387 					    arg_pointer_rtx,
   3388 					    -2 * UNITS_PER_WORD));
   3389 	}
   3390       return reg;
   3391     }
   3392 
   3393   bytes = arg.promoted_size_in_bytes ();
   3394   words = CEIL (bytes, UNITS_PER_WORD);
   3395 
   3396   /* To simplify the code below, represent vector types with a vector mode
   3397      even if MMX/SSE are not active.  */
   3398   if (arg.type && TREE_CODE (arg.type) == VECTOR_TYPE)
   3399     mode = type_natural_mode (arg.type, cum, false);
   3400 
   3401   if (TARGET_64BIT)
   3402     {
   3403       enum calling_abi call_abi = cum ? cum->call_abi : ix86_abi;
   3404 
   3405       if (call_abi == MS_ABI)
   3406 	reg = function_arg_ms_64 (cum, mode, arg.mode, arg.named,
   3407 				  arg.type, bytes);
   3408       else
   3409 	reg = function_arg_64 (cum, mode, arg.mode, arg.type, arg.named);
   3410     }
   3411   else
   3412     reg = function_arg_32 (cum, mode, arg.mode, arg.type, bytes, words);
   3413 
   3414   /* Track if there are outgoing arguments on stack.  */
   3415   if (reg == NULL_RTX && cum->caller)
   3416     cfun->machine->outgoing_args_on_stack = true;
   3417 
   3418   return reg;
   3419 }
   3420 
   3421 /* A C expression that indicates when an argument must be passed by
   3422    reference.  If nonzero for an argument, a copy of that argument is
   3423    made in memory and a pointer to the argument is passed instead of
   3424    the argument itself.  The pointer is passed in whatever way is
   3425    appropriate for passing a pointer to that type.  */
   3426 
   3427 static bool
   3428 ix86_pass_by_reference (cumulative_args_t cum_v, const function_arg_info &arg)
   3429 {
   3430   CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
   3431 
   3432   if (TARGET_64BIT)
   3433     {
   3434       enum calling_abi call_abi = cum ? cum->call_abi : ix86_abi;
   3435 
   3436       /* See Windows x64 Software Convention.  */
   3437       if (call_abi == MS_ABI)
   3438 	{
   3439 	  HOST_WIDE_INT msize = GET_MODE_SIZE (arg.mode);
   3440 
   3441 	  if (tree type = arg.type)
   3442 	    {
   3443 	      /* Arrays are passed by reference.  */
   3444 	      if (TREE_CODE (type) == ARRAY_TYPE)
   3445 		return true;
   3446 
   3447 	      if (RECORD_OR_UNION_TYPE_P (type))
   3448 		{
   3449 		  /* Structs/unions of sizes other than 8, 16, 32, or 64 bits
   3450 		     are passed by reference.  */
   3451 		  msize = int_size_in_bytes (type);
   3452 		}
   3453 	    }
   3454 
   3455 	  /* __m128 is passed by reference.  */
   3456 	  return msize != 1 && msize != 2 && msize != 4 && msize != 8;
   3457 	}
   3458       else if (arg.type && int_size_in_bytes (arg.type) == -1)
   3459 	return true;
   3460     }
   3461 
   3462   return false;
   3463 }
   3464 
   3465 /* Return true when TYPE should be 128bit aligned for 32bit argument
   3466    passing ABI.  XXX: This function is obsolete and is only used for
   3467    checking psABI compatibility with previous versions of GCC.  */
   3468 
   3469 static bool
   3470 ix86_compat_aligned_value_p (const_tree type)
   3471 {
   3472   machine_mode mode = TYPE_MODE (type);
   3473   if (((TARGET_SSE && SSE_REG_MODE_P (mode))
   3474        || mode == TDmode
   3475        || mode == TFmode
   3476        || mode == TCmode)
   3477       && (!TYPE_USER_ALIGN (type) || TYPE_ALIGN (type) > 128))
   3478     return true;
   3479   if (TYPE_ALIGN (type) < 128)
   3480     return false;
   3481 
   3482   if (AGGREGATE_TYPE_P (type))
   3483     {
   3484       /* Walk the aggregates recursively.  */
   3485       switch (TREE_CODE (type))
   3486 	{
   3487 	case RECORD_TYPE:
   3488 	case UNION_TYPE:
   3489 	case QUAL_UNION_TYPE:
   3490 	  {
   3491 	    tree field;
   3492 
   3493 	    /* Walk all the structure fields.  */
   3494 	    for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
   3495 	      {
   3496 		if (TREE_CODE (field) == FIELD_DECL
   3497 		    && ix86_compat_aligned_value_p (TREE_TYPE (field)))
   3498 		  return true;
   3499 	      }
   3500 	    break;
   3501 	  }
   3502 
   3503 	case ARRAY_TYPE:
   3504 	  /* Just for use if some languages passes arrays by value.  */
   3505 	  if (ix86_compat_aligned_value_p (TREE_TYPE (type)))
   3506 	    return true;
   3507 	  break;
   3508 
   3509 	default:
   3510 	  gcc_unreachable ();
   3511 	}
   3512     }
   3513   return false;
   3514 }
   3515 
   3516 /* Return the alignment boundary for MODE and TYPE with alignment ALIGN.
   3517    XXX: This function is obsolete and is only used for checking psABI
   3518    compatibility with previous versions of GCC.  */
   3519 
   3520 static unsigned int
   3521 ix86_compat_function_arg_boundary (machine_mode mode,
   3522 				   const_tree type, unsigned int align)
   3523 {
   3524   /* In 32bit, only _Decimal128 and __float128 are aligned to their
   3525      natural boundaries.  */
   3526   if (!TARGET_64BIT && mode != TDmode && mode != TFmode)
   3527     {
   3528       /* i386 ABI defines all arguments to be 4 byte aligned.  We have to
   3529 	 make an exception for SSE modes since these require 128bit
   3530 	 alignment.
   3531 
   3532 	 The handling here differs from field_alignment.  ICC aligns MMX
   3533 	 arguments to 4 byte boundaries, while structure fields are aligned
   3534 	 to 8 byte boundaries.  */
   3535       if (!type)
   3536 	{
   3537 	  if (!(TARGET_SSE && SSE_REG_MODE_P (mode)))
   3538 	    align = PARM_BOUNDARY;
   3539 	}
   3540       else
   3541 	{
   3542 	  if (!ix86_compat_aligned_value_p (type))
   3543 	    align = PARM_BOUNDARY;
   3544 	}
   3545     }
   3546   if (align > BIGGEST_ALIGNMENT)
   3547     align = BIGGEST_ALIGNMENT;
   3548   return align;
   3549 }
   3550 
   3551 /* Return true when TYPE should be 128bit aligned for 32bit argument
   3552    passing ABI.  */
   3553 
   3554 static bool
   3555 ix86_contains_aligned_value_p (const_tree type)
   3556 {
   3557   machine_mode mode = TYPE_MODE (type);
   3558 
   3559   if (mode == XFmode || mode == XCmode)
   3560     return false;
   3561 
   3562   if (TYPE_ALIGN (type) < 128)
   3563     return false;
   3564 
   3565   if (AGGREGATE_TYPE_P (type))
   3566     {
   3567       /* Walk the aggregates recursively.  */
   3568       switch (TREE_CODE (type))
   3569 	{
   3570 	case RECORD_TYPE:
   3571 	case UNION_TYPE:
   3572 	case QUAL_UNION_TYPE:
   3573 	  {
   3574 	    tree field;
   3575 
   3576 	    /* Walk all the structure fields.  */
   3577 	    for (field = TYPE_FIELDS (type);
   3578 		 field;
   3579 		 field = DECL_CHAIN (field))
   3580 	      {
   3581 		if (TREE_CODE (field) == FIELD_DECL
   3582 		    && ix86_contains_aligned_value_p (TREE_TYPE (field)))
   3583 		  return true;
   3584 	      }
   3585 	    break;
   3586 	  }
   3587 
   3588 	case ARRAY_TYPE:
   3589 	  /* Just for use if some languages passes arrays by value.  */
   3590 	  if (ix86_contains_aligned_value_p (TREE_TYPE (type)))
   3591 	    return true;
   3592 	  break;
   3593 
   3594 	default:
   3595 	  gcc_unreachable ();
   3596 	}
   3597     }
   3598   else
   3599     return TYPE_ALIGN (type) >= 128;
   3600 
   3601   return false;
   3602 }
   3603 
   3604 /* Gives the alignment boundary, in bits, of an argument with the
   3605    specified mode and type.  */
   3606 
   3607 static unsigned int
   3608 ix86_function_arg_boundary (machine_mode mode, const_tree type)
   3609 {
   3610   unsigned int align;
   3611   if (type)
   3612     {
   3613       /* Since the main variant type is used for call, we convert it to
   3614 	 the main variant type.  */
   3615       type = TYPE_MAIN_VARIANT (type);
   3616       align = TYPE_ALIGN (type);
   3617       if (TYPE_EMPTY_P (type))
   3618 	return PARM_BOUNDARY;
   3619     }
   3620   else
   3621     align = GET_MODE_ALIGNMENT (mode);
   3622   if (align < PARM_BOUNDARY)
   3623     align = PARM_BOUNDARY;
   3624   else
   3625     {
   3626       static bool warned;
   3627       unsigned int saved_align = align;
   3628 
   3629       if (!TARGET_64BIT)
   3630 	{
   3631 	  /* i386 ABI defines XFmode arguments to be 4 byte aligned.  */
   3632 	  if (!type)
   3633 	    {
   3634 	      if (mode == XFmode || mode == XCmode)
   3635 		align = PARM_BOUNDARY;
   3636 	    }
   3637 	  else if (!ix86_contains_aligned_value_p (type))
   3638 	    align = PARM_BOUNDARY;
   3639 
   3640 	  if (align < 128)
   3641 	    align = PARM_BOUNDARY;
   3642 	}
   3643 
   3644       if (warn_psabi
   3645 	  && !warned
   3646 	  && align != ix86_compat_function_arg_boundary (mode, type,
   3647 							 saved_align))
   3648 	{
   3649 	  warned = true;
   3650 	  inform (input_location,
   3651 		  "the ABI for passing parameters with %d-byte"
   3652 		  " alignment has changed in GCC 4.6",
   3653 		  align / BITS_PER_UNIT);
   3654 	}
   3655     }
   3656 
   3657   return align;
   3658 }
   3659 
   3660 /* Return true if N is a possible register number of function value.  */
   3661 
   3662 static bool
   3663 ix86_function_value_regno_p (const unsigned int regno)
   3664 {
   3665   switch (regno)
   3666     {
   3667     case AX_REG:
   3668       return true;
   3669     case DX_REG:
   3670       return (!TARGET_64BIT || ix86_cfun_abi () != MS_ABI);
   3671     case DI_REG:
   3672     case SI_REG:
   3673       return TARGET_64BIT && ix86_cfun_abi () != MS_ABI;
   3674 
   3675       /* Complex values are returned in %st(0)/%st(1) pair.  */
   3676     case ST0_REG:
   3677     case ST1_REG:
   3678       /* TODO: The function should depend on current function ABI but
   3679        builtins.cc would need updating then. Therefore we use the
   3680        default ABI.  */
   3681       if (TARGET_64BIT && ix86_cfun_abi () == MS_ABI)
   3682 	return false;
   3683       return TARGET_FLOAT_RETURNS_IN_80387;
   3684 
   3685       /* Complex values are returned in %xmm0/%xmm1 pair.  */
   3686     case XMM0_REG:
   3687     case XMM1_REG:
   3688       return TARGET_SSE;
   3689 
   3690     case MM0_REG:
   3691       if (TARGET_MACHO || TARGET_64BIT)
   3692 	return false;
   3693       return TARGET_MMX;
   3694     }
   3695 
   3696   return false;
   3697 }
   3698 
   3699 /* Check whether the register REGNO should be zeroed on X86.
   3700    When ALL_SSE_ZEROED is true, all SSE registers have been zeroed
   3701    together, no need to zero it again.
   3702    When NEED_ZERO_MMX is true, MMX registers should be cleared.  */
   3703 
   3704 static bool
   3705 zero_call_used_regno_p (const unsigned int regno,
   3706 			bool all_sse_zeroed,
   3707 			bool need_zero_mmx)
   3708 {
   3709   return GENERAL_REGNO_P (regno)
   3710 	 || (!all_sse_zeroed && SSE_REGNO_P (regno))
   3711 	 || MASK_REGNO_P (regno)
   3712 	 || (need_zero_mmx && MMX_REGNO_P (regno));
   3713 }
   3714 
   3715 /* Return the machine_mode that is used to zero register REGNO.  */
   3716 
   3717 static machine_mode
   3718 zero_call_used_regno_mode (const unsigned int regno)
   3719 {
   3720   /* NB: We only need to zero the lower 32 bits for integer registers
   3721      and the lower 128 bits for vector registers since destination are
   3722      zero-extended to the full register width.  */
   3723   if (GENERAL_REGNO_P (regno))
   3724     return SImode;
   3725   else if (SSE_REGNO_P (regno))
   3726     return V4SFmode;
   3727   else if (MASK_REGNO_P (regno))
   3728     return HImode;
   3729   else if (MMX_REGNO_P (regno))
   3730     return V2SImode;
   3731   else
   3732     gcc_unreachable ();
   3733 }
   3734 
   3735 /* Generate a rtx to zero all vector registers together if possible,
   3736    otherwise, return NULL.  */
   3737 
   3738 static rtx
   3739 zero_all_vector_registers (HARD_REG_SET need_zeroed_hardregs)
   3740 {
   3741   if (!TARGET_AVX)
   3742     return NULL;
   3743 
   3744   for (unsigned int regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
   3745     if ((LEGACY_SSE_REGNO_P (regno)
   3746 	 || (TARGET_64BIT
   3747 	     && (REX_SSE_REGNO_P (regno)
   3748 		 || (TARGET_AVX512F && EXT_REX_SSE_REGNO_P (regno)))))
   3749 	&& !TEST_HARD_REG_BIT (need_zeroed_hardregs, regno))
   3750       return NULL;
   3751 
   3752   return gen_avx_vzeroall ();
   3753 }
   3754 
   3755 /* Generate insns to zero all st registers together.
   3756    Return true when zeroing instructions are generated.
   3757    Assume the number of st registers that are zeroed is num_of_st,
   3758    we will emit the following sequence to zero them together:
   3759 		  fldz;		\
   3760 		  fldz;		\
   3761 		  ...
   3762 		  fldz;		\
   3763 		  fstp %%st(0);	\
   3764 		  fstp %%st(0);	\
   3765 		  ...
   3766 		  fstp %%st(0);
   3767    i.e., num_of_st fldz followed by num_of_st fstp to clear the stack
   3768    mark stack slots empty.
   3769 
   3770    How to compute the num_of_st:
   3771    There is no direct mapping from stack registers to hard register
   3772    numbers.  If one stack register needs to be cleared, we don't know
   3773    where in the stack the value remains.  So, if any stack register
   3774    needs to be cleared, the whole stack should be cleared.  However,
   3775    x87 stack registers that hold the return value should be excluded.
   3776    x87 returns in the top (two for complex values) register, so
   3777    num_of_st should be 7/6 when x87 returns, otherwise it will be 8.
   3778    return the value of num_of_st.  */
   3779 
   3780 
   3781 static int
   3782 zero_all_st_registers (HARD_REG_SET need_zeroed_hardregs)
   3783 {
   3784 
   3785   /* If the FPU is disabled, no need to zero all st registers.  */
   3786   if (! (TARGET_80387 || TARGET_FLOAT_RETURNS_IN_80387))
   3787     return 0;
   3788 
   3789   unsigned int num_of_st = 0;
   3790   for (unsigned int regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
   3791     if ((STACK_REGNO_P (regno) || MMX_REGNO_P (regno))
   3792 	&& TEST_HARD_REG_BIT (need_zeroed_hardregs, regno))
   3793       {
   3794 	num_of_st++;
   3795 	break;
   3796       }
   3797 
   3798   if (num_of_st == 0)
   3799     return 0;
   3800 
   3801   bool return_with_x87 = false;
   3802   return_with_x87 = (crtl->return_rtx
   3803 		     && (STACK_REG_P (crtl->return_rtx)));
   3804 
   3805   bool complex_return = false;
   3806   complex_return = (crtl->return_rtx
   3807 		    && COMPLEX_MODE_P (GET_MODE (crtl->return_rtx)));
   3808 
   3809   if (return_with_x87)
   3810     if (complex_return)
   3811       num_of_st = 6;
   3812     else
   3813       num_of_st = 7;
   3814   else
   3815     num_of_st = 8;
   3816 
   3817   rtx st_reg = gen_rtx_REG (XFmode, FIRST_STACK_REG);
   3818   for (unsigned int i = 0; i < num_of_st; i++)
   3819     emit_insn (gen_rtx_SET (st_reg, CONST0_RTX (XFmode)));
   3820 
   3821   for (unsigned int i = 0; i < num_of_st; i++)
   3822     {
   3823       rtx insn;
   3824       insn = emit_insn (gen_rtx_SET (st_reg, st_reg));
   3825       add_reg_note (insn, REG_DEAD, st_reg);
   3826     }
   3827   return num_of_st;
   3828 }
   3829 
   3830 
   3831 /* When the routine exit in MMX mode, if any ST register needs
   3832    to be zeroed, we should clear all MMX registers except the
   3833    RET_MMX_REGNO that holds the return value.  */
   3834 static bool
   3835 zero_all_mm_registers (HARD_REG_SET need_zeroed_hardregs,
   3836 		       unsigned int ret_mmx_regno)
   3837 {
   3838   bool need_zero_all_mm = false;
   3839   for (unsigned int regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
   3840     if (STACK_REGNO_P (regno)
   3841 	&& TEST_HARD_REG_BIT (need_zeroed_hardregs, regno))
   3842       {
   3843 	need_zero_all_mm = true;
   3844 	break;
   3845       }
   3846 
   3847   if (!need_zero_all_mm)
   3848     return false;
   3849 
   3850   machine_mode mode = V2SImode;
   3851   for (unsigned int regno = FIRST_MMX_REG; regno <= LAST_MMX_REG; regno++)
   3852     if (regno != ret_mmx_regno)
   3853       {
   3854 	rtx reg = gen_rtx_REG (mode, regno);
   3855 	emit_insn (gen_rtx_SET (reg, CONST0_RTX (mode)));
   3856       }
   3857   return true;
   3858 }
   3859 
   3860 /* TARGET_ZERO_CALL_USED_REGS.  */
   3861 /* Generate a sequence of instructions that zero registers specified by
   3862    NEED_ZEROED_HARDREGS.  Return the ZEROED_HARDREGS that are actually
   3863    zeroed.  */
   3864 static HARD_REG_SET
   3865 ix86_zero_call_used_regs (HARD_REG_SET need_zeroed_hardregs)
   3866 {
   3867   HARD_REG_SET zeroed_hardregs;
   3868   bool all_sse_zeroed = false;
   3869   int all_st_zeroed_num = 0;
   3870   bool all_mm_zeroed = false;
   3871 
   3872   CLEAR_HARD_REG_SET (zeroed_hardregs);
   3873 
   3874   /* first, let's see whether we can zero all vector registers together.  */
   3875   rtx zero_all_vec_insn = zero_all_vector_registers (need_zeroed_hardregs);
   3876   if (zero_all_vec_insn)
   3877     {
   3878       emit_insn (zero_all_vec_insn);
   3879       all_sse_zeroed = true;
   3880     }
   3881 
   3882   /* mm/st registers are shared registers set, we should follow the following
   3883      rules to clear them:
   3884 			MMX exit mode	      x87 exit mode
   3885 	-------------|----------------------|---------------
   3886 	uses x87 reg | clear all MMX	    | clear all x87
   3887 	uses MMX reg | clear individual MMX | clear all x87
   3888 	x87 + MMX    | clear all MMX	    | clear all x87
   3889 
   3890      first, we should decide which mode (MMX mode or x87 mode) the function
   3891      exit with.  */
   3892 
   3893   bool exit_with_mmx_mode = (crtl->return_rtx
   3894 			     && (MMX_REG_P (crtl->return_rtx)));
   3895 
   3896   if (!exit_with_mmx_mode)
   3897     /* x87 exit mode, we should zero all st registers together.  */
   3898     {
   3899       all_st_zeroed_num = zero_all_st_registers (need_zeroed_hardregs);
   3900 
   3901       if (all_st_zeroed_num > 0)
   3902 	for (unsigned int regno = FIRST_STACK_REG; regno <= LAST_STACK_REG; regno++)
   3903 	  /* x87 stack registers that hold the return value should be excluded.
   3904 	     x87 returns in the top (two for complex values) register.  */
   3905 	  if (all_st_zeroed_num == 8
   3906 	      || !((all_st_zeroed_num >= 6 && regno == REGNO (crtl->return_rtx))
   3907 		   || (all_st_zeroed_num == 6
   3908 		       && (regno == (REGNO (crtl->return_rtx) + 1)))))
   3909 	    SET_HARD_REG_BIT (zeroed_hardregs, regno);
   3910     }
   3911   else
   3912     /* MMX exit mode, check whether we can zero all mm registers.  */
   3913     {
   3914       unsigned int exit_mmx_regno = REGNO (crtl->return_rtx);
   3915       all_mm_zeroed = zero_all_mm_registers (need_zeroed_hardregs,
   3916 					     exit_mmx_regno);
   3917       if (all_mm_zeroed)
   3918 	for (unsigned int regno = FIRST_MMX_REG; regno <= LAST_MMX_REG; regno++)
   3919 	  if (regno != exit_mmx_regno)
   3920 	    SET_HARD_REG_BIT (zeroed_hardregs, regno);
   3921     }
   3922 
   3923   /* Now, generate instructions to zero all the other registers.  */
   3924 
   3925   for (unsigned int regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
   3926     {
   3927       if (!TEST_HARD_REG_BIT (need_zeroed_hardregs, regno))
   3928 	continue;
   3929       if (!zero_call_used_regno_p (regno, all_sse_zeroed,
   3930 				   exit_with_mmx_mode && !all_mm_zeroed))
   3931 	continue;
   3932 
   3933       SET_HARD_REG_BIT (zeroed_hardregs, regno);
   3934 
   3935       machine_mode mode = zero_call_used_regno_mode (regno);
   3936 
   3937       rtx reg = gen_rtx_REG (mode, regno);
   3938       rtx tmp = gen_rtx_SET (reg, CONST0_RTX (mode));
   3939 
   3940       switch (mode)
   3941 	{
   3942 	case E_SImode:
   3943 	  if (!TARGET_USE_MOV0 || optimize_insn_for_size_p ())
   3944 	    {
   3945 	      rtx clob = gen_rtx_CLOBBER (VOIDmode,
   3946 					  gen_rtx_REG (CCmode,
   3947 						       FLAGS_REG));
   3948 	      tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2,
   3949 							   tmp,
   3950 							   clob));
   3951 	    }
   3952 	  /* FALLTHRU.  */
   3953 
   3954 	case E_V4SFmode:
   3955 	case E_HImode:
   3956 	case E_V2SImode:
   3957 	  emit_insn (tmp);
   3958 	  break;
   3959 
   3960 	default:
   3961 	  gcc_unreachable ();
   3962 	}
   3963     }
   3964   return zeroed_hardregs;
   3965 }
   3966 
   3967 /* Define how to find the value returned by a function.
   3968    VALTYPE is the data type of the value (as a tree).
   3969    If the precise function being called is known, FUNC is its FUNCTION_DECL;
   3970    otherwise, FUNC is 0.  */
   3971 
   3972 static rtx
   3973 function_value_32 (machine_mode orig_mode, machine_mode mode,
   3974 		   const_tree fntype, const_tree fn)
   3975 {
   3976   unsigned int regno;
   3977 
   3978   /* 8-byte vector modes in %mm0. See ix86_return_in_memory for where
   3979      we normally prevent this case when mmx is not available.  However
   3980      some ABIs may require the result to be returned like DImode.  */
   3981   if (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 8)
   3982     regno = FIRST_MMX_REG;
   3983 
   3984   /* 16-byte vector modes in %xmm0.  See ix86_return_in_memory for where
   3985      we prevent this case when sse is not available.  However some ABIs
   3986      may require the result to be returned like integer TImode.  */
   3987   else if (mode == TImode
   3988 	   || (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 16))
   3989     regno = FIRST_SSE_REG;
   3990 
   3991   /* 32-byte vector modes in %ymm0.   */
   3992   else if (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 32)
   3993     regno = FIRST_SSE_REG;
   3994 
   3995   /* 64-byte vector modes in %zmm0.   */
   3996   else if (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 64)
   3997     regno = FIRST_SSE_REG;
   3998 
   3999   /* Floating point return values in %st(0) (unless -mno-fp-ret-in-387).  */
   4000   else if (X87_FLOAT_MODE_P (mode) && TARGET_FLOAT_RETURNS_IN_80387)
   4001     regno = FIRST_FLOAT_REG;
   4002   else
   4003     /* Most things go in %eax.  */
   4004     regno = AX_REG;
   4005 
   4006   /* Return _Float16/_Complex _Foat16 by sse register.  */
   4007   if (mode == HFmode)
   4008     regno = FIRST_SSE_REG;
   4009   if (mode == HCmode)
   4010     {
   4011       rtx ret = gen_rtx_PARALLEL (mode, rtvec_alloc(1));
   4012       XVECEXP (ret, 0, 0)
   4013 	= gen_rtx_EXPR_LIST (VOIDmode,
   4014 			     gen_rtx_REG (SImode, FIRST_SSE_REG),
   4015 			     GEN_INT (0));
   4016       return ret;
   4017     }
   4018 
   4019   /* Override FP return register with %xmm0 for local functions when
   4020      SSE math is enabled or for functions with sseregparm attribute.  */
   4021   if ((fn || fntype) && (mode == SFmode || mode == DFmode))
   4022     {
   4023       int sse_level = ix86_function_sseregparm (fntype, fn, false);
   4024       if (sse_level == -1)
   4025 	{
   4026 	  error ("calling %qD with SSE calling convention without "
   4027 		 "SSE/SSE2 enabled", fn);
   4028 	  sorry ("this is a GCC bug that can be worked around by adding "
   4029 		 "attribute used to function called");
   4030 	}
   4031       else if ((sse_level >= 1 && mode == SFmode)
   4032 	       || (sse_level == 2 && mode == DFmode))
   4033 	regno = FIRST_SSE_REG;
   4034     }
   4035 
   4036   /* OImode shouldn't be used directly.  */
   4037   gcc_assert (mode != OImode);
   4038 
   4039   return gen_rtx_REG (orig_mode, regno);
   4040 }
   4041 
   4042 static rtx
   4043 function_value_64 (machine_mode orig_mode, machine_mode mode,
   4044 		   const_tree valtype)
   4045 {
   4046   rtx ret;
   4047 
   4048   /* Handle libcalls, which don't provide a type node.  */
   4049   if (valtype == NULL)
   4050     {
   4051       unsigned int regno;
   4052 
   4053       switch (mode)
   4054 	{
   4055 	case E_HFmode:
   4056 	case E_HCmode:
   4057 	case E_SFmode:
   4058 	case E_SCmode:
   4059 	case E_DFmode:
   4060 	case E_DCmode:
   4061 	case E_TFmode:
   4062 	case E_SDmode:
   4063 	case E_DDmode:
   4064 	case E_TDmode:
   4065 	  regno = FIRST_SSE_REG;
   4066 	  break;
   4067 	case E_XFmode:
   4068 	case E_XCmode:
   4069 	  regno = FIRST_FLOAT_REG;
   4070 	  break;
   4071 	case E_TCmode:
   4072 	  return NULL;
   4073 	default:
   4074 	  regno = AX_REG;
   4075 	}
   4076 
   4077       return gen_rtx_REG (mode, regno);
   4078     }
   4079   else if (POINTER_TYPE_P (valtype))
   4080     {
   4081       /* Pointers are always returned in word_mode.  */
   4082       mode = word_mode;
   4083     }
   4084 
   4085   ret = construct_container (mode, orig_mode, valtype, 1,
   4086 			     X86_64_REGPARM_MAX, X86_64_SSE_REGPARM_MAX,
   4087 			     x86_64_int_return_registers, 0);
   4088 
   4089   /* For zero sized structures, construct_container returns NULL, but we
   4090      need to keep rest of compiler happy by returning meaningful value.  */
   4091   if (!ret)
   4092     ret = gen_rtx_REG (orig_mode, AX_REG);
   4093 
   4094   return ret;
   4095 }
   4096 
   4097 static rtx
   4098 function_value_ms_32 (machine_mode orig_mode, machine_mode mode,
   4099 		      const_tree fntype, const_tree fn, const_tree valtype)
   4100 {
   4101   unsigned int regno;
   4102 
   4103   /* Floating point return values in %st(0)
   4104      (unless -mno-fp-ret-in-387 or aggregate type of up to 8 bytes).  */
   4105   if (X87_FLOAT_MODE_P (mode) && TARGET_FLOAT_RETURNS_IN_80387
   4106 	   && (GET_MODE_SIZE (mode) > 8
   4107 	       || valtype == NULL_TREE || !AGGREGATE_TYPE_P (valtype)))
   4108   {
   4109     regno = FIRST_FLOAT_REG;
   4110     return gen_rtx_REG (orig_mode, regno);
   4111   }
   4112   else
   4113     return function_value_32(orig_mode, mode, fntype,fn);
   4114 }
   4115 
   4116 static rtx
   4117 function_value_ms_64 (machine_mode orig_mode, machine_mode mode,
   4118 		      const_tree valtype)
   4119 {
   4120   unsigned int regno = AX_REG;
   4121 
   4122   if (TARGET_SSE)
   4123     {
   4124       switch (GET_MODE_SIZE (mode))
   4125 	{
   4126 	case 16:
   4127 	  if (valtype != NULL_TREE
   4128 	      && !VECTOR_INTEGER_TYPE_P (valtype)
   4129 	      && !VECTOR_INTEGER_TYPE_P (valtype)
   4130 	      && !INTEGRAL_TYPE_P (valtype)
   4131 	      && !VECTOR_FLOAT_TYPE_P (valtype))
   4132 	    break;
   4133 	  if ((SCALAR_INT_MODE_P (mode) || VECTOR_MODE_P (mode))
   4134 	      && !COMPLEX_MODE_P (mode))
   4135 	    regno = FIRST_SSE_REG;
   4136 	  break;
   4137 	case 8:
   4138 	case 4:
   4139 	  if (valtype != NULL_TREE && AGGREGATE_TYPE_P (valtype))
   4140 	    break;
   4141 	  if (mode == SFmode || mode == DFmode)
   4142 	    regno = FIRST_SSE_REG;
   4143 	  break;
   4144 	default:
   4145 	  break;
   4146         }
   4147     }
   4148   return gen_rtx_REG (orig_mode, regno);
   4149 }
   4150 
   4151 static rtx
   4152 ix86_function_value_1 (const_tree valtype, const_tree fntype_or_decl,
   4153 		       machine_mode orig_mode, machine_mode mode)
   4154 {
   4155   const_tree fn, fntype;
   4156 
   4157   fn = NULL_TREE;
   4158   if (fntype_or_decl && DECL_P (fntype_or_decl))
   4159     fn = fntype_or_decl;
   4160   fntype = fn ? TREE_TYPE (fn) : fntype_or_decl;
   4161 
   4162   if (ix86_function_type_abi (fntype) == MS_ABI)
   4163     {
   4164       if (TARGET_64BIT)
   4165 	return function_value_ms_64 (orig_mode, mode, valtype);
   4166       else
   4167 	return function_value_ms_32 (orig_mode, mode, fntype, fn, valtype);
   4168     }
   4169   else if (TARGET_64BIT)
   4170     return function_value_64 (orig_mode, mode, valtype);
   4171   else
   4172     return function_value_32 (orig_mode, mode, fntype, fn);
   4173 }
   4174 
   4175 static rtx
   4176 ix86_function_value (const_tree valtype, const_tree fntype_or_decl, bool)
   4177 {
   4178   machine_mode mode, orig_mode;
   4179 
   4180   orig_mode = TYPE_MODE (valtype);
   4181   mode = type_natural_mode (valtype, NULL, true);
   4182   return ix86_function_value_1 (valtype, fntype_or_decl, orig_mode, mode);
   4183 }
   4184 
   4185 /* Pointer function arguments and return values are promoted to
   4186    word_mode for normal functions.  */
   4187 
   4188 static machine_mode
   4189 ix86_promote_function_mode (const_tree type, machine_mode mode,
   4190 			    int *punsignedp, const_tree fntype,
   4191 			    int for_return)
   4192 {
   4193   if (cfun->machine->func_type == TYPE_NORMAL
   4194       && type != NULL_TREE
   4195       && POINTER_TYPE_P (type))
   4196     {
   4197       *punsignedp = POINTERS_EXTEND_UNSIGNED;
   4198       return word_mode;
   4199     }
   4200   return default_promote_function_mode (type, mode, punsignedp, fntype,
   4201 					for_return);
   4202 }
   4203 
   4204 /* Return true if a structure, union or array with MODE containing FIELD
   4205    should be accessed using BLKmode.  */
   4206 
   4207 static bool
   4208 ix86_member_type_forces_blk (const_tree field, machine_mode mode)
   4209 {
   4210   /* Union with XFmode must be in BLKmode.  */
   4211   return (mode == XFmode
   4212 	  && (TREE_CODE (DECL_FIELD_CONTEXT (field)) == UNION_TYPE
   4213 	      || TREE_CODE (DECL_FIELD_CONTEXT (field)) == QUAL_UNION_TYPE));
   4214 }
   4215 
   4216 rtx
   4217 ix86_libcall_value (machine_mode mode)
   4218 {
   4219   return ix86_function_value_1 (NULL, NULL, mode, mode);
   4220 }
   4221 
   4222 /* Return true iff type is returned in memory.  */
   4223 
   4224 static bool
   4225 ix86_return_in_memory (const_tree type, const_tree fntype ATTRIBUTE_UNUSED)
   4226 {
   4227   const machine_mode mode = type_natural_mode (type, NULL, true);
   4228   HOST_WIDE_INT size;
   4229 
   4230   if (TARGET_64BIT)
   4231     {
   4232       if (ix86_function_type_abi (fntype) == MS_ABI)
   4233 	{
   4234 	  size = int_size_in_bytes (type);
   4235 
   4236 	  /* __m128 is returned in xmm0.  */
   4237 	  if ((!type || VECTOR_INTEGER_TYPE_P (type)
   4238 	       || INTEGRAL_TYPE_P (type)
   4239 	       || VECTOR_FLOAT_TYPE_P (type))
   4240 	      && (SCALAR_INT_MODE_P (mode) || VECTOR_MODE_P (mode))
   4241 	      && !COMPLEX_MODE_P (mode)
   4242 	      && (GET_MODE_SIZE (mode) == 16 || size == 16))
   4243 	    return false;
   4244 
   4245 	  /* Otherwise, the size must be exactly in [1248]. */
   4246 	  return size != 1 && size != 2 && size != 4 && size != 8;
   4247 	}
   4248       else
   4249 	{
   4250 	  int needed_intregs, needed_sseregs;
   4251 
   4252 	  return examine_argument (mode, type, 1,
   4253 				   &needed_intregs, &needed_sseregs);
   4254 	}
   4255     }
   4256   else
   4257     {
   4258       size = int_size_in_bytes (type);
   4259 
   4260       /* Intel MCU psABI returns scalars and aggregates no larger than 8
   4261 	 bytes in registers.  */
   4262       if (TARGET_IAMCU)
   4263 	return VECTOR_MODE_P (mode) || size < 0 || size > 8;
   4264 
   4265       if (mode == BLKmode)
   4266 	return true;
   4267 
   4268       if (MS_AGGREGATE_RETURN && AGGREGATE_TYPE_P (type) && size <= 8)
   4269 	return false;
   4270 
   4271       if (VECTOR_MODE_P (mode) || mode == TImode)
   4272 	{
   4273 	  /* User-created vectors small enough to fit in EAX.  */
   4274 	  if (size < 8)
   4275 	    return false;
   4276 
   4277 	  /* Unless ABI prescibes otherwise,
   4278 	     MMX/3dNow values are returned in MM0 if available.  */
   4279 
   4280 	  if (size == 8)
   4281 	    return TARGET_VECT8_RETURNS || !TARGET_MMX;
   4282 
   4283 	  /* SSE values are returned in XMM0 if available.  */
   4284 	  if (size == 16)
   4285 	    return !TARGET_SSE;
   4286 
   4287 	  /* AVX values are returned in YMM0 if available.  */
   4288 	  if (size == 32)
   4289 	    return !TARGET_AVX;
   4290 
   4291 	  /* AVX512F values are returned in ZMM0 if available.  */
   4292 	  if (size == 64)
   4293 	    return !TARGET_AVX512F;
   4294 	}
   4295 
   4296       if (mode == XFmode)
   4297 	return false;
   4298 
   4299       if (size > 12)
   4300 	return true;
   4301 
   4302       /* OImode shouldn't be used directly.  */
   4303       gcc_assert (mode != OImode);
   4304 
   4305       return false;
   4306     }
   4307 }
   4308 
   4309 /* Implement TARGET_PUSH_ARGUMENT.  */
   4310 
   4311 static bool
   4312 ix86_push_argument (unsigned int npush)
   4313 {
   4314   /* If SSE2 is available, use vector move to put large argument onto
   4315      stack.  NB:  In 32-bit mode, use 8-byte vector move.  */
   4316   return ((!TARGET_SSE2 || npush < (TARGET_64BIT ? 16 : 8))
   4317 	  && TARGET_PUSH_ARGS
   4318 	  && !ACCUMULATE_OUTGOING_ARGS);
   4319 }
   4320 
   4321 
   4322 /* Create the va_list data type.  */
   4324 
   4325 static tree
   4326 ix86_build_builtin_va_list_64 (void)
   4327 {
   4328   tree f_gpr, f_fpr, f_ovf, f_sav, record, type_decl;
   4329 
   4330   record = lang_hooks.types.make_type (RECORD_TYPE);
   4331   type_decl = build_decl (BUILTINS_LOCATION,
   4332 			  TYPE_DECL, get_identifier ("__va_list_tag"), record);
   4333 
   4334   f_gpr = build_decl (BUILTINS_LOCATION,
   4335 		      FIELD_DECL, get_identifier ("gp_offset"),
   4336 		      unsigned_type_node);
   4337   f_fpr = build_decl (BUILTINS_LOCATION,
   4338 		      FIELD_DECL, get_identifier ("fp_offset"),
   4339 		      unsigned_type_node);
   4340   f_ovf = build_decl (BUILTINS_LOCATION,
   4341 		      FIELD_DECL, get_identifier ("overflow_arg_area"),
   4342 		      ptr_type_node);
   4343   f_sav = build_decl (BUILTINS_LOCATION,
   4344 		      FIELD_DECL, get_identifier ("reg_save_area"),
   4345 		      ptr_type_node);
   4346 
   4347   va_list_gpr_counter_field = f_gpr;
   4348   va_list_fpr_counter_field = f_fpr;
   4349 
   4350   DECL_FIELD_CONTEXT (f_gpr) = record;
   4351   DECL_FIELD_CONTEXT (f_fpr) = record;
   4352   DECL_FIELD_CONTEXT (f_ovf) = record;
   4353   DECL_FIELD_CONTEXT (f_sav) = record;
   4354 
   4355   TYPE_STUB_DECL (record) = type_decl;
   4356   TYPE_NAME (record) = type_decl;
   4357   TYPE_FIELDS (record) = f_gpr;
   4358   DECL_CHAIN (f_gpr) = f_fpr;
   4359   DECL_CHAIN (f_fpr) = f_ovf;
   4360   DECL_CHAIN (f_ovf) = f_sav;
   4361 
   4362   layout_type (record);
   4363 
   4364   TYPE_ATTRIBUTES (record) = tree_cons (get_identifier ("sysv_abi va_list"),
   4365 					NULL_TREE, TYPE_ATTRIBUTES (record));
   4366 
   4367   /* The correct type is an array type of one element.  */
   4368   return build_array_type (record, build_index_type (size_zero_node));
   4369 }
   4370 
   4371 /* Setup the builtin va_list data type and for 64-bit the additional
   4372    calling convention specific va_list data types.  */
   4373 
   4374 static tree
   4375 ix86_build_builtin_va_list (void)
   4376 {
   4377   if (TARGET_64BIT)
   4378     {
   4379       /* Initialize ABI specific va_list builtin types.
   4380 
   4381 	 In lto1, we can encounter two va_list types:
   4382 	 - one as a result of the type-merge across TUs, and
   4383 	 - the one constructed here.
   4384 	 These two types will not have the same TYPE_MAIN_VARIANT, and therefore
   4385 	 a type identity check in canonical_va_list_type based on
   4386 	 TYPE_MAIN_VARIANT (which we used to have) will not work.
   4387 	 Instead, we tag each va_list_type_node with its unique attribute, and
   4388 	 look for the attribute in the type identity check in
   4389 	 canonical_va_list_type.
   4390 
   4391 	 Tagging sysv_va_list_type_node directly with the attribute is
   4392 	 problematic since it's a array of one record, which will degrade into a
   4393 	 pointer to record when used as parameter (see build_va_arg comments for
   4394 	 an example), dropping the attribute in the process.  So we tag the
   4395 	 record instead.  */
   4396 
   4397       /* For SYSV_ABI we use an array of one record.  */
   4398       sysv_va_list_type_node = ix86_build_builtin_va_list_64 ();
   4399 
   4400       /* For MS_ABI we use plain pointer to argument area.  */
   4401       tree char_ptr_type = build_pointer_type (char_type_node);
   4402       tree attr = tree_cons (get_identifier ("ms_abi va_list"), NULL_TREE,
   4403 			     TYPE_ATTRIBUTES (char_ptr_type));
   4404       ms_va_list_type_node = build_type_attribute_variant (char_ptr_type, attr);
   4405 
   4406       return ((ix86_abi == MS_ABI)
   4407 	      ? ms_va_list_type_node
   4408 	      : sysv_va_list_type_node);
   4409     }
   4410   else
   4411     {
   4412       /* For i386 we use plain pointer to argument area.  */
   4413       return build_pointer_type (char_type_node);
   4414     }
   4415 }
   4416 
   4417 /* Worker function for TARGET_SETUP_INCOMING_VARARGS.  */
   4418 
   4419 static void
   4420 setup_incoming_varargs_64 (CUMULATIVE_ARGS *cum)
   4421 {
   4422   rtx save_area, mem;
   4423   alias_set_type set;
   4424   int i, max;
   4425 
   4426   /* GPR size of varargs save area.  */
   4427   if (cfun->va_list_gpr_size)
   4428     ix86_varargs_gpr_size = X86_64_REGPARM_MAX * UNITS_PER_WORD;
   4429   else
   4430     ix86_varargs_gpr_size = 0;
   4431 
   4432   /* FPR size of varargs save area.  We don't need it if we don't pass
   4433      anything in SSE registers.  */
   4434   if (TARGET_SSE && cfun->va_list_fpr_size)
   4435     ix86_varargs_fpr_size = X86_64_SSE_REGPARM_MAX * 16;
   4436   else
   4437     ix86_varargs_fpr_size = 0;
   4438 
   4439   if (! ix86_varargs_gpr_size && ! ix86_varargs_fpr_size)
   4440     return;
   4441 
   4442   save_area = frame_pointer_rtx;
   4443   set = get_varargs_alias_set ();
   4444 
   4445   max = cum->regno + cfun->va_list_gpr_size / UNITS_PER_WORD;
   4446   if (max > X86_64_REGPARM_MAX)
   4447     max = X86_64_REGPARM_MAX;
   4448 
   4449   for (i = cum->regno; i < max; i++)
   4450     {
   4451       mem = gen_rtx_MEM (word_mode,
   4452 			 plus_constant (Pmode, save_area, i * UNITS_PER_WORD));
   4453       MEM_NOTRAP_P (mem) = 1;
   4454       set_mem_alias_set (mem, set);
   4455       emit_move_insn (mem,
   4456 		      gen_rtx_REG (word_mode,
   4457 				   x86_64_int_parameter_registers[i]));
   4458     }
   4459 
   4460   if (ix86_varargs_fpr_size)
   4461     {
   4462       machine_mode smode;
   4463       rtx_code_label *label;
   4464       rtx test;
   4465 
   4466       /* Now emit code to save SSE registers.  The AX parameter contains number
   4467 	 of SSE parameter registers used to call this function, though all we
   4468 	 actually check here is the zero/non-zero status.  */
   4469 
   4470       label = gen_label_rtx ();
   4471       test = gen_rtx_EQ (VOIDmode, gen_rtx_REG (QImode, AX_REG), const0_rtx);
   4472       emit_jump_insn (gen_cbranchqi4 (test, XEXP (test, 0), XEXP (test, 1),
   4473 				      label));
   4474 
   4475       /* ??? If !TARGET_SSE_TYPELESS_STORES, would we perform better if
   4476 	 we used movdqa (i.e. TImode) instead?  Perhaps even better would
   4477 	 be if we could determine the real mode of the data, via a hook
   4478 	 into pass_stdarg.  Ignore all that for now.  */
   4479       smode = V4SFmode;
   4480       if (crtl->stack_alignment_needed < GET_MODE_ALIGNMENT (smode))
   4481 	crtl->stack_alignment_needed = GET_MODE_ALIGNMENT (smode);
   4482 
   4483       max = cum->sse_regno + cfun->va_list_fpr_size / 16;
   4484       if (max > X86_64_SSE_REGPARM_MAX)
   4485 	max = X86_64_SSE_REGPARM_MAX;
   4486 
   4487       for (i = cum->sse_regno; i < max; ++i)
   4488 	{
   4489 	  mem = plus_constant (Pmode, save_area,
   4490 			       i * 16 + ix86_varargs_gpr_size);
   4491 	  mem = gen_rtx_MEM (smode, mem);
   4492 	  MEM_NOTRAP_P (mem) = 1;
   4493 	  set_mem_alias_set (mem, set);
   4494 	  set_mem_align (mem, GET_MODE_ALIGNMENT (smode));
   4495 
   4496 	  emit_move_insn (mem, gen_rtx_REG (smode, GET_SSE_REGNO (i)));
   4497 	}
   4498 
   4499       emit_label (label);
   4500     }
   4501 }
   4502 
   4503 static void
   4504 setup_incoming_varargs_ms_64 (CUMULATIVE_ARGS *cum)
   4505 {
   4506   alias_set_type set = get_varargs_alias_set ();
   4507   int i;
   4508 
   4509   /* Reset to zero, as there might be a sysv vaarg used
   4510      before.  */
   4511   ix86_varargs_gpr_size = 0;
   4512   ix86_varargs_fpr_size = 0;
   4513 
   4514   for (i = cum->regno; i < X86_64_MS_REGPARM_MAX; i++)
   4515     {
   4516       rtx reg, mem;
   4517 
   4518       mem = gen_rtx_MEM (Pmode,
   4519 			 plus_constant (Pmode, virtual_incoming_args_rtx,
   4520 					i * UNITS_PER_WORD));
   4521       MEM_NOTRAP_P (mem) = 1;
   4522       set_mem_alias_set (mem, set);
   4523 
   4524       reg = gen_rtx_REG (Pmode, x86_64_ms_abi_int_parameter_registers[i]);
   4525       emit_move_insn (mem, reg);
   4526     }
   4527 }
   4528 
   4529 static void
   4530 ix86_setup_incoming_varargs (cumulative_args_t cum_v,
   4531 			     const function_arg_info &arg,
   4532 			     int *, int no_rtl)
   4533 {
   4534   CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
   4535   CUMULATIVE_ARGS next_cum;
   4536   tree fntype;
   4537 
   4538   /* This argument doesn't appear to be used anymore.  Which is good,
   4539      because the old code here didn't suppress rtl generation.  */
   4540   gcc_assert (!no_rtl);
   4541 
   4542   if (!TARGET_64BIT)
   4543     return;
   4544 
   4545   fntype = TREE_TYPE (current_function_decl);
   4546 
   4547   /* For varargs, we do not want to skip the dummy va_dcl argument.
   4548      For stdargs, we do want to skip the last named argument.  */
   4549   next_cum = *cum;
   4550   if (stdarg_p (fntype))
   4551     ix86_function_arg_advance (pack_cumulative_args (&next_cum), arg);
   4552 
   4553   if (cum->call_abi == MS_ABI)
   4554     setup_incoming_varargs_ms_64 (&next_cum);
   4555   else
   4556     setup_incoming_varargs_64 (&next_cum);
   4557 }
   4558 
   4559 /* Checks if TYPE is of kind va_list char *.  */
   4560 
   4561 static bool
   4562 is_va_list_char_pointer (tree type)
   4563 {
   4564   tree canonic;
   4565 
   4566   /* For 32-bit it is always true.  */
   4567   if (!TARGET_64BIT)
   4568     return true;
   4569   canonic = ix86_canonical_va_list_type (type);
   4570   return (canonic == ms_va_list_type_node
   4571           || (ix86_abi == MS_ABI && canonic == va_list_type_node));
   4572 }
   4573 
   4574 /* Implement va_start.  */
   4575 
   4576 static void
   4577 ix86_va_start (tree valist, rtx nextarg)
   4578 {
   4579   HOST_WIDE_INT words, n_gpr, n_fpr;
   4580   tree f_gpr, f_fpr, f_ovf, f_sav;
   4581   tree gpr, fpr, ovf, sav, t;
   4582   tree type;
   4583   rtx ovf_rtx;
   4584 
   4585   if (flag_split_stack
   4586       && cfun->machine->split_stack_varargs_pointer == NULL_RTX)
   4587     {
   4588       unsigned int scratch_regno;
   4589 
   4590       /* When we are splitting the stack, we can't refer to the stack
   4591 	 arguments using internal_arg_pointer, because they may be on
   4592 	 the old stack.  The split stack prologue will arrange to
   4593 	 leave a pointer to the old stack arguments in a scratch
   4594 	 register, which we here copy to a pseudo-register.  The split
   4595 	 stack prologue can't set the pseudo-register directly because
   4596 	 it (the prologue) runs before any registers have been saved.  */
   4597 
   4598       scratch_regno = split_stack_prologue_scratch_regno ();
   4599       if (scratch_regno != INVALID_REGNUM)
   4600 	{
   4601 	  rtx reg;
   4602 	  rtx_insn *seq;
   4603 
   4604 	  reg = gen_reg_rtx (Pmode);
   4605 	  cfun->machine->split_stack_varargs_pointer = reg;
   4606 
   4607 	  start_sequence ();
   4608 	  emit_move_insn (reg, gen_rtx_REG (Pmode, scratch_regno));
   4609 	  seq = get_insns ();
   4610 	  end_sequence ();
   4611 
   4612 	  push_topmost_sequence ();
   4613 	  emit_insn_after (seq, entry_of_function ());
   4614 	  pop_topmost_sequence ();
   4615 	}
   4616     }
   4617 
   4618   /* Only 64bit target needs something special.  */
   4619   if (is_va_list_char_pointer (TREE_TYPE (valist)))
   4620     {
   4621       if (cfun->machine->split_stack_varargs_pointer == NULL_RTX)
   4622 	std_expand_builtin_va_start (valist, nextarg);
   4623       else
   4624 	{
   4625 	  rtx va_r, next;
   4626 
   4627 	  va_r = expand_expr (valist, NULL_RTX, VOIDmode, EXPAND_WRITE);
   4628 	  next = expand_binop (ptr_mode, add_optab,
   4629 			       cfun->machine->split_stack_varargs_pointer,
   4630 			       crtl->args.arg_offset_rtx,
   4631 			       NULL_RTX, 0, OPTAB_LIB_WIDEN);
   4632 	  convert_move (va_r, next, 0);
   4633 	}
   4634       return;
   4635     }
   4636 
   4637   f_gpr = TYPE_FIELDS (TREE_TYPE (sysv_va_list_type_node));
   4638   f_fpr = DECL_CHAIN (f_gpr);
   4639   f_ovf = DECL_CHAIN (f_fpr);
   4640   f_sav = DECL_CHAIN (f_ovf);
   4641 
   4642   valist = build_simple_mem_ref (valist);
   4643   TREE_TYPE (valist) = TREE_TYPE (sysv_va_list_type_node);
   4644   /* The following should be folded into the MEM_REF offset.  */
   4645   gpr = build3 (COMPONENT_REF, TREE_TYPE (f_gpr), unshare_expr (valist),
   4646 		f_gpr, NULL_TREE);
   4647   fpr = build3 (COMPONENT_REF, TREE_TYPE (f_fpr), unshare_expr (valist),
   4648 		f_fpr, NULL_TREE);
   4649   ovf = build3 (COMPONENT_REF, TREE_TYPE (f_ovf), unshare_expr (valist),
   4650 		f_ovf, NULL_TREE);
   4651   sav = build3 (COMPONENT_REF, TREE_TYPE (f_sav), unshare_expr (valist),
   4652 		f_sav, NULL_TREE);
   4653 
   4654   /* Count number of gp and fp argument registers used.  */
   4655   words = crtl->args.info.words;
   4656   n_gpr = crtl->args.info.regno;
   4657   n_fpr = crtl->args.info.sse_regno;
   4658 
   4659   if (cfun->va_list_gpr_size)
   4660     {
   4661       type = TREE_TYPE (gpr);
   4662       t = build2 (MODIFY_EXPR, type,
   4663 		  gpr, build_int_cst (type, n_gpr * 8));
   4664       TREE_SIDE_EFFECTS (t) = 1;
   4665       expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
   4666     }
   4667 
   4668   if (TARGET_SSE && cfun->va_list_fpr_size)
   4669     {
   4670       type = TREE_TYPE (fpr);
   4671       t = build2 (MODIFY_EXPR, type, fpr,
   4672 		  build_int_cst (type, n_fpr * 16 + 8*X86_64_REGPARM_MAX));
   4673       TREE_SIDE_EFFECTS (t) = 1;
   4674       expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
   4675     }
   4676 
   4677   /* Find the overflow area.  */
   4678   type = TREE_TYPE (ovf);
   4679   if (cfun->machine->split_stack_varargs_pointer == NULL_RTX)
   4680     ovf_rtx = crtl->args.internal_arg_pointer;
   4681   else
   4682     ovf_rtx = cfun->machine->split_stack_varargs_pointer;
   4683   t = make_tree (type, ovf_rtx);
   4684   if (words != 0)
   4685     t = fold_build_pointer_plus_hwi (t, words * UNITS_PER_WORD);
   4686 
   4687   t = build2 (MODIFY_EXPR, type, ovf, t);
   4688   TREE_SIDE_EFFECTS (t) = 1;
   4689   expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
   4690 
   4691   if (ix86_varargs_gpr_size || ix86_varargs_fpr_size)
   4692     {
   4693       /* Find the register save area.
   4694 	 Prologue of the function save it right above stack frame.  */
   4695       type = TREE_TYPE (sav);
   4696       t = make_tree (type, frame_pointer_rtx);
   4697       if (!ix86_varargs_gpr_size)
   4698 	t = fold_build_pointer_plus_hwi (t, -8 * X86_64_REGPARM_MAX);
   4699 
   4700       t = build2 (MODIFY_EXPR, type, sav, t);
   4701       TREE_SIDE_EFFECTS (t) = 1;
   4702       expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
   4703     }
   4704 }
   4705 
   4706 /* Implement va_arg.  */
   4707 
   4708 static tree
   4709 ix86_gimplify_va_arg (tree valist, tree type, gimple_seq *pre_p,
   4710 		      gimple_seq *post_p)
   4711 {
   4712   static const int intreg[6] = { 0, 1, 2, 3, 4, 5 };
   4713   tree f_gpr, f_fpr, f_ovf, f_sav;
   4714   tree gpr, fpr, ovf, sav, t;
   4715   int size, rsize;
   4716   tree lab_false, lab_over = NULL_TREE;
   4717   tree addr, t2;
   4718   rtx container;
   4719   int indirect_p = 0;
   4720   tree ptrtype;
   4721   machine_mode nat_mode;
   4722   unsigned int arg_boundary;
   4723   unsigned int type_align;
   4724 
   4725   /* Only 64bit target needs something special.  */
   4726   if (is_va_list_char_pointer (TREE_TYPE (valist)))
   4727     return std_gimplify_va_arg_expr (valist, type, pre_p, post_p);
   4728 
   4729   f_gpr = TYPE_FIELDS (TREE_TYPE (sysv_va_list_type_node));
   4730   f_fpr = DECL_CHAIN (f_gpr);
   4731   f_ovf = DECL_CHAIN (f_fpr);
   4732   f_sav = DECL_CHAIN (f_ovf);
   4733 
   4734   gpr = build3 (COMPONENT_REF, TREE_TYPE (f_gpr),
   4735 		valist, f_gpr, NULL_TREE);
   4736 
   4737   fpr = build3 (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr, NULL_TREE);
   4738   ovf = build3 (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf, NULL_TREE);
   4739   sav = build3 (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav, NULL_TREE);
   4740 
   4741   indirect_p = pass_va_arg_by_reference (type);
   4742   if (indirect_p)
   4743     type = build_pointer_type (type);
   4744   size = arg_int_size_in_bytes (type);
   4745   rsize = CEIL (size, UNITS_PER_WORD);
   4746 
   4747   nat_mode = type_natural_mode (type, NULL, false);
   4748   switch (nat_mode)
   4749     {
   4750     case E_V16HFmode:
   4751     case E_V8SFmode:
   4752     case E_V8SImode:
   4753     case E_V32QImode:
   4754     case E_V16HImode:
   4755     case E_V4DFmode:
   4756     case E_V4DImode:
   4757     case E_V32HFmode:
   4758     case E_V16SFmode:
   4759     case E_V16SImode:
   4760     case E_V64QImode:
   4761     case E_V32HImode:
   4762     case E_V8DFmode:
   4763     case E_V8DImode:
   4764       /* Unnamed 256 and 512bit vector mode parameters are passed on stack.  */
   4765       if (!TARGET_64BIT_MS_ABI)
   4766 	{
   4767 	  container = NULL;
   4768 	  break;
   4769 	}
   4770       /* FALLTHRU */
   4771 
   4772     default:
   4773       container = construct_container (nat_mode, TYPE_MODE (type),
   4774 				       type, 0, X86_64_REGPARM_MAX,
   4775 				       X86_64_SSE_REGPARM_MAX, intreg,
   4776 				       0);
   4777       break;
   4778     }
   4779 
   4780   /* Pull the value out of the saved registers.  */
   4781 
   4782   addr = create_tmp_var (ptr_type_node, "addr");
   4783   type_align = TYPE_ALIGN (type);
   4784 
   4785   if (container)
   4786     {
   4787       int needed_intregs, needed_sseregs;
   4788       bool need_temp;
   4789       tree int_addr, sse_addr;
   4790 
   4791       lab_false = create_artificial_label (UNKNOWN_LOCATION);
   4792       lab_over = create_artificial_label (UNKNOWN_LOCATION);
   4793 
   4794       examine_argument (nat_mode, type, 0, &needed_intregs, &needed_sseregs);
   4795 
   4796       bool container_in_reg = false;
   4797       if (REG_P (container))
   4798 	container_in_reg = true;
   4799       else if (GET_CODE (container) == PARALLEL
   4800 	       && GET_MODE (container) == BLKmode
   4801 	       && XVECLEN (container, 0) == 1)
   4802 	{
   4803 	  /* Check if it is a PARALLEL BLKmode container of an EXPR_LIST
   4804 	     expression in a TImode register.  In this case, temp isn't
   4805 	     needed.  Otherwise, the TImode variable will be put in the
   4806 	     GPR save area which guarantees only 8-byte alignment.   */
   4807 	  rtx x = XVECEXP (container, 0, 0);
   4808 	  if (GET_CODE (x) == EXPR_LIST
   4809 	      && REG_P (XEXP (x, 0))
   4810 	      && XEXP (x, 1) == const0_rtx)
   4811 	    container_in_reg = true;
   4812 	}
   4813 
   4814       need_temp = (!container_in_reg
   4815 		   && ((needed_intregs && TYPE_ALIGN (type) > 64)
   4816 		       || TYPE_ALIGN (type) > 128));
   4817 
   4818       /* In case we are passing structure, verify that it is consecutive block
   4819          on the register save area.  If not we need to do moves.  */
   4820       if (!need_temp && !container_in_reg)
   4821 	{
   4822 	  /* Verify that all registers are strictly consecutive  */
   4823 	  if (SSE_REGNO_P (REGNO (XEXP (XVECEXP (container, 0, 0), 0))))
   4824 	    {
   4825 	      int i;
   4826 
   4827 	      for (i = 0; i < XVECLEN (container, 0) && !need_temp; i++)
   4828 		{
   4829 		  rtx slot = XVECEXP (container, 0, i);
   4830 		  if (REGNO (XEXP (slot, 0)) != FIRST_SSE_REG + (unsigned int) i
   4831 		      || INTVAL (XEXP (slot, 1)) != i * 16)
   4832 		    need_temp = true;
   4833 		}
   4834 	    }
   4835 	  else
   4836 	    {
   4837 	      int i;
   4838 
   4839 	      for (i = 0; i < XVECLEN (container, 0) && !need_temp; i++)
   4840 		{
   4841 		  rtx slot = XVECEXP (container, 0, i);
   4842 		  if (REGNO (XEXP (slot, 0)) != (unsigned int) i
   4843 		      || INTVAL (XEXP (slot, 1)) != i * 8)
   4844 		    need_temp = true;
   4845 		}
   4846 	    }
   4847 	}
   4848       if (!need_temp)
   4849 	{
   4850 	  int_addr = addr;
   4851 	  sse_addr = addr;
   4852 	}
   4853       else
   4854 	{
   4855 	  int_addr = create_tmp_var (ptr_type_node, "int_addr");
   4856 	  sse_addr = create_tmp_var (ptr_type_node, "sse_addr");
   4857 	}
   4858 
   4859       /* First ensure that we fit completely in registers.  */
   4860       if (needed_intregs)
   4861 	{
   4862 	  t = build_int_cst (TREE_TYPE (gpr),
   4863 			     (X86_64_REGPARM_MAX - needed_intregs + 1) * 8);
   4864 	  t = build2 (GE_EXPR, boolean_type_node, gpr, t);
   4865 	  t2 = build1 (GOTO_EXPR, void_type_node, lab_false);
   4866 	  t = build3 (COND_EXPR, void_type_node, t, t2, NULL_TREE);
   4867 	  gimplify_and_add (t, pre_p);
   4868 	}
   4869       if (needed_sseregs)
   4870 	{
   4871 	  t = build_int_cst (TREE_TYPE (fpr),
   4872 			     (X86_64_SSE_REGPARM_MAX - needed_sseregs + 1) * 16
   4873 			     + X86_64_REGPARM_MAX * 8);
   4874 	  t = build2 (GE_EXPR, boolean_type_node, fpr, t);
   4875 	  t2 = build1 (GOTO_EXPR, void_type_node, lab_false);
   4876 	  t = build3 (COND_EXPR, void_type_node, t, t2, NULL_TREE);
   4877 	  gimplify_and_add (t, pre_p);
   4878 	}
   4879 
   4880       /* Compute index to start of area used for integer regs.  */
   4881       if (needed_intregs)
   4882 	{
   4883 	  /* int_addr = gpr + sav; */
   4884 	  t = fold_build_pointer_plus (sav, gpr);
   4885 	  gimplify_assign (int_addr, t, pre_p);
   4886 	}
   4887       if (needed_sseregs)
   4888 	{
   4889 	  /* sse_addr = fpr + sav; */
   4890 	  t = fold_build_pointer_plus (sav, fpr);
   4891 	  gimplify_assign (sse_addr, t, pre_p);
   4892 	}
   4893       if (need_temp)
   4894 	{
   4895 	  int i, prev_size = 0;
   4896 	  tree temp = create_tmp_var (type, "va_arg_tmp");
   4897 	  TREE_ADDRESSABLE (temp) = 1;
   4898 
   4899 	  /* addr = &temp; */
   4900 	  t = build1 (ADDR_EXPR, build_pointer_type (type), temp);
   4901 	  gimplify_assign (addr, t, pre_p);
   4902 
   4903 	  for (i = 0; i < XVECLEN (container, 0); i++)
   4904 	    {
   4905 	      rtx slot = XVECEXP (container, 0, i);
   4906 	      rtx reg = XEXP (slot, 0);
   4907 	      machine_mode mode = GET_MODE (reg);
   4908 	      tree piece_type;
   4909 	      tree addr_type;
   4910 	      tree daddr_type;
   4911 	      tree src_addr, src;
   4912 	      int src_offset;
   4913 	      tree dest_addr, dest;
   4914 	      int cur_size = GET_MODE_SIZE (mode);
   4915 
   4916 	      gcc_assert (prev_size <= INTVAL (XEXP (slot, 1)));
   4917 	      prev_size = INTVAL (XEXP (slot, 1));
   4918 	      if (prev_size + cur_size > size)
   4919 		{
   4920 		  cur_size = size - prev_size;
   4921 		  unsigned int nbits = cur_size * BITS_PER_UNIT;
   4922 		  if (!int_mode_for_size (nbits, 1).exists (&mode))
   4923 		    mode = QImode;
   4924 		}
   4925 	      piece_type = lang_hooks.types.type_for_mode (mode, 1);
   4926 	      if (mode == GET_MODE (reg))
   4927 		addr_type = build_pointer_type (piece_type);
   4928 	      else
   4929 		addr_type = build_pointer_type_for_mode (piece_type, ptr_mode,
   4930 							 true);
   4931 	      daddr_type = build_pointer_type_for_mode (piece_type, ptr_mode,
   4932 							true);
   4933 
   4934 	      if (SSE_REGNO_P (REGNO (reg)))
   4935 		{
   4936 		  src_addr = sse_addr;
   4937 		  src_offset = (REGNO (reg) - FIRST_SSE_REG) * 16;
   4938 		}
   4939 	      else
   4940 		{
   4941 		  src_addr = int_addr;
   4942 		  src_offset = REGNO (reg) * 8;
   4943 		}
   4944 	      src_addr = fold_convert (addr_type, src_addr);
   4945 	      src_addr = fold_build_pointer_plus_hwi (src_addr, src_offset);
   4946 
   4947 	      dest_addr = fold_convert (daddr_type, addr);
   4948 	      dest_addr = fold_build_pointer_plus_hwi (dest_addr, prev_size);
   4949 	      if (cur_size == GET_MODE_SIZE (mode))
   4950 		{
   4951 		  src = build_va_arg_indirect_ref (src_addr);
   4952 		  dest = build_va_arg_indirect_ref (dest_addr);
   4953 
   4954 		  gimplify_assign (dest, src, pre_p);
   4955 		}
   4956 	      else
   4957 		{
   4958 		  tree copy
   4959 		    = build_call_expr (builtin_decl_implicit (BUILT_IN_MEMCPY),
   4960 				       3, dest_addr, src_addr,
   4961 				       size_int (cur_size));
   4962 		  gimplify_and_add (copy, pre_p);
   4963 		}
   4964 	      prev_size += cur_size;
   4965 	    }
   4966 	}
   4967 
   4968       if (needed_intregs)
   4969 	{
   4970 	  t = build2 (PLUS_EXPR, TREE_TYPE (gpr), gpr,
   4971 		      build_int_cst (TREE_TYPE (gpr), needed_intregs * 8));
   4972 	  gimplify_assign (gpr, t, pre_p);
   4973 	  /* The GPR save area guarantees only 8-byte alignment.  */
   4974 	  if (!need_temp)
   4975 	    type_align = MIN (type_align, 64);
   4976 	}
   4977 
   4978       if (needed_sseregs)
   4979 	{
   4980 	  t = build2 (PLUS_EXPR, TREE_TYPE (fpr), fpr,
   4981 		      build_int_cst (TREE_TYPE (fpr), needed_sseregs * 16));
   4982 	  gimplify_assign (unshare_expr (fpr), t, pre_p);
   4983 	}
   4984 
   4985       gimple_seq_add_stmt (pre_p, gimple_build_goto (lab_over));
   4986 
   4987       gimple_seq_add_stmt (pre_p, gimple_build_label (lab_false));
   4988     }
   4989 
   4990   /* ... otherwise out of the overflow area.  */
   4991 
   4992   /* When we align parameter on stack for caller, if the parameter
   4993      alignment is beyond MAX_SUPPORTED_STACK_ALIGNMENT, it will be
   4994      aligned at MAX_SUPPORTED_STACK_ALIGNMENT.  We will match callee
   4995      here with caller.  */
   4996   arg_boundary = ix86_function_arg_boundary (VOIDmode, type);
   4997   if ((unsigned int) arg_boundary > MAX_SUPPORTED_STACK_ALIGNMENT)
   4998     arg_boundary = MAX_SUPPORTED_STACK_ALIGNMENT;
   4999 
   5000   /* Care for on-stack alignment if needed.  */
   5001   if (arg_boundary <= 64 || size == 0)
   5002     t = ovf;
   5003  else
   5004     {
   5005       HOST_WIDE_INT align = arg_boundary / 8;
   5006       t = fold_build_pointer_plus_hwi (ovf, align - 1);
   5007       t = build2 (BIT_AND_EXPR, TREE_TYPE (t), t,
   5008 		  build_int_cst (TREE_TYPE (t), -align));
   5009     }
   5010 
   5011   gimplify_expr (&t, pre_p, NULL, is_gimple_val, fb_rvalue);
   5012   gimplify_assign (addr, t, pre_p);
   5013 
   5014   t = fold_build_pointer_plus_hwi (t, rsize * UNITS_PER_WORD);
   5015   gimplify_assign (unshare_expr (ovf), t, pre_p);
   5016 
   5017   if (container)
   5018     gimple_seq_add_stmt (pre_p, gimple_build_label (lab_over));
   5019 
   5020   type = build_aligned_type (type, type_align);
   5021   ptrtype = build_pointer_type_for_mode (type, ptr_mode, true);
   5022   addr = fold_convert (ptrtype, addr);
   5023 
   5024   if (indirect_p)
   5025     addr = build_va_arg_indirect_ref (addr);
   5026   return build_va_arg_indirect_ref (addr);
   5027 }
   5028 
   5029 /* Return true if OPNUM's MEM should be matched
   5031    in movabs* patterns.  */
   5032 
   5033 bool
   5034 ix86_check_movabs (rtx insn, int opnum)
   5035 {
   5036   rtx set, mem;
   5037 
   5038   set = PATTERN (insn);
   5039   if (GET_CODE (set) == PARALLEL)
   5040     set = XVECEXP (set, 0, 0);
   5041   gcc_assert (GET_CODE (set) == SET);
   5042   mem = XEXP (set, opnum);
   5043   while (SUBREG_P (mem))
   5044     mem = SUBREG_REG (mem);
   5045   gcc_assert (MEM_P (mem));
   5046   return volatile_ok || !MEM_VOLATILE_P (mem);
   5047 }
   5048 
   5049 /* Return false if INSN contains a MEM with a non-default address space.  */
   5050 bool
   5051 ix86_check_no_addr_space (rtx insn)
   5052 {
   5053   subrtx_var_iterator::array_type array;
   5054   FOR_EACH_SUBRTX_VAR (iter, array, PATTERN (insn), ALL)
   5055     {
   5056       rtx x = *iter;
   5057       if (MEM_P (x) && !ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (x)))
   5058 	return false;
   5059     }
   5060   return true;
   5061 }
   5062 
   5063 /* Initialize the table of extra 80387 mathematical constants.  */
   5065 
   5066 static void
   5067 init_ext_80387_constants (void)
   5068 {
   5069   static const char * cst[5] =
   5070   {
   5071     "0.3010299956639811952256464283594894482",  /* 0: fldlg2  */
   5072     "0.6931471805599453094286904741849753009",  /* 1: fldln2  */
   5073     "1.4426950408889634073876517827983434472",  /* 2: fldl2e  */
   5074     "3.3219280948873623478083405569094566090",  /* 3: fldl2t  */
   5075     "3.1415926535897932385128089594061862044",  /* 4: fldpi   */
   5076   };
   5077   int i;
   5078 
   5079   for (i = 0; i < 5; i++)
   5080     {
   5081       real_from_string (&ext_80387_constants_table[i], cst[i]);
   5082       /* Ensure each constant is rounded to XFmode precision.  */
   5083       real_convert (&ext_80387_constants_table[i],
   5084 		    XFmode, &ext_80387_constants_table[i]);
   5085     }
   5086 
   5087   ext_80387_constants_init = 1;
   5088 }
   5089 
   5090 /* Return non-zero if the constant is something that
   5091    can be loaded with a special instruction.  */
   5092 
   5093 int
   5094 standard_80387_constant_p (rtx x)
   5095 {
   5096   machine_mode mode = GET_MODE (x);
   5097 
   5098   const REAL_VALUE_TYPE *r;
   5099 
   5100   if (!(CONST_DOUBLE_P (x) && X87_FLOAT_MODE_P (mode)))
   5101     return -1;
   5102 
   5103   if (x == CONST0_RTX (mode))
   5104     return 1;
   5105   if (x == CONST1_RTX (mode))
   5106     return 2;
   5107 
   5108   r = CONST_DOUBLE_REAL_VALUE (x);
   5109 
   5110   /* For XFmode constants, try to find a special 80387 instruction when
   5111      optimizing for size or on those CPUs that benefit from them.  */
   5112   if (mode == XFmode
   5113       && (optimize_function_for_size_p (cfun) || TARGET_EXT_80387_CONSTANTS)
   5114       && !flag_rounding_math)
   5115     {
   5116       int i;
   5117 
   5118       if (! ext_80387_constants_init)
   5119 	init_ext_80387_constants ();
   5120 
   5121       for (i = 0; i < 5; i++)
   5122         if (real_identical (r, &ext_80387_constants_table[i]))
   5123 	  return i + 3;
   5124     }
   5125 
   5126   /* Load of the constant -0.0 or -1.0 will be split as
   5127      fldz;fchs or fld1;fchs sequence.  */
   5128   if (real_isnegzero (r))
   5129     return 8;
   5130   if (real_identical (r, &dconstm1))
   5131     return 9;
   5132 
   5133   return 0;
   5134 }
   5135 
   5136 /* Return the opcode of the special instruction to be used to load
   5137    the constant X.  */
   5138 
   5139 const char *
   5140 standard_80387_constant_opcode (rtx x)
   5141 {
   5142   switch (standard_80387_constant_p (x))
   5143     {
   5144     case 1:
   5145       return "fldz";
   5146     case 2:
   5147       return "fld1";
   5148     case 3:
   5149       return "fldlg2";
   5150     case 4:
   5151       return "fldln2";
   5152     case 5:
   5153       return "fldl2e";
   5154     case 6:
   5155       return "fldl2t";
   5156     case 7:
   5157       return "fldpi";
   5158     case 8:
   5159     case 9:
   5160       return "#";
   5161     default:
   5162       gcc_unreachable ();
   5163     }
   5164 }
   5165 
   5166 /* Return the CONST_DOUBLE representing the 80387 constant that is
   5167    loaded by the specified special instruction.  The argument IDX
   5168    matches the return value from standard_80387_constant_p.  */
   5169 
   5170 rtx
   5171 standard_80387_constant_rtx (int idx)
   5172 {
   5173   int i;
   5174 
   5175   if (! ext_80387_constants_init)
   5176     init_ext_80387_constants ();
   5177 
   5178   switch (idx)
   5179     {
   5180     case 3:
   5181     case 4:
   5182     case 5:
   5183     case 6:
   5184     case 7:
   5185       i = idx - 3;
   5186       break;
   5187 
   5188     default:
   5189       gcc_unreachable ();
   5190     }
   5191 
   5192   return const_double_from_real_value (ext_80387_constants_table[i],
   5193 				       XFmode);
   5194 }
   5195 
   5196 /* Return 1 if X is all bits 0 and 2 if X is all bits 1
   5197    in supported SSE/AVX vector mode.  */
   5198 
   5199 int
   5200 standard_sse_constant_p (rtx x, machine_mode pred_mode)
   5201 {
   5202   machine_mode mode;
   5203 
   5204   if (!TARGET_SSE)
   5205     return 0;
   5206 
   5207   mode = GET_MODE (x);
   5208 
   5209   if (x == const0_rtx || const0_operand (x, mode))
   5210     return 1;
   5211 
   5212   if (x == constm1_rtx
   5213       || vector_all_ones_operand (x, mode)
   5214       || ((GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT
   5215 	   || GET_MODE_CLASS (pred_mode) == MODE_VECTOR_FLOAT)
   5216 	  && float_vector_all_ones_operand (x, mode)))
   5217     {
   5218       /* VOIDmode integer constant, get mode from the predicate.  */
   5219       if (mode == VOIDmode)
   5220 	mode = pred_mode;
   5221 
   5222       switch (GET_MODE_SIZE (mode))
   5223 	{
   5224 	case 64:
   5225 	  if (TARGET_AVX512F)
   5226 	    return 2;
   5227 	  break;
   5228 	case 32:
   5229 	  if (TARGET_AVX2)
   5230 	    return 2;
   5231 	  break;
   5232 	case 16:
   5233 	  if (TARGET_SSE2)
   5234 	    return 2;
   5235 	  break;
   5236 	case 0:
   5237 	  /* VOIDmode */
   5238 	  gcc_unreachable ();
   5239 	default:
   5240 	  break;
   5241 	}
   5242     }
   5243 
   5244   return 0;
   5245 }
   5246 
   5247 /* Return the opcode of the special instruction to be used to load
   5248    the constant operands[1] into operands[0].  */
   5249 
   5250 const char *
   5251 standard_sse_constant_opcode (rtx_insn *insn, rtx *operands)
   5252 {
   5253   machine_mode mode;
   5254   rtx x = operands[1];
   5255 
   5256   gcc_assert (TARGET_SSE);
   5257 
   5258   mode = GET_MODE (x);
   5259 
   5260   if (x == const0_rtx || const0_operand (x, mode))
   5261     {
   5262       switch (get_attr_mode (insn))
   5263 	{
   5264 	case MODE_TI:
   5265 	  if (!EXT_REX_SSE_REG_P (operands[0]))
   5266 	    return "%vpxor\t%0, %d0";
   5267 	  /* FALLTHRU */
   5268 	case MODE_XI:
   5269 	case MODE_OI:
   5270 	  if (EXT_REX_SSE_REG_P (operands[0]))
   5271 	    return (TARGET_AVX512VL
   5272 		    ? "vpxord\t%x0, %x0, %x0"
   5273 		    : "vpxord\t%g0, %g0, %g0");
   5274 	  return "vpxor\t%x0, %x0, %x0";
   5275 
   5276 	case MODE_V2DF:
   5277 	  if (!EXT_REX_SSE_REG_P (operands[0]))
   5278 	    return "%vxorpd\t%0, %d0";
   5279 	  /* FALLTHRU */
   5280 	case MODE_V8DF:
   5281 	case MODE_V4DF:
   5282 	  if (!EXT_REX_SSE_REG_P (operands[0]))
   5283 	    return "vxorpd\t%x0, %x0, %x0";
   5284 	  else if (TARGET_AVX512DQ)
   5285 	    return (TARGET_AVX512VL
   5286 		    ? "vxorpd\t%x0, %x0, %x0"
   5287 		    : "vxorpd\t%g0, %g0, %g0");
   5288 	  else
   5289 	    return (TARGET_AVX512VL
   5290 		    ? "vpxorq\t%x0, %x0, %x0"
   5291 		    : "vpxorq\t%g0, %g0, %g0");
   5292 
   5293 	case MODE_V4SF:
   5294 	  if (!EXT_REX_SSE_REG_P (operands[0]))
   5295 	    return "%vxorps\t%0, %d0";
   5296 	  /* FALLTHRU */
   5297 	case MODE_V16SF:
   5298 	case MODE_V8SF:
   5299 	  if (!EXT_REX_SSE_REG_P (operands[0]))
   5300 	    return "vxorps\t%x0, %x0, %x0";
   5301 	  else if (TARGET_AVX512DQ)
   5302 	    return (TARGET_AVX512VL
   5303 		    ? "vxorps\t%x0, %x0, %x0"
   5304 		    : "vxorps\t%g0, %g0, %g0");
   5305 	  else
   5306 	    return (TARGET_AVX512VL
   5307 		    ? "vpxord\t%x0, %x0, %x0"
   5308 		    : "vpxord\t%g0, %g0, %g0");
   5309 
   5310 	default:
   5311 	  gcc_unreachable ();
   5312 	}
   5313     }
   5314   else if (x == constm1_rtx
   5315 	   || vector_all_ones_operand (x, mode)
   5316 	   || (GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT
   5317 	       && float_vector_all_ones_operand (x, mode)))
   5318     {
   5319       enum attr_mode insn_mode = get_attr_mode (insn);
   5320 
   5321       switch (insn_mode)
   5322 	{
   5323 	case MODE_XI:
   5324 	case MODE_V8DF:
   5325 	case MODE_V16SF:
   5326 	  gcc_assert (TARGET_AVX512F);
   5327 	  return "vpternlogd\t{$0xFF, %g0, %g0, %g0|%g0, %g0, %g0, 0xFF}";
   5328 
   5329 	case MODE_OI:
   5330 	case MODE_V4DF:
   5331 	case MODE_V8SF:
   5332 	  gcc_assert (TARGET_AVX2);
   5333 	  /* FALLTHRU */
   5334 	case MODE_TI:
   5335 	case MODE_V2DF:
   5336 	case MODE_V4SF:
   5337 	  gcc_assert (TARGET_SSE2);
   5338 	  if (!EXT_REX_SSE_REG_P (operands[0]))
   5339 	    return (TARGET_AVX
   5340 		    ? "vpcmpeqd\t%0, %0, %0"
   5341 		    : "pcmpeqd\t%0, %0");
   5342 	  else if (TARGET_AVX512VL)
   5343 	    return "vpternlogd\t{$0xFF, %0, %0, %0|%0, %0, %0, 0xFF}";
   5344 	  else
   5345 	    return "vpternlogd\t{$0xFF, %g0, %g0, %g0|%g0, %g0, %g0, 0xFF}";
   5346 
   5347 	default:
   5348 	  gcc_unreachable ();
   5349 	}
   5350    }
   5351 
   5352   gcc_unreachable ();
   5353 }
   5354 
   5355 /* Returns true if INSN can be transformed from a memory load
   5356    to a supported FP constant load.  */
   5357 
   5358 bool
   5359 ix86_standard_x87sse_constant_load_p (const rtx_insn *insn, rtx dst)
   5360 {
   5361   rtx src = find_constant_src (insn);
   5362 
   5363   gcc_assert (REG_P (dst));
   5364 
   5365   if (src == NULL
   5366       || (SSE_REGNO_P (REGNO (dst))
   5367 	  && standard_sse_constant_p (src, GET_MODE (dst)) != 1)
   5368       || (STACK_REGNO_P (REGNO (dst))
   5369 	   && standard_80387_constant_p (src) < 1))
   5370     return false;
   5371 
   5372   return true;
   5373 }
   5374 
   5375 /* Predicate for pre-reload splitters with associated instructions,
   5376    which can match any time before the split1 pass (usually combine),
   5377    then are unconditionally split in that pass and should not be
   5378    matched again afterwards.  */
   5379 
   5380 bool
   5381 ix86_pre_reload_split (void)
   5382 {
   5383   return (can_create_pseudo_p ()
   5384 	  && !(cfun->curr_properties & PROP_rtl_split_insns));
   5385 }
   5386 
   5387 /* Return the opcode of the TYPE_SSEMOV instruction.  To move from
   5388    or to xmm16-xmm31/ymm16-ymm31 registers, we either require
   5389    TARGET_AVX512VL or it is a register to register move which can
   5390    be done with zmm register move. */
   5391 
   5392 static const char *
   5393 ix86_get_ssemov (rtx *operands, unsigned size,
   5394 		 enum attr_mode insn_mode, machine_mode mode)
   5395 {
   5396   char buf[128];
   5397   bool misaligned_p = (misaligned_operand (operands[0], mode)
   5398 		       || misaligned_operand (operands[1], mode));
   5399   bool evex_reg_p = (size == 64
   5400 		     || EXT_REX_SSE_REG_P (operands[0])
   5401 		     || EXT_REX_SSE_REG_P (operands[1]));
   5402   machine_mode scalar_mode;
   5403 
   5404   const char *opcode = NULL;
   5405   enum
   5406     {
   5407       opcode_int,
   5408       opcode_float,
   5409       opcode_double
   5410     } type = opcode_int;
   5411 
   5412   switch (insn_mode)
   5413     {
   5414     case MODE_V16SF:
   5415     case MODE_V8SF:
   5416     case MODE_V4SF:
   5417       scalar_mode = E_SFmode;
   5418       type = opcode_float;
   5419       break;
   5420     case MODE_V8DF:
   5421     case MODE_V4DF:
   5422     case MODE_V2DF:
   5423       scalar_mode = E_DFmode;
   5424       type = opcode_double;
   5425       break;
   5426     case MODE_XI:
   5427     case MODE_OI:
   5428     case MODE_TI:
   5429       scalar_mode = GET_MODE_INNER (mode);
   5430       break;
   5431     default:
   5432       gcc_unreachable ();
   5433     }
   5434 
   5435   /* NB: To move xmm16-xmm31/ymm16-ymm31 registers without AVX512VL,
   5436      we can only use zmm register move without memory operand.  */
   5437   if (evex_reg_p
   5438       && !TARGET_AVX512VL
   5439       && GET_MODE_SIZE (mode) < 64)
   5440     {
   5441       /* NB: Even though ix86_hard_regno_mode_ok doesn't allow
   5442 	 xmm16-xmm31 nor ymm16-ymm31 in 128/256 bit modes when
   5443 	 AVX512VL is disabled, LRA can still generate reg to
   5444 	 reg moves with xmm16-xmm31 and ymm16-ymm31 in 128/256 bit
   5445 	 modes.  */
   5446       if (memory_operand (operands[0], mode)
   5447 	  || memory_operand (operands[1], mode))
   5448 	gcc_unreachable ();
   5449       size = 64;
   5450       switch (type)
   5451 	{
   5452 	case opcode_int:
   5453 	  if (scalar_mode == E_HFmode)
   5454 	    opcode = (misaligned_p
   5455 		      ? (TARGET_AVX512BW ? "vmovdqu16" : "vmovdqu64")
   5456 		      : "vmovdqa64");
   5457 	  else
   5458 	    opcode = misaligned_p ? "vmovdqu32" : "vmovdqa32";
   5459 	  break;
   5460 	case opcode_float:
   5461 	  opcode = misaligned_p ? "vmovups" : "vmovaps";
   5462 	  break;
   5463 	case opcode_double:
   5464 	  opcode = misaligned_p ? "vmovupd" : "vmovapd";
   5465 	  break;
   5466 	}
   5467     }
   5468   else if (SCALAR_FLOAT_MODE_P (scalar_mode))
   5469     {
   5470       switch (scalar_mode)
   5471 	{
   5472 	case E_HFmode:
   5473 	  if (evex_reg_p)
   5474 	    opcode = (misaligned_p
   5475 		      ? (TARGET_AVX512BW
   5476 			 ? "vmovdqu16"
   5477 			 : "vmovdqu64")
   5478 		      : "vmovdqa64");
   5479 	  else
   5480 	    opcode = (misaligned_p
   5481 		      ? (TARGET_AVX512BW
   5482 			 ? "vmovdqu16"
   5483 			 : "%vmovdqu")
   5484 		      : "%vmovdqa");
   5485 	  break;
   5486 	case E_SFmode:
   5487 	  opcode = misaligned_p ? "%vmovups" : "%vmovaps";
   5488 	  break;
   5489 	case E_DFmode:
   5490 	  opcode = misaligned_p ? "%vmovupd" : "%vmovapd";
   5491 	  break;
   5492 	case E_TFmode:
   5493 	  if (evex_reg_p)
   5494 	    opcode = misaligned_p ? "vmovdqu64" : "vmovdqa64";
   5495 	  else
   5496 	    opcode = misaligned_p ? "%vmovdqu" : "%vmovdqa";
   5497 	  break;
   5498 	default:
   5499 	  gcc_unreachable ();
   5500 	}
   5501     }
   5502   else if (SCALAR_INT_MODE_P (scalar_mode))
   5503     {
   5504       switch (scalar_mode)
   5505 	{
   5506 	case E_QImode:
   5507 	  if (evex_reg_p)
   5508 	    opcode = (misaligned_p
   5509 		      ? (TARGET_AVX512BW
   5510 			 ? "vmovdqu8"
   5511 			 : "vmovdqu64")
   5512 		      : "vmovdqa64");
   5513 	  else
   5514 	    opcode = (misaligned_p
   5515 		      ? (TARGET_AVX512BW
   5516 			 ? "vmovdqu8"
   5517 			 : "%vmovdqu")
   5518 		      : "%vmovdqa");
   5519 	  break;
   5520 	case E_HImode:
   5521 	  if (evex_reg_p)
   5522 	    opcode = (misaligned_p
   5523 		      ? (TARGET_AVX512BW
   5524 			 ? "vmovdqu16"
   5525 			 : "vmovdqu64")
   5526 		      : "vmovdqa64");
   5527 	  else
   5528 	    opcode = (misaligned_p
   5529 		      ? (TARGET_AVX512BW
   5530 			 ? "vmovdqu16"
   5531 			 : "%vmovdqu")
   5532 		      : "%vmovdqa");
   5533 	  break;
   5534 	case E_SImode:
   5535 	  if (evex_reg_p)
   5536 	    opcode = misaligned_p ? "vmovdqu32" : "vmovdqa32";
   5537 	  else
   5538 	    opcode = misaligned_p ? "%vmovdqu" : "%vmovdqa";
   5539 	  break;
   5540 	case E_DImode:
   5541 	case E_TImode:
   5542 	case E_OImode:
   5543 	  if (evex_reg_p)
   5544 	    opcode = misaligned_p ? "vmovdqu64" : "vmovdqa64";
   5545 	  else
   5546 	    opcode = misaligned_p ? "%vmovdqu" : "%vmovdqa";
   5547 	  break;
   5548 	case E_XImode:
   5549 	  opcode = misaligned_p ? "vmovdqu64" : "vmovdqa64";
   5550 	  break;
   5551 	default:
   5552 	  gcc_unreachable ();
   5553 	}
   5554     }
   5555   else
   5556     gcc_unreachable ();
   5557 
   5558   switch (size)
   5559     {
   5560     case 64:
   5561       snprintf (buf, sizeof (buf), "%s\t{%%g1, %%g0|%%g0, %%g1}",
   5562 		opcode);
   5563       break;
   5564     case 32:
   5565       snprintf (buf, sizeof (buf), "%s\t{%%t1, %%t0|%%t0, %%t1}",
   5566 		opcode);
   5567       break;
   5568     case 16:
   5569       snprintf (buf, sizeof (buf), "%s\t{%%x1, %%x0|%%x0, %%x1}",
   5570 		opcode);
   5571       break;
   5572     default:
   5573       gcc_unreachable ();
   5574     }
   5575   output_asm_insn (buf, operands);
   5576   return "";
   5577 }
   5578 
   5579 /* Return the template of the TYPE_SSEMOV instruction to move
   5580    operands[1] into operands[0].  */
   5581 
   5582 const char *
   5583 ix86_output_ssemov (rtx_insn *insn, rtx *operands)
   5584 {
   5585   machine_mode mode = GET_MODE (operands[0]);
   5586   if (get_attr_type (insn) != TYPE_SSEMOV
   5587       || mode != GET_MODE (operands[1]))
   5588     gcc_unreachable ();
   5589 
   5590   enum attr_mode insn_mode = get_attr_mode (insn);
   5591 
   5592   switch (insn_mode)
   5593     {
   5594     case MODE_XI:
   5595     case MODE_V8DF:
   5596     case MODE_V16SF:
   5597       return ix86_get_ssemov (operands, 64, insn_mode, mode);
   5598 
   5599     case MODE_OI:
   5600     case MODE_V4DF:
   5601     case MODE_V8SF:
   5602       return ix86_get_ssemov (operands, 32, insn_mode, mode);
   5603 
   5604     case MODE_TI:
   5605     case MODE_V2DF:
   5606     case MODE_V4SF:
   5607       return ix86_get_ssemov (operands, 16, insn_mode, mode);
   5608 
   5609     case MODE_DI:
   5610       /* Handle broken assemblers that require movd instead of movq. */
   5611       if (GENERAL_REG_P (operands[0]))
   5612 	{
   5613 	  if (HAVE_AS_IX86_INTERUNIT_MOVQ)
   5614 	    return "%vmovq\t{%1, %q0|%q0, %1}";
   5615 	  else
   5616 	    return "%vmovd\t{%1, %q0|%q0, %1}";
   5617 	}
   5618       else if (GENERAL_REG_P (operands[1]))
   5619 	{
   5620 	  if (HAVE_AS_IX86_INTERUNIT_MOVQ)
   5621 	    return "%vmovq\t{%q1, %0|%0, %q1}";
   5622 	  else
   5623 	    return "%vmovd\t{%q1, %0|%0, %q1}";
   5624 	}
   5625       else
   5626 	return "%vmovq\t{%1, %0|%0, %1}";
   5627 
   5628     case MODE_SI:
   5629       if (GENERAL_REG_P (operands[0]))
   5630 	return "%vmovd\t{%1, %k0|%k0, %1}";
   5631       else if (GENERAL_REG_P (operands[1]))
   5632 	return "%vmovd\t{%k1, %0|%0, %k1}";
   5633       else
   5634 	return "%vmovd\t{%1, %0|%0, %1}";
   5635 
   5636     case MODE_HI:
   5637       if (GENERAL_REG_P (operands[0]))
   5638 	return "vmovw\t{%1, %k0|%k0, %1}";
   5639       else if (GENERAL_REG_P (operands[1]))
   5640 	return "vmovw\t{%k1, %0|%0, %k1}";
   5641       else
   5642 	return "vmovw\t{%1, %0|%0, %1}";
   5643 
   5644     case MODE_DF:
   5645       if (TARGET_AVX && REG_P (operands[0]) && REG_P (operands[1]))
   5646 	return "vmovsd\t{%d1, %0|%0, %d1}";
   5647       else
   5648 	return "%vmovsd\t{%1, %0|%0, %1}";
   5649 
   5650     case MODE_SF:
   5651       if (TARGET_AVX && REG_P (operands[0]) && REG_P (operands[1]))
   5652 	return "vmovss\t{%d1, %0|%0, %d1}";
   5653       else
   5654 	return "%vmovss\t{%1, %0|%0, %1}";
   5655 
   5656     case MODE_HF:
   5657       if (REG_P (operands[0]) && REG_P (operands[1]))
   5658 	return "vmovsh\t{%d1, %0|%0, %d1}";
   5659       else
   5660 	return "vmovsh\t{%1, %0|%0, %1}";
   5661 
   5662     case MODE_V1DF:
   5663       gcc_assert (!TARGET_AVX);
   5664       return "movlpd\t{%1, %0|%0, %1}";
   5665 
   5666     case MODE_V2SF:
   5667       if (TARGET_AVX && REG_P (operands[0]))
   5668 	return "vmovlps\t{%1, %d0|%d0, %1}";
   5669       else
   5670 	return "%vmovlps\t{%1, %0|%0, %1}";
   5671 
   5672     default:
   5673       gcc_unreachable ();
   5674     }
   5675 }
   5676 
   5677 /* Returns true if OP contains a symbol reference */
   5678 
   5679 bool
   5680 symbolic_reference_mentioned_p (rtx op)
   5681 {
   5682   const char *fmt;
   5683   int i;
   5684 
   5685   if (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF)
   5686     return true;
   5687 
   5688   fmt = GET_RTX_FORMAT (GET_CODE (op));
   5689   for (i = GET_RTX_LENGTH (GET_CODE (op)) - 1; i >= 0; i--)
   5690     {
   5691       if (fmt[i] == 'E')
   5692 	{
   5693 	  int j;
   5694 
   5695 	  for (j = XVECLEN (op, i) - 1; j >= 0; j--)
   5696 	    if (symbolic_reference_mentioned_p (XVECEXP (op, i, j)))
   5697 	      return true;
   5698 	}
   5699 
   5700       else if (fmt[i] == 'e' && symbolic_reference_mentioned_p (XEXP (op, i)))
   5701 	return true;
   5702     }
   5703 
   5704   return false;
   5705 }
   5706 
   5707 /* Return true if it is appropriate to emit `ret' instructions in the
   5708    body of a function.  Do this only if the epilogue is simple, needing a
   5709    couple of insns.  Prior to reloading, we can't tell how many registers
   5710    must be saved, so return false then.  Return false if there is no frame
   5711    marker to de-allocate.  */
   5712 
   5713 bool
   5714 ix86_can_use_return_insn_p (void)
   5715 {
   5716   if (ix86_function_ms_hook_prologue (current_function_decl))
   5717     return false;
   5718 
   5719   if (ix86_function_naked (current_function_decl))
   5720     return false;
   5721 
   5722   /* Don't use `ret' instruction in interrupt handler.  */
   5723   if (! reload_completed
   5724       || frame_pointer_needed
   5725       || cfun->machine->func_type != TYPE_NORMAL)
   5726     return 0;
   5727 
   5728   /* Don't allow more than 32k pop, since that's all we can do
   5729      with one instruction.  */
   5730   if (crtl->args.pops_args && crtl->args.size >= 32768)
   5731     return 0;
   5732 
   5733   struct ix86_frame &frame = cfun->machine->frame;
   5734   return (frame.stack_pointer_offset == UNITS_PER_WORD
   5735 	  && (frame.nregs + frame.nsseregs) == 0);
   5736 }
   5737 
   5738 /* Return stack frame size.  get_frame_size () returns used stack slots
   5740    during compilation, which may be optimized out later.  If stack frame
   5741    is needed, stack_frame_required should be true.  */
   5742 
   5743 static HOST_WIDE_INT
   5744 ix86_get_frame_size (void)
   5745 {
   5746   if (cfun->machine->stack_frame_required)
   5747     return get_frame_size ();
   5748   else
   5749     return 0;
   5750 }
   5751 
   5752 /* Value should be nonzero if functions must have frame pointers.
   5753    Zero means the frame pointer need not be set up (and parms may
   5754    be accessed via the stack pointer) in functions that seem suitable.  */
   5755 
   5756 static bool
   5757 ix86_frame_pointer_required (void)
   5758 {
   5759   /* If we accessed previous frames, then the generated code expects
   5760      to be able to access the saved ebp value in our frame.  */
   5761   if (cfun->machine->accesses_prev_frame)
   5762     return true;
   5763 
   5764   /* Several x86 os'es need a frame pointer for other reasons,
   5765      usually pertaining to setjmp.  */
   5766   if (SUBTARGET_FRAME_POINTER_REQUIRED)
   5767     return true;
   5768 
   5769   /* For older 32-bit runtimes setjmp requires valid frame-pointer.  */
   5770   if (TARGET_32BIT_MS_ABI && cfun->calls_setjmp)
   5771     return true;
   5772 
   5773   /* Win64 SEH, very large frames need a frame-pointer as maximum stack
   5774      allocation is 4GB.  */
   5775   if (TARGET_64BIT_MS_ABI && ix86_get_frame_size () > SEH_MAX_FRAME_SIZE)
   5776     return true;
   5777 
   5778   /* SSE saves require frame-pointer when stack is misaligned.  */
   5779   if (TARGET_64BIT_MS_ABI && ix86_incoming_stack_boundary < 128)
   5780     return true;
   5781 
   5782   /* In ix86_option_override_internal, TARGET_OMIT_LEAF_FRAME_POINTER
   5783      turns off the frame pointer by default.  Turn it back on now if
   5784      we've not got a leaf function.  */
   5785   if (TARGET_OMIT_LEAF_FRAME_POINTER
   5786       && (!crtl->is_leaf
   5787 	  || ix86_current_function_calls_tls_descriptor))
   5788     return true;
   5789 
   5790   /* Several versions of mcount for the x86 assumes that there is a
   5791      frame, so we cannot allow profiling without a frame pointer.  */
   5792   if (crtl->profile && !flag_fentry)
   5793     return true;
   5794 
   5795   return false;
   5796 }
   5797 
   5798 /* Record that the current function accesses previous call frames.  */
   5799 
   5800 void
   5801 ix86_setup_frame_addresses (void)
   5802 {
   5803   cfun->machine->accesses_prev_frame = 1;
   5804 }
   5805 
   5806 #ifndef USE_HIDDEN_LINKONCE
   5808 # if defined(HAVE_GAS_HIDDEN) && (SUPPORTS_ONE_ONLY - 0)
   5809 #  define USE_HIDDEN_LINKONCE 1
   5810 # else
   5811 #  define USE_HIDDEN_LINKONCE 0
   5812 # endif
   5813 #endif
   5814 
   5815 /* Label count for call and return thunks.  It is used to make unique
   5816    labels in call and return thunks.  */
   5817 static int indirectlabelno;
   5818 
   5819 /* True if call thunk function is needed.  */
   5820 static bool indirect_thunk_needed = false;
   5821 
   5822 /* Bit masks of integer registers, which contain branch target, used
   5823    by call thunk functions.  */
   5824 static HARD_REG_SET indirect_thunks_used;
   5825 
   5826 /* True if return thunk function is needed.  */
   5827 static bool indirect_return_needed = false;
   5828 
   5829 /* True if return thunk function via CX is needed.  */
   5830 static bool indirect_return_via_cx;
   5831 
   5832 #ifndef INDIRECT_LABEL
   5833 # define INDIRECT_LABEL "LIND"
   5834 #endif
   5835 
   5836 /* Indicate what prefix is needed for an indirect branch.  */
   5837 enum indirect_thunk_prefix
   5838 {
   5839   indirect_thunk_prefix_none,
   5840   indirect_thunk_prefix_nt
   5841 };
   5842 
   5843 /* Return the prefix needed for an indirect branch INSN.  */
   5844 
   5845 enum indirect_thunk_prefix
   5846 indirect_thunk_need_prefix (rtx_insn *insn)
   5847 {
   5848   enum indirect_thunk_prefix need_prefix;
   5849   if ((cfun->machine->indirect_branch_type
   5850 	    == indirect_branch_thunk_extern)
   5851 	   && ix86_notrack_prefixed_insn_p (insn))
   5852     {
   5853       /* NOTRACK prefix is only used with external thunk so that it
   5854 	 can be properly updated to support CET at run-time.  */
   5855       need_prefix = indirect_thunk_prefix_nt;
   5856     }
   5857   else
   5858     need_prefix = indirect_thunk_prefix_none;
   5859   return need_prefix;
   5860 }
   5861 
   5862 /* Fills in the label name that should be used for the indirect thunk.  */
   5863 
   5864 static void
   5865 indirect_thunk_name (char name[32], unsigned int regno,
   5866 		     enum indirect_thunk_prefix need_prefix,
   5867 		     bool ret_p)
   5868 {
   5869   if (regno != INVALID_REGNUM && regno != CX_REG && ret_p)
   5870     gcc_unreachable ();
   5871 
   5872   if (USE_HIDDEN_LINKONCE)
   5873     {
   5874       const char *prefix;
   5875 
   5876       if (need_prefix == indirect_thunk_prefix_nt
   5877 	  && regno != INVALID_REGNUM)
   5878 	{
   5879 	  /* NOTRACK prefix is only used with external thunk via
   5880 	     register so that NOTRACK prefix can be added to indirect
   5881 	     branch via register to support CET at run-time.  */
   5882 	  prefix = "_nt";
   5883 	}
   5884       else
   5885 	prefix = "";
   5886 
   5887       const char *ret = ret_p ? "return" : "indirect";
   5888 
   5889       if (regno != INVALID_REGNUM)
   5890 	{
   5891 	  const char *reg_prefix;
   5892 	  if (LEGACY_INT_REGNO_P (regno))
   5893 	    reg_prefix = TARGET_64BIT ? "r" : "e";
   5894 	  else
   5895 	    reg_prefix = "";
   5896 	  sprintf (name, "__x86_%s_thunk%s_%s%s",
   5897 		   ret, prefix, reg_prefix, reg_names[regno]);
   5898 	}
   5899       else
   5900 	sprintf (name, "__x86_%s_thunk%s", ret, prefix);
   5901     }
   5902   else
   5903     {
   5904       if (regno != INVALID_REGNUM)
   5905 	ASM_GENERATE_INTERNAL_LABEL (name, "LITR", regno);
   5906       else
   5907 	{
   5908 	  if (ret_p)
   5909 	    ASM_GENERATE_INTERNAL_LABEL (name, "LRT", 0);
   5910 	  else
   5911 	    ASM_GENERATE_INTERNAL_LABEL (name, "LIT", 0);
   5912 	}
   5913     }
   5914 }
   5915 
   5916 /* Output a call and return thunk for indirect branch.  If REGNO != -1,
   5917    the function address is in REGNO and the call and return thunk looks like:
   5918 
   5919 	call	L2
   5920    L1:
   5921 	pause
   5922 	lfence
   5923 	jmp	L1
   5924    L2:
   5925 	mov	%REG, (%sp)
   5926 	ret
   5927 
   5928    Otherwise, the function address is on the top of stack and the
   5929    call and return thunk looks like:
   5930 
   5931 	call L2
   5932   L1:
   5933 	pause
   5934 	lfence
   5935 	jmp L1
   5936   L2:
   5937 	lea WORD_SIZE(%sp), %sp
   5938 	ret
   5939  */
   5940 
   5941 static void
   5942 output_indirect_thunk (unsigned int regno)
   5943 {
   5944   char indirectlabel1[32];
   5945   char indirectlabel2[32];
   5946 
   5947   ASM_GENERATE_INTERNAL_LABEL (indirectlabel1, INDIRECT_LABEL,
   5948 			       indirectlabelno++);
   5949   ASM_GENERATE_INTERNAL_LABEL (indirectlabel2, INDIRECT_LABEL,
   5950 			       indirectlabelno++);
   5951 
   5952   /* Call */
   5953   fputs ("\tcall\t", asm_out_file);
   5954   assemble_name_raw (asm_out_file, indirectlabel2);
   5955   fputc ('\n', asm_out_file);
   5956 
   5957   ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, indirectlabel1);
   5958 
   5959   /* AMD and Intel CPUs prefer each a different instruction as loop filler.
   5960      Usage of both pause + lfence is compromise solution.  */
   5961   fprintf (asm_out_file, "\tpause\n\tlfence\n");
   5962 
   5963   /* Jump.  */
   5964   fputs ("\tjmp\t", asm_out_file);
   5965   assemble_name_raw (asm_out_file, indirectlabel1);
   5966   fputc ('\n', asm_out_file);
   5967 
   5968   ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, indirectlabel2);
   5969 
   5970   /* The above call insn pushed a word to stack.  Adjust CFI info.  */
   5971   if (flag_asynchronous_unwind_tables && dwarf2out_do_frame ())
   5972     {
   5973       if (! dwarf2out_do_cfi_asm ())
   5974 	{
   5975 	  dw_cfi_ref xcfi = ggc_cleared_alloc<dw_cfi_node> ();
   5976 	  xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
   5977 	  xcfi->dw_cfi_oprnd1.dw_cfi_addr = ggc_strdup (indirectlabel2);
   5978 	  vec_safe_push (cfun->fde->dw_fde_cfi, xcfi);
   5979 	}
   5980       dw_cfi_ref xcfi = ggc_cleared_alloc<dw_cfi_node> ();
   5981       xcfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
   5982       xcfi->dw_cfi_oprnd1.dw_cfi_offset = 2 * UNITS_PER_WORD;
   5983       vec_safe_push (cfun->fde->dw_fde_cfi, xcfi);
   5984       dwarf2out_emit_cfi (xcfi);
   5985     }
   5986 
   5987   if (regno != INVALID_REGNUM)
   5988     {
   5989       /* MOV.  */
   5990       rtx xops[2];
   5991       xops[0] = gen_rtx_MEM (word_mode, stack_pointer_rtx);
   5992       xops[1] = gen_rtx_REG (word_mode, regno);
   5993       output_asm_insn ("mov\t{%1, %0|%0, %1}", xops);
   5994     }
   5995   else
   5996     {
   5997       /* LEA.  */
   5998       rtx xops[2];
   5999       xops[0] = stack_pointer_rtx;
   6000       xops[1] = plus_constant (Pmode, stack_pointer_rtx, UNITS_PER_WORD);
   6001       output_asm_insn ("lea\t{%E1, %0|%0, %E1}", xops);
   6002     }
   6003 
   6004   fputs ("\tret\n", asm_out_file);
   6005   if ((ix86_harden_sls & harden_sls_return))
   6006     fputs ("\tint3\n", asm_out_file);
   6007 }
   6008 
   6009 /* Output a funtion with a call and return thunk for indirect branch.
   6010    If REGNO != INVALID_REGNUM, the function address is in REGNO.
   6011    Otherwise, the function address is on the top of stack.  Thunk is
   6012    used for function return if RET_P is true.  */
   6013 
   6014 static void
   6015 output_indirect_thunk_function (enum indirect_thunk_prefix need_prefix,
   6016 				unsigned int regno, bool ret_p)
   6017 {
   6018   char name[32];
   6019   tree decl;
   6020 
   6021   /* Create __x86_indirect_thunk.  */
   6022   indirect_thunk_name (name, regno, need_prefix, ret_p);
   6023   decl = build_decl (BUILTINS_LOCATION, FUNCTION_DECL,
   6024 		     get_identifier (name),
   6025 		     build_function_type_list (void_type_node, NULL_TREE));
   6026   DECL_RESULT (decl) = build_decl (BUILTINS_LOCATION, RESULT_DECL,
   6027 				   NULL_TREE, void_type_node);
   6028   TREE_PUBLIC (decl) = 1;
   6029   TREE_STATIC (decl) = 1;
   6030   DECL_IGNORED_P (decl) = 1;
   6031 
   6032 #if TARGET_MACHO
   6033   if (TARGET_MACHO)
   6034     {
   6035       switch_to_section (darwin_sections[picbase_thunk_section]);
   6036       fputs ("\t.weak_definition\t", asm_out_file);
   6037       assemble_name (asm_out_file, name);
   6038       fputs ("\n\t.private_extern\t", asm_out_file);
   6039       assemble_name (asm_out_file, name);
   6040       putc ('\n', asm_out_file);
   6041       ASM_OUTPUT_LABEL (asm_out_file, name);
   6042       DECL_WEAK (decl) = 1;
   6043     }
   6044   else
   6045 #endif
   6046     if (USE_HIDDEN_LINKONCE)
   6047       {
   6048 	cgraph_node::create (decl)->set_comdat_group (DECL_ASSEMBLER_NAME (decl));
   6049 
   6050 	targetm.asm_out.unique_section (decl, 0);
   6051 	switch_to_section (get_named_section (decl, NULL, 0));
   6052 
   6053 	targetm.asm_out.globalize_label (asm_out_file, name);
   6054 	fputs ("\t.hidden\t", asm_out_file);
   6055 	assemble_name (asm_out_file, name);
   6056 	putc ('\n', asm_out_file);
   6057 	ASM_DECLARE_FUNCTION_NAME (asm_out_file, name, decl);
   6058       }
   6059     else
   6060       {
   6061 	switch_to_section (text_section);
   6062 	ASM_OUTPUT_LABEL (asm_out_file, name);
   6063       }
   6064 
   6065   DECL_INITIAL (decl) = make_node (BLOCK);
   6066   current_function_decl = decl;
   6067   allocate_struct_function (decl, false);
   6068   init_function_start (decl);
   6069   /* We're about to hide the function body from callees of final_* by
   6070      emitting it directly; tell them we're a thunk, if they care.  */
   6071   cfun->is_thunk = true;
   6072   first_function_block_is_cold = false;
   6073   /* Make sure unwind info is emitted for the thunk if needed.  */
   6074   final_start_function (emit_barrier (), asm_out_file, 1);
   6075 
   6076   output_indirect_thunk (regno);
   6077 
   6078   final_end_function ();
   6079   init_insn_lengths ();
   6080   free_after_compilation (cfun);
   6081   set_cfun (NULL);
   6082   current_function_decl = NULL;
   6083 }
   6084 
   6085 static int pic_labels_used;
   6086 
   6087 /* Fills in the label name that should be used for a pc thunk for
   6088    the given register.  */
   6089 
   6090 static void
   6091 get_pc_thunk_name (char name[32], unsigned int regno)
   6092 {
   6093   gcc_assert (!TARGET_64BIT);
   6094 
   6095   if (USE_HIDDEN_LINKONCE)
   6096     sprintf (name, "__x86.get_pc_thunk.%s", reg_names[regno]);
   6097   else
   6098     ASM_GENERATE_INTERNAL_LABEL (name, "LPR", regno);
   6099 }
   6100 
   6101 
   6102 /* This function generates code for -fpic that loads %ebx with
   6103    the return address of the caller and then returns.  */
   6104 
   6105 static void
   6106 ix86_code_end (void)
   6107 {
   6108   rtx xops[2];
   6109   unsigned int regno;
   6110 
   6111   if (indirect_return_needed)
   6112     output_indirect_thunk_function (indirect_thunk_prefix_none,
   6113 				    INVALID_REGNUM, true);
   6114   if (indirect_return_via_cx)
   6115     output_indirect_thunk_function (indirect_thunk_prefix_none,
   6116 				    CX_REG, true);
   6117   if (indirect_thunk_needed)
   6118     output_indirect_thunk_function (indirect_thunk_prefix_none,
   6119 				    INVALID_REGNUM, false);
   6120 
   6121   for (regno = FIRST_REX_INT_REG; regno <= LAST_REX_INT_REG; regno++)
   6122     {
   6123       if (TEST_HARD_REG_BIT (indirect_thunks_used, regno))
   6124 	output_indirect_thunk_function (indirect_thunk_prefix_none,
   6125 					regno, false);
   6126     }
   6127 
   6128   for (regno = FIRST_INT_REG; regno <= LAST_INT_REG; regno++)
   6129     {
   6130       char name[32];
   6131       tree decl;
   6132 
   6133       if (TEST_HARD_REG_BIT (indirect_thunks_used, regno))
   6134 	output_indirect_thunk_function (indirect_thunk_prefix_none,
   6135 					regno, false);
   6136 
   6137       if (!(pic_labels_used & (1 << regno)))
   6138 	continue;
   6139 
   6140       get_pc_thunk_name (name, regno);
   6141 
   6142       decl = build_decl (BUILTINS_LOCATION, FUNCTION_DECL,
   6143 			 get_identifier (name),
   6144 			 build_function_type_list (void_type_node, NULL_TREE));
   6145       DECL_RESULT (decl) = build_decl (BUILTINS_LOCATION, RESULT_DECL,
   6146 				       NULL_TREE, void_type_node);
   6147       TREE_PUBLIC (decl) = 1;
   6148       TREE_STATIC (decl) = 1;
   6149       DECL_IGNORED_P (decl) = 1;
   6150 
   6151 #if TARGET_MACHO
   6152       if (TARGET_MACHO)
   6153 	{
   6154 	  switch_to_section (darwin_sections[picbase_thunk_section]);
   6155 	  fputs ("\t.weak_definition\t", asm_out_file);
   6156 	  assemble_name (asm_out_file, name);
   6157 	  fputs ("\n\t.private_extern\t", asm_out_file);
   6158 	  assemble_name (asm_out_file, name);
   6159 	  putc ('\n', asm_out_file);
   6160 	  ASM_OUTPUT_LABEL (asm_out_file, name);
   6161 	  DECL_WEAK (decl) = 1;
   6162 	}
   6163       else
   6164 #endif
   6165       if (USE_HIDDEN_LINKONCE)
   6166 	{
   6167 	  cgraph_node::create (decl)->set_comdat_group (DECL_ASSEMBLER_NAME (decl));
   6168 
   6169 	  targetm.asm_out.unique_section (decl, 0);
   6170 	  switch_to_section (get_named_section (decl, NULL, 0));
   6171 
   6172 	  targetm.asm_out.globalize_label (asm_out_file, name);
   6173 	  fputs ("\t.hidden\t", asm_out_file);
   6174 	  assemble_name (asm_out_file, name);
   6175 	  putc ('\n', asm_out_file);
   6176 	  ASM_DECLARE_FUNCTION_NAME (asm_out_file, name, decl);
   6177 	}
   6178       else
   6179 	{
   6180 	  switch_to_section (text_section);
   6181 	  ASM_OUTPUT_LABEL (asm_out_file, name);
   6182 	}
   6183 
   6184       DECL_INITIAL (decl) = make_node (BLOCK);
   6185       current_function_decl = decl;
   6186       allocate_struct_function (decl, false);
   6187       init_function_start (decl);
   6188       /* We're about to hide the function body from callees of final_* by
   6189 	 emitting it directly; tell them we're a thunk, if they care.  */
   6190       cfun->is_thunk = true;
   6191       first_function_block_is_cold = false;
   6192       /* Make sure unwind info is emitted for the thunk if needed.  */
   6193       final_start_function (emit_barrier (), asm_out_file, 1);
   6194 
   6195       /* Pad stack IP move with 4 instructions (two NOPs count
   6196 	 as one instruction).  */
   6197       if (TARGET_PAD_SHORT_FUNCTION)
   6198 	{
   6199 	  int i = 8;
   6200 
   6201 	  while (i--)
   6202 	    fputs ("\tnop\n", asm_out_file);
   6203 	}
   6204 
   6205       xops[0] = gen_rtx_REG (Pmode, regno);
   6206       xops[1] = gen_rtx_MEM (Pmode, stack_pointer_rtx);
   6207       output_asm_insn ("mov%z0\t{%1, %0|%0, %1}", xops);
   6208       fputs ("\tret\n", asm_out_file);
   6209       final_end_function ();
   6210       init_insn_lengths ();
   6211       free_after_compilation (cfun);
   6212       set_cfun (NULL);
   6213       current_function_decl = NULL;
   6214     }
   6215 
   6216   if (flag_split_stack)
   6217     file_end_indicate_split_stack ();
   6218 }
   6219 
   6220 /* Emit code for the SET_GOT patterns.  */
   6221 
   6222 const char *
   6223 output_set_got (rtx dest, rtx label)
   6224 {
   6225   rtx xops[3];
   6226 
   6227   xops[0] = dest;
   6228 
   6229   if (TARGET_VXWORKS_RTP && flag_pic)
   6230     {
   6231       /* Load (*VXWORKS_GOTT_BASE) into the PIC register.  */
   6232       xops[2] = gen_rtx_MEM (Pmode,
   6233 			     gen_rtx_SYMBOL_REF (Pmode, VXWORKS_GOTT_BASE));
   6234       output_asm_insn ("mov{l}\t{%2, %0|%0, %2}", xops);
   6235 
   6236       /* Load (*VXWORKS_GOTT_BASE)[VXWORKS_GOTT_INDEX] into the PIC register.
   6237 	 Use %P and a local symbol in order to print VXWORKS_GOTT_INDEX as
   6238 	 an unadorned address.  */
   6239       xops[2] = gen_rtx_SYMBOL_REF (Pmode, VXWORKS_GOTT_INDEX);
   6240       SYMBOL_REF_FLAGS (xops[2]) |= SYMBOL_FLAG_LOCAL;
   6241       output_asm_insn ("mov{l}\t{%P2(%0), %0|%0, DWORD PTR %P2[%0]}", xops);
   6242       return "";
   6243     }
   6244 
   6245   xops[1] = gen_rtx_SYMBOL_REF (Pmode, GOT_SYMBOL_NAME);
   6246 
   6247   if (flag_pic)
   6248     {
   6249       char name[32];
   6250       get_pc_thunk_name (name, REGNO (dest));
   6251       pic_labels_used |= 1 << REGNO (dest);
   6252 
   6253       xops[2] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (name));
   6254       xops[2] = gen_rtx_MEM (QImode, xops[2]);
   6255       output_asm_insn ("%!call\t%X2", xops);
   6256 
   6257 #if TARGET_MACHO
   6258       /* Output the Mach-O "canonical" pic base label name ("Lxx$pb") here.
   6259          This is what will be referenced by the Mach-O PIC subsystem.  */
   6260       if (machopic_should_output_picbase_label () || !label)
   6261 	ASM_OUTPUT_LABEL (asm_out_file, MACHOPIC_FUNCTION_BASE_NAME);
   6262 
   6263       /* When we are restoring the pic base at the site of a nonlocal label,
   6264          and we decided to emit the pic base above, we will still output a
   6265          local label used for calculating the correction offset (even though
   6266          the offset will be 0 in that case).  */
   6267       if (label)
   6268         targetm.asm_out.internal_label (asm_out_file, "L",
   6269 					   CODE_LABEL_NUMBER (label));
   6270 #endif
   6271     }
   6272   else
   6273     {
   6274       if (TARGET_MACHO)
   6275 	/* We don't need a pic base, we're not producing pic.  */
   6276 	gcc_unreachable ();
   6277 
   6278       xops[2] = gen_rtx_LABEL_REF (Pmode, label ? label : gen_label_rtx ());
   6279       output_asm_insn ("mov%z0\t{%2, %0|%0, %2}", xops);
   6280       targetm.asm_out.internal_label (asm_out_file, "L",
   6281 				      CODE_LABEL_NUMBER (XEXP (xops[2], 0)));
   6282     }
   6283 
   6284   if (!TARGET_MACHO)
   6285     output_asm_insn ("add%z0\t{%1, %0|%0, %1}", xops);
   6286 
   6287   return "";
   6288 }
   6289 
   6290 /* Generate an "push" pattern for input ARG.  */
   6291 
   6292 rtx
   6293 gen_push (rtx arg)
   6294 {
   6295   struct machine_function *m = cfun->machine;
   6296 
   6297   if (m->fs.cfa_reg == stack_pointer_rtx)
   6298     m->fs.cfa_offset += UNITS_PER_WORD;
   6299   m->fs.sp_offset += UNITS_PER_WORD;
   6300 
   6301   if (REG_P (arg) && GET_MODE (arg) != word_mode)
   6302     arg = gen_rtx_REG (word_mode, REGNO (arg));
   6303 
   6304   return gen_rtx_SET (gen_rtx_MEM (word_mode,
   6305 				   gen_rtx_PRE_DEC (Pmode,
   6306 						    stack_pointer_rtx)),
   6307 		      arg);
   6308 }
   6309 
   6310 /* Generate an "pop" pattern for input ARG.  */
   6311 
   6312 rtx
   6313 gen_pop (rtx arg)
   6314 {
   6315   if (REG_P (arg) && GET_MODE (arg) != word_mode)
   6316     arg = gen_rtx_REG (word_mode, REGNO (arg));
   6317 
   6318   return gen_rtx_SET (arg,
   6319 		      gen_rtx_MEM (word_mode,
   6320 				   gen_rtx_POST_INC (Pmode,
   6321 						     stack_pointer_rtx)));
   6322 }
   6323 
   6324 /* Return >= 0 if there is an unused call-clobbered register available
   6325    for the entire function.  */
   6326 
   6327 static unsigned int
   6328 ix86_select_alt_pic_regnum (void)
   6329 {
   6330   if (ix86_use_pseudo_pic_reg ())
   6331     return INVALID_REGNUM;
   6332 
   6333   if (crtl->is_leaf
   6334       && !crtl->profile
   6335       && !ix86_current_function_calls_tls_descriptor)
   6336     {
   6337       int i, drap;
   6338       /* Can't use the same register for both PIC and DRAP.  */
   6339       if (crtl->drap_reg)
   6340 	drap = REGNO (crtl->drap_reg);
   6341       else
   6342 	drap = -1;
   6343       for (i = 2; i >= 0; --i)
   6344         if (i != drap && !df_regs_ever_live_p (i))
   6345 	  return i;
   6346     }
   6347 
   6348   return INVALID_REGNUM;
   6349 }
   6350 
   6351 /* Return true if REGNO is used by the epilogue.  */
   6352 
   6353 bool
   6354 ix86_epilogue_uses (int regno)
   6355 {
   6356   /* If there are no caller-saved registers, we preserve all registers,
   6357      except for MMX and x87 registers which aren't supported when saving
   6358      and restoring registers.  Don't explicitly save SP register since
   6359      it is always preserved.  */
   6360   return (epilogue_completed
   6361 	  && cfun->machine->no_caller_saved_registers
   6362 	  && !fixed_regs[regno]
   6363 	  && !STACK_REGNO_P (regno)
   6364 	  && !MMX_REGNO_P (regno));
   6365 }
   6366 
   6367 /* Return nonzero if register REGNO can be used as a scratch register
   6368    in peephole2.  */
   6369 
   6370 static bool
   6371 ix86_hard_regno_scratch_ok (unsigned int regno)
   6372 {
   6373   /* If there are no caller-saved registers, we can't use any register
   6374      as a scratch register after epilogue and use REGNO as scratch
   6375      register only if it has been used before to avoid saving and
   6376      restoring it.  */
   6377   return (!cfun->machine->no_caller_saved_registers
   6378 	  || (!epilogue_completed
   6379 	      && df_regs_ever_live_p (regno)));
   6380 }
   6381 
   6382 /* Return TRUE if we need to save REGNO.  */
   6383 
   6384 bool
   6385 ix86_save_reg (unsigned int regno, bool maybe_eh_return, bool ignore_outlined)
   6386 {
   6387   /* If there are no caller-saved registers, we preserve all registers,
   6388      except for MMX and x87 registers which aren't supported when saving
   6389      and restoring registers.  Don't explicitly save SP register since
   6390      it is always preserved.  */
   6391   if (cfun->machine->no_caller_saved_registers)
   6392     {
   6393       /* Don't preserve registers used for function return value.  */
   6394       rtx reg = crtl->return_rtx;
   6395       if (reg)
   6396 	{
   6397 	  unsigned int i = REGNO (reg);
   6398 	  unsigned int nregs = REG_NREGS (reg);
   6399 	  while (nregs-- > 0)
   6400 	    if ((i + nregs) == regno)
   6401 	      return false;
   6402 	}
   6403 
   6404       return (df_regs_ever_live_p (regno)
   6405 	      && !fixed_regs[regno]
   6406 	      && !STACK_REGNO_P (regno)
   6407 	      && !MMX_REGNO_P (regno)
   6408 	      && (regno != HARD_FRAME_POINTER_REGNUM
   6409 		  || !frame_pointer_needed));
   6410     }
   6411 
   6412   if (regno == REAL_PIC_OFFSET_TABLE_REGNUM
   6413       && pic_offset_table_rtx)
   6414     {
   6415       if (ix86_use_pseudo_pic_reg ())
   6416 	{
   6417 	  /* REAL_PIC_OFFSET_TABLE_REGNUM used by call to
   6418 	  _mcount in prologue.  */
   6419 	  if (!TARGET_64BIT && flag_pic && crtl->profile)
   6420 	    return true;
   6421 	}
   6422       else if (df_regs_ever_live_p (REAL_PIC_OFFSET_TABLE_REGNUM)
   6423 	       || crtl->profile
   6424 	       || crtl->calls_eh_return
   6425 	       || crtl->uses_const_pool
   6426 	       || cfun->has_nonlocal_label)
   6427         return ix86_select_alt_pic_regnum () == INVALID_REGNUM;
   6428     }
   6429 
   6430   if (crtl->calls_eh_return && maybe_eh_return)
   6431     {
   6432       unsigned i;
   6433       for (i = 0; ; i++)
   6434 	{
   6435 	  unsigned test = EH_RETURN_DATA_REGNO (i);
   6436 	  if (test == INVALID_REGNUM)
   6437 	    break;
   6438 	  if (test == regno)
   6439 	    return true;
   6440 	}
   6441     }
   6442 
   6443   if (ignore_outlined && cfun->machine->call_ms2sysv)
   6444     {
   6445       unsigned count = cfun->machine->call_ms2sysv_extra_regs
   6446 		       + xlogue_layout::MIN_REGS;
   6447       if (xlogue_layout::is_stub_managed_reg (regno, count))
   6448 	return false;
   6449     }
   6450 
   6451   if (crtl->drap_reg
   6452       && regno == REGNO (crtl->drap_reg)
   6453       && !cfun->machine->no_drap_save_restore)
   6454     return true;
   6455 
   6456   return (df_regs_ever_live_p (regno)
   6457 	  && !call_used_or_fixed_reg_p (regno)
   6458 	  && (regno != HARD_FRAME_POINTER_REGNUM || !frame_pointer_needed));
   6459 }
   6460 
   6461 /* Return number of saved general prupose registers.  */
   6462 
   6463 static int
   6464 ix86_nsaved_regs (void)
   6465 {
   6466   int nregs = 0;
   6467   int regno;
   6468 
   6469   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
   6470     if (GENERAL_REGNO_P (regno) && ix86_save_reg (regno, true, true))
   6471       nregs ++;
   6472   return nregs;
   6473 }
   6474 
   6475 /* Return number of saved SSE registers.  */
   6476 
   6477 static int
   6478 ix86_nsaved_sseregs (void)
   6479 {
   6480   int nregs = 0;
   6481   int regno;
   6482 
   6483   if (!TARGET_64BIT_MS_ABI)
   6484     return 0;
   6485   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
   6486     if (SSE_REGNO_P (regno) && ix86_save_reg (regno, true, true))
   6487       nregs ++;
   6488   return nregs;
   6489 }
   6490 
   6491 /* Given FROM and TO register numbers, say whether this elimination is
   6492    allowed.  If stack alignment is needed, we can only replace argument
   6493    pointer with hard frame pointer, or replace frame pointer with stack
   6494    pointer.  Otherwise, frame pointer elimination is automatically
   6495    handled and all other eliminations are valid.  */
   6496 
   6497 static bool
   6498 ix86_can_eliminate (const int from, const int to)
   6499 {
   6500   if (stack_realign_fp)
   6501     return ((from == ARG_POINTER_REGNUM
   6502 	     && to == HARD_FRAME_POINTER_REGNUM)
   6503 	    || (from == FRAME_POINTER_REGNUM
   6504 		&& to == STACK_POINTER_REGNUM));
   6505   else
   6506     return to == STACK_POINTER_REGNUM ? !frame_pointer_needed : true;
   6507 }
   6508 
   6509 /* Return the offset between two registers, one to be eliminated, and the other
   6510    its replacement, at the start of a routine.  */
   6511 
   6512 HOST_WIDE_INT
   6513 ix86_initial_elimination_offset (int from, int to)
   6514 {
   6515   struct ix86_frame &frame = cfun->machine->frame;
   6516 
   6517   if (from == ARG_POINTER_REGNUM && to == HARD_FRAME_POINTER_REGNUM)
   6518     return frame.hard_frame_pointer_offset;
   6519   else if (from == FRAME_POINTER_REGNUM
   6520 	   && to == HARD_FRAME_POINTER_REGNUM)
   6521     return frame.hard_frame_pointer_offset - frame.frame_pointer_offset;
   6522   else
   6523     {
   6524       gcc_assert (to == STACK_POINTER_REGNUM);
   6525 
   6526       if (from == ARG_POINTER_REGNUM)
   6527 	return frame.stack_pointer_offset;
   6528 
   6529       gcc_assert (from == FRAME_POINTER_REGNUM);
   6530       return frame.stack_pointer_offset - frame.frame_pointer_offset;
   6531     }
   6532 }
   6533 
   6534 /* Emits a warning for unsupported msabi to sysv pro/epilogues.  */
   6535 void
   6536 warn_once_call_ms2sysv_xlogues (const char *feature)
   6537 {
   6538   static bool warned_once = false;
   6539   if (!warned_once)
   6540     {
   6541       warning (0, "%<-mcall-ms2sysv-xlogues%> is not compatible with %s",
   6542 	       feature);
   6543       warned_once = true;
   6544     }
   6545 }
   6546 
   6547 /* Return the probing interval for -fstack-clash-protection.  */
   6548 
   6549 static HOST_WIDE_INT
   6550 get_probe_interval (void)
   6551 {
   6552   if (flag_stack_clash_protection)
   6553     return (HOST_WIDE_INT_1U
   6554 	    << param_stack_clash_protection_probe_interval);
   6555   else
   6556     return (HOST_WIDE_INT_1U << STACK_CHECK_PROBE_INTERVAL_EXP);
   6557 }
   6558 
   6559 /* When using -fsplit-stack, the allocation routines set a field in
   6560    the TCB to the bottom of the stack plus this much space, measured
   6561    in bytes.  */
   6562 
   6563 #define SPLIT_STACK_AVAILABLE 256
   6564 
   6565 /* Fill structure ix86_frame about frame of currently computed function.  */
   6566 
   6567 static void
   6568 ix86_compute_frame_layout (void)
   6569 {
   6570   struct ix86_frame *frame = &cfun->machine->frame;
   6571   struct machine_function *m = cfun->machine;
   6572   unsigned HOST_WIDE_INT stack_alignment_needed;
   6573   HOST_WIDE_INT offset;
   6574   unsigned HOST_WIDE_INT preferred_alignment;
   6575   HOST_WIDE_INT size = ix86_get_frame_size ();
   6576   HOST_WIDE_INT to_allocate;
   6577 
   6578   /* m->call_ms2sysv is initially enabled in ix86_expand_call for all 64-bit
   6579    * ms_abi functions that call a sysv function.  We now need to prune away
   6580    * cases where it should be disabled.  */
   6581   if (TARGET_64BIT && m->call_ms2sysv)
   6582     {
   6583       gcc_assert (TARGET_64BIT_MS_ABI);
   6584       gcc_assert (TARGET_CALL_MS2SYSV_XLOGUES);
   6585       gcc_assert (!TARGET_SEH);
   6586       gcc_assert (TARGET_SSE);
   6587       gcc_assert (!ix86_using_red_zone ());
   6588 
   6589       if (crtl->calls_eh_return)
   6590 	{
   6591 	  gcc_assert (!reload_completed);
   6592 	  m->call_ms2sysv = false;
   6593 	  warn_once_call_ms2sysv_xlogues ("__builtin_eh_return");
   6594 	}
   6595 
   6596       else if (ix86_static_chain_on_stack)
   6597 	{
   6598 	  gcc_assert (!reload_completed);
   6599 	  m->call_ms2sysv = false;
   6600 	  warn_once_call_ms2sysv_xlogues ("static call chains");
   6601 	}
   6602 
   6603       /* Finally, compute which registers the stub will manage.  */
   6604       else
   6605 	{
   6606 	  unsigned count = xlogue_layout::count_stub_managed_regs ();
   6607 	  m->call_ms2sysv_extra_regs = count - xlogue_layout::MIN_REGS;
   6608 	  m->call_ms2sysv_pad_in = 0;
   6609 	}
   6610     }
   6611 
   6612   frame->nregs = ix86_nsaved_regs ();
   6613   frame->nsseregs = ix86_nsaved_sseregs ();
   6614 
   6615   /* 64-bit MS ABI seem to require stack alignment to be always 16,
   6616      except for function prologues, leaf functions and when the defult
   6617      incoming stack boundary is overriden at command line or via
   6618      force_align_arg_pointer attribute.
   6619 
   6620      Darwin's ABI specifies 128b alignment for both 32 and  64 bit variants
   6621      at call sites, including profile function calls.
   6622  */
   6623   if (((TARGET_64BIT_MS_ABI || TARGET_MACHO)
   6624         && crtl->preferred_stack_boundary < 128)
   6625       && (!crtl->is_leaf || cfun->calls_alloca != 0
   6626 	  || ix86_current_function_calls_tls_descriptor
   6627 	  || (TARGET_MACHO && crtl->profile)
   6628 	  || ix86_incoming_stack_boundary < 128))
   6629     {
   6630       crtl->preferred_stack_boundary = 128;
   6631       crtl->stack_alignment_needed = 128;
   6632     }
   6633 
   6634   stack_alignment_needed = crtl->stack_alignment_needed / BITS_PER_UNIT;
   6635   preferred_alignment = crtl->preferred_stack_boundary / BITS_PER_UNIT;
   6636 
   6637   gcc_assert (!size || stack_alignment_needed);
   6638   gcc_assert (preferred_alignment >= STACK_BOUNDARY / BITS_PER_UNIT);
   6639   gcc_assert (preferred_alignment <= stack_alignment_needed);
   6640 
   6641   /* The only ABI saving SSE regs should be 64-bit ms_abi.  */
   6642   gcc_assert (TARGET_64BIT || !frame->nsseregs);
   6643   if (TARGET_64BIT && m->call_ms2sysv)
   6644     {
   6645       gcc_assert (stack_alignment_needed >= 16);
   6646       gcc_assert (!frame->nsseregs);
   6647     }
   6648 
   6649   /* For SEH we have to limit the amount of code movement into the prologue.
   6650      At present we do this via a BLOCKAGE, at which point there's very little
   6651      scheduling that can be done, which means that there's very little point
   6652      in doing anything except PUSHs.  */
   6653   if (TARGET_SEH)
   6654     m->use_fast_prologue_epilogue = false;
   6655   else if (!optimize_bb_for_size_p (ENTRY_BLOCK_PTR_FOR_FN (cfun)))
   6656     {
   6657       int count = frame->nregs;
   6658       struct cgraph_node *node = cgraph_node::get (current_function_decl);
   6659 
   6660       /* The fast prologue uses move instead of push to save registers.  This
   6661          is significantly longer, but also executes faster as modern hardware
   6662          can execute the moves in parallel, but can't do that for push/pop.
   6663 
   6664 	 Be careful about choosing what prologue to emit:  When function takes
   6665 	 many instructions to execute we may use slow version as well as in
   6666 	 case function is known to be outside hot spot (this is known with
   6667 	 feedback only).  Weight the size of function by number of registers
   6668 	 to save as it is cheap to use one or two push instructions but very
   6669 	 slow to use many of them.
   6670 
   6671 	 Calling this hook multiple times with the same frame requirements
   6672 	 must produce the same layout, since the RA might otherwise be
   6673 	 unable to reach a fixed point or might fail its final sanity checks.
   6674 	 This means that once we've assumed that a function does or doesn't
   6675 	 have a particular size, we have to stick to that assumption
   6676 	 regardless of how the function has changed since.  */
   6677       if (count)
   6678 	count = (count - 1) * FAST_PROLOGUE_INSN_COUNT;
   6679       if (node->frequency < NODE_FREQUENCY_NORMAL
   6680 	  || (flag_branch_probabilities
   6681 	      && node->frequency < NODE_FREQUENCY_HOT))
   6682 	m->use_fast_prologue_epilogue = false;
   6683       else
   6684 	{
   6685 	  if (count != frame->expensive_count)
   6686 	    {
   6687 	      frame->expensive_count = count;
   6688 	      frame->expensive_p = expensive_function_p (count);
   6689 	    }
   6690 	  m->use_fast_prologue_epilogue = !frame->expensive_p;
   6691 	}
   6692     }
   6693 
   6694   frame->save_regs_using_mov
   6695     = TARGET_PROLOGUE_USING_MOVE && m->use_fast_prologue_epilogue;
   6696 
   6697   /* Skip return address and error code in exception handler.  */
   6698   offset = INCOMING_FRAME_SP_OFFSET;
   6699 
   6700   /* Skip pushed static chain.  */
   6701   if (ix86_static_chain_on_stack)
   6702     offset += UNITS_PER_WORD;
   6703 
   6704   /* Skip saved base pointer.  */
   6705   if (frame_pointer_needed)
   6706     offset += UNITS_PER_WORD;
   6707   frame->hfp_save_offset = offset;
   6708 
   6709   /* The traditional frame pointer location is at the top of the frame.  */
   6710   frame->hard_frame_pointer_offset = offset;
   6711 
   6712   /* Register save area */
   6713   offset += frame->nregs * UNITS_PER_WORD;
   6714   frame->reg_save_offset = offset;
   6715 
   6716   /* Calculate the size of the va-arg area (not including padding, if any).  */
   6717   frame->va_arg_size = ix86_varargs_gpr_size + ix86_varargs_fpr_size;
   6718 
   6719   /* Also adjust stack_realign_offset for the largest alignment of
   6720      stack slot actually used.  */
   6721   if (stack_realign_fp
   6722       || (cfun->machine->max_used_stack_alignment != 0
   6723 	  && (offset % cfun->machine->max_used_stack_alignment) != 0))
   6724     {
   6725       /* We may need a 16-byte aligned stack for the remainder of the
   6726 	 register save area, but the stack frame for the local function
   6727 	 may require a greater alignment if using AVX/2/512.  In order
   6728 	 to avoid wasting space, we first calculate the space needed for
   6729 	 the rest of the register saves, add that to the stack pointer,
   6730 	 and then realign the stack to the boundary of the start of the
   6731 	 frame for the local function.  */
   6732       HOST_WIDE_INT space_needed = 0;
   6733       HOST_WIDE_INT sse_reg_space_needed = 0;
   6734 
   6735       if (TARGET_64BIT)
   6736 	{
   6737 	  if (m->call_ms2sysv)
   6738 	    {
   6739 	      m->call_ms2sysv_pad_in = 0;
   6740 	      space_needed = xlogue_layout::get_instance ().get_stack_space_used ();
   6741 	    }
   6742 
   6743 	  else if (frame->nsseregs)
   6744 	    /* The only ABI that has saved SSE registers (Win64) also has a
   6745 	       16-byte aligned default stack.  However, many programs violate
   6746 	       the ABI, and Wine64 forces stack realignment to compensate.  */
   6747 	    space_needed = frame->nsseregs * 16;
   6748 
   6749 	  sse_reg_space_needed = space_needed = ROUND_UP (space_needed, 16);
   6750 
   6751 	  /* 64-bit frame->va_arg_size should always be a multiple of 16, but
   6752 	     rounding to be pedantic.  */
   6753 	  space_needed = ROUND_UP (space_needed + frame->va_arg_size, 16);
   6754 	}
   6755       else
   6756 	space_needed = frame->va_arg_size;
   6757 
   6758       /* Record the allocation size required prior to the realignment AND.  */
   6759       frame->stack_realign_allocate = space_needed;
   6760 
   6761       /* The re-aligned stack starts at frame->stack_realign_offset.  Values
   6762 	 before this point are not directly comparable with values below
   6763 	 this point.  Use sp_valid_at to determine if the stack pointer is
   6764 	 valid for a given offset, fp_valid_at for the frame pointer, or
   6765 	 choose_baseaddr to have a base register chosen for you.
   6766 
   6767 	 Note that the result of (frame->stack_realign_offset
   6768 	 & (stack_alignment_needed - 1)) may not equal zero.  */
   6769       offset = ROUND_UP (offset + space_needed, stack_alignment_needed);
   6770       frame->stack_realign_offset = offset - space_needed;
   6771       frame->sse_reg_save_offset = frame->stack_realign_offset
   6772 							+ sse_reg_space_needed;
   6773     }
   6774   else
   6775     {
   6776       frame->stack_realign_offset = offset;
   6777 
   6778       if (TARGET_64BIT && m->call_ms2sysv)
   6779 	{
   6780 	  m->call_ms2sysv_pad_in = !!(offset & UNITS_PER_WORD);
   6781 	  offset += xlogue_layout::get_instance ().get_stack_space_used ();
   6782 	}
   6783 
   6784       /* Align and set SSE register save area.  */
   6785       else if (frame->nsseregs)
   6786 	{
   6787 	  /* If the incoming stack boundary is at least 16 bytes, or DRAP is
   6788 	     required and the DRAP re-alignment boundary is at least 16 bytes,
   6789 	     then we want the SSE register save area properly aligned.  */
   6790 	  if (ix86_incoming_stack_boundary >= 128
   6791 		  || (stack_realign_drap && stack_alignment_needed >= 16))
   6792 	    offset = ROUND_UP (offset, 16);
   6793 	  offset += frame->nsseregs * 16;
   6794 	}
   6795       frame->sse_reg_save_offset = offset;
   6796       offset += frame->va_arg_size;
   6797     }
   6798 
   6799   /* Align start of frame for local function.  When a function call
   6800      is removed, it may become a leaf function.  But if argument may
   6801      be passed on stack, we need to align the stack when there is no
   6802      tail call.  */
   6803   if (m->call_ms2sysv
   6804       || frame->va_arg_size != 0
   6805       || size != 0
   6806       || !crtl->is_leaf
   6807       || (!crtl->tail_call_emit
   6808 	  && cfun->machine->outgoing_args_on_stack)
   6809       || cfun->calls_alloca
   6810       || ix86_current_function_calls_tls_descriptor)
   6811     offset = ROUND_UP (offset, stack_alignment_needed);
   6812 
   6813   /* Frame pointer points here.  */
   6814   frame->frame_pointer_offset = offset;
   6815 
   6816   offset += size;
   6817 
   6818   /* Add outgoing arguments area.  Can be skipped if we eliminated
   6819      all the function calls as dead code.
   6820      Skipping is however impossible when function calls alloca.  Alloca
   6821      expander assumes that last crtl->outgoing_args_size
   6822      of stack frame are unused.  */
   6823   if (ACCUMULATE_OUTGOING_ARGS
   6824       && (!crtl->is_leaf || cfun->calls_alloca
   6825 	  || ix86_current_function_calls_tls_descriptor))
   6826     {
   6827       offset += crtl->outgoing_args_size;
   6828       frame->outgoing_arguments_size = crtl->outgoing_args_size;
   6829     }
   6830   else
   6831     frame->outgoing_arguments_size = 0;
   6832 
   6833   /* Align stack boundary.  Only needed if we're calling another function
   6834      or using alloca.  */
   6835   if (!crtl->is_leaf || cfun->calls_alloca
   6836       || ix86_current_function_calls_tls_descriptor)
   6837     offset = ROUND_UP (offset, preferred_alignment);
   6838 
   6839   /* We've reached end of stack frame.  */
   6840   frame->stack_pointer_offset = offset;
   6841 
   6842   /* Size prologue needs to allocate.  */
   6843   to_allocate = offset - frame->sse_reg_save_offset;
   6844 
   6845   if ((!to_allocate && frame->nregs <= 1)
   6846       || (TARGET_64BIT && to_allocate >= HOST_WIDE_INT_C (0x80000000))
   6847        /* If static stack checking is enabled and done with probes,
   6848 	  the registers need to be saved before allocating the frame.  */
   6849       || flag_stack_check == STATIC_BUILTIN_STACK_CHECK
   6850       /* If stack clash probing needs a loop, then it needs a
   6851 	 scratch register.  But the returned register is only guaranteed
   6852 	 to be safe to use after register saves are complete.  So if
   6853 	 stack clash protections are enabled and the allocated frame is
   6854 	 larger than the probe interval, then use pushes to save
   6855 	 callee saved registers.  */
   6856       || (flag_stack_clash_protection
   6857 	  && !ix86_target_stack_probe ()
   6858 	  && to_allocate > get_probe_interval ()))
   6859     frame->save_regs_using_mov = false;
   6860 
   6861   if (ix86_using_red_zone ()
   6862       && crtl->sp_is_unchanging
   6863       && crtl->is_leaf
   6864       && !ix86_pc_thunk_call_expanded
   6865       && !ix86_current_function_calls_tls_descriptor)
   6866     {
   6867       frame->red_zone_size = to_allocate;
   6868       if (frame->save_regs_using_mov)
   6869 	frame->red_zone_size += frame->nregs * UNITS_PER_WORD;
   6870       if (frame->red_zone_size > RED_ZONE_SIZE - RED_ZONE_RESERVE)
   6871 	frame->red_zone_size = RED_ZONE_SIZE - RED_ZONE_RESERVE;
   6872     }
   6873   else
   6874     frame->red_zone_size = 0;
   6875   frame->stack_pointer_offset -= frame->red_zone_size;
   6876 
   6877   /* The SEH frame pointer location is near the bottom of the frame.
   6878      This is enforced by the fact that the difference between the
   6879      stack pointer and the frame pointer is limited to 240 bytes in
   6880      the unwind data structure.  */
   6881   if (TARGET_SEH)
   6882     {
   6883       /* Force the frame pointer to point at or below the lowest register save
   6884 	 area, see the SEH code in config/i386/winnt.cc for the rationale.  */
   6885       frame->hard_frame_pointer_offset = frame->sse_reg_save_offset;
   6886 
   6887       /* If we can leave the frame pointer where it is, do so; however return
   6888 	 the establisher frame for __builtin_frame_address (0) or else if the
   6889 	 frame overflows the SEH maximum frame size.
   6890 
   6891 	 Note that the value returned by __builtin_frame_address (0) is quite
   6892 	 constrained, because setjmp is piggybacked on the SEH machinery with
   6893 	 recent versions of MinGW:
   6894 
   6895 	  #    elif defined(__SEH__)
   6896 	  #     if defined(__aarch64__) || defined(_ARM64_)
   6897 	  #      define setjmp(BUF) _setjmp((BUF), __builtin_sponentry())
   6898 	  #     elif (__MINGW_GCC_VERSION < 40702)
   6899 	  #      define setjmp(BUF) _setjmp((BUF), mingw_getsp())
   6900 	  #     else
   6901 	  #      define setjmp(BUF) _setjmp((BUF), __builtin_frame_address (0))
   6902 	  #     endif
   6903 
   6904 	 and the second argument passed to _setjmp, if not null, is forwarded
   6905 	 to the TargetFrame parameter of RtlUnwindEx by longjmp (after it has
   6906 	 built an ExceptionRecord on the fly describing the setjmp buffer).  */
   6907       const HOST_WIDE_INT diff
   6908 	= frame->stack_pointer_offset - frame->hard_frame_pointer_offset;
   6909       if (diff <= 255 && !crtl->accesses_prior_frames)
   6910 	{
   6911 	  /* The resulting diff will be a multiple of 16 lower than 255,
   6912 	     i.e. at most 240 as required by the unwind data structure.  */
   6913 	  frame->hard_frame_pointer_offset += (diff & 15);
   6914 	}
   6915       else if (diff <= SEH_MAX_FRAME_SIZE && !crtl->accesses_prior_frames)
   6916 	{
   6917 	  /* Ideally we'd determine what portion of the local stack frame
   6918 	     (within the constraint of the lowest 240) is most heavily used.
   6919 	     But without that complication, simply bias the frame pointer
   6920 	     by 128 bytes so as to maximize the amount of the local stack
   6921 	     frame that is addressable with 8-bit offsets.  */
   6922 	  frame->hard_frame_pointer_offset = frame->stack_pointer_offset - 128;
   6923 	}
   6924       else
   6925 	frame->hard_frame_pointer_offset = frame->hfp_save_offset;
   6926     }
   6927 }
   6928 
   6929 /* This is semi-inlined memory_address_length, but simplified
   6930    since we know that we're always dealing with reg+offset, and
   6931    to avoid having to create and discard all that rtl.  */
   6932 
   6933 static inline int
   6934 choose_baseaddr_len (unsigned int regno, HOST_WIDE_INT offset)
   6935 {
   6936   int len = 4;
   6937 
   6938   if (offset == 0)
   6939     {
   6940       /* EBP and R13 cannot be encoded without an offset.  */
   6941       len = (regno == BP_REG || regno == R13_REG);
   6942     }
   6943   else if (IN_RANGE (offset, -128, 127))
   6944     len = 1;
   6945 
   6946   /* ESP and R12 must be encoded with a SIB byte.  */
   6947   if (regno == SP_REG || regno == R12_REG)
   6948     len++;
   6949 
   6950   return len;
   6951 }
   6952 
   6953 /* Determine if the stack pointer is valid for accessing the CFA_OFFSET in
   6954    the frame save area.  The register is saved at CFA - CFA_OFFSET.  */
   6955 
   6956 static bool
   6957 sp_valid_at (HOST_WIDE_INT cfa_offset)
   6958 {
   6959   const struct machine_frame_state &fs = cfun->machine->fs;
   6960   if (fs.sp_realigned && cfa_offset <= fs.sp_realigned_offset)
   6961     {
   6962       /* Validate that the cfa_offset isn't in a "no-man's land".  */
   6963       gcc_assert (cfa_offset <= fs.sp_realigned_fp_last);
   6964       return false;
   6965     }
   6966   return fs.sp_valid;
   6967 }
   6968 
   6969 /* Determine if the frame pointer is valid for accessing the CFA_OFFSET in
   6970    the frame save area.  The register is saved at CFA - CFA_OFFSET.  */
   6971 
   6972 static inline bool
   6973 fp_valid_at (HOST_WIDE_INT cfa_offset)
   6974 {
   6975   const struct machine_frame_state &fs = cfun->machine->fs;
   6976   if (fs.sp_realigned && cfa_offset > fs.sp_realigned_fp_last)
   6977     {
   6978       /* Validate that the cfa_offset isn't in a "no-man's land".  */
   6979       gcc_assert (cfa_offset >= fs.sp_realigned_offset);
   6980       return false;
   6981     }
   6982   return fs.fp_valid;
   6983 }
   6984 
   6985 /* Choose a base register based upon alignment requested, speed and/or
   6986    size.  */
   6987 
   6988 static void
   6989 choose_basereg (HOST_WIDE_INT cfa_offset, rtx &base_reg,
   6990 		HOST_WIDE_INT &base_offset,
   6991 		unsigned int align_reqested, unsigned int *align)
   6992 {
   6993   const struct machine_function *m = cfun->machine;
   6994   unsigned int hfp_align;
   6995   unsigned int drap_align;
   6996   unsigned int sp_align;
   6997   bool hfp_ok  = fp_valid_at (cfa_offset);
   6998   bool drap_ok = m->fs.drap_valid;
   6999   bool sp_ok   = sp_valid_at (cfa_offset);
   7000 
   7001   hfp_align = drap_align = sp_align = INCOMING_STACK_BOUNDARY;
   7002 
   7003   /* Filter out any registers that don't meet the requested alignment
   7004      criteria.  */
   7005   if (align_reqested)
   7006     {
   7007       if (m->fs.realigned)
   7008 	hfp_align = drap_align = sp_align = crtl->stack_alignment_needed;
   7009       /* SEH unwind code does do not currently support REG_CFA_EXPRESSION
   7010 	 notes (which we would need to use a realigned stack pointer),
   7011 	 so disable on SEH targets.  */
   7012       else if (m->fs.sp_realigned)
   7013 	sp_align = crtl->stack_alignment_needed;
   7014 
   7015       hfp_ok = hfp_ok && hfp_align >= align_reqested;
   7016       drap_ok = drap_ok && drap_align >= align_reqested;
   7017       sp_ok = sp_ok && sp_align >= align_reqested;
   7018     }
   7019 
   7020   if (m->use_fast_prologue_epilogue)
   7021     {
   7022       /* Choose the base register most likely to allow the most scheduling
   7023          opportunities.  Generally FP is valid throughout the function,
   7024          while DRAP must be reloaded within the epilogue.  But choose either
   7025          over the SP due to increased encoding size.  */
   7026 
   7027       if (hfp_ok)
   7028 	{
   7029 	  base_reg = hard_frame_pointer_rtx;
   7030 	  base_offset = m->fs.fp_offset - cfa_offset;
   7031 	}
   7032       else if (drap_ok)
   7033 	{
   7034 	  base_reg = crtl->drap_reg;
   7035 	  base_offset = 0 - cfa_offset;
   7036 	}
   7037       else if (sp_ok)
   7038 	{
   7039 	  base_reg = stack_pointer_rtx;
   7040 	  base_offset = m->fs.sp_offset - cfa_offset;
   7041 	}
   7042     }
   7043   else
   7044     {
   7045       HOST_WIDE_INT toffset;
   7046       int len = 16, tlen;
   7047 
   7048       /* Choose the base register with the smallest address encoding.
   7049          With a tie, choose FP > DRAP > SP.  */
   7050       if (sp_ok)
   7051 	{
   7052 	  base_reg = stack_pointer_rtx;
   7053 	  base_offset = m->fs.sp_offset - cfa_offset;
   7054           len = choose_baseaddr_len (STACK_POINTER_REGNUM, base_offset);
   7055 	}
   7056       if (drap_ok)
   7057 	{
   7058 	  toffset = 0 - cfa_offset;
   7059 	  tlen = choose_baseaddr_len (REGNO (crtl->drap_reg), toffset);
   7060 	  if (tlen <= len)
   7061 	    {
   7062 	      base_reg = crtl->drap_reg;
   7063 	      base_offset = toffset;
   7064 	      len = tlen;
   7065 	    }
   7066 	}
   7067       if (hfp_ok)
   7068 	{
   7069 	  toffset = m->fs.fp_offset - cfa_offset;
   7070 	  tlen = choose_baseaddr_len (HARD_FRAME_POINTER_REGNUM, toffset);
   7071 	  if (tlen <= len)
   7072 	    {
   7073 	      base_reg = hard_frame_pointer_rtx;
   7074 	      base_offset = toffset;
   7075 	    }
   7076 	}
   7077     }
   7078 
   7079     /* Set the align return value.  */
   7080     if (align)
   7081       {
   7082 	if (base_reg == stack_pointer_rtx)
   7083 	  *align = sp_align;
   7084 	else if (base_reg == crtl->drap_reg)
   7085 	  *align = drap_align;
   7086 	else if (base_reg == hard_frame_pointer_rtx)
   7087 	  *align = hfp_align;
   7088       }
   7089 }
   7090 
   7091 /* Return an RTX that points to CFA_OFFSET within the stack frame and
   7092    the alignment of address.  If ALIGN is non-null, it should point to
   7093    an alignment value (in bits) that is preferred or zero and will
   7094    recieve the alignment of the base register that was selected,
   7095    irrespective of rather or not CFA_OFFSET is a multiple of that
   7096    alignment value.  If it is possible for the base register offset to be
   7097    non-immediate then SCRATCH_REGNO should specify a scratch register to
   7098    use.
   7099 
   7100    The valid base registers are taken from CFUN->MACHINE->FS.  */
   7101 
   7102 static rtx
   7103 choose_baseaddr (HOST_WIDE_INT cfa_offset, unsigned int *align,
   7104 		 unsigned int scratch_regno = INVALID_REGNUM)
   7105 {
   7106   rtx base_reg = NULL;
   7107   HOST_WIDE_INT base_offset = 0;
   7108 
   7109   /* If a specific alignment is requested, try to get a base register
   7110      with that alignment first.  */
   7111   if (align && *align)
   7112     choose_basereg (cfa_offset, base_reg, base_offset, *align, align);
   7113 
   7114   if (!base_reg)
   7115     choose_basereg (cfa_offset, base_reg, base_offset, 0, align);
   7116 
   7117   gcc_assert (base_reg != NULL);
   7118 
   7119   rtx base_offset_rtx = GEN_INT (base_offset);
   7120 
   7121   if (!x86_64_immediate_operand (base_offset_rtx, Pmode))
   7122     {
   7123       gcc_assert (scratch_regno != INVALID_REGNUM);
   7124 
   7125       rtx scratch_reg = gen_rtx_REG (Pmode, scratch_regno);
   7126       emit_move_insn (scratch_reg, base_offset_rtx);
   7127 
   7128       return gen_rtx_PLUS (Pmode, base_reg, scratch_reg);
   7129     }
   7130 
   7131   return plus_constant (Pmode, base_reg, base_offset);
   7132 }
   7133 
   7134 /* Emit code to save registers in the prologue.  */
   7135 
   7136 static void
   7137 ix86_emit_save_regs (void)
   7138 {
   7139   unsigned int regno;
   7140   rtx_insn *insn;
   7141 
   7142   for (regno = FIRST_PSEUDO_REGISTER - 1; regno-- > 0; )
   7143     if (GENERAL_REGNO_P (regno) && ix86_save_reg (regno, true, true))
   7144       {
   7145 	insn = emit_insn (gen_push (gen_rtx_REG (word_mode, regno)));
   7146 	RTX_FRAME_RELATED_P (insn) = 1;
   7147       }
   7148 }
   7149 
   7150 /* Emit a single register save at CFA - CFA_OFFSET.  */
   7151 
   7152 static void
   7153 ix86_emit_save_reg_using_mov (machine_mode mode, unsigned int regno,
   7154 			      HOST_WIDE_INT cfa_offset)
   7155 {
   7156   struct machine_function *m = cfun->machine;
   7157   rtx reg = gen_rtx_REG (mode, regno);
   7158   rtx mem, addr, base, insn;
   7159   unsigned int align = GET_MODE_ALIGNMENT (mode);
   7160 
   7161   addr = choose_baseaddr (cfa_offset, &align);
   7162   mem = gen_frame_mem (mode, addr);
   7163 
   7164   /* The location aligment depends upon the base register.  */
   7165   align = MIN (GET_MODE_ALIGNMENT (mode), align);
   7166   gcc_assert (! (cfa_offset & (align / BITS_PER_UNIT - 1)));
   7167   set_mem_align (mem, align);
   7168 
   7169   insn = emit_insn (gen_rtx_SET (mem, reg));
   7170   RTX_FRAME_RELATED_P (insn) = 1;
   7171 
   7172   base = addr;
   7173   if (GET_CODE (base) == PLUS)
   7174     base = XEXP (base, 0);
   7175   gcc_checking_assert (REG_P (base));
   7176 
   7177   /* When saving registers into a re-aligned local stack frame, avoid
   7178      any tricky guessing by dwarf2out.  */
   7179   if (m->fs.realigned)
   7180     {
   7181       gcc_checking_assert (stack_realign_drap);
   7182 
   7183       if (regno == REGNO (crtl->drap_reg))
   7184 	{
   7185 	  /* A bit of a hack.  We force the DRAP register to be saved in
   7186 	     the re-aligned stack frame, which provides us with a copy
   7187 	     of the CFA that will last past the prologue.  Install it.  */
   7188 	  gcc_checking_assert (cfun->machine->fs.fp_valid);
   7189 	  addr = plus_constant (Pmode, hard_frame_pointer_rtx,
   7190 				cfun->machine->fs.fp_offset - cfa_offset);
   7191 	  mem = gen_rtx_MEM (mode, addr);
   7192 	  add_reg_note (insn, REG_CFA_DEF_CFA, mem);
   7193 	}
   7194       else
   7195 	{
   7196 	  /* The frame pointer is a stable reference within the
   7197 	     aligned frame.  Use it.  */
   7198 	  gcc_checking_assert (cfun->machine->fs.fp_valid);
   7199 	  addr = plus_constant (Pmode, hard_frame_pointer_rtx,
   7200 				cfun->machine->fs.fp_offset - cfa_offset);
   7201 	  mem = gen_rtx_MEM (mode, addr);
   7202 	  add_reg_note (insn, REG_CFA_EXPRESSION, gen_rtx_SET (mem, reg));
   7203 	}
   7204     }
   7205 
   7206   else if (base == stack_pointer_rtx && m->fs.sp_realigned
   7207 	   && cfa_offset >= m->fs.sp_realigned_offset)
   7208     {
   7209       gcc_checking_assert (stack_realign_fp);
   7210       add_reg_note (insn, REG_CFA_EXPRESSION, gen_rtx_SET (mem, reg));
   7211     }
   7212 
   7213   /* The memory may not be relative to the current CFA register,
   7214      which means that we may need to generate a new pattern for
   7215      use by the unwind info.  */
   7216   else if (base != m->fs.cfa_reg)
   7217     {
   7218       addr = plus_constant (Pmode, m->fs.cfa_reg,
   7219 			    m->fs.cfa_offset - cfa_offset);
   7220       mem = gen_rtx_MEM (mode, addr);
   7221       add_reg_note (insn, REG_CFA_OFFSET, gen_rtx_SET (mem, reg));
   7222     }
   7223 }
   7224 
   7225 /* Emit code to save registers using MOV insns.
   7226    First register is stored at CFA - CFA_OFFSET.  */
   7227 static void
   7228 ix86_emit_save_regs_using_mov (HOST_WIDE_INT cfa_offset)
   7229 {
   7230   unsigned int regno;
   7231 
   7232   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
   7233     if (GENERAL_REGNO_P (regno) && ix86_save_reg (regno, true, true))
   7234       {
   7235         ix86_emit_save_reg_using_mov (word_mode, regno, cfa_offset);
   7236 	cfa_offset -= UNITS_PER_WORD;
   7237       }
   7238 }
   7239 
   7240 /* Emit code to save SSE registers using MOV insns.
   7241    First register is stored at CFA - CFA_OFFSET.  */
   7242 static void
   7243 ix86_emit_save_sse_regs_using_mov (HOST_WIDE_INT cfa_offset)
   7244 {
   7245   unsigned int regno;
   7246 
   7247   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
   7248     if (SSE_REGNO_P (regno) && ix86_save_reg (regno, true, true))
   7249       {
   7250 	ix86_emit_save_reg_using_mov (V4SFmode, regno, cfa_offset);
   7251 	cfa_offset -= GET_MODE_SIZE (V4SFmode);
   7252       }
   7253 }
   7254 
   7255 static GTY(()) rtx queued_cfa_restores;
   7256 
   7257 /* Add a REG_CFA_RESTORE REG note to INSN or queue them until next stack
   7258    manipulation insn.  The value is on the stack at CFA - CFA_OFFSET.
   7259    Don't add the note if the previously saved value will be left untouched
   7260    within stack red-zone till return, as unwinders can find the same value
   7261    in the register and on the stack.  */
   7262 
   7263 static void
   7264 ix86_add_cfa_restore_note (rtx_insn *insn, rtx reg, HOST_WIDE_INT cfa_offset)
   7265 {
   7266   if (!crtl->shrink_wrapped
   7267       && cfa_offset <= cfun->machine->fs.red_zone_offset)
   7268     return;
   7269 
   7270   if (insn)
   7271     {
   7272       add_reg_note (insn, REG_CFA_RESTORE, reg);
   7273       RTX_FRAME_RELATED_P (insn) = 1;
   7274     }
   7275   else
   7276     queued_cfa_restores
   7277       = alloc_reg_note (REG_CFA_RESTORE, reg, queued_cfa_restores);
   7278 }
   7279 
   7280 /* Add queued REG_CFA_RESTORE notes if any to INSN.  */
   7281 
   7282 static void
   7283 ix86_add_queued_cfa_restore_notes (rtx insn)
   7284 {
   7285   rtx last;
   7286   if (!queued_cfa_restores)
   7287     return;
   7288   for (last = queued_cfa_restores; XEXP (last, 1); last = XEXP (last, 1))
   7289     ;
   7290   XEXP (last, 1) = REG_NOTES (insn);
   7291   REG_NOTES (insn) = queued_cfa_restores;
   7292   queued_cfa_restores = NULL_RTX;
   7293   RTX_FRAME_RELATED_P (insn) = 1;
   7294 }
   7295 
   7296 /* Expand prologue or epilogue stack adjustment.
   7297    The pattern exist to put a dependency on all ebp-based memory accesses.
   7298    STYLE should be negative if instructions should be marked as frame related,
   7299    zero if %r11 register is live and cannot be freely used and positive
   7300    otherwise.  */
   7301 
   7302 static rtx
   7303 pro_epilogue_adjust_stack (rtx dest, rtx src, rtx offset,
   7304 			   int style, bool set_cfa)
   7305 {
   7306   struct machine_function *m = cfun->machine;
   7307   rtx addend = offset;
   7308   rtx insn;
   7309   bool add_frame_related_expr = false;
   7310 
   7311   if (!x86_64_immediate_operand (offset, Pmode))
   7312     {
   7313       /* r11 is used by indirect sibcall return as well, set before the
   7314 	 epilogue and used after the epilogue.  */
   7315       if (style)
   7316         addend = gen_rtx_REG (Pmode, R11_REG);
   7317       else
   7318 	{
   7319 	  gcc_assert (src != hard_frame_pointer_rtx
   7320 		      && dest != hard_frame_pointer_rtx);
   7321 	  addend = hard_frame_pointer_rtx;
   7322 	}
   7323       emit_insn (gen_rtx_SET (addend, offset));
   7324       if (style < 0)
   7325 	add_frame_related_expr = true;
   7326     }
   7327 
   7328   insn = emit_insn (gen_pro_epilogue_adjust_stack_add
   7329 		    (Pmode, dest, src, addend));
   7330   if (style >= 0)
   7331     ix86_add_queued_cfa_restore_notes (insn);
   7332 
   7333   if (set_cfa)
   7334     {
   7335       rtx r;
   7336 
   7337       gcc_assert (m->fs.cfa_reg == src);
   7338       m->fs.cfa_offset += INTVAL (offset);
   7339       m->fs.cfa_reg = dest;
   7340 
   7341       r = gen_rtx_PLUS (Pmode, src, offset);
   7342       r = gen_rtx_SET (dest, r);
   7343       add_reg_note (insn, REG_CFA_ADJUST_CFA, r);
   7344       RTX_FRAME_RELATED_P (insn) = 1;
   7345     }
   7346   else if (style < 0)
   7347     {
   7348       RTX_FRAME_RELATED_P (insn) = 1;
   7349       if (add_frame_related_expr)
   7350 	{
   7351 	  rtx r = gen_rtx_PLUS (Pmode, src, offset);
   7352 	  r = gen_rtx_SET (dest, r);
   7353 	  add_reg_note (insn, REG_FRAME_RELATED_EXPR, r);
   7354 	}
   7355     }
   7356 
   7357   if (dest == stack_pointer_rtx)
   7358     {
   7359       HOST_WIDE_INT ooffset = m->fs.sp_offset;
   7360       bool valid = m->fs.sp_valid;
   7361       bool realigned = m->fs.sp_realigned;
   7362 
   7363       if (src == hard_frame_pointer_rtx)
   7364 	{
   7365 	  valid = m->fs.fp_valid;
   7366 	  realigned = false;
   7367 	  ooffset = m->fs.fp_offset;
   7368 	}
   7369       else if (src == crtl->drap_reg)
   7370 	{
   7371 	  valid = m->fs.drap_valid;
   7372 	  realigned = false;
   7373 	  ooffset = 0;
   7374 	}
   7375       else
   7376 	{
   7377 	  /* Else there are two possibilities: SP itself, which we set
   7378 	     up as the default above.  Or EH_RETURN_STACKADJ_RTX, which is
   7379 	     taken care of this by hand along the eh_return path.  */
   7380 	  gcc_checking_assert (src == stack_pointer_rtx
   7381 			       || offset == const0_rtx);
   7382 	}
   7383 
   7384       m->fs.sp_offset = ooffset - INTVAL (offset);
   7385       m->fs.sp_valid = valid;
   7386       m->fs.sp_realigned = realigned;
   7387     }
   7388   return insn;
   7389 }
   7390 
   7391 /* Find an available register to be used as dynamic realign argument
   7392    pointer regsiter.  Such a register will be written in prologue and
   7393    used in begin of body, so it must not be
   7394 	1. parameter passing register.
   7395 	2. GOT pointer.
   7396    We reuse static-chain register if it is available.  Otherwise, we
   7397    use DI for i386 and R13 for x86-64.  We chose R13 since it has
   7398    shorter encoding.
   7399 
   7400    Return: the regno of chosen register.  */
   7401 
   7402 static unsigned int
   7403 find_drap_reg (void)
   7404 {
   7405   tree decl = cfun->decl;
   7406 
   7407   /* Always use callee-saved register if there are no caller-saved
   7408      registers.  */
   7409   if (TARGET_64BIT)
   7410     {
   7411       /* Use R13 for nested function or function need static chain.
   7412 	 Since function with tail call may use any caller-saved
   7413 	 registers in epilogue, DRAP must not use caller-saved
   7414 	 register in such case.  */
   7415       if (DECL_STATIC_CHAIN (decl)
   7416 	  || cfun->machine->no_caller_saved_registers
   7417 	  || crtl->tail_call_emit)
   7418 	return R13_REG;
   7419 
   7420       return R10_REG;
   7421     }
   7422   else
   7423     {
   7424       /* Use DI for nested function or function need static chain.
   7425 	 Since function with tail call may use any caller-saved
   7426 	 registers in epilogue, DRAP must not use caller-saved
   7427 	 register in such case.  */
   7428       if (DECL_STATIC_CHAIN (decl)
   7429 	  || cfun->machine->no_caller_saved_registers
   7430 	  || crtl->tail_call_emit
   7431 	  || crtl->calls_eh_return)
   7432 	return DI_REG;
   7433 
   7434       /* Reuse static chain register if it isn't used for parameter
   7435          passing.  */
   7436       if (ix86_function_regparm (TREE_TYPE (decl), decl) <= 2)
   7437 	{
   7438 	  unsigned int ccvt = ix86_get_callcvt (TREE_TYPE (decl));
   7439 	  if ((ccvt & (IX86_CALLCVT_FASTCALL | IX86_CALLCVT_THISCALL)) == 0)
   7440 	    return CX_REG;
   7441 	}
   7442       return DI_REG;
   7443     }
   7444 }
   7445 
   7446 /* Return minimum incoming stack alignment.  */
   7447 
   7448 static unsigned int
   7449 ix86_minimum_incoming_stack_boundary (bool sibcall)
   7450 {
   7451   unsigned int incoming_stack_boundary;
   7452 
   7453   /* Stack of interrupt handler is aligned to 128 bits in 64bit mode.  */
   7454   if (cfun->machine->func_type != TYPE_NORMAL)
   7455     incoming_stack_boundary = TARGET_64BIT ? 128 : MIN_STACK_BOUNDARY;
   7456   /* Prefer the one specified at command line. */
   7457   else if (ix86_user_incoming_stack_boundary)
   7458     incoming_stack_boundary = ix86_user_incoming_stack_boundary;
   7459   /* In 32bit, use MIN_STACK_BOUNDARY for incoming stack boundary
   7460      if -mstackrealign is used, it isn't used for sibcall check and
   7461      estimated stack alignment is 128bit.  */
   7462   else if (!sibcall
   7463 	   && ix86_force_align_arg_pointer
   7464 	   && crtl->stack_alignment_estimated == 128)
   7465     incoming_stack_boundary = MIN_STACK_BOUNDARY;
   7466   else
   7467     incoming_stack_boundary = ix86_default_incoming_stack_boundary;
   7468 
   7469   /* Incoming stack alignment can be changed on individual functions
   7470      via force_align_arg_pointer attribute.  We use the smallest
   7471      incoming stack boundary.  */
   7472   if (incoming_stack_boundary > MIN_STACK_BOUNDARY
   7473       && lookup_attribute ("force_align_arg_pointer",
   7474 			   TYPE_ATTRIBUTES (TREE_TYPE (current_function_decl))))
   7475     incoming_stack_boundary = MIN_STACK_BOUNDARY;
   7476 
   7477   /* The incoming stack frame has to be aligned at least at
   7478      parm_stack_boundary.  */
   7479   if (incoming_stack_boundary < crtl->parm_stack_boundary)
   7480     incoming_stack_boundary = crtl->parm_stack_boundary;
   7481 
   7482   /* Stack at entrance of main is aligned by runtime.  We use the
   7483      smallest incoming stack boundary. */
   7484   if (incoming_stack_boundary > MAIN_STACK_BOUNDARY
   7485       && DECL_NAME (current_function_decl)
   7486       && MAIN_NAME_P (DECL_NAME (current_function_decl))
   7487       && DECL_FILE_SCOPE_P (current_function_decl))
   7488     incoming_stack_boundary = MAIN_STACK_BOUNDARY;
   7489 
   7490   return incoming_stack_boundary;
   7491 }
   7492 
   7493 /* Update incoming stack boundary and estimated stack alignment.  */
   7494 
   7495 static void
   7496 ix86_update_stack_boundary (void)
   7497 {
   7498   ix86_incoming_stack_boundary
   7499     = ix86_minimum_incoming_stack_boundary (false);
   7500 
   7501   /* x86_64 vararg needs 16byte stack alignment for register save area.  */
   7502   if (TARGET_64BIT
   7503       && cfun->stdarg
   7504       && crtl->stack_alignment_estimated < 128)
   7505     crtl->stack_alignment_estimated = 128;
   7506 
   7507   /* __tls_get_addr needs to be called with 16-byte aligned stack.  */
   7508   if (ix86_tls_descriptor_calls_expanded_in_cfun
   7509       && crtl->preferred_stack_boundary < 128)
   7510     crtl->preferred_stack_boundary = 128;
   7511 }
   7512 
   7513 /* Handle the TARGET_GET_DRAP_RTX hook.  Return NULL if no DRAP is
   7514    needed or an rtx for DRAP otherwise.  */
   7515 
   7516 static rtx
   7517 ix86_get_drap_rtx (void)
   7518 {
   7519   /* We must use DRAP if there are outgoing arguments on stack or
   7520      the stack pointer register is clobbered by asm statment and
   7521      ACCUMULATE_OUTGOING_ARGS is false.  */
   7522   if (ix86_force_drap
   7523       || ((cfun->machine->outgoing_args_on_stack
   7524 	   || crtl->sp_is_clobbered_by_asm)
   7525 	  && !ACCUMULATE_OUTGOING_ARGS))
   7526     crtl->need_drap = true;
   7527 
   7528   if (stack_realign_drap)
   7529     {
   7530       /* Assign DRAP to vDRAP and returns vDRAP */
   7531       unsigned int regno = find_drap_reg ();
   7532       rtx drap_vreg;
   7533       rtx arg_ptr;
   7534       rtx_insn *seq, *insn;
   7535 
   7536       arg_ptr = gen_rtx_REG (Pmode, regno);
   7537       crtl->drap_reg = arg_ptr;
   7538 
   7539       start_sequence ();
   7540       drap_vreg = copy_to_reg (arg_ptr);
   7541       seq = get_insns ();
   7542       end_sequence ();
   7543 
   7544       insn = emit_insn_before (seq, NEXT_INSN (entry_of_function ()));
   7545       if (!optimize)
   7546 	{
   7547 	  add_reg_note (insn, REG_CFA_SET_VDRAP, drap_vreg);
   7548 	  RTX_FRAME_RELATED_P (insn) = 1;
   7549 	}
   7550       return drap_vreg;
   7551     }
   7552   else
   7553     return NULL;
   7554 }
   7555 
   7556 /* Handle the TARGET_INTERNAL_ARG_POINTER hook.  */
   7557 
   7558 static rtx
   7559 ix86_internal_arg_pointer (void)
   7560 {
   7561   return virtual_incoming_args_rtx;
   7562 }
   7563 
   7564 struct scratch_reg {
   7565   rtx reg;
   7566   bool saved;
   7567 };
   7568 
   7569 /* Return a short-lived scratch register for use on function entry.
   7570    In 32-bit mode, it is valid only after the registers are saved
   7571    in the prologue.  This register must be released by means of
   7572    release_scratch_register_on_entry once it is dead.  */
   7573 
   7574 static void
   7575 get_scratch_register_on_entry (struct scratch_reg *sr)
   7576 {
   7577   int regno;
   7578 
   7579   sr->saved = false;
   7580 
   7581   if (TARGET_64BIT)
   7582     {
   7583       /* We always use R11 in 64-bit mode.  */
   7584       regno = R11_REG;
   7585     }
   7586   else
   7587     {
   7588       tree decl = current_function_decl, fntype = TREE_TYPE (decl);
   7589       bool fastcall_p
   7590 	= lookup_attribute ("fastcall", TYPE_ATTRIBUTES (fntype)) != NULL_TREE;
   7591       bool thiscall_p
   7592 	= lookup_attribute ("thiscall", TYPE_ATTRIBUTES (fntype)) != NULL_TREE;
   7593       bool static_chain_p = DECL_STATIC_CHAIN (decl);
   7594       int regparm = ix86_function_regparm (fntype, decl);
   7595       int drap_regno
   7596 	= crtl->drap_reg ? REGNO (crtl->drap_reg) : INVALID_REGNUM;
   7597 
   7598       /* 'fastcall' sets regparm to 2, uses ecx/edx for arguments and eax
   7599 	  for the static chain register.  */
   7600       if ((regparm < 1 || (fastcall_p && !static_chain_p))
   7601 	  && drap_regno != AX_REG)
   7602 	regno = AX_REG;
   7603       /* 'thiscall' sets regparm to 1, uses ecx for arguments and edx
   7604 	  for the static chain register.  */
   7605       else if (thiscall_p && !static_chain_p && drap_regno != AX_REG)
   7606         regno = AX_REG;
   7607       else if (regparm < 2 && !thiscall_p && drap_regno != DX_REG)
   7608 	regno = DX_REG;
   7609       /* ecx is the static chain register.  */
   7610       else if (regparm < 3 && !fastcall_p && !thiscall_p
   7611 	       && !static_chain_p
   7612 	       && drap_regno != CX_REG)
   7613 	regno = CX_REG;
   7614       else if (ix86_save_reg (BX_REG, true, false))
   7615 	regno = BX_REG;
   7616       /* esi is the static chain register.  */
   7617       else if (!(regparm == 3 && static_chain_p)
   7618 	       && ix86_save_reg (SI_REG, true, false))
   7619 	regno = SI_REG;
   7620       else if (ix86_save_reg (DI_REG, true, false))
   7621 	regno = DI_REG;
   7622       else
   7623 	{
   7624 	  regno = (drap_regno == AX_REG ? DX_REG : AX_REG);
   7625 	  sr->saved = true;
   7626 	}
   7627     }
   7628 
   7629   sr->reg = gen_rtx_REG (Pmode, regno);
   7630   if (sr->saved)
   7631     {
   7632       rtx_insn *insn = emit_insn (gen_push (sr->reg));
   7633       RTX_FRAME_RELATED_P (insn) = 1;
   7634     }
   7635 }
   7636 
   7637 /* Release a scratch register obtained from the preceding function.
   7638 
   7639    If RELEASE_VIA_POP is true, we just pop the register off the stack
   7640    to release it.  This is what non-Linux systems use with -fstack-check.
   7641 
   7642    Otherwise we use OFFSET to locate the saved register and the
   7643    allocated stack space becomes part of the local frame and is
   7644    deallocated by the epilogue.  */
   7645 
   7646 static void
   7647 release_scratch_register_on_entry (struct scratch_reg *sr, HOST_WIDE_INT offset,
   7648 				   bool release_via_pop)
   7649 {
   7650   if (sr->saved)
   7651     {
   7652       if (release_via_pop)
   7653 	{
   7654 	  struct machine_function *m = cfun->machine;
   7655 	  rtx x, insn = emit_insn (gen_pop (sr->reg));
   7656 
   7657 	  /* The RX FRAME_RELATED_P mechanism doesn't know about pop.  */
   7658 	  RTX_FRAME_RELATED_P (insn) = 1;
   7659 	  x = plus_constant (Pmode, stack_pointer_rtx, UNITS_PER_WORD);
   7660 	  x = gen_rtx_SET (stack_pointer_rtx, x);
   7661 	  add_reg_note (insn, REG_FRAME_RELATED_EXPR, x);
   7662 	  m->fs.sp_offset -= UNITS_PER_WORD;
   7663 	}
   7664       else
   7665 	{
   7666 	  rtx x = plus_constant (Pmode, stack_pointer_rtx, offset);
   7667 	  x = gen_rtx_SET (sr->reg, gen_rtx_MEM (word_mode, x));
   7668 	  emit_insn (x);
   7669 	}
   7670     }
   7671 }
   7672 
   7673 /* Emit code to adjust the stack pointer by SIZE bytes while probing it.
   7674 
   7675    If INT_REGISTERS_SAVED is true, then integer registers have already been
   7676    pushed on the stack.
   7677 
   7678    If PROTECTION AREA is true, then probe PROBE_INTERVAL plus a small dope
   7679    beyond SIZE bytes.
   7680 
   7681    This assumes no knowledge of the current probing state, i.e. it is never
   7682    allowed to allocate more than PROBE_INTERVAL bytes of stack space without
   7683    a suitable probe.  */
   7684 
   7685 static void
   7686 ix86_adjust_stack_and_probe (HOST_WIDE_INT size,
   7687 			     const bool int_registers_saved,
   7688 			     const bool protection_area)
   7689 {
   7690   struct machine_function *m = cfun->machine;
   7691 
   7692   /* If this function does not statically allocate stack space, then
   7693      no probes are needed.  */
   7694   if (!size)
   7695     {
   7696       /* However, the allocation of space via pushes for register
   7697 	 saves could be viewed as allocating space, but without the
   7698 	 need to probe.  */
   7699       if (m->frame.nregs || m->frame.nsseregs || frame_pointer_needed)
   7700         dump_stack_clash_frame_info (NO_PROBE_SMALL_FRAME, true);
   7701       else
   7702 	dump_stack_clash_frame_info (NO_PROBE_NO_FRAME, false);
   7703       return;
   7704     }
   7705 
   7706   /* If we are a noreturn function, then we have to consider the
   7707      possibility that we're called via a jump rather than a call.
   7708 
   7709      Thus we don't have the implicit probe generated by saving the
   7710      return address into the stack at the call.  Thus, the stack
   7711      pointer could be anywhere in the guard page.  The safe thing
   7712      to do is emit a probe now.
   7713 
   7714      The probe can be avoided if we have already emitted any callee
   7715      register saves into the stack or have a frame pointer (which will
   7716      have been saved as well).  Those saves will function as implicit
   7717      probes.
   7718 
   7719      ?!? This should be revamped to work like aarch64 and s390 where
   7720      we track the offset from the most recent probe.  Normally that
   7721      offset would be zero.  For a noreturn function we would reset
   7722      it to PROBE_INTERVAL - (STACK_BOUNDARY / BITS_PER_UNIT).   Then
   7723      we just probe when we cross PROBE_INTERVAL.  */
   7724   if (TREE_THIS_VOLATILE (cfun->decl)
   7725       && !(m->frame.nregs || m->frame.nsseregs || frame_pointer_needed))
   7726     {
   7727       /* We can safely use any register here since we're just going to push
   7728 	 its value and immediately pop it back.  But we do try and avoid
   7729 	 argument passing registers so as not to introduce dependencies in
   7730 	 the pipeline.  For 32 bit we use %esi and for 64 bit we use %rax.  */
   7731       rtx dummy_reg = gen_rtx_REG (word_mode, TARGET_64BIT ? AX_REG : SI_REG);
   7732       rtx_insn *insn_push = emit_insn (gen_push (dummy_reg));
   7733       rtx_insn *insn_pop = emit_insn (gen_pop (dummy_reg));
   7734       m->fs.sp_offset -= UNITS_PER_WORD;
   7735       if (m->fs.cfa_reg == stack_pointer_rtx)
   7736 	{
   7737 	  m->fs.cfa_offset -= UNITS_PER_WORD;
   7738 	  rtx x = plus_constant (Pmode, stack_pointer_rtx, -UNITS_PER_WORD);
   7739 	  x = gen_rtx_SET (stack_pointer_rtx, x);
   7740 	  add_reg_note (insn_push, REG_CFA_ADJUST_CFA, x);
   7741 	  RTX_FRAME_RELATED_P (insn_push) = 1;
   7742 	  x = plus_constant (Pmode, stack_pointer_rtx, UNITS_PER_WORD);
   7743 	  x = gen_rtx_SET (stack_pointer_rtx, x);
   7744 	  add_reg_note (insn_pop, REG_CFA_ADJUST_CFA, x);
   7745 	  RTX_FRAME_RELATED_P (insn_pop) = 1;
   7746 	}
   7747       emit_insn (gen_blockage ());
   7748     }
   7749 
   7750   const HOST_WIDE_INT probe_interval = get_probe_interval ();
   7751   const int dope = 4 * UNITS_PER_WORD;
   7752 
   7753   /* If there is protection area, take it into account in the size.  */
   7754   if (protection_area)
   7755     size += probe_interval + dope;
   7756 
   7757   /* If we allocate less than the size of the guard statically,
   7758      then no probing is necessary, but we do need to allocate
   7759      the stack.  */
   7760   else if (size < (1 << param_stack_clash_protection_guard_size))
   7761     {
   7762       pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
   7763 			         GEN_INT (-size), -1,
   7764 			         m->fs.cfa_reg == stack_pointer_rtx);
   7765       dump_stack_clash_frame_info (NO_PROBE_SMALL_FRAME, true);
   7766       return;
   7767     }
   7768 
   7769   /* We're allocating a large enough stack frame that we need to
   7770      emit probes.  Either emit them inline or in a loop depending
   7771      on the size.  */
   7772   if (size <= 4 * probe_interval)
   7773     {
   7774       HOST_WIDE_INT i;
   7775       for (i = probe_interval; i <= size; i += probe_interval)
   7776 	{
   7777 	  /* Allocate PROBE_INTERVAL bytes.  */
   7778 	  rtx insn
   7779 	    = pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
   7780 					 GEN_INT (-probe_interval), -1,
   7781 					 m->fs.cfa_reg == stack_pointer_rtx);
   7782 	  add_reg_note (insn, REG_STACK_CHECK, const0_rtx);
   7783 
   7784 	  /* And probe at *sp.  */
   7785 	  emit_stack_probe (stack_pointer_rtx);
   7786 	  emit_insn (gen_blockage ());
   7787 	}
   7788 
   7789       /* We need to allocate space for the residual, but we do not need
   7790 	 to probe the residual...  */
   7791       HOST_WIDE_INT residual = (i - probe_interval - size);
   7792       if (residual)
   7793 	{
   7794 	  pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
   7795 				     GEN_INT (residual), -1,
   7796 				     m->fs.cfa_reg == stack_pointer_rtx);
   7797 
   7798 	  /* ...except if there is a protection area to maintain.  */
   7799 	  if (protection_area)
   7800 	    emit_stack_probe (stack_pointer_rtx);
   7801 	}
   7802 
   7803       dump_stack_clash_frame_info (PROBE_INLINE, residual != 0);
   7804     }
   7805   else
   7806     {
   7807       /* We expect the GP registers to be saved when probes are used
   7808 	 as the probing sequences might need a scratch register and
   7809 	 the routine to allocate one assumes the integer registers
   7810 	 have already been saved.  */
   7811       gcc_assert (int_registers_saved);
   7812 
   7813       struct scratch_reg sr;
   7814       get_scratch_register_on_entry (&sr);
   7815 
   7816       /* If we needed to save a register, then account for any space
   7817 	 that was pushed (we are not going to pop the register when
   7818 	 we do the restore).  */
   7819       if (sr.saved)
   7820 	size -= UNITS_PER_WORD;
   7821 
   7822       /* Step 1: round SIZE down to a multiple of the interval.  */
   7823       HOST_WIDE_INT rounded_size = size & -probe_interval;
   7824 
   7825       /* Step 2: compute final value of the loop counter.  Use lea if
   7826 	 possible.  */
   7827       rtx addr = plus_constant (Pmode, stack_pointer_rtx, -rounded_size);
   7828       rtx insn;
   7829       if (address_no_seg_operand (addr, Pmode))
   7830 	insn = emit_insn (gen_rtx_SET (sr.reg, addr));
   7831       else
   7832 	{
   7833 	  emit_move_insn (sr.reg, GEN_INT (-rounded_size));
   7834 	  insn = emit_insn (gen_rtx_SET (sr.reg,
   7835 					 gen_rtx_PLUS (Pmode, sr.reg,
   7836 						       stack_pointer_rtx)));
   7837 	}
   7838       if (m->fs.cfa_reg == stack_pointer_rtx)
   7839 	{
   7840 	  add_reg_note (insn, REG_CFA_DEF_CFA,
   7841 			plus_constant (Pmode, sr.reg,
   7842 				       m->fs.cfa_offset + rounded_size));
   7843 	  RTX_FRAME_RELATED_P (insn) = 1;
   7844 	}
   7845 
   7846       /* Step 3: the loop.  */
   7847       rtx size_rtx = GEN_INT (rounded_size);
   7848       insn = emit_insn (gen_adjust_stack_and_probe (Pmode, sr.reg, sr.reg,
   7849 						    size_rtx));
   7850       if (m->fs.cfa_reg == stack_pointer_rtx)
   7851 	{
   7852 	  m->fs.cfa_offset += rounded_size;
   7853 	  add_reg_note (insn, REG_CFA_DEF_CFA,
   7854 			plus_constant (Pmode, stack_pointer_rtx,
   7855 				       m->fs.cfa_offset));
   7856 	  RTX_FRAME_RELATED_P (insn) = 1;
   7857 	}
   7858       m->fs.sp_offset += rounded_size;
   7859       emit_insn (gen_blockage ());
   7860 
   7861       /* Step 4: adjust SP if we cannot assert at compile-time that SIZE
   7862 	 is equal to ROUNDED_SIZE.  */
   7863 
   7864       if (size != rounded_size)
   7865 	{
   7866 	  pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
   7867 				     GEN_INT (rounded_size - size), -1,
   7868 				     m->fs.cfa_reg == stack_pointer_rtx);
   7869 
   7870 	  if (protection_area)
   7871 	    emit_stack_probe (stack_pointer_rtx);
   7872 	}
   7873 
   7874       dump_stack_clash_frame_info (PROBE_LOOP, size != rounded_size);
   7875 
   7876       /* This does not deallocate the space reserved for the scratch
   7877 	 register.  That will be deallocated in the epilogue.  */
   7878       release_scratch_register_on_entry (&sr, size, false);
   7879     }
   7880 
   7881   /* Adjust back to account for the protection area.  */
   7882   if (protection_area)
   7883     pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
   7884 			       GEN_INT (probe_interval + dope), -1,
   7885 			       m->fs.cfa_reg == stack_pointer_rtx);
   7886 
   7887   /* Make sure nothing is scheduled before we are done.  */
   7888   emit_insn (gen_blockage ());
   7889 }
   7890 
   7891 /* Adjust the stack pointer up to REG while probing it.  */
   7892 
   7893 const char *
   7894 output_adjust_stack_and_probe (rtx reg)
   7895 {
   7896   static int labelno = 0;
   7897   char loop_lab[32];
   7898   rtx xops[2];
   7899 
   7900   ASM_GENERATE_INTERNAL_LABEL (loop_lab, "LPSRL", labelno++);
   7901 
   7902   /* Loop.  */
   7903   ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, loop_lab);
   7904 
   7905   /* SP = SP + PROBE_INTERVAL.  */
   7906   xops[0] = stack_pointer_rtx;
   7907   xops[1] = GEN_INT (get_probe_interval ());
   7908   output_asm_insn ("sub%z0\t{%1, %0|%0, %1}", xops);
   7909 
   7910   /* Probe at SP.  */
   7911   xops[1] = const0_rtx;
   7912   output_asm_insn ("or%z0\t{%1, (%0)|DWORD PTR [%0], %1}", xops);
   7913 
   7914   /* Test if SP == LAST_ADDR.  */
   7915   xops[0] = stack_pointer_rtx;
   7916   xops[1] = reg;
   7917   output_asm_insn ("cmp%z0\t{%1, %0|%0, %1}", xops);
   7918 
   7919   /* Branch.  */
   7920   fputs ("\tjne\t", asm_out_file);
   7921   assemble_name_raw (asm_out_file, loop_lab);
   7922   fputc ('\n', asm_out_file);
   7923 
   7924   return "";
   7925 }
   7926 
   7927 /* Emit code to probe a range of stack addresses from FIRST to FIRST+SIZE,
   7928    inclusive.  These are offsets from the current stack pointer.
   7929 
   7930    INT_REGISTERS_SAVED is true if integer registers have already been
   7931    pushed on the stack.  */
   7932 
   7933 static void
   7934 ix86_emit_probe_stack_range (HOST_WIDE_INT first, HOST_WIDE_INT size,
   7935 			     const bool int_registers_saved)
   7936 {
   7937   const HOST_WIDE_INT probe_interval = get_probe_interval ();
   7938 
   7939   /* See if we have a constant small number of probes to generate.  If so,
   7940      that's the easy case.  The run-time loop is made up of 6 insns in the
   7941      generic case while the compile-time loop is made up of n insns for n #
   7942      of intervals.  */
   7943   if (size <= 6 * probe_interval)
   7944     {
   7945       HOST_WIDE_INT i;
   7946 
   7947       /* Probe at FIRST + N * PROBE_INTERVAL for values of N from 1 until
   7948 	 it exceeds SIZE.  If only one probe is needed, this will not
   7949 	 generate any code.  Then probe at FIRST + SIZE.  */
   7950       for (i = probe_interval; i < size; i += probe_interval)
   7951 	emit_stack_probe (plus_constant (Pmode, stack_pointer_rtx,
   7952 					 -(first + i)));
   7953 
   7954       emit_stack_probe (plus_constant (Pmode, stack_pointer_rtx,
   7955 				       -(first + size)));
   7956     }
   7957 
   7958   /* Otherwise, do the same as above, but in a loop.  Note that we must be
   7959      extra careful with variables wrapping around because we might be at
   7960      the very top (or the very bottom) of the address space and we have
   7961      to be able to handle this case properly; in particular, we use an
   7962      equality test for the loop condition.  */
   7963   else
   7964     {
   7965       /* We expect the GP registers to be saved when probes are used
   7966 	 as the probing sequences might need a scratch register and
   7967 	 the routine to allocate one assumes the integer registers
   7968 	 have already been saved.  */
   7969       gcc_assert (int_registers_saved);
   7970 
   7971       HOST_WIDE_INT rounded_size, last;
   7972       struct scratch_reg sr;
   7973 
   7974       get_scratch_register_on_entry (&sr);
   7975 
   7976 
   7977       /* Step 1: round SIZE to the previous multiple of the interval.  */
   7978 
   7979       rounded_size = ROUND_DOWN (size, probe_interval);
   7980 
   7981 
   7982       /* Step 2: compute initial and final value of the loop counter.  */
   7983 
   7984       /* TEST_OFFSET = FIRST.  */
   7985       emit_move_insn (sr.reg, GEN_INT (-first));
   7986 
   7987       /* LAST_OFFSET = FIRST + ROUNDED_SIZE.  */
   7988       last = first + rounded_size;
   7989 
   7990 
   7991       /* Step 3: the loop
   7992 
   7993 	 do
   7994 	   {
   7995 	     TEST_ADDR = TEST_ADDR + PROBE_INTERVAL
   7996 	     probe at TEST_ADDR
   7997 	   }
   7998 	 while (TEST_ADDR != LAST_ADDR)
   7999 
   8000          probes at FIRST + N * PROBE_INTERVAL for values of N from 1
   8001          until it is equal to ROUNDED_SIZE.  */
   8002 
   8003       emit_insn
   8004 	(gen_probe_stack_range (Pmode, sr.reg, sr.reg, GEN_INT (-last)));
   8005 
   8006 
   8007       /* Step 4: probe at FIRST + SIZE if we cannot assert at compile-time
   8008 	 that SIZE is equal to ROUNDED_SIZE.  */
   8009 
   8010       if (size != rounded_size)
   8011 	emit_stack_probe (plus_constant (Pmode,
   8012 					 gen_rtx_PLUS (Pmode,
   8013 						       stack_pointer_rtx,
   8014 						       sr.reg),
   8015 					 rounded_size - size));
   8016 
   8017       release_scratch_register_on_entry (&sr, size, true);
   8018     }
   8019 
   8020   /* Make sure nothing is scheduled before we are done.  */
   8021   emit_insn (gen_blockage ());
   8022 }
   8023 
   8024 /* Probe a range of stack addresses from REG to END, inclusive.  These are
   8025    offsets from the current stack pointer.  */
   8026 
   8027 const char *
   8028 output_probe_stack_range (rtx reg, rtx end)
   8029 {
   8030   static int labelno = 0;
   8031   char loop_lab[32];
   8032   rtx xops[3];
   8033 
   8034   ASM_GENERATE_INTERNAL_LABEL (loop_lab, "LPSRL", labelno++);
   8035 
   8036   /* Loop.  */
   8037   ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, loop_lab);
   8038 
   8039   /* TEST_ADDR = TEST_ADDR + PROBE_INTERVAL.  */
   8040   xops[0] = reg;
   8041   xops[1] = GEN_INT (get_probe_interval ());
   8042   output_asm_insn ("sub%z0\t{%1, %0|%0, %1}", xops);
   8043 
   8044   /* Probe at TEST_ADDR.  */
   8045   xops[0] = stack_pointer_rtx;
   8046   xops[1] = reg;
   8047   xops[2] = const0_rtx;
   8048   output_asm_insn ("or%z0\t{%2, (%0,%1)|DWORD PTR [%0+%1], %2}", xops);
   8049 
   8050   /* Test if TEST_ADDR == LAST_ADDR.  */
   8051   xops[0] = reg;
   8052   xops[1] = end;
   8053   output_asm_insn ("cmp%z0\t{%1, %0|%0, %1}", xops);
   8054 
   8055   /* Branch.  */
   8056   fputs ("\tjne\t", asm_out_file);
   8057   assemble_name_raw (asm_out_file, loop_lab);
   8058   fputc ('\n', asm_out_file);
   8059 
   8060   return "";
   8061 }
   8062 
   8063 /* Set stack_frame_required to false if stack frame isn't required.
   8064    Update STACK_ALIGNMENT to the largest alignment, in bits, of stack
   8065    slot used if stack frame is required and CHECK_STACK_SLOT is true.  */
   8066 
   8067 static void
   8068 ix86_find_max_used_stack_alignment (unsigned int &stack_alignment,
   8069 				    bool check_stack_slot)
   8070 {
   8071   HARD_REG_SET set_up_by_prologue, prologue_used;
   8072   basic_block bb;
   8073 
   8074   CLEAR_HARD_REG_SET (prologue_used);
   8075   CLEAR_HARD_REG_SET (set_up_by_prologue);
   8076   add_to_hard_reg_set (&set_up_by_prologue, Pmode, STACK_POINTER_REGNUM);
   8077   add_to_hard_reg_set (&set_up_by_prologue, Pmode, ARG_POINTER_REGNUM);
   8078   add_to_hard_reg_set (&set_up_by_prologue, Pmode,
   8079 		       HARD_FRAME_POINTER_REGNUM);
   8080 
   8081   /* The preferred stack alignment is the minimum stack alignment.  */
   8082   if (stack_alignment > crtl->preferred_stack_boundary)
   8083     stack_alignment = crtl->preferred_stack_boundary;
   8084 
   8085   bool require_stack_frame = false;
   8086 
   8087   FOR_EACH_BB_FN (bb, cfun)
   8088     {
   8089       rtx_insn *insn;
   8090       FOR_BB_INSNS (bb, insn)
   8091 	if (NONDEBUG_INSN_P (insn)
   8092 	    && requires_stack_frame_p (insn, prologue_used,
   8093 				       set_up_by_prologue))
   8094 	  {
   8095 	    require_stack_frame = true;
   8096 
   8097 	    if (check_stack_slot)
   8098 	      {
   8099 		/* Find the maximum stack alignment.  */
   8100 		subrtx_iterator::array_type array;
   8101 		FOR_EACH_SUBRTX (iter, array, PATTERN (insn), ALL)
   8102 		  if (MEM_P (*iter)
   8103 		      && (reg_mentioned_p (stack_pointer_rtx,
   8104 					   *iter)
   8105 			  || reg_mentioned_p (frame_pointer_rtx,
   8106 					      *iter)))
   8107 		    {
   8108 		      unsigned int alignment = MEM_ALIGN (*iter);
   8109 		      if (alignment > stack_alignment)
   8110 			stack_alignment = alignment;
   8111 		    }
   8112 	      }
   8113 	  }
   8114     }
   8115 
   8116   cfun->machine->stack_frame_required = require_stack_frame;
   8117 }
   8118 
   8119 /* Finalize stack_realign_needed and frame_pointer_needed flags, which
   8120    will guide prologue/epilogue to be generated in correct form.  */
   8121 
   8122 static void
   8123 ix86_finalize_stack_frame_flags (void)
   8124 {
   8125   /* Check if stack realign is really needed after reload, and
   8126      stores result in cfun */
   8127   unsigned int incoming_stack_boundary
   8128     = (crtl->parm_stack_boundary > ix86_incoming_stack_boundary
   8129        ? crtl->parm_stack_boundary : ix86_incoming_stack_boundary);
   8130   unsigned int stack_alignment
   8131     = (crtl->is_leaf && !ix86_current_function_calls_tls_descriptor
   8132        ? crtl->max_used_stack_slot_alignment
   8133        : crtl->stack_alignment_needed);
   8134   unsigned int stack_realign
   8135     = (incoming_stack_boundary < stack_alignment);
   8136   bool recompute_frame_layout_p = false;
   8137 
   8138   if (crtl->stack_realign_finalized)
   8139     {
   8140       /* After stack_realign_needed is finalized, we can't no longer
   8141 	 change it.  */
   8142       gcc_assert (crtl->stack_realign_needed == stack_realign);
   8143       return;
   8144     }
   8145 
   8146   /* It is always safe to compute max_used_stack_alignment.  We
   8147      compute it only if 128-bit aligned load/store may be generated
   8148      on misaligned stack slot which will lead to segfault. */
   8149   bool check_stack_slot
   8150     = (stack_realign || crtl->max_used_stack_slot_alignment >= 128);
   8151   ix86_find_max_used_stack_alignment (stack_alignment,
   8152 				      check_stack_slot);
   8153 
   8154   /* If the only reason for frame_pointer_needed is that we conservatively
   8155      assumed stack realignment might be needed or -fno-omit-frame-pointer
   8156      is used, but in the end nothing that needed the stack alignment had
   8157      been spilled nor stack access, clear frame_pointer_needed and say we
   8158      don't need stack realignment.
   8159 
   8160      When vector register is used for piecewise move and store, we don't
   8161      increase stack_alignment_needed as there is no register spill for
   8162      piecewise move and store.  Since stack_realign_needed is set to true
   8163      by checking stack_alignment_estimated which is updated by pseudo
   8164      vector register usage, we also need to check stack_realign_needed to
   8165      eliminate frame pointer.  */
   8166   if ((stack_realign
   8167        || (!flag_omit_frame_pointer && optimize)
   8168        || crtl->stack_realign_needed)
   8169       && frame_pointer_needed
   8170       && crtl->is_leaf
   8171       && crtl->sp_is_unchanging
   8172       && !ix86_current_function_calls_tls_descriptor
   8173       && !crtl->accesses_prior_frames
   8174       && !cfun->calls_alloca
   8175       && !crtl->calls_eh_return
   8176       /* See ira_setup_eliminable_regset for the rationale.  */
   8177       && !(STACK_CHECK_MOVING_SP
   8178 	   && flag_stack_check
   8179 	   && flag_exceptions
   8180 	   && cfun->can_throw_non_call_exceptions)
   8181       && !ix86_frame_pointer_required ()
   8182       && ix86_get_frame_size () == 0
   8183       && ix86_nsaved_sseregs () == 0
   8184       && ix86_varargs_gpr_size + ix86_varargs_fpr_size == 0)
   8185     {
   8186       if (cfun->machine->stack_frame_required)
   8187 	{
   8188 	  /* Stack frame is required.  If stack alignment needed is less
   8189 	     than incoming stack boundary, don't realign stack.  */
   8190 	  stack_realign = incoming_stack_boundary < stack_alignment;
   8191 	  if (!stack_realign)
   8192 	    {
   8193 	      crtl->max_used_stack_slot_alignment
   8194 		= incoming_stack_boundary;
   8195 	      crtl->stack_alignment_needed
   8196 		= incoming_stack_boundary;
   8197 	      /* Also update preferred_stack_boundary for leaf
   8198 	         functions.  */
   8199 	      crtl->preferred_stack_boundary
   8200 		= incoming_stack_boundary;
   8201 	    }
   8202 	}
   8203       else
   8204 	{
   8205 	  /* If drap has been set, but it actually isn't live at the
   8206 	     start of the function, there is no reason to set it up.  */
   8207 	  if (crtl->drap_reg)
   8208 	    {
   8209 	      basic_block bb = ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb;
   8210 	      if (! REGNO_REG_SET_P (DF_LR_IN (bb),
   8211 				     REGNO (crtl->drap_reg)))
   8212 		{
   8213 		  crtl->drap_reg = NULL_RTX;
   8214 		  crtl->need_drap = false;
   8215 		}
   8216 	    }
   8217 	  else
   8218 	    cfun->machine->no_drap_save_restore = true;
   8219 
   8220 	  frame_pointer_needed = false;
   8221 	  stack_realign = false;
   8222 	  crtl->max_used_stack_slot_alignment = incoming_stack_boundary;
   8223 	  crtl->stack_alignment_needed = incoming_stack_boundary;
   8224 	  crtl->stack_alignment_estimated = incoming_stack_boundary;
   8225 	  if (crtl->preferred_stack_boundary > incoming_stack_boundary)
   8226 	    crtl->preferred_stack_boundary = incoming_stack_boundary;
   8227 	  df_finish_pass (true);
   8228 	  df_scan_alloc (NULL);
   8229 	  df_scan_blocks ();
   8230 	  df_compute_regs_ever_live (true);
   8231 	  df_analyze ();
   8232 
   8233 	  if (flag_var_tracking)
   8234 	    {
   8235 	      /* Since frame pointer is no longer available, replace it with
   8236 		 stack pointer - UNITS_PER_WORD in debug insns.  */
   8237 	      df_ref ref, next;
   8238 	      for (ref = DF_REG_USE_CHAIN (HARD_FRAME_POINTER_REGNUM);
   8239 		   ref; ref = next)
   8240 		{
   8241 		  next = DF_REF_NEXT_REG (ref);
   8242 		  if (!DF_REF_INSN_INFO (ref))
   8243 		    continue;
   8244 
   8245 		  /* Make sure the next ref is for a different instruction,
   8246 		     so that we're not affected by the rescan.  */
   8247 		  rtx_insn *insn = DF_REF_INSN (ref);
   8248 		  while (next && DF_REF_INSN (next) == insn)
   8249 		    next = DF_REF_NEXT_REG (next);
   8250 
   8251 		  if (DEBUG_INSN_P (insn))
   8252 		    {
   8253 		      bool changed = false;
   8254 		      for (; ref != next; ref = DF_REF_NEXT_REG (ref))
   8255 			{
   8256 			  rtx *loc = DF_REF_LOC (ref);
   8257 			  if (*loc == hard_frame_pointer_rtx)
   8258 			    {
   8259 			      *loc = plus_constant (Pmode,
   8260 						    stack_pointer_rtx,
   8261 						    -UNITS_PER_WORD);
   8262 			      changed = true;
   8263 			    }
   8264 			}
   8265 		      if (changed)
   8266 			df_insn_rescan (insn);
   8267 		    }
   8268 		}
   8269 	    }
   8270 
   8271 	  recompute_frame_layout_p = true;
   8272 	}
   8273     }
   8274   else if (crtl->max_used_stack_slot_alignment >= 128
   8275 	   && cfun->machine->stack_frame_required)
   8276     {
   8277       /* We don't need to realign stack.  max_used_stack_alignment is
   8278 	 used to decide how stack frame should be aligned.  This is
   8279 	 independent of any psABIs nor 32-bit vs 64-bit.  */
   8280       cfun->machine->max_used_stack_alignment
   8281 	= stack_alignment / BITS_PER_UNIT;
   8282     }
   8283 
   8284   if (crtl->stack_realign_needed != stack_realign)
   8285     recompute_frame_layout_p = true;
   8286   crtl->stack_realign_needed = stack_realign;
   8287   crtl->stack_realign_finalized = true;
   8288   if (recompute_frame_layout_p)
   8289     ix86_compute_frame_layout ();
   8290 }
   8291 
   8292 /* Delete SET_GOT right after entry block if it is allocated to reg.  */
   8293 
   8294 static void
   8295 ix86_elim_entry_set_got (rtx reg)
   8296 {
   8297   basic_block bb = ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb;
   8298   rtx_insn *c_insn = BB_HEAD (bb);
   8299   if (!NONDEBUG_INSN_P (c_insn))
   8300     c_insn = next_nonnote_nondebug_insn (c_insn);
   8301   if (c_insn && NONJUMP_INSN_P (c_insn))
   8302     {
   8303       rtx pat = PATTERN (c_insn);
   8304       if (GET_CODE (pat) == PARALLEL)
   8305 	{
   8306 	  rtx set = XVECEXP (pat, 0, 0);
   8307 	  if (GET_CODE (set) == SET
   8308 	      && GET_CODE (SET_SRC (set)) == UNSPEC
   8309 	      && XINT (SET_SRC (set), 1) == UNSPEC_SET_GOT
   8310 	      && REGNO (SET_DEST (set)) == REGNO (reg))
   8311 	    delete_insn (c_insn);
   8312 	}
   8313     }
   8314 }
   8315 
   8316 static rtx
   8317 gen_frame_set (rtx reg, rtx frame_reg, int offset, bool store)
   8318 {
   8319   rtx addr, mem;
   8320 
   8321   if (offset)
   8322     addr = plus_constant (Pmode, frame_reg, offset);
   8323   mem = gen_frame_mem (GET_MODE (reg), offset ? addr : frame_reg);
   8324   return gen_rtx_SET (store ? mem : reg, store ? reg : mem);
   8325 }
   8326 
   8327 static inline rtx
   8328 gen_frame_load (rtx reg, rtx frame_reg, int offset)
   8329 {
   8330   return gen_frame_set (reg, frame_reg, offset, false);
   8331 }
   8332 
   8333 static inline rtx
   8334 gen_frame_store (rtx reg, rtx frame_reg, int offset)
   8335 {
   8336   return gen_frame_set (reg, frame_reg, offset, true);
   8337 }
   8338 
   8339 static void
   8340 ix86_emit_outlined_ms2sysv_save (const struct ix86_frame &frame)
   8341 {
   8342   struct machine_function *m = cfun->machine;
   8343   const unsigned ncregs = NUM_X86_64_MS_CLOBBERED_REGS
   8344 			  + m->call_ms2sysv_extra_regs;
   8345   rtvec v = rtvec_alloc (ncregs + 1);
   8346   unsigned int align, i, vi = 0;
   8347   rtx_insn *insn;
   8348   rtx sym, addr;
   8349   rtx rax = gen_rtx_REG (word_mode, AX_REG);
   8350   const class xlogue_layout &xlogue = xlogue_layout::get_instance ();
   8351 
   8352   /* AL should only be live with sysv_abi.  */
   8353   gcc_assert (!ix86_eax_live_at_start_p ());
   8354   gcc_assert (m->fs.sp_offset >= frame.sse_reg_save_offset);
   8355 
   8356   /* Setup RAX as the stub's base pointer.  We use stack_realign_offset rather
   8357      we've actually realigned the stack or not.  */
   8358   align = GET_MODE_ALIGNMENT (V4SFmode);
   8359   addr = choose_baseaddr (frame.stack_realign_offset
   8360 			  + xlogue.get_stub_ptr_offset (), &align, AX_REG);
   8361   gcc_assert (align >= GET_MODE_ALIGNMENT (V4SFmode));
   8362 
   8363   emit_insn (gen_rtx_SET (rax, addr));
   8364 
   8365   /* Get the stub symbol.  */
   8366   sym = xlogue.get_stub_rtx (frame_pointer_needed ? XLOGUE_STUB_SAVE_HFP
   8367 						  : XLOGUE_STUB_SAVE);
   8368   RTVEC_ELT (v, vi++) = gen_rtx_USE (VOIDmode, sym);
   8369 
   8370   for (i = 0; i < ncregs; ++i)
   8371     {
   8372       const xlogue_layout::reginfo &r = xlogue.get_reginfo (i);
   8373       rtx reg = gen_rtx_REG ((SSE_REGNO_P (r.regno) ? V4SFmode : word_mode),
   8374 			     r.regno);
   8375       RTVEC_ELT (v, vi++) = gen_frame_store (reg, rax, -r.offset);
   8376     }
   8377 
   8378   gcc_assert (vi == (unsigned)GET_NUM_ELEM (v));
   8379 
   8380   insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, v));
   8381   RTX_FRAME_RELATED_P (insn) = true;
   8382 }
   8383 
   8384 /* Generate and return an insn body to AND X with Y.  */
   8385 
   8386 static rtx_insn *
   8387 gen_and2_insn (rtx x, rtx y)
   8388 {
   8389   enum insn_code icode = optab_handler (and_optab, GET_MODE (x));
   8390 
   8391   gcc_assert (insn_operand_matches (icode, 0, x));
   8392   gcc_assert (insn_operand_matches (icode, 1, x));
   8393   gcc_assert (insn_operand_matches (icode, 2, y));
   8394 
   8395   return GEN_FCN (icode) (x, x, y);
   8396 }
   8397 
   8398 /* Expand the prologue into a bunch of separate insns.  */
   8399 
   8400 void
   8401 ix86_expand_prologue (void)
   8402 {
   8403   struct machine_function *m = cfun->machine;
   8404   rtx insn, t;
   8405   HOST_WIDE_INT allocate;
   8406   bool int_registers_saved;
   8407   bool sse_registers_saved;
   8408   bool save_stub_call_needed;
   8409   rtx static_chain = NULL_RTX;
   8410 
   8411   ix86_last_zero_store_uid = 0;
   8412   if (ix86_function_naked (current_function_decl))
   8413     {
   8414       if (flag_stack_usage_info)
   8415 	current_function_static_stack_size = 0;
   8416       return;
   8417     }
   8418 
   8419   ix86_finalize_stack_frame_flags ();
   8420 
   8421   /* DRAP should not coexist with stack_realign_fp */
   8422   gcc_assert (!(crtl->drap_reg && stack_realign_fp));
   8423 
   8424   memset (&m->fs, 0, sizeof (m->fs));
   8425 
   8426   /* Initialize CFA state for before the prologue.  */
   8427   m->fs.cfa_reg = stack_pointer_rtx;
   8428   m->fs.cfa_offset = INCOMING_FRAME_SP_OFFSET;
   8429 
   8430   /* Track SP offset to the CFA.  We continue tracking this after we've
   8431      swapped the CFA register away from SP.  In the case of re-alignment
   8432      this is fudged; we're interested to offsets within the local frame.  */
   8433   m->fs.sp_offset = INCOMING_FRAME_SP_OFFSET;
   8434   m->fs.sp_valid = true;
   8435   m->fs.sp_realigned = false;
   8436 
   8437   const struct ix86_frame &frame = cfun->machine->frame;
   8438 
   8439   if (!TARGET_64BIT && ix86_function_ms_hook_prologue (current_function_decl))
   8440     {
   8441       /* We should have already generated an error for any use of
   8442          ms_hook on a nested function.  */
   8443       gcc_checking_assert (!ix86_static_chain_on_stack);
   8444 
   8445       /* Check if profiling is active and we shall use profiling before
   8446          prologue variant. If so sorry.  */
   8447       if (crtl->profile && flag_fentry != 0)
   8448 	sorry ("%<ms_hook_prologue%> attribute is not compatible "
   8449 	       "with %<-mfentry%> for 32-bit");
   8450 
   8451       /* In ix86_asm_output_function_label we emitted:
   8452 	 8b ff     movl.s %edi,%edi
   8453 	 55        push   %ebp
   8454 	 8b ec     movl.s %esp,%ebp
   8455 
   8456 	 This matches the hookable function prologue in Win32 API
   8457 	 functions in Microsoft Windows XP Service Pack 2 and newer.
   8458 	 Wine uses this to enable Windows apps to hook the Win32 API
   8459 	 functions provided by Wine.
   8460 
   8461 	 What that means is that we've already set up the frame pointer.  */
   8462 
   8463       if (frame_pointer_needed
   8464 	  && !(crtl->drap_reg && crtl->stack_realign_needed))
   8465 	{
   8466 	  rtx push, mov;
   8467 
   8468 	  /* We've decided to use the frame pointer already set up.
   8469 	     Describe this to the unwinder by pretending that both
   8470 	     push and mov insns happen right here.
   8471 
   8472 	     Putting the unwind info here at the end of the ms_hook
   8473 	     is done so that we can make absolutely certain we get
   8474 	     the required byte sequence at the start of the function,
   8475 	     rather than relying on an assembler that can produce
   8476 	     the exact encoding required.
   8477 
   8478 	     However it does mean (in the unpatched case) that we have
   8479 	     a 1 insn window where the asynchronous unwind info is
   8480 	     incorrect.  However, if we placed the unwind info at
   8481 	     its correct location we would have incorrect unwind info
   8482 	     in the patched case.  Which is probably all moot since
   8483 	     I don't expect Wine generates dwarf2 unwind info for the
   8484 	     system libraries that use this feature.  */
   8485 
   8486 	  insn = emit_insn (gen_blockage ());
   8487 
   8488 	  push = gen_push (hard_frame_pointer_rtx);
   8489 	  mov = gen_rtx_SET (hard_frame_pointer_rtx,
   8490 			     stack_pointer_rtx);
   8491 	  RTX_FRAME_RELATED_P (push) = 1;
   8492 	  RTX_FRAME_RELATED_P (mov) = 1;
   8493 
   8494 	  RTX_FRAME_RELATED_P (insn) = 1;
   8495 	  add_reg_note (insn, REG_FRAME_RELATED_EXPR,
   8496 			gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, push, mov)));
   8497 
   8498 	  /* Note that gen_push incremented m->fs.cfa_offset, even
   8499 	     though we didn't emit the push insn here.  */
   8500 	  m->fs.cfa_reg = hard_frame_pointer_rtx;
   8501 	  m->fs.fp_offset = m->fs.cfa_offset;
   8502 	  m->fs.fp_valid = true;
   8503 	}
   8504       else
   8505 	{
   8506 	  /* The frame pointer is not needed so pop %ebp again.
   8507 	     This leaves us with a pristine state.  */
   8508 	  emit_insn (gen_pop (hard_frame_pointer_rtx));
   8509 	}
   8510     }
   8511 
   8512   /* The first insn of a function that accepts its static chain on the
   8513      stack is to push the register that would be filled in by a direct
   8514      call.  This insn will be skipped by the trampoline.  */
   8515   else if (ix86_static_chain_on_stack)
   8516     {
   8517       static_chain = ix86_static_chain (cfun->decl, false);
   8518       insn = emit_insn (gen_push (static_chain));
   8519       emit_insn (gen_blockage ());
   8520 
   8521       /* We don't want to interpret this push insn as a register save,
   8522 	 only as a stack adjustment.  The real copy of the register as
   8523 	 a save will be done later, if needed.  */
   8524       t = plus_constant (Pmode, stack_pointer_rtx, -UNITS_PER_WORD);
   8525       t = gen_rtx_SET (stack_pointer_rtx, t);
   8526       add_reg_note (insn, REG_CFA_ADJUST_CFA, t);
   8527       RTX_FRAME_RELATED_P (insn) = 1;
   8528     }
   8529 
   8530   /* Emit prologue code to adjust stack alignment and setup DRAP, in case
   8531      of DRAP is needed and stack realignment is really needed after reload */
   8532   if (stack_realign_drap)
   8533     {
   8534       int align_bytes = crtl->stack_alignment_needed / BITS_PER_UNIT;
   8535 
   8536       /* Can't use DRAP in interrupt function.  */
   8537       if (cfun->machine->func_type != TYPE_NORMAL)
   8538 	sorry ("Dynamic Realign Argument Pointer (DRAP) not supported "
   8539 	       "in interrupt service routine.  This may be worked "
   8540 	       "around by avoiding functions with aggregate return.");
   8541 
   8542       /* Only need to push parameter pointer reg if it is caller saved.  */
   8543       if (!call_used_or_fixed_reg_p (REGNO (crtl->drap_reg)))
   8544 	{
   8545 	  /* Push arg pointer reg */
   8546 	  insn = emit_insn (gen_push (crtl->drap_reg));
   8547 	  RTX_FRAME_RELATED_P (insn) = 1;
   8548 	}
   8549 
   8550       /* Grab the argument pointer.  */
   8551       t = plus_constant (Pmode, stack_pointer_rtx, m->fs.sp_offset);
   8552       insn = emit_insn (gen_rtx_SET (crtl->drap_reg, t));
   8553       RTX_FRAME_RELATED_P (insn) = 1;
   8554       m->fs.cfa_reg = crtl->drap_reg;
   8555       m->fs.cfa_offset = 0;
   8556 
   8557       /* Align the stack.  */
   8558       insn = emit_insn (gen_and2_insn (stack_pointer_rtx,
   8559 				       GEN_INT (-align_bytes)));
   8560       RTX_FRAME_RELATED_P (insn) = 1;
   8561 
   8562       /* Replicate the return address on the stack so that return
   8563 	 address can be reached via (argp - 1) slot.  This is needed
   8564 	 to implement macro RETURN_ADDR_RTX and intrinsic function
   8565 	 expand_builtin_return_addr etc.  */
   8566       t = plus_constant (Pmode, crtl->drap_reg, -UNITS_PER_WORD);
   8567       t = gen_frame_mem (word_mode, t);
   8568       insn = emit_insn (gen_push (t));
   8569       RTX_FRAME_RELATED_P (insn) = 1;
   8570 
   8571       /* For the purposes of frame and register save area addressing,
   8572 	 we've started over with a new frame.  */
   8573       m->fs.sp_offset = INCOMING_FRAME_SP_OFFSET;
   8574       m->fs.realigned = true;
   8575 
   8576       if (static_chain)
   8577 	{
   8578 	  /* Replicate static chain on the stack so that static chain
   8579 	     can be reached via (argp - 2) slot.  This is needed for
   8580 	     nested function with stack realignment.  */
   8581 	  insn = emit_insn (gen_push (static_chain));
   8582 	  RTX_FRAME_RELATED_P (insn) = 1;
   8583 	}
   8584     }
   8585 
   8586   int_registers_saved = (frame.nregs == 0);
   8587   sse_registers_saved = (frame.nsseregs == 0);
   8588   save_stub_call_needed = (m->call_ms2sysv);
   8589   gcc_assert (sse_registers_saved || !save_stub_call_needed);
   8590 
   8591   if (frame_pointer_needed && !m->fs.fp_valid)
   8592     {
   8593       /* Note: AT&T enter does NOT have reversed args.  Enter is probably
   8594          slower on all targets.  Also sdb didn't like it.  */
   8595       insn = emit_insn (gen_push (hard_frame_pointer_rtx));
   8596       RTX_FRAME_RELATED_P (insn) = 1;
   8597 
   8598       if (m->fs.sp_offset == frame.hard_frame_pointer_offset)
   8599 	{
   8600 	  insn = emit_move_insn (hard_frame_pointer_rtx, stack_pointer_rtx);
   8601 	  RTX_FRAME_RELATED_P (insn) = 1;
   8602 
   8603 	  if (m->fs.cfa_reg == stack_pointer_rtx)
   8604 	    m->fs.cfa_reg = hard_frame_pointer_rtx;
   8605 	  m->fs.fp_offset = m->fs.sp_offset;
   8606 	  m->fs.fp_valid = true;
   8607 	}
   8608     }
   8609 
   8610   if (!int_registers_saved)
   8611     {
   8612       /* If saving registers via PUSH, do so now.  */
   8613       if (!frame.save_regs_using_mov)
   8614 	{
   8615 	  ix86_emit_save_regs ();
   8616 	  int_registers_saved = true;
   8617 	  gcc_assert (m->fs.sp_offset == frame.reg_save_offset);
   8618 	}
   8619 
   8620       /* When using red zone we may start register saving before allocating
   8621 	 the stack frame saving one cycle of the prologue.  However, avoid
   8622 	 doing this if we have to probe the stack; at least on x86_64 the
   8623 	 stack probe can turn into a call that clobbers a red zone location. */
   8624       else if (ix86_using_red_zone ()
   8625 	       && (! TARGET_STACK_PROBE
   8626 		   || frame.stack_pointer_offset < CHECK_STACK_LIMIT))
   8627 	{
   8628 	  ix86_emit_save_regs_using_mov (frame.reg_save_offset);
   8629 	  cfun->machine->red_zone_used = true;
   8630 	  int_registers_saved = true;
   8631 	}
   8632     }
   8633 
   8634   if (frame.red_zone_size != 0)
   8635     cfun->machine->red_zone_used = true;
   8636 
   8637   if (stack_realign_fp)
   8638     {
   8639       int align_bytes = crtl->stack_alignment_needed / BITS_PER_UNIT;
   8640       gcc_assert (align_bytes > MIN_STACK_BOUNDARY / BITS_PER_UNIT);
   8641 
   8642       /* Record last valid frame pointer offset.  */
   8643       m->fs.sp_realigned_fp_last = frame.reg_save_offset;
   8644 
   8645       /* The computation of the size of the re-aligned stack frame means
   8646 	 that we must allocate the size of the register save area before
   8647 	 performing the actual alignment.  Otherwise we cannot guarantee
   8648 	 that there's enough storage above the realignment point.  */
   8649       allocate = frame.reg_save_offset - m->fs.sp_offset
   8650 		 + frame.stack_realign_allocate;
   8651       if (allocate)
   8652         pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
   8653 				   GEN_INT (-allocate), -1, false);
   8654 
   8655       /* Align the stack.  */
   8656       emit_insn (gen_and2_insn (stack_pointer_rtx, GEN_INT (-align_bytes)));
   8657       m->fs.sp_offset = ROUND_UP (m->fs.sp_offset, align_bytes);
   8658       m->fs.sp_realigned_offset = m->fs.sp_offset
   8659 					      - frame.stack_realign_allocate;
   8660       /* The stack pointer may no longer be equal to CFA - m->fs.sp_offset.
   8661 	 Beyond this point, stack access should be done via choose_baseaddr or
   8662 	 by using sp_valid_at and fp_valid_at to determine the correct base
   8663 	 register.  Henceforth, any CFA offset should be thought of as logical
   8664 	 and not physical.  */
   8665       gcc_assert (m->fs.sp_realigned_offset >= m->fs.sp_realigned_fp_last);
   8666       gcc_assert (m->fs.sp_realigned_offset == frame.stack_realign_offset);
   8667       m->fs.sp_realigned = true;
   8668 
   8669       /* SEH unwind emit doesn't currently support REG_CFA_EXPRESSION, which
   8670 	 is needed to describe where a register is saved using a realigned
   8671 	 stack pointer, so we need to invalidate the stack pointer for that
   8672 	 target.  */
   8673       if (TARGET_SEH)
   8674 	m->fs.sp_valid = false;
   8675 
   8676       /* If SP offset is non-immediate after allocation of the stack frame,
   8677 	 then emit SSE saves or stub call prior to allocating the rest of the
   8678 	 stack frame.  This is less efficient for the out-of-line stub because
   8679 	 we can't combine allocations across the call barrier, but it's better
   8680 	 than using a scratch register.  */
   8681       else if (!x86_64_immediate_operand (GEN_INT (frame.stack_pointer_offset
   8682 						   - m->fs.sp_realigned_offset),
   8683 					  Pmode))
   8684 	{
   8685 	  if (!sse_registers_saved)
   8686 	    {
   8687 	      ix86_emit_save_sse_regs_using_mov (frame.sse_reg_save_offset);
   8688 	      sse_registers_saved = true;
   8689 	    }
   8690 	  else if (save_stub_call_needed)
   8691 	    {
   8692 	      ix86_emit_outlined_ms2sysv_save (frame);
   8693 	      save_stub_call_needed = false;
   8694 	    }
   8695 	}
   8696     }
   8697 
   8698   allocate = frame.stack_pointer_offset - m->fs.sp_offset;
   8699 
   8700   if (flag_stack_usage_info)
   8701     {
   8702       /* We start to count from ARG_POINTER.  */
   8703       HOST_WIDE_INT stack_size = frame.stack_pointer_offset;
   8704 
   8705       /* If it was realigned, take into account the fake frame.  */
   8706       if (stack_realign_drap)
   8707 	{
   8708 	  if (ix86_static_chain_on_stack)
   8709 	    stack_size += UNITS_PER_WORD;
   8710 
   8711 	  if (!call_used_or_fixed_reg_p (REGNO (crtl->drap_reg)))
   8712 	    stack_size += UNITS_PER_WORD;
   8713 
   8714 	  /* This over-estimates by 1 minimal-stack-alignment-unit but
   8715 	     mitigates that by counting in the new return address slot.  */
   8716 	  current_function_dynamic_stack_size
   8717 	    += crtl->stack_alignment_needed / BITS_PER_UNIT;
   8718 	}
   8719 
   8720       current_function_static_stack_size = stack_size;
   8721     }
   8722 
   8723   /* On SEH target with very large frame size, allocate an area to save
   8724      SSE registers (as the very large allocation won't be described).  */
   8725   if (TARGET_SEH
   8726       && frame.stack_pointer_offset > SEH_MAX_FRAME_SIZE
   8727       && !sse_registers_saved)
   8728     {
   8729       HOST_WIDE_INT sse_size
   8730 	= frame.sse_reg_save_offset - frame.reg_save_offset;
   8731 
   8732       gcc_assert (int_registers_saved);
   8733 
   8734       /* No need to do stack checking as the area will be immediately
   8735 	 written.  */
   8736       pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
   8737 			         GEN_INT (-sse_size), -1,
   8738 				 m->fs.cfa_reg == stack_pointer_rtx);
   8739       allocate -= sse_size;
   8740       ix86_emit_save_sse_regs_using_mov (frame.sse_reg_save_offset);
   8741       sse_registers_saved = true;
   8742     }
   8743 
   8744   /* If stack clash protection is requested, then probe the stack, unless it
   8745      is already probed on the target.  */
   8746   if (allocate >= 0
   8747       && flag_stack_clash_protection
   8748       && !ix86_target_stack_probe ())
   8749     {
   8750       ix86_adjust_stack_and_probe (allocate, int_registers_saved, false);
   8751       allocate = 0;
   8752     }
   8753 
   8754   /* The stack has already been decremented by the instruction calling us
   8755      so probe if the size is non-negative to preserve the protection area.  */
   8756   else if (allocate >= 0 && flag_stack_check == STATIC_BUILTIN_STACK_CHECK)
   8757     {
   8758       const HOST_WIDE_INT probe_interval = get_probe_interval ();
   8759 
   8760       if (STACK_CHECK_MOVING_SP)
   8761 	{
   8762 	  if (crtl->is_leaf
   8763 	      && !cfun->calls_alloca
   8764 	      && allocate <= probe_interval)
   8765 	    ;
   8766 
   8767 	  else
   8768 	    {
   8769 	      ix86_adjust_stack_and_probe (allocate, int_registers_saved, true);
   8770 	      allocate = 0;
   8771 	    }
   8772 	}
   8773 
   8774       else
   8775 	{
   8776 	  HOST_WIDE_INT size = allocate;
   8777 
   8778 	  if (TARGET_64BIT && size >= HOST_WIDE_INT_C (0x80000000))
   8779 	    size = 0x80000000 - get_stack_check_protect () - 1;
   8780 
   8781 	  if (TARGET_STACK_PROBE)
   8782 	    {
   8783 	      if (crtl->is_leaf && !cfun->calls_alloca)
   8784 		{
   8785 		  if (size > probe_interval)
   8786 		    ix86_emit_probe_stack_range (0, size, int_registers_saved);
   8787 		}
   8788 	      else
   8789 		ix86_emit_probe_stack_range (0,
   8790 					     size + get_stack_check_protect (),
   8791 					     int_registers_saved);
   8792 	    }
   8793 	  else
   8794 	    {
   8795 	      if (crtl->is_leaf && !cfun->calls_alloca)
   8796 		{
   8797 		  if (size > probe_interval
   8798 		      && size > get_stack_check_protect ())
   8799 		    ix86_emit_probe_stack_range (get_stack_check_protect (),
   8800 						 (size
   8801 						  - get_stack_check_protect ()),
   8802 						 int_registers_saved);
   8803 		}
   8804 	      else
   8805 		ix86_emit_probe_stack_range (get_stack_check_protect (), size,
   8806 					     int_registers_saved);
   8807 	    }
   8808 	}
   8809     }
   8810 
   8811   if (allocate == 0)
   8812     ;
   8813   else if (!ix86_target_stack_probe ()
   8814 	   || frame.stack_pointer_offset < CHECK_STACK_LIMIT)
   8815     {
   8816       pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
   8817 			         GEN_INT (-allocate), -1,
   8818 			         m->fs.cfa_reg == stack_pointer_rtx);
   8819     }
   8820   else
   8821     {
   8822       rtx eax = gen_rtx_REG (Pmode, AX_REG);
   8823       rtx r10 = NULL;
   8824       const bool sp_is_cfa_reg = (m->fs.cfa_reg == stack_pointer_rtx);
   8825       bool eax_live = ix86_eax_live_at_start_p ();
   8826       bool r10_live = false;
   8827 
   8828       if (TARGET_64BIT)
   8829         r10_live = (DECL_STATIC_CHAIN (current_function_decl) != 0);
   8830 
   8831       if (eax_live)
   8832 	{
   8833 	  insn = emit_insn (gen_push (eax));
   8834 	  allocate -= UNITS_PER_WORD;
   8835 	  /* Note that SEH directives need to continue tracking the stack
   8836 	     pointer even after the frame pointer has been set up.  */
   8837 	  if (sp_is_cfa_reg || TARGET_SEH)
   8838 	    {
   8839 	      if (sp_is_cfa_reg)
   8840 		m->fs.cfa_offset += UNITS_PER_WORD;
   8841 	      RTX_FRAME_RELATED_P (insn) = 1;
   8842 	      add_reg_note (insn, REG_FRAME_RELATED_EXPR,
   8843 			    gen_rtx_SET (stack_pointer_rtx,
   8844 					 plus_constant (Pmode,
   8845 							stack_pointer_rtx,
   8846 							-UNITS_PER_WORD)));
   8847 	    }
   8848 	}
   8849 
   8850       if (r10_live)
   8851 	{
   8852 	  r10 = gen_rtx_REG (Pmode, R10_REG);
   8853 	  insn = emit_insn (gen_push (r10));
   8854 	  allocate -= UNITS_PER_WORD;
   8855 	  if (sp_is_cfa_reg || TARGET_SEH)
   8856 	    {
   8857 	      if (sp_is_cfa_reg)
   8858 		m->fs.cfa_offset += UNITS_PER_WORD;
   8859 	      RTX_FRAME_RELATED_P (insn) = 1;
   8860 	      add_reg_note (insn, REG_FRAME_RELATED_EXPR,
   8861 			    gen_rtx_SET (stack_pointer_rtx,
   8862 					 plus_constant (Pmode,
   8863 							stack_pointer_rtx,
   8864 							-UNITS_PER_WORD)));
   8865 	    }
   8866 	}
   8867 
   8868       emit_move_insn (eax, GEN_INT (allocate));
   8869       emit_insn (gen_allocate_stack_worker_probe (Pmode, eax, eax));
   8870 
   8871       /* Use the fact that AX still contains ALLOCATE.  */
   8872       insn = emit_insn (gen_pro_epilogue_adjust_stack_sub
   8873 			(Pmode, stack_pointer_rtx, stack_pointer_rtx, eax));
   8874 
   8875       if (sp_is_cfa_reg || TARGET_SEH)
   8876 	{
   8877 	  if (sp_is_cfa_reg)
   8878 	    m->fs.cfa_offset += allocate;
   8879 	  RTX_FRAME_RELATED_P (insn) = 1;
   8880 	  add_reg_note (insn, REG_FRAME_RELATED_EXPR,
   8881 			gen_rtx_SET (stack_pointer_rtx,
   8882 				     plus_constant (Pmode, stack_pointer_rtx,
   8883 						    -allocate)));
   8884 	}
   8885       m->fs.sp_offset += allocate;
   8886 
   8887       /* Use stack_pointer_rtx for relative addressing so that code works for
   8888 	 realigned stack.  But this means that we need a blockage to prevent
   8889 	 stores based on the frame pointer from being scheduled before.  */
   8890       if (r10_live && eax_live)
   8891         {
   8892 	  t = gen_rtx_PLUS (Pmode, stack_pointer_rtx, eax);
   8893 	  emit_move_insn (gen_rtx_REG (word_mode, R10_REG),
   8894 			  gen_frame_mem (word_mode, t));
   8895 	  t = plus_constant (Pmode, t, UNITS_PER_WORD);
   8896 	  emit_move_insn (gen_rtx_REG (word_mode, AX_REG),
   8897 			  gen_frame_mem (word_mode, t));
   8898 	  emit_insn (gen_memory_blockage ());
   8899 	}
   8900       else if (eax_live || r10_live)
   8901 	{
   8902 	  t = gen_rtx_PLUS (Pmode, stack_pointer_rtx, eax);
   8903 	  emit_move_insn (gen_rtx_REG (word_mode,
   8904 				       (eax_live ? AX_REG : R10_REG)),
   8905 			  gen_frame_mem (word_mode, t));
   8906 	  emit_insn (gen_memory_blockage ());
   8907 	}
   8908     }
   8909   gcc_assert (m->fs.sp_offset == frame.stack_pointer_offset);
   8910 
   8911   /* If we havn't already set up the frame pointer, do so now.  */
   8912   if (frame_pointer_needed && !m->fs.fp_valid)
   8913     {
   8914       insn = gen_add3_insn (hard_frame_pointer_rtx, stack_pointer_rtx,
   8915 			    GEN_INT (frame.stack_pointer_offset
   8916 				     - frame.hard_frame_pointer_offset));
   8917       insn = emit_insn (insn);
   8918       RTX_FRAME_RELATED_P (insn) = 1;
   8919       add_reg_note (insn, REG_CFA_ADJUST_CFA, NULL);
   8920 
   8921       if (m->fs.cfa_reg == stack_pointer_rtx)
   8922 	m->fs.cfa_reg = hard_frame_pointer_rtx;
   8923       m->fs.fp_offset = frame.hard_frame_pointer_offset;
   8924       m->fs.fp_valid = true;
   8925     }
   8926 
   8927   if (!int_registers_saved)
   8928     ix86_emit_save_regs_using_mov (frame.reg_save_offset);
   8929   if (!sse_registers_saved)
   8930     ix86_emit_save_sse_regs_using_mov (frame.sse_reg_save_offset);
   8931   else if (save_stub_call_needed)
   8932     ix86_emit_outlined_ms2sysv_save (frame);
   8933 
   8934   /* For the mcount profiling on 32 bit PIC mode we need to emit SET_GOT
   8935      in PROLOGUE.  */
   8936   if (!TARGET_64BIT && pic_offset_table_rtx && crtl->profile && !flag_fentry)
   8937     {
   8938       rtx pic = gen_rtx_REG (Pmode, REAL_PIC_OFFSET_TABLE_REGNUM);
   8939       insn = emit_insn (gen_set_got (pic));
   8940       RTX_FRAME_RELATED_P (insn) = 1;
   8941       add_reg_note (insn, REG_CFA_FLUSH_QUEUE, NULL_RTX);
   8942       emit_insn (gen_prologue_use (pic));
   8943       /* Deleting already emmitted SET_GOT if exist and allocated to
   8944 	 REAL_PIC_OFFSET_TABLE_REGNUM.  */
   8945       ix86_elim_entry_set_got (pic);
   8946     }
   8947 
   8948   if (crtl->drap_reg && !crtl->stack_realign_needed)
   8949     {
   8950       /* vDRAP is setup but after reload it turns out stack realign
   8951          isn't necessary, here we will emit prologue to setup DRAP
   8952          without stack realign adjustment */
   8953       t = choose_baseaddr (0, NULL);
   8954       emit_insn (gen_rtx_SET (crtl->drap_reg, t));
   8955     }
   8956 
   8957   /* Prevent instructions from being scheduled into register save push
   8958      sequence when access to the redzone area is done through frame pointer.
   8959      The offset between the frame pointer and the stack pointer is calculated
   8960      relative to the value of the stack pointer at the end of the function
   8961      prologue, and moving instructions that access redzone area via frame
   8962      pointer inside push sequence violates this assumption.  */
   8963   if (frame_pointer_needed && frame.red_zone_size)
   8964     emit_insn (gen_memory_blockage ());
   8965 
   8966   /* SEH requires that the prologue end within 256 bytes of the start of
   8967      the function.  Prevent instruction schedules that would extend that.
   8968      Further, prevent alloca modifications to the stack pointer from being
   8969      combined with prologue modifications.  */
   8970   if (TARGET_SEH)
   8971     emit_insn (gen_prologue_use (stack_pointer_rtx));
   8972 }
   8973 
   8974 /* Emit code to restore REG using a POP insn.  */
   8975 
   8976 static void
   8977 ix86_emit_restore_reg_using_pop (rtx reg)
   8978 {
   8979   struct machine_function *m = cfun->machine;
   8980   rtx_insn *insn = emit_insn (gen_pop (reg));
   8981 
   8982   ix86_add_cfa_restore_note (insn, reg, m->fs.sp_offset);
   8983   m->fs.sp_offset -= UNITS_PER_WORD;
   8984 
   8985   if (m->fs.cfa_reg == crtl->drap_reg
   8986       && REGNO (reg) == REGNO (crtl->drap_reg))
   8987     {
   8988       /* Previously we'd represented the CFA as an expression
   8989 	 like *(%ebp - 8).  We've just popped that value from
   8990 	 the stack, which means we need to reset the CFA to
   8991 	 the drap register.  This will remain until we restore
   8992 	 the stack pointer.  */
   8993       add_reg_note (insn, REG_CFA_DEF_CFA, reg);
   8994       RTX_FRAME_RELATED_P (insn) = 1;
   8995 
   8996       /* This means that the DRAP register is valid for addressing too.  */
   8997       m->fs.drap_valid = true;
   8998       return;
   8999     }
   9000 
   9001   if (m->fs.cfa_reg == stack_pointer_rtx)
   9002     {
   9003       rtx x = plus_constant (Pmode, stack_pointer_rtx, UNITS_PER_WORD);
   9004       x = gen_rtx_SET (stack_pointer_rtx, x);
   9005       add_reg_note (insn, REG_CFA_ADJUST_CFA, x);
   9006       RTX_FRAME_RELATED_P (insn) = 1;
   9007 
   9008       m->fs.cfa_offset -= UNITS_PER_WORD;
   9009     }
   9010 
   9011   /* When the frame pointer is the CFA, and we pop it, we are
   9012      swapping back to the stack pointer as the CFA.  This happens
   9013      for stack frames that don't allocate other data, so we assume
   9014      the stack pointer is now pointing at the return address, i.e.
   9015      the function entry state, which makes the offset be 1 word.  */
   9016   if (reg == hard_frame_pointer_rtx)
   9017     {
   9018       m->fs.fp_valid = false;
   9019       if (m->fs.cfa_reg == hard_frame_pointer_rtx)
   9020 	{
   9021 	  m->fs.cfa_reg = stack_pointer_rtx;
   9022 	  m->fs.cfa_offset -= UNITS_PER_WORD;
   9023 
   9024 	  add_reg_note (insn, REG_CFA_DEF_CFA,
   9025 			plus_constant (Pmode, stack_pointer_rtx,
   9026 				       m->fs.cfa_offset));
   9027 	  RTX_FRAME_RELATED_P (insn) = 1;
   9028 	}
   9029     }
   9030 }
   9031 
   9032 /* Emit code to restore saved registers using POP insns.  */
   9033 
   9034 static void
   9035 ix86_emit_restore_regs_using_pop (void)
   9036 {
   9037   unsigned int regno;
   9038 
   9039   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
   9040     if (GENERAL_REGNO_P (regno) && ix86_save_reg (regno, false, true))
   9041       ix86_emit_restore_reg_using_pop (gen_rtx_REG (word_mode, regno));
   9042 }
   9043 
   9044 /* Emit code and notes for the LEAVE instruction.  If insn is non-null,
   9045    omits the emit and only attaches the notes.  */
   9046 
   9047 static void
   9048 ix86_emit_leave (rtx_insn *insn)
   9049 {
   9050   struct machine_function *m = cfun->machine;
   9051 
   9052   if (!insn)
   9053     insn = emit_insn (gen_leave (word_mode));
   9054 
   9055   ix86_add_queued_cfa_restore_notes (insn);
   9056 
   9057   gcc_assert (m->fs.fp_valid);
   9058   m->fs.sp_valid = true;
   9059   m->fs.sp_realigned = false;
   9060   m->fs.sp_offset = m->fs.fp_offset - UNITS_PER_WORD;
   9061   m->fs.fp_valid = false;
   9062 
   9063   if (m->fs.cfa_reg == hard_frame_pointer_rtx)
   9064     {
   9065       m->fs.cfa_reg = stack_pointer_rtx;
   9066       m->fs.cfa_offset = m->fs.sp_offset;
   9067 
   9068       add_reg_note (insn, REG_CFA_DEF_CFA,
   9069 		    plus_constant (Pmode, stack_pointer_rtx,
   9070 				   m->fs.sp_offset));
   9071       RTX_FRAME_RELATED_P (insn) = 1;
   9072     }
   9073   ix86_add_cfa_restore_note (insn, hard_frame_pointer_rtx,
   9074 			     m->fs.fp_offset);
   9075 }
   9076 
   9077 /* Emit code to restore saved registers using MOV insns.
   9078    First register is restored from CFA - CFA_OFFSET.  */
   9079 static void
   9080 ix86_emit_restore_regs_using_mov (HOST_WIDE_INT cfa_offset,
   9081 				  bool maybe_eh_return)
   9082 {
   9083   struct machine_function *m = cfun->machine;
   9084   unsigned int regno;
   9085 
   9086   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
   9087     if (GENERAL_REGNO_P (regno) && ix86_save_reg (regno, maybe_eh_return, true))
   9088       {
   9089 	rtx reg = gen_rtx_REG (word_mode, regno);
   9090 	rtx mem;
   9091 	rtx_insn *insn;
   9092 
   9093 	mem = choose_baseaddr (cfa_offset, NULL);
   9094 	mem = gen_frame_mem (word_mode, mem);
   9095 	insn = emit_move_insn (reg, mem);
   9096 
   9097         if (m->fs.cfa_reg == crtl->drap_reg && regno == REGNO (crtl->drap_reg))
   9098 	  {
   9099 	    /* Previously we'd represented the CFA as an expression
   9100 	       like *(%ebp - 8).  We've just popped that value from
   9101 	       the stack, which means we need to reset the CFA to
   9102 	       the drap register.  This will remain until we restore
   9103 	       the stack pointer.  */
   9104 	    add_reg_note (insn, REG_CFA_DEF_CFA, reg);
   9105 	    RTX_FRAME_RELATED_P (insn) = 1;
   9106 
   9107 	    /* This means that the DRAP register is valid for addressing.  */
   9108 	    m->fs.drap_valid = true;
   9109 	  }
   9110 	else
   9111 	  ix86_add_cfa_restore_note (NULL, reg, cfa_offset);
   9112 
   9113 	cfa_offset -= UNITS_PER_WORD;
   9114       }
   9115 }
   9116 
   9117 /* Emit code to restore saved registers using MOV insns.
   9118    First register is restored from CFA - CFA_OFFSET.  */
   9119 static void
   9120 ix86_emit_restore_sse_regs_using_mov (HOST_WIDE_INT cfa_offset,
   9121 				      bool maybe_eh_return)
   9122 {
   9123   unsigned int regno;
   9124 
   9125   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
   9126     if (SSE_REGNO_P (regno) && ix86_save_reg (regno, maybe_eh_return, true))
   9127       {
   9128 	rtx reg = gen_rtx_REG (V4SFmode, regno);
   9129 	rtx mem;
   9130 	unsigned int align = GET_MODE_ALIGNMENT (V4SFmode);
   9131 
   9132 	mem = choose_baseaddr (cfa_offset, &align);
   9133 	mem = gen_rtx_MEM (V4SFmode, mem);
   9134 
   9135 	/* The location aligment depends upon the base register.  */
   9136 	align = MIN (GET_MODE_ALIGNMENT (V4SFmode), align);
   9137 	gcc_assert (! (cfa_offset & (align / BITS_PER_UNIT - 1)));
   9138 	set_mem_align (mem, align);
   9139 	emit_insn (gen_rtx_SET (reg, mem));
   9140 
   9141 	ix86_add_cfa_restore_note (NULL, reg, cfa_offset);
   9142 
   9143 	cfa_offset -= GET_MODE_SIZE (V4SFmode);
   9144       }
   9145 }
   9146 
   9147 static void
   9148 ix86_emit_outlined_ms2sysv_restore (const struct ix86_frame &frame,
   9149 				  bool use_call, int style)
   9150 {
   9151   struct machine_function *m = cfun->machine;
   9152   const unsigned ncregs = NUM_X86_64_MS_CLOBBERED_REGS
   9153 			  + m->call_ms2sysv_extra_regs;
   9154   rtvec v;
   9155   unsigned int elems_needed, align, i, vi = 0;
   9156   rtx_insn *insn;
   9157   rtx sym, tmp;
   9158   rtx rsi = gen_rtx_REG (word_mode, SI_REG);
   9159   rtx r10 = NULL_RTX;
   9160   const class xlogue_layout &xlogue = xlogue_layout::get_instance ();
   9161   HOST_WIDE_INT stub_ptr_offset = xlogue.get_stub_ptr_offset ();
   9162   HOST_WIDE_INT rsi_offset = frame.stack_realign_offset + stub_ptr_offset;
   9163   rtx rsi_frame_load = NULL_RTX;
   9164   HOST_WIDE_INT rsi_restore_offset = (HOST_WIDE_INT)-1;
   9165   enum xlogue_stub stub;
   9166 
   9167   gcc_assert (!m->fs.fp_valid || frame_pointer_needed);
   9168 
   9169   /* If using a realigned stack, we should never start with padding.  */
   9170   gcc_assert (!stack_realign_fp || !xlogue.get_stack_align_off_in ());
   9171 
   9172   /* Setup RSI as the stub's base pointer.  */
   9173   align = GET_MODE_ALIGNMENT (V4SFmode);
   9174   tmp = choose_baseaddr (rsi_offset, &align, SI_REG);
   9175   gcc_assert (align >= GET_MODE_ALIGNMENT (V4SFmode));
   9176 
   9177   emit_insn (gen_rtx_SET (rsi, tmp));
   9178 
   9179   /* Get a symbol for the stub.  */
   9180   if (frame_pointer_needed)
   9181     stub = use_call ? XLOGUE_STUB_RESTORE_HFP
   9182 		    : XLOGUE_STUB_RESTORE_HFP_TAIL;
   9183   else
   9184     stub = use_call ? XLOGUE_STUB_RESTORE
   9185 		    : XLOGUE_STUB_RESTORE_TAIL;
   9186   sym = xlogue.get_stub_rtx (stub);
   9187 
   9188   elems_needed = ncregs;
   9189   if (use_call)
   9190     elems_needed += 1;
   9191   else
   9192     elems_needed += frame_pointer_needed ? 5 : 3;
   9193   v = rtvec_alloc (elems_needed);
   9194 
   9195   /* We call the epilogue stub when we need to pop incoming args or we are
   9196      doing a sibling call as the tail.  Otherwise, we will emit a jmp to the
   9197      epilogue stub and it is the tail-call.  */
   9198   if (use_call)
   9199       RTVEC_ELT (v, vi++) = gen_rtx_USE (VOIDmode, sym);
   9200   else
   9201     {
   9202       RTVEC_ELT (v, vi++) = ret_rtx;
   9203       RTVEC_ELT (v, vi++) = gen_rtx_USE (VOIDmode, sym);
   9204       if (frame_pointer_needed)
   9205 	{
   9206 	  rtx rbp = gen_rtx_REG (DImode, BP_REG);
   9207 	  gcc_assert (m->fs.fp_valid);
   9208 	  gcc_assert (m->fs.cfa_reg == hard_frame_pointer_rtx);
   9209 
   9210 	  tmp = plus_constant (DImode, rbp, 8);
   9211 	  RTVEC_ELT (v, vi++) = gen_rtx_SET (stack_pointer_rtx, tmp);
   9212 	  RTVEC_ELT (v, vi++) = gen_rtx_SET (rbp, gen_rtx_MEM (DImode, rbp));
   9213 	  tmp = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (VOIDmode));
   9214 	  RTVEC_ELT (v, vi++) = gen_rtx_CLOBBER (VOIDmode, tmp);
   9215 	}
   9216       else
   9217 	{
   9218 	  /* If no hard frame pointer, we set R10 to the SP restore value.  */
   9219 	  gcc_assert (!m->fs.fp_valid);
   9220 	  gcc_assert (m->fs.cfa_reg == stack_pointer_rtx);
   9221 	  gcc_assert (m->fs.sp_valid);
   9222 
   9223 	  r10 = gen_rtx_REG (DImode, R10_REG);
   9224 	  tmp = plus_constant (Pmode, rsi, stub_ptr_offset);
   9225 	  emit_insn (gen_rtx_SET (r10, tmp));
   9226 
   9227 	  RTVEC_ELT (v, vi++) = gen_rtx_SET (stack_pointer_rtx, r10);
   9228 	}
   9229     }
   9230 
   9231   /* Generate frame load insns and restore notes.  */
   9232   for (i = 0; i < ncregs; ++i)
   9233     {
   9234       const xlogue_layout::reginfo &r = xlogue.get_reginfo (i);
   9235       machine_mode mode = SSE_REGNO_P (r.regno) ? V4SFmode : word_mode;
   9236       rtx reg, frame_load;
   9237 
   9238       reg = gen_rtx_REG (mode, r.regno);
   9239       frame_load = gen_frame_load (reg, rsi, r.offset);
   9240 
   9241       /* Save RSI frame load insn & note to add last.  */
   9242       if (r.regno == SI_REG)
   9243 	{
   9244 	  gcc_assert (!rsi_frame_load);
   9245 	  rsi_frame_load = frame_load;
   9246 	  rsi_restore_offset = r.offset;
   9247 	}
   9248       else
   9249 	{
   9250 	  RTVEC_ELT (v, vi++) = frame_load;
   9251 	  ix86_add_cfa_restore_note (NULL, reg, r.offset);
   9252 	}
   9253     }
   9254 
   9255   /* Add RSI frame load & restore note at the end.  */
   9256   gcc_assert (rsi_frame_load);
   9257   gcc_assert (rsi_restore_offset != (HOST_WIDE_INT)-1);
   9258   RTVEC_ELT (v, vi++) = rsi_frame_load;
   9259   ix86_add_cfa_restore_note (NULL, gen_rtx_REG (DImode, SI_REG),
   9260 			     rsi_restore_offset);
   9261 
   9262   /* Finally, for tail-call w/o a hard frame pointer, set SP to R10.  */
   9263   if (!use_call && !frame_pointer_needed)
   9264     {
   9265       gcc_assert (m->fs.sp_valid);
   9266       gcc_assert (!m->fs.sp_realigned);
   9267 
   9268       /* At this point, R10 should point to frame.stack_realign_offset.  */
   9269       if (m->fs.cfa_reg == stack_pointer_rtx)
   9270 	m->fs.cfa_offset += m->fs.sp_offset - frame.stack_realign_offset;
   9271       m->fs.sp_offset = frame.stack_realign_offset;
   9272     }
   9273 
   9274   gcc_assert (vi == (unsigned int)GET_NUM_ELEM (v));
   9275   tmp = gen_rtx_PARALLEL (VOIDmode, v);
   9276   if (use_call)
   9277       insn = emit_insn (tmp);
   9278   else
   9279     {
   9280       insn = emit_jump_insn (tmp);
   9281       JUMP_LABEL (insn) = ret_rtx;
   9282 
   9283       if (frame_pointer_needed)
   9284 	ix86_emit_leave (insn);
   9285       else
   9286 	{
   9287 	  /* Need CFA adjust note.  */
   9288 	  tmp = gen_rtx_SET (stack_pointer_rtx, r10);
   9289 	  add_reg_note (insn, REG_CFA_ADJUST_CFA, tmp);
   9290 	}
   9291     }
   9292 
   9293   RTX_FRAME_RELATED_P (insn) = true;
   9294   ix86_add_queued_cfa_restore_notes (insn);
   9295 
   9296   /* If we're not doing a tail-call, we need to adjust the stack.  */
   9297   if (use_call && m->fs.sp_valid)
   9298     {
   9299       HOST_WIDE_INT dealloc = m->fs.sp_offset - frame.stack_realign_offset;
   9300       pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
   9301 				GEN_INT (dealloc), style,
   9302 				m->fs.cfa_reg == stack_pointer_rtx);
   9303     }
   9304 }
   9305 
   9306 /* Restore function stack, frame, and registers.  */
   9307 
   9308 void
   9309 ix86_expand_epilogue (int style)
   9310 {
   9311   struct machine_function *m = cfun->machine;
   9312   struct machine_frame_state frame_state_save = m->fs;
   9313   bool restore_regs_via_mov;
   9314   bool using_drap;
   9315   bool restore_stub_is_tail = false;
   9316 
   9317   if (ix86_function_naked (current_function_decl))
   9318     {
   9319       /* The program should not reach this point.  */
   9320       emit_insn (gen_ud2 ());
   9321       return;
   9322     }
   9323 
   9324   ix86_finalize_stack_frame_flags ();
   9325   const struct ix86_frame &frame = cfun->machine->frame;
   9326 
   9327   m->fs.sp_realigned = stack_realign_fp;
   9328   m->fs.sp_valid = stack_realign_fp
   9329 		   || !frame_pointer_needed
   9330 		   || crtl->sp_is_unchanging;
   9331   gcc_assert (!m->fs.sp_valid
   9332 	      || m->fs.sp_offset == frame.stack_pointer_offset);
   9333 
   9334   /* The FP must be valid if the frame pointer is present.  */
   9335   gcc_assert (frame_pointer_needed == m->fs.fp_valid);
   9336   gcc_assert (!m->fs.fp_valid
   9337 	      || m->fs.fp_offset == frame.hard_frame_pointer_offset);
   9338 
   9339   /* We must have *some* valid pointer to the stack frame.  */
   9340   gcc_assert (m->fs.sp_valid || m->fs.fp_valid);
   9341 
   9342   /* The DRAP is never valid at this point.  */
   9343   gcc_assert (!m->fs.drap_valid);
   9344 
   9345   /* See the comment about red zone and frame
   9346      pointer usage in ix86_expand_prologue.  */
   9347   if (frame_pointer_needed && frame.red_zone_size)
   9348     emit_insn (gen_memory_blockage ());
   9349 
   9350   using_drap = crtl->drap_reg && crtl->stack_realign_needed;
   9351   gcc_assert (!using_drap || m->fs.cfa_reg == crtl->drap_reg);
   9352 
   9353   /* Determine the CFA offset of the end of the red-zone.  */
   9354   m->fs.red_zone_offset = 0;
   9355   if (ix86_using_red_zone () && crtl->args.pops_args < 65536)
   9356     {
   9357       /* The red-zone begins below return address and error code in
   9358 	 exception handler.  */
   9359       m->fs.red_zone_offset = RED_ZONE_SIZE + INCOMING_FRAME_SP_OFFSET;
   9360 
   9361       /* When the register save area is in the aligned portion of
   9362          the stack, determine the maximum runtime displacement that
   9363 	 matches up with the aligned frame.  */
   9364       if (stack_realign_drap)
   9365 	m->fs.red_zone_offset -= (crtl->stack_alignment_needed / BITS_PER_UNIT
   9366 				  + UNITS_PER_WORD);
   9367     }
   9368 
   9369   HOST_WIDE_INT reg_save_offset = frame.reg_save_offset;
   9370 
   9371   /* Special care must be taken for the normal return case of a function
   9372      using eh_return: the eax and edx registers are marked as saved, but
   9373      not restored along this path.  Adjust the save location to match.  */
   9374   if (crtl->calls_eh_return && style != 2)
   9375     reg_save_offset -= 2 * UNITS_PER_WORD;
   9376 
   9377   /* EH_RETURN requires the use of moves to function properly.  */
   9378   if (crtl->calls_eh_return)
   9379     restore_regs_via_mov = true;
   9380   /* SEH requires the use of pops to identify the epilogue.  */
   9381   else if (TARGET_SEH)
   9382     restore_regs_via_mov = false;
   9383   /* If we're only restoring one register and sp cannot be used then
   9384      using a move instruction to restore the register since it's
   9385      less work than reloading sp and popping the register.  */
   9386   else if (!sp_valid_at (frame.hfp_save_offset) && frame.nregs <= 1)
   9387     restore_regs_via_mov = true;
   9388   else if (TARGET_EPILOGUE_USING_MOVE
   9389 	   && cfun->machine->use_fast_prologue_epilogue
   9390 	   && (frame.nregs > 1
   9391 	       || m->fs.sp_offset != reg_save_offset))
   9392     restore_regs_via_mov = true;
   9393   else if (frame_pointer_needed
   9394 	   && !frame.nregs
   9395 	   && m->fs.sp_offset != reg_save_offset)
   9396     restore_regs_via_mov = true;
   9397   else if (frame_pointer_needed
   9398 	   && TARGET_USE_LEAVE
   9399 	   && cfun->machine->use_fast_prologue_epilogue
   9400 	   && frame.nregs == 1)
   9401     restore_regs_via_mov = true;
   9402   else
   9403     restore_regs_via_mov = false;
   9404 
   9405   if (restore_regs_via_mov || frame.nsseregs)
   9406     {
   9407       /* Ensure that the entire register save area is addressable via
   9408 	 the stack pointer, if we will restore SSE regs via sp.  */
   9409       if (TARGET_64BIT
   9410 	  && m->fs.sp_offset > 0x7fffffff
   9411 	  && sp_valid_at (frame.stack_realign_offset + 1)
   9412 	  && (frame.nsseregs + frame.nregs) != 0)
   9413 	{
   9414 	  pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
   9415 				     GEN_INT (m->fs.sp_offset
   9416 					      - frame.sse_reg_save_offset),
   9417 				     style,
   9418 				     m->fs.cfa_reg == stack_pointer_rtx);
   9419 	}
   9420     }
   9421 
   9422   /* If there are any SSE registers to restore, then we have to do it
   9423      via moves, since there's obviously no pop for SSE regs.  */
   9424   if (frame.nsseregs)
   9425     ix86_emit_restore_sse_regs_using_mov (frame.sse_reg_save_offset,
   9426 					  style == 2);
   9427 
   9428   if (m->call_ms2sysv)
   9429     {
   9430       int pop_incoming_args = crtl->args.pops_args && crtl->args.size;
   9431 
   9432       /* We cannot use a tail-call for the stub if:
   9433 	 1. We have to pop incoming args,
   9434 	 2. We have additional int regs to restore, or
   9435 	 3. A sibling call will be the tail-call, or
   9436 	 4. We are emitting an eh_return_internal epilogue.
   9437 
   9438 	 TODO: Item 4 has not yet tested!
   9439 
   9440 	 If any of the above are true, we will call the stub rather than
   9441 	 jump to it.  */
   9442       restore_stub_is_tail = !(pop_incoming_args || frame.nregs || style != 1);
   9443       ix86_emit_outlined_ms2sysv_restore (frame, !restore_stub_is_tail, style);
   9444     }
   9445 
   9446   /* If using out-of-line stub that is a tail-call, then...*/
   9447   if (m->call_ms2sysv && restore_stub_is_tail)
   9448     {
   9449       /* TODO: parinoid tests. (remove eventually)  */
   9450       gcc_assert (m->fs.sp_valid);
   9451       gcc_assert (!m->fs.sp_realigned);
   9452       gcc_assert (!m->fs.fp_valid);
   9453       gcc_assert (!m->fs.realigned);
   9454       gcc_assert (m->fs.sp_offset == UNITS_PER_WORD);
   9455       gcc_assert (!crtl->drap_reg);
   9456       gcc_assert (!frame.nregs);
   9457     }
   9458   else if (restore_regs_via_mov)
   9459     {
   9460       rtx t;
   9461 
   9462       if (frame.nregs)
   9463 	ix86_emit_restore_regs_using_mov (reg_save_offset, style == 2);
   9464 
   9465       /* eh_return epilogues need %ecx added to the stack pointer.  */
   9466       if (style == 2)
   9467 	{
   9468 	  rtx sa = EH_RETURN_STACKADJ_RTX;
   9469 	  rtx_insn *insn;
   9470 
   9471 	  /* Stack realignment doesn't work with eh_return.  */
   9472 	  if (crtl->stack_realign_needed)
   9473 	    sorry ("Stack realignment not supported with "
   9474 		   "%<__builtin_eh_return%>");
   9475 
   9476 	  /* regparm nested functions don't work with eh_return.  */
   9477 	  if (ix86_static_chain_on_stack)
   9478 	    sorry ("regparm nested function not supported with "
   9479 		   "%<__builtin_eh_return%>");
   9480 
   9481 	  if (frame_pointer_needed)
   9482 	    {
   9483 	      t = gen_rtx_PLUS (Pmode, hard_frame_pointer_rtx, sa);
   9484 	      t = plus_constant (Pmode, t, m->fs.fp_offset - UNITS_PER_WORD);
   9485 	      emit_insn (gen_rtx_SET (sa, t));
   9486 
   9487 	      /* NB: eh_return epilogues must restore the frame pointer
   9488 		 in word_mode since the upper 32 bits of RBP register
   9489 		 can have any values.  */
   9490 	      t = gen_frame_mem (word_mode, hard_frame_pointer_rtx);
   9491 	      rtx frame_reg = gen_rtx_REG (word_mode,
   9492 					   HARD_FRAME_POINTER_REGNUM);
   9493 	      insn = emit_move_insn (frame_reg, t);
   9494 
   9495 	      /* Note that we use SA as a temporary CFA, as the return
   9496 		 address is at the proper place relative to it.  We
   9497 		 pretend this happens at the FP restore insn because
   9498 		 prior to this insn the FP would be stored at the wrong
   9499 		 offset relative to SA, and after this insn we have no
   9500 		 other reasonable register to use for the CFA.  We don't
   9501 		 bother resetting the CFA to the SP for the duration of
   9502 		 the return insn, unless the control flow instrumentation
   9503 		 is done.  In this case the SP is used later and we have
   9504 		 to reset CFA to SP.  */
   9505 	      add_reg_note (insn, REG_CFA_DEF_CFA,
   9506 			    plus_constant (Pmode, sa, UNITS_PER_WORD));
   9507 	      ix86_add_queued_cfa_restore_notes (insn);
   9508 	      add_reg_note (insn, REG_CFA_RESTORE, frame_reg);
   9509 	      RTX_FRAME_RELATED_P (insn) = 1;
   9510 
   9511 	      m->fs.cfa_reg = sa;
   9512 	      m->fs.cfa_offset = UNITS_PER_WORD;
   9513 	      m->fs.fp_valid = false;
   9514 
   9515 	      pro_epilogue_adjust_stack (stack_pointer_rtx, sa,
   9516 					 const0_rtx, style,
   9517 					 flag_cf_protection);
   9518 	    }
   9519 	  else
   9520 	    {
   9521 	      t = gen_rtx_PLUS (Pmode, stack_pointer_rtx, sa);
   9522 	      t = plus_constant (Pmode, t, m->fs.sp_offset - UNITS_PER_WORD);
   9523 	      insn = emit_insn (gen_rtx_SET (stack_pointer_rtx, t));
   9524 	      ix86_add_queued_cfa_restore_notes (insn);
   9525 
   9526 	      gcc_assert (m->fs.cfa_reg == stack_pointer_rtx);
   9527 	      if (m->fs.cfa_offset != UNITS_PER_WORD)
   9528 		{
   9529 		  m->fs.cfa_offset = UNITS_PER_WORD;
   9530 		  add_reg_note (insn, REG_CFA_DEF_CFA,
   9531 				plus_constant (Pmode, stack_pointer_rtx,
   9532 					       UNITS_PER_WORD));
   9533 		  RTX_FRAME_RELATED_P (insn) = 1;
   9534 		}
   9535 	    }
   9536 	  m->fs.sp_offset = UNITS_PER_WORD;
   9537 	  m->fs.sp_valid = true;
   9538 	  m->fs.sp_realigned = false;
   9539 	}
   9540     }
   9541   else
   9542     {
   9543       /* SEH requires that the function end with (1) a stack adjustment
   9544 	 if necessary, (2) a sequence of pops, and (3) a return or
   9545 	 jump instruction.  Prevent insns from the function body from
   9546 	 being scheduled into this sequence.  */
   9547       if (TARGET_SEH)
   9548 	{
   9549 	  /* Prevent a catch region from being adjacent to the standard
   9550 	     epilogue sequence.  Unfortunately neither crtl->uses_eh_lsda
   9551 	     nor several other flags that would be interesting to test are
   9552 	     set up yet.  */
   9553 	  if (flag_non_call_exceptions)
   9554 	    emit_insn (gen_nops (const1_rtx));
   9555 	  else
   9556 	    emit_insn (gen_blockage ());
   9557 	}
   9558 
   9559       /* First step is to deallocate the stack frame so that we can
   9560 	 pop the registers.  If the stack pointer was realigned, it needs
   9561 	 to be restored now.  Also do it on SEH target for very large
   9562 	 frame as the emitted instructions aren't allowed by the ABI
   9563 	 in epilogues.  */
   9564       if (!m->fs.sp_valid || m->fs.sp_realigned
   9565  	  || (TARGET_SEH
   9566 	      && (m->fs.sp_offset - reg_save_offset
   9567 		  >= SEH_MAX_FRAME_SIZE)))
   9568 	{
   9569 	  pro_epilogue_adjust_stack (stack_pointer_rtx, hard_frame_pointer_rtx,
   9570 				     GEN_INT (m->fs.fp_offset
   9571 					      - reg_save_offset),
   9572 				     style, false);
   9573 	}
   9574       else if (m->fs.sp_offset != reg_save_offset)
   9575 	{
   9576 	  pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
   9577 				     GEN_INT (m->fs.sp_offset
   9578 					      - reg_save_offset),
   9579 				     style,
   9580 				     m->fs.cfa_reg == stack_pointer_rtx);
   9581 	}
   9582 
   9583       ix86_emit_restore_regs_using_pop ();
   9584     }
   9585 
   9586   /* If we used a stack pointer and haven't already got rid of it,
   9587      then do so now.  */
   9588   if (m->fs.fp_valid)
   9589     {
   9590       /* If the stack pointer is valid and pointing at the frame
   9591 	 pointer store address, then we only need a pop.  */
   9592       if (sp_valid_at (frame.hfp_save_offset)
   9593 	  && m->fs.sp_offset == frame.hfp_save_offset)
   9594 	ix86_emit_restore_reg_using_pop (hard_frame_pointer_rtx);
   9595       /* Leave results in shorter dependency chains on CPUs that are
   9596 	 able to grok it fast.  */
   9597       else if (TARGET_USE_LEAVE
   9598 	       || optimize_bb_for_size_p (EXIT_BLOCK_PTR_FOR_FN (cfun))
   9599 	       || !cfun->machine->use_fast_prologue_epilogue)
   9600 	ix86_emit_leave (NULL);
   9601       else
   9602         {
   9603 	  pro_epilogue_adjust_stack (stack_pointer_rtx,
   9604 				     hard_frame_pointer_rtx,
   9605 				     const0_rtx, style, !using_drap);
   9606 	  ix86_emit_restore_reg_using_pop (hard_frame_pointer_rtx);
   9607         }
   9608     }
   9609 
   9610   if (using_drap)
   9611     {
   9612       int param_ptr_offset = UNITS_PER_WORD;
   9613       rtx_insn *insn;
   9614 
   9615       gcc_assert (stack_realign_drap);
   9616 
   9617       if (ix86_static_chain_on_stack)
   9618 	param_ptr_offset += UNITS_PER_WORD;
   9619       if (!call_used_or_fixed_reg_p (REGNO (crtl->drap_reg)))
   9620 	param_ptr_offset += UNITS_PER_WORD;
   9621 
   9622       insn = emit_insn (gen_rtx_SET
   9623 			(stack_pointer_rtx,
   9624 			 plus_constant (Pmode, crtl->drap_reg,
   9625 					-param_ptr_offset)));
   9626       m->fs.cfa_reg = stack_pointer_rtx;
   9627       m->fs.cfa_offset = param_ptr_offset;
   9628       m->fs.sp_offset = param_ptr_offset;
   9629       m->fs.realigned = false;
   9630 
   9631       add_reg_note (insn, REG_CFA_DEF_CFA,
   9632 		    plus_constant (Pmode, stack_pointer_rtx,
   9633 				   param_ptr_offset));
   9634       RTX_FRAME_RELATED_P (insn) = 1;
   9635 
   9636       if (!call_used_or_fixed_reg_p (REGNO (crtl->drap_reg)))
   9637 	ix86_emit_restore_reg_using_pop (crtl->drap_reg);
   9638     }
   9639 
   9640   /* At this point the stack pointer must be valid, and we must have
   9641      restored all of the registers.  We may not have deallocated the
   9642      entire stack frame.  We've delayed this until now because it may
   9643      be possible to merge the local stack deallocation with the
   9644      deallocation forced by ix86_static_chain_on_stack.   */
   9645   gcc_assert (m->fs.sp_valid);
   9646   gcc_assert (!m->fs.sp_realigned);
   9647   gcc_assert (!m->fs.fp_valid);
   9648   gcc_assert (!m->fs.realigned);
   9649   if (m->fs.sp_offset != UNITS_PER_WORD)
   9650     {
   9651       pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
   9652 				 GEN_INT (m->fs.sp_offset - UNITS_PER_WORD),
   9653 				 style, true);
   9654     }
   9655   else
   9656     ix86_add_queued_cfa_restore_notes (get_last_insn ());
   9657 
   9658   /* Sibcall epilogues don't want a return instruction.  */
   9659   if (style == 0)
   9660     {
   9661       m->fs = frame_state_save;
   9662       return;
   9663     }
   9664 
   9665   if (cfun->machine->func_type != TYPE_NORMAL)
   9666     emit_jump_insn (gen_interrupt_return ());
   9667   else if (crtl->args.pops_args && crtl->args.size)
   9668     {
   9669       rtx popc = GEN_INT (crtl->args.pops_args);
   9670 
   9671       /* i386 can only pop 64K bytes.  If asked to pop more, pop return
   9672 	 address, do explicit add, and jump indirectly to the caller.  */
   9673 
   9674       if (crtl->args.pops_args >= 65536)
   9675 	{
   9676 	  rtx ecx = gen_rtx_REG (SImode, CX_REG);
   9677 	  rtx_insn *insn;
   9678 
   9679 	  /* There is no "pascal" calling convention in any 64bit ABI.  */
   9680 	  gcc_assert (!TARGET_64BIT);
   9681 
   9682 	  insn = emit_insn (gen_pop (ecx));
   9683 	  m->fs.cfa_offset -= UNITS_PER_WORD;
   9684 	  m->fs.sp_offset -= UNITS_PER_WORD;
   9685 
   9686 	  rtx x = plus_constant (Pmode, stack_pointer_rtx, UNITS_PER_WORD);
   9687 	  x = gen_rtx_SET (stack_pointer_rtx, x);
   9688 	  add_reg_note (insn, REG_CFA_ADJUST_CFA, x);
   9689 	  add_reg_note (insn, REG_CFA_REGISTER, gen_rtx_SET (ecx, pc_rtx));
   9690 	  RTX_FRAME_RELATED_P (insn) = 1;
   9691 
   9692 	  pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
   9693 				     popc, -1, true);
   9694 	  emit_jump_insn (gen_simple_return_indirect_internal (ecx));
   9695 	}
   9696       else
   9697 	emit_jump_insn (gen_simple_return_pop_internal (popc));
   9698     }
   9699   else if (!m->call_ms2sysv || !restore_stub_is_tail)
   9700     {
   9701       /* In case of return from EH a simple return cannot be used
   9702 	 as a return address will be compared with a shadow stack
   9703 	 return address.  Use indirect jump instead.  */
   9704       if (style == 2 && flag_cf_protection)
   9705 	{
   9706 	  /* Register used in indirect jump must be in word_mode.  But
   9707 	     Pmode may not be the same as word_mode for x32.  */
   9708 	  rtx ecx = gen_rtx_REG (word_mode, CX_REG);
   9709 	  rtx_insn *insn;
   9710 
   9711 	  insn = emit_insn (gen_pop (ecx));
   9712 	  m->fs.cfa_offset -= UNITS_PER_WORD;
   9713 	  m->fs.sp_offset -= UNITS_PER_WORD;
   9714 
   9715 	  rtx x = plus_constant (Pmode, stack_pointer_rtx, UNITS_PER_WORD);
   9716 	  x = gen_rtx_SET (stack_pointer_rtx, x);
   9717 	  add_reg_note (insn, REG_CFA_ADJUST_CFA, x);
   9718 	  add_reg_note (insn, REG_CFA_REGISTER, gen_rtx_SET (ecx, pc_rtx));
   9719 	  RTX_FRAME_RELATED_P (insn) = 1;
   9720 
   9721 	  emit_jump_insn (gen_simple_return_indirect_internal (ecx));
   9722 	}
   9723       else
   9724 	emit_jump_insn (gen_simple_return_internal ());
   9725     }
   9726 
   9727   /* Restore the state back to the state from the prologue,
   9728      so that it's correct for the next epilogue.  */
   9729   m->fs = frame_state_save;
   9730 }
   9731 
   9732 /* Reset from the function's potential modifications.  */
   9733 
   9734 static void
   9735 ix86_output_function_epilogue (FILE *file ATTRIBUTE_UNUSED)
   9736 {
   9737   if (pic_offset_table_rtx
   9738       && !ix86_use_pseudo_pic_reg ())
   9739     SET_REGNO (pic_offset_table_rtx, REAL_PIC_OFFSET_TABLE_REGNUM);
   9740 
   9741   if (TARGET_MACHO)
   9742     {
   9743       rtx_insn *insn = get_last_insn ();
   9744       rtx_insn *deleted_debug_label = NULL;
   9745 
   9746       /* Mach-O doesn't support labels at the end of objects, so if
   9747          it looks like we might want one, take special action.
   9748         First, collect any sequence of deleted debug labels.  */
   9749       while (insn
   9750 	     && NOTE_P (insn)
   9751 	     && NOTE_KIND (insn) != NOTE_INSN_DELETED_LABEL)
   9752 	{
   9753 	  /* Don't insert a nop for NOTE_INSN_DELETED_DEBUG_LABEL
   9754 	     notes only, instead set their CODE_LABEL_NUMBER to -1,
   9755 	     otherwise there would be code generation differences
   9756 	     in between -g and -g0.  */
   9757 	  if (NOTE_P (insn) && NOTE_KIND (insn)
   9758 	      == NOTE_INSN_DELETED_DEBUG_LABEL)
   9759 	    deleted_debug_label = insn;
   9760 	  insn = PREV_INSN (insn);
   9761 	}
   9762 
   9763       /* If we have:
   9764 	 label:
   9765 	    barrier
   9766 	  then this needs to be detected, so skip past the barrier.  */
   9767 
   9768       if (insn && BARRIER_P (insn))
   9769 	insn = PREV_INSN (insn);
   9770 
   9771       /* Up to now we've only seen notes or barriers.  */
   9772       if (insn)
   9773 	{
   9774 	  if (LABEL_P (insn)
   9775 	      || (NOTE_P (insn)
   9776 		  && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL))
   9777 	    /* Trailing label.  */
   9778 	    fputs ("\tnop\n", file);
   9779 	  else if (cfun && ! cfun->is_thunk)
   9780 	    {
   9781 	      /* See if we have a completely empty function body, skipping
   9782 	         the special case of the picbase thunk emitted as asm.  */
   9783 	      while (insn && ! INSN_P (insn))
   9784 		insn = PREV_INSN (insn);
   9785 	      /* If we don't find any insns, we've got an empty function body;
   9786 		 I.e. completely empty - without a return or branch.  This is
   9787 		 taken as the case where a function body has been removed
   9788 		 because it contains an inline __builtin_unreachable().  GCC
   9789 		 declares that reaching __builtin_unreachable() means UB so
   9790 		 we're not obliged to do anything special; however, we want
   9791 		 non-zero-sized function bodies.  To meet this, and help the
   9792 		 user out, let's trap the case.  */
   9793 	      if (insn == NULL)
   9794 		fputs ("\tud2\n", file);
   9795 	    }
   9796 	}
   9797       else if (deleted_debug_label)
   9798 	for (insn = deleted_debug_label; insn; insn = NEXT_INSN (insn))
   9799 	  if (NOTE_KIND (insn) == NOTE_INSN_DELETED_DEBUG_LABEL)
   9800 	    CODE_LABEL_NUMBER (insn) = -1;
   9801     }
   9802 }
   9803 
   9804 /* Implement TARGET_ASM_PRINT_PATCHABLE_FUNCTION_ENTRY.  */
   9805 
   9806 void
   9807 ix86_print_patchable_function_entry (FILE *file,
   9808 				     unsigned HOST_WIDE_INT patch_area_size,
   9809 				     bool record_p)
   9810 {
   9811   if (cfun->machine->function_label_emitted)
   9812     {
   9813       /* NB: When ix86_print_patchable_function_entry is called after
   9814 	 function table has been emitted, we have inserted or queued
   9815 	 a pseudo UNSPECV_PATCHABLE_AREA instruction at the proper
   9816 	 place.  There is nothing to do here.  */
   9817       return;
   9818     }
   9819 
   9820   default_print_patchable_function_entry (file, patch_area_size,
   9821 					  record_p);
   9822 }
   9823 
   9824 /* Output patchable area.  NB: default_print_patchable_function_entry
   9825    isn't available in i386.md.  */
   9826 
   9827 void
   9828 ix86_output_patchable_area (unsigned int patch_area_size,
   9829 			    bool record_p)
   9830 {
   9831   default_print_patchable_function_entry (asm_out_file,
   9832 					  patch_area_size,
   9833 					  record_p);
   9834 }
   9835 
   9836 /* Return a scratch register to use in the split stack prologue.  The
   9837    split stack prologue is used for -fsplit-stack.  It is the first
   9838    instructions in the function, even before the regular prologue.
   9839    The scratch register can be any caller-saved register which is not
   9840    used for parameters or for the static chain.  */
   9841 
   9842 static unsigned int
   9843 split_stack_prologue_scratch_regno (void)
   9844 {
   9845   if (TARGET_64BIT)
   9846     return R11_REG;
   9847   else
   9848     {
   9849       bool is_fastcall, is_thiscall;
   9850       int regparm;
   9851 
   9852       is_fastcall = (lookup_attribute ("fastcall",
   9853 				       TYPE_ATTRIBUTES (TREE_TYPE (cfun->decl)))
   9854 		     != NULL);
   9855       is_thiscall = (lookup_attribute ("thiscall",
   9856 				       TYPE_ATTRIBUTES (TREE_TYPE (cfun->decl)))
   9857 		     != NULL);
   9858       regparm = ix86_function_regparm (TREE_TYPE (cfun->decl), cfun->decl);
   9859 
   9860       if (is_fastcall)
   9861 	{
   9862 	  if (DECL_STATIC_CHAIN (cfun->decl))
   9863 	    {
   9864 	      sorry ("%<-fsplit-stack%> does not support fastcall with "
   9865 		     "nested function");
   9866 	      return INVALID_REGNUM;
   9867 	    }
   9868 	  return AX_REG;
   9869 	}
   9870       else if (is_thiscall)
   9871         {
   9872 	  if (!DECL_STATIC_CHAIN (cfun->decl))
   9873 	    return DX_REG;
   9874 	  return AX_REG;
   9875 	}
   9876       else if (regparm < 3)
   9877 	{
   9878 	  if (!DECL_STATIC_CHAIN (cfun->decl))
   9879 	    return CX_REG;
   9880 	  else
   9881 	    {
   9882 	      if (regparm >= 2)
   9883 		{
   9884 		  sorry ("%<-fsplit-stack%> does not support 2 register "
   9885 			 "parameters for a nested function");
   9886 		  return INVALID_REGNUM;
   9887 		}
   9888 	      return DX_REG;
   9889 	    }
   9890 	}
   9891       else
   9892 	{
   9893 	  /* FIXME: We could make this work by pushing a register
   9894 	     around the addition and comparison.  */
   9895 	  sorry ("%<-fsplit-stack%> does not support 3 register parameters");
   9896 	  return INVALID_REGNUM;
   9897 	}
   9898     }
   9899 }
   9900 
   9901 /* A SYMBOL_REF for the function which allocates new stackspace for
   9902    -fsplit-stack.  */
   9903 
   9904 static GTY(()) rtx split_stack_fn;
   9905 
   9906 /* A SYMBOL_REF for the more stack function when using the large
   9907    model.  */
   9908 
   9909 static GTY(()) rtx split_stack_fn_large;
   9910 
   9911 /* Return location of the stack guard value in the TLS block.  */
   9912 
   9913 rtx
   9914 ix86_split_stack_guard (void)
   9915 {
   9916   int offset;
   9917   addr_space_t as = DEFAULT_TLS_SEG_REG;
   9918   rtx r;
   9919 
   9920   gcc_assert (flag_split_stack);
   9921 
   9922 #ifdef TARGET_THREAD_SPLIT_STACK_OFFSET
   9923   offset = TARGET_THREAD_SPLIT_STACK_OFFSET;
   9924 #else
   9925   gcc_unreachable ();
   9926 #endif
   9927 
   9928   r = GEN_INT (offset);
   9929   r = gen_const_mem (Pmode, r);
   9930   set_mem_addr_space (r, as);
   9931 
   9932   return r;
   9933 }
   9934 
   9935 /* Handle -fsplit-stack.  These are the first instructions in the
   9936    function, even before the regular prologue.  */
   9937 
   9938 void
   9939 ix86_expand_split_stack_prologue (void)
   9940 {
   9941   HOST_WIDE_INT allocate;
   9942   unsigned HOST_WIDE_INT args_size;
   9943   rtx_code_label *label;
   9944   rtx limit, current, allocate_rtx, call_fusage;
   9945   rtx_insn *call_insn;
   9946   rtx scratch_reg = NULL_RTX;
   9947   rtx_code_label *varargs_label = NULL;
   9948   rtx fn;
   9949 
   9950   gcc_assert (flag_split_stack && reload_completed);
   9951 
   9952   ix86_finalize_stack_frame_flags ();
   9953   struct ix86_frame &frame = cfun->machine->frame;
   9954   allocate = frame.stack_pointer_offset - INCOMING_FRAME_SP_OFFSET;
   9955 
   9956   /* This is the label we will branch to if we have enough stack
   9957      space.  We expect the basic block reordering pass to reverse this
   9958      branch if optimizing, so that we branch in the unlikely case.  */
   9959   label = gen_label_rtx ();
   9960 
   9961   /* We need to compare the stack pointer minus the frame size with
   9962      the stack boundary in the TCB.  The stack boundary always gives
   9963      us SPLIT_STACK_AVAILABLE bytes, so if we need less than that we
   9964      can compare directly.  Otherwise we need to do an addition.  */
   9965 
   9966   limit = ix86_split_stack_guard ();
   9967 
   9968   if (allocate < SPLIT_STACK_AVAILABLE)
   9969     current = stack_pointer_rtx;
   9970   else
   9971     {
   9972       unsigned int scratch_regno;
   9973       rtx offset;
   9974 
   9975       /* We need a scratch register to hold the stack pointer minus
   9976 	 the required frame size.  Since this is the very start of the
   9977 	 function, the scratch register can be any caller-saved
   9978 	 register which is not used for parameters.  */
   9979       offset = GEN_INT (- allocate);
   9980       scratch_regno = split_stack_prologue_scratch_regno ();
   9981       if (scratch_regno == INVALID_REGNUM)
   9982 	return;
   9983       scratch_reg = gen_rtx_REG (Pmode, scratch_regno);
   9984       if (!TARGET_64BIT || x86_64_immediate_operand (offset, Pmode))
   9985 	{
   9986 	  /* We don't use gen_add in this case because it will
   9987 	     want to split to lea, but when not optimizing the insn
   9988 	     will not be split after this point.  */
   9989 	  emit_insn (gen_rtx_SET (scratch_reg,
   9990 				  gen_rtx_PLUS (Pmode, stack_pointer_rtx,
   9991 						offset)));
   9992 	}
   9993       else
   9994 	{
   9995 	  emit_move_insn (scratch_reg, offset);
   9996 	  emit_insn (gen_add2_insn (scratch_reg, stack_pointer_rtx));
   9997 	}
   9998       current = scratch_reg;
   9999     }
   10000 
   10001   ix86_expand_branch (GEU, current, limit, label);
   10002   rtx_insn *jump_insn = get_last_insn ();
   10003   JUMP_LABEL (jump_insn) = label;
   10004 
   10005   /* Mark the jump as very likely to be taken.  */
   10006   add_reg_br_prob_note (jump_insn, profile_probability::very_likely ());
   10007 
   10008   if (split_stack_fn == NULL_RTX)
   10009     {
   10010       split_stack_fn = gen_rtx_SYMBOL_REF (Pmode, "__morestack");
   10011       SYMBOL_REF_FLAGS (split_stack_fn) |= SYMBOL_FLAG_LOCAL;
   10012     }
   10013   fn = split_stack_fn;
   10014 
   10015   /* Get more stack space.  We pass in the desired stack space and the
   10016      size of the arguments to copy to the new stack.  In 32-bit mode
   10017      we push the parameters; __morestack will return on a new stack
   10018      anyhow.  In 64-bit mode we pass the parameters in r10 and
   10019      r11.  */
   10020   allocate_rtx = GEN_INT (allocate);
   10021   args_size = crtl->args.size >= 0 ? (HOST_WIDE_INT) crtl->args.size : 0;
   10022   call_fusage = NULL_RTX;
   10023   rtx pop = NULL_RTX;
   10024   if (TARGET_64BIT)
   10025     {
   10026       rtx reg10, reg11;
   10027 
   10028       reg10 = gen_rtx_REG (Pmode, R10_REG);
   10029       reg11 = gen_rtx_REG (Pmode, R11_REG);
   10030 
   10031       /* If this function uses a static chain, it will be in %r10.
   10032 	 Preserve it across the call to __morestack.  */
   10033       if (DECL_STATIC_CHAIN (cfun->decl))
   10034 	{
   10035 	  rtx rax;
   10036 
   10037 	  rax = gen_rtx_REG (word_mode, AX_REG);
   10038 	  emit_move_insn (rax, gen_rtx_REG (word_mode, R10_REG));
   10039 	  use_reg (&call_fusage, rax);
   10040 	}
   10041 
   10042       if ((ix86_cmodel == CM_LARGE || ix86_cmodel == CM_LARGE_PIC)
   10043           && !TARGET_PECOFF)
   10044 	{
   10045 	  HOST_WIDE_INT argval;
   10046 
   10047 	  gcc_assert (Pmode == DImode);
   10048 	  /* When using the large model we need to load the address
   10049 	     into a register, and we've run out of registers.  So we
   10050 	     switch to a different calling convention, and we call a
   10051 	     different function: __morestack_large.  We pass the
   10052 	     argument size in the upper 32 bits of r10 and pass the
   10053 	     frame size in the lower 32 bits.  */
   10054 	  gcc_assert ((allocate & HOST_WIDE_INT_C (0xffffffff)) == allocate);
   10055 	  gcc_assert ((args_size & 0xffffffff) == args_size);
   10056 
   10057 	  if (split_stack_fn_large == NULL_RTX)
   10058 	    {
   10059 	      split_stack_fn_large
   10060 		= gen_rtx_SYMBOL_REF (Pmode, "__morestack_large_model");
   10061 	      SYMBOL_REF_FLAGS (split_stack_fn_large) |= SYMBOL_FLAG_LOCAL;
   10062 	    }
   10063 	  if (ix86_cmodel == CM_LARGE_PIC)
   10064 	    {
   10065 	      rtx_code_label *label;
   10066 	      rtx x;
   10067 
   10068 	      label = gen_label_rtx ();
   10069 	      emit_label (label);
   10070 	      LABEL_PRESERVE_P (label) = 1;
   10071 	      emit_insn (gen_set_rip_rex64 (reg10, label));
   10072 	      emit_insn (gen_set_got_offset_rex64 (reg11, label));
   10073 	      emit_insn (gen_add2_insn (reg10, reg11));
   10074 	      x = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, split_stack_fn_large),
   10075 				  UNSPEC_GOT);
   10076 	      x = gen_rtx_CONST (Pmode, x);
   10077 	      emit_move_insn (reg11, x);
   10078 	      x = gen_rtx_PLUS (Pmode, reg10, reg11);
   10079 	      x = gen_const_mem (Pmode, x);
   10080 	      emit_move_insn (reg11, x);
   10081 	    }
   10082 	  else
   10083 	    emit_move_insn (reg11, split_stack_fn_large);
   10084 
   10085 	  fn = reg11;
   10086 
   10087 	  argval = ((args_size << 16) << 16) + allocate;
   10088 	  emit_move_insn (reg10, GEN_INT (argval));
   10089 	}
   10090       else
   10091 	{
   10092 	  emit_move_insn (reg10, allocate_rtx);
   10093 	  emit_move_insn (reg11, GEN_INT (args_size));
   10094 	  use_reg (&call_fusage, reg11);
   10095 	}
   10096 
   10097       use_reg (&call_fusage, reg10);
   10098     }
   10099   else
   10100     {
   10101       rtx_insn *insn = emit_insn (gen_push (GEN_INT (args_size)));
   10102       add_reg_note (insn, REG_ARGS_SIZE, GEN_INT (UNITS_PER_WORD));
   10103       insn = emit_insn (gen_push (allocate_rtx));
   10104       add_reg_note (insn, REG_ARGS_SIZE, GEN_INT (2 * UNITS_PER_WORD));
   10105       pop = GEN_INT (2 * UNITS_PER_WORD);
   10106     }
   10107   call_insn = ix86_expand_call (NULL_RTX, gen_rtx_MEM (QImode, fn),
   10108 				GEN_INT (UNITS_PER_WORD), constm1_rtx,
   10109 				pop, false);
   10110   add_function_usage_to (call_insn, call_fusage);
   10111   if (!TARGET_64BIT)
   10112     add_reg_note (call_insn, REG_ARGS_SIZE, GEN_INT (0));
   10113   /* Indicate that this function can't jump to non-local gotos.  */
   10114   make_reg_eh_region_note_nothrow_nononlocal (call_insn);
   10115 
   10116   /* In order to make call/return prediction work right, we now need
   10117      to execute a return instruction.  See
   10118      libgcc/config/i386/morestack.S for the details on how this works.
   10119 
   10120      For flow purposes gcc must not see this as a return
   10121      instruction--we need control flow to continue at the subsequent
   10122      label.  Therefore, we use an unspec.  */
   10123   gcc_assert (crtl->args.pops_args < 65536);
   10124   rtx_insn *ret_insn
   10125     = emit_insn (gen_split_stack_return (GEN_INT (crtl->args.pops_args)));
   10126 
   10127   if ((flag_cf_protection & CF_BRANCH))
   10128     {
   10129       /* Insert ENDBR since __morestack will jump back here via indirect
   10130 	 call.  */
   10131       rtx cet_eb = gen_nop_endbr ();
   10132       emit_insn_after (cet_eb, ret_insn);
   10133     }
   10134 
   10135   /* If we are in 64-bit mode and this function uses a static chain,
   10136      we saved %r10 in %rax before calling _morestack.  */
   10137   if (TARGET_64BIT && DECL_STATIC_CHAIN (cfun->decl))
   10138     emit_move_insn (gen_rtx_REG (word_mode, R10_REG),
   10139 		    gen_rtx_REG (word_mode, AX_REG));
   10140 
   10141   /* If this function calls va_start, we need to store a pointer to
   10142      the arguments on the old stack, because they may not have been
   10143      all copied to the new stack.  At this point the old stack can be
   10144      found at the frame pointer value used by __morestack, because
   10145      __morestack has set that up before calling back to us.  Here we
   10146      store that pointer in a scratch register, and in
   10147      ix86_expand_prologue we store the scratch register in a stack
   10148      slot.  */
   10149   if (cfun->machine->split_stack_varargs_pointer != NULL_RTX)
   10150     {
   10151       unsigned int scratch_regno;
   10152       rtx frame_reg;
   10153       int words;
   10154 
   10155       scratch_regno = split_stack_prologue_scratch_regno ();
   10156       scratch_reg = gen_rtx_REG (Pmode, scratch_regno);
   10157       frame_reg = gen_rtx_REG (Pmode, BP_REG);
   10158 
   10159       /* 64-bit:
   10160 	 fp -> old fp value
   10161 	       return address within this function
   10162 	       return address of caller of this function
   10163 	       stack arguments
   10164 	 So we add three words to get to the stack arguments.
   10165 
   10166 	 32-bit:
   10167 	 fp -> old fp value
   10168 	       return address within this function
   10169                first argument to __morestack
   10170                second argument to __morestack
   10171                return address of caller of this function
   10172                stack arguments
   10173          So we add five words to get to the stack arguments.
   10174       */
   10175       words = TARGET_64BIT ? 3 : 5;
   10176       emit_insn (gen_rtx_SET (scratch_reg,
   10177 			      plus_constant (Pmode, frame_reg,
   10178 					     words * UNITS_PER_WORD)));
   10179 
   10180       varargs_label = gen_label_rtx ();
   10181       emit_jump_insn (gen_jump (varargs_label));
   10182       JUMP_LABEL (get_last_insn ()) = varargs_label;
   10183 
   10184       emit_barrier ();
   10185     }
   10186 
   10187   emit_label (label);
   10188   LABEL_NUSES (label) = 1;
   10189 
   10190   /* If this function calls va_start, we now have to set the scratch
   10191      register for the case where we do not call __morestack.  In this
   10192      case we need to set it based on the stack pointer.  */
   10193   if (cfun->machine->split_stack_varargs_pointer != NULL_RTX)
   10194     {
   10195       emit_insn (gen_rtx_SET (scratch_reg,
   10196 			      plus_constant (Pmode, stack_pointer_rtx,
   10197 					     UNITS_PER_WORD)));
   10198 
   10199       emit_label (varargs_label);
   10200       LABEL_NUSES (varargs_label) = 1;
   10201     }
   10202 }
   10203 
   10204 /* We may have to tell the dataflow pass that the split stack prologue
   10205    is initializing a scratch register.  */
   10206 
   10207 static void
   10208 ix86_live_on_entry (bitmap regs)
   10209 {
   10210   if (cfun->machine->split_stack_varargs_pointer != NULL_RTX)
   10211     {
   10212       gcc_assert (flag_split_stack);
   10213       bitmap_set_bit (regs, split_stack_prologue_scratch_regno ());
   10214     }
   10215 }
   10216 
   10217 /* Extract the parts of an RTL expression that is a valid memory address
   10219    for an instruction.  Return false if the structure of the address is
   10220    grossly off.  */
   10221 
   10222 bool
   10223 ix86_decompose_address (rtx addr, struct ix86_address *out)
   10224 {
   10225   rtx base = NULL_RTX, index = NULL_RTX, disp = NULL_RTX;
   10226   rtx base_reg, index_reg;
   10227   HOST_WIDE_INT scale = 1;
   10228   rtx scale_rtx = NULL_RTX;
   10229   rtx tmp;
   10230   addr_space_t seg = ADDR_SPACE_GENERIC;
   10231 
   10232   /* Allow zero-extended SImode addresses,
   10233      they will be emitted with addr32 prefix.  */
   10234   if (TARGET_64BIT && GET_MODE (addr) == DImode)
   10235     {
   10236       if (GET_CODE (addr) == ZERO_EXTEND
   10237 	  && GET_MODE (XEXP (addr, 0)) == SImode)
   10238 	{
   10239 	  addr = XEXP (addr, 0);
   10240 	  if (CONST_INT_P (addr))
   10241 	    return false;
   10242 	}
   10243       else if (GET_CODE (addr) == AND
   10244 	       && const_32bit_mask (XEXP (addr, 1), DImode))
   10245 	{
   10246 	  addr = lowpart_subreg (SImode, XEXP (addr, 0), DImode);
   10247 	  if (addr == NULL_RTX)
   10248 	    return false;
   10249 
   10250 	  if (CONST_INT_P (addr))
   10251 	    return false;
   10252 	}
   10253       else if (GET_CODE (addr) == AND)
   10254 	{
   10255 	  /* For ASHIFT inside AND, combine will not generate
   10256 	     canonical zero-extend. Merge mask for AND and shift_count
   10257 	     to check if it is canonical zero-extend.  */
   10258 	  tmp = XEXP (addr, 0);
   10259 	  rtx mask = XEXP (addr, 1);
   10260 	  if (tmp && GET_CODE(tmp) == ASHIFT)
   10261 	    {
   10262 	      rtx shift_val = XEXP (tmp, 1);
   10263 	      if (CONST_INT_P (mask) && CONST_INT_P (shift_val)
   10264 		  && (((unsigned HOST_WIDE_INT) INTVAL(mask)
   10265 		      | ((HOST_WIDE_INT_1U << INTVAL(shift_val)) - 1))
   10266 		      == 0xffffffff))
   10267 		{
   10268 		  addr = lowpart_subreg (SImode, XEXP (addr, 0),
   10269 					 DImode);
   10270 		}
   10271 	    }
   10272 
   10273 	}
   10274     }
   10275 
   10276   /* Allow SImode subregs of DImode addresses,
   10277      they will be emitted with addr32 prefix.  */
   10278   if (TARGET_64BIT && GET_MODE (addr) == SImode)
   10279     {
   10280       if (SUBREG_P (addr)
   10281 	  && GET_MODE (SUBREG_REG (addr)) == DImode)
   10282 	{
   10283 	  addr = SUBREG_REG (addr);
   10284 	  if (CONST_INT_P (addr))
   10285 	    return false;
   10286 	}
   10287     }
   10288 
   10289   if (REG_P (addr))
   10290     base = addr;
   10291   else if (SUBREG_P (addr))
   10292     {
   10293       if (REG_P (SUBREG_REG (addr)))
   10294 	base = addr;
   10295       else
   10296 	return false;
   10297     }
   10298   else if (GET_CODE (addr) == PLUS)
   10299     {
   10300       rtx addends[4], op;
   10301       int n = 0, i;
   10302 
   10303       op = addr;
   10304       do
   10305 	{
   10306 	  if (n >= 4)
   10307 	    return false;
   10308 	  addends[n++] = XEXP (op, 1);
   10309 	  op = XEXP (op, 0);
   10310 	}
   10311       while (GET_CODE (op) == PLUS);
   10312       if (n >= 4)
   10313 	return false;
   10314       addends[n] = op;
   10315 
   10316       for (i = n; i >= 0; --i)
   10317 	{
   10318 	  op = addends[i];
   10319 	  switch (GET_CODE (op))
   10320 	    {
   10321 	    case MULT:
   10322 	      if (index)
   10323 		return false;
   10324 	      index = XEXP (op, 0);
   10325 	      scale_rtx = XEXP (op, 1);
   10326 	      break;
   10327 
   10328 	    case ASHIFT:
   10329 	      if (index)
   10330 		return false;
   10331 	      index = XEXP (op, 0);
   10332 	      tmp = XEXP (op, 1);
   10333 	      if (!CONST_INT_P (tmp))
   10334 		return false;
   10335 	      scale = INTVAL (tmp);
   10336 	      if ((unsigned HOST_WIDE_INT) scale > 3)
   10337 		return false;
   10338 	      scale = 1 << scale;
   10339 	      break;
   10340 
   10341 	    case ZERO_EXTEND:
   10342 	      op = XEXP (op, 0);
   10343 	      if (GET_CODE (op) != UNSPEC)
   10344 		return false;
   10345 	      /* FALLTHRU */
   10346 
   10347 	    case UNSPEC:
   10348 	      if (XINT (op, 1) == UNSPEC_TP
   10349 	          && TARGET_TLS_DIRECT_SEG_REFS
   10350 	          && seg == ADDR_SPACE_GENERIC)
   10351 		seg = DEFAULT_TLS_SEG_REG;
   10352 	      else
   10353 		return false;
   10354 	      break;
   10355 
   10356 	    case SUBREG:
   10357 	      if (!REG_P (SUBREG_REG (op)))
   10358 		return false;
   10359 	      /* FALLTHRU */
   10360 
   10361 	    case REG:
   10362 	      if (!base)
   10363 		base = op;
   10364 	      else if (!index)
   10365 		index = op;
   10366 	      else
   10367 		return false;
   10368 	      break;
   10369 
   10370 	    case CONST:
   10371 	    case CONST_INT:
   10372 	    case SYMBOL_REF:
   10373 	    case LABEL_REF:
   10374 	      if (disp)
   10375 		return false;
   10376 	      disp = op;
   10377 	      break;
   10378 
   10379 	    default:
   10380 	      return false;
   10381 	    }
   10382 	}
   10383     }
   10384   else if (GET_CODE (addr) == MULT)
   10385     {
   10386       index = XEXP (addr, 0);		/* index*scale */
   10387       scale_rtx = XEXP (addr, 1);
   10388     }
   10389   else if (GET_CODE (addr) == ASHIFT)
   10390     {
   10391       /* We're called for lea too, which implements ashift on occasion.  */
   10392       index = XEXP (addr, 0);
   10393       tmp = XEXP (addr, 1);
   10394       if (!CONST_INT_P (tmp))
   10395 	return false;
   10396       scale = INTVAL (tmp);
   10397       if ((unsigned HOST_WIDE_INT) scale > 3)
   10398 	return false;
   10399       scale = 1 << scale;
   10400     }
   10401   else
   10402     disp = addr;			/* displacement */
   10403 
   10404   if (index)
   10405     {
   10406       if (REG_P (index))
   10407 	;
   10408       else if (SUBREG_P (index)
   10409 	       && REG_P (SUBREG_REG (index)))
   10410 	;
   10411       else
   10412 	return false;
   10413     }
   10414 
   10415   /* Extract the integral value of scale.  */
   10416   if (scale_rtx)
   10417     {
   10418       if (!CONST_INT_P (scale_rtx))
   10419 	return false;
   10420       scale = INTVAL (scale_rtx);
   10421     }
   10422 
   10423   base_reg = base && SUBREG_P (base) ? SUBREG_REG (base) : base;
   10424   index_reg = index && SUBREG_P (index) ? SUBREG_REG (index) : index;
   10425 
   10426   /* Avoid useless 0 displacement.  */
   10427   if (disp == const0_rtx && (base || index))
   10428     disp = NULL_RTX;
   10429 
   10430   /* Allow arg pointer and stack pointer as index if there is not scaling.  */
   10431   if (base_reg && index_reg && scale == 1
   10432       && (REGNO (index_reg) == ARG_POINTER_REGNUM
   10433 	  || REGNO (index_reg) == FRAME_POINTER_REGNUM
   10434 	  || REGNO (index_reg) == SP_REG))
   10435     {
   10436       std::swap (base, index);
   10437       std::swap (base_reg, index_reg);
   10438     }
   10439 
   10440   /* Special case: %ebp cannot be encoded as a base without a displacement.
   10441      Similarly %r13.  */
   10442   if (!disp && base_reg
   10443       && (REGNO (base_reg) == ARG_POINTER_REGNUM
   10444 	  || REGNO (base_reg) == FRAME_POINTER_REGNUM
   10445 	  || REGNO (base_reg) == BP_REG
   10446 	  || REGNO (base_reg) == R13_REG))
   10447     disp = const0_rtx;
   10448 
   10449   /* Special case: on K6, [%esi] makes the instruction vector decoded.
   10450      Avoid this by transforming to [%esi+0].
   10451      Reload calls address legitimization without cfun defined, so we need
   10452      to test cfun for being non-NULL. */
   10453   if (TARGET_CPU_P (K6) && cfun && optimize_function_for_speed_p (cfun)
   10454       && base_reg && !index_reg && !disp
   10455       && REGNO (base_reg) == SI_REG)
   10456     disp = const0_rtx;
   10457 
   10458   /* Special case: encode reg+reg instead of reg*2.  */
   10459   if (!base && index && scale == 2)
   10460     base = index, base_reg = index_reg, scale = 1;
   10461 
   10462   /* Special case: scaling cannot be encoded without base or displacement.  */
   10463   if (!base && !disp && index && scale != 1)
   10464     disp = const0_rtx;
   10465 
   10466   out->base = base;
   10467   out->index = index;
   10468   out->disp = disp;
   10469   out->scale = scale;
   10470   out->seg = seg;
   10471 
   10472   return true;
   10473 }
   10474 
   10475 /* Return cost of the memory address x.
   10477    For i386, it is better to use a complex address than let gcc copy
   10478    the address into a reg and make a new pseudo.  But not if the address
   10479    requires to two regs - that would mean more pseudos with longer
   10480    lifetimes.  */
   10481 static int
   10482 ix86_address_cost (rtx x, machine_mode, addr_space_t, bool)
   10483 {
   10484   struct ix86_address parts;
   10485   int cost = 1;
   10486   int ok = ix86_decompose_address (x, &parts);
   10487 
   10488   gcc_assert (ok);
   10489 
   10490   if (parts.base && SUBREG_P (parts.base))
   10491     parts.base = SUBREG_REG (parts.base);
   10492   if (parts.index && SUBREG_P (parts.index))
   10493     parts.index = SUBREG_REG (parts.index);
   10494 
   10495   /* Attempt to minimize number of registers in the address by increasing
   10496      address cost for each used register.  We don't increase address cost
   10497      for "pic_offset_table_rtx".  When a memopt with "pic_offset_table_rtx"
   10498      is not invariant itself it most likely means that base or index is not
   10499      invariant.  Therefore only "pic_offset_table_rtx" could be hoisted out,
   10500      which is not profitable for x86.  */
   10501   if (parts.base
   10502       && (!REG_P (parts.base) || REGNO (parts.base) >= FIRST_PSEUDO_REGISTER)
   10503       && (current_pass->type == GIMPLE_PASS
   10504 	  || !pic_offset_table_rtx
   10505 	  || !REG_P (parts.base)
   10506 	  || REGNO (pic_offset_table_rtx) != REGNO (parts.base)))
   10507     cost++;
   10508 
   10509   if (parts.index
   10510       && (!REG_P (parts.index) || REGNO (parts.index) >= FIRST_PSEUDO_REGISTER)
   10511       && (current_pass->type == GIMPLE_PASS
   10512 	  || !pic_offset_table_rtx
   10513 	  || !REG_P (parts.index)
   10514 	  || REGNO (pic_offset_table_rtx) != REGNO (parts.index)))
   10515     cost++;
   10516 
   10517   /* AMD-K6 don't like addresses with ModR/M set to 00_xxx_100b,
   10518      since it's predecode logic can't detect the length of instructions
   10519      and it degenerates to vector decoded.  Increase cost of such
   10520      addresses here.  The penalty is minimally 2 cycles.  It may be worthwhile
   10521      to split such addresses or even refuse such addresses at all.
   10522 
   10523      Following addressing modes are affected:
   10524       [base+scale*index]
   10525       [scale*index+disp]
   10526       [base+index]
   10527 
   10528      The first and last case  may be avoidable by explicitly coding the zero in
   10529      memory address, but I don't have AMD-K6 machine handy to check this
   10530      theory.  */
   10531 
   10532   if (TARGET_CPU_P (K6)
   10533       && ((!parts.disp && parts.base && parts.index && parts.scale != 1)
   10534 	  || (parts.disp && !parts.base && parts.index && parts.scale != 1)
   10535 	  || (!parts.disp && parts.base && parts.index && parts.scale == 1)))
   10536     cost += 10;
   10537 
   10538   return cost;
   10539 }
   10540 
   10541 /* Allow {LABEL | SYMBOL}_REF - SYMBOL_REF-FOR-PICBASE for Mach-O as
   10543    this is used for to form addresses to local data when -fPIC is in
   10544    use.  */
   10545 
   10546 static bool
   10547 darwin_local_data_pic (rtx disp)
   10548 {
   10549   return (GET_CODE (disp) == UNSPEC
   10550 	  && XINT (disp, 1) == UNSPEC_MACHOPIC_OFFSET);
   10551 }
   10552 
   10553 /* True if the function symbol operand X should be loaded from GOT.
   10554    If CALL_P is true, X is a call operand.
   10555 
   10556    NB: -mno-direct-extern-access doesn't force load from GOT for
   10557    call.
   10558 
   10559    NB: In 32-bit mode, only non-PIC is allowed in inline assembly
   10560    statements, since a PIC register could not be available at the
   10561    call site.  */
   10562 
   10563 bool
   10564 ix86_force_load_from_GOT_p (rtx x, bool call_p)
   10565 {
   10566   return ((TARGET_64BIT || (!flag_pic && HAVE_AS_IX86_GOT32X))
   10567 	  && !TARGET_PECOFF && !TARGET_MACHO
   10568 	  && (!flag_pic || this_is_asm_operands)
   10569 	  && ix86_cmodel != CM_LARGE
   10570 	  && ix86_cmodel != CM_LARGE_PIC
   10571 	  && GET_CODE (x) == SYMBOL_REF
   10572 	  && ((!call_p
   10573 	       && (!ix86_direct_extern_access
   10574 		   || (SYMBOL_REF_DECL (x)
   10575 		       && lookup_attribute ("nodirect_extern_access",
   10576 					    DECL_ATTRIBUTES (SYMBOL_REF_DECL (x))))))
   10577 	      || (SYMBOL_REF_FUNCTION_P (x)
   10578 		  && (!flag_plt
   10579 		      || (SYMBOL_REF_DECL (x)
   10580 			  && lookup_attribute ("noplt",
   10581 					       DECL_ATTRIBUTES (SYMBOL_REF_DECL (x)))))))
   10582 	  && !SYMBOL_REF_LOCAL_P (x));
   10583 }
   10584 
   10585 /* Determine if a given RTX is a valid constant.  We already know this
   10586    satisfies CONSTANT_P.  */
   10587 
   10588 static bool
   10589 ix86_legitimate_constant_p (machine_mode mode, rtx x)
   10590 {
   10591   switch (GET_CODE (x))
   10592     {
   10593     case CONST:
   10594       x = XEXP (x, 0);
   10595 
   10596       if (GET_CODE (x) == PLUS)
   10597 	{
   10598 	  if (!CONST_INT_P (XEXP (x, 1)))
   10599 	    return false;
   10600 	  x = XEXP (x, 0);
   10601 	}
   10602 
   10603       if (TARGET_MACHO && darwin_local_data_pic (x))
   10604 	return true;
   10605 
   10606       /* Only some unspecs are valid as "constants".  */
   10607       if (GET_CODE (x) == UNSPEC)
   10608 	switch (XINT (x, 1))
   10609 	  {
   10610 	  case UNSPEC_GOT:
   10611 	  case UNSPEC_GOTOFF:
   10612 	  case UNSPEC_PLTOFF:
   10613 	    return TARGET_64BIT;
   10614 	  case UNSPEC_TPOFF:
   10615 	  case UNSPEC_NTPOFF:
   10616 	    x = XVECEXP (x, 0, 0);
   10617 	    return (GET_CODE (x) == SYMBOL_REF
   10618 		    && SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_EXEC);
   10619 	  case UNSPEC_DTPOFF:
   10620 	    x = XVECEXP (x, 0, 0);
   10621 	    return (GET_CODE (x) == SYMBOL_REF
   10622 		    && SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_DYNAMIC);
   10623 	  default:
   10624 	    return false;
   10625 	  }
   10626 
   10627       /* We must have drilled down to a symbol.  */
   10628       if (GET_CODE (x) == LABEL_REF)
   10629 	return true;
   10630       if (GET_CODE (x) != SYMBOL_REF)
   10631 	return false;
   10632       /* FALLTHRU */
   10633 
   10634     case SYMBOL_REF:
   10635       /* TLS symbols are never valid.  */
   10636       if (SYMBOL_REF_TLS_MODEL (x))
   10637 	return false;
   10638 
   10639       /* DLLIMPORT symbols are never valid.  */
   10640       if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
   10641 	  && SYMBOL_REF_DLLIMPORT_P (x))
   10642 	return false;
   10643 
   10644 #if TARGET_MACHO
   10645       /* mdynamic-no-pic */
   10646       if (MACHO_DYNAMIC_NO_PIC_P)
   10647 	return machopic_symbol_defined_p (x);
   10648 #endif
   10649 
   10650       /* External function address should be loaded
   10651 	 via the GOT slot to avoid PLT.  */
   10652       if (ix86_force_load_from_GOT_p (x))
   10653 	return false;
   10654 
   10655       break;
   10656 
   10657     CASE_CONST_SCALAR_INT:
   10658       if (ix86_endbr_immediate_operand (x, VOIDmode))
   10659 	return false;
   10660 
   10661       switch (mode)
   10662 	{
   10663 	case E_TImode:
   10664 	  if (TARGET_64BIT)
   10665 	    return true;
   10666 	  /* FALLTHRU */
   10667 	case E_OImode:
   10668 	case E_XImode:
   10669 	  if (!standard_sse_constant_p (x, mode)
   10670 	      && GET_MODE_SIZE (TARGET_AVX512F
   10671 				? XImode
   10672 				: (TARGET_AVX
   10673 				   ? OImode
   10674 				   : (TARGET_SSE2
   10675 				      ? TImode : DImode))) < GET_MODE_SIZE (mode))
   10676 	    return false;
   10677 	default:
   10678 	  break;
   10679 	}
   10680       break;
   10681 
   10682     case CONST_VECTOR:
   10683       if (!standard_sse_constant_p (x, mode))
   10684 	return false;
   10685 
   10686     default:
   10687       break;
   10688     }
   10689 
   10690   /* Otherwise we handle everything else in the move patterns.  */
   10691   return true;
   10692 }
   10693 
   10694 /* Determine if it's legal to put X into the constant pool.  This
   10695    is not possible for the address of thread-local symbols, which
   10696    is checked above.  */
   10697 
   10698 static bool
   10699 ix86_cannot_force_const_mem (machine_mode mode, rtx x)
   10700 {
   10701   /* We can put any immediate constant in memory.  */
   10702   switch (GET_CODE (x))
   10703     {
   10704     CASE_CONST_ANY:
   10705       return false;
   10706 
   10707     default:
   10708       break;
   10709     }
   10710 
   10711   return !ix86_legitimate_constant_p (mode, x);
   10712 }
   10713 
   10714 /*  Nonzero if the symbol is marked as dllimport, or as stub-variable,
   10715     otherwise zero.  */
   10716 
   10717 static bool
   10718 is_imported_p (rtx x)
   10719 {
   10720   if (!TARGET_DLLIMPORT_DECL_ATTRIBUTES
   10721       || GET_CODE (x) != SYMBOL_REF)
   10722     return false;
   10723 
   10724   return SYMBOL_REF_DLLIMPORT_P (x) || SYMBOL_REF_STUBVAR_P (x);
   10725 }
   10726 
   10727 
   10728 /* Nonzero if the constant value X is a legitimate general operand
   10729    when generating PIC code.  It is given that flag_pic is on and
   10730    that X satisfies CONSTANT_P.  */
   10731 
   10732 bool
   10733 legitimate_pic_operand_p (rtx x)
   10734 {
   10735   rtx inner;
   10736 
   10737   switch (GET_CODE (x))
   10738     {
   10739     case CONST:
   10740       inner = XEXP (x, 0);
   10741       if (GET_CODE (inner) == PLUS
   10742 	  && CONST_INT_P (XEXP (inner, 1)))
   10743 	inner = XEXP (inner, 0);
   10744 
   10745       /* Only some unspecs are valid as "constants".  */
   10746       if (GET_CODE (inner) == UNSPEC)
   10747 	switch (XINT (inner, 1))
   10748 	  {
   10749 	  case UNSPEC_GOT:
   10750 	  case UNSPEC_GOTOFF:
   10751 	  case UNSPEC_PLTOFF:
   10752 	    return TARGET_64BIT;
   10753 	  case UNSPEC_TPOFF:
   10754 	    x = XVECEXP (inner, 0, 0);
   10755 	    return (GET_CODE (x) == SYMBOL_REF
   10756 		    && SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_EXEC);
   10757 	  case UNSPEC_MACHOPIC_OFFSET:
   10758 	    return legitimate_pic_address_disp_p (x);
   10759 	  default:
   10760 	    return false;
   10761 	  }
   10762       /* FALLTHRU */
   10763 
   10764     case SYMBOL_REF:
   10765     case LABEL_REF:
   10766       return legitimate_pic_address_disp_p (x);
   10767 
   10768     default:
   10769       return true;
   10770     }
   10771 }
   10772 
   10773 /* Determine if a given CONST RTX is a valid memory displacement
   10774    in PIC mode.  */
   10775 
   10776 bool
   10777 legitimate_pic_address_disp_p (rtx disp)
   10778 {
   10779   bool saw_plus;
   10780 
   10781   /* In 64bit mode we can allow direct addresses of symbols and labels
   10782      when they are not dynamic symbols.  */
   10783   if (TARGET_64BIT)
   10784     {
   10785       rtx op0 = disp, op1;
   10786 
   10787       switch (GET_CODE (disp))
   10788 	{
   10789 	case LABEL_REF:
   10790 	  return true;
   10791 
   10792 	case CONST:
   10793 	  if (GET_CODE (XEXP (disp, 0)) != PLUS)
   10794 	    break;
   10795 	  op0 = XEXP (XEXP (disp, 0), 0);
   10796 	  op1 = XEXP (XEXP (disp, 0), 1);
   10797 	  if (!CONST_INT_P (op1))
   10798 	    break;
   10799 	  if (GET_CODE (op0) == UNSPEC
   10800 	      && (XINT (op0, 1) == UNSPEC_DTPOFF
   10801 		  || XINT (op0, 1) == UNSPEC_NTPOFF)
   10802 	      && trunc_int_for_mode (INTVAL (op1), SImode) == INTVAL (op1))
   10803 	    return true;
   10804 	  if (INTVAL (op1) >= 16*1024*1024
   10805 	      || INTVAL (op1) < -16*1024*1024)
   10806 	    break;
   10807 	  if (GET_CODE (op0) == LABEL_REF)
   10808 	    return true;
   10809 	  if (GET_CODE (op0) == CONST
   10810 	      && GET_CODE (XEXP (op0, 0)) == UNSPEC
   10811 	      && XINT (XEXP (op0, 0), 1) == UNSPEC_PCREL)
   10812 	    return true;
   10813 	  if (GET_CODE (op0) == UNSPEC
   10814 	      && XINT (op0, 1) == UNSPEC_PCREL)
   10815 	    return true;
   10816 	  if (GET_CODE (op0) != SYMBOL_REF)
   10817 	    break;
   10818 	  /* FALLTHRU */
   10819 
   10820 	case SYMBOL_REF:
   10821 	  /* TLS references should always be enclosed in UNSPEC.
   10822 	     The dllimported symbol needs always to be resolved.  */
   10823 	  if (SYMBOL_REF_TLS_MODEL (op0)
   10824 	      || (TARGET_DLLIMPORT_DECL_ATTRIBUTES && SYMBOL_REF_DLLIMPORT_P (op0)))
   10825 	    return false;
   10826 
   10827 	  if (TARGET_PECOFF)
   10828 	    {
   10829 	      if (is_imported_p (op0))
   10830 		return true;
   10831 
   10832 	      if (SYMBOL_REF_FAR_ADDR_P (op0) || !SYMBOL_REF_LOCAL_P (op0))
   10833 		break;
   10834 
   10835 	      /* Non-external-weak function symbols need to be resolved only
   10836 		 for the large model.  Non-external symbols don't need to be
   10837 		 resolved for large and medium models.  For the small model,
   10838 		 we don't need to resolve anything here.  */
   10839 	      if ((ix86_cmodel != CM_LARGE_PIC
   10840 		   && SYMBOL_REF_FUNCTION_P (op0)
   10841 		   && !(SYMBOL_REF_EXTERNAL_P (op0) && SYMBOL_REF_WEAK (op0)))
   10842 		  || !SYMBOL_REF_EXTERNAL_P (op0)
   10843 		  || ix86_cmodel == CM_SMALL_PIC)
   10844 		return true;
   10845 	    }
   10846 	  else if (!SYMBOL_REF_FAR_ADDR_P (op0)
   10847 		   && (SYMBOL_REF_LOCAL_P (op0)
   10848 		       || ((ix86_direct_extern_access
   10849 			    && !(SYMBOL_REF_DECL (op0)
   10850 				 && lookup_attribute ("nodirect_extern_access",
   10851 						      DECL_ATTRIBUTES (SYMBOL_REF_DECL (op0)))))
   10852 			   && HAVE_LD_PIE_COPYRELOC
   10853 			   && flag_pie
   10854 			   && !SYMBOL_REF_WEAK (op0)
   10855 			   && !SYMBOL_REF_FUNCTION_P (op0)))
   10856 		   && ix86_cmodel != CM_LARGE_PIC)
   10857 	    return true;
   10858 	  break;
   10859 
   10860 	default:
   10861 	  break;
   10862 	}
   10863     }
   10864   if (GET_CODE (disp) != CONST)
   10865     return false;
   10866   disp = XEXP (disp, 0);
   10867 
   10868   if (TARGET_64BIT)
   10869     {
   10870       /* We are unsafe to allow PLUS expressions.  This limit allowed distance
   10871          of GOT tables.  We should not need these anyway.  */
   10872       if (GET_CODE (disp) != UNSPEC
   10873 	  || (XINT (disp, 1) != UNSPEC_GOTPCREL
   10874 	      && XINT (disp, 1) != UNSPEC_GOTOFF
   10875 	      && XINT (disp, 1) != UNSPEC_PCREL
   10876 	      && XINT (disp, 1) != UNSPEC_PLTOFF))
   10877 	return false;
   10878 
   10879       if (GET_CODE (XVECEXP (disp, 0, 0)) != SYMBOL_REF
   10880 	  && GET_CODE (XVECEXP (disp, 0, 0)) != LABEL_REF)
   10881 	return false;
   10882       return true;
   10883     }
   10884 
   10885   saw_plus = false;
   10886   if (GET_CODE (disp) == PLUS)
   10887     {
   10888       if (!CONST_INT_P (XEXP (disp, 1)))
   10889 	return false;
   10890       disp = XEXP (disp, 0);
   10891       saw_plus = true;
   10892     }
   10893 
   10894   if (TARGET_MACHO && darwin_local_data_pic (disp))
   10895     return true;
   10896 
   10897   if (GET_CODE (disp) != UNSPEC)
   10898     return false;
   10899 
   10900   switch (XINT (disp, 1))
   10901     {
   10902     case UNSPEC_GOT:
   10903       if (saw_plus)
   10904 	return false;
   10905       /* We need to check for both symbols and labels because VxWorks loads
   10906 	 text labels with @GOT rather than @GOTOFF.  See gotoff_operand for
   10907 	 details.  */
   10908       return (GET_CODE (XVECEXP (disp, 0, 0)) == SYMBOL_REF
   10909 	      || GET_CODE (XVECEXP (disp, 0, 0)) == LABEL_REF);
   10910     case UNSPEC_GOTOFF:
   10911       /* Refuse GOTOFF in 64bit mode since it is always 64bit when used.
   10912 	 While ABI specify also 32bit relocation but we don't produce it in
   10913 	 small PIC model at all.  */
   10914       if ((GET_CODE (XVECEXP (disp, 0, 0)) == SYMBOL_REF
   10915 	   || GET_CODE (XVECEXP (disp, 0, 0)) == LABEL_REF)
   10916 	  && !TARGET_64BIT)
   10917         return !TARGET_PECOFF && gotoff_operand (XVECEXP (disp, 0, 0), Pmode);
   10918       return false;
   10919     case UNSPEC_GOTTPOFF:
   10920     case UNSPEC_GOTNTPOFF:
   10921     case UNSPEC_INDNTPOFF:
   10922       if (saw_plus)
   10923 	return false;
   10924       disp = XVECEXP (disp, 0, 0);
   10925       return (GET_CODE (disp) == SYMBOL_REF
   10926 	      && SYMBOL_REF_TLS_MODEL (disp) == TLS_MODEL_INITIAL_EXEC);
   10927     case UNSPEC_NTPOFF:
   10928       disp = XVECEXP (disp, 0, 0);
   10929       return (GET_CODE (disp) == SYMBOL_REF
   10930 	      && SYMBOL_REF_TLS_MODEL (disp) == TLS_MODEL_LOCAL_EXEC);
   10931     case UNSPEC_DTPOFF:
   10932       disp = XVECEXP (disp, 0, 0);
   10933       return (GET_CODE (disp) == SYMBOL_REF
   10934 	      && SYMBOL_REF_TLS_MODEL (disp) == TLS_MODEL_LOCAL_DYNAMIC);
   10935     }
   10936 
   10937   return false;
   10938 }
   10939 
   10940 /* Determine if op is suitable RTX for an address register.
   10941    Return naked register if a register or a register subreg is
   10942    found, otherwise return NULL_RTX.  */
   10943 
   10944 static rtx
   10945 ix86_validate_address_register (rtx op)
   10946 {
   10947   machine_mode mode = GET_MODE (op);
   10948 
   10949   /* Only SImode or DImode registers can form the address.  */
   10950   if (mode != SImode && mode != DImode)
   10951     return NULL_RTX;
   10952 
   10953   if (REG_P (op))
   10954     return op;
   10955   else if (SUBREG_P (op))
   10956     {
   10957       rtx reg = SUBREG_REG (op);
   10958 
   10959       if (!REG_P (reg))
   10960 	return NULL_RTX;
   10961 
   10962       mode = GET_MODE (reg);
   10963 
   10964       /* Don't allow SUBREGs that span more than a word.  It can
   10965 	 lead to spill failures when the register is one word out
   10966 	 of a two word structure.  */
   10967       if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
   10968 	return NULL_RTX;
   10969 
   10970       /* Allow only SUBREGs of non-eliminable hard registers.  */
   10971       if (register_no_elim_operand (reg, mode))
   10972 	return reg;
   10973     }
   10974 
   10975   /* Op is not a register.  */
   10976   return NULL_RTX;
   10977 }
   10978 
   10979 /* Recognizes RTL expressions that are valid memory addresses for an
   10980    instruction.  The MODE argument is the machine mode for the MEM
   10981    expression that wants to use this address.
   10982 
   10983    It only recognizes address in canonical form.  LEGITIMIZE_ADDRESS should
   10984    convert common non-canonical forms to canonical form so that they will
   10985    be recognized.  */
   10986 
   10987 static bool
   10988 ix86_legitimate_address_p (machine_mode, rtx addr, bool strict)
   10989 {
   10990   struct ix86_address parts;
   10991   rtx base, index, disp;
   10992   HOST_WIDE_INT scale;
   10993   addr_space_t seg;
   10994 
   10995   if (ix86_decompose_address (addr, &parts) == 0)
   10996     /* Decomposition failed.  */
   10997     return false;
   10998 
   10999   base = parts.base;
   11000   index = parts.index;
   11001   disp = parts.disp;
   11002   scale = parts.scale;
   11003   seg = parts.seg;
   11004 
   11005   /* Validate base register.  */
   11006   if (base)
   11007     {
   11008       rtx reg = ix86_validate_address_register (base);
   11009 
   11010       if (reg == NULL_RTX)
   11011 	return false;
   11012 
   11013       if ((strict && ! REG_OK_FOR_BASE_STRICT_P (reg))
   11014 	  || (! strict && ! REG_OK_FOR_BASE_NONSTRICT_P (reg)))
   11015 	/* Base is not valid.  */
   11016 	return false;
   11017     }
   11018 
   11019   /* Validate index register.  */
   11020   if (index)
   11021     {
   11022       rtx reg = ix86_validate_address_register (index);
   11023 
   11024       if (reg == NULL_RTX)
   11025 	return false;
   11026 
   11027       if ((strict && ! REG_OK_FOR_INDEX_STRICT_P (reg))
   11028 	  || (! strict && ! REG_OK_FOR_INDEX_NONSTRICT_P (reg)))
   11029 	/* Index is not valid.  */
   11030 	return false;
   11031     }
   11032 
   11033   /* Index and base should have the same mode.  */
   11034   if (base && index
   11035       && GET_MODE (base) != GET_MODE (index))
   11036     return false;
   11037 
   11038   /* Address override works only on the (%reg) part of %fs:(%reg).  */
   11039   if (seg != ADDR_SPACE_GENERIC
   11040       && ((base && GET_MODE (base) != word_mode)
   11041 	  || (index && GET_MODE (index) != word_mode)))
   11042     return false;
   11043 
   11044   /* Validate scale factor.  */
   11045   if (scale != 1)
   11046     {
   11047       if (!index)
   11048 	/* Scale without index.  */
   11049 	return false;
   11050 
   11051       if (scale != 2 && scale != 4 && scale != 8)
   11052 	/* Scale is not a valid multiplier.  */
   11053 	return false;
   11054     }
   11055 
   11056   /* Validate displacement.  */
   11057   if (disp)
   11058     {
   11059       if (ix86_endbr_immediate_operand (disp, VOIDmode))
   11060 	return false;
   11061 
   11062       if (GET_CODE (disp) == CONST
   11063 	  && GET_CODE (XEXP (disp, 0)) == UNSPEC
   11064 	  && XINT (XEXP (disp, 0), 1) != UNSPEC_MACHOPIC_OFFSET)
   11065 	switch (XINT (XEXP (disp, 0), 1))
   11066 	  {
   11067 	  /* Refuse GOTOFF and GOT in 64bit mode since it is always 64bit
   11068 	     when used.  While ABI specify also 32bit relocations, we
   11069 	     don't produce them at all and use IP relative instead.
   11070 	     Allow GOT in 32bit mode for both PIC and non-PIC if symbol
   11071 	     should be loaded via GOT.  */
   11072 	  case UNSPEC_GOT:
   11073 	    if (!TARGET_64BIT
   11074 		&& ix86_force_load_from_GOT_p (XVECEXP (XEXP (disp, 0), 0, 0)))
   11075 	      goto is_legitimate_pic;
   11076 	    /* FALLTHRU */
   11077 	  case UNSPEC_GOTOFF:
   11078 	    gcc_assert (flag_pic);
   11079 	    if (!TARGET_64BIT)
   11080 	      goto is_legitimate_pic;
   11081 
   11082 	    /* 64bit address unspec.  */
   11083 	    return false;
   11084 
   11085 	  case UNSPEC_GOTPCREL:
   11086 	    if (ix86_force_load_from_GOT_p (XVECEXP (XEXP (disp, 0), 0, 0)))
   11087 	      goto is_legitimate_pic;
   11088 	    /* FALLTHRU */
   11089 	  case UNSPEC_PCREL:
   11090 	    gcc_assert (flag_pic);
   11091 	    goto is_legitimate_pic;
   11092 
   11093 	  case UNSPEC_GOTTPOFF:
   11094 	  case UNSPEC_GOTNTPOFF:
   11095 	  case UNSPEC_INDNTPOFF:
   11096 	  case UNSPEC_NTPOFF:
   11097 	  case UNSPEC_DTPOFF:
   11098 	    break;
   11099 
   11100 	  default:
   11101 	    /* Invalid address unspec.  */
   11102 	    return false;
   11103 	  }
   11104 
   11105       else if (SYMBOLIC_CONST (disp)
   11106 	       && (flag_pic
   11107 #if TARGET_MACHO
   11108 		   || (MACHOPIC_INDIRECT
   11109 		       && !machopic_operand_p (disp))
   11110 #endif
   11111 		  ))
   11112 	{
   11113 
   11114 	is_legitimate_pic:
   11115 	  if (TARGET_64BIT && (index || base))
   11116 	    {
   11117 	      /* foo@dtpoff(%rX) is ok.  */
   11118 	      if (GET_CODE (disp) != CONST
   11119 		  || GET_CODE (XEXP (disp, 0)) != PLUS
   11120 		  || GET_CODE (XEXP (XEXP (disp, 0), 0)) != UNSPEC
   11121 		  || !CONST_INT_P (XEXP (XEXP (disp, 0), 1))
   11122 		  || (XINT (XEXP (XEXP (disp, 0), 0), 1) != UNSPEC_DTPOFF
   11123 		      && XINT (XEXP (XEXP (disp, 0), 0), 1) != UNSPEC_NTPOFF))
   11124 		/* Non-constant pic memory reference.  */
   11125 		return false;
   11126 	    }
   11127 	  else if ((!TARGET_MACHO || flag_pic)
   11128 		    && ! legitimate_pic_address_disp_p (disp))
   11129 	    /* Displacement is an invalid pic construct.  */
   11130 	    return false;
   11131 #if TARGET_MACHO
   11132 	  else if (MACHO_DYNAMIC_NO_PIC_P
   11133 		   && !ix86_legitimate_constant_p (Pmode, disp))
   11134 	    /* displacment must be referenced via non_lazy_pointer */
   11135 	    return false;
   11136 #endif
   11137 
   11138           /* This code used to verify that a symbolic pic displacement
   11139 	     includes the pic_offset_table_rtx register.
   11140 
   11141 	     While this is good idea, unfortunately these constructs may
   11142 	     be created by "adds using lea" optimization for incorrect
   11143 	     code like:
   11144 
   11145 	     int a;
   11146 	     int foo(int i)
   11147 	       {
   11148 	         return *(&a+i);
   11149 	       }
   11150 
   11151 	     This code is nonsensical, but results in addressing
   11152 	     GOT table with pic_offset_table_rtx base.  We can't
   11153 	     just refuse it easily, since it gets matched by
   11154 	     "addsi3" pattern, that later gets split to lea in the
   11155 	     case output register differs from input.  While this
   11156 	     can be handled by separate addsi pattern for this case
   11157 	     that never results in lea, this seems to be easier and
   11158 	     correct fix for crash to disable this test.  */
   11159 	}
   11160       else if (GET_CODE (disp) != LABEL_REF
   11161 	       && !CONST_INT_P (disp)
   11162 	       && (GET_CODE (disp) != CONST
   11163 		   || !ix86_legitimate_constant_p (Pmode, disp))
   11164 	       && (GET_CODE (disp) != SYMBOL_REF
   11165 		   || !ix86_legitimate_constant_p (Pmode, disp)))
   11166 	/* Displacement is not constant.  */
   11167 	return false;
   11168       else if (TARGET_64BIT
   11169 	       && !x86_64_immediate_operand (disp, VOIDmode))
   11170 	/* Displacement is out of range.  */
   11171 	return false;
   11172       /* In x32 mode, constant addresses are sign extended to 64bit, so
   11173 	 we have to prevent addresses from 0x80000000 to 0xffffffff.  */
   11174       else if (TARGET_X32 && !(index || base)
   11175 	       && CONST_INT_P (disp)
   11176 	       && val_signbit_known_set_p (SImode, INTVAL (disp)))
   11177 	return false;
   11178     }
   11179 
   11180   /* Everything looks valid.  */
   11181   return true;
   11182 }
   11183 
   11184 /* Determine if a given RTX is a valid constant address.  */
   11185 
   11186 bool
   11187 constant_address_p (rtx x)
   11188 {
   11189   return CONSTANT_P (x) && ix86_legitimate_address_p (Pmode, x, 1);
   11190 }
   11191 
   11192 /* Return a unique alias set for the GOT.  */
   11194 
   11195 alias_set_type
   11196 ix86_GOT_alias_set (void)
   11197 {
   11198   static alias_set_type set = -1;
   11199   if (set == -1)
   11200     set = new_alias_set ();
   11201   return set;
   11202 }
   11203 
   11204 /* Return a legitimate reference for ORIG (an address) using the
   11205    register REG.  If REG is 0, a new pseudo is generated.
   11206 
   11207    There are two types of references that must be handled:
   11208 
   11209    1. Global data references must load the address from the GOT, via
   11210       the PIC reg.  An insn is emitted to do this load, and the reg is
   11211       returned.
   11212 
   11213    2. Static data references, constant pool addresses, and code labels
   11214       compute the address as an offset from the GOT, whose base is in
   11215       the PIC reg.  Static data objects have SYMBOL_FLAG_LOCAL set to
   11216       differentiate them from global data objects.  The returned
   11217       address is the PIC reg + an unspec constant.
   11218 
   11219    TARGET_LEGITIMATE_ADDRESS_P rejects symbolic references unless the PIC
   11220    reg also appears in the address.  */
   11221 
   11222 rtx
   11223 legitimize_pic_address (rtx orig, rtx reg)
   11224 {
   11225   rtx addr = orig;
   11226   rtx new_rtx = orig;
   11227 
   11228 #if TARGET_MACHO
   11229   if (TARGET_MACHO && !TARGET_64BIT)
   11230     {
   11231       if (reg == 0)
   11232 	reg = gen_reg_rtx (Pmode);
   11233       /* Use the generic Mach-O PIC machinery.  */
   11234       return machopic_legitimize_pic_address (orig, GET_MODE (orig), reg);
   11235     }
   11236 #endif
   11237 
   11238   if (TARGET_64BIT && TARGET_DLLIMPORT_DECL_ATTRIBUTES)
   11239     {
   11240       rtx tmp = legitimize_pe_coff_symbol (addr, true);
   11241       if (tmp)
   11242         return tmp;
   11243     }
   11244 
   11245   if (TARGET_64BIT && legitimate_pic_address_disp_p (addr))
   11246     new_rtx = addr;
   11247   else if ((!TARGET_64BIT
   11248 	    || /* TARGET_64BIT && */ ix86_cmodel != CM_SMALL_PIC)
   11249 	   && !TARGET_PECOFF
   11250 	   && gotoff_operand (addr, Pmode))
   11251     {
   11252       /* This symbol may be referenced via a displacement
   11253 	 from the PIC base address (@GOTOFF).  */
   11254       if (GET_CODE (addr) == CONST)
   11255 	addr = XEXP (addr, 0);
   11256 
   11257       if (GET_CODE (addr) == PLUS)
   11258 	  {
   11259             new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, XEXP (addr, 0)),
   11260 				      UNSPEC_GOTOFF);
   11261 	    new_rtx = gen_rtx_PLUS (Pmode, new_rtx, XEXP (addr, 1));
   11262 	  }
   11263 	else
   11264           new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOTOFF);
   11265 
   11266       new_rtx = gen_rtx_CONST (Pmode, new_rtx);
   11267 
   11268       if (TARGET_64BIT)
   11269 	new_rtx = copy_to_suggested_reg (new_rtx, reg, Pmode);
   11270 
   11271       if (reg != 0)
   11272 	{
   11273  	  gcc_assert (REG_P (reg));
   11274 	  new_rtx = expand_simple_binop (Pmode, PLUS, pic_offset_table_rtx,
   11275 					 new_rtx, reg, 1, OPTAB_DIRECT);
   11276  	}
   11277       else
   11278 	new_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, new_rtx);
   11279     }
   11280   else if ((GET_CODE (addr) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (addr) == 0)
   11281 	   /* We can't always use @GOTOFF for text labels
   11282 	      on VxWorks, see gotoff_operand.  */
   11283 	   || (TARGET_VXWORKS_RTP && GET_CODE (addr) == LABEL_REF))
   11284     {
   11285       rtx tmp = legitimize_pe_coff_symbol (addr, true);
   11286       if (tmp)
   11287         return tmp;
   11288 
   11289       /* For x64 PE-COFF there is no GOT table,
   11290 	 so we use address directly.  */
   11291       if (TARGET_64BIT && TARGET_PECOFF)
   11292 	{
   11293 	  new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_PCREL);
   11294 	  new_rtx = gen_rtx_CONST (Pmode, new_rtx);
   11295 	}
   11296       else if (TARGET_64BIT && ix86_cmodel != CM_LARGE_PIC)
   11297 	{
   11298 	  new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr),
   11299 				    UNSPEC_GOTPCREL);
   11300 	  new_rtx = gen_rtx_CONST (Pmode, new_rtx);
   11301 	  new_rtx = gen_const_mem (Pmode, new_rtx);
   11302 	  set_mem_alias_set (new_rtx, ix86_GOT_alias_set ());
   11303 	}
   11304       else
   11305 	{
   11306 	  /* This symbol must be referenced via a load
   11307 	     from the Global Offset Table (@GOT).  */
   11308 	  new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOT);
   11309 	  new_rtx = gen_rtx_CONST (Pmode, new_rtx);
   11310 
   11311 	  if (TARGET_64BIT)
   11312 	    new_rtx = copy_to_suggested_reg (new_rtx, reg, Pmode);
   11313 
   11314 	  if (reg != 0)
   11315 	    {
   11316 	      gcc_assert (REG_P (reg));
   11317 	      new_rtx = expand_simple_binop (Pmode, PLUS, pic_offset_table_rtx,
   11318 					     new_rtx, reg, 1, OPTAB_DIRECT);
   11319 	    }
   11320 	  else
   11321 	    new_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, new_rtx);
   11322 
   11323 	  new_rtx = gen_const_mem (Pmode, new_rtx);
   11324 	  set_mem_alias_set (new_rtx, ix86_GOT_alias_set ());
   11325 	}
   11326 
   11327       new_rtx = copy_to_suggested_reg (new_rtx, reg, Pmode);
   11328     }
   11329   else
   11330     {
   11331       if (CONST_INT_P (addr)
   11332 	  && !x86_64_immediate_operand (addr, VOIDmode))
   11333 	new_rtx = copy_to_suggested_reg (addr, reg, Pmode);
   11334       else if (GET_CODE (addr) == CONST)
   11335 	{
   11336 	  addr = XEXP (addr, 0);
   11337 
   11338 	  /* We must match stuff we generate before.  Assume the only
   11339 	     unspecs that can get here are ours.  Not that we could do
   11340 	     anything with them anyway....  */
   11341 	  if (GET_CODE (addr) == UNSPEC
   11342 	      || (GET_CODE (addr) == PLUS
   11343 		  && GET_CODE (XEXP (addr, 0)) == UNSPEC))
   11344 	    return orig;
   11345 	  gcc_assert (GET_CODE (addr) == PLUS);
   11346 	}
   11347 
   11348       if (GET_CODE (addr) == PLUS)
   11349 	{
   11350 	  rtx op0 = XEXP (addr, 0), op1 = XEXP (addr, 1);
   11351 
   11352 	  /* Check first to see if this is a constant
   11353 	     offset from a @GOTOFF symbol reference.  */
   11354 	  if (!TARGET_PECOFF
   11355 	      && gotoff_operand (op0, Pmode)
   11356 	      && CONST_INT_P (op1))
   11357 	    {
   11358 	      if (!TARGET_64BIT)
   11359 		{
   11360 		  new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, op0),
   11361 					    UNSPEC_GOTOFF);
   11362 		  new_rtx = gen_rtx_PLUS (Pmode, new_rtx, op1);
   11363 		  new_rtx = gen_rtx_CONST (Pmode, new_rtx);
   11364 
   11365 		  if (reg != 0)
   11366 		    {
   11367 		      gcc_assert (REG_P (reg));
   11368 		      new_rtx = expand_simple_binop (Pmode, PLUS,
   11369 						     pic_offset_table_rtx,
   11370 						     new_rtx, reg, 1,
   11371 						     OPTAB_DIRECT);
   11372 		    }
   11373 		  else
   11374 		    new_rtx
   11375 		      = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, new_rtx);
   11376 		}
   11377 	      else
   11378 		{
   11379 		  if (INTVAL (op1) < -16*1024*1024
   11380 		      || INTVAL (op1) >= 16*1024*1024)
   11381 		    {
   11382 		      if (!x86_64_immediate_operand (op1, Pmode))
   11383 			op1 = force_reg (Pmode, op1);
   11384 
   11385 		      new_rtx
   11386 			= gen_rtx_PLUS (Pmode, force_reg (Pmode, op0), op1);
   11387 		    }
   11388 		}
   11389 	    }
   11390 	  else
   11391 	    {
   11392 	      rtx base = legitimize_pic_address (op0, reg);
   11393 	      machine_mode mode = GET_MODE (base);
   11394 	      new_rtx
   11395 	        = legitimize_pic_address (op1, base == reg ? NULL_RTX : reg);
   11396 
   11397 	      if (CONST_INT_P (new_rtx))
   11398 		{
   11399 		  if (INTVAL (new_rtx) < -16*1024*1024
   11400 		      || INTVAL (new_rtx) >= 16*1024*1024)
   11401 		    {
   11402 		      if (!x86_64_immediate_operand (new_rtx, mode))
   11403 			new_rtx = force_reg (mode, new_rtx);
   11404 
   11405 		      new_rtx
   11406 		        = gen_rtx_PLUS (mode, force_reg (mode, base), new_rtx);
   11407 		    }
   11408 		  else
   11409 		    new_rtx = plus_constant (mode, base, INTVAL (new_rtx));
   11410 		}
   11411 	      else
   11412 		{
   11413 		  /* For %rip addressing, we have to use
   11414 		     just disp32, not base nor index.  */
   11415 		  if (TARGET_64BIT
   11416 		      && (GET_CODE (base) == SYMBOL_REF
   11417 			  || GET_CODE (base) == LABEL_REF))
   11418 		    base = force_reg (mode, base);
   11419 		  if (GET_CODE (new_rtx) == PLUS
   11420 		      && CONSTANT_P (XEXP (new_rtx, 1)))
   11421 		    {
   11422 		      base = gen_rtx_PLUS (mode, base, XEXP (new_rtx, 0));
   11423 		      new_rtx = XEXP (new_rtx, 1);
   11424 		    }
   11425 		  new_rtx = gen_rtx_PLUS (mode, base, new_rtx);
   11426 		}
   11427 	    }
   11428 	}
   11429     }
   11430   return new_rtx;
   11431 }
   11432 
   11433 /* Load the thread pointer.  If TO_REG is true, force it into a register.  */
   11435 
   11436 static rtx
   11437 get_thread_pointer (machine_mode tp_mode, bool to_reg)
   11438 {
   11439   rtx tp = gen_rtx_UNSPEC (ptr_mode, gen_rtvec (1, const0_rtx), UNSPEC_TP);
   11440 
   11441   if (GET_MODE (tp) != tp_mode)
   11442     {
   11443       gcc_assert (GET_MODE (tp) == SImode);
   11444       gcc_assert (tp_mode == DImode);
   11445 
   11446       tp = gen_rtx_ZERO_EXTEND (tp_mode, tp);
   11447     }
   11448 
   11449   if (to_reg)
   11450     tp = copy_to_mode_reg (tp_mode, tp);
   11451 
   11452   return tp;
   11453 }
   11454 
   11455 /* Construct the SYMBOL_REF for the tls_get_addr function.  */
   11456 
   11457 static GTY(()) rtx ix86_tls_symbol;
   11458 
   11459 static rtx
   11460 ix86_tls_get_addr (void)
   11461 {
   11462   if (!ix86_tls_symbol)
   11463     {
   11464       const char *sym
   11465 	= ((TARGET_ANY_GNU_TLS && !TARGET_64BIT)
   11466 	   ? "___tls_get_addr" : "__tls_get_addr");
   11467 
   11468       ix86_tls_symbol = gen_rtx_SYMBOL_REF (Pmode, sym);
   11469     }
   11470 
   11471   if (ix86_cmodel == CM_LARGE_PIC && !TARGET_PECOFF)
   11472     {
   11473       rtx unspec = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, ix86_tls_symbol),
   11474 				   UNSPEC_PLTOFF);
   11475       return gen_rtx_PLUS (Pmode, pic_offset_table_rtx,
   11476 			   gen_rtx_CONST (Pmode, unspec));
   11477     }
   11478 
   11479   return ix86_tls_symbol;
   11480 }
   11481 
   11482 /* Construct the SYMBOL_REF for the _TLS_MODULE_BASE_ symbol.  */
   11483 
   11484 static GTY(()) rtx ix86_tls_module_base_symbol;
   11485 
   11486 rtx
   11487 ix86_tls_module_base (void)
   11488 {
   11489   if (!ix86_tls_module_base_symbol)
   11490     {
   11491       ix86_tls_module_base_symbol
   11492 	= gen_rtx_SYMBOL_REF (ptr_mode, "_TLS_MODULE_BASE_");
   11493 
   11494       SYMBOL_REF_FLAGS (ix86_tls_module_base_symbol)
   11495 	|= TLS_MODEL_GLOBAL_DYNAMIC << SYMBOL_FLAG_TLS_SHIFT;
   11496     }
   11497 
   11498   return ix86_tls_module_base_symbol;
   11499 }
   11500 
   11501 /* A subroutine of ix86_legitimize_address and ix86_expand_move.  FOR_MOV is
   11502    false if we expect this to be used for a memory address and true if
   11503    we expect to load the address into a register.  */
   11504 
   11505 rtx
   11506 legitimize_tls_address (rtx x, enum tls_model model, bool for_mov)
   11507 {
   11508   rtx dest, base, off;
   11509   rtx pic = NULL_RTX, tp = NULL_RTX;
   11510   machine_mode tp_mode = Pmode;
   11511   int type;
   11512 
   11513   /* Fall back to global dynamic model if tool chain cannot support local
   11514      dynamic.  */
   11515   if (TARGET_SUN_TLS && !TARGET_64BIT
   11516       && !HAVE_AS_IX86_TLSLDMPLT && !HAVE_AS_IX86_TLSLDM
   11517       && model == TLS_MODEL_LOCAL_DYNAMIC)
   11518     model = TLS_MODEL_GLOBAL_DYNAMIC;
   11519 
   11520   switch (model)
   11521     {
   11522     case TLS_MODEL_GLOBAL_DYNAMIC:
   11523       if (!TARGET_64BIT)
   11524 	{
   11525 	  if (flag_pic && !TARGET_PECOFF)
   11526 	    pic = pic_offset_table_rtx;
   11527 	  else
   11528 	    {
   11529 	      pic = gen_reg_rtx (Pmode);
   11530 	      emit_insn (gen_set_got (pic));
   11531 	    }
   11532 	}
   11533 
   11534       if (TARGET_GNU2_TLS)
   11535 	{
   11536 	  dest = gen_reg_rtx (ptr_mode);
   11537 	  if (TARGET_64BIT)
   11538 	    emit_insn (gen_tls_dynamic_gnu2_64 (ptr_mode, dest, x));
   11539 	  else
   11540 	    emit_insn (gen_tls_dynamic_gnu2_32 (dest, x, pic));
   11541 
   11542 	  tp = get_thread_pointer (ptr_mode, true);
   11543 	  dest = gen_rtx_PLUS (ptr_mode, tp, dest);
   11544 	  if (GET_MODE (dest) != Pmode)
   11545 	     dest = gen_rtx_ZERO_EXTEND (Pmode, dest);
   11546 	  dest = force_reg (Pmode, dest);
   11547 
   11548 	  if (GET_MODE (x) != Pmode)
   11549 	    x = gen_rtx_ZERO_EXTEND (Pmode, x);
   11550 
   11551 	  set_unique_reg_note (get_last_insn (), REG_EQUAL, x);
   11552 	}
   11553       else
   11554 	{
   11555 	  rtx caddr = ix86_tls_get_addr ();
   11556 
   11557 	  dest = gen_reg_rtx (Pmode);
   11558 	  if (TARGET_64BIT)
   11559 	    {
   11560 	      rtx rax = gen_rtx_REG (Pmode, AX_REG);
   11561 	      rtx_insn *insns;
   11562 
   11563 	      start_sequence ();
   11564 	      emit_call_insn
   11565 		(gen_tls_global_dynamic_64 (Pmode, rax, x, caddr));
   11566 	      insns = get_insns ();
   11567 	      end_sequence ();
   11568 
   11569 	      if (GET_MODE (x) != Pmode)
   11570 		x = gen_rtx_ZERO_EXTEND (Pmode, x);
   11571 
   11572 	      RTL_CONST_CALL_P (insns) = 1;
   11573 	      emit_libcall_block (insns, dest, rax, x);
   11574 	    }
   11575 	  else
   11576 	    emit_insn (gen_tls_global_dynamic_32 (dest, x, pic, caddr));
   11577 	}
   11578       break;
   11579 
   11580     case TLS_MODEL_LOCAL_DYNAMIC:
   11581       if (!TARGET_64BIT)
   11582 	{
   11583 	  if (flag_pic)
   11584 	    pic = pic_offset_table_rtx;
   11585 	  else
   11586 	    {
   11587 	      pic = gen_reg_rtx (Pmode);
   11588 	      emit_insn (gen_set_got (pic));
   11589 	    }
   11590 	}
   11591 
   11592       if (TARGET_GNU2_TLS)
   11593 	{
   11594 	  rtx tmp = ix86_tls_module_base ();
   11595 
   11596 	  base = gen_reg_rtx (ptr_mode);
   11597 	  if (TARGET_64BIT)
   11598 	    emit_insn (gen_tls_dynamic_gnu2_64 (ptr_mode, base, tmp));
   11599 	  else
   11600 	    emit_insn (gen_tls_dynamic_gnu2_32 (base, tmp, pic));
   11601 
   11602 	  tp = get_thread_pointer (ptr_mode, true);
   11603 	  if (GET_MODE (base) != Pmode)
   11604 	    base = gen_rtx_ZERO_EXTEND (Pmode, base);
   11605 	  base = force_reg (Pmode, base);
   11606 	}
   11607       else
   11608 	{
   11609 	  rtx caddr = ix86_tls_get_addr ();
   11610 
   11611 	  base = gen_reg_rtx (Pmode);
   11612 	  if (TARGET_64BIT)
   11613 	    {
   11614 	      rtx rax = gen_rtx_REG (Pmode, AX_REG);
   11615 	      rtx_insn *insns;
   11616 	      rtx eqv;
   11617 
   11618 	      start_sequence ();
   11619 	      emit_call_insn
   11620 		(gen_tls_local_dynamic_base_64 (Pmode, rax, caddr));
   11621 	      insns = get_insns ();
   11622 	      end_sequence ();
   11623 
   11624 	      /* Attach a unique REG_EQUAL, to allow the RTL optimizers to
   11625 		 share the LD_BASE result with other LD model accesses.  */
   11626 	      eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx),
   11627 				    UNSPEC_TLS_LD_BASE);
   11628 
   11629 	      RTL_CONST_CALL_P (insns) = 1;
   11630 	      emit_libcall_block (insns, base, rax, eqv);
   11631 	    }
   11632 	  else
   11633 	    emit_insn (gen_tls_local_dynamic_base_32 (base, pic, caddr));
   11634 	}
   11635 
   11636       off = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, x), UNSPEC_DTPOFF);
   11637       off = gen_rtx_CONST (Pmode, off);
   11638 
   11639       dest = force_reg (Pmode, gen_rtx_PLUS (Pmode, base, off));
   11640 
   11641       if (TARGET_GNU2_TLS)
   11642 	{
   11643 	  if (GET_MODE (tp) != Pmode)
   11644 	    {
   11645 	      dest = lowpart_subreg (ptr_mode, dest, Pmode);
   11646 	      dest = gen_rtx_PLUS (ptr_mode, tp, dest);
   11647 	      dest = gen_rtx_ZERO_EXTEND (Pmode, dest);
   11648 	    }
   11649 	  else
   11650 	    dest = gen_rtx_PLUS (Pmode, tp, dest);
   11651 	  dest = force_reg (Pmode, dest);
   11652 
   11653 	  if (GET_MODE (x) != Pmode)
   11654 	    x = gen_rtx_ZERO_EXTEND (Pmode, x);
   11655 
   11656 	  set_unique_reg_note (get_last_insn (), REG_EQUAL, x);
   11657 	}
   11658       break;
   11659 
   11660     case TLS_MODEL_INITIAL_EXEC:
   11661       if (TARGET_64BIT)
   11662 	{
   11663 	  if (TARGET_SUN_TLS && !TARGET_X32)
   11664 	    {
   11665 	      /* The Sun linker took the AMD64 TLS spec literally
   11666 		 and can only handle %rax as destination of the
   11667 		 initial executable code sequence.  */
   11668 
   11669 	      dest = gen_reg_rtx (DImode);
   11670 	      emit_insn (gen_tls_initial_exec_64_sun (dest, x));
   11671 	      return dest;
   11672 	    }
   11673 
   11674 	  /* Generate DImode references to avoid %fs:(%reg32)
   11675 	     problems and linker IE->LE relaxation bug.  */
   11676 	  tp_mode = DImode;
   11677 	  pic = NULL;
   11678 	  type = UNSPEC_GOTNTPOFF;
   11679 	}
   11680       else if (flag_pic)
   11681 	{
   11682 	  pic = pic_offset_table_rtx;
   11683 	  type = TARGET_ANY_GNU_TLS ? UNSPEC_GOTNTPOFF : UNSPEC_GOTTPOFF;
   11684 	}
   11685       else if (!TARGET_ANY_GNU_TLS)
   11686 	{
   11687 	  pic = gen_reg_rtx (Pmode);
   11688 	  emit_insn (gen_set_got (pic));
   11689 	  type = UNSPEC_GOTTPOFF;
   11690 	}
   11691       else
   11692 	{
   11693 	  pic = NULL;
   11694 	  type = UNSPEC_INDNTPOFF;
   11695 	}
   11696 
   11697       off = gen_rtx_UNSPEC (tp_mode, gen_rtvec (1, x), type);
   11698       off = gen_rtx_CONST (tp_mode, off);
   11699       if (pic)
   11700 	off = gen_rtx_PLUS (tp_mode, pic, off);
   11701       off = gen_const_mem (tp_mode, off);
   11702       set_mem_alias_set (off, ix86_GOT_alias_set ());
   11703 
   11704       if (TARGET_64BIT || TARGET_ANY_GNU_TLS)
   11705 	{
   11706 	  base = get_thread_pointer (tp_mode,
   11707 				     for_mov || !TARGET_TLS_DIRECT_SEG_REFS);
   11708 	  off = force_reg (tp_mode, off);
   11709 	  dest = gen_rtx_PLUS (tp_mode, base, off);
   11710 	  if (tp_mode != Pmode)
   11711 	    dest = convert_to_mode (Pmode, dest, 1);
   11712 	}
   11713       else
   11714 	{
   11715 	  base = get_thread_pointer (Pmode, true);
   11716 	  dest = gen_reg_rtx (Pmode);
   11717 	  emit_insn (gen_sub3_insn (dest, base, off));
   11718 	}
   11719       break;
   11720 
   11721     case TLS_MODEL_LOCAL_EXEC:
   11722       off = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, x),
   11723 			    (TARGET_64BIT || TARGET_ANY_GNU_TLS)
   11724 			    ? UNSPEC_NTPOFF : UNSPEC_TPOFF);
   11725       off = gen_rtx_CONST (Pmode, off);
   11726 
   11727       if (TARGET_64BIT || TARGET_ANY_GNU_TLS)
   11728 	{
   11729 	  base = get_thread_pointer (Pmode,
   11730 				     for_mov || !TARGET_TLS_DIRECT_SEG_REFS);
   11731 	  return gen_rtx_PLUS (Pmode, base, off);
   11732 	}
   11733       else
   11734 	{
   11735 	  base = get_thread_pointer (Pmode, true);
   11736 	  dest = gen_reg_rtx (Pmode);
   11737 	  emit_insn (gen_sub3_insn (dest, base, off));
   11738 	}
   11739       break;
   11740 
   11741     default:
   11742       gcc_unreachable ();
   11743     }
   11744 
   11745   return dest;
   11746 }
   11747 
   11748 /* Return true if the TLS address requires insn using integer registers.
   11749    It's used to prevent KMOV/VMOV in TLS code sequences which require integer
   11750    MOV instructions, refer to PR103275.  */
   11751 bool
   11752 ix86_gpr_tls_address_pattern_p (rtx mem)
   11753 {
   11754   gcc_assert (MEM_P (mem));
   11755 
   11756   rtx addr = XEXP (mem, 0);
   11757   subrtx_var_iterator::array_type array;
   11758   FOR_EACH_SUBRTX_VAR (iter, array, addr, ALL)
   11759     {
   11760       rtx op = *iter;
   11761       if (GET_CODE (op) == UNSPEC)
   11762 	switch (XINT (op, 1))
   11763 	  {
   11764 	  case UNSPEC_GOTNTPOFF:
   11765 	    return true;
   11766 	  case UNSPEC_TPOFF:
   11767 	    if (!TARGET_64BIT)
   11768 	      return true;
   11769 	    break;
   11770 	  default:
   11771 	    break;
   11772 	  }
   11773     }
   11774 
   11775   return false;
   11776 }
   11777 
   11778 /* Return true if OP refers to a TLS address.  */
   11779 bool
   11780 ix86_tls_address_pattern_p (rtx op)
   11781 {
   11782   subrtx_var_iterator::array_type array;
   11783   FOR_EACH_SUBRTX_VAR (iter, array, op, ALL)
   11784     {
   11785       rtx op = *iter;
   11786       if (MEM_P (op))
   11787 	{
   11788 	  rtx *x = &XEXP (op, 0);
   11789 	  while (GET_CODE (*x) == PLUS)
   11790 	    {
   11791 	      int i;
   11792 	      for (i = 0; i < 2; i++)
   11793 		{
   11794 		  rtx u = XEXP (*x, i);
   11795 		  if (GET_CODE (u) == ZERO_EXTEND)
   11796 		    u = XEXP (u, 0);
   11797 		  if (GET_CODE (u) == UNSPEC
   11798 		      && XINT (u, 1) == UNSPEC_TP)
   11799 		    return true;
   11800 		}
   11801 	      x = &XEXP (*x, 0);
   11802 	    }
   11803 
   11804 	  iter.skip_subrtxes ();
   11805 	}
   11806     }
   11807 
   11808   return false;
   11809 }
   11810 
   11811 /* Rewrite *LOC so that it refers to a default TLS address space.  */
   11812 static void
   11813 ix86_rewrite_tls_address_1 (rtx *loc)
   11814 {
   11815   subrtx_ptr_iterator::array_type array;
   11816   FOR_EACH_SUBRTX_PTR (iter, array, loc, ALL)
   11817     {
   11818       rtx *loc = *iter;
   11819       if (MEM_P (*loc))
   11820 	{
   11821 	  rtx addr = XEXP (*loc, 0);
   11822 	  rtx *x = &addr;
   11823 	  while (GET_CODE (*x) == PLUS)
   11824 	    {
   11825 	      int i;
   11826 	      for (i = 0; i < 2; i++)
   11827 		{
   11828 		  rtx u = XEXP (*x, i);
   11829 		  if (GET_CODE (u) == ZERO_EXTEND)
   11830 		    u = XEXP (u, 0);
   11831 		  if (GET_CODE (u) == UNSPEC
   11832 		      && XINT (u, 1) == UNSPEC_TP)
   11833 		    {
   11834 		      /* NB: Since address override only applies to the
   11835 			 (reg32) part in fs:(reg32), return if address
   11836 			 override is used.  */
   11837 		      if (Pmode != word_mode
   11838 			  && REG_P (XEXP (*x, 1 - i)))
   11839 			return;
   11840 
   11841 		      addr_space_t as = DEFAULT_TLS_SEG_REG;
   11842 
   11843 		      *x = XEXP (*x, 1 - i);
   11844 
   11845 		      *loc = replace_equiv_address_nv (*loc, addr, true);
   11846 		      set_mem_addr_space (*loc, as);
   11847 		      return;
   11848 		    }
   11849 		}
   11850 	      x = &XEXP (*x, 0);
   11851 	    }
   11852 
   11853 	  iter.skip_subrtxes ();
   11854 	}
   11855     }
   11856 }
   11857 
   11858 /* Rewrite instruction pattern involvning TLS address
   11859    so that it refers to a default TLS address space.  */
   11860 rtx
   11861 ix86_rewrite_tls_address (rtx pattern)
   11862 {
   11863   pattern = copy_insn (pattern);
   11864   ix86_rewrite_tls_address_1 (&pattern);
   11865   return pattern;
   11866 }
   11867 
   11868 /* Create or return the unique __imp_DECL dllimport symbol corresponding
   11869    to symbol DECL if BEIMPORT is true.  Otherwise create or return the
   11870    unique refptr-DECL symbol corresponding to symbol DECL.  */
   11871 
   11872 struct dllimport_hasher : ggc_cache_ptr_hash<tree_map>
   11873 {
   11874   static inline hashval_t hash (tree_map *m) { return m->hash; }
   11875   static inline bool
   11876   equal (tree_map *a, tree_map *b)
   11877   {
   11878     return a->base.from == b->base.from;
   11879   }
   11880 
   11881   static int
   11882   keep_cache_entry (tree_map *&m)
   11883   {
   11884     return ggc_marked_p (m->base.from);
   11885   }
   11886 };
   11887 
   11888 static GTY((cache)) hash_table<dllimport_hasher> *dllimport_map;
   11889 
   11890 static tree
   11891 get_dllimport_decl (tree decl, bool beimport)
   11892 {
   11893   struct tree_map *h, in;
   11894   const char *name;
   11895   const char *prefix;
   11896   size_t namelen, prefixlen;
   11897   char *imp_name;
   11898   tree to;
   11899   rtx rtl;
   11900 
   11901   if (!dllimport_map)
   11902     dllimport_map = hash_table<dllimport_hasher>::create_ggc (512);
   11903 
   11904   in.hash = htab_hash_pointer (decl);
   11905   in.base.from = decl;
   11906   tree_map **loc = dllimport_map->find_slot_with_hash (&in, in.hash, INSERT);
   11907   h = *loc;
   11908   if (h)
   11909     return h->to;
   11910 
   11911   *loc = h = ggc_alloc<tree_map> ();
   11912   h->hash = in.hash;
   11913   h->base.from = decl;
   11914   h->to = to = build_decl (DECL_SOURCE_LOCATION (decl),
   11915 			   VAR_DECL, NULL, ptr_type_node);
   11916   DECL_ARTIFICIAL (to) = 1;
   11917   DECL_IGNORED_P (to) = 1;
   11918   DECL_EXTERNAL (to) = 1;
   11919   TREE_READONLY (to) = 1;
   11920 
   11921   name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
   11922   name = targetm.strip_name_encoding (name);
   11923   if (beimport)
   11924     prefix = name[0] == FASTCALL_PREFIX || user_label_prefix[0] == 0
   11925       ? "*__imp_" : "*__imp__";
   11926   else
   11927     prefix = user_label_prefix[0] == 0 ? "*.refptr." : "*refptr.";
   11928   namelen = strlen (name);
   11929   prefixlen = strlen (prefix);
   11930   imp_name = (char *) alloca (namelen + prefixlen + 1);
   11931   memcpy (imp_name, prefix, prefixlen);
   11932   memcpy (imp_name + prefixlen, name, namelen + 1);
   11933 
   11934   name = ggc_alloc_string (imp_name, namelen + prefixlen);
   11935   rtl = gen_rtx_SYMBOL_REF (Pmode, name);
   11936   SET_SYMBOL_REF_DECL (rtl, to);
   11937   SYMBOL_REF_FLAGS (rtl) = SYMBOL_FLAG_LOCAL | SYMBOL_FLAG_STUBVAR;
   11938   if (!beimport)
   11939     {
   11940       SYMBOL_REF_FLAGS (rtl) |= SYMBOL_FLAG_EXTERNAL;
   11941 #ifdef SUB_TARGET_RECORD_STUB
   11942       SUB_TARGET_RECORD_STUB (name);
   11943 #endif
   11944     }
   11945 
   11946   rtl = gen_const_mem (Pmode, rtl);
   11947   set_mem_alias_set (rtl, ix86_GOT_alias_set ());
   11948 
   11949   SET_DECL_RTL (to, rtl);
   11950   SET_DECL_ASSEMBLER_NAME (to, get_identifier (name));
   11951 
   11952   return to;
   11953 }
   11954 
   11955 /* Expand SYMBOL into its corresponding far-address symbol.
   11956    WANT_REG is true if we require the result be a register.  */
   11957 
   11958 static rtx
   11959 legitimize_pe_coff_extern_decl (rtx symbol, bool want_reg)
   11960 {
   11961   tree imp_decl;
   11962   rtx x;
   11963 
   11964   gcc_assert (SYMBOL_REF_DECL (symbol));
   11965   imp_decl = get_dllimport_decl (SYMBOL_REF_DECL (symbol), false);
   11966 
   11967   x = DECL_RTL (imp_decl);
   11968   if (want_reg)
   11969     x = force_reg (Pmode, x);
   11970   return x;
   11971 }
   11972 
   11973 /* Expand SYMBOL into its corresponding dllimport symbol.  WANT_REG is
   11974    true if we require the result be a register.  */
   11975 
   11976 static rtx
   11977 legitimize_dllimport_symbol (rtx symbol, bool want_reg)
   11978 {
   11979   tree imp_decl;
   11980   rtx x;
   11981 
   11982   gcc_assert (SYMBOL_REF_DECL (symbol));
   11983   imp_decl = get_dllimport_decl (SYMBOL_REF_DECL (symbol), true);
   11984 
   11985   x = DECL_RTL (imp_decl);
   11986   if (want_reg)
   11987     x = force_reg (Pmode, x);
   11988   return x;
   11989 }
   11990 
   11991 /* Expand SYMBOL into its corresponding dllimport or refptr symbol.  WANT_REG
   11992    is true if we require the result be a register.  */
   11993 
   11994 rtx
   11995 legitimize_pe_coff_symbol (rtx addr, bool inreg)
   11996 {
   11997   if (!TARGET_PECOFF)
   11998     return NULL_RTX;
   11999 
   12000   if (TARGET_DLLIMPORT_DECL_ATTRIBUTES)
   12001     {
   12002       if (GET_CODE (addr) == SYMBOL_REF && SYMBOL_REF_DLLIMPORT_P (addr))
   12003 	return legitimize_dllimport_symbol (addr, inreg);
   12004       if (GET_CODE (addr) == CONST
   12005 	  && GET_CODE (XEXP (addr, 0)) == PLUS
   12006 	  && GET_CODE (XEXP (XEXP (addr, 0), 0)) == SYMBOL_REF
   12007 	  && SYMBOL_REF_DLLIMPORT_P (XEXP (XEXP (addr, 0), 0)))
   12008 	{
   12009 	  rtx t = legitimize_dllimport_symbol (XEXP (XEXP (addr, 0), 0), inreg);
   12010 	  return gen_rtx_PLUS (Pmode, t, XEXP (XEXP (addr, 0), 1));
   12011 	}
   12012     }
   12013 
   12014   if (ix86_cmodel != CM_LARGE_PIC && ix86_cmodel != CM_MEDIUM_PIC)
   12015     return NULL_RTX;
   12016   if (GET_CODE (addr) == SYMBOL_REF
   12017       && !is_imported_p (addr)
   12018       && SYMBOL_REF_EXTERNAL_P (addr)
   12019       && SYMBOL_REF_DECL (addr))
   12020     return legitimize_pe_coff_extern_decl (addr, inreg);
   12021 
   12022   if (GET_CODE (addr) == CONST
   12023       && GET_CODE (XEXP (addr, 0)) == PLUS
   12024       && GET_CODE (XEXP (XEXP (addr, 0), 0)) == SYMBOL_REF
   12025       && !is_imported_p (XEXP (XEXP (addr, 0), 0))
   12026       && SYMBOL_REF_EXTERNAL_P (XEXP (XEXP (addr, 0), 0))
   12027       && SYMBOL_REF_DECL (XEXP (XEXP (addr, 0), 0)))
   12028     {
   12029       rtx t = legitimize_pe_coff_extern_decl (XEXP (XEXP (addr, 0), 0), inreg);
   12030       return gen_rtx_PLUS (Pmode, t, XEXP (XEXP (addr, 0), 1));
   12031     }
   12032   return NULL_RTX;
   12033 }
   12034 
   12035 /* Try machine-dependent ways of modifying an illegitimate address
   12036    to be legitimate.  If we find one, return the new, valid address.
   12037    This macro is used in only one place: `memory_address' in explow.cc.
   12038 
   12039    OLDX is the address as it was before break_out_memory_refs was called.
   12040    In some cases it is useful to look at this to decide what needs to be done.
   12041 
   12042    It is always safe for this macro to do nothing.  It exists to recognize
   12043    opportunities to optimize the output.
   12044 
   12045    For the 80386, we handle X+REG by loading X into a register R and
   12046    using R+REG.  R will go in a general reg and indexing will be used.
   12047    However, if REG is a broken-out memory address or multiplication,
   12048    nothing needs to be done because REG can certainly go in a general reg.
   12049 
   12050    When -fpic is used, special handling is needed for symbolic references.
   12051    See comments by legitimize_pic_address in i386.cc for details.  */
   12052 
   12053 static rtx
   12054 ix86_legitimize_address (rtx x, rtx, machine_mode mode)
   12055 {
   12056   bool changed = false;
   12057   unsigned log;
   12058 
   12059   log = GET_CODE (x) == SYMBOL_REF ? SYMBOL_REF_TLS_MODEL (x) : 0;
   12060   if (log)
   12061     return legitimize_tls_address (x, (enum tls_model) log, false);
   12062   if (GET_CODE (x) == CONST
   12063       && GET_CODE (XEXP (x, 0)) == PLUS
   12064       && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
   12065       && (log = SYMBOL_REF_TLS_MODEL (XEXP (XEXP (x, 0), 0))))
   12066     {
   12067       rtx t = legitimize_tls_address (XEXP (XEXP (x, 0), 0),
   12068 				      (enum tls_model) log, false);
   12069       return gen_rtx_PLUS (Pmode, t, XEXP (XEXP (x, 0), 1));
   12070     }
   12071 
   12072   if (TARGET_DLLIMPORT_DECL_ATTRIBUTES)
   12073     {
   12074       rtx tmp = legitimize_pe_coff_symbol (x, true);
   12075       if (tmp)
   12076         return tmp;
   12077     }
   12078 
   12079   if (flag_pic && SYMBOLIC_CONST (x))
   12080     return legitimize_pic_address (x, 0);
   12081 
   12082 #if TARGET_MACHO
   12083   if (MACHO_DYNAMIC_NO_PIC_P && SYMBOLIC_CONST (x))
   12084     return machopic_indirect_data_reference (x, 0);
   12085 #endif
   12086 
   12087   /* Canonicalize shifts by 0, 1, 2, 3 into multiply */
   12088   if (GET_CODE (x) == ASHIFT
   12089       && CONST_INT_P (XEXP (x, 1))
   12090       && (unsigned HOST_WIDE_INT) INTVAL (XEXP (x, 1)) < 4)
   12091     {
   12092       changed = true;
   12093       log = INTVAL (XEXP (x, 1));
   12094       x = gen_rtx_MULT (Pmode, force_reg (Pmode, XEXP (x, 0)),
   12095 			GEN_INT (1 << log));
   12096     }
   12097 
   12098   if (GET_CODE (x) == PLUS)
   12099     {
   12100       /* Canonicalize shifts by 0, 1, 2, 3 into multiply.  */
   12101 
   12102       if (GET_CODE (XEXP (x, 0)) == ASHIFT
   12103 	  && CONST_INT_P (XEXP (XEXP (x, 0), 1))
   12104 	  && (unsigned HOST_WIDE_INT) INTVAL (XEXP (XEXP (x, 0), 1)) < 4)
   12105 	{
   12106 	  changed = true;
   12107 	  log = INTVAL (XEXP (XEXP (x, 0), 1));
   12108 	  XEXP (x, 0) = gen_rtx_MULT (Pmode,
   12109 				      force_reg (Pmode, XEXP (XEXP (x, 0), 0)),
   12110 				      GEN_INT (1 << log));
   12111 	}
   12112 
   12113       if (GET_CODE (XEXP (x, 1)) == ASHIFT
   12114 	  && CONST_INT_P (XEXP (XEXP (x, 1), 1))
   12115 	  && (unsigned HOST_WIDE_INT) INTVAL (XEXP (XEXP (x, 1), 1)) < 4)
   12116 	{
   12117 	  changed = true;
   12118 	  log = INTVAL (XEXP (XEXP (x, 1), 1));
   12119 	  XEXP (x, 1) = gen_rtx_MULT (Pmode,
   12120 				      force_reg (Pmode, XEXP (XEXP (x, 1), 0)),
   12121 				      GEN_INT (1 << log));
   12122 	}
   12123 
   12124       /* Put multiply first if it isn't already.  */
   12125       if (GET_CODE (XEXP (x, 1)) == MULT)
   12126 	{
   12127 	  std::swap (XEXP (x, 0), XEXP (x, 1));
   12128 	  changed = true;
   12129 	}
   12130 
   12131       /* Canonicalize (plus (mult (reg) (const)) (plus (reg) (const)))
   12132 	 into (plus (plus (mult (reg) (const)) (reg)) (const)).  This can be
   12133 	 created by virtual register instantiation, register elimination, and
   12134 	 similar optimizations.  */
   12135       if (GET_CODE (XEXP (x, 0)) == MULT && GET_CODE (XEXP (x, 1)) == PLUS)
   12136 	{
   12137 	  changed = true;
   12138 	  x = gen_rtx_PLUS (Pmode,
   12139 			    gen_rtx_PLUS (Pmode, XEXP (x, 0),
   12140 					  XEXP (XEXP (x, 1), 0)),
   12141 			    XEXP (XEXP (x, 1), 1));
   12142 	}
   12143 
   12144       /* Canonicalize
   12145 	 (plus (plus (mult (reg) (const)) (plus (reg) (const))) const)
   12146 	 into (plus (plus (mult (reg) (const)) (reg)) (const)).  */
   12147       else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == PLUS
   12148 	       && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT
   12149 	       && GET_CODE (XEXP (XEXP (x, 0), 1)) == PLUS
   12150 	       && CONSTANT_P (XEXP (x, 1)))
   12151 	{
   12152 	  rtx constant;
   12153 	  rtx other = NULL_RTX;
   12154 
   12155 	  if (CONST_INT_P (XEXP (x, 1)))
   12156 	    {
   12157 	      constant = XEXP (x, 1);
   12158 	      other = XEXP (XEXP (XEXP (x, 0), 1), 1);
   12159 	    }
   12160 	  else if (CONST_INT_P (XEXP (XEXP (XEXP (x, 0), 1), 1)))
   12161 	    {
   12162 	      constant = XEXP (XEXP (XEXP (x, 0), 1), 1);
   12163 	      other = XEXP (x, 1);
   12164 	    }
   12165 	  else
   12166 	    constant = 0;
   12167 
   12168 	  if (constant)
   12169 	    {
   12170 	      changed = true;
   12171 	      x = gen_rtx_PLUS (Pmode,
   12172 				gen_rtx_PLUS (Pmode, XEXP (XEXP (x, 0), 0),
   12173 					      XEXP (XEXP (XEXP (x, 0), 1), 0)),
   12174 				plus_constant (Pmode, other,
   12175 					       INTVAL (constant)));
   12176 	    }
   12177 	}
   12178 
   12179       if (changed && ix86_legitimate_address_p (mode, x, false))
   12180 	return x;
   12181 
   12182       if (GET_CODE (XEXP (x, 0)) == MULT)
   12183 	{
   12184 	  changed = true;
   12185 	  XEXP (x, 0) = copy_addr_to_reg (XEXP (x, 0));
   12186 	}
   12187 
   12188       if (GET_CODE (XEXP (x, 1)) == MULT)
   12189 	{
   12190 	  changed = true;
   12191 	  XEXP (x, 1) = copy_addr_to_reg (XEXP (x, 1));
   12192 	}
   12193 
   12194       if (changed
   12195 	  && REG_P (XEXP (x, 1))
   12196 	  && REG_P (XEXP (x, 0)))
   12197 	return x;
   12198 
   12199       if (flag_pic && SYMBOLIC_CONST (XEXP (x, 1)))
   12200 	{
   12201 	  changed = true;
   12202 	  x = legitimize_pic_address (x, 0);
   12203 	}
   12204 
   12205       if (changed && ix86_legitimate_address_p (mode, x, false))
   12206 	return x;
   12207 
   12208       if (REG_P (XEXP (x, 0)))
   12209 	{
   12210 	  rtx temp = gen_reg_rtx (Pmode);
   12211 	  rtx val  = force_operand (XEXP (x, 1), temp);
   12212 	  if (val != temp)
   12213 	    {
   12214 	      val = convert_to_mode (Pmode, val, 1);
   12215 	      emit_move_insn (temp, val);
   12216 	    }
   12217 
   12218 	  XEXP (x, 1) = temp;
   12219 	  return x;
   12220 	}
   12221 
   12222       else if (REG_P (XEXP (x, 1)))
   12223 	{
   12224 	  rtx temp = gen_reg_rtx (Pmode);
   12225 	  rtx val  = force_operand (XEXP (x, 0), temp);
   12226 	  if (val != temp)
   12227 	    {
   12228 	      val = convert_to_mode (Pmode, val, 1);
   12229 	      emit_move_insn (temp, val);
   12230 	    }
   12231 
   12232 	  XEXP (x, 0) = temp;
   12233 	  return x;
   12234 	}
   12235     }
   12236 
   12237   return x;
   12238 }
   12239 
   12240 /* Print an integer constant expression in assembler syntax.  Addition
   12242    and subtraction are the only arithmetic that may appear in these
   12243    expressions.  FILE is the stdio stream to write to, X is the rtx, and
   12244    CODE is the operand print code from the output string.  */
   12245 
   12246 static void
   12247 output_pic_addr_const (FILE *file, rtx x, int code)
   12248 {
   12249   char buf[256];
   12250 
   12251   switch (GET_CODE (x))
   12252     {
   12253     case PC:
   12254       gcc_assert (flag_pic);
   12255       putc ('.', file);
   12256       break;
   12257 
   12258     case SYMBOL_REF:
   12259       if (TARGET_64BIT || ! TARGET_MACHO_SYMBOL_STUBS)
   12260 	output_addr_const (file, x);
   12261       else
   12262 	{
   12263 	  const char *name = XSTR (x, 0);
   12264 
   12265 	  /* Mark the decl as referenced so that cgraph will
   12266 	     output the function.  */
   12267 	  if (SYMBOL_REF_DECL (x))
   12268 	    mark_decl_referenced (SYMBOL_REF_DECL (x));
   12269 
   12270 #if TARGET_MACHO
   12271 	  if (MACHOPIC_INDIRECT
   12272 	      && machopic_classify_symbol (x) == MACHOPIC_UNDEFINED_FUNCTION)
   12273 	    name = machopic_indirection_name (x, /*stub_p=*/true);
   12274 #endif
   12275 	  assemble_name (file, name);
   12276 	}
   12277       if (!TARGET_MACHO && !(TARGET_64BIT && TARGET_PECOFF)
   12278 	  && code == 'P' && ix86_call_use_plt_p (x))
   12279 	fputs ("@PLT", file);
   12280       break;
   12281 
   12282     case LABEL_REF:
   12283       x = XEXP (x, 0);
   12284       /* FALLTHRU */
   12285     case CODE_LABEL:
   12286       ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
   12287       assemble_name (asm_out_file, buf);
   12288       break;
   12289 
   12290     CASE_CONST_SCALAR_INT:
   12291       output_addr_const (file, x);
   12292       break;
   12293 
   12294     case CONST:
   12295       /* This used to output parentheses around the expression,
   12296 	 but that does not work on the 386 (either ATT or BSD assembler).  */
   12297       output_pic_addr_const (file, XEXP (x, 0), code);
   12298       break;
   12299 
   12300     case CONST_DOUBLE:
   12301       /* We can't handle floating point constants;
   12302 	 TARGET_PRINT_OPERAND must handle them.  */
   12303       output_operand_lossage ("floating constant misused");
   12304       break;
   12305 
   12306     case PLUS:
   12307       /* Some assemblers need integer constants to appear first.  */
   12308       if (CONST_INT_P (XEXP (x, 0)))
   12309 	{
   12310 	  output_pic_addr_const (file, XEXP (x, 0), code);
   12311 	  putc ('+', file);
   12312 	  output_pic_addr_const (file, XEXP (x, 1), code);
   12313 	}
   12314       else
   12315 	{
   12316 	  gcc_assert (CONST_INT_P (XEXP (x, 1)));
   12317 	  output_pic_addr_const (file, XEXP (x, 1), code);
   12318 	  putc ('+', file);
   12319 	  output_pic_addr_const (file, XEXP (x, 0), code);
   12320 	}
   12321       break;
   12322 
   12323     case MINUS:
   12324       if (!TARGET_MACHO)
   12325 	putc (ASSEMBLER_DIALECT == ASM_INTEL ? '(' : '[', file);
   12326       output_pic_addr_const (file, XEXP (x, 0), code);
   12327       putc ('-', file);
   12328       output_pic_addr_const (file, XEXP (x, 1), code);
   12329       if (!TARGET_MACHO)
   12330 	putc (ASSEMBLER_DIALECT == ASM_INTEL ? ')' : ']', file);
   12331       break;
   12332 
   12333     case UNSPEC:
   12334       gcc_assert (XVECLEN (x, 0) == 1);
   12335       output_pic_addr_const (file, XVECEXP (x, 0, 0), code);
   12336       switch (XINT (x, 1))
   12337 	{
   12338 	case UNSPEC_GOT:
   12339 	  fputs ("@GOT", file);
   12340 	  break;
   12341 	case UNSPEC_GOTOFF:
   12342 	  fputs ("@GOTOFF", file);
   12343 	  break;
   12344 	case UNSPEC_PLTOFF:
   12345 	  fputs ("@PLTOFF", file);
   12346 	  break;
   12347 	case UNSPEC_PCREL:
   12348 	  fputs (ASSEMBLER_DIALECT == ASM_ATT ?
   12349 		 "(%rip)" : "[rip]", file);
   12350 	  break;
   12351 	case UNSPEC_GOTPCREL:
   12352 	  fputs (ASSEMBLER_DIALECT == ASM_ATT ?
   12353 		 "@GOTPCREL(%rip)" : "@GOTPCREL[rip]", file);
   12354 	  break;
   12355 	case UNSPEC_GOTTPOFF:
   12356 	  /* FIXME: This might be @TPOFF in Sun ld too.  */
   12357 	  fputs ("@gottpoff", file);
   12358 	  break;
   12359 	case UNSPEC_TPOFF:
   12360 	  fputs ("@tpoff", file);
   12361 	  break;
   12362 	case UNSPEC_NTPOFF:
   12363 	  if (TARGET_64BIT)
   12364 	    fputs ("@tpoff", file);
   12365 	  else
   12366 	    fputs ("@ntpoff", file);
   12367 	  break;
   12368 	case UNSPEC_DTPOFF:
   12369 	  fputs ("@dtpoff", file);
   12370 	  break;
   12371 	case UNSPEC_GOTNTPOFF:
   12372 	  if (TARGET_64BIT)
   12373 	    fputs (ASSEMBLER_DIALECT == ASM_ATT ?
   12374 		   "@gottpoff(%rip)": "@gottpoff[rip]", file);
   12375 	  else
   12376 	    fputs ("@gotntpoff", file);
   12377 	  break;
   12378 	case UNSPEC_INDNTPOFF:
   12379 	  fputs ("@indntpoff", file);
   12380 	  break;
   12381 #if TARGET_MACHO
   12382 	case UNSPEC_MACHOPIC_OFFSET:
   12383 	  putc ('-', file);
   12384 	  machopic_output_function_base_name (file);
   12385 	  break;
   12386 #endif
   12387 	default:
   12388 	  output_operand_lossage ("invalid UNSPEC as operand");
   12389 	  break;
   12390 	}
   12391        break;
   12392 
   12393     default:
   12394       output_operand_lossage ("invalid expression as operand");
   12395     }
   12396 }
   12397 
   12398 /* This is called from dwarf2out.cc via TARGET_ASM_OUTPUT_DWARF_DTPREL.
   12399    We need to emit DTP-relative relocations.  */
   12400 
   12401 static void ATTRIBUTE_UNUSED
   12402 i386_output_dwarf_dtprel (FILE *file, int size, rtx x)
   12403 {
   12404   fputs (ASM_LONG, file);
   12405   output_addr_const (file, x);
   12406   fputs ("@dtpoff", file);
   12407   switch (size)
   12408     {
   12409     case 4:
   12410       break;
   12411     case 8:
   12412       fputs (", 0", file);
   12413       break;
   12414     default:
   12415       gcc_unreachable ();
   12416    }
   12417 }
   12418 
   12419 /* Return true if X is a representation of the PIC register.  This copes
   12420    with calls from ix86_find_base_term, where the register might have
   12421    been replaced by a cselib value.  */
   12422 
   12423 static bool
   12424 ix86_pic_register_p (rtx x)
   12425 {
   12426   if (GET_CODE (x) == VALUE && CSELIB_VAL_PTR (x))
   12427     return (pic_offset_table_rtx
   12428 	    && rtx_equal_for_cselib_p (x, pic_offset_table_rtx));
   12429   else if (GET_CODE (x) == UNSPEC && XINT (x, 1) == UNSPEC_SET_GOT)
   12430     return true;
   12431   else if (!REG_P (x))
   12432     return false;
   12433   else if (pic_offset_table_rtx)
   12434     {
   12435       if (REGNO (x) == REGNO (pic_offset_table_rtx))
   12436 	return true;
   12437       if (HARD_REGISTER_P (x)
   12438 	  && !HARD_REGISTER_P (pic_offset_table_rtx)
   12439 	  && ORIGINAL_REGNO (x) == REGNO (pic_offset_table_rtx))
   12440 	return true;
   12441       return false;
   12442     }
   12443   else
   12444     return REGNO (x) == PIC_OFFSET_TABLE_REGNUM;
   12445 }
   12446 
   12447 /* Helper function for ix86_delegitimize_address.
   12448    Attempt to delegitimize TLS local-exec accesses.  */
   12449 
   12450 static rtx
   12451 ix86_delegitimize_tls_address (rtx orig_x)
   12452 {
   12453   rtx x = orig_x, unspec;
   12454   struct ix86_address addr;
   12455 
   12456   if (!TARGET_TLS_DIRECT_SEG_REFS)
   12457     return orig_x;
   12458   if (MEM_P (x))
   12459     x = XEXP (x, 0);
   12460   if (GET_CODE (x) != PLUS || GET_MODE (x) != Pmode)
   12461     return orig_x;
   12462   if (ix86_decompose_address (x, &addr) == 0
   12463       || addr.seg != DEFAULT_TLS_SEG_REG
   12464       || addr.disp == NULL_RTX
   12465       || GET_CODE (addr.disp) != CONST)
   12466     return orig_x;
   12467   unspec = XEXP (addr.disp, 0);
   12468   if (GET_CODE (unspec) == PLUS && CONST_INT_P (XEXP (unspec, 1)))
   12469     unspec = XEXP (unspec, 0);
   12470   if (GET_CODE (unspec) != UNSPEC || XINT (unspec, 1) != UNSPEC_NTPOFF)
   12471     return orig_x;
   12472   x = XVECEXP (unspec, 0, 0);
   12473   gcc_assert (GET_CODE (x) == SYMBOL_REF);
   12474   if (unspec != XEXP (addr.disp, 0))
   12475     x = gen_rtx_PLUS (Pmode, x, XEXP (XEXP (addr.disp, 0), 1));
   12476   if (addr.index)
   12477     {
   12478       rtx idx = addr.index;
   12479       if (addr.scale != 1)
   12480 	idx = gen_rtx_MULT (Pmode, idx, GEN_INT (addr.scale));
   12481       x = gen_rtx_PLUS (Pmode, idx, x);
   12482     }
   12483   if (addr.base)
   12484     x = gen_rtx_PLUS (Pmode, addr.base, x);
   12485   if (MEM_P (orig_x))
   12486     x = replace_equiv_address_nv (orig_x, x);
   12487   return x;
   12488 }
   12489 
   12490 /* In the name of slightly smaller debug output, and to cater to
   12491    general assembler lossage, recognize PIC+GOTOFF and turn it back
   12492    into a direct symbol reference.
   12493 
   12494    On Darwin, this is necessary to avoid a crash, because Darwin
   12495    has a different PIC label for each routine but the DWARF debugging
   12496    information is not associated with any particular routine, so it's
   12497    necessary to remove references to the PIC label from RTL stored by
   12498    the DWARF output code.
   12499 
   12500    This helper is used in the normal ix86_delegitimize_address
   12501    entrypoint (e.g. used in the target delegitimization hook) and
   12502    in ix86_find_base_term.  As compile time memory optimization, we
   12503    avoid allocating rtxes that will not change anything on the outcome
   12504    of the callers (find_base_value and find_base_term).  */
   12505 
   12506 static inline rtx
   12507 ix86_delegitimize_address_1 (rtx x, bool base_term_p)
   12508 {
   12509   rtx orig_x = delegitimize_mem_from_attrs (x);
   12510   /* addend is NULL or some rtx if x is something+GOTOFF where
   12511      something doesn't include the PIC register.  */
   12512   rtx addend = NULL_RTX;
   12513   /* reg_addend is NULL or a multiple of some register.  */
   12514   rtx reg_addend = NULL_RTX;
   12515   /* const_addend is NULL or a const_int.  */
   12516   rtx const_addend = NULL_RTX;
   12517   /* This is the result, or NULL.  */
   12518   rtx result = NULL_RTX;
   12519 
   12520   x = orig_x;
   12521 
   12522   if (MEM_P (x))
   12523     x = XEXP (x, 0);
   12524 
   12525   if (TARGET_64BIT)
   12526     {
   12527       if (GET_CODE (x) == CONST
   12528           && GET_CODE (XEXP (x, 0)) == PLUS
   12529           && GET_MODE (XEXP (x, 0)) == Pmode
   12530           && CONST_INT_P (XEXP (XEXP (x, 0), 1))
   12531           && GET_CODE (XEXP (XEXP (x, 0), 0)) == UNSPEC
   12532           && XINT (XEXP (XEXP (x, 0), 0), 1) == UNSPEC_PCREL)
   12533         {
   12534 	  /* find_base_{value,term} only care about MEMs with arg_pointer_rtx
   12535 	     base.  A CONST can't be arg_pointer_rtx based.  */
   12536 	  if (base_term_p && MEM_P (orig_x))
   12537 	    return orig_x;
   12538 	  rtx x2 = XVECEXP (XEXP (XEXP (x, 0), 0), 0, 0);
   12539 	  x = gen_rtx_PLUS (Pmode, XEXP (XEXP (x, 0), 1), x2);
   12540 	  if (MEM_P (orig_x))
   12541 	    x = replace_equiv_address_nv (orig_x, x);
   12542 	  return x;
   12543 	}
   12544 
   12545       if (GET_CODE (x) == CONST
   12546 	  && GET_CODE (XEXP (x, 0)) == UNSPEC
   12547 	  && (XINT (XEXP (x, 0), 1) == UNSPEC_GOTPCREL
   12548 	      || XINT (XEXP (x, 0), 1) == UNSPEC_PCREL)
   12549 	  && (MEM_P (orig_x) || XINT (XEXP (x, 0), 1) == UNSPEC_PCREL))
   12550 	{
   12551 	  x = XVECEXP (XEXP (x, 0), 0, 0);
   12552 	  if (GET_MODE (orig_x) != GET_MODE (x) && MEM_P (orig_x))
   12553 	    {
   12554 	      x = lowpart_subreg (GET_MODE (orig_x), x, GET_MODE (x));
   12555 	      if (x == NULL_RTX)
   12556 		return orig_x;
   12557 	    }
   12558 	  return x;
   12559 	}
   12560 
   12561       if (ix86_cmodel != CM_MEDIUM_PIC && ix86_cmodel != CM_LARGE_PIC)
   12562 	return ix86_delegitimize_tls_address (orig_x);
   12563 
   12564       /* Fall thru into the code shared with -m32 for -mcmodel=large -fpic
   12565 	 and -mcmodel=medium -fpic.  */
   12566     }
   12567 
   12568   if (GET_CODE (x) != PLUS
   12569       || GET_CODE (XEXP (x, 1)) != CONST)
   12570     return ix86_delegitimize_tls_address (orig_x);
   12571 
   12572   if (ix86_pic_register_p (XEXP (x, 0)))
   12573     /* %ebx + GOT/GOTOFF */
   12574     ;
   12575   else if (GET_CODE (XEXP (x, 0)) == PLUS)
   12576     {
   12577       /* %ebx + %reg * scale + GOT/GOTOFF */
   12578       reg_addend = XEXP (x, 0);
   12579       if (ix86_pic_register_p (XEXP (reg_addend, 0)))
   12580 	reg_addend = XEXP (reg_addend, 1);
   12581       else if (ix86_pic_register_p (XEXP (reg_addend, 1)))
   12582 	reg_addend = XEXP (reg_addend, 0);
   12583       else
   12584 	{
   12585 	  reg_addend = NULL_RTX;
   12586 	  addend = XEXP (x, 0);
   12587 	}
   12588     }
   12589   else
   12590     addend = XEXP (x, 0);
   12591 
   12592   x = XEXP (XEXP (x, 1), 0);
   12593   if (GET_CODE (x) == PLUS
   12594       && CONST_INT_P (XEXP (x, 1)))
   12595     {
   12596       const_addend = XEXP (x, 1);
   12597       x = XEXP (x, 0);
   12598     }
   12599 
   12600   if (GET_CODE (x) == UNSPEC
   12601       && ((XINT (x, 1) == UNSPEC_GOT && MEM_P (orig_x) && !addend)
   12602 	  || (XINT (x, 1) == UNSPEC_GOTOFF && !MEM_P (orig_x))
   12603 	  || (XINT (x, 1) == UNSPEC_PLTOFF && ix86_cmodel == CM_LARGE_PIC
   12604 	      && !MEM_P (orig_x) && !addend)))
   12605     result = XVECEXP (x, 0, 0);
   12606 
   12607   if (!TARGET_64BIT && TARGET_MACHO && darwin_local_data_pic (x)
   12608       && !MEM_P (orig_x))
   12609     result = XVECEXP (x, 0, 0);
   12610 
   12611   if (! result)
   12612     return ix86_delegitimize_tls_address (orig_x);
   12613 
   12614   /* For (PLUS something CONST_INT) both find_base_{value,term} just
   12615      recurse on the first operand.  */
   12616   if (const_addend && !base_term_p)
   12617     result = gen_rtx_CONST (Pmode, gen_rtx_PLUS (Pmode, result, const_addend));
   12618   if (reg_addend)
   12619     result = gen_rtx_PLUS (Pmode, reg_addend, result);
   12620   if (addend)
   12621     {
   12622       /* If the rest of original X doesn't involve the PIC register, add
   12623 	 addend and subtract pic_offset_table_rtx.  This can happen e.g.
   12624 	 for code like:
   12625 	 leal (%ebx, %ecx, 4), %ecx
   12626 	 ...
   12627 	 movl foo@GOTOFF(%ecx), %edx
   12628 	 in which case we return (%ecx - %ebx) + foo
   12629 	 or (%ecx - _GLOBAL_OFFSET_TABLE_) + foo if pseudo_pic_reg
   12630 	 and reload has completed.  Don't do the latter for debug,
   12631 	 as _GLOBAL_OFFSET_TABLE_ can't be expressed in the assembly.  */
   12632       if (pic_offset_table_rtx
   12633 	  && (!reload_completed || !ix86_use_pseudo_pic_reg ()))
   12634         result = gen_rtx_PLUS (Pmode, gen_rtx_MINUS (Pmode, copy_rtx (addend),
   12635 						     pic_offset_table_rtx),
   12636 			       result);
   12637       else if (base_term_p
   12638 	       && pic_offset_table_rtx
   12639 	       && !TARGET_MACHO
   12640 	       && !TARGET_VXWORKS_RTP)
   12641 	{
   12642 	  rtx tmp = gen_rtx_SYMBOL_REF (Pmode, GOT_SYMBOL_NAME);
   12643 	  tmp = gen_rtx_MINUS (Pmode, copy_rtx (addend), tmp);
   12644 	  result = gen_rtx_PLUS (Pmode, tmp, result);
   12645 	}
   12646       else
   12647 	return orig_x;
   12648     }
   12649   if (GET_MODE (orig_x) != Pmode && MEM_P (orig_x))
   12650     {
   12651       result = lowpart_subreg (GET_MODE (orig_x), result, Pmode);
   12652       if (result == NULL_RTX)
   12653 	return orig_x;
   12654     }
   12655   return result;
   12656 }
   12657 
   12658 /* The normal instantiation of the above template.  */
   12659 
   12660 static rtx
   12661 ix86_delegitimize_address (rtx x)
   12662 {
   12663   return ix86_delegitimize_address_1 (x, false);
   12664 }
   12665 
   12666 /* If X is a machine specific address (i.e. a symbol or label being
   12667    referenced as a displacement from the GOT implemented using an
   12668    UNSPEC), then return the base term.  Otherwise return X.  */
   12669 
   12670 rtx
   12671 ix86_find_base_term (rtx x)
   12672 {
   12673   rtx term;
   12674 
   12675   if (TARGET_64BIT)
   12676     {
   12677       if (GET_CODE (x) != CONST)
   12678 	return x;
   12679       term = XEXP (x, 0);
   12680       if (GET_CODE (term) == PLUS
   12681 	  && CONST_INT_P (XEXP (term, 1)))
   12682 	term = XEXP (term, 0);
   12683       if (GET_CODE (term) != UNSPEC
   12684 	  || (XINT (term, 1) != UNSPEC_GOTPCREL
   12685 	      && XINT (term, 1) != UNSPEC_PCREL))
   12686 	return x;
   12687 
   12688       return XVECEXP (term, 0, 0);
   12689     }
   12690 
   12691   return ix86_delegitimize_address_1 (x, true);
   12692 }
   12693 
   12694 /* Return true if X shouldn't be emitted into the debug info.
   12695    Disallow UNSPECs other than @gotoff - we can't emit _GLOBAL_OFFSET_TABLE_
   12696    symbol easily into the .debug_info section, so we need not to
   12697    delegitimize, but instead assemble as @gotoff.
   12698    Disallow _GLOBAL_OFFSET_TABLE_ SYMBOL_REF - the assembler magically
   12699    assembles that as _GLOBAL_OFFSET_TABLE_-. expression.  */
   12700 
   12701 static bool
   12702 ix86_const_not_ok_for_debug_p (rtx x)
   12703 {
   12704   if (GET_CODE (x) == UNSPEC && XINT (x, 1) != UNSPEC_GOTOFF)
   12705     return true;
   12706 
   12707   if (SYMBOL_REF_P (x) && strcmp (XSTR (x, 0), GOT_SYMBOL_NAME) == 0)
   12708     return true;
   12709 
   12710   return false;
   12711 }
   12712 
   12713 static void
   12715 put_condition_code (enum rtx_code code, machine_mode mode, bool reverse,
   12716 		    bool fp, FILE *file)
   12717 {
   12718   const char *suffix;
   12719 
   12720   if (mode == CCFPmode)
   12721     {
   12722       code = ix86_fp_compare_code_to_integer (code);
   12723       mode = CCmode;
   12724     }
   12725   if (reverse)
   12726     code = reverse_condition (code);
   12727 
   12728   switch (code)
   12729     {
   12730     case EQ:
   12731       gcc_assert (mode != CCGZmode);
   12732       switch (mode)
   12733 	{
   12734 	case E_CCAmode:
   12735 	  suffix = "a";
   12736 	  break;
   12737 	case E_CCCmode:
   12738 	  suffix = "c";
   12739 	  break;
   12740 	case E_CCOmode:
   12741 	  suffix = "o";
   12742 	  break;
   12743 	case E_CCPmode:
   12744 	  suffix = "p";
   12745 	  break;
   12746 	case E_CCSmode:
   12747 	  suffix = "s";
   12748 	  break;
   12749 	default:
   12750 	  suffix = "e";
   12751 	  break;
   12752 	}
   12753       break;
   12754     case NE:
   12755       gcc_assert (mode != CCGZmode);
   12756       switch (mode)
   12757 	{
   12758 	case E_CCAmode:
   12759 	  suffix = "na";
   12760 	  break;
   12761 	case E_CCCmode:
   12762 	  suffix = "nc";
   12763 	  break;
   12764 	case E_CCOmode:
   12765 	  suffix = "no";
   12766 	  break;
   12767 	case E_CCPmode:
   12768 	  suffix = "np";
   12769 	  break;
   12770 	case E_CCSmode:
   12771 	  suffix = "ns";
   12772 	  break;
   12773 	default:
   12774 	  suffix = "ne";
   12775 	  break;
   12776 	}
   12777       break;
   12778     case GT:
   12779       gcc_assert (mode == CCmode || mode == CCNOmode || mode == CCGCmode);
   12780       suffix = "g";
   12781       break;
   12782     case GTU:
   12783       /* ??? Use "nbe" instead of "a" for fcmov lossage on some assemblers.
   12784 	 Those same assemblers have the same but opposite lossage on cmov.  */
   12785       if (mode == CCmode)
   12786 	suffix = fp ? "nbe" : "a";
   12787       else
   12788 	gcc_unreachable ();
   12789       break;
   12790     case LT:
   12791       switch (mode)
   12792 	{
   12793 	case E_CCNOmode:
   12794 	case E_CCGOCmode:
   12795 	  suffix = "s";
   12796 	  break;
   12797 
   12798 	case E_CCmode:
   12799 	case E_CCGCmode:
   12800 	case E_CCGZmode:
   12801 	  suffix = "l";
   12802 	  break;
   12803 
   12804 	default:
   12805 	  gcc_unreachable ();
   12806 	}
   12807       break;
   12808     case LTU:
   12809       if (mode == CCmode || mode == CCGZmode)
   12810 	suffix = "b";
   12811       else if (mode == CCCmode)
   12812 	suffix = fp ? "b" : "c";
   12813       else
   12814 	gcc_unreachable ();
   12815       break;
   12816     case GE:
   12817       switch (mode)
   12818 	{
   12819 	case E_CCNOmode:
   12820 	case E_CCGOCmode:
   12821 	  suffix = "ns";
   12822 	  break;
   12823 
   12824 	case E_CCmode:
   12825 	case E_CCGCmode:
   12826 	case E_CCGZmode:
   12827 	  suffix = "ge";
   12828 	  break;
   12829 
   12830 	default:
   12831 	  gcc_unreachable ();
   12832 	}
   12833       break;
   12834     case GEU:
   12835       if (mode == CCmode || mode == CCGZmode)
   12836 	suffix = "nb";
   12837       else if (mode == CCCmode)
   12838 	suffix = fp ? "nb" : "nc";
   12839       else
   12840 	gcc_unreachable ();
   12841       break;
   12842     case LE:
   12843       gcc_assert (mode == CCmode || mode == CCGCmode || mode == CCNOmode);
   12844       suffix = "le";
   12845       break;
   12846     case LEU:
   12847       if (mode == CCmode)
   12848 	suffix = "be";
   12849       else
   12850 	gcc_unreachable ();
   12851       break;
   12852     case UNORDERED:
   12853       suffix = fp ? "u" : "p";
   12854       break;
   12855     case ORDERED:
   12856       suffix = fp ? "nu" : "np";
   12857       break;
   12858     default:
   12859       gcc_unreachable ();
   12860     }
   12861   fputs (suffix, file);
   12862 }
   12863 
   12864 /* Print the name of register X to FILE based on its machine mode and number.
   12865    If CODE is 'w', pretend the mode is HImode.
   12866    If CODE is 'b', pretend the mode is QImode.
   12867    If CODE is 'k', pretend the mode is SImode.
   12868    If CODE is 'q', pretend the mode is DImode.
   12869    If CODE is 'x', pretend the mode is V4SFmode.
   12870    If CODE is 't', pretend the mode is V8SFmode.
   12871    If CODE is 'g', pretend the mode is V16SFmode.
   12872    If CODE is 'h', pretend the reg is the 'high' byte register.
   12873    If CODE is 'y', print "st(0)" instead of "st", if the reg is stack op.
   12874    If CODE is 'd', duplicate the operand for AVX instruction.
   12875    If CODE is 'V', print naked full integer register name without %.
   12876  */
   12877 
   12878 void
   12879 print_reg (rtx x, int code, FILE *file)
   12880 {
   12881   const char *reg;
   12882   int msize;
   12883   unsigned int regno;
   12884   bool duplicated;
   12885 
   12886   if (ASSEMBLER_DIALECT == ASM_ATT && code != 'V')
   12887     putc ('%', file);
   12888 
   12889   if (x == pc_rtx)
   12890     {
   12891       gcc_assert (TARGET_64BIT);
   12892       fputs ("rip", file);
   12893       return;
   12894     }
   12895 
   12896   if (code == 'y' && STACK_TOP_P (x))
   12897     {
   12898       fputs ("st(0)", file);
   12899       return;
   12900     }
   12901 
   12902   if (code == 'w')
   12903     msize = 2;
   12904   else if (code == 'b')
   12905     msize = 1;
   12906   else if (code == 'k')
   12907     msize = 4;
   12908   else if (code == 'q')
   12909     msize = 8;
   12910   else if (code == 'h')
   12911     msize = 0;
   12912   else if (code == 'x')
   12913     msize = 16;
   12914   else if (code == 't')
   12915     msize = 32;
   12916   else if (code == 'g')
   12917     msize = 64;
   12918   else
   12919     msize = GET_MODE_SIZE (GET_MODE (x));
   12920 
   12921   regno = REGNO (x);
   12922 
   12923   if (regno == ARG_POINTER_REGNUM
   12924       || regno == FRAME_POINTER_REGNUM
   12925       || regno == FPSR_REG)
   12926     {
   12927       output_operand_lossage
   12928 	("invalid use of register '%s'", reg_names[regno]);
   12929       return;
   12930     }
   12931   else if (regno == FLAGS_REG)
   12932     {
   12933       output_operand_lossage ("invalid use of asm flag output");
   12934       return;
   12935     }
   12936 
   12937   if (code == 'V')
   12938     {
   12939       if (GENERAL_REGNO_P (regno))
   12940 	msize = GET_MODE_SIZE (word_mode);
   12941       else
   12942 	error ("%<V%> modifier on non-integer register");
   12943     }
   12944 
   12945   duplicated = code == 'd' && TARGET_AVX;
   12946 
   12947   switch (msize)
   12948     {
   12949     case 16:
   12950     case 12:
   12951     case 8:
   12952       if (GENERAL_REGNO_P (regno) && msize > GET_MODE_SIZE (word_mode))
   12953 	warning (0, "unsupported size for integer register");
   12954       /* FALLTHRU */
   12955     case 4:
   12956       if (LEGACY_INT_REGNO_P (regno))
   12957 	putc (msize > 4 && TARGET_64BIT ? 'r' : 'e', file);
   12958       /* FALLTHRU */
   12959     case 2:
   12960     normal:
   12961       reg = hi_reg_name[regno];
   12962       break;
   12963     case 1:
   12964       if (regno >= ARRAY_SIZE (qi_reg_name))
   12965 	goto normal;
   12966       if (!ANY_QI_REGNO_P (regno))
   12967 	error ("unsupported size for integer register");
   12968       reg = qi_reg_name[regno];
   12969       break;
   12970     case 0:
   12971       if (regno >= ARRAY_SIZE (qi_high_reg_name))
   12972 	goto normal;
   12973       reg = qi_high_reg_name[regno];
   12974       break;
   12975     case 32:
   12976     case 64:
   12977       if (SSE_REGNO_P (regno))
   12978 	{
   12979 	  gcc_assert (!duplicated);
   12980 	  putc (msize == 32 ? 'y' : 'z', file);
   12981 	  reg = hi_reg_name[regno] + 1;
   12982 	  break;
   12983 	}
   12984       goto normal;
   12985     default:
   12986       gcc_unreachable ();
   12987     }
   12988 
   12989   fputs (reg, file);
   12990 
   12991   /* Irritatingly, AMD extended registers use
   12992      different naming convention: "r%d[bwd]"  */
   12993   if (REX_INT_REGNO_P (regno))
   12994     {
   12995       gcc_assert (TARGET_64BIT);
   12996       switch (msize)
   12997 	{
   12998 	  case 0:
   12999 	    error ("extended registers have no high halves");
   13000 	    break;
   13001 	  case 1:
   13002 	    putc ('b', file);
   13003 	    break;
   13004 	  case 2:
   13005 	    putc ('w', file);
   13006 	    break;
   13007 	  case 4:
   13008 	    putc ('d', file);
   13009 	    break;
   13010 	  case 8:
   13011 	    /* no suffix */
   13012 	    break;
   13013 	  default:
   13014 	    error ("unsupported operand size for extended register");
   13015 	    break;
   13016 	}
   13017       return;
   13018     }
   13019 
   13020   if (duplicated)
   13021     {
   13022       if (ASSEMBLER_DIALECT == ASM_ATT)
   13023 	fprintf (file, ", %%%s", reg);
   13024       else
   13025 	fprintf (file, ", %s", reg);
   13026     }
   13027 }
   13028 
   13029 /* Meaning of CODE:
   13030    L,W,B,Q,S,T -- print the opcode suffix for specified size of operand.
   13031    C -- print opcode suffix for set/cmov insn.
   13032    c -- like C, but print reversed condition
   13033    F,f -- likewise, but for floating-point.
   13034    O -- if HAVE_AS_IX86_CMOV_SUN_SYNTAX, expand to "w.", "l." or "q.",
   13035 	otherwise nothing
   13036    R -- print embedded rounding and sae.
   13037    r -- print only sae.
   13038    z -- print the opcode suffix for the size of the current operand.
   13039    Z -- likewise, with special suffixes for x87 instructions.
   13040    * -- print a star (in certain assembler syntax)
   13041    A -- print an absolute memory reference.
   13042    E -- print address with DImode register names if TARGET_64BIT.
   13043    w -- print the operand as if it's a "word" (HImode) even if it isn't.
   13044    s -- print a shift double count, followed by the assemblers argument
   13045 	delimiter.
   13046    b -- print the QImode name of the register for the indicated operand.
   13047 	%b0 would print %al if operands[0] is reg 0.
   13048    w --  likewise, print the HImode name of the register.
   13049    k --  likewise, print the SImode name of the register.
   13050    q --  likewise, print the DImode name of the register.
   13051    x --  likewise, print the V4SFmode name of the register.
   13052    t --  likewise, print the V8SFmode name of the register.
   13053    g --  likewise, print the V16SFmode name of the register.
   13054    h -- print the QImode name for a "high" register, either ah, bh, ch or dh.
   13055    y -- print "st(0)" instead of "st" as a register.
   13056    d -- print duplicated register operand for AVX instruction.
   13057    D -- print condition for SSE cmp instruction.
   13058    P -- if PIC, print an @PLT suffix.  For -fno-plt, load function
   13059 	address from GOT.
   13060    p -- print raw symbol name.
   13061    X -- don't print any sort of PIC '@' suffix for a symbol.
   13062    & -- print some in-use local-dynamic symbol name.
   13063    H -- print a memory address offset by 8; used for sse high-parts
   13064    Y -- print condition for XOP pcom* instruction.
   13065    V -- print naked full integer register name without %.
   13066    + -- print a branch hint as 'cs' or 'ds' prefix
   13067    ; -- print a semicolon (after prefixes due to bug in older gas).
   13068    ~ -- print "i" if TARGET_AVX2, "f" otherwise.
   13069    ^ -- print addr32 prefix if TARGET_64BIT and Pmode != word_mode
   13070    M -- print addr32 prefix for TARGET_X32 with VSIB address.
   13071    ! -- print NOTRACK prefix for jxx/call/ret instructions if required.
   13072    N -- print maskz if it's constant 0 operand.
   13073  */
   13074 
   13075 void
   13076 ix86_print_operand (FILE *file, rtx x, int code)
   13077 {
   13078   if (code)
   13079     {
   13080       switch (code)
   13081 	{
   13082 	case 'A':
   13083 	  switch (ASSEMBLER_DIALECT)
   13084 	    {
   13085 	    case ASM_ATT:
   13086 	      putc ('*', file);
   13087 	      break;
   13088 
   13089 	    case ASM_INTEL:
   13090 	      /* Intel syntax. For absolute addresses, registers should not
   13091 		 be surrounded by braces.  */
   13092 	      if (!REG_P (x))
   13093 		{
   13094 		  putc ('[', file);
   13095 		  ix86_print_operand (file, x, 0);
   13096 		  putc (']', file);
   13097 		  return;
   13098 		}
   13099 	      break;
   13100 
   13101 	    default:
   13102 	      gcc_unreachable ();
   13103 	    }
   13104 
   13105 	  ix86_print_operand (file, x, 0);
   13106 	  return;
   13107 
   13108 	case 'E':
   13109 	  /* Wrap address in an UNSPEC to declare special handling.  */
   13110 	  if (TARGET_64BIT)
   13111 	    x = gen_rtx_UNSPEC (DImode, gen_rtvec (1, x), UNSPEC_LEA_ADDR);
   13112 
   13113 	  output_address (VOIDmode, x);
   13114 	  return;
   13115 
   13116 	case 'L':
   13117 	  if (ASSEMBLER_DIALECT == ASM_ATT)
   13118 	    putc ('l', file);
   13119 	  return;
   13120 
   13121 	case 'W':
   13122 	  if (ASSEMBLER_DIALECT == ASM_ATT)
   13123 	    putc ('w', file);
   13124 	  return;
   13125 
   13126 	case 'B':
   13127 	  if (ASSEMBLER_DIALECT == ASM_ATT)
   13128 	    putc ('b', file);
   13129 	  return;
   13130 
   13131 	case 'Q':
   13132 	  if (ASSEMBLER_DIALECT == ASM_ATT)
   13133 	    putc ('l', file);
   13134 	  return;
   13135 
   13136 	case 'S':
   13137 	  if (ASSEMBLER_DIALECT == ASM_ATT)
   13138 	    putc ('s', file);
   13139 	  return;
   13140 
   13141 	case 'T':
   13142 	  if (ASSEMBLER_DIALECT == ASM_ATT)
   13143 	    putc ('t', file);
   13144 	  return;
   13145 
   13146 	case 'O':
   13147 #ifdef HAVE_AS_IX86_CMOV_SUN_SYNTAX
   13148 	  if (ASSEMBLER_DIALECT != ASM_ATT)
   13149 	    return;
   13150 
   13151 	  switch (GET_MODE_SIZE (GET_MODE (x)))
   13152 	    {
   13153 	    case 2:
   13154 	      putc ('w', file);
   13155 	      break;
   13156 
   13157 	    case 4:
   13158 	      putc ('l', file);
   13159 	      break;
   13160 
   13161 	    case 8:
   13162 	      putc ('q', file);
   13163 	      break;
   13164 
   13165 	    default:
   13166 	      output_operand_lossage ("invalid operand size for operand "
   13167 				      "code 'O'");
   13168 	      return;
   13169 	    }
   13170 
   13171 	  putc ('.', file);
   13172 #endif
   13173 	  return;
   13174 
   13175 	case 'z':
   13176 	  if (GET_MODE_CLASS (GET_MODE (x)) == MODE_INT)
   13177 	    {
   13178 	      /* Opcodes don't get size suffixes if using Intel opcodes.  */
   13179 	      if (ASSEMBLER_DIALECT == ASM_INTEL)
   13180 		return;
   13181 
   13182 	      switch (GET_MODE_SIZE (GET_MODE (x)))
   13183 		{
   13184 		case 1:
   13185 		  putc ('b', file);
   13186 		  return;
   13187 
   13188 		case 2:
   13189 		  putc ('w', file);
   13190 		  return;
   13191 
   13192 		case 4:
   13193 		  putc ('l', file);
   13194 		  return;
   13195 
   13196 		case 8:
   13197 		  putc ('q', file);
   13198 		  return;
   13199 
   13200 		default:
   13201 		  output_operand_lossage ("invalid operand size for operand "
   13202 					  "code 'z'");
   13203 		  return;
   13204 		}
   13205 	    }
   13206 
   13207 	  if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
   13208 	    warning (0, "non-integer operand used with operand code %<z%>");
   13209 	  /* FALLTHRU */
   13210 
   13211 	case 'Z':
   13212 	  /* 387 opcodes don't get size suffixes if using Intel opcodes.  */
   13213 	  if (ASSEMBLER_DIALECT == ASM_INTEL)
   13214 	    return;
   13215 
   13216 	  if (GET_MODE_CLASS (GET_MODE (x)) == MODE_INT)
   13217 	    {
   13218 	      switch (GET_MODE_SIZE (GET_MODE (x)))
   13219 		{
   13220 		case 2:
   13221 #ifdef HAVE_AS_IX86_FILDS
   13222 		  putc ('s', file);
   13223 #endif
   13224 		  return;
   13225 
   13226 		case 4:
   13227 		  putc ('l', file);
   13228 		  return;
   13229 
   13230 		case 8:
   13231 #ifdef HAVE_AS_IX86_FILDQ
   13232 		  putc ('q', file);
   13233 #else
   13234 		  fputs ("ll", file);
   13235 #endif
   13236 		  return;
   13237 
   13238 		default:
   13239 		  break;
   13240 		}
   13241 	    }
   13242 	  else if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
   13243 	    {
   13244 	      /* 387 opcodes don't get size suffixes
   13245 		 if the operands are registers.  */
   13246 	      if (STACK_REG_P (x))
   13247 		return;
   13248 
   13249 	      switch (GET_MODE_SIZE (GET_MODE (x)))
   13250 		{
   13251 		case 4:
   13252 		  putc ('s', file);
   13253 		  return;
   13254 
   13255 		case 8:
   13256 		  putc ('l', file);
   13257 		  return;
   13258 
   13259 		case 12:
   13260 		case 16:
   13261 		  putc ('t', file);
   13262 		  return;
   13263 
   13264 		default:
   13265 		  break;
   13266 		}
   13267 	    }
   13268 	  else
   13269 	    {
   13270 	      output_operand_lossage ("invalid operand type used with "
   13271 				      "operand code 'Z'");
   13272 	      return;
   13273 	    }
   13274 
   13275 	  output_operand_lossage ("invalid operand size for operand code 'Z'");
   13276 	  return;
   13277 
   13278 	case 'd':
   13279 	case 'b':
   13280 	case 'w':
   13281 	case 'k':
   13282 	case 'q':
   13283 	case 'h':
   13284 	case 't':
   13285 	case 'g':
   13286 	case 'y':
   13287 	case 'x':
   13288 	case 'X':
   13289 	case 'P':
   13290 	case 'p':
   13291 	case 'V':
   13292 	  break;
   13293 
   13294 	case 's':
   13295 	  if (CONST_INT_P (x) || ! SHIFT_DOUBLE_OMITS_COUNT)
   13296 	    {
   13297 	      ix86_print_operand (file, x, 0);
   13298 	      fputs (", ", file);
   13299 	    }
   13300 	  return;
   13301 
   13302 	case 'Y':
   13303 	  switch (GET_CODE (x))
   13304 	    {
   13305 	    case NE:
   13306 	      fputs ("neq", file);
   13307 	      break;
   13308 	    case EQ:
   13309 	      fputs ("eq", file);
   13310 	      break;
   13311 	    case GE:
   13312 	    case GEU:
   13313 	      fputs (INTEGRAL_MODE_P (GET_MODE (x)) ? "ge" : "unlt", file);
   13314 	      break;
   13315 	    case GT:
   13316 	    case GTU:
   13317 	      fputs (INTEGRAL_MODE_P (GET_MODE (x)) ? "gt" : "unle", file);
   13318 	      break;
   13319 	    case LE:
   13320 	    case LEU:
   13321 	      fputs ("le", file);
   13322 	      break;
   13323 	    case LT:
   13324 	    case LTU:
   13325 	      fputs ("lt", file);
   13326 	      break;
   13327 	    case UNORDERED:
   13328 	      fputs ("unord", file);
   13329 	      break;
   13330 	    case ORDERED:
   13331 	      fputs ("ord", file);
   13332 	      break;
   13333 	    case UNEQ:
   13334 	      fputs ("ueq", file);
   13335 	      break;
   13336 	    case UNGE:
   13337 	      fputs ("nlt", file);
   13338 	      break;
   13339 	    case UNGT:
   13340 	      fputs ("nle", file);
   13341 	      break;
   13342 	    case UNLE:
   13343 	      fputs ("ule", file);
   13344 	      break;
   13345 	    case UNLT:
   13346 	      fputs ("ult", file);
   13347 	      break;
   13348 	    case LTGT:
   13349 	      fputs ("une", file);
   13350 	      break;
   13351 	    default:
   13352 	      output_operand_lossage ("operand is not a condition code, "
   13353 				      "invalid operand code 'Y'");
   13354 	      return;
   13355 	    }
   13356 	  return;
   13357 
   13358 	case 'D':
   13359 	  /* Little bit of braindamage here.  The SSE compare instructions
   13360 	     does use completely different names for the comparisons that the
   13361 	     fp conditional moves.  */
   13362 	  switch (GET_CODE (x))
   13363 	    {
   13364 	    case UNEQ:
   13365 	      if (TARGET_AVX)
   13366 		{
   13367 		  fputs ("eq_us", file);
   13368 		  break;
   13369 		}
   13370 	     /* FALLTHRU */
   13371 	    case EQ:
   13372 	      fputs ("eq", file);
   13373 	      break;
   13374 	    case UNLT:
   13375 	      if (TARGET_AVX)
   13376 		{
   13377 		  fputs ("nge", file);
   13378 		  break;
   13379 		}
   13380 	     /* FALLTHRU */
   13381 	    case LT:
   13382 	      fputs ("lt", file);
   13383 	      break;
   13384 	    case UNLE:
   13385 	      if (TARGET_AVX)
   13386 		{
   13387 		  fputs ("ngt", file);
   13388 		  break;
   13389 		}
   13390 	     /* FALLTHRU */
   13391 	    case LE:
   13392 	      fputs ("le", file);
   13393 	      break;
   13394 	    case UNORDERED:
   13395 	      fputs ("unord", file);
   13396 	      break;
   13397 	    case LTGT:
   13398 	      if (TARGET_AVX)
   13399 		{
   13400 		  fputs ("neq_oq", file);
   13401 		  break;
   13402 		}
   13403 	     /* FALLTHRU */
   13404 	    case NE:
   13405 	      fputs ("neq", file);
   13406 	      break;
   13407 	    case GE:
   13408 	      if (TARGET_AVX)
   13409 		{
   13410 		  fputs ("ge", file);
   13411 		  break;
   13412 		}
   13413 	     /* FALLTHRU */
   13414 	    case UNGE:
   13415 	      fputs ("nlt", file);
   13416 	      break;
   13417 	    case GT:
   13418 	      if (TARGET_AVX)
   13419 		{
   13420 		  fputs ("gt", file);
   13421 		  break;
   13422 		}
   13423 	     /* FALLTHRU */
   13424 	    case UNGT:
   13425 	      fputs ("nle", file);
   13426 	      break;
   13427 	    case ORDERED:
   13428 	      fputs ("ord", file);
   13429 	      break;
   13430 	    default:
   13431 	      output_operand_lossage ("operand is not a condition code, "
   13432 				      "invalid operand code 'D'");
   13433 	      return;
   13434 	    }
   13435 	  return;
   13436 
   13437 	case 'F':
   13438 	case 'f':
   13439 #ifdef HAVE_AS_IX86_CMOV_SUN_SYNTAX
   13440 	  if (ASSEMBLER_DIALECT == ASM_ATT)
   13441 	    putc ('.', file);
   13442 	  gcc_fallthrough ();
   13443 #endif
   13444 
   13445 	case 'C':
   13446 	case 'c':
   13447 	  if (!COMPARISON_P (x))
   13448 	    {
   13449 	      output_operand_lossage ("operand is not a condition code, "
   13450 				      "invalid operand code '%c'", code);
   13451 	      return;
   13452 	    }
   13453 	  put_condition_code (GET_CODE (x), GET_MODE (XEXP (x, 0)),
   13454 			      code == 'c' || code == 'f',
   13455 			      code == 'F' || code == 'f',
   13456 			      file);
   13457 	  return;
   13458 
   13459 	case 'H':
   13460 	  if (!offsettable_memref_p (x))
   13461 	    {
   13462 	      output_operand_lossage ("operand is not an offsettable memory "
   13463 				      "reference, invalid operand code 'H'");
   13464 	      return;
   13465 	    }
   13466 	  /* It doesn't actually matter what mode we use here, as we're
   13467 	     only going to use this for printing.  */
   13468 	  x = adjust_address_nv (x, DImode, 8);
   13469 	  /* Output 'qword ptr' for intel assembler dialect.  */
   13470 	  if (ASSEMBLER_DIALECT == ASM_INTEL)
   13471 	    code = 'q';
   13472 	  break;
   13473 
   13474 	case 'K':
   13475 	  if (!CONST_INT_P (x))
   13476 	    {
   13477 	      output_operand_lossage ("operand is not an integer, invalid "
   13478 				      "operand code 'K'");
   13479 	      return;
   13480 	    }
   13481 
   13482 	  if (INTVAL (x) & IX86_HLE_ACQUIRE)
   13483 #ifdef HAVE_AS_IX86_HLE
   13484 	    fputs ("xacquire ", file);
   13485 #else
   13486 	    fputs ("\n" ASM_BYTE "0xf2\n\t", file);
   13487 #endif
   13488 	  else if (INTVAL (x) & IX86_HLE_RELEASE)
   13489 #ifdef HAVE_AS_IX86_HLE
   13490 	    fputs ("xrelease ", file);
   13491 #else
   13492 	    fputs ("\n" ASM_BYTE "0xf3\n\t", file);
   13493 #endif
   13494 	  /* We do not want to print value of the operand.  */
   13495 	  return;
   13496 
   13497 	case 'N':
   13498 	  if (x == const0_rtx || x == CONST0_RTX (GET_MODE (x)))
   13499 	    fputs ("{z}", file);
   13500 	  return;
   13501 
   13502 	case 'r':
   13503 	  if (!CONST_INT_P (x) || INTVAL (x) != ROUND_SAE)
   13504 	    {
   13505 	      output_operand_lossage ("operand is not a specific integer, "
   13506 				      "invalid operand code 'r'");
   13507 	      return;
   13508 	    }
   13509 
   13510 	  if (ASSEMBLER_DIALECT == ASM_INTEL)
   13511 	    fputs (", ", file);
   13512 
   13513 	  fputs ("{sae}", file);
   13514 
   13515 	  if (ASSEMBLER_DIALECT == ASM_ATT)
   13516 	    fputs (", ", file);
   13517 
   13518 	  return;
   13519 
   13520 	case 'R':
   13521 	  if (!CONST_INT_P (x))
   13522 	    {
   13523 	      output_operand_lossage ("operand is not an integer, invalid "
   13524 				      "operand code 'R'");
   13525 	      return;
   13526 	    }
   13527 
   13528 	  if (ASSEMBLER_DIALECT == ASM_INTEL)
   13529 	    fputs (", ", file);
   13530 
   13531 	  switch (INTVAL (x))
   13532 	    {
   13533 	    case ROUND_NEAREST_INT | ROUND_SAE:
   13534 	      fputs ("{rn-sae}", file);
   13535 	      break;
   13536 	    case ROUND_NEG_INF | ROUND_SAE:
   13537 	      fputs ("{rd-sae}", file);
   13538 	      break;
   13539 	    case ROUND_POS_INF | ROUND_SAE:
   13540 	      fputs ("{ru-sae}", file);
   13541 	      break;
   13542 	    case ROUND_ZERO | ROUND_SAE:
   13543 	      fputs ("{rz-sae}", file);
   13544 	      break;
   13545 	    default:
   13546 	      output_operand_lossage ("operand is not a specific integer, "
   13547 				      "invalid operand code 'R'");
   13548 	    }
   13549 
   13550 	  if (ASSEMBLER_DIALECT == ASM_ATT)
   13551 	    fputs (", ", file);
   13552 
   13553 	  return;
   13554 
   13555 	case '*':
   13556 	  if (ASSEMBLER_DIALECT == ASM_ATT)
   13557 	    putc ('*', file);
   13558 	  return;
   13559 
   13560 	case '&':
   13561 	  {
   13562 	    const char *name = get_some_local_dynamic_name ();
   13563 	    if (name == NULL)
   13564 	      output_operand_lossage ("'%%&' used without any "
   13565 				      "local dynamic TLS references");
   13566 	    else
   13567 	      assemble_name (file, name);
   13568 	    return;
   13569 	  }
   13570 
   13571 	case '+':
   13572 	  {
   13573 	    rtx x;
   13574 
   13575 	    if (!optimize
   13576 	        || optimize_function_for_size_p (cfun)
   13577 		|| !TARGET_BRANCH_PREDICTION_HINTS)
   13578 	      return;
   13579 
   13580 	    x = find_reg_note (current_output_insn, REG_BR_PROB, 0);
   13581 	    if (x)
   13582 	      {
   13583 		int pred_val = profile_probability::from_reg_br_prob_note
   13584 				 (XINT (x, 0)).to_reg_br_prob_base ();
   13585 
   13586 		if (pred_val < REG_BR_PROB_BASE * 45 / 100
   13587 		    || pred_val > REG_BR_PROB_BASE * 55 / 100)
   13588 		  {
   13589 		    bool taken = pred_val > REG_BR_PROB_BASE / 2;
   13590 		    bool cputaken
   13591 		      = final_forward_branch_p (current_output_insn) == 0;
   13592 
   13593 		    /* Emit hints only in the case default branch prediction
   13594 		       heuristics would fail.  */
   13595 		    if (taken != cputaken)
   13596 		      {
   13597 			/* We use 3e (DS) prefix for taken branches and
   13598 			   2e (CS) prefix for not taken branches.  */
   13599 			if (taken)
   13600 			  fputs ("ds ; ", file);
   13601 			else
   13602 			  fputs ("cs ; ", file);
   13603 		      }
   13604 		  }
   13605 	      }
   13606 	    return;
   13607 	  }
   13608 
   13609 	case ';':
   13610 #ifndef HAVE_AS_IX86_REP_LOCK_PREFIX
   13611 	  putc (';', file);
   13612 #endif
   13613 	  return;
   13614 
   13615 	case '~':
   13616 	  putc (TARGET_AVX2 ? 'i' : 'f', file);
   13617 	  return;
   13618 
   13619 	case 'M':
   13620 	  if (TARGET_X32)
   13621 	    {
   13622 	      /* NB: 32-bit indices in VSIB address are sign-extended
   13623 		 to 64 bits. In x32, if 32-bit address 0xf7fa3010 is
   13624 		 sign-extended to 0xfffffffff7fa3010 which is invalid
   13625 		 address.  Add addr32 prefix if there is no base
   13626 		 register nor symbol.  */
   13627 	      bool ok;
   13628 	      struct ix86_address parts;
   13629 	      ok = ix86_decompose_address (x, &parts);
   13630 	      gcc_assert (ok && parts.index == NULL_RTX);
   13631 	      if (parts.base == NULL_RTX
   13632 		  && (parts.disp == NULL_RTX
   13633 		      || !symbolic_operand (parts.disp,
   13634 					    GET_MODE (parts.disp))))
   13635 		fputs ("addr32 ", file);
   13636 	    }
   13637 	  return;
   13638 
   13639 	case '^':
   13640 	  if (TARGET_64BIT && Pmode != word_mode)
   13641 	    fputs ("addr32 ", file);
   13642 	  return;
   13643 
   13644 	case '!':
   13645 	  if (ix86_notrack_prefixed_insn_p (current_output_insn))
   13646 	    fputs ("notrack ", file);
   13647 	  return;
   13648 
   13649 	default:
   13650 	  output_operand_lossage ("invalid operand code '%c'", code);
   13651 	}
   13652     }
   13653 
   13654   if (REG_P (x))
   13655     print_reg (x, code, file);
   13656 
   13657   else if (MEM_P (x))
   13658     {
   13659       rtx addr = XEXP (x, 0);
   13660 
   13661       /* No `byte ptr' prefix for call instructions ... */
   13662       if (ASSEMBLER_DIALECT == ASM_INTEL && code != 'X' && code != 'P')
   13663 	{
   13664 	  machine_mode mode = GET_MODE (x);
   13665 	  const char *size;
   13666 
   13667 	  /* Check for explicit size override codes.  */
   13668 	  if (code == 'b')
   13669 	    size = "BYTE";
   13670 	  else if (code == 'w')
   13671 	    size = "WORD";
   13672 	  else if (code == 'k')
   13673 	    size = "DWORD";
   13674 	  else if (code == 'q')
   13675 	    size = "QWORD";
   13676 	  else if (code == 'x')
   13677 	    size = "XMMWORD";
   13678 	  else if (code == 't')
   13679 	    size = "YMMWORD";
   13680 	  else if (code == 'g')
   13681 	    size = "ZMMWORD";
   13682 	  else if (mode == BLKmode)
   13683 	    /* ... or BLKmode operands, when not overridden.  */
   13684 	    size = NULL;
   13685 	  else
   13686 	    switch (GET_MODE_SIZE (mode))
   13687 	      {
   13688 	      case 1: size = "BYTE"; break;
   13689 	      case 2: size = "WORD"; break;
   13690 	      case 4: size = "DWORD"; break;
   13691 	      case 8: size = "QWORD"; break;
   13692 	      case 12: size = "TBYTE"; break;
   13693 	      case 16:
   13694 		if (mode == XFmode)
   13695 		  size = "TBYTE";
   13696 		else
   13697 		  size = "XMMWORD";
   13698 		break;
   13699 	      case 32: size = "YMMWORD"; break;
   13700 	      case 64: size = "ZMMWORD"; break;
   13701 	      default:
   13702 		gcc_unreachable ();
   13703 	      }
   13704 	  if (size)
   13705 	    {
   13706 	      fputs (size, file);
   13707 	      fputs (" PTR ", file);
   13708 	    }
   13709 	}
   13710 
   13711       if (this_is_asm_operands && ! address_operand (addr, VOIDmode))
   13712 	output_operand_lossage ("invalid constraints for operand");
   13713       else
   13714 	ix86_print_operand_address_as
   13715 	  (file, addr, MEM_ADDR_SPACE (x), code == 'p' || code == 'P');
   13716     }
   13717 
   13718   else if (CONST_DOUBLE_P (x) && GET_MODE (x) == HFmode)
   13719     {
   13720       long l = real_to_target (NULL, CONST_DOUBLE_REAL_VALUE (x),
   13721 			       REAL_MODE_FORMAT (HFmode));
   13722       if (ASSEMBLER_DIALECT == ASM_ATT)
   13723 	putc ('$', file);
   13724       fprintf (file, "0x%04x", (unsigned int) l);
   13725     }
   13726 
   13727   else if (CONST_DOUBLE_P (x) && GET_MODE (x) == SFmode)
   13728     {
   13729       long l;
   13730 
   13731       REAL_VALUE_TO_TARGET_SINGLE (*CONST_DOUBLE_REAL_VALUE (x), l);
   13732 
   13733       if (ASSEMBLER_DIALECT == ASM_ATT)
   13734 	putc ('$', file);
   13735       /* Sign extend 32bit SFmode immediate to 8 bytes.  */
   13736       if (code == 'q')
   13737 	fprintf (file, "0x%08" HOST_LONG_LONG_FORMAT "x",
   13738 		 (unsigned long long) (int) l);
   13739       else
   13740 	fprintf (file, "0x%08x", (unsigned int) l);
   13741     }
   13742 
   13743   else if (CONST_DOUBLE_P (x) && GET_MODE (x) == DFmode)
   13744     {
   13745       long l[2];
   13746 
   13747       REAL_VALUE_TO_TARGET_DOUBLE (*CONST_DOUBLE_REAL_VALUE (x), l);
   13748 
   13749       if (ASSEMBLER_DIALECT == ASM_ATT)
   13750 	putc ('$', file);
   13751       fprintf (file, "0x%lx%08lx", l[1] & 0xffffffff, l[0] & 0xffffffff);
   13752     }
   13753 
   13754   /* These float cases don't actually occur as immediate operands.  */
   13755   else if (CONST_DOUBLE_P (x) && GET_MODE (x) == XFmode)
   13756     {
   13757       char dstr[30];
   13758 
   13759       real_to_decimal (dstr, CONST_DOUBLE_REAL_VALUE (x), sizeof (dstr), 0, 1);
   13760       fputs (dstr, file);
   13761     }
   13762 
   13763   /* Print bcst_mem_operand.  */
   13764   else if (GET_CODE (x) == VEC_DUPLICATE)
   13765     {
   13766       machine_mode vmode = GET_MODE (x);
   13767       /* Must be bcst_memory_operand.  */
   13768       gcc_assert (bcst_mem_operand (x, vmode));
   13769 
   13770       rtx mem = XEXP (x,0);
   13771       ix86_print_operand (file, mem, 0);
   13772 
   13773       switch (vmode)
   13774 	{
   13775 	case E_V2DImode:
   13776 	case E_V2DFmode:
   13777 	  fputs ("{1to2}", file);
   13778 	  break;
   13779 	case E_V4SImode:
   13780 	case E_V4SFmode:
   13781 	case E_V4DImode:
   13782 	case E_V4DFmode:
   13783 	  fputs ("{1to4}", file);
   13784 	  break;
   13785 	case E_V8SImode:
   13786 	case E_V8SFmode:
   13787 	case E_V8DFmode:
   13788 	case E_V8DImode:
   13789 	case E_V8HFmode:
   13790 	  fputs ("{1to8}", file);
   13791 	  break;
   13792 	case E_V16SFmode:
   13793 	case E_V16SImode:
   13794 	case E_V16HFmode:
   13795 	  fputs ("{1to16}", file);
   13796 	  break;
   13797 	case E_V32HFmode:
   13798 	  fputs ("{1to32}", file);
   13799 	  break;
   13800 	default:
   13801 	  gcc_unreachable ();
   13802 	}
   13803     }
   13804 
   13805   else
   13806     {
   13807       /* We have patterns that allow zero sets of memory, for instance.
   13808 	 In 64-bit mode, we should probably support all 8-byte vectors,
   13809 	 since we can in fact encode that into an immediate.  */
   13810       if (GET_CODE (x) == CONST_VECTOR)
   13811 	{
   13812 	  if (x != CONST0_RTX (GET_MODE (x)))
   13813 	    output_operand_lossage ("invalid vector immediate");
   13814 	  x = const0_rtx;
   13815 	}
   13816 
   13817       if (code == 'P')
   13818 	{
   13819 	  if (ix86_force_load_from_GOT_p (x, true))
   13820 	    {
   13821 	      /* For inline assembly statement, load function address
   13822 		 from GOT with 'P' operand modifier to avoid PLT.  */
   13823 	      x = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, x),
   13824 				  (TARGET_64BIT
   13825 				   ? UNSPEC_GOTPCREL
   13826 				   : UNSPEC_GOT));
   13827 	      x = gen_rtx_CONST (Pmode, x);
   13828 	      x = gen_const_mem (Pmode, x);
   13829 	      ix86_print_operand (file, x, 'A');
   13830 	      return;
   13831 	    }
   13832 	}
   13833       else if (code != 'p')
   13834 	{
   13835 	  if (CONST_INT_P (x))
   13836 	    {
   13837 	      if (ASSEMBLER_DIALECT == ASM_ATT)
   13838 		putc ('$', file);
   13839 	    }
   13840 	  else if (GET_CODE (x) == CONST || GET_CODE (x) == SYMBOL_REF
   13841 		   || GET_CODE (x) == LABEL_REF)
   13842 	    {
   13843 	      if (ASSEMBLER_DIALECT == ASM_ATT)
   13844 		putc ('$', file);
   13845 	      else
   13846 		fputs ("OFFSET FLAT:", file);
   13847 	    }
   13848 	}
   13849       if (CONST_INT_P (x))
   13850 	fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
   13851       else if (flag_pic || MACHOPIC_INDIRECT)
   13852 	output_pic_addr_const (file, x, code);
   13853       else
   13854 	output_addr_const (file, x);
   13855     }
   13856 }
   13857 
   13858 static bool
   13859 ix86_print_operand_punct_valid_p (unsigned char code)
   13860 {
   13861   return (code == '*' || code == '+' || code == '&' || code == ';'
   13862 	  || code == '~' || code == '^' || code == '!');
   13863 }
   13864 
   13865 /* Print a memory operand whose address is ADDR.  */
   13867 
   13868 static void
   13869 ix86_print_operand_address_as (FILE *file, rtx addr,
   13870 			       addr_space_t as, bool raw)
   13871 {
   13872   struct ix86_address parts;
   13873   rtx base, index, disp;
   13874   int scale;
   13875   int ok;
   13876   bool vsib = false;
   13877   int code = 0;
   13878 
   13879   if (GET_CODE (addr) == UNSPEC && XINT (addr, 1) == UNSPEC_VSIBADDR)
   13880     {
   13881       ok = ix86_decompose_address (XVECEXP (addr, 0, 0), &parts);
   13882       gcc_assert (parts.index == NULL_RTX);
   13883       parts.index = XVECEXP (addr, 0, 1);
   13884       parts.scale = INTVAL (XVECEXP (addr, 0, 2));
   13885       addr = XVECEXP (addr, 0, 0);
   13886       vsib = true;
   13887     }
   13888   else if (GET_CODE (addr) == UNSPEC && XINT (addr, 1) == UNSPEC_LEA_ADDR)
   13889     {
   13890       gcc_assert (TARGET_64BIT);
   13891       ok = ix86_decompose_address (XVECEXP (addr, 0, 0), &parts);
   13892       code = 'q';
   13893     }
   13894   else
   13895     ok = ix86_decompose_address (addr, &parts);
   13896 
   13897   gcc_assert (ok);
   13898 
   13899   base = parts.base;
   13900   index = parts.index;
   13901   disp = parts.disp;
   13902   scale = parts.scale;
   13903 
   13904   if (ADDR_SPACE_GENERIC_P (as))
   13905     as = parts.seg;
   13906   else
   13907     gcc_assert (ADDR_SPACE_GENERIC_P (parts.seg));
   13908 
   13909   if (!ADDR_SPACE_GENERIC_P (as) && !raw)
   13910     {
   13911       if (ASSEMBLER_DIALECT == ASM_ATT)
   13912 	putc ('%', file);
   13913 
   13914       switch (as)
   13915 	{
   13916 	case ADDR_SPACE_SEG_FS:
   13917 	  fputs ("fs:", file);
   13918 	  break;
   13919 	case ADDR_SPACE_SEG_GS:
   13920 	  fputs ("gs:", file);
   13921 	  break;
   13922 	default:
   13923 	  gcc_unreachable ();
   13924 	}
   13925     }
   13926 
   13927   /* Use one byte shorter RIP relative addressing for 64bit mode.  */
   13928   if (TARGET_64BIT && !base && !index && !raw)
   13929     {
   13930       rtx symbol = disp;
   13931 
   13932       if (GET_CODE (disp) == CONST
   13933 	  && GET_CODE (XEXP (disp, 0)) == PLUS
   13934 	  && CONST_INT_P (XEXP (XEXP (disp, 0), 1)))
   13935 	symbol = XEXP (XEXP (disp, 0), 0);
   13936 
   13937       if (GET_CODE (symbol) == LABEL_REF
   13938 	  || (GET_CODE (symbol) == SYMBOL_REF
   13939 	      && SYMBOL_REF_TLS_MODEL (symbol) == 0))
   13940 	base = pc_rtx;
   13941     }
   13942 
   13943   if (!base && !index)
   13944     {
   13945       /* Displacement only requires special attention.  */
   13946       if (CONST_INT_P (disp))
   13947 	{
   13948 	  if (ASSEMBLER_DIALECT == ASM_INTEL && ADDR_SPACE_GENERIC_P (as))
   13949 	    fputs ("ds:", file);
   13950 	  fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (disp));
   13951 	}
   13952       /* Load the external function address via the GOT slot to avoid PLT.  */
   13953       else if (GET_CODE (disp) == CONST
   13954 	       && GET_CODE (XEXP (disp, 0)) == UNSPEC
   13955 	       && (XINT (XEXP (disp, 0), 1) == UNSPEC_GOTPCREL
   13956 		   || XINT (XEXP (disp, 0), 1) == UNSPEC_GOT)
   13957 	       && ix86_force_load_from_GOT_p (XVECEXP (XEXP (disp, 0), 0, 0)))
   13958 	output_pic_addr_const (file, disp, 0);
   13959       else if (flag_pic)
   13960 	output_pic_addr_const (file, disp, 0);
   13961       else
   13962 	output_addr_const (file, disp);
   13963     }
   13964   else
   13965     {
   13966       /* Print SImode register names to force addr32 prefix.  */
   13967       if (SImode_address_operand (addr, VOIDmode))
   13968 	{
   13969 	  if (flag_checking)
   13970 	    {
   13971 	      gcc_assert (TARGET_64BIT);
   13972 	      switch (GET_CODE (addr))
   13973 		{
   13974 		case SUBREG:
   13975 		  gcc_assert (GET_MODE (addr) == SImode);
   13976 		  gcc_assert (GET_MODE (SUBREG_REG (addr)) == DImode);
   13977 		  break;
   13978 		case ZERO_EXTEND:
   13979 		case AND:
   13980 		  gcc_assert (GET_MODE (addr) == DImode);
   13981 		  break;
   13982 		default:
   13983 		  gcc_unreachable ();
   13984 		}
   13985 	    }
   13986 	  gcc_assert (!code);
   13987 	  code = 'k';
   13988 	}
   13989       else if (code == 0
   13990 	       && TARGET_X32
   13991 	       && disp
   13992 	       && CONST_INT_P (disp)
   13993 	       && INTVAL (disp) < -16*1024*1024)
   13994 	{
   13995 	  /* X32 runs in 64-bit mode, where displacement, DISP, in
   13996 	     address DISP(%r64), is encoded as 32-bit immediate sign-
   13997 	     extended from 32-bit to 64-bit.  For -0x40000300(%r64),
   13998 	     address is %r64 + 0xffffffffbffffd00.  When %r64 <
   13999 	     0x40000300, like 0x37ffe064, address is 0xfffffffff7ffdd64,
   14000 	     which is invalid for x32.  The correct address is %r64
   14001 	     - 0x40000300 == 0xf7ffdd64.  To properly encode
   14002 	     -0x40000300(%r64) for x32, we zero-extend negative
   14003 	     displacement by forcing addr32 prefix which truncates
   14004 	     0xfffffffff7ffdd64 to 0xf7ffdd64.  In theory, we should
   14005 	     zero-extend all negative displacements, including -1(%rsp).
   14006 	     However, for small negative displacements, sign-extension
   14007 	     won't cause overflow.  We only zero-extend negative
   14008 	     displacements if they < -16*1024*1024, which is also used
   14009 	     to check legitimate address displacements for PIC.  */
   14010 	  code = 'k';
   14011 	}
   14012 
   14013       /* Since the upper 32 bits of RSP are always zero for x32,
   14014 	 we can encode %esp as %rsp to avoid 0x67 prefix if
   14015 	 there is no index register.  */
   14016       if (TARGET_X32 && Pmode == SImode
   14017 	  && !index && base && REG_P (base) && REGNO (base) == SP_REG)
   14018 	code = 'q';
   14019 
   14020       if (ASSEMBLER_DIALECT == ASM_ATT)
   14021 	{
   14022 	  if (disp)
   14023 	    {
   14024 	      if (flag_pic)
   14025 		output_pic_addr_const (file, disp, 0);
   14026 	      else if (GET_CODE (disp) == LABEL_REF)
   14027 		output_asm_label (disp);
   14028 	      else
   14029 		output_addr_const (file, disp);
   14030 	    }
   14031 
   14032 	  putc ('(', file);
   14033 	  if (base)
   14034 	    print_reg (base, code, file);
   14035 	  if (index)
   14036 	    {
   14037 	      putc (',', file);
   14038 	      print_reg (index, vsib ? 0 : code, file);
   14039 	      if (scale != 1 || vsib)
   14040 		fprintf (file, ",%d", scale);
   14041 	    }
   14042 	  putc (')', file);
   14043 	}
   14044       else
   14045 	{
   14046 	  rtx offset = NULL_RTX;
   14047 
   14048 	  if (disp)
   14049 	    {
   14050 	      /* Pull out the offset of a symbol; print any symbol itself.  */
   14051 	      if (GET_CODE (disp) == CONST
   14052 		  && GET_CODE (XEXP (disp, 0)) == PLUS
   14053 		  && CONST_INT_P (XEXP (XEXP (disp, 0), 1)))
   14054 		{
   14055 		  offset = XEXP (XEXP (disp, 0), 1);
   14056 		  disp = gen_rtx_CONST (VOIDmode,
   14057 					XEXP (XEXP (disp, 0), 0));
   14058 		}
   14059 
   14060 	      if (flag_pic)
   14061 		output_pic_addr_const (file, disp, 0);
   14062 	      else if (GET_CODE (disp) == LABEL_REF)
   14063 		output_asm_label (disp);
   14064 	      else if (CONST_INT_P (disp))
   14065 		offset = disp;
   14066 	      else
   14067 		output_addr_const (file, disp);
   14068 	    }
   14069 
   14070 	  putc ('[', file);
   14071 	  if (base)
   14072 	    {
   14073 	      print_reg (base, code, file);
   14074 	      if (offset)
   14075 		{
   14076 		  if (INTVAL (offset) >= 0)
   14077 		    putc ('+', file);
   14078 		  fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (offset));
   14079 		}
   14080 	    }
   14081 	  else if (offset)
   14082 	    fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (offset));
   14083 	  else
   14084 	    putc ('0', file);
   14085 
   14086 	  if (index)
   14087 	    {
   14088 	      putc ('+', file);
   14089 	      print_reg (index, vsib ? 0 : code, file);
   14090 	      if (scale != 1 || vsib)
   14091 		fprintf (file, "*%d", scale);
   14092 	    }
   14093 	  putc (']', file);
   14094 	}
   14095     }
   14096 }
   14097 
   14098 static void
   14099 ix86_print_operand_address (FILE *file, machine_mode /*mode*/, rtx addr)
   14100 {
   14101   if (this_is_asm_operands && ! address_operand (addr, VOIDmode))
   14102     output_operand_lossage ("invalid constraints for operand");
   14103   else
   14104     ix86_print_operand_address_as (file, addr, ADDR_SPACE_GENERIC, false);
   14105 }
   14106 
   14107 /* Implementation of TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA.  */
   14108 
   14109 static bool
   14110 i386_asm_output_addr_const_extra (FILE *file, rtx x)
   14111 {
   14112   rtx op;
   14113 
   14114   if (GET_CODE (x) != UNSPEC)
   14115     return false;
   14116 
   14117   op = XVECEXP (x, 0, 0);
   14118   switch (XINT (x, 1))
   14119     {
   14120     case UNSPEC_GOTOFF:
   14121       output_addr_const (file, op);
   14122       fputs ("@gotoff", file);
   14123       break;
   14124     case UNSPEC_GOTTPOFF:
   14125       output_addr_const (file, op);
   14126       /* FIXME: This might be @TPOFF in Sun ld.  */
   14127       fputs ("@gottpoff", file);
   14128       break;
   14129     case UNSPEC_TPOFF:
   14130       output_addr_const (file, op);
   14131       fputs ("@tpoff", file);
   14132       break;
   14133     case UNSPEC_NTPOFF:
   14134       output_addr_const (file, op);
   14135       if (TARGET_64BIT)
   14136 	fputs ("@tpoff", file);
   14137       else
   14138 	fputs ("@ntpoff", file);
   14139       break;
   14140     case UNSPEC_DTPOFF:
   14141       output_addr_const (file, op);
   14142       fputs ("@dtpoff", file);
   14143       break;
   14144     case UNSPEC_GOTNTPOFF:
   14145       output_addr_const (file, op);
   14146       if (TARGET_64BIT)
   14147 	fputs (ASSEMBLER_DIALECT == ASM_ATT ?
   14148 	       "@gottpoff(%rip)" : "@gottpoff[rip]", file);
   14149       else
   14150 	fputs ("@gotntpoff", file);
   14151       break;
   14152     case UNSPEC_INDNTPOFF:
   14153       output_addr_const (file, op);
   14154       fputs ("@indntpoff", file);
   14155       break;
   14156 #if TARGET_MACHO
   14157     case UNSPEC_MACHOPIC_OFFSET:
   14158       output_addr_const (file, op);
   14159       putc ('-', file);
   14160       machopic_output_function_base_name (file);
   14161       break;
   14162 #endif
   14163 
   14164     default:
   14165       return false;
   14166     }
   14167 
   14168   return true;
   14169 }
   14170 
   14171 
   14173 /* Output code to perform a 387 binary operation in INSN, one of PLUS,
   14175    MINUS, MULT or DIV.  OPERANDS are the insn operands, where operands[3]
   14176    is the expression of the binary operation.  The output may either be
   14177    emitted here, or returned to the caller, like all output_* functions.
   14178 
   14179    There is no guarantee that the operands are the same mode, as they
   14180    might be within FLOAT or FLOAT_EXTEND expressions.  */
   14181 
   14182 #ifndef SYSV386_COMPAT
   14183 /* Set to 1 for compatibility with brain-damaged assemblers.  No-one
   14184    wants to fix the assemblers because that causes incompatibility
   14185    with gcc.  No-one wants to fix gcc because that causes
   14186    incompatibility with assemblers...  You can use the option of
   14187    -DSYSV386_COMPAT=0 if you recompile both gcc and gas this way.  */
   14188 #define SYSV386_COMPAT 1
   14189 #endif
   14190 
   14191 const char *
   14192 output_387_binary_op (rtx_insn *insn, rtx *operands)
   14193 {
   14194   static char buf[40];
   14195   const char *p;
   14196   bool is_sse
   14197     = (SSE_REG_P (operands[0])
   14198        || SSE_REG_P (operands[1]) || SSE_REG_P (operands[2]));
   14199 
   14200   if (is_sse)
   14201     p = "%v";
   14202   else if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT
   14203 	   || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT)
   14204     p = "fi";
   14205   else
   14206     p = "f";
   14207 
   14208   strcpy (buf, p);
   14209 
   14210   switch (GET_CODE (operands[3]))
   14211     {
   14212     case PLUS:
   14213       p = "add"; break;
   14214     case MINUS:
   14215       p = "sub"; break;
   14216     case MULT:
   14217       p = "mul"; break;
   14218     case DIV:
   14219       p = "div"; break;
   14220     default:
   14221       gcc_unreachable ();
   14222     }
   14223 
   14224   strcat (buf, p);
   14225 
   14226   if (is_sse)
   14227    {
   14228      p = GET_MODE (operands[0]) == SFmode ? "ss" : "sd";
   14229      strcat (buf, p);
   14230 
   14231      if (TARGET_AVX)
   14232        p = "\t{%2, %1, %0|%0, %1, %2}";
   14233      else
   14234        p = "\t{%2, %0|%0, %2}";
   14235 
   14236      strcat (buf, p);
   14237      return buf;
   14238    }
   14239 
   14240   /* Even if we do not want to check the inputs, this documents input
   14241      constraints.  Which helps in understanding the following code.  */
   14242   if (flag_checking)
   14243     {
   14244       if (STACK_REG_P (operands[0])
   14245 	  && ((REG_P (operands[1])
   14246 	       && REGNO (operands[0]) == REGNO (operands[1])
   14247 	       && (STACK_REG_P (operands[2]) || MEM_P (operands[2])))
   14248 	      || (REG_P (operands[2])
   14249 		  && REGNO (operands[0]) == REGNO (operands[2])
   14250 		  && (STACK_REG_P (operands[1]) || MEM_P (operands[1]))))
   14251 	  && (STACK_TOP_P (operands[1]) || STACK_TOP_P (operands[2])))
   14252 	; /* ok */
   14253       else
   14254 	gcc_unreachable ();
   14255     }
   14256 
   14257   switch (GET_CODE (operands[3]))
   14258     {
   14259     case MULT:
   14260     case PLUS:
   14261       if (REG_P (operands[2]) && REGNO (operands[0]) == REGNO (operands[2]))
   14262 	std::swap (operands[1], operands[2]);
   14263 
   14264       /* know operands[0] == operands[1].  */
   14265 
   14266       if (MEM_P (operands[2]))
   14267 	{
   14268 	  p = "%Z2\t%2";
   14269 	  break;
   14270 	}
   14271 
   14272       if (find_regno_note (insn, REG_DEAD, REGNO (operands[2])))
   14273 	{
   14274 	  if (STACK_TOP_P (operands[0]))
   14275 	    /* How is it that we are storing to a dead operand[2]?
   14276 	       Well, presumably operands[1] is dead too.  We can't
   14277 	       store the result to st(0) as st(0) gets popped on this
   14278 	       instruction.  Instead store to operands[2] (which I
   14279 	       think has to be st(1)).  st(1) will be popped later.
   14280 	       gcc <= 2.8.1 didn't have this check and generated
   14281 	       assembly code that the Unixware assembler rejected.  */
   14282 	    p = "p\t{%0, %2|%2, %0}";	/* st(1) = st(0) op st(1); pop */
   14283 	  else
   14284 	    p = "p\t{%2, %0|%0, %2}";	/* st(r1) = st(r1) op st(0); pop */
   14285 	  break;
   14286 	}
   14287 
   14288       if (STACK_TOP_P (operands[0]))
   14289 	p = "\t{%y2, %0|%0, %y2}";	/* st(0) = st(0) op st(r2) */
   14290       else
   14291 	p = "\t{%2, %0|%0, %2}";	/* st(r1) = st(r1) op st(0) */
   14292       break;
   14293 
   14294     case MINUS:
   14295     case DIV:
   14296       if (MEM_P (operands[1]))
   14297 	{
   14298 	  p = "r%Z1\t%1";
   14299 	  break;
   14300 	}
   14301 
   14302       if (MEM_P (operands[2]))
   14303 	{
   14304 	  p = "%Z2\t%2";
   14305 	  break;
   14306 	}
   14307 
   14308       if (find_regno_note (insn, REG_DEAD, REGNO (operands[2])))
   14309 	{
   14310 #if SYSV386_COMPAT
   14311 	  /* The SystemV/386 SVR3.2 assembler, and probably all AT&T
   14312 	     derived assemblers, confusingly reverse the direction of
   14313 	     the operation for fsub{r} and fdiv{r} when the
   14314 	     destination register is not st(0).  The Intel assembler
   14315 	     doesn't have this brain damage.  Read !SYSV386_COMPAT to
   14316 	     figure out what the hardware really does.  */
   14317 	  if (STACK_TOP_P (operands[0]))
   14318 	    p = "{p\t%0, %2|rp\t%2, %0}";
   14319 	  else
   14320 	    p = "{rp\t%2, %0|p\t%0, %2}";
   14321 #else
   14322 	  if (STACK_TOP_P (operands[0]))
   14323 	    /* As above for fmul/fadd, we can't store to st(0).  */
   14324 	    p = "rp\t{%0, %2|%2, %0}";	/* st(1) = st(0) op st(1); pop */
   14325 	  else
   14326 	    p = "p\t{%2, %0|%0, %2}";	/* st(r1) = st(r1) op st(0); pop */
   14327 #endif
   14328 	  break;
   14329 	}
   14330 
   14331       if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
   14332 	{
   14333 #if SYSV386_COMPAT
   14334 	  if (STACK_TOP_P (operands[0]))
   14335 	    p = "{rp\t%0, %1|p\t%1, %0}";
   14336 	  else
   14337 	    p = "{p\t%1, %0|rp\t%0, %1}";
   14338 #else
   14339 	  if (STACK_TOP_P (operands[0]))
   14340 	    p = "p\t{%0, %1|%1, %0}";	/* st(1) = st(1) op st(0); pop */
   14341 	  else
   14342 	    p = "rp\t{%1, %0|%0, %1}";	/* st(r2) = st(0) op st(r2); pop */
   14343 #endif
   14344 	  break;
   14345 	}
   14346 
   14347       if (STACK_TOP_P (operands[0]))
   14348 	{
   14349 	  if (STACK_TOP_P (operands[1]))
   14350 	    p = "\t{%y2, %0|%0, %y2}";	/* st(0) = st(0) op st(r2) */
   14351 	  else
   14352 	    p = "r\t{%y1, %0|%0, %y1}";	/* st(0) = st(r1) op st(0) */
   14353 	  break;
   14354 	}
   14355       else if (STACK_TOP_P (operands[1]))
   14356 	{
   14357 #if SYSV386_COMPAT
   14358 	  p = "{\t%1, %0|r\t%0, %1}";
   14359 #else
   14360 	  p = "r\t{%1, %0|%0, %1}";	/* st(r2) = st(0) op st(r2) */
   14361 #endif
   14362 	}
   14363       else
   14364 	{
   14365 #if SYSV386_COMPAT
   14366 	  p = "{r\t%2, %0|\t%0, %2}";
   14367 #else
   14368 	  p = "\t{%2, %0|%0, %2}";	/* st(r1) = st(r1) op st(0) */
   14369 #endif
   14370 	}
   14371       break;
   14372 
   14373     default:
   14374       gcc_unreachable ();
   14375     }
   14376 
   14377   strcat (buf, p);
   14378   return buf;
   14379 }
   14380 
   14381 /* Return needed mode for entity in optimize_mode_switching pass.  */
   14382 
   14383 static int
   14384 ix86_dirflag_mode_needed (rtx_insn *insn)
   14385 {
   14386   if (CALL_P (insn))
   14387     {
   14388       if (cfun->machine->func_type == TYPE_NORMAL)
   14389 	return X86_DIRFLAG_ANY;
   14390       else
   14391 	/* No need to emit CLD in interrupt handler for TARGET_CLD.  */
   14392 	return TARGET_CLD ? X86_DIRFLAG_ANY : X86_DIRFLAG_RESET;
   14393     }
   14394 
   14395   if (recog_memoized (insn) < 0)
   14396     return X86_DIRFLAG_ANY;
   14397 
   14398   if (get_attr_type (insn) == TYPE_STR)
   14399     {
   14400       /* Emit cld instruction if stringops are used in the function.  */
   14401       if (cfun->machine->func_type == TYPE_NORMAL)
   14402 	return TARGET_CLD ? X86_DIRFLAG_RESET : X86_DIRFLAG_ANY;
   14403       else
   14404 	return X86_DIRFLAG_RESET;
   14405     }
   14406 
   14407   return X86_DIRFLAG_ANY;
   14408 }
   14409 
   14410 /* Check if a 256bit or 512 bit AVX register is referenced inside of EXP.   */
   14411 
   14412 static bool
   14413 ix86_check_avx_upper_register (const_rtx exp)
   14414 {
   14415   /* construct_container may return a parallel with expr_list
   14416      which contains the real reg and mode  */
   14417   subrtx_iterator::array_type array;
   14418   FOR_EACH_SUBRTX (iter, array, exp, NONCONST)
   14419     {
   14420       const_rtx x = *iter;
   14421       if (SSE_REG_P (x)
   14422 	  && !EXT_REX_SSE_REG_P (x)
   14423 	  && GET_MODE_BITSIZE (GET_MODE (x)) > 128)
   14424 	return true;
   14425     }
   14426 
   14427   return false;
   14428 }
   14429 
   14430 /* Check if a 256bit or 512bit AVX register is referenced in stores.   */
   14431 
   14432 static void
   14433 ix86_check_avx_upper_stores (rtx dest, const_rtx, void *data)
   14434 {
   14435   if (SSE_REG_P (dest)
   14436       && !EXT_REX_SSE_REG_P (dest)
   14437       && GET_MODE_BITSIZE (GET_MODE (dest)) > 128)
   14438     {
   14439       bool *used = (bool *) data;
   14440       *used = true;
   14441     }
   14442 }
   14443 
   14444 /* Return needed mode for entity in optimize_mode_switching pass.  */
   14445 
   14446 static int
   14447 ix86_avx_u128_mode_needed (rtx_insn *insn)
   14448 {
   14449   if (DEBUG_INSN_P (insn))
   14450     return AVX_U128_ANY;
   14451 
   14452   if (CALL_P (insn))
   14453     {
   14454       rtx link;
   14455 
   14456       /* Needed mode is set to AVX_U128_CLEAN if there are
   14457 	 no 256bit or 512bit modes used in function arguments. */
   14458       for (link = CALL_INSN_FUNCTION_USAGE (insn);
   14459 	   link;
   14460 	   link = XEXP (link, 1))
   14461 	{
   14462 	  if (GET_CODE (XEXP (link, 0)) == USE)
   14463 	    {
   14464 	      rtx arg = XEXP (XEXP (link, 0), 0);
   14465 
   14466 	      if (ix86_check_avx_upper_register (arg))
   14467 		return AVX_U128_DIRTY;
   14468 	    }
   14469 	}
   14470 
   14471       /* Needed mode is set to AVX_U128_CLEAN if there are no 256bit
   14472 	 nor 512bit registers used in the function return register.  */
   14473       bool avx_upper_reg_found = false;
   14474       note_stores (insn, ix86_check_avx_upper_stores,
   14475 		   &avx_upper_reg_found);
   14476       if (avx_upper_reg_found)
   14477 	return AVX_U128_DIRTY;
   14478 
   14479       /* If the function is known to preserve some SSE registers,
   14480 	 RA and previous passes can legitimately rely on that for
   14481 	 modes wider than 256 bits.  It's only safe to issue a
   14482 	 vzeroupper if all SSE registers are clobbered.  */
   14483       const function_abi &abi = insn_callee_abi (insn);
   14484       /* Should be safe to issue an vzeroupper before sibling_call_p.
   14485 	 Also there not mode_exit for sibling_call, so there could be
   14486 	 missing vzeroupper for that.  */
   14487       if (!(SIBLING_CALL_P (insn)
   14488 	    || hard_reg_set_subset_p (reg_class_contents[SSE_REGS],
   14489 				      abi.mode_clobbers (V4DImode))))
   14490 	return AVX_U128_ANY;
   14491 
   14492       return AVX_U128_CLEAN;
   14493     }
   14494 
   14495   rtx set = single_set (insn);
   14496   if (set)
   14497     {
   14498       rtx dest = SET_DEST (set);
   14499       rtx src = SET_SRC (set);
   14500       if (SSE_REG_P (dest)
   14501 	  && !EXT_REX_SSE_REG_P (dest)
   14502 	  && GET_MODE_BITSIZE (GET_MODE (dest)) > 128)
   14503 	{
   14504 	  /* This is an YMM/ZMM load.  Return AVX_U128_DIRTY if the
   14505 	     source isn't zero.  */
   14506 	  if (standard_sse_constant_p (src, GET_MODE (dest)) != 1)
   14507 	    return AVX_U128_DIRTY;
   14508 	  else
   14509 	    return AVX_U128_ANY;
   14510 	}
   14511       else
   14512 	{
   14513 	  if (ix86_check_avx_upper_register (src))
   14514 	    return AVX_U128_DIRTY;
   14515 	}
   14516 
   14517       /* This isn't YMM/ZMM load/store.  */
   14518       return AVX_U128_ANY;
   14519     }
   14520 
   14521   /* Require DIRTY mode if a 256bit or 512bit AVX register is referenced.
   14522      Hardware changes state only when a 256bit register is written to,
   14523      but we need to prevent the compiler from moving optimal insertion
   14524      point above eventual read from 256bit or 512 bit register.  */
   14525   if (ix86_check_avx_upper_register (PATTERN (insn)))
   14526     return AVX_U128_DIRTY;
   14527 
   14528   return AVX_U128_ANY;
   14529 }
   14530 
   14531 /* Return mode that i387 must be switched into
   14532    prior to the execution of insn.  */
   14533 
   14534 static int
   14535 ix86_i387_mode_needed (int entity, rtx_insn *insn)
   14536 {
   14537   enum attr_i387_cw mode;
   14538 
   14539   /* The mode UNINITIALIZED is used to store control word after a
   14540      function call or ASM pattern.  The mode ANY specify that function
   14541      has no requirements on the control word and make no changes in the
   14542      bits we are interested in.  */
   14543 
   14544   if (CALL_P (insn)
   14545       || (NONJUMP_INSN_P (insn)
   14546 	  && (asm_noperands (PATTERN (insn)) >= 0
   14547 	      || GET_CODE (PATTERN (insn)) == ASM_INPUT)))
   14548     return I387_CW_UNINITIALIZED;
   14549 
   14550   if (recog_memoized (insn) < 0)
   14551     return I387_CW_ANY;
   14552 
   14553   mode = get_attr_i387_cw (insn);
   14554 
   14555   switch (entity)
   14556     {
   14557     case I387_ROUNDEVEN:
   14558       if (mode == I387_CW_ROUNDEVEN)
   14559 	return mode;
   14560       break;
   14561 
   14562     case I387_TRUNC:
   14563       if (mode == I387_CW_TRUNC)
   14564 	return mode;
   14565       break;
   14566 
   14567     case I387_FLOOR:
   14568       if (mode == I387_CW_FLOOR)
   14569 	return mode;
   14570       break;
   14571 
   14572     case I387_CEIL:
   14573       if (mode == I387_CW_CEIL)
   14574 	return mode;
   14575       break;
   14576 
   14577     default:
   14578       gcc_unreachable ();
   14579     }
   14580 
   14581   return I387_CW_ANY;
   14582 }
   14583 
   14584 /* Return mode that entity must be switched into
   14585    prior to the execution of insn.  */
   14586 
   14587 static int
   14588 ix86_mode_needed (int entity, rtx_insn *insn)
   14589 {
   14590   switch (entity)
   14591     {
   14592     case X86_DIRFLAG:
   14593       return ix86_dirflag_mode_needed (insn);
   14594     case AVX_U128:
   14595       return ix86_avx_u128_mode_needed (insn);
   14596     case I387_ROUNDEVEN:
   14597     case I387_TRUNC:
   14598     case I387_FLOOR:
   14599     case I387_CEIL:
   14600       return ix86_i387_mode_needed (entity, insn);
   14601     default:
   14602       gcc_unreachable ();
   14603     }
   14604   return 0;
   14605 }
   14606 
   14607 /* Calculate mode of upper 128bit AVX registers after the insn.  */
   14608 
   14609 static int
   14610 ix86_avx_u128_mode_after (int mode, rtx_insn *insn)
   14611 {
   14612   rtx pat = PATTERN (insn);
   14613 
   14614   if (vzeroupper_pattern (pat, VOIDmode)
   14615       || vzeroall_pattern (pat, VOIDmode))
   14616     return AVX_U128_CLEAN;
   14617 
   14618   /* We know that state is clean after CALL insn if there are no
   14619      256bit or 512bit registers used in the function return register. */
   14620   if (CALL_P (insn))
   14621     {
   14622       bool avx_upper_reg_found = false;
   14623       note_stores (insn, ix86_check_avx_upper_stores, &avx_upper_reg_found);
   14624 
   14625       if (avx_upper_reg_found)
   14626 	return AVX_U128_DIRTY;
   14627 
   14628       /* If the function desn't clobber any sse registers or only clobber
   14629 	 128-bit part, Then vzeroupper isn't issued before the function exit.
   14630 	 the status not CLEAN but ANY after the function.  */
   14631       const function_abi &abi = insn_callee_abi (insn);
   14632       if (!(SIBLING_CALL_P (insn)
   14633 	    || hard_reg_set_subset_p (reg_class_contents[SSE_REGS],
   14634 				      abi.mode_clobbers (V4DImode))))
   14635 	return AVX_U128_ANY;
   14636 
   14637       return  AVX_U128_CLEAN;
   14638     }
   14639 
   14640   /* Otherwise, return current mode.  Remember that if insn
   14641      references AVX 256bit or 512bit registers, the mode was already
   14642      changed to DIRTY from MODE_NEEDED.  */
   14643   return mode;
   14644 }
   14645 
   14646 /* Return the mode that an insn results in.  */
   14647 
   14648 static int
   14649 ix86_mode_after (int entity, int mode, rtx_insn *insn)
   14650 {
   14651   switch (entity)
   14652     {
   14653     case X86_DIRFLAG:
   14654       return mode;
   14655     case AVX_U128:
   14656       return ix86_avx_u128_mode_after (mode, insn);
   14657     case I387_ROUNDEVEN:
   14658     case I387_TRUNC:
   14659     case I387_FLOOR:
   14660     case I387_CEIL:
   14661       return mode;
   14662     default:
   14663       gcc_unreachable ();
   14664     }
   14665 }
   14666 
   14667 static int
   14668 ix86_dirflag_mode_entry (void)
   14669 {
   14670   /* For TARGET_CLD or in the interrupt handler we can't assume
   14671      direction flag state at function entry.  */
   14672   if (TARGET_CLD
   14673       || cfun->machine->func_type != TYPE_NORMAL)
   14674     return X86_DIRFLAG_ANY;
   14675 
   14676   return X86_DIRFLAG_RESET;
   14677 }
   14678 
   14679 static int
   14680 ix86_avx_u128_mode_entry (void)
   14681 {
   14682   tree arg;
   14683 
   14684   /* Entry mode is set to AVX_U128_DIRTY if there are
   14685      256bit or 512bit modes used in function arguments.  */
   14686   for (arg = DECL_ARGUMENTS (current_function_decl); arg;
   14687        arg = TREE_CHAIN (arg))
   14688     {
   14689       rtx incoming = DECL_INCOMING_RTL (arg);
   14690 
   14691       if (incoming && ix86_check_avx_upper_register (incoming))
   14692 	return AVX_U128_DIRTY;
   14693     }
   14694 
   14695   return AVX_U128_CLEAN;
   14696 }
   14697 
   14698 /* Return a mode that ENTITY is assumed to be
   14699    switched to at function entry.  */
   14700 
   14701 static int
   14702 ix86_mode_entry (int entity)
   14703 {
   14704   switch (entity)
   14705     {
   14706     case X86_DIRFLAG:
   14707       return ix86_dirflag_mode_entry ();
   14708     case AVX_U128:
   14709       return ix86_avx_u128_mode_entry ();
   14710     case I387_ROUNDEVEN:
   14711     case I387_TRUNC:
   14712     case I387_FLOOR:
   14713     case I387_CEIL:
   14714       return I387_CW_ANY;
   14715     default:
   14716       gcc_unreachable ();
   14717     }
   14718 }
   14719 
   14720 static int
   14721 ix86_avx_u128_mode_exit (void)
   14722 {
   14723   rtx reg = crtl->return_rtx;
   14724 
   14725   /* Exit mode is set to AVX_U128_DIRTY if there are 256bit
   14726      or 512 bit modes used in the function return register. */
   14727   if (reg && ix86_check_avx_upper_register (reg))
   14728     return AVX_U128_DIRTY;
   14729 
   14730   /* Exit mode is set to AVX_U128_DIRTY if there are 256bit or 512bit
   14731      modes used in function arguments, otherwise return AVX_U128_CLEAN.
   14732    */
   14733   return ix86_avx_u128_mode_entry ();
   14734 }
   14735 
   14736 /* Return a mode that ENTITY is assumed to be
   14737    switched to at function exit.  */
   14738 
   14739 static int
   14740 ix86_mode_exit (int entity)
   14741 {
   14742   switch (entity)
   14743     {
   14744     case X86_DIRFLAG:
   14745       return X86_DIRFLAG_ANY;
   14746     case AVX_U128:
   14747       return ix86_avx_u128_mode_exit ();
   14748     case I387_ROUNDEVEN:
   14749     case I387_TRUNC:
   14750     case I387_FLOOR:
   14751     case I387_CEIL:
   14752       return I387_CW_ANY;
   14753     default:
   14754       gcc_unreachable ();
   14755     }
   14756 }
   14757 
   14758 static int
   14759 ix86_mode_priority (int, int n)
   14760 {
   14761   return n;
   14762 }
   14763 
   14764 /* Output code to initialize control word copies used by trunc?f?i and
   14765    rounding patterns.  CURRENT_MODE is set to current control word,
   14766    while NEW_MODE is set to new control word.  */
   14767 
   14768 static void
   14769 emit_i387_cw_initialization (int mode)
   14770 {
   14771   rtx stored_mode = assign_386_stack_local (HImode, SLOT_CW_STORED);
   14772   rtx new_mode;
   14773 
   14774   enum ix86_stack_slot slot;
   14775 
   14776   rtx reg = gen_reg_rtx (HImode);
   14777 
   14778   emit_insn (gen_x86_fnstcw_1 (stored_mode));
   14779   emit_move_insn (reg, copy_rtx (stored_mode));
   14780 
   14781   switch (mode)
   14782     {
   14783     case I387_CW_ROUNDEVEN:
   14784       /* round to nearest */
   14785       emit_insn (gen_andhi3 (reg, reg, GEN_INT (~0x0c00)));
   14786       slot = SLOT_CW_ROUNDEVEN;
   14787       break;
   14788 
   14789     case I387_CW_TRUNC:
   14790       /* round toward zero (truncate) */
   14791       emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0c00)));
   14792       slot = SLOT_CW_TRUNC;
   14793       break;
   14794 
   14795     case I387_CW_FLOOR:
   14796       /* round down toward -oo */
   14797       emit_insn (gen_andhi3 (reg, reg, GEN_INT (~0x0c00)));
   14798       emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0400)));
   14799       slot = SLOT_CW_FLOOR;
   14800       break;
   14801 
   14802     case I387_CW_CEIL:
   14803       /* round up toward +oo */
   14804       emit_insn (gen_andhi3 (reg, reg, GEN_INT (~0x0c00)));
   14805       emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0800)));
   14806       slot = SLOT_CW_CEIL;
   14807       break;
   14808 
   14809     default:
   14810       gcc_unreachable ();
   14811     }
   14812 
   14813   gcc_assert (slot < MAX_386_STACK_LOCALS);
   14814 
   14815   new_mode = assign_386_stack_local (HImode, slot);
   14816   emit_move_insn (new_mode, reg);
   14817 }
   14818 
   14819 /* Generate one or more insns to set ENTITY to MODE.  */
   14820 
   14821 static void
   14822 ix86_emit_mode_set (int entity, int mode, int prev_mode ATTRIBUTE_UNUSED,
   14823 		    HARD_REG_SET regs_live ATTRIBUTE_UNUSED)
   14824 {
   14825   switch (entity)
   14826     {
   14827     case X86_DIRFLAG:
   14828       if (mode == X86_DIRFLAG_RESET)
   14829 	emit_insn (gen_cld ());
   14830       break;
   14831     case AVX_U128:
   14832       if (mode == AVX_U128_CLEAN)
   14833 	ix86_expand_avx_vzeroupper ();
   14834       break;
   14835     case I387_ROUNDEVEN:
   14836     case I387_TRUNC:
   14837     case I387_FLOOR:
   14838     case I387_CEIL:
   14839       if (mode != I387_CW_ANY
   14840 	  && mode != I387_CW_UNINITIALIZED)
   14841 	emit_i387_cw_initialization (mode);
   14842       break;
   14843     default:
   14844       gcc_unreachable ();
   14845     }
   14846 }
   14847 
   14848 /* Output code for INSN to convert a float to a signed int.  OPERANDS
   14849    are the insn operands.  The output may be [HSD]Imode and the input
   14850    operand may be [SDX]Fmode.  */
   14851 
   14852 const char *
   14853 output_fix_trunc (rtx_insn *insn, rtx *operands, bool fisttp)
   14854 {
   14855   bool stack_top_dies = find_regno_note (insn, REG_DEAD, FIRST_STACK_REG);
   14856   bool dimode_p = GET_MODE (operands[0]) == DImode;
   14857   int round_mode = get_attr_i387_cw (insn);
   14858 
   14859   static char buf[40];
   14860   const char *p;
   14861 
   14862   /* Jump through a hoop or two for DImode, since the hardware has no
   14863      non-popping instruction.  We used to do this a different way, but
   14864      that was somewhat fragile and broke with post-reload splitters.  */
   14865   if ((dimode_p || fisttp) && !stack_top_dies)
   14866     output_asm_insn ("fld\t%y1", operands);
   14867 
   14868   gcc_assert (STACK_TOP_P (operands[1]));
   14869   gcc_assert (MEM_P (operands[0]));
   14870   gcc_assert (GET_MODE (operands[1]) != TFmode);
   14871 
   14872   if (fisttp)
   14873     return "fisttp%Z0\t%0";
   14874 
   14875   strcpy (buf, "fist");
   14876 
   14877   if (round_mode != I387_CW_ANY)
   14878     output_asm_insn ("fldcw\t%3", operands);
   14879 
   14880   p = "p%Z0\t%0";
   14881   strcat (buf, p + !(stack_top_dies || dimode_p));
   14882 
   14883   output_asm_insn (buf, operands);
   14884 
   14885   if (round_mode != I387_CW_ANY)
   14886     output_asm_insn ("fldcw\t%2", operands);
   14887 
   14888   return "";
   14889 }
   14890 
   14891 /* Output code for x87 ffreep insn.  The OPNO argument, which may only
   14892    have the values zero or one, indicates the ffreep insn's operand
   14893    from the OPERANDS array.  */
   14894 
   14895 static const char *
   14896 output_387_ffreep (rtx *operands ATTRIBUTE_UNUSED, int opno)
   14897 {
   14898   if (TARGET_USE_FFREEP)
   14899 #ifdef HAVE_AS_IX86_FFREEP
   14900     return opno ? "ffreep\t%y1" : "ffreep\t%y0";
   14901 #else
   14902     {
   14903       static char retval[32];
   14904       int regno = REGNO (operands[opno]);
   14905 
   14906       gcc_assert (STACK_REGNO_P (regno));
   14907 
   14908       regno -= FIRST_STACK_REG;
   14909 
   14910       snprintf (retval, sizeof (retval), ASM_SHORT "0xc%ddf", regno);
   14911       return retval;
   14912     }
   14913 #endif
   14914 
   14915   return opno ? "fstp\t%y1" : "fstp\t%y0";
   14916 }
   14917 
   14918 
   14919 /* Output code for INSN to compare OPERANDS.  EFLAGS_P is 1 when fcomi
   14920    should be used.  UNORDERED_P is true when fucom should be used.  */
   14921 
   14922 const char *
   14923 output_fp_compare (rtx_insn *insn, rtx *operands,
   14924 		   bool eflags_p, bool unordered_p)
   14925 {
   14926   rtx *xops = eflags_p ? &operands[0] : &operands[1];
   14927   bool stack_top_dies;
   14928 
   14929   static char buf[40];
   14930   const char *p;
   14931 
   14932   gcc_assert (STACK_TOP_P (xops[0]));
   14933 
   14934   stack_top_dies = find_regno_note (insn, REG_DEAD, FIRST_STACK_REG);
   14935 
   14936   if (eflags_p)
   14937     {
   14938       p = unordered_p ? "fucomi" : "fcomi";
   14939       strcpy (buf, p);
   14940 
   14941       p = "p\t{%y1, %0|%0, %y1}";
   14942       strcat (buf, p + !stack_top_dies);
   14943 
   14944       return buf;
   14945     }
   14946 
   14947   if (STACK_REG_P (xops[1])
   14948       && stack_top_dies
   14949       && find_regno_note (insn, REG_DEAD, FIRST_STACK_REG + 1))
   14950     {
   14951       gcc_assert (REGNO (xops[1]) == FIRST_STACK_REG + 1);
   14952 
   14953       /* If both the top of the 387 stack die, and the other operand
   14954 	 is also a stack register that dies, then this must be a
   14955 	 `fcompp' float compare.  */
   14956       p = unordered_p ? "fucompp" : "fcompp";
   14957       strcpy (buf, p);
   14958     }
   14959   else if (const0_operand (xops[1], VOIDmode))
   14960     {
   14961       gcc_assert (!unordered_p);
   14962       strcpy (buf, "ftst");
   14963     }
   14964   else
   14965     {
   14966       if (GET_MODE_CLASS (GET_MODE (xops[1])) == MODE_INT)
   14967 	{
   14968 	  gcc_assert (!unordered_p);
   14969 	  p = "ficom";
   14970 	}
   14971       else
   14972 	p = unordered_p ? "fucom" : "fcom";
   14973 
   14974       strcpy (buf, p);
   14975 
   14976       p = "p%Z2\t%y2";
   14977       strcat (buf, p + !stack_top_dies);
   14978     }
   14979 
   14980   output_asm_insn (buf, operands);
   14981   return "fnstsw\t%0";
   14982 }
   14983 
   14984 void
   14985 ix86_output_addr_vec_elt (FILE *file, int value)
   14986 {
   14987   const char *directive = ASM_LONG;
   14988 
   14989 #ifdef ASM_QUAD
   14990   if (TARGET_LP64)
   14991     directive = ASM_QUAD;
   14992 #else
   14993   gcc_assert (!TARGET_64BIT);
   14994 #endif
   14995 
   14996   fprintf (file, "%s%s%d\n", directive, LPREFIX, value);
   14997 }
   14998 
   14999 void
   15000 ix86_output_addr_diff_elt (FILE *file, int value, int rel)
   15001 {
   15002   const char *directive = ASM_LONG;
   15003 
   15004 #ifdef ASM_QUAD
   15005   if (TARGET_64BIT && CASE_VECTOR_MODE == DImode)
   15006     directive = ASM_QUAD;
   15007 #else
   15008   gcc_assert (!TARGET_64BIT);
   15009 #endif
   15010   /* We can't use @GOTOFF for text labels on VxWorks; see gotoff_operand.  */
   15011   if (TARGET_64BIT || TARGET_VXWORKS_RTP)
   15012     fprintf (file, "%s%s%d-%s%d\n",
   15013 	     directive, LPREFIX, value, LPREFIX, rel);
   15014 #if TARGET_MACHO
   15015   else if (TARGET_MACHO)
   15016     {
   15017       fprintf (file, ASM_LONG "%s%d-", LPREFIX, value);
   15018       machopic_output_function_base_name (file);
   15019       putc ('\n', file);
   15020     }
   15021 #endif
   15022   else if (HAVE_AS_GOTOFF_IN_DATA)
   15023     fprintf (file, ASM_LONG "%s%d@GOTOFF\n", LPREFIX, value);
   15024   else
   15025     asm_fprintf (file, ASM_LONG "%U%s+[.-%s%d]\n",
   15026 		 GOT_SYMBOL_NAME, LPREFIX, value);
   15027 }
   15028 
   15029 #define LEA_MAX_STALL (3)
   15031 #define LEA_SEARCH_THRESHOLD (LEA_MAX_STALL << 1)
   15032 
   15033 /* Increase given DISTANCE in half-cycles according to
   15034    dependencies between PREV and NEXT instructions.
   15035    Add 1 half-cycle if there is no dependency and
   15036    go to next cycle if there is some dependecy.  */
   15037 
   15038 static unsigned int
   15039 increase_distance (rtx_insn *prev, rtx_insn *next, unsigned int distance)
   15040 {
   15041   df_ref def, use;
   15042 
   15043   if (!prev || !next)
   15044     return distance + (distance & 1) + 2;
   15045 
   15046   if (!DF_INSN_USES (next) || !DF_INSN_DEFS (prev))
   15047     return distance + 1;
   15048 
   15049   FOR_EACH_INSN_USE (use, next)
   15050     FOR_EACH_INSN_DEF (def, prev)
   15051       if (!DF_REF_IS_ARTIFICIAL (def)
   15052 	  && DF_REF_REGNO (use) == DF_REF_REGNO (def))
   15053 	return distance + (distance & 1) + 2;
   15054 
   15055   return distance + 1;
   15056 }
   15057 
   15058 /* Function checks if instruction INSN defines register number
   15059    REGNO1 or REGNO2.  */
   15060 
   15061 bool
   15062 insn_defines_reg (unsigned int regno1, unsigned int regno2,
   15063 		  rtx_insn *insn)
   15064 {
   15065   df_ref def;
   15066 
   15067   FOR_EACH_INSN_DEF (def, insn)
   15068     if (DF_REF_REG_DEF_P (def)
   15069 	&& !DF_REF_IS_ARTIFICIAL (def)
   15070 	&& (regno1 == DF_REF_REGNO (def)
   15071 	    || regno2 == DF_REF_REGNO (def)))
   15072       return true;
   15073 
   15074   return false;
   15075 }
   15076 
   15077 /* Function checks if instruction INSN uses register number
   15078    REGNO as a part of address expression.  */
   15079 
   15080 static bool
   15081 insn_uses_reg_mem (unsigned int regno, rtx insn)
   15082 {
   15083   df_ref use;
   15084 
   15085   FOR_EACH_INSN_USE (use, insn)
   15086     if (DF_REF_REG_MEM_P (use) && regno == DF_REF_REGNO (use))
   15087       return true;
   15088 
   15089   return false;
   15090 }
   15091 
   15092 /* Search backward for non-agu definition of register number REGNO1
   15093    or register number REGNO2 in basic block starting from instruction
   15094    START up to head of basic block or instruction INSN.
   15095 
   15096    Function puts true value into *FOUND var if definition was found
   15097    and false otherwise.
   15098 
   15099    Distance in half-cycles between START and found instruction or head
   15100    of BB is added to DISTANCE and returned.  */
   15101 
   15102 static int
   15103 distance_non_agu_define_in_bb (unsigned int regno1, unsigned int regno2,
   15104 			       rtx_insn *insn, int distance,
   15105 			       rtx_insn *start, bool *found)
   15106 {
   15107   basic_block bb = start ? BLOCK_FOR_INSN (start) : NULL;
   15108   rtx_insn *prev = start;
   15109   rtx_insn *next = NULL;
   15110 
   15111   *found = false;
   15112 
   15113   while (prev
   15114 	 && prev != insn
   15115 	 && distance < LEA_SEARCH_THRESHOLD)
   15116     {
   15117       if (NONDEBUG_INSN_P (prev) && NONJUMP_INSN_P (prev))
   15118 	{
   15119 	  distance = increase_distance (prev, next, distance);
   15120 	  if (insn_defines_reg (regno1, regno2, prev))
   15121 	    {
   15122 	      if (recog_memoized (prev) < 0
   15123 		  || get_attr_type (prev) != TYPE_LEA)
   15124 		{
   15125 		  *found = true;
   15126 		  return distance;
   15127 		}
   15128 	    }
   15129 
   15130 	  next = prev;
   15131 	}
   15132       if (prev == BB_HEAD (bb))
   15133 	break;
   15134 
   15135       prev = PREV_INSN (prev);
   15136     }
   15137 
   15138   return distance;
   15139 }
   15140 
   15141 /* Search backward for non-agu definition of register number REGNO1
   15142    or register number REGNO2 in INSN's basic block until
   15143    1. Pass LEA_SEARCH_THRESHOLD instructions, or
   15144    2. Reach neighbor BBs boundary, or
   15145    3. Reach agu definition.
   15146    Returns the distance between the non-agu definition point and INSN.
   15147    If no definition point, returns -1.  */
   15148 
   15149 static int
   15150 distance_non_agu_define (unsigned int regno1, unsigned int regno2,
   15151 			 rtx_insn *insn)
   15152 {
   15153   basic_block bb = BLOCK_FOR_INSN (insn);
   15154   int distance = 0;
   15155   bool found = false;
   15156 
   15157   if (insn != BB_HEAD (bb))
   15158     distance = distance_non_agu_define_in_bb (regno1, regno2, insn,
   15159 					      distance, PREV_INSN (insn),
   15160 					      &found);
   15161 
   15162   if (!found && distance < LEA_SEARCH_THRESHOLD)
   15163     {
   15164       edge e;
   15165       edge_iterator ei;
   15166       bool simple_loop = false;
   15167 
   15168       FOR_EACH_EDGE (e, ei, bb->preds)
   15169 	if (e->src == bb)
   15170 	  {
   15171 	    simple_loop = true;
   15172 	    break;
   15173 	  }
   15174 
   15175       if (simple_loop)
   15176 	distance = distance_non_agu_define_in_bb (regno1, regno2,
   15177 						  insn, distance,
   15178 						  BB_END (bb), &found);
   15179       else
   15180 	{
   15181 	  int shortest_dist = -1;
   15182 	  bool found_in_bb = false;
   15183 
   15184 	  FOR_EACH_EDGE (e, ei, bb->preds)
   15185 	    {
   15186 	      int bb_dist
   15187 		= distance_non_agu_define_in_bb (regno1, regno2,
   15188 						 insn, distance,
   15189 						 BB_END (e->src),
   15190 						 &found_in_bb);
   15191 	      if (found_in_bb)
   15192 		{
   15193 		  if (shortest_dist < 0)
   15194 		    shortest_dist = bb_dist;
   15195 		  else if (bb_dist > 0)
   15196 		    shortest_dist = MIN (bb_dist, shortest_dist);
   15197 
   15198 		  found = true;
   15199 		}
   15200 	    }
   15201 
   15202 	  distance = shortest_dist;
   15203 	}
   15204     }
   15205 
   15206   if (!found)
   15207     return -1;
   15208 
   15209   return distance >> 1;
   15210 }
   15211 
   15212 /* Return the distance in half-cycles between INSN and the next
   15213    insn that uses register number REGNO in memory address added
   15214    to DISTANCE.  Return -1 if REGNO0 is set.
   15215 
   15216    Put true value into *FOUND if register usage was found and
   15217    false otherwise.
   15218    Put true value into *REDEFINED if register redefinition was
   15219    found and false otherwise.  */
   15220 
   15221 static int
   15222 distance_agu_use_in_bb (unsigned int regno,
   15223 			rtx_insn *insn, int distance, rtx_insn *start,
   15224 			bool *found, bool *redefined)
   15225 {
   15226   basic_block bb = NULL;
   15227   rtx_insn *next = start;
   15228   rtx_insn *prev = NULL;
   15229 
   15230   *found = false;
   15231   *redefined = false;
   15232 
   15233   if (start != NULL_RTX)
   15234     {
   15235       bb = BLOCK_FOR_INSN (start);
   15236       if (start != BB_HEAD (bb))
   15237 	/* If insn and start belong to the same bb, set prev to insn,
   15238 	   so the call to increase_distance will increase the distance
   15239 	   between insns by 1.  */
   15240 	prev = insn;
   15241     }
   15242 
   15243   while (next
   15244 	 && next != insn
   15245 	 && distance < LEA_SEARCH_THRESHOLD)
   15246     {
   15247       if (NONDEBUG_INSN_P (next) && NONJUMP_INSN_P (next))
   15248 	{
   15249 	  distance = increase_distance(prev, next, distance);
   15250 	  if (insn_uses_reg_mem (regno, next))
   15251 	    {
   15252 	      /* Return DISTANCE if OP0 is used in memory
   15253 		 address in NEXT.  */
   15254 	      *found = true;
   15255 	      return distance;
   15256 	    }
   15257 
   15258 	  if (insn_defines_reg (regno, INVALID_REGNUM, next))
   15259 	    {
   15260 	      /* Return -1 if OP0 is set in NEXT.  */
   15261 	      *redefined = true;
   15262 	      return -1;
   15263 	    }
   15264 
   15265 	  prev = next;
   15266 	}
   15267 
   15268       if (next == BB_END (bb))
   15269 	break;
   15270 
   15271       next = NEXT_INSN (next);
   15272     }
   15273 
   15274   return distance;
   15275 }
   15276 
   15277 /* Return the distance between INSN and the next insn that uses
   15278    register number REGNO0 in memory address.  Return -1 if no such
   15279    a use is found within LEA_SEARCH_THRESHOLD or REGNO0 is set.  */
   15280 
   15281 static int
   15282 distance_agu_use (unsigned int regno0, rtx_insn *insn)
   15283 {
   15284   basic_block bb = BLOCK_FOR_INSN (insn);
   15285   int distance = 0;
   15286   bool found = false;
   15287   bool redefined = false;
   15288 
   15289   if (insn != BB_END (bb))
   15290     distance = distance_agu_use_in_bb (regno0, insn, distance,
   15291 				       NEXT_INSN (insn),
   15292 				       &found, &redefined);
   15293 
   15294   if (!found && !redefined && distance < LEA_SEARCH_THRESHOLD)
   15295     {
   15296       edge e;
   15297       edge_iterator ei;
   15298       bool simple_loop = false;
   15299 
   15300       FOR_EACH_EDGE (e, ei, bb->succs)
   15301         if (e->dest == bb)
   15302 	  {
   15303 	    simple_loop = true;
   15304 	    break;
   15305 	  }
   15306 
   15307       if (simple_loop)
   15308 	distance = distance_agu_use_in_bb (regno0, insn,
   15309 					   distance, BB_HEAD (bb),
   15310 					   &found, &redefined);
   15311       else
   15312 	{
   15313 	  int shortest_dist = -1;
   15314 	  bool found_in_bb = false;
   15315 	  bool redefined_in_bb = false;
   15316 
   15317 	  FOR_EACH_EDGE (e, ei, bb->succs)
   15318 	    {
   15319 	      int bb_dist
   15320 		= distance_agu_use_in_bb (regno0, insn,
   15321 					  distance, BB_HEAD (e->dest),
   15322 					  &found_in_bb, &redefined_in_bb);
   15323 	      if (found_in_bb)
   15324 		{
   15325 		  if (shortest_dist < 0)
   15326 		    shortest_dist = bb_dist;
   15327 		  else if (bb_dist > 0)
   15328 		    shortest_dist = MIN (bb_dist, shortest_dist);
   15329 
   15330 		  found = true;
   15331 		}
   15332 	    }
   15333 
   15334 	  distance = shortest_dist;
   15335 	}
   15336     }
   15337 
   15338   if (!found || redefined)
   15339     return -1;
   15340 
   15341   return distance >> 1;
   15342 }
   15343 
   15344 /* Define this macro to tune LEA priority vs ADD, it take effect when
   15345    there is a dilemma of choosing LEA or ADD
   15346    Negative value: ADD is more preferred than LEA
   15347    Zero: Neutral
   15348    Positive value: LEA is more preferred than ADD.  */
   15349 #define IX86_LEA_PRIORITY 0
   15350 
   15351 /* Return true if usage of lea INSN has performance advantage
   15352    over a sequence of instructions.  Instructions sequence has
   15353    SPLIT_COST cycles higher latency than lea latency.  */
   15354 
   15355 static bool
   15356 ix86_lea_outperforms (rtx_insn *insn, unsigned int regno0, unsigned int regno1,
   15357 		      unsigned int regno2, int split_cost, bool has_scale)
   15358 {
   15359   int dist_define, dist_use;
   15360 
   15361   /* For Atom processors newer than Bonnell, if using a 2-source or
   15362      3-source LEA for non-destructive destination purposes, or due to
   15363      wanting ability to use SCALE, the use of LEA is justified.  */
   15364   if (!TARGET_CPU_P (BONNELL))
   15365     {
   15366       if (has_scale)
   15367 	return true;
   15368       if (split_cost < 1)
   15369 	return false;
   15370       if (regno0 == regno1 || regno0 == regno2)
   15371 	return false;
   15372       return true;
   15373     }
   15374 
   15375   /* Remember recog_data content.  */
   15376   struct recog_data_d recog_data_save = recog_data;
   15377 
   15378   dist_define = distance_non_agu_define (regno1, regno2, insn);
   15379   dist_use = distance_agu_use (regno0, insn);
   15380 
   15381   /* distance_non_agu_define can call get_attr_type which can call
   15382      recog_memoized, restore recog_data back to previous content.  */
   15383   recog_data = recog_data_save;
   15384 
   15385   if (dist_define < 0 || dist_define >= LEA_MAX_STALL)
   15386     {
   15387       /* If there is no non AGU operand definition, no AGU
   15388 	 operand usage and split cost is 0 then both lea
   15389 	 and non lea variants have same priority.  Currently
   15390 	 we prefer lea for 64 bit code and non lea on 32 bit
   15391 	 code.  */
   15392       if (dist_use < 0 && split_cost == 0)
   15393 	return TARGET_64BIT || IX86_LEA_PRIORITY;
   15394       else
   15395 	return true;
   15396     }
   15397 
   15398   /* With longer definitions distance lea is more preferable.
   15399      Here we change it to take into account splitting cost and
   15400      lea priority.  */
   15401   dist_define += split_cost + IX86_LEA_PRIORITY;
   15402 
   15403   /* If there is no use in memory addess then we just check
   15404      that split cost exceeds AGU stall.  */
   15405   if (dist_use < 0)
   15406     return dist_define > LEA_MAX_STALL;
   15407 
   15408   /* If this insn has both backward non-agu dependence and forward
   15409      agu dependence, the one with short distance takes effect.  */
   15410   return dist_define >= dist_use;
   15411 }
   15412 
   15413 /* Return true if we need to split op0 = op1 + op2 into a sequence of
   15414    move and add to avoid AGU stalls.  */
   15415 
   15416 bool
   15417 ix86_avoid_lea_for_add (rtx_insn *insn, rtx operands[])
   15418 {
   15419   unsigned int regno0, regno1, regno2;
   15420 
   15421   /* Check if we need to optimize.  */
   15422   if (!TARGET_OPT_AGU || optimize_function_for_size_p (cfun))
   15423     return false;
   15424 
   15425   regno0 = true_regnum (operands[0]);
   15426   regno1 = true_regnum (operands[1]);
   15427   regno2 = true_regnum (operands[2]);
   15428 
   15429   /* We need to split only adds with non destructive
   15430      destination operand.  */
   15431   if (regno0 == regno1 || regno0 == regno2)
   15432     return false;
   15433   else
   15434     return !ix86_lea_outperforms (insn, regno0, regno1, regno2, 1, false);
   15435 }
   15436 
   15437 /* Return true if we should emit lea instruction instead of mov
   15438    instruction.  */
   15439 
   15440 bool
   15441 ix86_use_lea_for_mov (rtx_insn *insn, rtx operands[])
   15442 {
   15443   unsigned int regno0, regno1;
   15444 
   15445   /* Check if we need to optimize.  */
   15446   if (!TARGET_OPT_AGU || optimize_function_for_size_p (cfun))
   15447     return false;
   15448 
   15449   /* Use lea for reg to reg moves only.  */
   15450   if (!REG_P (operands[0]) || !REG_P (operands[1]))
   15451     return false;
   15452 
   15453   regno0 = true_regnum (operands[0]);
   15454   regno1 = true_regnum (operands[1]);
   15455 
   15456   return ix86_lea_outperforms (insn, regno0, regno1, INVALID_REGNUM, 0, false);
   15457 }
   15458 
   15459 /* Return true if we need to split lea into a sequence of
   15460    instructions to avoid AGU stalls during peephole2. */
   15461 
   15462 bool
   15463 ix86_avoid_lea_for_addr (rtx_insn *insn, rtx operands[])
   15464 {
   15465   unsigned int regno0, regno1, regno2;
   15466   int split_cost;
   15467   struct ix86_address parts;
   15468   int ok;
   15469 
   15470   /* The "at least two components" test below might not catch simple
   15471      move or zero extension insns if parts.base is non-NULL and parts.disp
   15472      is const0_rtx as the only components in the address, e.g. if the
   15473      register is %rbp or %r13.  As this test is much cheaper and moves or
   15474      zero extensions are the common case, do this check first.  */
   15475   if (REG_P (operands[1])
   15476       || (SImode_address_operand (operands[1], VOIDmode)
   15477 	  && REG_P (XEXP (operands[1], 0))))
   15478     return false;
   15479 
   15480   ok = ix86_decompose_address (operands[1], &parts);
   15481   gcc_assert (ok);
   15482 
   15483   /* There should be at least two components in the address.  */
   15484   if ((parts.base != NULL_RTX) + (parts.index != NULL_RTX)
   15485       + (parts.disp != NULL_RTX) + (parts.scale > 1) < 2)
   15486     return false;
   15487 
   15488   /* We should not split into add if non legitimate pic
   15489      operand is used as displacement. */
   15490   if (parts.disp && flag_pic && !LEGITIMATE_PIC_OPERAND_P (parts.disp))
   15491     return false;
   15492 
   15493   regno0 = true_regnum (operands[0]) ;
   15494   regno1 = INVALID_REGNUM;
   15495   regno2 = INVALID_REGNUM;
   15496 
   15497   if (parts.base)
   15498     regno1 = true_regnum (parts.base);
   15499   if (parts.index)
   15500     regno2 = true_regnum (parts.index);
   15501 
   15502   /* Use add for a = a + b and a = b + a since it is faster and shorter
   15503      than lea for most processors.  For the processors like BONNELL, if
   15504      the destination register of LEA holds an actual address which will
   15505      be used soon, LEA is better and otherwise ADD is better.  */
   15506   if (!TARGET_CPU_P (BONNELL)
   15507       && parts.scale == 1
   15508       && (!parts.disp || parts.disp == const0_rtx)
   15509       && (regno0 == regno1 || regno0 == regno2))
   15510     return true;
   15511 
   15512   /* Check we need to optimize.  */
   15513   if (!TARGET_AVOID_LEA_FOR_ADDR || optimize_function_for_size_p (cfun))
   15514     return false;
   15515 
   15516   split_cost = 0;
   15517 
   15518   /* Compute how many cycles we will add to execution time
   15519      if split lea into a sequence of instructions.  */
   15520   if (parts.base || parts.index)
   15521     {
   15522       /* Have to use mov instruction if non desctructive
   15523 	 destination form is used.  */
   15524       if (regno1 != regno0 && regno2 != regno0)
   15525 	split_cost += 1;
   15526 
   15527       /* Have to add index to base if both exist.  */
   15528       if (parts.base && parts.index)
   15529 	split_cost += 1;
   15530 
   15531       /* Have to use shift and adds if scale is 2 or greater.  */
   15532       if (parts.scale > 1)
   15533 	{
   15534 	  if (regno0 != regno1)
   15535 	    split_cost += 1;
   15536 	  else if (regno2 == regno0)
   15537 	    split_cost += 4;
   15538 	  else
   15539 	    split_cost += parts.scale;
   15540 	}
   15541 
   15542       /* Have to use add instruction with immediate if
   15543 	 disp is non zero.  */
   15544       if (parts.disp && parts.disp != const0_rtx)
   15545 	split_cost += 1;
   15546 
   15547       /* Subtract the price of lea.  */
   15548       split_cost -= 1;
   15549     }
   15550 
   15551   return !ix86_lea_outperforms (insn, regno0, regno1, regno2, split_cost,
   15552 				parts.scale > 1);
   15553 }
   15554 
   15555 /* Return true if it is ok to optimize an ADD operation to LEA
   15556    operation to avoid flag register consumation.  For most processors,
   15557    ADD is faster than LEA.  For the processors like BONNELL, if the
   15558    destination register of LEA holds an actual address which will be
   15559    used soon, LEA is better and otherwise ADD is better.  */
   15560 
   15561 bool
   15562 ix86_lea_for_add_ok (rtx_insn *insn, rtx operands[])
   15563 {
   15564   unsigned int regno0 = true_regnum (operands[0]);
   15565   unsigned int regno1 = true_regnum (operands[1]);
   15566   unsigned int regno2 = true_regnum (operands[2]);
   15567 
   15568   /* If a = b + c, (a!=b && a!=c), must use lea form. */
   15569   if (regno0 != regno1 && regno0 != regno2)
   15570     return true;
   15571 
   15572   if (!TARGET_OPT_AGU || optimize_function_for_size_p (cfun))
   15573     return false;
   15574 
   15575   return ix86_lea_outperforms (insn, regno0, regno1, regno2, 0, false);
   15576 }
   15577 
   15578 /* Return true if destination reg of SET_BODY is shift count of
   15579    USE_BODY.  */
   15580 
   15581 static bool
   15582 ix86_dep_by_shift_count_body (const_rtx set_body, const_rtx use_body)
   15583 {
   15584   rtx set_dest;
   15585   rtx shift_rtx;
   15586   int i;
   15587 
   15588   /* Retrieve destination of SET_BODY.  */
   15589   switch (GET_CODE (set_body))
   15590     {
   15591     case SET:
   15592       set_dest = SET_DEST (set_body);
   15593       if (!set_dest || !REG_P (set_dest))
   15594 	return false;
   15595       break;
   15596     case PARALLEL:
   15597       for (i = XVECLEN (set_body, 0) - 1; i >= 0; i--)
   15598 	if (ix86_dep_by_shift_count_body (XVECEXP (set_body, 0, i),
   15599 					  use_body))
   15600 	  return true;
   15601       /* FALLTHROUGH */
   15602     default:
   15603       return false;
   15604     }
   15605 
   15606   /* Retrieve shift count of USE_BODY.  */
   15607   switch (GET_CODE (use_body))
   15608     {
   15609     case SET:
   15610       shift_rtx = XEXP (use_body, 1);
   15611       break;
   15612     case PARALLEL:
   15613       for (i = XVECLEN (use_body, 0) - 1; i >= 0; i--)
   15614 	if (ix86_dep_by_shift_count_body (set_body,
   15615 					  XVECEXP (use_body, 0, i)))
   15616 	  return true;
   15617       /* FALLTHROUGH */
   15618     default:
   15619       return false;
   15620     }
   15621 
   15622   if (shift_rtx
   15623       && (GET_CODE (shift_rtx) == ASHIFT
   15624 	  || GET_CODE (shift_rtx) == LSHIFTRT
   15625 	  || GET_CODE (shift_rtx) == ASHIFTRT
   15626 	  || GET_CODE (shift_rtx) == ROTATE
   15627 	  || GET_CODE (shift_rtx) == ROTATERT))
   15628     {
   15629       rtx shift_count = XEXP (shift_rtx, 1);
   15630 
   15631       /* Return true if shift count is dest of SET_BODY.  */
   15632       if (REG_P (shift_count))
   15633 	{
   15634 	  /* Add check since it can be invoked before register
   15635 	     allocation in pre-reload schedule.  */
   15636 	  if (reload_completed
   15637 	      && true_regnum (set_dest) == true_regnum (shift_count))
   15638 	    return true;
   15639 	  else if (REGNO(set_dest) == REGNO(shift_count))
   15640 	    return true;
   15641 	}
   15642     }
   15643 
   15644   return false;
   15645 }
   15646 
   15647 /* Return true if destination reg of SET_INSN is shift count of
   15648    USE_INSN.  */
   15649 
   15650 bool
   15651 ix86_dep_by_shift_count (const_rtx set_insn, const_rtx use_insn)
   15652 {
   15653   return ix86_dep_by_shift_count_body (PATTERN (set_insn),
   15654 				       PATTERN (use_insn));
   15655 }
   15656 
   15657 /* Return TRUE or FALSE depending on whether the unary operator meets the
   15658    appropriate constraints.  */
   15659 
   15660 bool
   15661 ix86_unary_operator_ok (enum rtx_code,
   15662 			machine_mode,
   15663 			rtx operands[2])
   15664 {
   15665   /* If one of operands is memory, source and destination must match.  */
   15666   if ((MEM_P (operands[0])
   15667        || MEM_P (operands[1]))
   15668       && ! rtx_equal_p (operands[0], operands[1]))
   15669     return false;
   15670   return true;
   15671 }
   15672 
   15673 /* Return TRUE if the operands to a vec_interleave_{high,low}v2df
   15674    are ok, keeping in mind the possible movddup alternative.  */
   15675 
   15676 bool
   15677 ix86_vec_interleave_v2df_operator_ok (rtx operands[3], bool high)
   15678 {
   15679   if (MEM_P (operands[0]))
   15680     return rtx_equal_p (operands[0], operands[1 + high]);
   15681   if (MEM_P (operands[1]) && MEM_P (operands[2]))
   15682     return TARGET_SSE3 && rtx_equal_p (operands[1], operands[2]);
   15683   return true;
   15684 }
   15685 
   15686 /* A subroutine of ix86_build_signbit_mask.  If VECT is true,
   15687    then replicate the value for all elements of the vector
   15688    register.  */
   15689 
   15690 rtx
   15691 ix86_build_const_vector (machine_mode mode, bool vect, rtx value)
   15692 {
   15693   int i, n_elt;
   15694   rtvec v;
   15695   machine_mode scalar_mode;
   15696 
   15697   switch (mode)
   15698     {
   15699     case E_V64QImode:
   15700     case E_V32QImode:
   15701     case E_V16QImode:
   15702     case E_V32HImode:
   15703     case E_V16HImode:
   15704     case E_V8HImode:
   15705     case E_V16SImode:
   15706     case E_V8SImode:
   15707     case E_V4SImode:
   15708     case E_V2SImode:
   15709     case E_V8DImode:
   15710     case E_V4DImode:
   15711     case E_V2DImode:
   15712       gcc_assert (vect);
   15713       /* FALLTHRU */
   15714     case E_V8HFmode:
   15715     case E_V16HFmode:
   15716     case E_V32HFmode:
   15717     case E_V16SFmode:
   15718     case E_V8SFmode:
   15719     case E_V4SFmode:
   15720     case E_V2SFmode:
   15721     case E_V8DFmode:
   15722     case E_V4DFmode:
   15723     case E_V2DFmode:
   15724       n_elt = GET_MODE_NUNITS (mode);
   15725       v = rtvec_alloc (n_elt);
   15726       scalar_mode = GET_MODE_INNER (mode);
   15727 
   15728       RTVEC_ELT (v, 0) = value;
   15729 
   15730       for (i = 1; i < n_elt; ++i)
   15731 	RTVEC_ELT (v, i) = vect ? value : CONST0_RTX (scalar_mode);
   15732 
   15733       return gen_rtx_CONST_VECTOR (mode, v);
   15734 
   15735     default:
   15736       gcc_unreachable ();
   15737     }
   15738 }
   15739 
   15740 /* A subroutine of ix86_expand_fp_absneg_operator, copysign expanders
   15741    and ix86_expand_int_vcond.  Create a mask for the sign bit in MODE
   15742    for an SSE register.  If VECT is true, then replicate the mask for
   15743    all elements of the vector register.  If INVERT is true, then create
   15744    a mask excluding the sign bit.  */
   15745 
   15746 rtx
   15747 ix86_build_signbit_mask (machine_mode mode, bool vect, bool invert)
   15748 {
   15749   machine_mode vec_mode, imode;
   15750   wide_int w;
   15751   rtx mask, v;
   15752 
   15753   switch (mode)
   15754     {
   15755     case E_V8HFmode:
   15756     case E_V16HFmode:
   15757     case E_V32HFmode:
   15758       vec_mode = mode;
   15759       imode = HImode;
   15760       break;
   15761 
   15762     case E_V16SImode:
   15763     case E_V16SFmode:
   15764     case E_V8SImode:
   15765     case E_V4SImode:
   15766     case E_V8SFmode:
   15767     case E_V4SFmode:
   15768     case E_V2SFmode:
   15769     case E_V2SImode:
   15770       vec_mode = mode;
   15771       imode = SImode;
   15772       break;
   15773 
   15774     case E_V8DImode:
   15775     case E_V4DImode:
   15776     case E_V2DImode:
   15777     case E_V8DFmode:
   15778     case E_V4DFmode:
   15779     case E_V2DFmode:
   15780       vec_mode = mode;
   15781       imode = DImode;
   15782       break;
   15783 
   15784     case E_TImode:
   15785     case E_TFmode:
   15786       vec_mode = VOIDmode;
   15787       imode = TImode;
   15788       break;
   15789 
   15790     default:
   15791       gcc_unreachable ();
   15792     }
   15793 
   15794   machine_mode inner_mode = GET_MODE_INNER (mode);
   15795   w = wi::set_bit_in_zero (GET_MODE_BITSIZE (inner_mode) - 1,
   15796 			   GET_MODE_BITSIZE (inner_mode));
   15797   if (invert)
   15798     w = wi::bit_not (w);
   15799 
   15800   /* Force this value into the low part of a fp vector constant.  */
   15801   mask = immed_wide_int_const (w, imode);
   15802   mask = gen_lowpart (inner_mode, mask);
   15803 
   15804   if (vec_mode == VOIDmode)
   15805     return force_reg (inner_mode, mask);
   15806 
   15807   v = ix86_build_const_vector (vec_mode, vect, mask);
   15808   return force_reg (vec_mode, v);
   15809 }
   15810 
   15811 /* Return TRUE or FALSE depending on whether the first SET in INSN
   15812    has source and destination with matching CC modes, and that the
   15813    CC mode is at least as constrained as REQ_MODE.  */
   15814 
   15815 bool
   15816 ix86_match_ccmode (rtx insn, machine_mode req_mode)
   15817 {
   15818   rtx set;
   15819   machine_mode set_mode;
   15820 
   15821   set = PATTERN (insn);
   15822   if (GET_CODE (set) == PARALLEL)
   15823     set = XVECEXP (set, 0, 0);
   15824   gcc_assert (GET_CODE (set) == SET);
   15825   gcc_assert (GET_CODE (SET_SRC (set)) == COMPARE);
   15826 
   15827   set_mode = GET_MODE (SET_DEST (set));
   15828   switch (set_mode)
   15829     {
   15830     case E_CCNOmode:
   15831       if (req_mode != CCNOmode
   15832 	  && (req_mode != CCmode
   15833 	      || XEXP (SET_SRC (set), 1) != const0_rtx))
   15834 	return false;
   15835       break;
   15836     case E_CCmode:
   15837       if (req_mode == CCGCmode)
   15838 	return false;
   15839       /* FALLTHRU */
   15840     case E_CCGCmode:
   15841       if (req_mode == CCGOCmode || req_mode == CCNOmode)
   15842 	return false;
   15843       /* FALLTHRU */
   15844     case E_CCGOCmode:
   15845       if (req_mode == CCZmode)
   15846 	return false;
   15847       /* FALLTHRU */
   15848     case E_CCZmode:
   15849       break;
   15850 
   15851     case E_CCGZmode:
   15852 
   15853     case E_CCAmode:
   15854     case E_CCCmode:
   15855     case E_CCOmode:
   15856     case E_CCPmode:
   15857     case E_CCSmode:
   15858       if (set_mode != req_mode)
   15859 	return false;
   15860       break;
   15861 
   15862     default:
   15863       gcc_unreachable ();
   15864     }
   15865 
   15866   return GET_MODE (SET_SRC (set)) == set_mode;
   15867 }
   15868 
   15869 machine_mode
   15870 ix86_cc_mode (enum rtx_code code, rtx op0, rtx op1)
   15871 {
   15872   machine_mode mode = GET_MODE (op0);
   15873 
   15874   if (SCALAR_FLOAT_MODE_P (mode))
   15875     {
   15876       gcc_assert (!DECIMAL_FLOAT_MODE_P (mode));
   15877       return CCFPmode;
   15878     }
   15879 
   15880   switch (code)
   15881     {
   15882       /* Only zero flag is needed.  */
   15883     case EQ:			/* ZF=0 */
   15884     case NE:			/* ZF!=0 */
   15885       return CCZmode;
   15886       /* Codes needing carry flag.  */
   15887     case GEU:			/* CF=0 */
   15888     case LTU:			/* CF=1 */
   15889       rtx geu;
   15890       /* Detect overflow checks.  They need just the carry flag.  */
   15891       if (GET_CODE (op0) == PLUS
   15892 	  && (rtx_equal_p (op1, XEXP (op0, 0))
   15893 	      || rtx_equal_p (op1, XEXP (op0, 1))))
   15894 	return CCCmode;
   15895       /* Similarly for *setcc_qi_addqi3_cconly_overflow_1_* patterns.
   15896 	 Match LTU of op0
   15897 	 (neg:QI (geu:QI (reg:CC_CCC FLAGS_REG) (const_int 0)))
   15898 	 and op1
   15899 	 (ltu:QI (reg:CC_CCC FLAGS_REG) (const_int 0))
   15900 	 where CC_CCC is either CC or CCC.  */
   15901       else if (code == LTU
   15902 	       && GET_CODE (op0) == NEG
   15903 	       && GET_CODE (geu = XEXP (op0, 0)) == GEU
   15904 	       && REG_P (XEXP (geu, 0))
   15905 	       && (GET_MODE (XEXP (geu, 0)) == CCCmode
   15906 		   || GET_MODE (XEXP (geu, 0)) == CCmode)
   15907 	       && REGNO (XEXP (geu, 0)) == FLAGS_REG
   15908 	       && XEXP (geu, 1) == const0_rtx
   15909 	       && GET_CODE (op1) == LTU
   15910 	       && REG_P (XEXP (op1, 0))
   15911 	       && GET_MODE (XEXP (op1, 0)) == GET_MODE (XEXP (geu, 0))
   15912 	       && REGNO (XEXP (op1, 0)) == FLAGS_REG
   15913 	       && XEXP (op1, 1) == const0_rtx)
   15914 	return CCCmode;
   15915       else
   15916 	return CCmode;
   15917     case GTU:			/* CF=0 & ZF=0 */
   15918     case LEU:			/* CF=1 | ZF=1 */
   15919       return CCmode;
   15920       /* Codes possibly doable only with sign flag when
   15921          comparing against zero.  */
   15922     case GE:			/* SF=OF   or   SF=0 */
   15923     case LT:			/* SF<>OF  or   SF=1 */
   15924       if (op1 == const0_rtx)
   15925 	return CCGOCmode;
   15926       else
   15927 	/* For other cases Carry flag is not required.  */
   15928 	return CCGCmode;
   15929       /* Codes doable only with sign flag when comparing
   15930          against zero, but we miss jump instruction for it
   15931          so we need to use relational tests against overflow
   15932          that thus needs to be zero.  */
   15933     case GT:			/* ZF=0 & SF=OF */
   15934     case LE:			/* ZF=1 | SF<>OF */
   15935       if (op1 == const0_rtx)
   15936 	return CCNOmode;
   15937       else
   15938 	return CCGCmode;
   15939       /* strcmp pattern do (use flags) and combine may ask us for proper
   15940 	 mode.  */
   15941     case USE:
   15942       return CCmode;
   15943     default:
   15944       gcc_unreachable ();
   15945     }
   15946 }
   15947 
   15948 /* Return the fixed registers used for condition codes.  */
   15949 
   15950 static bool
   15951 ix86_fixed_condition_code_regs (unsigned int *p1, unsigned int *p2)
   15952 {
   15953   *p1 = FLAGS_REG;
   15954   *p2 = INVALID_REGNUM;
   15955   return true;
   15956 }
   15957 
   15958 /* If two condition code modes are compatible, return a condition code
   15959    mode which is compatible with both.  Otherwise, return
   15960    VOIDmode.  */
   15961 
   15962 static machine_mode
   15963 ix86_cc_modes_compatible (machine_mode m1, machine_mode m2)
   15964 {
   15965   if (m1 == m2)
   15966     return m1;
   15967 
   15968   if (GET_MODE_CLASS (m1) != MODE_CC || GET_MODE_CLASS (m2) != MODE_CC)
   15969     return VOIDmode;
   15970 
   15971   if ((m1 == CCGCmode && m2 == CCGOCmode)
   15972       || (m1 == CCGOCmode && m2 == CCGCmode))
   15973     return CCGCmode;
   15974 
   15975   if ((m1 == CCNOmode && m2 == CCGOCmode)
   15976       || (m1 == CCGOCmode && m2 == CCNOmode))
   15977     return CCNOmode;
   15978 
   15979   if (m1 == CCZmode
   15980       && (m2 == CCGCmode || m2 == CCGOCmode || m2 == CCNOmode))
   15981     return m2;
   15982   else if (m2 == CCZmode
   15983 	   && (m1 == CCGCmode || m1 == CCGOCmode || m1 == CCNOmode))
   15984     return m1;
   15985 
   15986   switch (m1)
   15987     {
   15988     default:
   15989       gcc_unreachable ();
   15990 
   15991     case E_CCmode:
   15992     case E_CCGCmode:
   15993     case E_CCGOCmode:
   15994     case E_CCNOmode:
   15995     case E_CCAmode:
   15996     case E_CCCmode:
   15997     case E_CCOmode:
   15998     case E_CCPmode:
   15999     case E_CCSmode:
   16000     case E_CCZmode:
   16001       switch (m2)
   16002 	{
   16003 	default:
   16004 	  return VOIDmode;
   16005 
   16006 	case E_CCmode:
   16007 	case E_CCGCmode:
   16008 	case E_CCGOCmode:
   16009 	case E_CCNOmode:
   16010 	case E_CCAmode:
   16011 	case E_CCCmode:
   16012 	case E_CCOmode:
   16013 	case E_CCPmode:
   16014 	case E_CCSmode:
   16015 	case E_CCZmode:
   16016 	  return CCmode;
   16017 	}
   16018 
   16019     case E_CCFPmode:
   16020       /* These are only compatible with themselves, which we already
   16021 	 checked above.  */
   16022       return VOIDmode;
   16023     }
   16024 }
   16025 
   16026 /* Return strategy to use for floating-point.  We assume that fcomi is always
   16027    preferrable where available, since that is also true when looking at size
   16028    (2 bytes, vs. 3 for fnstsw+sahf and at least 5 for fnstsw+test).  */
   16029 
   16030 enum ix86_fpcmp_strategy
   16031 ix86_fp_comparison_strategy (enum rtx_code)
   16032 {
   16033   /* Do fcomi/sahf based test when profitable.  */
   16034 
   16035   if (TARGET_CMOVE)
   16036     return IX86_FPCMP_COMI;
   16037 
   16038   if (TARGET_SAHF && (TARGET_USE_SAHF || optimize_insn_for_size_p ()))
   16039     return IX86_FPCMP_SAHF;
   16040 
   16041   return IX86_FPCMP_ARITH;
   16042 }
   16043 
   16044 /* Convert comparison codes we use to represent FP comparison to integer
   16045    code that will result in proper branch.  Return UNKNOWN if no such code
   16046    is available.  */
   16047 
   16048 enum rtx_code
   16049 ix86_fp_compare_code_to_integer (enum rtx_code code)
   16050 {
   16051   switch (code)
   16052     {
   16053     case GT:
   16054       return GTU;
   16055     case GE:
   16056       return GEU;
   16057     case ORDERED:
   16058     case UNORDERED:
   16059       return code;
   16060     case UNEQ:
   16061       return EQ;
   16062     case UNLT:
   16063       return LTU;
   16064     case UNLE:
   16065       return LEU;
   16066     case LTGT:
   16067       return NE;
   16068     default:
   16069       return UNKNOWN;
   16070     }
   16071 }
   16072 
   16073 /* Zero extend possibly SImode EXP to Pmode register.  */
   16074 rtx
   16075 ix86_zero_extend_to_Pmode (rtx exp)
   16076 {
   16077   return force_reg (Pmode, convert_to_mode (Pmode, exp, 1));
   16078 }
   16079 
   16080 /* Return true if the function is called via PLT.   */
   16081 
   16082 bool
   16083 ix86_call_use_plt_p (rtx call_op)
   16084 {
   16085   if (SYMBOL_REF_LOCAL_P (call_op))
   16086     {
   16087       if (SYMBOL_REF_DECL (call_op)
   16088 	  && TREE_CODE (SYMBOL_REF_DECL (call_op)) == FUNCTION_DECL)
   16089 	{
   16090 	  /* NB: All ifunc functions must be called via PLT.  */
   16091 	  cgraph_node *node
   16092 	    = cgraph_node::get (SYMBOL_REF_DECL (call_op));
   16093 	  if (node && node->ifunc_resolver)
   16094 	    return true;
   16095 	}
   16096       return false;
   16097     }
   16098   return true;
   16099 }
   16100 
   16101 /* Return true if the function being called was marked with attribute
   16102    "noplt" or using -fno-plt and we are compiling for non-PIC.  We need
   16103    to handle the non-PIC case in the backend because there is no easy
   16104    interface for the front-end to force non-PLT calls to use the GOT.
   16105    This is currently used only with 64-bit or 32-bit GOT32X ELF targets
   16106    to call the function marked "noplt" indirectly.  */
   16107 
   16108 static bool
   16109 ix86_nopic_noplt_attribute_p (rtx call_op)
   16110 {
   16111   if (flag_pic || ix86_cmodel == CM_LARGE
   16112       || !(TARGET_64BIT || HAVE_AS_IX86_GOT32X)
   16113       || TARGET_MACHO || TARGET_SEH || TARGET_PECOFF
   16114       || SYMBOL_REF_LOCAL_P (call_op))
   16115     return false;
   16116 
   16117   tree symbol_decl = SYMBOL_REF_DECL (call_op);
   16118 
   16119   if (!flag_plt
   16120       || (symbol_decl != NULL_TREE
   16121           && lookup_attribute ("noplt", DECL_ATTRIBUTES (symbol_decl))))
   16122     return true;
   16123 
   16124   return false;
   16125 }
   16126 
   16127 /* Helper to output the jmp/call.  */
   16128 static void
   16129 ix86_output_jmp_thunk_or_indirect (const char *thunk_name, const int regno)
   16130 {
   16131   if (thunk_name != NULL)
   16132     {
   16133       if (REX_INT_REGNO_P (regno)
   16134 	  && ix86_indirect_branch_cs_prefix)
   16135 	fprintf (asm_out_file, "\tcs\n");
   16136       fprintf (asm_out_file, "\tjmp\t");
   16137       assemble_name (asm_out_file, thunk_name);
   16138       putc ('\n', asm_out_file);
   16139       if ((ix86_harden_sls & harden_sls_indirect_jmp))
   16140 	fputs ("\tint3\n", asm_out_file);
   16141     }
   16142   else
   16143     output_indirect_thunk (regno);
   16144 }
   16145 
   16146 /* Output indirect branch via a call and return thunk.  CALL_OP is a
   16147    register which contains the branch target.  XASM is the assembly
   16148    template for CALL_OP.  Branch is a tail call if SIBCALL_P is true.
   16149    A normal call is converted to:
   16150 
   16151 	call __x86_indirect_thunk_reg
   16152 
   16153    and a tail call is converted to:
   16154 
   16155 	jmp __x86_indirect_thunk_reg
   16156  */
   16157 
   16158 static void
   16159 ix86_output_indirect_branch_via_reg (rtx call_op, bool sibcall_p)
   16160 {
   16161   char thunk_name_buf[32];
   16162   char *thunk_name;
   16163   enum indirect_thunk_prefix need_prefix
   16164     = indirect_thunk_need_prefix (current_output_insn);
   16165   int regno = REGNO (call_op);
   16166 
   16167   if (cfun->machine->indirect_branch_type
   16168       != indirect_branch_thunk_inline)
   16169     {
   16170       if (cfun->machine->indirect_branch_type == indirect_branch_thunk)
   16171 	SET_HARD_REG_BIT (indirect_thunks_used, regno);
   16172 
   16173       indirect_thunk_name (thunk_name_buf, regno, need_prefix, false);
   16174       thunk_name = thunk_name_buf;
   16175     }
   16176   else
   16177     thunk_name = NULL;
   16178 
   16179   if (sibcall_p)
   16180      ix86_output_jmp_thunk_or_indirect (thunk_name, regno);
   16181   else
   16182     {
   16183       if (thunk_name != NULL)
   16184 	{
   16185 	  if (REX_INT_REGNO_P (regno)
   16186 	      && ix86_indirect_branch_cs_prefix)
   16187 	    fprintf (asm_out_file, "\tcs\n");
   16188 	  fprintf (asm_out_file, "\tcall\t");
   16189 	  assemble_name (asm_out_file, thunk_name);
   16190 	  putc ('\n', asm_out_file);
   16191 	  return;
   16192 	}
   16193 
   16194       char indirectlabel1[32];
   16195       char indirectlabel2[32];
   16196 
   16197       ASM_GENERATE_INTERNAL_LABEL (indirectlabel1,
   16198 				   INDIRECT_LABEL,
   16199 				   indirectlabelno++);
   16200       ASM_GENERATE_INTERNAL_LABEL (indirectlabel2,
   16201 				   INDIRECT_LABEL,
   16202 				   indirectlabelno++);
   16203 
   16204       /* Jump.  */
   16205       fputs ("\tjmp\t", asm_out_file);
   16206       assemble_name_raw (asm_out_file, indirectlabel2);
   16207       fputc ('\n', asm_out_file);
   16208 
   16209       ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, indirectlabel1);
   16210 
   16211      ix86_output_jmp_thunk_or_indirect (thunk_name, regno);
   16212 
   16213       ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, indirectlabel2);
   16214 
   16215       /* Call.  */
   16216       fputs ("\tcall\t", asm_out_file);
   16217       assemble_name_raw (asm_out_file, indirectlabel1);
   16218       fputc ('\n', asm_out_file);
   16219     }
   16220 }
   16221 
   16222 /* Output indirect branch via a call and return thunk.  CALL_OP is
   16223    the branch target.  XASM is the assembly template for CALL_OP.
   16224    Branch is a tail call if SIBCALL_P is true.  A normal call is
   16225    converted to:
   16226 
   16227 	jmp L2
   16228    L1:
   16229 	push CALL_OP
   16230 	jmp __x86_indirect_thunk
   16231    L2:
   16232 	call L1
   16233 
   16234    and a tail call is converted to:
   16235 
   16236 	push CALL_OP
   16237 	jmp __x86_indirect_thunk
   16238  */
   16239 
   16240 static void
   16241 ix86_output_indirect_branch_via_push (rtx call_op, const char *xasm,
   16242 				      bool sibcall_p)
   16243 {
   16244   char thunk_name_buf[32];
   16245   char *thunk_name;
   16246   char push_buf[64];
   16247   enum indirect_thunk_prefix need_prefix
   16248     = indirect_thunk_need_prefix (current_output_insn);
   16249   int regno = -1;
   16250 
   16251   if (cfun->machine->indirect_branch_type
   16252       != indirect_branch_thunk_inline)
   16253     {
   16254       if (cfun->machine->indirect_branch_type == indirect_branch_thunk)
   16255 	indirect_thunk_needed = true;
   16256       indirect_thunk_name (thunk_name_buf, regno, need_prefix, false);
   16257       thunk_name = thunk_name_buf;
   16258     }
   16259   else
   16260     thunk_name = NULL;
   16261 
   16262   snprintf (push_buf, sizeof (push_buf), "push{%c}\t%s",
   16263 	    TARGET_64BIT ? 'q' : 'l', xasm);
   16264 
   16265   if (sibcall_p)
   16266     {
   16267       output_asm_insn (push_buf, &call_op);
   16268       ix86_output_jmp_thunk_or_indirect (thunk_name, regno);
   16269     }
   16270   else
   16271     {
   16272       char indirectlabel1[32];
   16273       char indirectlabel2[32];
   16274 
   16275       ASM_GENERATE_INTERNAL_LABEL (indirectlabel1,
   16276 				   INDIRECT_LABEL,
   16277 				   indirectlabelno++);
   16278       ASM_GENERATE_INTERNAL_LABEL (indirectlabel2,
   16279 				   INDIRECT_LABEL,
   16280 				   indirectlabelno++);
   16281 
   16282       /* Jump.  */
   16283       fputs ("\tjmp\t", asm_out_file);
   16284       assemble_name_raw (asm_out_file, indirectlabel2);
   16285       fputc ('\n', asm_out_file);
   16286 
   16287       ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, indirectlabel1);
   16288 
   16289       /* An external function may be called via GOT, instead of PLT.  */
   16290       if (MEM_P (call_op))
   16291 	{
   16292 	  struct ix86_address parts;
   16293 	  rtx addr = XEXP (call_op, 0);
   16294 	  if (ix86_decompose_address (addr, &parts)
   16295 	      && parts.base == stack_pointer_rtx)
   16296 	    {
   16297 	      /* Since call will adjust stack by -UNITS_PER_WORD,
   16298 		 we must convert "disp(stack, index, scale)" to
   16299 		 "disp+UNITS_PER_WORD(stack, index, scale)".  */
   16300 	      if (parts.index)
   16301 		{
   16302 		  addr = gen_rtx_MULT (Pmode, parts.index,
   16303 				       GEN_INT (parts.scale));
   16304 		  addr = gen_rtx_PLUS (Pmode, stack_pointer_rtx,
   16305 				       addr);
   16306 		}
   16307 	      else
   16308 		addr = stack_pointer_rtx;
   16309 
   16310 	      rtx disp;
   16311 	      if (parts.disp != NULL_RTX)
   16312 		disp = plus_constant (Pmode, parts.disp,
   16313 				      UNITS_PER_WORD);
   16314 	      else
   16315 		disp = GEN_INT (UNITS_PER_WORD);
   16316 
   16317 	      addr = gen_rtx_PLUS (Pmode, addr, disp);
   16318 	      call_op = gen_rtx_MEM (GET_MODE (call_op), addr);
   16319 	    }
   16320 	}
   16321 
   16322       output_asm_insn (push_buf, &call_op);
   16323 
   16324       ix86_output_jmp_thunk_or_indirect (thunk_name, regno);
   16325 
   16326       ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, indirectlabel2);
   16327 
   16328       /* Call.  */
   16329       fputs ("\tcall\t", asm_out_file);
   16330       assemble_name_raw (asm_out_file, indirectlabel1);
   16331       fputc ('\n', asm_out_file);
   16332     }
   16333 }
   16334 
   16335 /* Output indirect branch via a call and return thunk.  CALL_OP is
   16336    the branch target.  XASM is the assembly template for CALL_OP.
   16337    Branch is a tail call if SIBCALL_P is true.   */
   16338 
   16339 static void
   16340 ix86_output_indirect_branch (rtx call_op, const char *xasm,
   16341 			     bool sibcall_p)
   16342 {
   16343   if (REG_P (call_op))
   16344     ix86_output_indirect_branch_via_reg (call_op, sibcall_p);
   16345   else
   16346     ix86_output_indirect_branch_via_push (call_op, xasm, sibcall_p);
   16347 }
   16348 
   16349 /* Output indirect jump.  CALL_OP is the jump target.  */
   16350 
   16351 const char *
   16352 ix86_output_indirect_jmp (rtx call_op)
   16353 {
   16354   if (cfun->machine->indirect_branch_type != indirect_branch_keep)
   16355     {
   16356       /* We can't have red-zone since "call" in the indirect thunk
   16357          pushes the return address onto stack, destroying red-zone.  */
   16358       if (ix86_red_zone_used)
   16359 	gcc_unreachable ();
   16360 
   16361       ix86_output_indirect_branch (call_op, "%0", true);
   16362     }
   16363   else
   16364     output_asm_insn ("%!jmp\t%A0", &call_op);
   16365   return (ix86_harden_sls & harden_sls_indirect_jmp) ? "int3" : "";
   16366 }
   16367 
   16368 /* Output return instrumentation for current function if needed.  */
   16369 
   16370 static void
   16371 output_return_instrumentation (void)
   16372 {
   16373   if (ix86_instrument_return != instrument_return_none
   16374       && flag_fentry
   16375       && !DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (cfun->decl))
   16376     {
   16377       if (ix86_flag_record_return)
   16378 	fprintf (asm_out_file, "1:\n");
   16379       switch (ix86_instrument_return)
   16380 	{
   16381 	case instrument_return_call:
   16382 	  fprintf (asm_out_file, "\tcall\t__return__\n");
   16383 	  break;
   16384 	case instrument_return_nop5:
   16385 	  /* 5 byte nop: nopl 0(%[re]ax,%[re]ax,1)  */
   16386 	  fprintf (asm_out_file, ASM_BYTE "0x0f, 0x1f, 0x44, 0x00, 0x00\n");
   16387 	  break;
   16388 	case instrument_return_none:
   16389 	  break;
   16390 	}
   16391 
   16392       if (ix86_flag_record_return)
   16393 	{
   16394 	  fprintf (asm_out_file, "\t.section __return_loc, \"a\",@progbits\n");
   16395 	  fprintf (asm_out_file, "\t.%s 1b\n", TARGET_64BIT ? "quad" : "long");
   16396 	  fprintf (asm_out_file, "\t.previous\n");
   16397 	}
   16398     }
   16399 }
   16400 
   16401 /* Output function return.  CALL_OP is the jump target.  Add a REP
   16402    prefix to RET if LONG_P is true and function return is kept.  */
   16403 
   16404 const char *
   16405 ix86_output_function_return (bool long_p)
   16406 {
   16407   output_return_instrumentation ();
   16408 
   16409   if (cfun->machine->function_return_type != indirect_branch_keep)
   16410     {
   16411       char thunk_name[32];
   16412       enum indirect_thunk_prefix need_prefix
   16413 	= indirect_thunk_need_prefix (current_output_insn);
   16414 
   16415       if (cfun->machine->function_return_type
   16416 	  != indirect_branch_thunk_inline)
   16417 	{
   16418 	  bool need_thunk = (cfun->machine->function_return_type
   16419 			     == indirect_branch_thunk);
   16420 	  indirect_thunk_name (thunk_name, INVALID_REGNUM, need_prefix,
   16421 			       true);
   16422 	  indirect_return_needed |= need_thunk;
   16423 	  fprintf (asm_out_file, "\tjmp\t");
   16424 	  assemble_name (asm_out_file, thunk_name);
   16425 	  putc ('\n', asm_out_file);
   16426 	}
   16427       else
   16428 	output_indirect_thunk (INVALID_REGNUM);
   16429 
   16430       return "";
   16431     }
   16432 
   16433   output_asm_insn (long_p ? "rep%; ret" : "ret", nullptr);
   16434   return (ix86_harden_sls & harden_sls_return) ? "int3" : "";
   16435 }
   16436 
   16437 /* Output indirect function return.  RET_OP is the function return
   16438    target.  */
   16439 
   16440 const char *
   16441 ix86_output_indirect_function_return (rtx ret_op)
   16442 {
   16443   if (cfun->machine->function_return_type != indirect_branch_keep)
   16444     {
   16445       char thunk_name[32];
   16446       enum indirect_thunk_prefix need_prefix
   16447 	= indirect_thunk_need_prefix (current_output_insn);
   16448       unsigned int regno = REGNO (ret_op);
   16449       gcc_assert (regno == CX_REG);
   16450 
   16451       if (cfun->machine->function_return_type
   16452 	  != indirect_branch_thunk_inline)
   16453 	{
   16454 	  bool need_thunk = (cfun->machine->function_return_type
   16455 			     == indirect_branch_thunk);
   16456 	  indirect_thunk_name (thunk_name, regno, need_prefix, true);
   16457 
   16458 	  if (need_thunk)
   16459 	    {
   16460 	      indirect_return_via_cx = true;
   16461 	      SET_HARD_REG_BIT (indirect_thunks_used, CX_REG);
   16462 	    }
   16463 	  fprintf (asm_out_file, "\tjmp\t");
   16464 	  assemble_name (asm_out_file, thunk_name);
   16465 	  putc ('\n', asm_out_file);
   16466 	}
   16467       else
   16468 	output_indirect_thunk (regno);
   16469     }
   16470   else
   16471     {
   16472       output_asm_insn ("%!jmp\t%A0", &ret_op);
   16473       if (ix86_harden_sls & harden_sls_indirect_jmp)
   16474 	fputs ("\tint3\n", asm_out_file);
   16475     }
   16476   return "";
   16477 }
   16478 
   16479 /* Output the assembly for a call instruction.  */
   16480 
   16481 const char *
   16482 ix86_output_call_insn (rtx_insn *insn, rtx call_op)
   16483 {
   16484   bool direct_p = constant_call_address_operand (call_op, VOIDmode);
   16485   bool output_indirect_p
   16486     = (!TARGET_SEH
   16487        && cfun->machine->indirect_branch_type != indirect_branch_keep);
   16488   bool seh_nop_p = false;
   16489   const char *xasm;
   16490 
   16491   if (SIBLING_CALL_P (insn))
   16492     {
   16493       output_return_instrumentation ();
   16494       if (direct_p)
   16495 	{
   16496 	  if (ix86_nopic_noplt_attribute_p (call_op))
   16497 	    {
   16498 	      direct_p = false;
   16499 	      if (TARGET_64BIT)
   16500 		{
   16501 		  if (output_indirect_p)
   16502 		    xasm = "{%p0@GOTPCREL(%%rip)|[QWORD PTR %p0@GOTPCREL[rip]]}";
   16503 		  else
   16504 		    xasm = "%!jmp\t{*%p0@GOTPCREL(%%rip)|[QWORD PTR %p0@GOTPCREL[rip]]}";
   16505 		}
   16506 	      else
   16507 		{
   16508 		  if (output_indirect_p)
   16509 		    xasm = "{%p0@GOT|[DWORD PTR %p0@GOT]}";
   16510 		  else
   16511 		    xasm = "%!jmp\t{*%p0@GOT|[DWORD PTR %p0@GOT]}";
   16512 		}
   16513 	    }
   16514 	  else
   16515 	    xasm = "%!jmp\t%P0";
   16516 	}
   16517       /* SEH epilogue detection requires the indirect branch case
   16518 	 to include REX.W.  */
   16519       else if (TARGET_SEH)
   16520 	xasm = "%!rex.W jmp\t%A0";
   16521       else
   16522 	{
   16523 	  if (output_indirect_p)
   16524 	    xasm = "%0";
   16525 	  else
   16526 	    xasm = "%!jmp\t%A0";
   16527 	}
   16528 
   16529       if (output_indirect_p && !direct_p)
   16530 	ix86_output_indirect_branch (call_op, xasm, true);
   16531       else
   16532 	{
   16533 	  output_asm_insn (xasm, &call_op);
   16534 	  if (!direct_p
   16535 	      && (ix86_harden_sls & harden_sls_indirect_jmp))
   16536 	    return "int3";
   16537 	}
   16538       return "";
   16539     }
   16540 
   16541   /* SEH unwinding can require an extra nop to be emitted in several
   16542      circumstances.  Determine if we have one of those.  */
   16543   if (TARGET_SEH)
   16544     {
   16545       rtx_insn *i;
   16546 
   16547       for (i = NEXT_INSN (insn); i ; i = NEXT_INSN (i))
   16548 	{
   16549 	  /* Prevent a catch region from being adjacent to a jump that would
   16550 	     be interpreted as an epilogue sequence by the unwinder.  */
   16551 	  if (JUMP_P(i) && CROSSING_JUMP_P (i))
   16552 	    {
   16553 	      seh_nop_p = true;
   16554 	      break;
   16555 	    }
   16556 
   16557 	  /* If we get to another real insn, we don't need the nop.  */
   16558 	  if (INSN_P (i))
   16559 	    break;
   16560 
   16561 	  /* If we get to the epilogue note, prevent a catch region from
   16562 	     being adjacent to the standard epilogue sequence.  Note that,
   16563 	     if non-call exceptions are enabled, we already did it during
   16564 	     epilogue expansion, or else, if the insn can throw internally,
   16565 	     we already did it during the reorg pass.  */
   16566 	  if (NOTE_P (i) && NOTE_KIND (i) == NOTE_INSN_EPILOGUE_BEG
   16567 	      && !flag_non_call_exceptions
   16568 	      && !can_throw_internal (insn))
   16569 	    {
   16570 	      seh_nop_p = true;
   16571 	      break;
   16572 	    }
   16573 	}
   16574 
   16575       /* If we didn't find a real insn following the call, prevent the
   16576 	 unwinder from looking into the next function.  */
   16577       if (i == NULL)
   16578 	seh_nop_p = true;
   16579     }
   16580 
   16581   if (direct_p)
   16582     {
   16583       if (ix86_nopic_noplt_attribute_p (call_op))
   16584 	{
   16585 	  direct_p = false;
   16586 	  if (TARGET_64BIT)
   16587 	    {
   16588 	      if (output_indirect_p)
   16589 		xasm = "{%p0@GOTPCREL(%%rip)|[QWORD PTR %p0@GOTPCREL[rip]]}";
   16590 	      else
   16591 		xasm = "%!call\t{*%p0@GOTPCREL(%%rip)|[QWORD PTR %p0@GOTPCREL[rip]]}";
   16592 	    }
   16593 	  else
   16594 	    {
   16595 	      if (output_indirect_p)
   16596 		xasm = "{%p0@GOT|[DWORD PTR %p0@GOT]}";
   16597 	      else
   16598 		xasm = "%!call\t{*%p0@GOT|[DWORD PTR %p0@GOT]}";
   16599 	    }
   16600 	}
   16601       else
   16602 	xasm = "%!call\t%P0";
   16603     }
   16604   else
   16605     {
   16606       if (output_indirect_p)
   16607 	xasm = "%0";
   16608       else
   16609 	xasm = "%!call\t%A0";
   16610     }
   16611 
   16612   if (output_indirect_p && !direct_p)
   16613     ix86_output_indirect_branch (call_op, xasm, false);
   16614   else
   16615     output_asm_insn (xasm, &call_op);
   16616 
   16617   if (seh_nop_p)
   16618     return "nop";
   16619 
   16620   return "";
   16621 }
   16622 
   16623 /* Return a MEM corresponding to a stack slot with mode MODE.
   16625    Allocate a new slot if necessary.
   16626 
   16627    The RTL for a function can have several slots available: N is
   16628    which slot to use.  */
   16629 
   16630 rtx
   16631 assign_386_stack_local (machine_mode mode, enum ix86_stack_slot n)
   16632 {
   16633   struct stack_local_entry *s;
   16634 
   16635   gcc_assert (n < MAX_386_STACK_LOCALS);
   16636 
   16637   for (s = ix86_stack_locals; s; s = s->next)
   16638     if (s->mode == mode && s->n == n)
   16639       return validize_mem (copy_rtx (s->rtl));
   16640 
   16641   int align = 0;
   16642   /* For DImode with SLOT_FLOATxFDI_387 use 32-bit
   16643      alignment with -m32 -mpreferred-stack-boundary=2.  */
   16644   if (mode == DImode
   16645       && !TARGET_64BIT
   16646       && n == SLOT_FLOATxFDI_387
   16647       && ix86_preferred_stack_boundary < GET_MODE_ALIGNMENT (DImode))
   16648     align = 32;
   16649   s = ggc_alloc<stack_local_entry> ();
   16650   s->n = n;
   16651   s->mode = mode;
   16652   s->rtl = assign_stack_local (mode, GET_MODE_SIZE (mode), align);
   16653 
   16654   s->next = ix86_stack_locals;
   16655   ix86_stack_locals = s;
   16656   return validize_mem (copy_rtx (s->rtl));
   16657 }
   16658 
   16659 static void
   16660 ix86_instantiate_decls (void)
   16661 {
   16662   struct stack_local_entry *s;
   16663 
   16664   for (s = ix86_stack_locals; s; s = s->next)
   16665     if (s->rtl != NULL_RTX)
   16666       instantiate_decl_rtl (s->rtl);
   16667 }
   16668 
   16669 /* Check whether x86 address PARTS is a pc-relative address.  */
   16671 
   16672 bool
   16673 ix86_rip_relative_addr_p (struct ix86_address *parts)
   16674 {
   16675   rtx base, index, disp;
   16676 
   16677   base = parts->base;
   16678   index = parts->index;
   16679   disp = parts->disp;
   16680 
   16681   if (disp && !base && !index)
   16682     {
   16683       if (TARGET_64BIT)
   16684 	{
   16685 	  rtx symbol = disp;
   16686 
   16687 	  if (GET_CODE (disp) == CONST)
   16688 	    symbol = XEXP (disp, 0);
   16689 	  if (GET_CODE (symbol) == PLUS
   16690 	      && CONST_INT_P (XEXP (symbol, 1)))
   16691 	    symbol = XEXP (symbol, 0);
   16692 
   16693 	  if (GET_CODE (symbol) == LABEL_REF
   16694 	      || (GET_CODE (symbol) == SYMBOL_REF
   16695 		  && SYMBOL_REF_TLS_MODEL (symbol) == 0)
   16696 	      || (GET_CODE (symbol) == UNSPEC
   16697 		  && (XINT (symbol, 1) == UNSPEC_GOTPCREL
   16698 		      || XINT (symbol, 1) == UNSPEC_PCREL
   16699 		      || XINT (symbol, 1) == UNSPEC_GOTNTPOFF)))
   16700 	    return true;
   16701 	}
   16702     }
   16703   return false;
   16704 }
   16705 
   16706 /* Calculate the length of the memory address in the instruction encoding.
   16707    Includes addr32 prefix, does not include the one-byte modrm, opcode,
   16708    or other prefixes.  We never generate addr32 prefix for LEA insn.  */
   16709 
   16710 int
   16711 memory_address_length (rtx addr, bool lea)
   16712 {
   16713   struct ix86_address parts;
   16714   rtx base, index, disp;
   16715   int len;
   16716   int ok;
   16717 
   16718   if (GET_CODE (addr) == PRE_DEC
   16719       || GET_CODE (addr) == POST_INC
   16720       || GET_CODE (addr) == PRE_MODIFY
   16721       || GET_CODE (addr) == POST_MODIFY)
   16722     return 0;
   16723 
   16724   ok = ix86_decompose_address (addr, &parts);
   16725   gcc_assert (ok);
   16726 
   16727   len = (parts.seg == ADDR_SPACE_GENERIC) ? 0 : 1;
   16728 
   16729   /*  If this is not LEA instruction, add the length of addr32 prefix.  */
   16730   if (TARGET_64BIT && !lea
   16731       && (SImode_address_operand (addr, VOIDmode)
   16732 	  || (parts.base && GET_MODE (parts.base) == SImode)
   16733 	  || (parts.index && GET_MODE (parts.index) == SImode)))
   16734     len++;
   16735 
   16736   base = parts.base;
   16737   index = parts.index;
   16738   disp = parts.disp;
   16739 
   16740   if (base && SUBREG_P (base))
   16741     base = SUBREG_REG (base);
   16742   if (index && SUBREG_P (index))
   16743     index = SUBREG_REG (index);
   16744 
   16745   gcc_assert (base == NULL_RTX || REG_P (base));
   16746   gcc_assert (index == NULL_RTX || REG_P (index));
   16747 
   16748   /* Rule of thumb:
   16749        - esp as the base always wants an index,
   16750        - ebp as the base always wants a displacement,
   16751        - r12 as the base always wants an index,
   16752        - r13 as the base always wants a displacement.  */
   16753 
   16754   /* Register Indirect.  */
   16755   if (base && !index && !disp)
   16756     {
   16757       /* esp (for its index) and ebp (for its displacement) need
   16758 	 the two-byte modrm form.  Similarly for r12 and r13 in 64-bit
   16759 	 code.  */
   16760       if (base == arg_pointer_rtx
   16761 	  || base == frame_pointer_rtx
   16762 	  || REGNO (base) == SP_REG
   16763 	  || REGNO (base) == BP_REG
   16764 	  || REGNO (base) == R12_REG
   16765 	  || REGNO (base) == R13_REG)
   16766 	len++;
   16767     }
   16768 
   16769   /* Direct Addressing.  In 64-bit mode mod 00 r/m 5
   16770      is not disp32, but disp32(%rip), so for disp32
   16771      SIB byte is needed, unless print_operand_address
   16772      optimizes it into disp32(%rip) or (%rip) is implied
   16773      by UNSPEC.  */
   16774   else if (disp && !base && !index)
   16775     {
   16776       len += 4;
   16777       if (!ix86_rip_relative_addr_p (&parts))
   16778 	len++;
   16779     }
   16780   else
   16781     {
   16782       /* Find the length of the displacement constant.  */
   16783       if (disp)
   16784 	{
   16785 	  if (base && satisfies_constraint_K (disp))
   16786 	    len += 1;
   16787 	  else
   16788 	    len += 4;
   16789 	}
   16790       /* ebp always wants a displacement.  Similarly r13.  */
   16791       else if (base && (REGNO (base) == BP_REG || REGNO (base) == R13_REG))
   16792 	len++;
   16793 
   16794       /* An index requires the two-byte modrm form....  */
   16795       if (index
   16796 	  /* ...like esp (or r12), which always wants an index.  */
   16797 	  || base == arg_pointer_rtx
   16798 	  || base == frame_pointer_rtx
   16799 	  || (base && (REGNO (base) == SP_REG || REGNO (base) == R12_REG)))
   16800 	len++;
   16801     }
   16802 
   16803   return len;
   16804 }
   16805 
   16806 /* Compute default value for "length_immediate" attribute.  When SHORTFORM
   16807    is set, expect that insn have 8bit immediate alternative.  */
   16808 int
   16809 ix86_attr_length_immediate_default (rtx_insn *insn, bool shortform)
   16810 {
   16811   int len = 0;
   16812   int i;
   16813   extract_insn_cached (insn);
   16814   for (i = recog_data.n_operands - 1; i >= 0; --i)
   16815     if (CONSTANT_P (recog_data.operand[i]))
   16816       {
   16817         enum attr_mode mode = get_attr_mode (insn);
   16818 
   16819 	gcc_assert (!len);
   16820 	if (shortform && CONST_INT_P (recog_data.operand[i]))
   16821 	  {
   16822 	    HOST_WIDE_INT ival = INTVAL (recog_data.operand[i]);
   16823 	    switch (mode)
   16824 	      {
   16825 	      case MODE_QI:
   16826 		len = 1;
   16827 		continue;
   16828 	      case MODE_HI:
   16829 		ival = trunc_int_for_mode (ival, HImode);
   16830 		break;
   16831 	      case MODE_SI:
   16832 		ival = trunc_int_for_mode (ival, SImode);
   16833 		break;
   16834 	      default:
   16835 		break;
   16836 	      }
   16837 	    if (IN_RANGE (ival, -128, 127))
   16838 	      {
   16839 		len = 1;
   16840 		continue;
   16841 	      }
   16842 	  }
   16843 	switch (mode)
   16844 	  {
   16845 	  case MODE_QI:
   16846 	    len = 1;
   16847 	    break;
   16848 	  case MODE_HI:
   16849 	    len = 2;
   16850 	    break;
   16851 	  case MODE_SI:
   16852 	    len = 4;
   16853 	    break;
   16854 	  /* Immediates for DImode instructions are encoded
   16855 	     as 32bit sign extended values.  */
   16856 	  case MODE_DI:
   16857 	    len = 4;
   16858 	    break;
   16859 	  default:
   16860 	    fatal_insn ("unknown insn mode", insn);
   16861 	}
   16862       }
   16863   return len;
   16864 }
   16865 
   16866 /* Compute default value for "length_address" attribute.  */
   16867 int
   16868 ix86_attr_length_address_default (rtx_insn *insn)
   16869 {
   16870   int i;
   16871 
   16872   if (get_attr_type (insn) == TYPE_LEA)
   16873     {
   16874       rtx set = PATTERN (insn), addr;
   16875 
   16876       if (GET_CODE (set) == PARALLEL)
   16877 	set = XVECEXP (set, 0, 0);
   16878 
   16879       gcc_assert (GET_CODE (set) == SET);
   16880 
   16881       addr = SET_SRC (set);
   16882 
   16883       return memory_address_length (addr, true);
   16884     }
   16885 
   16886   extract_insn_cached (insn);
   16887   for (i = recog_data.n_operands - 1; i >= 0; --i)
   16888     {
   16889       rtx op = recog_data.operand[i];
   16890       if (MEM_P (op))
   16891 	{
   16892 	  constrain_operands_cached (insn, reload_completed);
   16893 	  if (which_alternative != -1)
   16894 	    {
   16895 	      const char *constraints = recog_data.constraints[i];
   16896 	      int alt = which_alternative;
   16897 
   16898 	      while (*constraints == '=' || *constraints == '+')
   16899 		constraints++;
   16900 	      while (alt-- > 0)
   16901 	        while (*constraints++ != ',')
   16902 		  ;
   16903 	      /* Skip ignored operands.  */
   16904 	      if (*constraints == 'X')
   16905 		continue;
   16906 	    }
   16907 
   16908 	  int len = memory_address_length (XEXP (op, 0), false);
   16909 
   16910 	  /* Account for segment prefix for non-default addr spaces.  */
   16911 	  if (!ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (op)))
   16912 	    len++;
   16913 
   16914 	  return len;
   16915 	}
   16916     }
   16917   return 0;
   16918 }
   16919 
   16920 /* Compute default value for "length_vex" attribute. It includes
   16921    2 or 3 byte VEX prefix and 1 opcode byte.  */
   16922 
   16923 int
   16924 ix86_attr_length_vex_default (rtx_insn *insn, bool has_0f_opcode,
   16925 			      bool has_vex_w)
   16926 {
   16927   int i;
   16928 
   16929   /* Only 0f opcode can use 2 byte VEX prefix and  VEX W bit uses 3
   16930      byte VEX prefix.  */
   16931   if (!has_0f_opcode || has_vex_w)
   16932     return 3 + 1;
   16933 
   16934  /* We can always use 2 byte VEX prefix in 32bit.  */
   16935   if (!TARGET_64BIT)
   16936     return 2 + 1;
   16937 
   16938   extract_insn_cached (insn);
   16939 
   16940   for (i = recog_data.n_operands - 1; i >= 0; --i)
   16941     if (REG_P (recog_data.operand[i]))
   16942       {
   16943 	/* REX.W bit uses 3 byte VEX prefix.  */
   16944 	if (GET_MODE (recog_data.operand[i]) == DImode
   16945 	    && GENERAL_REG_P (recog_data.operand[i]))
   16946 	  return 3 + 1;
   16947       }
   16948     else
   16949       {
   16950 	/* REX.X or REX.B bits use 3 byte VEX prefix.  */
   16951 	if (MEM_P (recog_data.operand[i])
   16952 	    && x86_extended_reg_mentioned_p (recog_data.operand[i]))
   16953 	  return 3 + 1;
   16954       }
   16955 
   16956   return 2 + 1;
   16957 }
   16958 
   16959 
   16961 static bool
   16962 ix86_class_likely_spilled_p (reg_class_t);
   16963 
   16964 /* Returns true if lhs of insn is HW function argument register and set up
   16965    is_spilled to true if it is likely spilled HW register.  */
   16966 static bool
   16967 insn_is_function_arg (rtx insn, bool* is_spilled)
   16968 {
   16969   rtx dst;
   16970 
   16971   if (!NONDEBUG_INSN_P (insn))
   16972     return false;
   16973   /* Call instructions are not movable, ignore it.  */
   16974   if (CALL_P (insn))
   16975     return false;
   16976   insn = PATTERN (insn);
   16977   if (GET_CODE (insn) == PARALLEL)
   16978     insn = XVECEXP (insn, 0, 0);
   16979   if (GET_CODE (insn) != SET)
   16980     return false;
   16981   dst = SET_DEST (insn);
   16982   if (REG_P (dst) && HARD_REGISTER_P (dst)
   16983       && ix86_function_arg_regno_p (REGNO (dst)))
   16984     {
   16985       /* Is it likely spilled HW register?  */
   16986       if (!TEST_HARD_REG_BIT (fixed_reg_set, REGNO (dst))
   16987 	  && ix86_class_likely_spilled_p (REGNO_REG_CLASS (REGNO (dst))))
   16988 	*is_spilled = true;
   16989       return true;
   16990     }
   16991   return false;
   16992 }
   16993 
   16994 /* Add output dependencies for chain of function adjacent arguments if only
   16995    there is a move to likely spilled HW register.  Return first argument
   16996    if at least one dependence was added or NULL otherwise.  */
   16997 static rtx_insn *
   16998 add_parameter_dependencies (rtx_insn *call, rtx_insn *head)
   16999 {
   17000   rtx_insn *insn;
   17001   rtx_insn *last = call;
   17002   rtx_insn *first_arg = NULL;
   17003   bool is_spilled = false;
   17004 
   17005   head = PREV_INSN (head);
   17006 
   17007   /* Find nearest to call argument passing instruction.  */
   17008   while (true)
   17009     {
   17010       last = PREV_INSN (last);
   17011       if (last == head)
   17012 	return NULL;
   17013       if (!NONDEBUG_INSN_P (last))
   17014 	continue;
   17015       if (insn_is_function_arg (last, &is_spilled))
   17016 	break;
   17017       return NULL;
   17018     }
   17019 
   17020   first_arg = last;
   17021   while (true)
   17022     {
   17023       insn = PREV_INSN (last);
   17024       if (!INSN_P (insn))
   17025 	break;
   17026       if (insn == head)
   17027 	break;
   17028       if (!NONDEBUG_INSN_P (insn))
   17029 	{
   17030 	  last = insn;
   17031 	  continue;
   17032 	}
   17033       if (insn_is_function_arg (insn, &is_spilled))
   17034 	{
   17035 	  /* Add output depdendence between two function arguments if chain
   17036 	     of output arguments contains likely spilled HW registers.  */
   17037 	  if (is_spilled)
   17038 	    add_dependence (first_arg, insn, REG_DEP_OUTPUT);
   17039 	  first_arg = last = insn;
   17040 	}
   17041       else
   17042 	break;
   17043     }
   17044   if (!is_spilled)
   17045     return NULL;
   17046   return first_arg;
   17047 }
   17048 
   17049 /* Add output or anti dependency from insn to first_arg to restrict its code
   17050    motion.  */
   17051 static void
   17052 avoid_func_arg_motion (rtx_insn *first_arg, rtx_insn *insn)
   17053 {
   17054   rtx set;
   17055   rtx tmp;
   17056 
   17057   set = single_set (insn);
   17058   if (!set)
   17059     return;
   17060   tmp = SET_DEST (set);
   17061   if (REG_P (tmp))
   17062     {
   17063       /* Add output dependency to the first function argument.  */
   17064       add_dependence (first_arg, insn, REG_DEP_OUTPUT);
   17065       return;
   17066     }
   17067   /* Add anti dependency.  */
   17068   add_dependence (first_arg, insn, REG_DEP_ANTI);
   17069 }
   17070 
   17071 /* Avoid cross block motion of function argument through adding dependency
   17072    from the first non-jump instruction in bb.  */
   17073 static void
   17074 add_dependee_for_func_arg (rtx_insn *arg, basic_block bb)
   17075 {
   17076   rtx_insn *insn = BB_END (bb);
   17077 
   17078   while (insn)
   17079     {
   17080       if (NONDEBUG_INSN_P (insn) && NONJUMP_INSN_P (insn))
   17081 	{
   17082 	  rtx set = single_set (insn);
   17083 	  if (set)
   17084 	    {
   17085 	      avoid_func_arg_motion (arg, insn);
   17086 	      return;
   17087 	    }
   17088 	}
   17089       if (insn == BB_HEAD (bb))
   17090 	return;
   17091       insn = PREV_INSN (insn);
   17092     }
   17093 }
   17094 
   17095 /* Hook for pre-reload schedule - avoid motion of function arguments
   17096    passed in likely spilled HW registers.  */
   17097 static void
   17098 ix86_dependencies_evaluation_hook (rtx_insn *head, rtx_insn *tail)
   17099 {
   17100   rtx_insn *insn;
   17101   rtx_insn *first_arg = NULL;
   17102   if (reload_completed)
   17103     return;
   17104   while (head != tail && DEBUG_INSN_P (head))
   17105     head = NEXT_INSN (head);
   17106   for (insn = tail; insn != head; insn = PREV_INSN (insn))
   17107     if (INSN_P (insn) && CALL_P (insn))
   17108       {
   17109 	first_arg = add_parameter_dependencies (insn, head);
   17110 	if (first_arg)
   17111 	  {
   17112 	    /* Add dependee for first argument to predecessors if only
   17113 	       region contains more than one block.  */
   17114 	    basic_block bb =  BLOCK_FOR_INSN (insn);
   17115 	    int rgn = CONTAINING_RGN (bb->index);
   17116 	    int nr_blks = RGN_NR_BLOCKS (rgn);
   17117 	    /* Skip trivial regions and region head blocks that can have
   17118 	       predecessors outside of region.  */
   17119 	    if (nr_blks > 1 && BLOCK_TO_BB (bb->index) != 0)
   17120 	      {
   17121 		edge e;
   17122 		edge_iterator ei;
   17123 
   17124 		/* Regions are SCCs with the exception of selective
   17125 		   scheduling with pipelining of outer blocks enabled.
   17126 		   So also check that immediate predecessors of a non-head
   17127 		   block are in the same region.  */
   17128 		FOR_EACH_EDGE (e, ei, bb->preds)
   17129 		  {
   17130 		    /* Avoid creating of loop-carried dependencies through
   17131 		       using topological ordering in the region.  */
   17132 		    if (rgn == CONTAINING_RGN (e->src->index)
   17133 			&& BLOCK_TO_BB (bb->index) > BLOCK_TO_BB (e->src->index))
   17134 		      add_dependee_for_func_arg (first_arg, e->src);
   17135 		  }
   17136 	      }
   17137 	    insn = first_arg;
   17138 	    if (insn == head)
   17139 	      break;
   17140 	  }
   17141       }
   17142     else if (first_arg)
   17143       avoid_func_arg_motion (first_arg, insn);
   17144 }
   17145 
   17146 /* Hook for pre-reload schedule - set priority of moves from likely spilled
   17147    HW registers to maximum, to schedule them at soon as possible. These are
   17148    moves from function argument registers at the top of the function entry
   17149    and moves from function return value registers after call.  */
   17150 static int
   17151 ix86_adjust_priority (rtx_insn *insn, int priority)
   17152 {
   17153   rtx set;
   17154 
   17155   if (reload_completed)
   17156     return priority;
   17157 
   17158   if (!NONDEBUG_INSN_P (insn))
   17159     return priority;
   17160 
   17161   set = single_set (insn);
   17162   if (set)
   17163     {
   17164       rtx tmp = SET_SRC (set);
   17165       if (REG_P (tmp)
   17166           && HARD_REGISTER_P (tmp)
   17167           && !TEST_HARD_REG_BIT (fixed_reg_set, REGNO (tmp))
   17168           && ix86_class_likely_spilled_p (REGNO_REG_CLASS (REGNO (tmp))))
   17169 	return current_sched_info->sched_max_insns_priority;
   17170     }
   17171 
   17172   return priority;
   17173 }
   17174 
   17175 /* Prepare for scheduling pass.  */
   17176 static void
   17177 ix86_sched_init_global (FILE *, int, int)
   17178 {
   17179   /* Install scheduling hooks for current CPU.  Some of these hooks are used
   17180      in time-critical parts of the scheduler, so we only set them up when
   17181      they are actually used.  */
   17182   switch (ix86_tune)
   17183     {
   17184     case PROCESSOR_CORE2:
   17185     case PROCESSOR_NEHALEM:
   17186     case PROCESSOR_SANDYBRIDGE:
   17187     case PROCESSOR_HASWELL:
   17188     case PROCESSOR_TREMONT:
   17189     case PROCESSOR_ALDERLAKE:
   17190     case PROCESSOR_GENERIC:
   17191       /* Do not perform multipass scheduling for pre-reload schedule
   17192          to save compile time.  */
   17193       if (reload_completed)
   17194 	{
   17195 	  ix86_core2i7_init_hooks ();
   17196 	  break;
   17197 	}
   17198       /* Fall through.  */
   17199     default:
   17200       targetm.sched.dfa_post_advance_cycle = NULL;
   17201       targetm.sched.first_cycle_multipass_init = NULL;
   17202       targetm.sched.first_cycle_multipass_begin = NULL;
   17203       targetm.sched.first_cycle_multipass_issue = NULL;
   17204       targetm.sched.first_cycle_multipass_backtrack = NULL;
   17205       targetm.sched.first_cycle_multipass_end = NULL;
   17206       targetm.sched.first_cycle_multipass_fini = NULL;
   17207       break;
   17208     }
   17209 }
   17210 
   17211 
   17212 /* Implement TARGET_STATIC_RTX_ALIGNMENT.  */
   17214 
   17215 static HOST_WIDE_INT
   17216 ix86_static_rtx_alignment (machine_mode mode)
   17217 {
   17218   if (mode == DFmode)
   17219     return 64;
   17220   if (ALIGN_MODE_128 (mode))
   17221     return MAX (128, GET_MODE_ALIGNMENT (mode));
   17222   return GET_MODE_ALIGNMENT (mode);
   17223 }
   17224 
   17225 /* Implement TARGET_CONSTANT_ALIGNMENT.  */
   17226 
   17227 static HOST_WIDE_INT
   17228 ix86_constant_alignment (const_tree exp, HOST_WIDE_INT align)
   17229 {
   17230   if (TREE_CODE (exp) == REAL_CST || TREE_CODE (exp) == VECTOR_CST
   17231       || TREE_CODE (exp) == INTEGER_CST)
   17232     {
   17233       machine_mode mode = TYPE_MODE (TREE_TYPE (exp));
   17234       HOST_WIDE_INT mode_align = ix86_static_rtx_alignment (mode);
   17235       return MAX (mode_align, align);
   17236     }
   17237   else if (!optimize_size && TREE_CODE (exp) == STRING_CST
   17238 	   && TREE_STRING_LENGTH (exp) >= 31 && align < BITS_PER_WORD)
   17239     return BITS_PER_WORD;
   17240 
   17241   return align;
   17242 }
   17243 
   17244 /* Implement TARGET_EMPTY_RECORD_P.  */
   17245 
   17246 static bool
   17247 ix86_is_empty_record (const_tree type)
   17248 {
   17249   if (!TARGET_64BIT)
   17250     return false;
   17251   return default_is_empty_record (type);
   17252 }
   17253 
   17254 /* Implement TARGET_WARN_PARAMETER_PASSING_ABI.  */
   17255 
   17256 static void
   17257 ix86_warn_parameter_passing_abi (cumulative_args_t cum_v, tree type)
   17258 {
   17259   CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
   17260 
   17261   if (!cum->warn_empty)
   17262     return;
   17263 
   17264   if (!TYPE_EMPTY_P (type))
   17265     return;
   17266 
   17267   /* Don't warn if the function isn't visible outside of the TU.  */
   17268   if (cum->decl && !TREE_PUBLIC (cum->decl))
   17269     return;
   17270 
   17271   const_tree ctx = get_ultimate_context (cum->decl);
   17272   if (ctx != NULL_TREE
   17273       && !TRANSLATION_UNIT_WARN_EMPTY_P (ctx))
   17274     return;
   17275 
   17276   /* If the actual size of the type is zero, then there is no change
   17277      in how objects of this size are passed.  */
   17278   if (int_size_in_bytes (type) == 0)
   17279     return;
   17280 
   17281   warning (OPT_Wabi, "empty class %qT parameter passing ABI "
   17282 	   "changes in %<-fabi-version=12%> (GCC 8)", type);
   17283 
   17284   /* Only warn once.  */
   17285   cum->warn_empty = false;
   17286 }
   17287 
   17288 /* This hook returns name of multilib ABI.  */
   17289 
   17290 static const char *
   17291 ix86_get_multilib_abi_name (void)
   17292 {
   17293   if (!(TARGET_64BIT_P (ix86_isa_flags)))
   17294     return "i386";
   17295   else if (TARGET_X32_P (ix86_isa_flags))
   17296     return "x32";
   17297   else
   17298     return "x86_64";
   17299 }
   17300 
   17301 /* Compute the alignment for a variable for Intel MCU psABI.  TYPE is
   17302    the data type, and ALIGN is the alignment that the object would
   17303    ordinarily have.  */
   17304 
   17305 static int
   17306 iamcu_alignment (tree type, int align)
   17307 {
   17308   machine_mode mode;
   17309 
   17310   if (align < 32 || TYPE_USER_ALIGN (type))
   17311     return align;
   17312 
   17313   /* Intel MCU psABI specifies scalar types > 4 bytes aligned to 4
   17314      bytes.  */
   17315   type = strip_array_types (type);
   17316   if (TYPE_ATOMIC (type))
   17317     return align;
   17318 
   17319   mode = TYPE_MODE (type);
   17320   switch (GET_MODE_CLASS (mode))
   17321     {
   17322     case MODE_INT:
   17323     case MODE_COMPLEX_INT:
   17324     case MODE_COMPLEX_FLOAT:
   17325     case MODE_FLOAT:
   17326     case MODE_DECIMAL_FLOAT:
   17327       return 32;
   17328     default:
   17329       return align;
   17330     }
   17331 }
   17332 
   17333 /* Compute the alignment for a static variable.
   17334    TYPE is the data type, and ALIGN is the alignment that
   17335    the object would ordinarily have.  The value of this function is used
   17336    instead of that alignment to align the object.  */
   17337 
   17338 int
   17339 ix86_data_alignment (tree type, unsigned int align, bool opt)
   17340 {
   17341   /* GCC 4.8 and earlier used to incorrectly assume this alignment even
   17342      for symbols from other compilation units or symbols that don't need
   17343      to bind locally.  In order to preserve some ABI compatibility with
   17344      those compilers, ensure we don't decrease alignment from what we
   17345      used to assume.  */
   17346 
   17347   unsigned int max_align_compat = MIN (256, MAX_OFILE_ALIGNMENT);
   17348 
   17349   /* A data structure, equal or greater than the size of a cache line
   17350      (64 bytes in the Pentium 4 and other recent Intel processors, including
   17351      processors based on Intel Core microarchitecture) should be aligned
   17352      so that its base address is a multiple of a cache line size.  */
   17353 
   17354   unsigned int max_align
   17355     = MIN ((unsigned) ix86_tune_cost->prefetch_block * 8, MAX_OFILE_ALIGNMENT);
   17356 
   17357   if (max_align < BITS_PER_WORD)
   17358     max_align = BITS_PER_WORD;
   17359 
   17360   switch (ix86_align_data_type)
   17361     {
   17362     case ix86_align_data_type_abi: opt = false; break;
   17363     case ix86_align_data_type_compat: max_align = BITS_PER_WORD; break;
   17364     case ix86_align_data_type_cacheline: break;
   17365     }
   17366 
   17367   if (TARGET_IAMCU)
   17368     align = iamcu_alignment (type, align);
   17369 
   17370   if (opt
   17371       && AGGREGATE_TYPE_P (type)
   17372       && TYPE_SIZE (type)
   17373       && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
   17374     {
   17375       if (wi::geu_p (wi::to_wide (TYPE_SIZE (type)), max_align_compat)
   17376 	  && align < max_align_compat)
   17377 	align = max_align_compat;
   17378       if (wi::geu_p (wi::to_wide (TYPE_SIZE (type)), max_align)
   17379 	  && align < max_align)
   17380 	align = max_align;
   17381     }
   17382 
   17383   /* x86-64 ABI requires arrays greater than 16 bytes to be aligned
   17384      to 16byte boundary.  */
   17385   if (TARGET_64BIT)
   17386     {
   17387       if ((opt ? AGGREGATE_TYPE_P (type) : TREE_CODE (type) == ARRAY_TYPE)
   17388 	  && TYPE_SIZE (type)
   17389 	  && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
   17390 	  && wi::geu_p (wi::to_wide (TYPE_SIZE (type)), 128)
   17391 	  && align < 128)
   17392 	return 128;
   17393     }
   17394 
   17395   if (!opt)
   17396     return align;
   17397 
   17398   if (TREE_CODE (type) == ARRAY_TYPE)
   17399     {
   17400       if (TYPE_MODE (TREE_TYPE (type)) == DFmode && align < 64)
   17401 	return 64;
   17402       if (ALIGN_MODE_128 (TYPE_MODE (TREE_TYPE (type))) && align < 128)
   17403 	return 128;
   17404     }
   17405   else if (TREE_CODE (type) == COMPLEX_TYPE)
   17406     {
   17407 
   17408       if (TYPE_MODE (type) == DCmode && align < 64)
   17409 	return 64;
   17410       if ((TYPE_MODE (type) == XCmode
   17411 	   || TYPE_MODE (type) == TCmode) && align < 128)
   17412 	return 128;
   17413     }
   17414   else if ((TREE_CODE (type) == RECORD_TYPE
   17415 	    || TREE_CODE (type) == UNION_TYPE
   17416 	    || TREE_CODE (type) == QUAL_UNION_TYPE)
   17417 	   && TYPE_FIELDS (type))
   17418     {
   17419       if (DECL_MODE (TYPE_FIELDS (type)) == DFmode && align < 64)
   17420 	return 64;
   17421       if (ALIGN_MODE_128 (DECL_MODE (TYPE_FIELDS (type))) && align < 128)
   17422 	return 128;
   17423     }
   17424   else if (TREE_CODE (type) == REAL_TYPE || TREE_CODE (type) == VECTOR_TYPE
   17425 	   || TREE_CODE (type) == INTEGER_TYPE)
   17426     {
   17427       if (TYPE_MODE (type) == DFmode && align < 64)
   17428 	return 64;
   17429       if (ALIGN_MODE_128 (TYPE_MODE (type)) && align < 128)
   17430 	return 128;
   17431     }
   17432 
   17433   return align;
   17434 }
   17435 
   17436 /* Implememnt TARGET_LOWER_LOCAL_DECL_ALIGNMENT.  */
   17437 static void
   17438 ix86_lower_local_decl_alignment (tree decl)
   17439 {
   17440   unsigned int new_align = ix86_local_alignment (decl, VOIDmode,
   17441 						 DECL_ALIGN (decl), true);
   17442   if (new_align < DECL_ALIGN (decl))
   17443     SET_DECL_ALIGN (decl, new_align);
   17444 }
   17445 
   17446 /* Compute the alignment for a local variable or a stack slot.  EXP is
   17447    the data type or decl itself, MODE is the widest mode available and
   17448    ALIGN is the alignment that the object would ordinarily have.  The
   17449    value of this macro is used instead of that alignment to align the
   17450    object.  */
   17451 
   17452 unsigned int
   17453 ix86_local_alignment (tree exp, machine_mode mode,
   17454 		      unsigned int align, bool may_lower)
   17455 {
   17456   tree type, decl;
   17457 
   17458   if (exp && DECL_P (exp))
   17459     {
   17460       type = TREE_TYPE (exp);
   17461       decl = exp;
   17462     }
   17463   else
   17464     {
   17465       type = exp;
   17466       decl = NULL;
   17467     }
   17468 
   17469   /* Don't do dynamic stack realignment for long long objects with
   17470      -mpreferred-stack-boundary=2.  */
   17471   if (may_lower
   17472       && !TARGET_64BIT
   17473       && align == 64
   17474       && ix86_preferred_stack_boundary < 64
   17475       && (mode == DImode || (type && TYPE_MODE (type) == DImode))
   17476       && (!type || (!TYPE_USER_ALIGN (type)
   17477 		    && !TYPE_ATOMIC (strip_array_types (type))))
   17478       && (!decl || !DECL_USER_ALIGN (decl)))
   17479     align = 32;
   17480 
   17481   /* If TYPE is NULL, we are allocating a stack slot for caller-save
   17482      register in MODE.  We will return the largest alignment of XF
   17483      and DF.  */
   17484   if (!type)
   17485     {
   17486       if (mode == XFmode && align < GET_MODE_ALIGNMENT (DFmode))
   17487 	align = GET_MODE_ALIGNMENT (DFmode);
   17488       return align;
   17489     }
   17490 
   17491   /* Don't increase alignment for Intel MCU psABI.  */
   17492   if (TARGET_IAMCU)
   17493     return align;
   17494 
   17495   /* x86-64 ABI requires arrays greater than 16 bytes to be aligned
   17496      to 16byte boundary.  Exact wording is:
   17497 
   17498      An array uses the same alignment as its elements, except that a local or
   17499      global array variable of length at least 16 bytes or
   17500      a C99 variable-length array variable always has alignment of at least 16 bytes.
   17501 
   17502      This was added to allow use of aligned SSE instructions at arrays.  This
   17503      rule is meant for static storage (where compiler cannot do the analysis
   17504      by itself).  We follow it for automatic variables only when convenient.
   17505      We fully control everything in the function compiled and functions from
   17506      other unit cannot rely on the alignment.
   17507 
   17508      Exclude va_list type.  It is the common case of local array where
   17509      we cannot benefit from the alignment.
   17510 
   17511      TODO: Probably one should optimize for size only when var is not escaping.  */
   17512   if (TARGET_64BIT && optimize_function_for_speed_p (cfun)
   17513       && TARGET_SSE)
   17514     {
   17515       if (AGGREGATE_TYPE_P (type)
   17516 	  && (va_list_type_node == NULL_TREE
   17517 	      || (TYPE_MAIN_VARIANT (type)
   17518 		  != TYPE_MAIN_VARIANT (va_list_type_node)))
   17519 	  && TYPE_SIZE (type)
   17520 	  && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
   17521 	  && wi::geu_p (wi::to_wide (TYPE_SIZE (type)), 128)
   17522 	  && align < 128)
   17523 	return 128;
   17524     }
   17525   if (TREE_CODE (type) == ARRAY_TYPE)
   17526     {
   17527       if (TYPE_MODE (TREE_TYPE (type)) == DFmode && align < 64)
   17528 	return 64;
   17529       if (ALIGN_MODE_128 (TYPE_MODE (TREE_TYPE (type))) && align < 128)
   17530 	return 128;
   17531     }
   17532   else if (TREE_CODE (type) == COMPLEX_TYPE)
   17533     {
   17534       if (TYPE_MODE (type) == DCmode && align < 64)
   17535 	return 64;
   17536       if ((TYPE_MODE (type) == XCmode
   17537 	   || TYPE_MODE (type) == TCmode) && align < 128)
   17538 	return 128;
   17539     }
   17540   else if ((TREE_CODE (type) == RECORD_TYPE
   17541 	    || TREE_CODE (type) == UNION_TYPE
   17542 	    || TREE_CODE (type) == QUAL_UNION_TYPE)
   17543 	   && TYPE_FIELDS (type))
   17544     {
   17545       if (DECL_MODE (TYPE_FIELDS (type)) == DFmode && align < 64)
   17546 	return 64;
   17547       if (ALIGN_MODE_128 (DECL_MODE (TYPE_FIELDS (type))) && align < 128)
   17548 	return 128;
   17549     }
   17550   else if (TREE_CODE (type) == REAL_TYPE || TREE_CODE (type) == VECTOR_TYPE
   17551 	   || TREE_CODE (type) == INTEGER_TYPE)
   17552     {
   17553 
   17554       if (TYPE_MODE (type) == DFmode && align < 64)
   17555 	return 64;
   17556       if (ALIGN_MODE_128 (TYPE_MODE (type)) && align < 128)
   17557 	return 128;
   17558     }
   17559   return align;
   17560 }
   17561 
   17562 /* Compute the minimum required alignment for dynamic stack realignment
   17563    purposes for a local variable, parameter or a stack slot.  EXP is
   17564    the data type or decl itself, MODE is its mode and ALIGN is the
   17565    alignment that the object would ordinarily have.  */
   17566 
   17567 unsigned int
   17568 ix86_minimum_alignment (tree exp, machine_mode mode,
   17569 			unsigned int align)
   17570 {
   17571   tree type, decl;
   17572 
   17573   if (exp && DECL_P (exp))
   17574     {
   17575       type = TREE_TYPE (exp);
   17576       decl = exp;
   17577     }
   17578   else
   17579     {
   17580       type = exp;
   17581       decl = NULL;
   17582     }
   17583 
   17584   if (TARGET_64BIT || align != 64 || ix86_preferred_stack_boundary >= 64)
   17585     return align;
   17586 
   17587   /* Don't do dynamic stack realignment for long long objects with
   17588      -mpreferred-stack-boundary=2.  */
   17589   if ((mode == DImode || (type && TYPE_MODE (type) == DImode))
   17590       && (!type || (!TYPE_USER_ALIGN (type)
   17591 		    && !TYPE_ATOMIC (strip_array_types (type))))
   17592       && (!decl || !DECL_USER_ALIGN (decl)))
   17593     {
   17594       gcc_checking_assert (!TARGET_STV);
   17595       return 32;
   17596     }
   17597 
   17598   return align;
   17599 }
   17600 
   17601 /* Find a location for the static chain incoming to a nested function.
   17603    This is a register, unless all free registers are used by arguments.  */
   17604 
   17605 static rtx
   17606 ix86_static_chain (const_tree fndecl_or_type, bool incoming_p)
   17607 {
   17608   unsigned regno;
   17609 
   17610   if (TARGET_64BIT)
   17611     {
   17612       /* We always use R10 in 64-bit mode.  */
   17613       regno = R10_REG;
   17614     }
   17615   else
   17616     {
   17617       const_tree fntype, fndecl;
   17618       unsigned int ccvt;
   17619 
   17620       /* By default in 32-bit mode we use ECX to pass the static chain.  */
   17621       regno = CX_REG;
   17622 
   17623       if (TREE_CODE (fndecl_or_type) == FUNCTION_DECL)
   17624 	{
   17625           fntype = TREE_TYPE (fndecl_or_type);
   17626 	  fndecl = fndecl_or_type;
   17627 	}
   17628       else
   17629 	{
   17630 	  fntype = fndecl_or_type;
   17631 	  fndecl = NULL;
   17632 	}
   17633 
   17634       ccvt = ix86_get_callcvt (fntype);
   17635       if ((ccvt & IX86_CALLCVT_FASTCALL) != 0)
   17636 	{
   17637 	  /* Fastcall functions use ecx/edx for arguments, which leaves
   17638 	     us with EAX for the static chain.
   17639 	     Thiscall functions use ecx for arguments, which also
   17640 	     leaves us with EAX for the static chain.  */
   17641 	  regno = AX_REG;
   17642 	}
   17643       else if ((ccvt & IX86_CALLCVT_THISCALL) != 0)
   17644 	{
   17645 	  /* Thiscall functions use ecx for arguments, which leaves
   17646 	     us with EAX and EDX for the static chain.
   17647 	     We are using for abi-compatibility EAX.  */
   17648 	  regno = AX_REG;
   17649 	}
   17650       else if (ix86_function_regparm (fntype, fndecl) == 3)
   17651 	{
   17652 	  /* For regparm 3, we have no free call-clobbered registers in
   17653 	     which to store the static chain.  In order to implement this,
   17654 	     we have the trampoline push the static chain to the stack.
   17655 	     However, we can't push a value below the return address when
   17656 	     we call the nested function directly, so we have to use an
   17657 	     alternate entry point.  For this we use ESI, and have the
   17658 	     alternate entry point push ESI, so that things appear the
   17659 	     same once we're executing the nested function.  */
   17660 	  if (incoming_p)
   17661 	    {
   17662 	      if (fndecl == current_function_decl
   17663 		  && !ix86_static_chain_on_stack)
   17664 		{
   17665 		  gcc_assert (!reload_completed);
   17666 		  ix86_static_chain_on_stack = true;
   17667 		}
   17668 	      return gen_frame_mem (SImode,
   17669 				    plus_constant (Pmode,
   17670 						   arg_pointer_rtx, -8));
   17671 	    }
   17672 	  regno = SI_REG;
   17673 	}
   17674     }
   17675 
   17676   return gen_rtx_REG (Pmode, regno);
   17677 }
   17678 
   17679 /* Emit RTL insns to initialize the variable parts of a trampoline.
   17680    FNDECL is the decl of the target address; M_TRAMP is a MEM for
   17681    the trampoline, and CHAIN_VALUE is an RTX for the static chain
   17682    to be passed to the target function.  */
   17683 
   17684 static void
   17685 ix86_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value)
   17686 {
   17687   rtx mem, fnaddr;
   17688   int opcode;
   17689   int offset = 0;
   17690   bool need_endbr = (flag_cf_protection & CF_BRANCH);
   17691 
   17692   fnaddr = XEXP (DECL_RTL (fndecl), 0);
   17693 
   17694   if (TARGET_64BIT)
   17695     {
   17696       int size;
   17697 
   17698       if (need_endbr)
   17699 	{
   17700 	  /* Insert ENDBR64.  */
   17701 	  mem = adjust_address (m_tramp, SImode, offset);
   17702 	  emit_move_insn (mem, gen_int_mode (0xfa1e0ff3, SImode));
   17703 	  offset += 4;
   17704 	}
   17705 
   17706       /* Load the function address to r11.  Try to load address using
   17707 	 the shorter movl instead of movabs.  We may want to support
   17708 	 movq for kernel mode, but kernel does not use trampolines at
   17709 	 the moment.  FNADDR is a 32bit address and may not be in
   17710 	 DImode when ptr_mode == SImode.  Always use movl in this
   17711 	 case.  */
   17712       if (ptr_mode == SImode
   17713 	  || x86_64_zext_immediate_operand (fnaddr, VOIDmode))
   17714 	{
   17715 	  fnaddr = copy_addr_to_reg (fnaddr);
   17716 
   17717 	  mem = adjust_address (m_tramp, HImode, offset);
   17718 	  emit_move_insn (mem, gen_int_mode (0xbb41, HImode));
   17719 
   17720 	  mem = adjust_address (m_tramp, SImode, offset + 2);
   17721 	  emit_move_insn (mem, gen_lowpart (SImode, fnaddr));
   17722 	  offset += 6;
   17723 	}
   17724       else
   17725 	{
   17726 	  mem = adjust_address (m_tramp, HImode, offset);
   17727 	  emit_move_insn (mem, gen_int_mode (0xbb49, HImode));
   17728 
   17729 	  mem = adjust_address (m_tramp, DImode, offset + 2);
   17730 	  emit_move_insn (mem, fnaddr);
   17731 	  offset += 10;
   17732 	}
   17733 
   17734       /* Load static chain using movabs to r10.  Use the shorter movl
   17735          instead of movabs when ptr_mode == SImode.  */
   17736       if (ptr_mode == SImode)
   17737 	{
   17738 	  opcode = 0xba41;
   17739 	  size = 6;
   17740 	}
   17741       else
   17742 	{
   17743 	  opcode = 0xba49;
   17744 	  size = 10;
   17745 	}
   17746 
   17747       mem = adjust_address (m_tramp, HImode, offset);
   17748       emit_move_insn (mem, gen_int_mode (opcode, HImode));
   17749 
   17750       mem = adjust_address (m_tramp, ptr_mode, offset + 2);
   17751       emit_move_insn (mem, chain_value);
   17752       offset += size;
   17753 
   17754       /* Jump to r11; the last (unused) byte is a nop, only there to
   17755 	 pad the write out to a single 32-bit store.  */
   17756       mem = adjust_address (m_tramp, SImode, offset);
   17757       emit_move_insn (mem, gen_int_mode (0x90e3ff49, SImode));
   17758       offset += 4;
   17759     }
   17760   else
   17761     {
   17762       rtx disp, chain;
   17763 
   17764       /* Depending on the static chain location, either load a register
   17765 	 with a constant, or push the constant to the stack.  All of the
   17766 	 instructions are the same size.  */
   17767       chain = ix86_static_chain (fndecl, true);
   17768       if (REG_P (chain))
   17769 	{
   17770 	  switch (REGNO (chain))
   17771 	    {
   17772 	    case AX_REG:
   17773 	      opcode = 0xb8; break;
   17774 	    case CX_REG:
   17775 	      opcode = 0xb9; break;
   17776 	    default:
   17777 	      gcc_unreachable ();
   17778 	    }
   17779 	}
   17780       else
   17781 	opcode = 0x68;
   17782 
   17783       if (need_endbr)
   17784 	{
   17785 	  /* Insert ENDBR32.  */
   17786 	  mem = adjust_address (m_tramp, SImode, offset);
   17787 	  emit_move_insn (mem, gen_int_mode (0xfb1e0ff3, SImode));
   17788 	  offset += 4;
   17789 	}
   17790 
   17791       mem = adjust_address (m_tramp, QImode, offset);
   17792       emit_move_insn (mem, gen_int_mode (opcode, QImode));
   17793 
   17794       mem = adjust_address (m_tramp, SImode, offset + 1);
   17795       emit_move_insn (mem, chain_value);
   17796       offset += 5;
   17797 
   17798       mem = adjust_address (m_tramp, QImode, offset);
   17799       emit_move_insn (mem, gen_int_mode (0xe9, QImode));
   17800 
   17801       mem = adjust_address (m_tramp, SImode, offset + 1);
   17802 
   17803       /* Compute offset from the end of the jmp to the target function.
   17804 	 In the case in which the trampoline stores the static chain on
   17805 	 the stack, we need to skip the first insn which pushes the
   17806 	 (call-saved) register static chain; this push is 1 byte.  */
   17807       offset += 5;
   17808       int skip = MEM_P (chain) ? 1 : 0;
   17809       /* Skip ENDBR32 at the entry of the target function.  */
   17810       if (need_endbr
   17811 	  && !cgraph_node::get (fndecl)->only_called_directly_p ())
   17812 	skip += 4;
   17813       disp = expand_binop (SImode, sub_optab, fnaddr,
   17814 			   plus_constant (Pmode, XEXP (m_tramp, 0),
   17815 					  offset - skip),
   17816 			   NULL_RTX, 1, OPTAB_DIRECT);
   17817       emit_move_insn (mem, disp);
   17818     }
   17819 
   17820   gcc_assert (offset <= TRAMPOLINE_SIZE);
   17821 
   17822 #ifdef HAVE_ENABLE_EXECUTE_STACK
   17823 #ifdef CHECK_EXECUTE_STACK_ENABLED
   17824   if (CHECK_EXECUTE_STACK_ENABLED)
   17825 #endif
   17826   emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__enable_execute_stack"),
   17827 		     LCT_NORMAL, VOIDmode, XEXP (m_tramp, 0), Pmode);
   17828 #endif
   17829 }
   17830 
   17831 static bool
   17832 ix86_allocate_stack_slots_for_args (void)
   17833 {
   17834   /* Naked functions should not allocate stack slots for arguments.  */
   17835   return !ix86_function_naked (current_function_decl);
   17836 }
   17837 
   17838 static bool
   17839 ix86_warn_func_return (tree decl)
   17840 {
   17841   /* Naked functions are implemented entirely in assembly, including the
   17842      return sequence, so suppress warnings about this.  */
   17843   return !ix86_function_naked (decl);
   17844 }
   17845 
   17846 /* Return the shift count of a vector by scalar shift builtin second argument
   17848    ARG1.  */
   17849 static tree
   17850 ix86_vector_shift_count (tree arg1)
   17851 {
   17852   if (tree_fits_uhwi_p (arg1))
   17853     return arg1;
   17854   else if (TREE_CODE (arg1) == VECTOR_CST && CHAR_BIT == 8)
   17855     {
   17856       /* The count argument is weird, passed in as various 128-bit
   17857 	 (or 64-bit) vectors, the low 64 bits from it are the count.  */
   17858       unsigned char buf[16];
   17859       int len = native_encode_expr (arg1, buf, 16);
   17860       if (len == 0)
   17861 	return NULL_TREE;
   17862       tree t = native_interpret_expr (uint64_type_node, buf, len);
   17863       if (t && tree_fits_uhwi_p (t))
   17864 	return t;
   17865     }
   17866   return NULL_TREE;
   17867 }
   17868 
   17869 /* Return true if arg_mask is all ones, ELEMS is elements number of
   17870    corresponding vector.  */
   17871 static bool
   17872 ix86_masked_all_ones (unsigned HOST_WIDE_INT elems, tree arg_mask)
   17873 {
   17874   if (TREE_CODE (arg_mask) != INTEGER_CST)
   17875     return false;
   17876 
   17877   unsigned HOST_WIDE_INT mask = TREE_INT_CST_LOW (arg_mask);
   17878   if ((mask | (HOST_WIDE_INT_M1U << elems)) != HOST_WIDE_INT_M1U)
   17879     return false;
   17880 
   17881   return true;
   17882 }
   17883 
   17884 static tree
   17885 ix86_fold_builtin (tree fndecl, int n_args,
   17886 		   tree *args, bool ignore ATTRIBUTE_UNUSED)
   17887 {
   17888   if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_MD)
   17889     {
   17890       enum ix86_builtins fn_code
   17891 	= (enum ix86_builtins) DECL_MD_FUNCTION_CODE (fndecl);
   17892       enum rtx_code rcode;
   17893       bool is_vshift;
   17894       unsigned HOST_WIDE_INT mask;
   17895 
   17896       switch (fn_code)
   17897 	{
   17898 	case IX86_BUILTIN_CPU_IS:
   17899 	case IX86_BUILTIN_CPU_SUPPORTS:
   17900 	  gcc_assert (n_args == 1);
   17901 	  return fold_builtin_cpu (fndecl, args);
   17902 
   17903 	case IX86_BUILTIN_NANQ:
   17904 	case IX86_BUILTIN_NANSQ:
   17905 	  {
   17906 	    tree type = TREE_TYPE (TREE_TYPE (fndecl));
   17907 	    const char *str = c_getstr (*args);
   17908 	    int quiet = fn_code == IX86_BUILTIN_NANQ;
   17909 	    REAL_VALUE_TYPE real;
   17910 
   17911 	    if (str && real_nan (&real, str, quiet, TYPE_MODE (type)))
   17912 	      return build_real (type, real);
   17913 	    return NULL_TREE;
   17914 	  }
   17915 
   17916 	case IX86_BUILTIN_INFQ:
   17917 	case IX86_BUILTIN_HUGE_VALQ:
   17918 	  {
   17919 	    tree type = TREE_TYPE (TREE_TYPE (fndecl));
   17920 	    REAL_VALUE_TYPE inf;
   17921 	    real_inf (&inf);
   17922 	    return build_real (type, inf);
   17923 	  }
   17924 
   17925 	case IX86_BUILTIN_TZCNT16:
   17926 	case IX86_BUILTIN_CTZS:
   17927 	case IX86_BUILTIN_TZCNT32:
   17928 	case IX86_BUILTIN_TZCNT64:
   17929 	  gcc_assert (n_args == 1);
   17930 	  if (TREE_CODE (args[0]) == INTEGER_CST)
   17931 	    {
   17932 	      tree type = TREE_TYPE (TREE_TYPE (fndecl));
   17933 	      tree arg = args[0];
   17934 	      if (fn_code == IX86_BUILTIN_TZCNT16
   17935 		  || fn_code == IX86_BUILTIN_CTZS)
   17936 		arg = fold_convert (short_unsigned_type_node, arg);
   17937 	      if (integer_zerop (arg))
   17938 		return build_int_cst (type, TYPE_PRECISION (TREE_TYPE (arg)));
   17939 	      else
   17940 		return fold_const_call (CFN_CTZ, type, arg);
   17941 	    }
   17942 	  break;
   17943 
   17944 	case IX86_BUILTIN_LZCNT16:
   17945 	case IX86_BUILTIN_CLZS:
   17946 	case IX86_BUILTIN_LZCNT32:
   17947 	case IX86_BUILTIN_LZCNT64:
   17948 	  gcc_assert (n_args == 1);
   17949 	  if (TREE_CODE (args[0]) == INTEGER_CST)
   17950 	    {
   17951 	      tree type = TREE_TYPE (TREE_TYPE (fndecl));
   17952 	      tree arg = args[0];
   17953 	      if (fn_code == IX86_BUILTIN_LZCNT16
   17954 		  || fn_code == IX86_BUILTIN_CLZS)
   17955 		arg = fold_convert (short_unsigned_type_node, arg);
   17956 	      if (integer_zerop (arg))
   17957 		return build_int_cst (type, TYPE_PRECISION (TREE_TYPE (arg)));
   17958 	      else
   17959 		return fold_const_call (CFN_CLZ, type, arg);
   17960 	    }
   17961 	  break;
   17962 
   17963 	case IX86_BUILTIN_BEXTR32:
   17964 	case IX86_BUILTIN_BEXTR64:
   17965 	case IX86_BUILTIN_BEXTRI32:
   17966 	case IX86_BUILTIN_BEXTRI64:
   17967 	  gcc_assert (n_args == 2);
   17968 	  if (tree_fits_uhwi_p (args[1]))
   17969 	    {
   17970 	      unsigned HOST_WIDE_INT res = 0;
   17971 	      unsigned int prec = TYPE_PRECISION (TREE_TYPE (args[0]));
   17972 	      unsigned int start = tree_to_uhwi (args[1]);
   17973 	      unsigned int len = (start & 0xff00) >> 8;
   17974 	      tree lhs_type = TREE_TYPE (TREE_TYPE (fndecl));
   17975 	      start &= 0xff;
   17976 	      if (start >= prec || len == 0)
   17977 		return omit_one_operand (lhs_type, build_zero_cst (lhs_type),
   17978 					 args[0]);
   17979 	      else if (!tree_fits_uhwi_p (args[0]))
   17980 		break;
   17981 	      else
   17982 		res = tree_to_uhwi (args[0]) >> start;
   17983 	      if (len > prec)
   17984 		len = prec;
   17985 	      if (len < HOST_BITS_PER_WIDE_INT)
   17986 		res &= (HOST_WIDE_INT_1U << len) - 1;
   17987 	      return build_int_cstu (lhs_type, res);
   17988 	    }
   17989 	  break;
   17990 
   17991 	case IX86_BUILTIN_BZHI32:
   17992 	case IX86_BUILTIN_BZHI64:
   17993 	  gcc_assert (n_args == 2);
   17994 	  if (tree_fits_uhwi_p (args[1]))
   17995 	    {
   17996 	      unsigned int idx = tree_to_uhwi (args[1]) & 0xff;
   17997 	      tree lhs_type = TREE_TYPE (TREE_TYPE (fndecl));
   17998 	      if (idx >= TYPE_PRECISION (TREE_TYPE (args[0])))
   17999 		return args[0];
   18000 	      if (idx == 0)
   18001 		return omit_one_operand (lhs_type, build_zero_cst (lhs_type),
   18002 					 args[0]);
   18003 	      if (!tree_fits_uhwi_p (args[0]))
   18004 		break;
   18005 	      unsigned HOST_WIDE_INT res = tree_to_uhwi (args[0]);
   18006 	      res &= ~(HOST_WIDE_INT_M1U << idx);
   18007 	      return build_int_cstu (lhs_type, res);
   18008 	    }
   18009 	  break;
   18010 
   18011 	case IX86_BUILTIN_PDEP32:
   18012 	case IX86_BUILTIN_PDEP64:
   18013 	  gcc_assert (n_args == 2);
   18014 	  if (tree_fits_uhwi_p (args[0]) && tree_fits_uhwi_p (args[1]))
   18015 	    {
   18016 	      unsigned HOST_WIDE_INT src = tree_to_uhwi (args[0]);
   18017 	      unsigned HOST_WIDE_INT mask = tree_to_uhwi (args[1]);
   18018 	      unsigned HOST_WIDE_INT res = 0;
   18019 	      unsigned HOST_WIDE_INT m, k = 1;
   18020 	      for (m = 1; m; m <<= 1)
   18021 		if ((mask & m) != 0)
   18022 		  {
   18023 		    if ((src & k) != 0)
   18024 		      res |= m;
   18025 		    k <<= 1;
   18026 		  }
   18027 	      return build_int_cstu (TREE_TYPE (TREE_TYPE (fndecl)), res);
   18028 	    }
   18029 	  break;
   18030 
   18031 	case IX86_BUILTIN_PEXT32:
   18032 	case IX86_BUILTIN_PEXT64:
   18033 	  gcc_assert (n_args == 2);
   18034 	  if (tree_fits_uhwi_p (args[0]) && tree_fits_uhwi_p (args[1]))
   18035 	    {
   18036 	      unsigned HOST_WIDE_INT src = tree_to_uhwi (args[0]);
   18037 	      unsigned HOST_WIDE_INT mask = tree_to_uhwi (args[1]);
   18038 	      unsigned HOST_WIDE_INT res = 0;
   18039 	      unsigned HOST_WIDE_INT m, k = 1;
   18040 	      for (m = 1; m; m <<= 1)
   18041 		if ((mask & m) != 0)
   18042 		  {
   18043 		    if ((src & m) != 0)
   18044 		      res |= k;
   18045 		    k <<= 1;
   18046 		  }
   18047 	      return build_int_cstu (TREE_TYPE (TREE_TYPE (fndecl)), res);
   18048 	    }
   18049 	  break;
   18050 
   18051 	case IX86_BUILTIN_MOVMSKPS:
   18052 	case IX86_BUILTIN_PMOVMSKB:
   18053 	case IX86_BUILTIN_MOVMSKPD:
   18054 	case IX86_BUILTIN_PMOVMSKB128:
   18055 	case IX86_BUILTIN_MOVMSKPD256:
   18056 	case IX86_BUILTIN_MOVMSKPS256:
   18057 	case IX86_BUILTIN_PMOVMSKB256:
   18058 	  gcc_assert (n_args == 1);
   18059 	  if (TREE_CODE (args[0]) == VECTOR_CST)
   18060 	    {
   18061 	      HOST_WIDE_INT res = 0;
   18062 	      for (unsigned i = 0; i < VECTOR_CST_NELTS (args[0]); ++i)
   18063 		{
   18064 		  tree e = VECTOR_CST_ELT (args[0], i);
   18065 		  if (TREE_CODE (e) == INTEGER_CST && !TREE_OVERFLOW (e))
   18066 		    {
   18067 		      if (wi::neg_p (wi::to_wide (e)))
   18068 			res |= HOST_WIDE_INT_1 << i;
   18069 		    }
   18070 		  else if (TREE_CODE (e) == REAL_CST && !TREE_OVERFLOW (e))
   18071 		    {
   18072 		      if (TREE_REAL_CST (e).sign)
   18073 			res |= HOST_WIDE_INT_1 << i;
   18074 		    }
   18075 		  else
   18076 		    return NULL_TREE;
   18077 		}
   18078 	      return build_int_cst (TREE_TYPE (TREE_TYPE (fndecl)), res);
   18079 	    }
   18080 	  break;
   18081 
   18082 	case IX86_BUILTIN_PSLLD:
   18083 	case IX86_BUILTIN_PSLLD128:
   18084 	case IX86_BUILTIN_PSLLD128_MASK:
   18085 	case IX86_BUILTIN_PSLLD256:
   18086 	case IX86_BUILTIN_PSLLD256_MASK:
   18087 	case IX86_BUILTIN_PSLLD512:
   18088 	case IX86_BUILTIN_PSLLDI:
   18089 	case IX86_BUILTIN_PSLLDI128:
   18090 	case IX86_BUILTIN_PSLLDI128_MASK:
   18091 	case IX86_BUILTIN_PSLLDI256:
   18092 	case IX86_BUILTIN_PSLLDI256_MASK:
   18093 	case IX86_BUILTIN_PSLLDI512:
   18094 	case IX86_BUILTIN_PSLLQ:
   18095 	case IX86_BUILTIN_PSLLQ128:
   18096 	case IX86_BUILTIN_PSLLQ128_MASK:
   18097 	case IX86_BUILTIN_PSLLQ256:
   18098 	case IX86_BUILTIN_PSLLQ256_MASK:
   18099 	case IX86_BUILTIN_PSLLQ512:
   18100 	case IX86_BUILTIN_PSLLQI:
   18101 	case IX86_BUILTIN_PSLLQI128:
   18102 	case IX86_BUILTIN_PSLLQI128_MASK:
   18103 	case IX86_BUILTIN_PSLLQI256:
   18104 	case IX86_BUILTIN_PSLLQI256_MASK:
   18105 	case IX86_BUILTIN_PSLLQI512:
   18106 	case IX86_BUILTIN_PSLLW:
   18107 	case IX86_BUILTIN_PSLLW128:
   18108 	case IX86_BUILTIN_PSLLW128_MASK:
   18109 	case IX86_BUILTIN_PSLLW256:
   18110 	case IX86_BUILTIN_PSLLW256_MASK:
   18111 	case IX86_BUILTIN_PSLLW512_MASK:
   18112 	case IX86_BUILTIN_PSLLWI:
   18113 	case IX86_BUILTIN_PSLLWI128:
   18114 	case IX86_BUILTIN_PSLLWI128_MASK:
   18115 	case IX86_BUILTIN_PSLLWI256:
   18116 	case IX86_BUILTIN_PSLLWI256_MASK:
   18117 	case IX86_BUILTIN_PSLLWI512_MASK:
   18118 	  rcode = ASHIFT;
   18119 	  is_vshift = false;
   18120 	  goto do_shift;
   18121 	case IX86_BUILTIN_PSRAD:
   18122 	case IX86_BUILTIN_PSRAD128:
   18123 	case IX86_BUILTIN_PSRAD128_MASK:
   18124 	case IX86_BUILTIN_PSRAD256:
   18125 	case IX86_BUILTIN_PSRAD256_MASK:
   18126 	case IX86_BUILTIN_PSRAD512:
   18127 	case IX86_BUILTIN_PSRADI:
   18128 	case IX86_BUILTIN_PSRADI128:
   18129 	case IX86_BUILTIN_PSRADI128_MASK:
   18130 	case IX86_BUILTIN_PSRADI256:
   18131 	case IX86_BUILTIN_PSRADI256_MASK:
   18132 	case IX86_BUILTIN_PSRADI512:
   18133 	case IX86_BUILTIN_PSRAQ128_MASK:
   18134 	case IX86_BUILTIN_PSRAQ256_MASK:
   18135 	case IX86_BUILTIN_PSRAQ512:
   18136 	case IX86_BUILTIN_PSRAQI128_MASK:
   18137 	case IX86_BUILTIN_PSRAQI256_MASK:
   18138 	case IX86_BUILTIN_PSRAQI512:
   18139 	case IX86_BUILTIN_PSRAW:
   18140 	case IX86_BUILTIN_PSRAW128:
   18141 	case IX86_BUILTIN_PSRAW128_MASK:
   18142 	case IX86_BUILTIN_PSRAW256:
   18143 	case IX86_BUILTIN_PSRAW256_MASK:
   18144 	case IX86_BUILTIN_PSRAW512:
   18145 	case IX86_BUILTIN_PSRAWI:
   18146 	case IX86_BUILTIN_PSRAWI128:
   18147 	case IX86_BUILTIN_PSRAWI128_MASK:
   18148 	case IX86_BUILTIN_PSRAWI256:
   18149 	case IX86_BUILTIN_PSRAWI256_MASK:
   18150 	case IX86_BUILTIN_PSRAWI512:
   18151 	  rcode = ASHIFTRT;
   18152 	  is_vshift = false;
   18153 	  goto do_shift;
   18154 	case IX86_BUILTIN_PSRLD:
   18155 	case IX86_BUILTIN_PSRLD128:
   18156 	case IX86_BUILTIN_PSRLD128_MASK:
   18157 	case IX86_BUILTIN_PSRLD256:
   18158 	case IX86_BUILTIN_PSRLD256_MASK:
   18159 	case IX86_BUILTIN_PSRLD512:
   18160 	case IX86_BUILTIN_PSRLDI:
   18161 	case IX86_BUILTIN_PSRLDI128:
   18162 	case IX86_BUILTIN_PSRLDI128_MASK:
   18163 	case IX86_BUILTIN_PSRLDI256:
   18164 	case IX86_BUILTIN_PSRLDI256_MASK:
   18165 	case IX86_BUILTIN_PSRLDI512:
   18166 	case IX86_BUILTIN_PSRLQ:
   18167 	case IX86_BUILTIN_PSRLQ128:
   18168 	case IX86_BUILTIN_PSRLQ128_MASK:
   18169 	case IX86_BUILTIN_PSRLQ256:
   18170 	case IX86_BUILTIN_PSRLQ256_MASK:
   18171 	case IX86_BUILTIN_PSRLQ512:
   18172 	case IX86_BUILTIN_PSRLQI:
   18173 	case IX86_BUILTIN_PSRLQI128:
   18174 	case IX86_BUILTIN_PSRLQI128_MASK:
   18175 	case IX86_BUILTIN_PSRLQI256:
   18176 	case IX86_BUILTIN_PSRLQI256_MASK:
   18177 	case IX86_BUILTIN_PSRLQI512:
   18178 	case IX86_BUILTIN_PSRLW:
   18179 	case IX86_BUILTIN_PSRLW128:
   18180 	case IX86_BUILTIN_PSRLW128_MASK:
   18181 	case IX86_BUILTIN_PSRLW256:
   18182 	case IX86_BUILTIN_PSRLW256_MASK:
   18183 	case IX86_BUILTIN_PSRLW512:
   18184 	case IX86_BUILTIN_PSRLWI:
   18185 	case IX86_BUILTIN_PSRLWI128:
   18186 	case IX86_BUILTIN_PSRLWI128_MASK:
   18187 	case IX86_BUILTIN_PSRLWI256:
   18188 	case IX86_BUILTIN_PSRLWI256_MASK:
   18189 	case IX86_BUILTIN_PSRLWI512:
   18190 	  rcode = LSHIFTRT;
   18191 	  is_vshift = false;
   18192 	  goto do_shift;
   18193 	case IX86_BUILTIN_PSLLVV16HI:
   18194 	case IX86_BUILTIN_PSLLVV16SI:
   18195 	case IX86_BUILTIN_PSLLVV2DI:
   18196 	case IX86_BUILTIN_PSLLVV2DI_MASK:
   18197 	case IX86_BUILTIN_PSLLVV32HI:
   18198 	case IX86_BUILTIN_PSLLVV4DI:
   18199 	case IX86_BUILTIN_PSLLVV4DI_MASK:
   18200 	case IX86_BUILTIN_PSLLVV4SI:
   18201 	case IX86_BUILTIN_PSLLVV4SI_MASK:
   18202 	case IX86_BUILTIN_PSLLVV8DI:
   18203 	case IX86_BUILTIN_PSLLVV8HI:
   18204 	case IX86_BUILTIN_PSLLVV8SI:
   18205 	case IX86_BUILTIN_PSLLVV8SI_MASK:
   18206 	  rcode = ASHIFT;
   18207 	  is_vshift = true;
   18208 	  goto do_shift;
   18209 	case IX86_BUILTIN_PSRAVQ128:
   18210 	case IX86_BUILTIN_PSRAVQ256:
   18211 	case IX86_BUILTIN_PSRAVV16HI:
   18212 	case IX86_BUILTIN_PSRAVV16SI:
   18213 	case IX86_BUILTIN_PSRAVV32HI:
   18214 	case IX86_BUILTIN_PSRAVV4SI:
   18215 	case IX86_BUILTIN_PSRAVV4SI_MASK:
   18216 	case IX86_BUILTIN_PSRAVV8DI:
   18217 	case IX86_BUILTIN_PSRAVV8HI:
   18218 	case IX86_BUILTIN_PSRAVV8SI:
   18219 	case IX86_BUILTIN_PSRAVV8SI_MASK:
   18220 	  rcode = ASHIFTRT;
   18221 	  is_vshift = true;
   18222 	  goto do_shift;
   18223 	case IX86_BUILTIN_PSRLVV16HI:
   18224 	case IX86_BUILTIN_PSRLVV16SI:
   18225 	case IX86_BUILTIN_PSRLVV2DI:
   18226 	case IX86_BUILTIN_PSRLVV2DI_MASK:
   18227 	case IX86_BUILTIN_PSRLVV32HI:
   18228 	case IX86_BUILTIN_PSRLVV4DI:
   18229 	case IX86_BUILTIN_PSRLVV4DI_MASK:
   18230 	case IX86_BUILTIN_PSRLVV4SI:
   18231 	case IX86_BUILTIN_PSRLVV4SI_MASK:
   18232 	case IX86_BUILTIN_PSRLVV8DI:
   18233 	case IX86_BUILTIN_PSRLVV8HI:
   18234 	case IX86_BUILTIN_PSRLVV8SI:
   18235 	case IX86_BUILTIN_PSRLVV8SI_MASK:
   18236 	  rcode = LSHIFTRT;
   18237 	  is_vshift = true;
   18238 	  goto do_shift;
   18239 
   18240 	do_shift:
   18241 	  gcc_assert (n_args >= 2);
   18242 	  if (TREE_CODE (args[0]) != VECTOR_CST)
   18243 	    break;
   18244 	  mask = HOST_WIDE_INT_M1U;
   18245 	  if (n_args > 2)
   18246 	    {
   18247 	      /* This is masked shift.  */
   18248 	      if (!tree_fits_uhwi_p (args[n_args - 1])
   18249 		  || TREE_SIDE_EFFECTS (args[n_args - 2]))
   18250 		break;
   18251 	      mask = tree_to_uhwi (args[n_args - 1]);
   18252 	      unsigned elems = TYPE_VECTOR_SUBPARTS (TREE_TYPE (args[0]));
   18253 	      mask |= HOST_WIDE_INT_M1U << elems;
   18254 	      if (mask != HOST_WIDE_INT_M1U
   18255 		  && TREE_CODE (args[n_args - 2]) != VECTOR_CST)
   18256 		break;
   18257 	      if (mask == (HOST_WIDE_INT_M1U << elems))
   18258 		return args[n_args - 2];
   18259 	    }
   18260 	  if (is_vshift && TREE_CODE (args[1]) != VECTOR_CST)
   18261 	    break;
   18262 	  if (tree tem = (is_vshift ? integer_one_node
   18263 			  : ix86_vector_shift_count (args[1])))
   18264 	    {
   18265 	      unsigned HOST_WIDE_INT count = tree_to_uhwi (tem);
   18266 	      unsigned HOST_WIDE_INT prec
   18267 		= TYPE_PRECISION (TREE_TYPE (TREE_TYPE (args[0])));
   18268 	      if (count == 0 && mask == HOST_WIDE_INT_M1U)
   18269 		return args[0];
   18270 	      if (count >= prec)
   18271 		{
   18272 		  if (rcode == ASHIFTRT)
   18273 		    count = prec - 1;
   18274 		  else if (mask == HOST_WIDE_INT_M1U)
   18275 		    return build_zero_cst (TREE_TYPE (args[0]));
   18276 		}
   18277 	      tree countt = NULL_TREE;
   18278 	      if (!is_vshift)
   18279 		{
   18280 		  if (count >= prec)
   18281 		    countt = integer_zero_node;
   18282 		  else
   18283 		    countt = build_int_cst (integer_type_node, count);
   18284 		}
   18285 	      tree_vector_builder builder;
   18286 	      if (mask != HOST_WIDE_INT_M1U || is_vshift)
   18287 		builder.new_vector (TREE_TYPE (args[0]),
   18288 				    TYPE_VECTOR_SUBPARTS (TREE_TYPE (args[0])),
   18289 				    1);
   18290 	      else
   18291 		builder.new_unary_operation (TREE_TYPE (args[0]), args[0],
   18292 					     false);
   18293 	      unsigned int cnt = builder.encoded_nelts ();
   18294 	      for (unsigned int i = 0; i < cnt; ++i)
   18295 		{
   18296 		  tree elt = VECTOR_CST_ELT (args[0], i);
   18297 		  if (TREE_CODE (elt) != INTEGER_CST || TREE_OVERFLOW (elt))
   18298 		    return NULL_TREE;
   18299 		  tree type = TREE_TYPE (elt);
   18300 		  if (rcode == LSHIFTRT)
   18301 		    elt = fold_convert (unsigned_type_for (type), elt);
   18302 		  if (is_vshift)
   18303 		    {
   18304 		      countt = VECTOR_CST_ELT (args[1], i);
   18305 		      if (TREE_CODE (countt) != INTEGER_CST
   18306 			  || TREE_OVERFLOW (countt))
   18307 			return NULL_TREE;
   18308 		      if (wi::neg_p (wi::to_wide (countt))
   18309 			  || wi::to_widest (countt) >= prec)
   18310 			{
   18311 			  if (rcode == ASHIFTRT)
   18312 			    countt = build_int_cst (TREE_TYPE (countt),
   18313 						    prec - 1);
   18314 			  else
   18315 			    {
   18316 			      elt = build_zero_cst (TREE_TYPE (elt));
   18317 			      countt = build_zero_cst (TREE_TYPE (countt));
   18318 			    }
   18319 			}
   18320 		    }
   18321 		  else if (count >= prec)
   18322 		    elt = build_zero_cst (TREE_TYPE (elt));
   18323 		  elt = const_binop (rcode == ASHIFT
   18324 				     ? LSHIFT_EXPR : RSHIFT_EXPR,
   18325 				     TREE_TYPE (elt), elt, countt);
   18326 		  if (!elt || TREE_CODE (elt) != INTEGER_CST)
   18327 		    return NULL_TREE;
   18328 		  if (rcode == LSHIFTRT)
   18329 		    elt = fold_convert (type, elt);
   18330 		  if ((mask & (HOST_WIDE_INT_1U << i)) == 0)
   18331 		    {
   18332 		      elt = VECTOR_CST_ELT (args[n_args - 2], i);
   18333 		      if (TREE_CODE (elt) != INTEGER_CST
   18334 			  || TREE_OVERFLOW (elt))
   18335 			return NULL_TREE;
   18336 		    }
   18337 		  builder.quick_push (elt);
   18338 		}
   18339 	      return builder.build ();
   18340 	    }
   18341 	  break;
   18342 
   18343 	default:
   18344 	  break;
   18345 	}
   18346     }
   18347 
   18348 #ifdef SUBTARGET_FOLD_BUILTIN
   18349   return SUBTARGET_FOLD_BUILTIN (fndecl, n_args, args, ignore);
   18350 #endif
   18351 
   18352   return NULL_TREE;
   18353 }
   18354 
   18355 /* Fold a MD builtin (use ix86_fold_builtin for folding into
   18356    constant) in GIMPLE.  */
   18357 
   18358 bool
   18359 ix86_gimple_fold_builtin (gimple_stmt_iterator *gsi)
   18360 {
   18361   gimple *stmt = gsi_stmt (*gsi);
   18362   tree fndecl = gimple_call_fndecl (stmt);
   18363   gcc_checking_assert (fndecl && fndecl_built_in_p (fndecl, BUILT_IN_MD));
   18364   int n_args = gimple_call_num_args (stmt);
   18365   enum ix86_builtins fn_code
   18366     = (enum ix86_builtins) DECL_MD_FUNCTION_CODE (fndecl);
   18367   tree decl = NULL_TREE;
   18368   tree arg0, arg1, arg2;
   18369   enum rtx_code rcode;
   18370   enum tree_code tcode;
   18371   unsigned HOST_WIDE_INT count;
   18372   bool is_vshift;
   18373   unsigned HOST_WIDE_INT elems;
   18374 
   18375   /* Don't fold when there's isa mismatch.  */
   18376   if (!ix86_check_builtin_isa_match (fn_code, NULL, NULL))
   18377     return false;
   18378 
   18379   switch (fn_code)
   18380     {
   18381     case IX86_BUILTIN_TZCNT32:
   18382       decl = builtin_decl_implicit (BUILT_IN_CTZ);
   18383       goto fold_tzcnt_lzcnt;
   18384 
   18385     case IX86_BUILTIN_TZCNT64:
   18386       decl = builtin_decl_implicit (BUILT_IN_CTZLL);
   18387       goto fold_tzcnt_lzcnt;
   18388 
   18389     case IX86_BUILTIN_LZCNT32:
   18390       decl = builtin_decl_implicit (BUILT_IN_CLZ);
   18391       goto fold_tzcnt_lzcnt;
   18392 
   18393     case IX86_BUILTIN_LZCNT64:
   18394       decl = builtin_decl_implicit (BUILT_IN_CLZLL);
   18395       goto fold_tzcnt_lzcnt;
   18396 
   18397     fold_tzcnt_lzcnt:
   18398       gcc_assert (n_args == 1);
   18399       arg0 = gimple_call_arg (stmt, 0);
   18400       if (TREE_CODE (arg0) == SSA_NAME && decl && gimple_call_lhs (stmt))
   18401 	{
   18402 	  int prec = TYPE_PRECISION (TREE_TYPE (arg0));
   18403 	  /* If arg0 is provably non-zero, optimize into generic
   18404 	     __builtin_c[tl]z{,ll} function the middle-end handles
   18405 	     better.  */
   18406 	  if (!expr_not_equal_to (arg0, wi::zero (prec)))
   18407 	    return false;
   18408 
   18409 	  location_t loc = gimple_location (stmt);
   18410 	  gimple *g = gimple_build_call (decl, 1, arg0);
   18411 	  gimple_set_location (g, loc);
   18412 	  tree lhs = make_ssa_name (integer_type_node);
   18413 	  gimple_call_set_lhs (g, lhs);
   18414 	  gsi_insert_before (gsi, g, GSI_SAME_STMT);
   18415 	  g = gimple_build_assign (gimple_call_lhs (stmt), NOP_EXPR, lhs);
   18416 	  gimple_set_location (g, loc);
   18417 	  gsi_replace (gsi, g, false);
   18418 	  return true;
   18419 	}
   18420       break;
   18421 
   18422     case IX86_BUILTIN_BZHI32:
   18423     case IX86_BUILTIN_BZHI64:
   18424       gcc_assert (n_args == 2);
   18425       arg1 = gimple_call_arg (stmt, 1);
   18426       if (tree_fits_uhwi_p (arg1) && gimple_call_lhs (stmt))
   18427 	{
   18428 	  unsigned int idx = tree_to_uhwi (arg1) & 0xff;
   18429 	  arg0 = gimple_call_arg (stmt, 0);
   18430 	  if (idx < TYPE_PRECISION (TREE_TYPE (arg0)))
   18431 	    break;
   18432 	  location_t loc = gimple_location (stmt);
   18433 	  gimple *g = gimple_build_assign (gimple_call_lhs (stmt), arg0);
   18434 	  gimple_set_location (g, loc);
   18435 	  gsi_replace (gsi, g, false);
   18436 	  return true;
   18437 	}
   18438       break;
   18439 
   18440     case IX86_BUILTIN_PDEP32:
   18441     case IX86_BUILTIN_PDEP64:
   18442     case IX86_BUILTIN_PEXT32:
   18443     case IX86_BUILTIN_PEXT64:
   18444       gcc_assert (n_args == 2);
   18445       arg1 = gimple_call_arg (stmt, 1);
   18446       if (integer_all_onesp (arg1) && gimple_call_lhs (stmt))
   18447 	{
   18448 	  location_t loc = gimple_location (stmt);
   18449 	  arg0 = gimple_call_arg (stmt, 0);
   18450 	  gimple *g = gimple_build_assign (gimple_call_lhs (stmt), arg0);
   18451 	  gimple_set_location (g, loc);
   18452 	  gsi_replace (gsi, g, false);
   18453 	  return true;
   18454 	}
   18455       break;
   18456 
   18457     case IX86_BUILTIN_PBLENDVB256:
   18458     case IX86_BUILTIN_BLENDVPS256:
   18459     case IX86_BUILTIN_BLENDVPD256:
   18460       /* pcmpeqb/d/q is under avx2, w/o avx2, it's veclower
   18461 	 to scalar operations and not combined back.  */
   18462       if (!TARGET_AVX2)
   18463 	break;
   18464 
   18465       /* FALLTHRU.  */
   18466     case IX86_BUILTIN_BLENDVPD:
   18467       /* blendvpd is under sse4.1 but pcmpgtq is under sse4.2,
   18468 	 w/o sse4.2, it's veclowered to scalar operations and
   18469 	 not combined back.  */
   18470       if (!TARGET_SSE4_2)
   18471 	break;
   18472       /* FALLTHRU.  */
   18473     case IX86_BUILTIN_PBLENDVB128:
   18474     case IX86_BUILTIN_BLENDVPS:
   18475       gcc_assert (n_args == 3);
   18476       arg0 = gimple_call_arg (stmt, 0);
   18477       arg1 = gimple_call_arg (stmt, 1);
   18478       arg2 = gimple_call_arg (stmt, 2);
   18479       if (gimple_call_lhs (stmt))
   18480 	{
   18481 	  location_t loc = gimple_location (stmt);
   18482 	  tree type = TREE_TYPE (arg2);
   18483 	  gimple_seq stmts = NULL;
   18484 	  if (VECTOR_FLOAT_TYPE_P (type))
   18485 	    {
   18486 	      tree itype = GET_MODE_INNER (TYPE_MODE (type)) == E_SFmode
   18487 		? intSI_type_node : intDI_type_node;
   18488 	      type = get_same_sized_vectype (itype, type);
   18489 	    }
   18490 	  else
   18491 	    type = signed_type_for (type);
   18492 	  arg2 = gimple_build (&stmts, VIEW_CONVERT_EXPR, type, arg2);
   18493 	  tree zero_vec = build_zero_cst (type);
   18494 	  tree cmp_type = truth_type_for (type);
   18495 	  tree cmp = gimple_build (&stmts, LT_EXPR, cmp_type, arg2, zero_vec);
   18496 	  gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
   18497 	  gimple *g = gimple_build_assign (gimple_call_lhs (stmt),
   18498 					   VEC_COND_EXPR, cmp,
   18499 					   arg1, arg0);
   18500 	  gimple_set_location (g, loc);
   18501 	  gsi_replace (gsi, g, false);
   18502 	}
   18503       else
   18504 	gsi_replace (gsi, gimple_build_nop (), false);
   18505       return true;
   18506 
   18507 
   18508     case IX86_BUILTIN_PCMPEQB128:
   18509     case IX86_BUILTIN_PCMPEQW128:
   18510     case IX86_BUILTIN_PCMPEQD128:
   18511     case IX86_BUILTIN_PCMPEQQ:
   18512     case IX86_BUILTIN_PCMPEQB256:
   18513     case IX86_BUILTIN_PCMPEQW256:
   18514     case IX86_BUILTIN_PCMPEQD256:
   18515     case IX86_BUILTIN_PCMPEQQ256:
   18516       tcode = EQ_EXPR;
   18517       goto do_cmp;
   18518 
   18519     case IX86_BUILTIN_PCMPGTB128:
   18520     case IX86_BUILTIN_PCMPGTW128:
   18521     case IX86_BUILTIN_PCMPGTD128:
   18522     case IX86_BUILTIN_PCMPGTQ:
   18523     case IX86_BUILTIN_PCMPGTB256:
   18524     case IX86_BUILTIN_PCMPGTW256:
   18525     case IX86_BUILTIN_PCMPGTD256:
   18526     case IX86_BUILTIN_PCMPGTQ256:
   18527       tcode = GT_EXPR;
   18528 
   18529     do_cmp:
   18530       gcc_assert (n_args == 2);
   18531       arg0 = gimple_call_arg (stmt, 0);
   18532       arg1 = gimple_call_arg (stmt, 1);
   18533       if (gimple_call_lhs (stmt))
   18534 	{
   18535 	  location_t loc = gimple_location (stmt);
   18536 	  tree type = TREE_TYPE (arg0);
   18537 	  tree zero_vec = build_zero_cst (type);
   18538 	  tree minus_one_vec = build_minus_one_cst (type);
   18539 	  tree cmp_type = truth_type_for (type);
   18540 	  gimple_seq stmts = NULL;
   18541 	  tree cmp = gimple_build (&stmts, tcode, cmp_type, arg0, arg1);
   18542 	  gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
   18543 	  gimple* g = gimple_build_assign (gimple_call_lhs (stmt),
   18544 					   VEC_COND_EXPR, cmp,
   18545 					   minus_one_vec, zero_vec);
   18546 	  gimple_set_location (g, loc);
   18547 	  gsi_replace (gsi, g, false);
   18548 	}
   18549       else
   18550 	gsi_replace (gsi, gimple_build_nop (), false);
   18551       return true;
   18552 
   18553     case IX86_BUILTIN_PSLLD:
   18554     case IX86_BUILTIN_PSLLD128:
   18555     case IX86_BUILTIN_PSLLD128_MASK:
   18556     case IX86_BUILTIN_PSLLD256:
   18557     case IX86_BUILTIN_PSLLD256_MASK:
   18558     case IX86_BUILTIN_PSLLD512:
   18559     case IX86_BUILTIN_PSLLDI:
   18560     case IX86_BUILTIN_PSLLDI128:
   18561     case IX86_BUILTIN_PSLLDI128_MASK:
   18562     case IX86_BUILTIN_PSLLDI256:
   18563     case IX86_BUILTIN_PSLLDI256_MASK:
   18564     case IX86_BUILTIN_PSLLDI512:
   18565     case IX86_BUILTIN_PSLLQ:
   18566     case IX86_BUILTIN_PSLLQ128:
   18567     case IX86_BUILTIN_PSLLQ128_MASK:
   18568     case IX86_BUILTIN_PSLLQ256:
   18569     case IX86_BUILTIN_PSLLQ256_MASK:
   18570     case IX86_BUILTIN_PSLLQ512:
   18571     case IX86_BUILTIN_PSLLQI:
   18572     case IX86_BUILTIN_PSLLQI128:
   18573     case IX86_BUILTIN_PSLLQI128_MASK:
   18574     case IX86_BUILTIN_PSLLQI256:
   18575     case IX86_BUILTIN_PSLLQI256_MASK:
   18576     case IX86_BUILTIN_PSLLQI512:
   18577     case IX86_BUILTIN_PSLLW:
   18578     case IX86_BUILTIN_PSLLW128:
   18579     case IX86_BUILTIN_PSLLW128_MASK:
   18580     case IX86_BUILTIN_PSLLW256:
   18581     case IX86_BUILTIN_PSLLW256_MASK:
   18582     case IX86_BUILTIN_PSLLW512_MASK:
   18583     case IX86_BUILTIN_PSLLWI:
   18584     case IX86_BUILTIN_PSLLWI128:
   18585     case IX86_BUILTIN_PSLLWI128_MASK:
   18586     case IX86_BUILTIN_PSLLWI256:
   18587     case IX86_BUILTIN_PSLLWI256_MASK:
   18588     case IX86_BUILTIN_PSLLWI512_MASK:
   18589       rcode = ASHIFT;
   18590       is_vshift = false;
   18591       goto do_shift;
   18592     case IX86_BUILTIN_PSRAD:
   18593     case IX86_BUILTIN_PSRAD128:
   18594     case IX86_BUILTIN_PSRAD128_MASK:
   18595     case IX86_BUILTIN_PSRAD256:
   18596     case IX86_BUILTIN_PSRAD256_MASK:
   18597     case IX86_BUILTIN_PSRAD512:
   18598     case IX86_BUILTIN_PSRADI:
   18599     case IX86_BUILTIN_PSRADI128:
   18600     case IX86_BUILTIN_PSRADI128_MASK:
   18601     case IX86_BUILTIN_PSRADI256:
   18602     case IX86_BUILTIN_PSRADI256_MASK:
   18603     case IX86_BUILTIN_PSRADI512:
   18604     case IX86_BUILTIN_PSRAQ128_MASK:
   18605     case IX86_BUILTIN_PSRAQ256_MASK:
   18606     case IX86_BUILTIN_PSRAQ512:
   18607     case IX86_BUILTIN_PSRAQI128_MASK:
   18608     case IX86_BUILTIN_PSRAQI256_MASK:
   18609     case IX86_BUILTIN_PSRAQI512:
   18610     case IX86_BUILTIN_PSRAW:
   18611     case IX86_BUILTIN_PSRAW128:
   18612     case IX86_BUILTIN_PSRAW128_MASK:
   18613     case IX86_BUILTIN_PSRAW256:
   18614     case IX86_BUILTIN_PSRAW256_MASK:
   18615     case IX86_BUILTIN_PSRAW512:
   18616     case IX86_BUILTIN_PSRAWI:
   18617     case IX86_BUILTIN_PSRAWI128:
   18618     case IX86_BUILTIN_PSRAWI128_MASK:
   18619     case IX86_BUILTIN_PSRAWI256:
   18620     case IX86_BUILTIN_PSRAWI256_MASK:
   18621     case IX86_BUILTIN_PSRAWI512:
   18622       rcode = ASHIFTRT;
   18623       is_vshift = false;
   18624       goto do_shift;
   18625     case IX86_BUILTIN_PSRLD:
   18626     case IX86_BUILTIN_PSRLD128:
   18627     case IX86_BUILTIN_PSRLD128_MASK:
   18628     case IX86_BUILTIN_PSRLD256:
   18629     case IX86_BUILTIN_PSRLD256_MASK:
   18630     case IX86_BUILTIN_PSRLD512:
   18631     case IX86_BUILTIN_PSRLDI:
   18632     case IX86_BUILTIN_PSRLDI128:
   18633     case IX86_BUILTIN_PSRLDI128_MASK:
   18634     case IX86_BUILTIN_PSRLDI256:
   18635     case IX86_BUILTIN_PSRLDI256_MASK:
   18636     case IX86_BUILTIN_PSRLDI512:
   18637     case IX86_BUILTIN_PSRLQ:
   18638     case IX86_BUILTIN_PSRLQ128:
   18639     case IX86_BUILTIN_PSRLQ128_MASK:
   18640     case IX86_BUILTIN_PSRLQ256:
   18641     case IX86_BUILTIN_PSRLQ256_MASK:
   18642     case IX86_BUILTIN_PSRLQ512:
   18643     case IX86_BUILTIN_PSRLQI:
   18644     case IX86_BUILTIN_PSRLQI128:
   18645     case IX86_BUILTIN_PSRLQI128_MASK:
   18646     case IX86_BUILTIN_PSRLQI256:
   18647     case IX86_BUILTIN_PSRLQI256_MASK:
   18648     case IX86_BUILTIN_PSRLQI512:
   18649     case IX86_BUILTIN_PSRLW:
   18650     case IX86_BUILTIN_PSRLW128:
   18651     case IX86_BUILTIN_PSRLW128_MASK:
   18652     case IX86_BUILTIN_PSRLW256:
   18653     case IX86_BUILTIN_PSRLW256_MASK:
   18654     case IX86_BUILTIN_PSRLW512:
   18655     case IX86_BUILTIN_PSRLWI:
   18656     case IX86_BUILTIN_PSRLWI128:
   18657     case IX86_BUILTIN_PSRLWI128_MASK:
   18658     case IX86_BUILTIN_PSRLWI256:
   18659     case IX86_BUILTIN_PSRLWI256_MASK:
   18660     case IX86_BUILTIN_PSRLWI512:
   18661       rcode = LSHIFTRT;
   18662       is_vshift = false;
   18663       goto do_shift;
   18664     case IX86_BUILTIN_PSLLVV16HI:
   18665     case IX86_BUILTIN_PSLLVV16SI:
   18666     case IX86_BUILTIN_PSLLVV2DI:
   18667     case IX86_BUILTIN_PSLLVV2DI_MASK:
   18668     case IX86_BUILTIN_PSLLVV32HI:
   18669     case IX86_BUILTIN_PSLLVV4DI:
   18670     case IX86_BUILTIN_PSLLVV4DI_MASK:
   18671     case IX86_BUILTIN_PSLLVV4SI:
   18672     case IX86_BUILTIN_PSLLVV4SI_MASK:
   18673     case IX86_BUILTIN_PSLLVV8DI:
   18674     case IX86_BUILTIN_PSLLVV8HI:
   18675     case IX86_BUILTIN_PSLLVV8SI:
   18676     case IX86_BUILTIN_PSLLVV8SI_MASK:
   18677       rcode = ASHIFT;
   18678       is_vshift = true;
   18679       goto do_shift;
   18680     case IX86_BUILTIN_PSRAVQ128:
   18681     case IX86_BUILTIN_PSRAVQ256:
   18682     case IX86_BUILTIN_PSRAVV16HI:
   18683     case IX86_BUILTIN_PSRAVV16SI:
   18684     case IX86_BUILTIN_PSRAVV32HI:
   18685     case IX86_BUILTIN_PSRAVV4SI:
   18686     case IX86_BUILTIN_PSRAVV4SI_MASK:
   18687     case IX86_BUILTIN_PSRAVV8DI:
   18688     case IX86_BUILTIN_PSRAVV8HI:
   18689     case IX86_BUILTIN_PSRAVV8SI:
   18690     case IX86_BUILTIN_PSRAVV8SI_MASK:
   18691       rcode = ASHIFTRT;
   18692       is_vshift = true;
   18693       goto do_shift;
   18694     case IX86_BUILTIN_PSRLVV16HI:
   18695     case IX86_BUILTIN_PSRLVV16SI:
   18696     case IX86_BUILTIN_PSRLVV2DI:
   18697     case IX86_BUILTIN_PSRLVV2DI_MASK:
   18698     case IX86_BUILTIN_PSRLVV32HI:
   18699     case IX86_BUILTIN_PSRLVV4DI:
   18700     case IX86_BUILTIN_PSRLVV4DI_MASK:
   18701     case IX86_BUILTIN_PSRLVV4SI:
   18702     case IX86_BUILTIN_PSRLVV4SI_MASK:
   18703     case IX86_BUILTIN_PSRLVV8DI:
   18704     case IX86_BUILTIN_PSRLVV8HI:
   18705     case IX86_BUILTIN_PSRLVV8SI:
   18706     case IX86_BUILTIN_PSRLVV8SI_MASK:
   18707       rcode = LSHIFTRT;
   18708       is_vshift = true;
   18709       goto do_shift;
   18710 
   18711     do_shift:
   18712       gcc_assert (n_args >= 2);
   18713       if (!gimple_call_lhs (stmt))
   18714 	break;
   18715       arg0 = gimple_call_arg (stmt, 0);
   18716       arg1 = gimple_call_arg (stmt, 1);
   18717       elems = TYPE_VECTOR_SUBPARTS (TREE_TYPE (arg0));
   18718       /* For masked shift, only optimize if the mask is all ones.  */
   18719       if (n_args > 2
   18720 	  && !ix86_masked_all_ones (elems, gimple_call_arg (stmt, n_args - 1)))
   18721 	break;
   18722       if (is_vshift)
   18723 	{
   18724 	  if (TREE_CODE (arg1) != VECTOR_CST)
   18725 	    break;
   18726 	  count = TYPE_PRECISION (TREE_TYPE (TREE_TYPE (arg0)));
   18727 	  if (integer_zerop (arg1))
   18728 	    count = 0;
   18729 	  else if (rcode == ASHIFTRT)
   18730 	    break;
   18731 	  else
   18732 	    for (unsigned int i = 0; i < VECTOR_CST_NELTS (arg1); ++i)
   18733 	      {
   18734 		tree elt = VECTOR_CST_ELT (arg1, i);
   18735 		if (!wi::neg_p (wi::to_wide (elt))
   18736 		    && wi::to_widest (elt) < count)
   18737 		  return false;
   18738 	      }
   18739 	}
   18740       else
   18741 	{
   18742 	  arg1 = ix86_vector_shift_count (arg1);
   18743 	  if (!arg1)
   18744 	    break;
   18745 	  count = tree_to_uhwi (arg1);
   18746 	}
   18747       if (count == 0)
   18748 	{
   18749 	  /* Just return the first argument for shift by 0.  */
   18750 	  location_t loc = gimple_location (stmt);
   18751 	  gimple *g = gimple_build_assign (gimple_call_lhs (stmt), arg0);
   18752 	  gimple_set_location (g, loc);
   18753 	  gsi_replace (gsi, g, false);
   18754 	  return true;
   18755 	}
   18756       if (rcode != ASHIFTRT
   18757 	  && count >= TYPE_PRECISION (TREE_TYPE (TREE_TYPE (arg0))))
   18758 	{
   18759 	  /* For shift counts equal or greater than precision, except for
   18760 	     arithmetic right shift the result is zero.  */
   18761 	  location_t loc = gimple_location (stmt);
   18762 	  gimple *g = gimple_build_assign (gimple_call_lhs (stmt),
   18763 					   build_zero_cst (TREE_TYPE (arg0)));
   18764 	  gimple_set_location (g, loc);
   18765 	  gsi_replace (gsi, g, false);
   18766 	  return true;
   18767 	}
   18768       break;
   18769 
   18770     case IX86_BUILTIN_SHUFPD512:
   18771     case IX86_BUILTIN_SHUFPS512:
   18772     case IX86_BUILTIN_SHUFPD:
   18773     case IX86_BUILTIN_SHUFPD256:
   18774     case IX86_BUILTIN_SHUFPS:
   18775     case IX86_BUILTIN_SHUFPS256:
   18776       arg0 = gimple_call_arg (stmt, 0);
   18777       elems = TYPE_VECTOR_SUBPARTS (TREE_TYPE (arg0));
   18778       /* This is masked shuffle.  Only optimize if the mask is all ones.  */
   18779       if (n_args > 3
   18780 	  && !ix86_masked_all_ones (elems,
   18781 				    gimple_call_arg (stmt, n_args - 1)))
   18782 	break;
   18783       arg2 = gimple_call_arg (stmt, 2);
   18784       if (TREE_CODE (arg2) == INTEGER_CST && gimple_call_lhs (stmt))
   18785 	{
   18786 	  unsigned HOST_WIDE_INT shuffle_mask = TREE_INT_CST_LOW (arg2);
   18787 	  /* Check valid imm, refer to gcc.target/i386/testimm-10.c.  */
   18788 	  if (shuffle_mask > 255)
   18789 	    return false;
   18790 
   18791 	  machine_mode imode = GET_MODE_INNER (TYPE_MODE (TREE_TYPE (arg0)));
   18792 	  location_t loc = gimple_location (stmt);
   18793 	  tree itype = (imode == E_DFmode
   18794 			? long_long_integer_type_node : integer_type_node);
   18795 	  tree vtype = build_vector_type (itype, elems);
   18796 	  tree_vector_builder elts (vtype, elems, 1);
   18797 
   18798 
   18799 	  /* Transform integer shuffle_mask to vector perm_mask which
   18800 	     is used by vec_perm_expr, refer to shuflp[sd]256/512 in sse.md.  */
   18801 	  for (unsigned i = 0; i != elems; i++)
   18802 	    {
   18803 	      unsigned sel_idx;
   18804 	      /* Imm[1:0](if VL > 128, then use Imm[3:2],Imm[5:4],Imm[7:6])
   18805 		 provide 2 select constrols for each element of the
   18806 		 destination.  */
   18807 	      if (imode == E_DFmode)
   18808 		sel_idx = (i & 1) * elems + (i & ~1)
   18809 			  + ((shuffle_mask >> i) & 1);
   18810 	      else
   18811 		{
   18812 		  /* Imm[7:0](if VL > 128, also use Imm[7:0]) provide 4 select
   18813 		     controls for each element of the destination.  */
   18814 		  unsigned j = i % 4;
   18815 		  sel_idx = ((i >> 1) & 1) * elems + (i & ~3)
   18816 			    + ((shuffle_mask >> 2 * j) & 3);
   18817 		}
   18818 	      elts.quick_push (build_int_cst (itype, sel_idx));
   18819 	    }
   18820 
   18821 	  tree perm_mask = elts.build ();
   18822 	  arg1 = gimple_call_arg (stmt, 1);
   18823 	  gimple *g = gimple_build_assign (gimple_call_lhs (stmt),
   18824 					   VEC_PERM_EXPR,
   18825 					   arg0, arg1, perm_mask);
   18826 	  gimple_set_location (g, loc);
   18827 	  gsi_replace (gsi, g, false);
   18828 	  return true;
   18829 	}
   18830       // Do not error yet, the constant could be propagated later?
   18831       break;
   18832 
   18833     default:
   18834       break;
   18835     }
   18836 
   18837   return false;
   18838 }
   18839 
   18840 /* Handler for an SVML-style interface to
   18841    a library with vectorized intrinsics.  */
   18842 
   18843 tree
   18844 ix86_veclibabi_svml (combined_fn fn, tree type_out, tree type_in)
   18845 {
   18846   char name[20];
   18847   tree fntype, new_fndecl, args;
   18848   unsigned arity;
   18849   const char *bname;
   18850   machine_mode el_mode, in_mode;
   18851   int n, in_n;
   18852 
   18853   /* The SVML is suitable for unsafe math only.  */
   18854   if (!flag_unsafe_math_optimizations)
   18855     return NULL_TREE;
   18856 
   18857   el_mode = TYPE_MODE (TREE_TYPE (type_out));
   18858   n = TYPE_VECTOR_SUBPARTS (type_out);
   18859   in_mode = TYPE_MODE (TREE_TYPE (type_in));
   18860   in_n = TYPE_VECTOR_SUBPARTS (type_in);
   18861   if (el_mode != in_mode
   18862       || n != in_n)
   18863     return NULL_TREE;
   18864 
   18865   switch (fn)
   18866     {
   18867     CASE_CFN_EXP:
   18868     CASE_CFN_LOG:
   18869     CASE_CFN_LOG10:
   18870     CASE_CFN_POW:
   18871     CASE_CFN_TANH:
   18872     CASE_CFN_TAN:
   18873     CASE_CFN_ATAN:
   18874     CASE_CFN_ATAN2:
   18875     CASE_CFN_ATANH:
   18876     CASE_CFN_CBRT:
   18877     CASE_CFN_SINH:
   18878     CASE_CFN_SIN:
   18879     CASE_CFN_ASINH:
   18880     CASE_CFN_ASIN:
   18881     CASE_CFN_COSH:
   18882     CASE_CFN_COS:
   18883     CASE_CFN_ACOSH:
   18884     CASE_CFN_ACOS:
   18885       if ((el_mode != DFmode || n != 2)
   18886 	  && (el_mode != SFmode || n != 4))
   18887 	return NULL_TREE;
   18888       break;
   18889 
   18890     default:
   18891       return NULL_TREE;
   18892     }
   18893 
   18894   tree fndecl = mathfn_built_in (el_mode == DFmode
   18895 				 ? double_type_node : float_type_node, fn);
   18896   bname = IDENTIFIER_POINTER (DECL_NAME (fndecl));
   18897 
   18898   if (DECL_FUNCTION_CODE (fndecl) == BUILT_IN_LOGF)
   18899     strcpy (name, "vmlsLn4");
   18900   else if (DECL_FUNCTION_CODE (fndecl) == BUILT_IN_LOG)
   18901     strcpy (name, "vmldLn2");
   18902   else if (n == 4)
   18903     {
   18904       sprintf (name, "vmls%s", bname+10);
   18905       name[strlen (name)-1] = '4';
   18906     }
   18907   else
   18908     sprintf (name, "vmld%s2", bname+10);
   18909 
   18910   /* Convert to uppercase. */
   18911   name[4] &= ~0x20;
   18912 
   18913   arity = 0;
   18914   for (args = DECL_ARGUMENTS (fndecl); args; args = TREE_CHAIN (args))
   18915     arity++;
   18916 
   18917   if (arity == 1)
   18918     fntype = build_function_type_list (type_out, type_in, NULL);
   18919   else
   18920     fntype = build_function_type_list (type_out, type_in, type_in, NULL);
   18921 
   18922   /* Build a function declaration for the vectorized function.  */
   18923   new_fndecl = build_decl (BUILTINS_LOCATION,
   18924 			   FUNCTION_DECL, get_identifier (name), fntype);
   18925   TREE_PUBLIC (new_fndecl) = 1;
   18926   DECL_EXTERNAL (new_fndecl) = 1;
   18927   DECL_IS_NOVOPS (new_fndecl) = 1;
   18928   TREE_READONLY (new_fndecl) = 1;
   18929 
   18930   return new_fndecl;
   18931 }
   18932 
   18933 /* Handler for an ACML-style interface to
   18934    a library with vectorized intrinsics.  */
   18935 
   18936 tree
   18937 ix86_veclibabi_acml (combined_fn fn, tree type_out, tree type_in)
   18938 {
   18939   char name[20] = "__vr.._";
   18940   tree fntype, new_fndecl, args;
   18941   unsigned arity;
   18942   const char *bname;
   18943   machine_mode el_mode, in_mode;
   18944   int n, in_n;
   18945 
   18946   /* The ACML is 64bits only and suitable for unsafe math only as
   18947      it does not correctly support parts of IEEE with the required
   18948      precision such as denormals.  */
   18949   if (!TARGET_64BIT
   18950       || !flag_unsafe_math_optimizations)
   18951     return NULL_TREE;
   18952 
   18953   el_mode = TYPE_MODE (TREE_TYPE (type_out));
   18954   n = TYPE_VECTOR_SUBPARTS (type_out);
   18955   in_mode = TYPE_MODE (TREE_TYPE (type_in));
   18956   in_n = TYPE_VECTOR_SUBPARTS (type_in);
   18957   if (el_mode != in_mode
   18958       || n != in_n)
   18959     return NULL_TREE;
   18960 
   18961   switch (fn)
   18962     {
   18963     CASE_CFN_SIN:
   18964     CASE_CFN_COS:
   18965     CASE_CFN_EXP:
   18966     CASE_CFN_LOG:
   18967     CASE_CFN_LOG2:
   18968     CASE_CFN_LOG10:
   18969       if (el_mode == DFmode && n == 2)
   18970 	{
   18971 	  name[4] = 'd';
   18972 	  name[5] = '2';
   18973 	}
   18974       else if (el_mode == SFmode && n == 4)
   18975 	{
   18976 	  name[4] = 's';
   18977 	  name[5] = '4';
   18978 	}
   18979       else
   18980 	return NULL_TREE;
   18981       break;
   18982 
   18983     default:
   18984       return NULL_TREE;
   18985     }
   18986 
   18987   tree fndecl = mathfn_built_in (el_mode == DFmode
   18988 				 ? double_type_node : float_type_node, fn);
   18989   bname = IDENTIFIER_POINTER (DECL_NAME (fndecl));
   18990   sprintf (name + 7, "%s", bname+10);
   18991 
   18992   arity = 0;
   18993   for (args = DECL_ARGUMENTS (fndecl); args; args = TREE_CHAIN (args))
   18994     arity++;
   18995 
   18996   if (arity == 1)
   18997     fntype = build_function_type_list (type_out, type_in, NULL);
   18998   else
   18999     fntype = build_function_type_list (type_out, type_in, type_in, NULL);
   19000 
   19001   /* Build a function declaration for the vectorized function.  */
   19002   new_fndecl = build_decl (BUILTINS_LOCATION,
   19003 			   FUNCTION_DECL, get_identifier (name), fntype);
   19004   TREE_PUBLIC (new_fndecl) = 1;
   19005   DECL_EXTERNAL (new_fndecl) = 1;
   19006   DECL_IS_NOVOPS (new_fndecl) = 1;
   19007   TREE_READONLY (new_fndecl) = 1;
   19008 
   19009   return new_fndecl;
   19010 }
   19011 
   19012 /* Returns a decl of a function that implements scatter store with
   19013    register type VECTYPE and index type INDEX_TYPE and SCALE.
   19014    Return NULL_TREE if it is not available.  */
   19015 
   19016 static tree
   19017 ix86_vectorize_builtin_scatter (const_tree vectype,
   19018 				const_tree index_type, int scale)
   19019 {
   19020   bool si;
   19021   enum ix86_builtins code;
   19022 
   19023   if (!TARGET_AVX512F)
   19024     return NULL_TREE;
   19025 
   19026   if (known_eq (TYPE_VECTOR_SUBPARTS (vectype), 2u)
   19027       ? !TARGET_USE_SCATTER_2PARTS
   19028       : (known_eq (TYPE_VECTOR_SUBPARTS (vectype), 4u)
   19029 	 ? !TARGET_USE_SCATTER_4PARTS
   19030 	 : !TARGET_USE_SCATTER_8PARTS))
   19031     return NULL_TREE;
   19032 
   19033   if ((TREE_CODE (index_type) != INTEGER_TYPE
   19034        && !POINTER_TYPE_P (index_type))
   19035       || (TYPE_MODE (index_type) != SImode
   19036 	  && TYPE_MODE (index_type) != DImode))
   19037     return NULL_TREE;
   19038 
   19039   if (TYPE_PRECISION (index_type) > POINTER_SIZE)
   19040     return NULL_TREE;
   19041 
   19042   /* v*scatter* insn sign extends index to pointer mode.  */
   19043   if (TYPE_PRECISION (index_type) < POINTER_SIZE
   19044       && TYPE_UNSIGNED (index_type))
   19045     return NULL_TREE;
   19046 
   19047   /* Scale can be 1, 2, 4 or 8.  */
   19048   if (scale <= 0
   19049       || scale > 8
   19050       || (scale & (scale - 1)) != 0)
   19051     return NULL_TREE;
   19052 
   19053   si = TYPE_MODE (index_type) == SImode;
   19054   switch (TYPE_MODE (vectype))
   19055     {
   19056     case E_V8DFmode:
   19057       code = si ? IX86_BUILTIN_SCATTERALTSIV8DF : IX86_BUILTIN_SCATTERDIV8DF;
   19058       break;
   19059     case E_V8DImode:
   19060       code = si ? IX86_BUILTIN_SCATTERALTSIV8DI : IX86_BUILTIN_SCATTERDIV8DI;
   19061       break;
   19062     case E_V16SFmode:
   19063       code = si ? IX86_BUILTIN_SCATTERSIV16SF : IX86_BUILTIN_SCATTERALTDIV16SF;
   19064       break;
   19065     case E_V16SImode:
   19066       code = si ? IX86_BUILTIN_SCATTERSIV16SI : IX86_BUILTIN_SCATTERALTDIV16SI;
   19067       break;
   19068     case E_V4DFmode:
   19069       if (TARGET_AVX512VL)
   19070 	code = si ? IX86_BUILTIN_SCATTERALTSIV4DF : IX86_BUILTIN_SCATTERDIV4DF;
   19071       else
   19072 	return NULL_TREE;
   19073       break;
   19074     case E_V4DImode:
   19075       if (TARGET_AVX512VL)
   19076 	code = si ? IX86_BUILTIN_SCATTERALTSIV4DI : IX86_BUILTIN_SCATTERDIV4DI;
   19077       else
   19078 	return NULL_TREE;
   19079       break;
   19080     case E_V8SFmode:
   19081       if (TARGET_AVX512VL)
   19082 	code = si ? IX86_BUILTIN_SCATTERSIV8SF : IX86_BUILTIN_SCATTERALTDIV8SF;
   19083       else
   19084 	return NULL_TREE;
   19085       break;
   19086     case E_V8SImode:
   19087       if (TARGET_AVX512VL)
   19088 	code = si ? IX86_BUILTIN_SCATTERSIV8SI : IX86_BUILTIN_SCATTERALTDIV8SI;
   19089       else
   19090 	return NULL_TREE;
   19091       break;
   19092     case E_V2DFmode:
   19093       if (TARGET_AVX512VL)
   19094 	code = si ? IX86_BUILTIN_SCATTERALTSIV2DF : IX86_BUILTIN_SCATTERDIV2DF;
   19095       else
   19096 	return NULL_TREE;
   19097       break;
   19098     case E_V2DImode:
   19099       if (TARGET_AVX512VL)
   19100 	code = si ? IX86_BUILTIN_SCATTERALTSIV2DI : IX86_BUILTIN_SCATTERDIV2DI;
   19101       else
   19102 	return NULL_TREE;
   19103       break;
   19104     case E_V4SFmode:
   19105       if (TARGET_AVX512VL)
   19106 	code = si ? IX86_BUILTIN_SCATTERSIV4SF : IX86_BUILTIN_SCATTERALTDIV4SF;
   19107       else
   19108 	return NULL_TREE;
   19109       break;
   19110     case E_V4SImode:
   19111       if (TARGET_AVX512VL)
   19112 	code = si ? IX86_BUILTIN_SCATTERSIV4SI : IX86_BUILTIN_SCATTERALTDIV4SI;
   19113       else
   19114 	return NULL_TREE;
   19115       break;
   19116     default:
   19117       return NULL_TREE;
   19118     }
   19119 
   19120   return get_ix86_builtin (code);
   19121 }
   19122 
   19123 /* Return true if it is safe to use the rsqrt optabs to optimize
   19124    1.0/sqrt.  */
   19125 
   19126 static bool
   19127 use_rsqrt_p (machine_mode mode)
   19128 {
   19129   return ((mode == HFmode
   19130 	   || (TARGET_SSE && TARGET_SSE_MATH))
   19131 	  && flag_finite_math_only
   19132 	  && !flag_trapping_math
   19133 	  && flag_unsafe_math_optimizations);
   19134 }
   19135 
   19136 /* Helper for avx_vpermilps256_operand et al.  This is also used by
   19138    the expansion functions to turn the parallel back into a mask.
   19139    The return value is 0 for no match and the imm8+1 for a match.  */
   19140 
   19141 int
   19142 avx_vpermilp_parallel (rtx par, machine_mode mode)
   19143 {
   19144   unsigned i, nelt = GET_MODE_NUNITS (mode);
   19145   unsigned mask = 0;
   19146   unsigned char ipar[16] = {};  /* Silence -Wuninitialized warning.  */
   19147 
   19148   if (XVECLEN (par, 0) != (int) nelt)
   19149     return 0;
   19150 
   19151   /* Validate that all of the elements are constants, and not totally
   19152      out of range.  Copy the data into an integral array to make the
   19153      subsequent checks easier.  */
   19154   for (i = 0; i < nelt; ++i)
   19155     {
   19156       rtx er = XVECEXP (par, 0, i);
   19157       unsigned HOST_WIDE_INT ei;
   19158 
   19159       if (!CONST_INT_P (er))
   19160 	return 0;
   19161       ei = INTVAL (er);
   19162       if (ei >= nelt)
   19163 	return 0;
   19164       ipar[i] = ei;
   19165     }
   19166 
   19167   switch (mode)
   19168     {
   19169     case E_V8DFmode:
   19170       /* In the 512-bit DFmode case, we can only move elements within
   19171          a 128-bit lane.  First fill the second part of the mask,
   19172 	 then fallthru.  */
   19173       for (i = 4; i < 6; ++i)
   19174 	{
   19175 	  if (ipar[i] < 4 || ipar[i] >= 6)
   19176 	    return 0;
   19177 	  mask |= (ipar[i] - 4) << i;
   19178 	}
   19179       for (i = 6; i < 8; ++i)
   19180 	{
   19181 	  if (ipar[i] < 6)
   19182 	    return 0;
   19183 	  mask |= (ipar[i] - 6) << i;
   19184 	}
   19185       /* FALLTHRU */
   19186 
   19187     case E_V4DFmode:
   19188       /* In the 256-bit DFmode case, we can only move elements within
   19189          a 128-bit lane.  */
   19190       for (i = 0; i < 2; ++i)
   19191 	{
   19192 	  if (ipar[i] >= 2)
   19193 	    return 0;
   19194 	  mask |= ipar[i] << i;
   19195 	}
   19196       for (i = 2; i < 4; ++i)
   19197 	{
   19198 	  if (ipar[i] < 2)
   19199 	    return 0;
   19200 	  mask |= (ipar[i] - 2) << i;
   19201 	}
   19202       break;
   19203 
   19204     case E_V16SFmode:
   19205       /* In 512 bit SFmode case, permutation in the upper 256 bits
   19206 	 must mirror the permutation in the lower 256-bits.  */
   19207       for (i = 0; i < 8; ++i)
   19208 	if (ipar[i] + 8 != ipar[i + 8])
   19209 	  return 0;
   19210       /* FALLTHRU */
   19211 
   19212     case E_V8SFmode:
   19213       /* In 256 bit SFmode case, we have full freedom of
   19214          movement within the low 128-bit lane, but the high 128-bit
   19215          lane must mirror the exact same pattern.  */
   19216       for (i = 0; i < 4; ++i)
   19217 	if (ipar[i] + 4 != ipar[i + 4])
   19218 	  return 0;
   19219       nelt = 4;
   19220       /* FALLTHRU */
   19221 
   19222     case E_V2DFmode:
   19223     case E_V4SFmode:
   19224       /* In the 128-bit case, we've full freedom in the placement of
   19225 	 the elements from the source operand.  */
   19226       for (i = 0; i < nelt; ++i)
   19227 	mask |= ipar[i] << (i * (nelt / 2));
   19228       break;
   19229 
   19230     default:
   19231       gcc_unreachable ();
   19232     }
   19233 
   19234   /* Make sure success has a non-zero value by adding one.  */
   19235   return mask + 1;
   19236 }
   19237 
   19238 /* Helper for avx_vperm2f128_v4df_operand et al.  This is also used by
   19239    the expansion functions to turn the parallel back into a mask.
   19240    The return value is 0 for no match and the imm8+1 for a match.  */
   19241 
   19242 int
   19243 avx_vperm2f128_parallel (rtx par, machine_mode mode)
   19244 {
   19245   unsigned i, nelt = GET_MODE_NUNITS (mode), nelt2 = nelt / 2;
   19246   unsigned mask = 0;
   19247   unsigned char ipar[8] = {};  /* Silence -Wuninitialized warning.  */
   19248 
   19249   if (XVECLEN (par, 0) != (int) nelt)
   19250     return 0;
   19251 
   19252   /* Validate that all of the elements are constants, and not totally
   19253      out of range.  Copy the data into an integral array to make the
   19254      subsequent checks easier.  */
   19255   for (i = 0; i < nelt; ++i)
   19256     {
   19257       rtx er = XVECEXP (par, 0, i);
   19258       unsigned HOST_WIDE_INT ei;
   19259 
   19260       if (!CONST_INT_P (er))
   19261 	return 0;
   19262       ei = INTVAL (er);
   19263       if (ei >= 2 * nelt)
   19264 	return 0;
   19265       ipar[i] = ei;
   19266     }
   19267 
   19268   /* Validate that the halves of the permute are halves.  */
   19269   for (i = 0; i < nelt2 - 1; ++i)
   19270     if (ipar[i] + 1 != ipar[i + 1])
   19271       return 0;
   19272   for (i = nelt2; i < nelt - 1; ++i)
   19273     if (ipar[i] + 1 != ipar[i + 1])
   19274       return 0;
   19275 
   19276   /* Reconstruct the mask.  */
   19277   for (i = 0; i < 2; ++i)
   19278     {
   19279       unsigned e = ipar[i * nelt2];
   19280       if (e % nelt2)
   19281 	return 0;
   19282       e /= nelt2;
   19283       mask |= e << (i * 4);
   19284     }
   19285 
   19286   /* Make sure success has a non-zero value by adding one.  */
   19287   return mask + 1;
   19288 }
   19289 
   19290 /* Return a register priority for hard reg REGNO.  */
   19292 static int
   19293 ix86_register_priority (int hard_regno)
   19294 {
   19295   /* ebp and r13 as the base always wants a displacement, r12 as the
   19296      base always wants an index.  So discourage their usage in an
   19297      address.  */
   19298   if (hard_regno == R12_REG || hard_regno == R13_REG)
   19299     return 0;
   19300   if (hard_regno == BP_REG)
   19301     return 1;
   19302   /* New x86-64 int registers result in bigger code size.  Discourage them.  */
   19303   if (REX_INT_REGNO_P (hard_regno))
   19304     return 2;
   19305   /* New x86-64 SSE registers result in bigger code size.  Discourage them.  */
   19306   if (REX_SSE_REGNO_P (hard_regno))
   19307     return 2;
   19308   if (EXT_REX_SSE_REGNO_P (hard_regno))
   19309     return 1;
   19310   /* Usage of AX register results in smaller code.  Prefer it.  */
   19311   if (hard_regno == AX_REG)
   19312     return 4;
   19313   return 3;
   19314 }
   19315 
   19316 /* Implement TARGET_PREFERRED_RELOAD_CLASS.
   19317 
   19318    Put float CONST_DOUBLE in the constant pool instead of fp regs.
   19319    QImode must go into class Q_REGS.
   19320    Narrow ALL_REGS to GENERAL_REGS.  This supports allowing movsf and
   19321    movdf to do mem-to-mem moves through integer regs.  */
   19322 
   19323 static reg_class_t
   19324 ix86_preferred_reload_class (rtx x, reg_class_t regclass)
   19325 {
   19326   machine_mode mode = GET_MODE (x);
   19327 
   19328   /* We're only allowed to return a subclass of CLASS.  Many of the
   19329      following checks fail for NO_REGS, so eliminate that early.  */
   19330   if (regclass == NO_REGS)
   19331     return NO_REGS;
   19332 
   19333   /* All classes can load zeros.  */
   19334   if (x == CONST0_RTX (mode))
   19335     return regclass;
   19336 
   19337   /* Force constants into memory if we are loading a (nonzero) constant into
   19338      an MMX, SSE or MASK register.  This is because there are no MMX/SSE/MASK
   19339      instructions to load from a constant.  */
   19340   if (CONSTANT_P (x)
   19341       && (MAYBE_MMX_CLASS_P (regclass)
   19342 	  || MAYBE_SSE_CLASS_P (regclass)
   19343 	  || MAYBE_MASK_CLASS_P (regclass)))
   19344     return NO_REGS;
   19345 
   19346   /* Floating-point constants need more complex checks.  */
   19347   if (CONST_DOUBLE_P (x))
   19348     {
   19349       /* General regs can load everything.  */
   19350       if (INTEGER_CLASS_P (regclass))
   19351         return regclass;
   19352 
   19353       /* Floats can load 0 and 1 plus some others.  Note that we eliminated
   19354 	 zero above.  We only want to wind up preferring 80387 registers if
   19355 	 we plan on doing computation with them.  */
   19356       if (IS_STACK_MODE (mode)
   19357 	  && standard_80387_constant_p (x) > 0)
   19358 	{
   19359 	  /* Limit class to FP regs.  */
   19360 	  if (FLOAT_CLASS_P (regclass))
   19361 	    return FLOAT_REGS;
   19362 	}
   19363 
   19364       return NO_REGS;
   19365     }
   19366 
   19367   /* Prefer SSE if we can use them for math.  Also allow integer regs
   19368      when moves between register units are cheap.  */
   19369   if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
   19370     {
   19371       if (TARGET_INTER_UNIT_MOVES_FROM_VEC
   19372 	  && TARGET_INTER_UNIT_MOVES_TO_VEC
   19373 	  && GET_MODE_SIZE (mode) <= GET_MODE_SIZE (word_mode))
   19374 	return INT_SSE_CLASS_P (regclass) ? regclass : NO_REGS;
   19375       else
   19376 	return SSE_CLASS_P (regclass) ? regclass : NO_REGS;
   19377     }
   19378 
   19379   /* Generally when we see PLUS here, it's the function invariant
   19380      (plus soft-fp const_int).  Which can only be computed into general
   19381      regs.  */
   19382   if (GET_CODE (x) == PLUS)
   19383     return INTEGER_CLASS_P (regclass) ? regclass : NO_REGS;
   19384 
   19385   /* QImode constants are easy to load, but non-constant QImode data
   19386      must go into Q_REGS or ALL_MASK_REGS.  */
   19387   if (GET_MODE (x) == QImode && !CONSTANT_P (x))
   19388     {
   19389       if (Q_CLASS_P (regclass))
   19390 	return regclass;
   19391       else if (reg_class_subset_p (Q_REGS, regclass))
   19392 	return Q_REGS;
   19393       else if (MASK_CLASS_P (regclass))
   19394 	return regclass;
   19395       else
   19396 	return NO_REGS;
   19397     }
   19398 
   19399   return regclass;
   19400 }
   19401 
   19402 /* Discourage putting floating-point values in SSE registers unless
   19403    SSE math is being used, and likewise for the 387 registers.  */
   19404 static reg_class_t
   19405 ix86_preferred_output_reload_class (rtx x, reg_class_t regclass)
   19406 {
   19407   /* Restrict the output reload class to the register bank that we are doing
   19408      math on.  If we would like not to return a subset of CLASS, reject this
   19409      alternative: if reload cannot do this, it will still use its choice.  */
   19410   machine_mode mode = GET_MODE (x);
   19411   if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
   19412     return MAYBE_SSE_CLASS_P (regclass) ? ALL_SSE_REGS : NO_REGS;
   19413 
   19414   if (IS_STACK_MODE (mode))
   19415     return FLOAT_CLASS_P (regclass) ? regclass : NO_REGS;
   19416 
   19417   return regclass;
   19418 }
   19419 
   19420 static reg_class_t
   19421 ix86_secondary_reload (bool in_p, rtx x, reg_class_t rclass,
   19422 		       machine_mode mode, secondary_reload_info *sri)
   19423 {
   19424   /* Double-word spills from general registers to non-offsettable memory
   19425      references (zero-extended addresses) require special handling.  */
   19426   if (TARGET_64BIT
   19427       && MEM_P (x)
   19428       && GET_MODE_SIZE (mode) > UNITS_PER_WORD
   19429       && INTEGER_CLASS_P (rclass)
   19430       && !offsettable_memref_p (x))
   19431     {
   19432       sri->icode = (in_p
   19433 		    ? CODE_FOR_reload_noff_load
   19434 		    : CODE_FOR_reload_noff_store);
   19435       /* Add the cost of moving address to a temporary.  */
   19436       sri->extra_cost = 1;
   19437 
   19438       return NO_REGS;
   19439     }
   19440 
   19441   /* QImode spills from non-QI registers require
   19442      intermediate register on 32bit targets.  */
   19443   if (mode == QImode
   19444       && ((!TARGET_64BIT && !in_p
   19445 	   && INTEGER_CLASS_P (rclass)
   19446 	   && MAYBE_NON_Q_CLASS_P (rclass))
   19447 	  || (!TARGET_AVX512DQ
   19448 	      && MAYBE_MASK_CLASS_P (rclass))))
   19449     {
   19450       int regno = true_regnum (x);
   19451 
   19452       /* Return Q_REGS if the operand is in memory.  */
   19453       if (regno == -1)
   19454 	return Q_REGS;
   19455 
   19456       return NO_REGS;
   19457     }
   19458 
   19459   /* Require movement to gpr, and then store to memory.  */
   19460   if ((mode == HFmode || mode == HImode || mode == V2QImode)
   19461       && !TARGET_SSE4_1
   19462       && SSE_CLASS_P (rclass)
   19463       && !in_p && MEM_P (x))
   19464     {
   19465       sri->extra_cost = 1;
   19466       return GENERAL_REGS;
   19467     }
   19468 
   19469   /* This condition handles corner case where an expression involving
   19470      pointers gets vectorized.  We're trying to use the address of a
   19471      stack slot as a vector initializer.
   19472 
   19473      (set (reg:V2DI 74 [ vect_cst_.2 ])
   19474           (vec_duplicate:V2DI (reg/f:DI 20 frame)))
   19475 
   19476      Eventually frame gets turned into sp+offset like this:
   19477 
   19478      (set (reg:V2DI 21 xmm0 [orig:74 vect_cst_.2 ] [74])
   19479           (vec_duplicate:V2DI (plus:DI (reg/f:DI 7 sp)
   19480 	                               (const_int 392 [0x188]))))
   19481 
   19482      That later gets turned into:
   19483 
   19484      (set (reg:V2DI 21 xmm0 [orig:74 vect_cst_.2 ] [74])
   19485           (vec_duplicate:V2DI (plus:DI (reg/f:DI 7 sp)
   19486 	    (mem/u/c/i:DI (symbol_ref/u:DI ("*.LC0") [flags 0x2]) [0 S8 A64]))))
   19487 
   19488      We'll have the following reload recorded:
   19489 
   19490      Reload 0: reload_in (DI) =
   19491            (plus:DI (reg/f:DI 7 sp)
   19492             (mem/u/c/i:DI (symbol_ref/u:DI ("*.LC0") [flags 0x2]) [0 S8 A64]))
   19493      reload_out (V2DI) = (reg:V2DI 21 xmm0 [orig:74 vect_cst_.2 ] [74])
   19494      SSE_REGS, RELOAD_OTHER (opnum = 0), can't combine
   19495      reload_in_reg: (plus:DI (reg/f:DI 7 sp) (const_int 392 [0x188]))
   19496      reload_out_reg: (reg:V2DI 21 xmm0 [orig:74 vect_cst_.2 ] [74])
   19497      reload_reg_rtx: (reg:V2DI 22 xmm1)
   19498 
   19499      Which isn't going to work since SSE instructions can't handle scalar
   19500      additions.  Returning GENERAL_REGS forces the addition into integer
   19501      register and reload can handle subsequent reloads without problems.  */
   19502 
   19503   if (in_p && GET_CODE (x) == PLUS
   19504       && SSE_CLASS_P (rclass)
   19505       && SCALAR_INT_MODE_P (mode))
   19506     return GENERAL_REGS;
   19507 
   19508   return NO_REGS;
   19509 }
   19510 
   19511 /* Implement TARGET_CLASS_LIKELY_SPILLED_P.  */
   19512 
   19513 static bool
   19514 ix86_class_likely_spilled_p (reg_class_t rclass)
   19515 {
   19516   switch (rclass)
   19517     {
   19518       case AREG:
   19519       case DREG:
   19520       case CREG:
   19521       case BREG:
   19522       case AD_REGS:
   19523       case SIREG:
   19524       case DIREG:
   19525       case SSE_FIRST_REG:
   19526       case FP_TOP_REG:
   19527       case FP_SECOND_REG:
   19528 	return true;
   19529 
   19530       default:
   19531 	break;
   19532     }
   19533 
   19534   return false;
   19535 }
   19536 
   19537 /* Return true if a set of DST by the expression SRC should be allowed.
   19538    This prevents complex sets of likely_spilled hard regs before reload.  */
   19539 
   19540 bool
   19541 ix86_hardreg_mov_ok (rtx dst, rtx src)
   19542 {
   19543   /* Avoid complex sets of likely_spilled hard registers before reload.  */
   19544   if (REG_P (dst) && HARD_REGISTER_P (dst)
   19545       && !REG_P (src) && !MEM_P (src)
   19546       && !(VECTOR_MODE_P (GET_MODE (dst))
   19547 	   ? standard_sse_constant_p (src, GET_MODE (dst))
   19548 	   : x86_64_immediate_operand (src, GET_MODE (dst)))
   19549       && ix86_class_likely_spilled_p (REGNO_REG_CLASS (REGNO (dst)))
   19550       && !reload_completed)
   19551     return false;
   19552   return true;
   19553 }
   19554 
   19555 /* If we are copying between registers from different register sets
   19556    (e.g. FP and integer), we may need a memory location.
   19557 
   19558    The function can't work reliably when one of the CLASSES is a class
   19559    containing registers from multiple sets.  We avoid this by never combining
   19560    different sets in a single alternative in the machine description.
   19561    Ensure that this constraint holds to avoid unexpected surprises.
   19562 
   19563    When STRICT is false, we are being called from REGISTER_MOVE_COST,
   19564    so do not enforce these sanity checks.
   19565 
   19566    To optimize register_move_cost performance, define inline variant.  */
   19567 
   19568 static inline bool
   19569 inline_secondary_memory_needed (machine_mode mode, reg_class_t class1,
   19570 				reg_class_t class2, int strict)
   19571 {
   19572   if (lra_in_progress && (class1 == NO_REGS || class2 == NO_REGS))
   19573     return false;
   19574 
   19575   if (MAYBE_FLOAT_CLASS_P (class1) != FLOAT_CLASS_P (class1)
   19576       || MAYBE_FLOAT_CLASS_P (class2) != FLOAT_CLASS_P (class2)
   19577       || MAYBE_SSE_CLASS_P (class1) != SSE_CLASS_P (class1)
   19578       || MAYBE_SSE_CLASS_P (class2) != SSE_CLASS_P (class2)
   19579       || MAYBE_MMX_CLASS_P (class1) != MMX_CLASS_P (class1)
   19580       || MAYBE_MMX_CLASS_P (class2) != MMX_CLASS_P (class2)
   19581       || MAYBE_MASK_CLASS_P (class1) != MASK_CLASS_P (class1)
   19582       || MAYBE_MASK_CLASS_P (class2) != MASK_CLASS_P (class2))
   19583     {
   19584       gcc_assert (!strict || lra_in_progress);
   19585       return true;
   19586     }
   19587 
   19588   if (FLOAT_CLASS_P (class1) != FLOAT_CLASS_P (class2))
   19589     return true;
   19590 
   19591   /* ??? This is a lie.  We do have moves between mmx/general, and for
   19592      mmx/sse2.  But by saying we need secondary memory we discourage the
   19593      register allocator from using the mmx registers unless needed.  */
   19594   if (MMX_CLASS_P (class1) != MMX_CLASS_P (class2))
   19595     return true;
   19596 
   19597   /* Between mask and general, we have moves no larger than word size.  */
   19598   if (MASK_CLASS_P (class1) != MASK_CLASS_P (class2))
   19599     {
   19600       if (!(INTEGER_CLASS_P (class1) || INTEGER_CLASS_P (class2))
   19601 	  || GET_MODE_SIZE (mode) > UNITS_PER_WORD)
   19602 	return true;
   19603     }
   19604 
   19605   if (SSE_CLASS_P (class1) != SSE_CLASS_P (class2))
   19606     {
   19607       /* SSE1 doesn't have any direct moves from other classes.  */
   19608       if (!TARGET_SSE2)
   19609 	return true;
   19610 
   19611       if (!(INTEGER_CLASS_P (class1) || INTEGER_CLASS_P (class2)))
   19612 	return true;
   19613 
   19614       int msize = GET_MODE_SIZE (mode);
   19615 
   19616       /* Between SSE and general, we have moves no larger than word size.  */
   19617       if (msize > UNITS_PER_WORD)
   19618 	return true;
   19619 
   19620       /* In addition to SImode moves, HImode moves are supported for SSE2 and above,
   19621 	 Use vmovw with AVX512FP16, or pinsrw/pextrw without AVX512FP16.  */
   19622       int minsize = GET_MODE_SIZE (TARGET_SSE2 ? HImode : SImode);
   19623 
   19624       if (msize < minsize)
   19625 	return true;
   19626 
   19627       /* If the target says that inter-unit moves are more expensive
   19628 	 than moving through memory, then don't generate them.  */
   19629       if ((SSE_CLASS_P (class1) && !TARGET_INTER_UNIT_MOVES_FROM_VEC)
   19630 	  || (SSE_CLASS_P (class2) && !TARGET_INTER_UNIT_MOVES_TO_VEC))
   19631 	return true;
   19632     }
   19633 
   19634   return false;
   19635 }
   19636 
   19637 /* Implement TARGET_SECONDARY_MEMORY_NEEDED.  */
   19638 
   19639 static bool
   19640 ix86_secondary_memory_needed (machine_mode mode, reg_class_t class1,
   19641 			      reg_class_t class2)
   19642 {
   19643   return inline_secondary_memory_needed (mode, class1, class2, true);
   19644 }
   19645 
   19646 /* Implement TARGET_SECONDARY_MEMORY_NEEDED_MODE.
   19647 
   19648    get_secondary_mem widens integral modes to BITS_PER_WORD.
   19649    There is no need to emit full 64 bit move on 64 bit targets
   19650    for integral modes that can be moved using 32 bit move.  */
   19651 
   19652 static machine_mode
   19653 ix86_secondary_memory_needed_mode (machine_mode mode)
   19654 {
   19655   if (GET_MODE_BITSIZE (mode) < 32 && INTEGRAL_MODE_P (mode))
   19656     return mode_for_size (32, GET_MODE_CLASS (mode), 0).require ();
   19657   return mode;
   19658 }
   19659 
   19660 /* Implement the TARGET_CLASS_MAX_NREGS hook.
   19661 
   19662    On the 80386, this is the size of MODE in words,
   19663    except in the FP regs, where a single reg is always enough.  */
   19664 
   19665 static unsigned char
   19666 ix86_class_max_nregs (reg_class_t rclass, machine_mode mode)
   19667 {
   19668   if (MAYBE_INTEGER_CLASS_P (rclass))
   19669     {
   19670       if (mode == XFmode)
   19671 	return (TARGET_64BIT ? 2 : 3);
   19672       else if (mode == XCmode)
   19673 	return (TARGET_64BIT ? 4 : 6);
   19674       else
   19675 	return CEIL (GET_MODE_SIZE (mode), UNITS_PER_WORD);
   19676     }
   19677   else
   19678     {
   19679       if (COMPLEX_MODE_P (mode))
   19680 	return 2;
   19681       else
   19682 	return 1;
   19683     }
   19684 }
   19685 
   19686 /* Implement TARGET_CAN_CHANGE_MODE_CLASS.  */
   19687 
   19688 static bool
   19689 ix86_can_change_mode_class (machine_mode from, machine_mode to,
   19690 			    reg_class_t regclass)
   19691 {
   19692   if (from == to)
   19693     return true;
   19694 
   19695   /* x87 registers can't do subreg at all, as all values are reformatted
   19696      to extended precision.  */
   19697   if (MAYBE_FLOAT_CLASS_P (regclass))
   19698     return false;
   19699 
   19700   if (MAYBE_SSE_CLASS_P (regclass) || MAYBE_MMX_CLASS_P (regclass))
   19701     {
   19702       /* Vector registers do not support QI or HImode loads.  If we don't
   19703 	 disallow a change to these modes, reload will assume it's ok to
   19704 	 drop the subreg from (subreg:SI (reg:HI 100) 0).  This affects
   19705 	 the vec_dupv4hi pattern.
   19706 	 NB: SSE2 can load 16bit data to sse register via pinsrw.  */
   19707       int mov_size = MAYBE_SSE_CLASS_P (regclass) && TARGET_SSE2 ? 2 : 4;
   19708       if (GET_MODE_SIZE (from) < mov_size)
   19709 	return false;
   19710     }
   19711 
   19712   return true;
   19713 }
   19714 
   19715 /* Return index of MODE in the sse load/store tables.  */
   19716 
   19717 static inline int
   19718 sse_store_index (machine_mode mode)
   19719 {
   19720   /* NB: Use SFmode cost for HFmode instead of adding HFmode load/store
   19721      costs to processor_costs, which requires changes to all entries in
   19722      processor cost table.  */
   19723   if (mode == E_HFmode)
   19724     mode = E_SFmode;
   19725 
   19726   switch (GET_MODE_SIZE (mode))
   19727     {
   19728     case 4:
   19729       return 0;
   19730     case 8:
   19731       return 1;
   19732     case 16:
   19733       return 2;
   19734     case 32:
   19735       return 3;
   19736     case 64:
   19737       return 4;
   19738     default:
   19739       return -1;
   19740     }
   19741 }
   19742 
   19743 /* Return the cost of moving data of mode M between a
   19744    register and memory.  A value of 2 is the default; this cost is
   19745    relative to those in `REGISTER_MOVE_COST'.
   19746 
   19747    This function is used extensively by register_move_cost that is used to
   19748    build tables at startup.  Make it inline in this case.
   19749    When IN is 2, return maximum of in and out move cost.
   19750 
   19751    If moving between registers and memory is more expensive than
   19752    between two registers, you should define this macro to express the
   19753    relative cost.
   19754 
   19755    Model also increased moving costs of QImode registers in non
   19756    Q_REGS classes.
   19757  */
   19758 static inline int
   19759 inline_memory_move_cost (machine_mode mode, enum reg_class regclass, int in)
   19760 {
   19761   int cost;
   19762 
   19763   if (FLOAT_CLASS_P (regclass))
   19764     {
   19765       int index;
   19766       switch (mode)
   19767 	{
   19768 	  case E_SFmode:
   19769 	    index = 0;
   19770 	    break;
   19771 	  case E_DFmode:
   19772 	    index = 1;
   19773 	    break;
   19774 	  case E_XFmode:
   19775 	    index = 2;
   19776 	    break;
   19777 	  default:
   19778 	    return 100;
   19779 	}
   19780       if (in == 2)
   19781         return MAX (ix86_cost->hard_register.fp_load [index],
   19782 		    ix86_cost->hard_register.fp_store [index]);
   19783       return in ? ix86_cost->hard_register.fp_load [index]
   19784 		: ix86_cost->hard_register.fp_store [index];
   19785     }
   19786   if (SSE_CLASS_P (regclass))
   19787     {
   19788       int index = sse_store_index (mode);
   19789       if (index == -1)
   19790 	return 100;
   19791       if (in == 2)
   19792         return MAX (ix86_cost->hard_register.sse_load [index],
   19793 		    ix86_cost->hard_register.sse_store [index]);
   19794       return in ? ix86_cost->hard_register.sse_load [index]
   19795 		: ix86_cost->hard_register.sse_store [index];
   19796     }
   19797   if (MASK_CLASS_P (regclass))
   19798     {
   19799       int index;
   19800       switch (GET_MODE_SIZE (mode))
   19801 	{
   19802 	case 1:
   19803 	  index = 0;
   19804 	  break;
   19805 	case 2:
   19806 	  index = 1;
   19807 	  break;
   19808 	/* DImode loads and stores assumed to cost the same as SImode.  */
   19809 	default:
   19810 	  index = 2;
   19811 	  break;
   19812 	}
   19813 
   19814       if (in == 2)
   19815 	return MAX (ix86_cost->hard_register.mask_load[index],
   19816 		    ix86_cost->hard_register.mask_store[index]);
   19817       return in ? ix86_cost->hard_register.mask_load[2]
   19818 		: ix86_cost->hard_register.mask_store[2];
   19819     }
   19820   if (MMX_CLASS_P (regclass))
   19821     {
   19822       int index;
   19823       switch (GET_MODE_SIZE (mode))
   19824 	{
   19825 	  case 4:
   19826 	    index = 0;
   19827 	    break;
   19828 	  case 8:
   19829 	    index = 1;
   19830 	    break;
   19831 	  default:
   19832 	    return 100;
   19833 	}
   19834       if (in == 2)
   19835         return MAX (ix86_cost->hard_register.mmx_load [index],
   19836 		    ix86_cost->hard_register.mmx_store [index]);
   19837       return in ? ix86_cost->hard_register.mmx_load [index]
   19838 		: ix86_cost->hard_register.mmx_store [index];
   19839     }
   19840   switch (GET_MODE_SIZE (mode))
   19841     {
   19842       case 1:
   19843 	if (Q_CLASS_P (regclass) || TARGET_64BIT)
   19844 	  {
   19845 	    if (!in)
   19846 	      return ix86_cost->hard_register.int_store[0];
   19847 	    if (TARGET_PARTIAL_REG_DEPENDENCY
   19848 	        && optimize_function_for_speed_p (cfun))
   19849 	      cost = ix86_cost->hard_register.movzbl_load;
   19850 	    else
   19851 	      cost = ix86_cost->hard_register.int_load[0];
   19852 	    if (in == 2)
   19853 	      return MAX (cost, ix86_cost->hard_register.int_store[0]);
   19854 	    return cost;
   19855 	  }
   19856 	else
   19857 	  {
   19858 	   if (in == 2)
   19859 	     return MAX (ix86_cost->hard_register.movzbl_load,
   19860 			 ix86_cost->hard_register.int_store[0] + 4);
   19861 	   if (in)
   19862 	     return ix86_cost->hard_register.movzbl_load;
   19863 	   else
   19864 	     return ix86_cost->hard_register.int_store[0] + 4;
   19865 	  }
   19866 	break;
   19867       case 2:
   19868 	{
   19869 	  int cost;
   19870 	  if (in == 2)
   19871 	    cost = MAX (ix86_cost->hard_register.int_load[1],
   19872 			ix86_cost->hard_register.int_store[1]);
   19873 	  else
   19874 	    cost = in ? ix86_cost->hard_register.int_load[1]
   19875 		      : ix86_cost->hard_register.int_store[1];
   19876 
   19877 	  if (mode == E_HFmode)
   19878 	    {
   19879 	      /* Prefer SSE over GPR for HFmode.  */
   19880 	      int sse_cost;
   19881 	      int index = sse_store_index (mode);
   19882 	      if (in == 2)
   19883 		sse_cost = MAX (ix86_cost->hard_register.sse_load[index],
   19884 				ix86_cost->hard_register.sse_store[index]);
   19885 	      else
   19886 		sse_cost = (in
   19887 			    ? ix86_cost->hard_register.sse_load [index]
   19888 			    : ix86_cost->hard_register.sse_store [index]);
   19889 	      if (sse_cost >= cost)
   19890 		cost = sse_cost + 1;
   19891 	    }
   19892 	  return cost;
   19893 	}
   19894       default:
   19895 	if (in == 2)
   19896 	  cost = MAX (ix86_cost->hard_register.int_load[2],
   19897 		      ix86_cost->hard_register.int_store[2]);
   19898 	else if (in)
   19899 	  cost = ix86_cost->hard_register.int_load[2];
   19900 	else
   19901 	  cost = ix86_cost->hard_register.int_store[2];
   19902 	/* Multiply with the number of GPR moves needed.  */
   19903 	return cost * CEIL ((int) GET_MODE_SIZE (mode), UNITS_PER_WORD);
   19904     }
   19905 }
   19906 
   19907 static int
   19908 ix86_memory_move_cost (machine_mode mode, reg_class_t regclass, bool in)
   19909 {
   19910   return inline_memory_move_cost (mode, (enum reg_class) regclass, in ? 1 : 0);
   19911 }
   19912 
   19913 
   19914 /* Return the cost of moving data from a register in class CLASS1 to
   19915    one in class CLASS2.
   19916 
   19917    It is not required that the cost always equal 2 when FROM is the same as TO;
   19918    on some machines it is expensive to move between registers if they are not
   19919    general registers.  */
   19920 
   19921 static int
   19922 ix86_register_move_cost (machine_mode mode, reg_class_t class1_i,
   19923 			 reg_class_t class2_i)
   19924 {
   19925   enum reg_class class1 = (enum reg_class) class1_i;
   19926   enum reg_class class2 = (enum reg_class) class2_i;
   19927 
   19928   /* In case we require secondary memory, compute cost of the store followed
   19929      by load.  In order to avoid bad register allocation choices, we need
   19930      for this to be *at least* as high as the symmetric MEMORY_MOVE_COST.  */
   19931 
   19932   if (inline_secondary_memory_needed (mode, class1, class2, false))
   19933     {
   19934       int cost = 1;
   19935 
   19936       cost += inline_memory_move_cost (mode, class1, 2);
   19937       cost += inline_memory_move_cost (mode, class2, 2);
   19938 
   19939       /* In case of copying from general_purpose_register we may emit multiple
   19940          stores followed by single load causing memory size mismatch stall.
   19941          Count this as arbitrarily high cost of 20.  */
   19942       if (GET_MODE_BITSIZE (mode) > BITS_PER_WORD
   19943 	  && TARGET_MEMORY_MISMATCH_STALL
   19944 	  && targetm.class_max_nregs (class1, mode)
   19945 	     > targetm.class_max_nregs (class2, mode))
   19946 	cost += 20;
   19947 
   19948       /* In the case of FP/MMX moves, the registers actually overlap, and we
   19949 	 have to switch modes in order to treat them differently.  */
   19950       if ((MMX_CLASS_P (class1) && MAYBE_FLOAT_CLASS_P (class2))
   19951           || (MMX_CLASS_P (class2) && MAYBE_FLOAT_CLASS_P (class1)))
   19952 	cost += 20;
   19953 
   19954       return cost;
   19955     }
   19956 
   19957   /* Moves between MMX and non-MMX units require secondary memory.  */
   19958   if (MMX_CLASS_P (class1) != MMX_CLASS_P (class2))
   19959     gcc_unreachable ();
   19960 
   19961   if (SSE_CLASS_P (class1) != SSE_CLASS_P (class2))
   19962     return (SSE_CLASS_P (class1)
   19963 	    ? ix86_cost->hard_register.sse_to_integer
   19964 	    : ix86_cost->hard_register.integer_to_sse);
   19965 
   19966   /* Moves between mask register and GPR.  */
   19967   if (MASK_CLASS_P (class1) != MASK_CLASS_P (class2))
   19968     {
   19969       return (MASK_CLASS_P (class1)
   19970 	      ? ix86_cost->hard_register.mask_to_integer
   19971 	      : ix86_cost->hard_register.integer_to_mask);
   19972     }
   19973   /* Moving between mask registers.  */
   19974   if (MASK_CLASS_P (class1) && MASK_CLASS_P (class2))
   19975     return ix86_cost->hard_register.mask_move;
   19976 
   19977   if (MAYBE_FLOAT_CLASS_P (class1))
   19978     return ix86_cost->hard_register.fp_move;
   19979   if (MAYBE_SSE_CLASS_P (class1))
   19980     {
   19981       if (GET_MODE_BITSIZE (mode) <= 128)
   19982 	return ix86_cost->hard_register.xmm_move;
   19983       if (GET_MODE_BITSIZE (mode) <= 256)
   19984 	return ix86_cost->hard_register.ymm_move;
   19985       return ix86_cost->hard_register.zmm_move;
   19986     }
   19987   if (MAYBE_MMX_CLASS_P (class1))
   19988     return ix86_cost->hard_register.mmx_move;
   19989   return 2;
   19990 }
   19991 
   19992 /* Implement TARGET_HARD_REGNO_NREGS.  This is ordinarily the length in
   19993    words of a value of mode MODE but can be less for certain modes in
   19994    special long registers.
   19995 
   19996    Actually there are no two word move instructions for consecutive
   19997    registers.  And only registers 0-3 may have mov byte instructions
   19998    applied to them.  */
   19999 
   20000 static unsigned int
   20001 ix86_hard_regno_nregs (unsigned int regno, machine_mode mode)
   20002 {
   20003   if (GENERAL_REGNO_P (regno))
   20004     {
   20005       if (mode == XFmode)
   20006 	return TARGET_64BIT ? 2 : 3;
   20007       if (mode == XCmode)
   20008 	return TARGET_64BIT ? 4 : 6;
   20009       return CEIL (GET_MODE_SIZE (mode), UNITS_PER_WORD);
   20010     }
   20011   if (COMPLEX_MODE_P (mode))
   20012     return 2;
   20013   /* Register pair for mask registers.  */
   20014   if (mode == P2QImode || mode == P2HImode)
   20015     return 2;
   20016   if (mode == V64SFmode || mode == V64SImode)
   20017     return 4;
   20018   return 1;
   20019 }
   20020 
   20021 /* Implement REGMODE_NATURAL_SIZE(MODE).  */
   20022 unsigned int
   20023 ix86_regmode_natural_size (machine_mode mode)
   20024 {
   20025   if (mode == P2HImode || mode == P2QImode)
   20026     return GET_MODE_SIZE (mode) / 2;
   20027   return UNITS_PER_WORD;
   20028 }
   20029 
   20030 /* Implement TARGET_HARD_REGNO_MODE_OK.  */
   20031 
   20032 static bool
   20033 ix86_hard_regno_mode_ok (unsigned int regno, machine_mode mode)
   20034 {
   20035   /* Flags and only flags can only hold CCmode values.  */
   20036   if (CC_REGNO_P (regno))
   20037     return GET_MODE_CLASS (mode) == MODE_CC;
   20038   if (GET_MODE_CLASS (mode) == MODE_CC
   20039       || GET_MODE_CLASS (mode) == MODE_RANDOM)
   20040     return false;
   20041   if (STACK_REGNO_P (regno))
   20042     return VALID_FP_MODE_P (mode);
   20043   if (MASK_REGNO_P (regno))
   20044     {
   20045       /* Register pair only starts at even register number.  */
   20046       if ((mode == P2QImode || mode == P2HImode))
   20047 	return MASK_PAIR_REGNO_P(regno);
   20048 
   20049       return ((TARGET_AVX512F && VALID_MASK_REG_MODE (mode))
   20050 	      || (TARGET_AVX512BW
   20051 		  && VALID_MASK_AVX512BW_MODE (mode)));
   20052     }
   20053 
   20054   if (GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
   20055     return false;
   20056 
   20057   if (SSE_REGNO_P (regno))
   20058     {
   20059       /* We implement the move patterns for all vector modes into and
   20060 	 out of SSE registers, even when no operation instructions
   20061 	 are available.  */
   20062 
   20063       /* For AVX-512 we allow, regardless of regno:
   20064 	  - XI mode
   20065 	  - any of 512-bit wide vector mode
   20066 	  - any scalar mode.  */
   20067       if (TARGET_AVX512F
   20068 	  && (VALID_AVX512F_REG_OR_XI_MODE (mode)
   20069 	      || VALID_AVX512F_SCALAR_MODE (mode)))
   20070 	return true;
   20071 
   20072       /* For AVX512FP16, vmovw supports movement of HImode
   20073 	 and HFmode between GPR and SSE registers.  */
   20074       if (TARGET_AVX512FP16
   20075 	  && VALID_AVX512FP16_SCALAR_MODE (mode))
   20076 	return true;
   20077 
   20078       /* For AVX-5124FMAPS or AVX-5124VNNIW
   20079 	 allow V64SF and V64SI modes for special regnos.  */
   20080       if ((TARGET_AVX5124FMAPS || TARGET_AVX5124VNNIW)
   20081 	  && (mode == V64SFmode || mode == V64SImode)
   20082 	  && MOD4_SSE_REGNO_P (regno))
   20083 	return true;
   20084 
   20085       /* TODO check for QI/HI scalars.  */
   20086       /* AVX512VL allows sse regs16+ for 128/256 bit modes.  */
   20087       if (TARGET_AVX512VL
   20088 	  && (VALID_AVX256_REG_OR_OI_MODE (mode)
   20089 	      || VALID_AVX512VL_128_REG_MODE (mode)))
   20090 	return true;
   20091 
   20092       /* xmm16-xmm31 are only available for AVX-512.  */
   20093       if (EXT_REX_SSE_REGNO_P (regno))
   20094 	return false;
   20095 
   20096       /* OImode and AVX modes are available only when AVX is enabled.  */
   20097       return ((TARGET_AVX
   20098 	       && VALID_AVX256_REG_OR_OI_MODE (mode))
   20099 	      || VALID_SSE_REG_MODE (mode)
   20100 	      || VALID_SSE2_REG_MODE (mode)
   20101 	      || VALID_MMX_REG_MODE (mode)
   20102 	      || VALID_MMX_REG_MODE_3DNOW (mode));
   20103     }
   20104   if (MMX_REGNO_P (regno))
   20105     {
   20106       /* We implement the move patterns for 3DNOW modes even in MMX mode,
   20107 	 so if the register is available at all, then we can move data of
   20108 	 the given mode into or out of it.  */
   20109       return (VALID_MMX_REG_MODE (mode)
   20110 	      || VALID_MMX_REG_MODE_3DNOW (mode));
   20111     }
   20112 
   20113   if (mode == QImode)
   20114     {
   20115       /* Take care for QImode values - they can be in non-QI regs,
   20116 	 but then they do cause partial register stalls.  */
   20117       if (ANY_QI_REGNO_P (regno))
   20118 	return true;
   20119       if (!TARGET_PARTIAL_REG_STALL)
   20120 	return true;
   20121       /* LRA checks if the hard register is OK for the given mode.
   20122 	 QImode values can live in non-QI regs, so we allow all
   20123 	 registers here.  */
   20124       if (lra_in_progress)
   20125        return true;
   20126       return !can_create_pseudo_p ();
   20127     }
   20128   /* We handle both integer and floats in the general purpose registers.  */
   20129   else if (VALID_INT_MODE_P (mode)
   20130 	   || VALID_FP_MODE_P (mode))
   20131     return true;
   20132   /* Lots of MMX code casts 8 byte vector modes to DImode.  If we then go
   20133      on to use that value in smaller contexts, this can easily force a
   20134      pseudo to be allocated to GENERAL_REGS.  Since this is no worse than
   20135      supporting DImode, allow it.  */
   20136   else if (VALID_MMX_REG_MODE_3DNOW (mode) || VALID_MMX_REG_MODE (mode))
   20137     return true;
   20138 
   20139   return false;
   20140 }
   20141 
   20142 /* Implement TARGET_INSN_CALLEE_ABI.  */
   20143 
   20144 const predefined_function_abi &
   20145 ix86_insn_callee_abi (const rtx_insn *insn)
   20146 {
   20147   unsigned int abi_id = 0;
   20148   rtx pat = PATTERN (insn);
   20149   if (vzeroupper_pattern (pat, VOIDmode))
   20150     abi_id = ABI_VZEROUPPER;
   20151 
   20152   return function_abis[abi_id];
   20153 }
   20154 
   20155 /* Initialize function_abis with corresponding abi_id,
   20156    currently only handle vzeroupper.  */
   20157 void
   20158 ix86_initialize_callee_abi (unsigned int abi_id)
   20159 {
   20160   gcc_assert (abi_id == ABI_VZEROUPPER);
   20161   predefined_function_abi &vzeroupper_abi = function_abis[abi_id];
   20162   if (!vzeroupper_abi.initialized_p ())
   20163     {
   20164       HARD_REG_SET full_reg_clobbers;
   20165       CLEAR_HARD_REG_SET (full_reg_clobbers);
   20166       vzeroupper_abi.initialize (ABI_VZEROUPPER, full_reg_clobbers);
   20167     }
   20168 }
   20169 
   20170 void
   20171 ix86_expand_avx_vzeroupper (void)
   20172 {
   20173   /* Initialize vzeroupper_abi here.  */
   20174   ix86_initialize_callee_abi (ABI_VZEROUPPER);
   20175   rtx_insn *insn = emit_call_insn (gen_avx_vzeroupper_callee_abi ());
   20176   /* Return false for non-local goto in can_nonlocal_goto.  */
   20177   make_reg_eh_region_note (insn, 0, INT_MIN);
   20178   /* Flag used for call_insn indicates it's a fake call.  */
   20179   RTX_FLAG (insn, used) = 1;
   20180 }
   20181 
   20182 
   20183 /* Implement TARGET_HARD_REGNO_CALL_PART_CLOBBERED.  The only ABI that
   20184    saves SSE registers across calls is Win64 (thus no need to check the
   20185    current ABI here), and with AVX enabled Win64 only guarantees that
   20186    the low 16 bytes are saved.  */
   20187 
   20188 static bool
   20189 ix86_hard_regno_call_part_clobbered (unsigned int abi_id, unsigned int regno,
   20190 				     machine_mode mode)
   20191 {
   20192   /* Special ABI for vzeroupper which only clobber higher part of sse regs.  */
   20193   if (abi_id == ABI_VZEROUPPER)
   20194       return (GET_MODE_SIZE (mode) > 16
   20195 	      && ((TARGET_64BIT && REX_SSE_REGNO_P (regno))
   20196 		  || LEGACY_SSE_REGNO_P (regno)));
   20197 
   20198   return SSE_REGNO_P (regno) && GET_MODE_SIZE (mode) > 16;
   20199 }
   20200 
   20201 /* A subroutine of ix86_modes_tieable_p.  Return true if MODE is a
   20202    tieable integer mode.  */
   20203 
   20204 static bool
   20205 ix86_tieable_integer_mode_p (machine_mode mode)
   20206 {
   20207   switch (mode)
   20208     {
   20209     case E_HImode:
   20210     case E_SImode:
   20211       return true;
   20212 
   20213     case E_QImode:
   20214       return TARGET_64BIT || !TARGET_PARTIAL_REG_STALL;
   20215 
   20216     case E_DImode:
   20217       return TARGET_64BIT;
   20218 
   20219     default:
   20220       return false;
   20221     }
   20222 }
   20223 
   20224 /* Implement TARGET_MODES_TIEABLE_P.
   20225 
   20226    Return true if MODE1 is accessible in a register that can hold MODE2
   20227    without copying.  That is, all register classes that can hold MODE2
   20228    can also hold MODE1.  */
   20229 
   20230 static bool
   20231 ix86_modes_tieable_p (machine_mode mode1, machine_mode mode2)
   20232 {
   20233   if (mode1 == mode2)
   20234     return true;
   20235 
   20236   if (ix86_tieable_integer_mode_p (mode1)
   20237       && ix86_tieable_integer_mode_p (mode2))
   20238     return true;
   20239 
   20240   /* MODE2 being XFmode implies fp stack or general regs, which means we
   20241      can tie any smaller floating point modes to it.  Note that we do not
   20242      tie this with TFmode.  */
   20243   if (mode2 == XFmode)
   20244     return mode1 == SFmode || mode1 == DFmode;
   20245 
   20246   /* MODE2 being DFmode implies fp stack, general or sse regs, which means
   20247      that we can tie it with SFmode.  */
   20248   if (mode2 == DFmode)
   20249     return mode1 == SFmode;
   20250 
   20251   /* If MODE2 is only appropriate for an SSE register, then tie with
   20252      any other mode acceptable to SSE registers.  */
   20253   if (GET_MODE_SIZE (mode2) == 64
   20254       && ix86_hard_regno_mode_ok (FIRST_SSE_REG, mode2))
   20255     return (GET_MODE_SIZE (mode1) == 64
   20256 	    && ix86_hard_regno_mode_ok (FIRST_SSE_REG, mode1));
   20257   if (GET_MODE_SIZE (mode2) == 32
   20258       && ix86_hard_regno_mode_ok (FIRST_SSE_REG, mode2))
   20259     return (GET_MODE_SIZE (mode1) == 32
   20260 	    && ix86_hard_regno_mode_ok (FIRST_SSE_REG, mode1));
   20261   if (GET_MODE_SIZE (mode2) == 16
   20262       && ix86_hard_regno_mode_ok (FIRST_SSE_REG, mode2))
   20263     return (GET_MODE_SIZE (mode1) == 16
   20264 	    && ix86_hard_regno_mode_ok (FIRST_SSE_REG, mode1));
   20265 
   20266   /* If MODE2 is appropriate for an MMX register, then tie
   20267      with any other mode acceptable to MMX registers.  */
   20268   if (GET_MODE_SIZE (mode2) == 8
   20269       && ix86_hard_regno_mode_ok (FIRST_MMX_REG, mode2))
   20270     return (GET_MODE_SIZE (mode1) == 8
   20271 	    && ix86_hard_regno_mode_ok (FIRST_MMX_REG, mode1));
   20272 
   20273   return false;
   20274 }
   20275 
   20276 /* Return the cost of moving between two registers of mode MODE.  */
   20277 
   20278 static int
   20279 ix86_set_reg_reg_cost (machine_mode mode)
   20280 {
   20281   unsigned int units = UNITS_PER_WORD;
   20282 
   20283   switch (GET_MODE_CLASS (mode))
   20284     {
   20285     default:
   20286       break;
   20287 
   20288     case MODE_CC:
   20289       units = GET_MODE_SIZE (CCmode);
   20290       break;
   20291 
   20292     case MODE_FLOAT:
   20293       if ((TARGET_SSE && mode == TFmode)
   20294 	  || (TARGET_80387 && mode == XFmode)
   20295 	  || ((TARGET_80387 || TARGET_SSE2) && mode == DFmode)
   20296 	  || ((TARGET_80387 || TARGET_SSE) && mode == SFmode))
   20297 	units = GET_MODE_SIZE (mode);
   20298       break;
   20299 
   20300     case MODE_COMPLEX_FLOAT:
   20301       if ((TARGET_SSE && mode == TCmode)
   20302 	  || (TARGET_80387 && mode == XCmode)
   20303 	  || ((TARGET_80387 || TARGET_SSE2) && mode == DCmode)
   20304 	  || ((TARGET_80387 || TARGET_SSE) && mode == SCmode))
   20305 	units = GET_MODE_SIZE (mode);
   20306       break;
   20307 
   20308     case MODE_VECTOR_INT:
   20309     case MODE_VECTOR_FLOAT:
   20310       if ((TARGET_AVX512F && VALID_AVX512F_REG_MODE (mode))
   20311 	  || (TARGET_AVX && VALID_AVX256_REG_MODE (mode))
   20312 	  || (TARGET_SSE2 && VALID_SSE2_REG_MODE (mode))
   20313 	  || (TARGET_SSE && VALID_SSE_REG_MODE (mode))
   20314 	  || ((TARGET_MMX || TARGET_MMX_WITH_SSE)
   20315 	      && VALID_MMX_REG_MODE (mode)))
   20316 	units = GET_MODE_SIZE (mode);
   20317     }
   20318 
   20319   /* Return the cost of moving between two registers of mode MODE,
   20320      assuming that the move will be in pieces of at most UNITS bytes.  */
   20321   return COSTS_N_INSNS (CEIL (GET_MODE_SIZE (mode), units));
   20322 }
   20323 
   20324 /* Return cost of vector operation in MODE given that scalar version has
   20325    COST.  */
   20326 
   20327 static int
   20328 ix86_vec_cost (machine_mode mode, int cost)
   20329 {
   20330   if (!VECTOR_MODE_P (mode))
   20331     return cost;
   20332 
   20333   if (GET_MODE_BITSIZE (mode) == 128
   20334       && TARGET_SSE_SPLIT_REGS)
   20335     return cost * GET_MODE_BITSIZE (mode) / 64;
   20336   else if (GET_MODE_BITSIZE (mode) > 128
   20337       && TARGET_AVX256_SPLIT_REGS)
   20338     return cost * GET_MODE_BITSIZE (mode) / 128;
   20339   else if (GET_MODE_BITSIZE (mode) > 256
   20340       && TARGET_AVX512_SPLIT_REGS)
   20341     return cost * GET_MODE_BITSIZE (mode) / 256;
   20342   return cost;
   20343 }
   20344 
   20345 /* Return cost of vec_widen_<s>mult_hi/lo_<mode>,
   20346    vec_widen_<s>mul_hi/lo_<mode> is only available for VI124_AVX2.  */
   20347 static int
   20348 ix86_widen_mult_cost (const struct processor_costs *cost,
   20349 		      enum machine_mode mode, bool uns_p)
   20350 {
   20351   gcc_assert (GET_MODE_CLASS (mode) == MODE_VECTOR_INT);
   20352   int extra_cost = 0;
   20353   int basic_cost = 0;
   20354   switch (mode)
   20355     {
   20356     case V8HImode:
   20357     case V16HImode:
   20358       if (!uns_p || mode == V16HImode)
   20359 	extra_cost = cost->sse_op * 2;
   20360       basic_cost = cost->mulss * 2 + cost->sse_op * 4;
   20361       break;
   20362     case V4SImode:
   20363     case V8SImode:
   20364       /* pmulhw/pmullw can be used.  */
   20365       basic_cost = cost->mulss * 2 + cost->sse_op * 2;
   20366       break;
   20367     case V2DImode:
   20368       /* pmuludq under sse2, pmuldq under sse4.1, for sign_extend,
   20369 	 require extra 4 mul, 4 add, 4 cmp and 2 shift.  */
   20370       if (!TARGET_SSE4_1 && !uns_p)
   20371 	extra_cost = (cost->mulss + cost->addss + cost->sse_op) * 4
   20372 		      + cost->sse_op * 2;
   20373       /* Fallthru.  */
   20374     case V4DImode:
   20375       basic_cost = cost->mulss * 2 + cost->sse_op * 4;
   20376       break;
   20377     default:
   20378       gcc_unreachable();
   20379     }
   20380   return ix86_vec_cost (mode, basic_cost + extra_cost);
   20381 }
   20382 
   20383 /* Return cost of multiplication in MODE.  */
   20384 
   20385 static int
   20386 ix86_multiplication_cost (const struct processor_costs *cost,
   20387 			  enum machine_mode mode)
   20388 {
   20389   machine_mode inner_mode = mode;
   20390   if (VECTOR_MODE_P (mode))
   20391     inner_mode = GET_MODE_INNER (mode);
   20392 
   20393   if (SSE_FLOAT_MODE_SSEMATH_OR_HF_P (mode))
   20394     return inner_mode == DFmode ? cost->mulsd : cost->mulss;
   20395   else if (X87_FLOAT_MODE_P (mode))
   20396     return cost->fmul;
   20397   else if (FLOAT_MODE_P (mode))
   20398     return  ix86_vec_cost (mode,
   20399 			   inner_mode == DFmode ? cost->mulsd : cost->mulss);
   20400   else if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
   20401     {
   20402       /* vpmullq is used in this case. No emulation is needed.  */
   20403       if (TARGET_AVX512DQ)
   20404 	return ix86_vec_cost (mode, cost->mulss);
   20405 
   20406       /* V*QImode is emulated with 7-13 insns.  */
   20407       if (mode == V16QImode || mode == V32QImode)
   20408 	{
   20409 	  int extra = 11;
   20410 	  if (TARGET_XOP && mode == V16QImode)
   20411 	    extra = 5;
   20412 	  else if (TARGET_SSSE3)
   20413 	    extra = 6;
   20414 	  return ix86_vec_cost (mode, cost->mulss * 2 + cost->sse_op * extra);
   20415 	}
   20416       /* V*DImode is emulated with 5-8 insns.  */
   20417       else if (mode == V2DImode || mode == V4DImode)
   20418 	{
   20419 	  if (TARGET_XOP && mode == V2DImode)
   20420 	    return ix86_vec_cost (mode, cost->mulss * 2 + cost->sse_op * 3);
   20421 	  else
   20422 	    return ix86_vec_cost (mode, cost->mulss * 3 + cost->sse_op * 5);
   20423 	}
   20424       /* Without sse4.1, we don't have PMULLD; it's emulated with 7
   20425 	 insns, including two PMULUDQ.  */
   20426       else if (mode == V4SImode && !(TARGET_SSE4_1 || TARGET_AVX))
   20427 	return ix86_vec_cost (mode, cost->mulss * 2 + cost->sse_op * 5);
   20428       else
   20429 	return ix86_vec_cost (mode, cost->mulss);
   20430     }
   20431   else
   20432     return (cost->mult_init[MODE_INDEX (mode)] + cost->mult_bit * 7);
   20433 }
   20434 
   20435 /* Return cost of multiplication in MODE.  */
   20436 
   20437 static int
   20438 ix86_division_cost (const struct processor_costs *cost,
   20439 			  enum machine_mode mode)
   20440 {
   20441   machine_mode inner_mode = mode;
   20442   if (VECTOR_MODE_P (mode))
   20443     inner_mode = GET_MODE_INNER (mode);
   20444 
   20445   if (SSE_FLOAT_MODE_SSEMATH_OR_HF_P (mode))
   20446     return inner_mode == DFmode ? cost->divsd : cost->divss;
   20447   else if (X87_FLOAT_MODE_P (mode))
   20448     return cost->fdiv;
   20449   else if (FLOAT_MODE_P (mode))
   20450     return ix86_vec_cost (mode,
   20451 			  inner_mode == DFmode ? cost->divsd : cost->divss);
   20452   else
   20453     return cost->divide[MODE_INDEX (mode)];
   20454 }
   20455 
   20456 /* Return cost of shift in MODE.
   20457    If CONSTANT_OP1 is true, the op1 value is known and set in OP1_VAL.
   20458    AND_IN_OP1 specify in op1 is result of AND and SHIFT_AND_TRUNCATE
   20459    if op1 is a result of subreg.
   20460 
   20461    SKIP_OP0/1 is set to true if cost of OP0/1 should be ignored.  */
   20462 
   20463 static int
   20464 ix86_shift_rotate_cost (const struct processor_costs *cost,
   20465 			enum rtx_code code,
   20466 			enum machine_mode mode, bool constant_op1,
   20467 			HOST_WIDE_INT op1_val,
   20468 			bool speed,
   20469 			bool and_in_op1,
   20470 			bool shift_and_truncate,
   20471 			bool *skip_op0, bool *skip_op1)
   20472 {
   20473   if (skip_op0)
   20474     *skip_op0 = *skip_op1 = false;
   20475   if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
   20476     {
   20477       /* V*QImode is emulated with 1-11 insns.  */
   20478       if (mode == V16QImode || mode == V32QImode)
   20479 	{
   20480 	  int count = 11;
   20481 	  if (TARGET_XOP && mode == V16QImode)
   20482 	    {
   20483 	      /* For XOP we use vpshab, which requires a broadcast of the
   20484 		 value to the variable shift insn.  For constants this
   20485 		 means a V16Q const in mem; even when we can perform the
   20486 		 shift with one insn set the cost to prefer paddb.  */
   20487 	      if (constant_op1)
   20488 		{
   20489 		  if (skip_op1)
   20490 		    *skip_op1 = true;
   20491 		  return ix86_vec_cost (mode,
   20492 					cost->sse_op
   20493 					+ (speed
   20494 					   ? 2
   20495 					   : COSTS_N_BYTES
   20496 					       (GET_MODE_UNIT_SIZE (mode))));
   20497 		}
   20498 	      count = 3;
   20499 	    }
   20500 	  else if (TARGET_SSSE3)
   20501 	    count = 7;
   20502 	  return ix86_vec_cost (mode, cost->sse_op * count);
   20503 	}
   20504       /* V*DImode arithmetic right shift is emulated.  */
   20505       else if (code == ASHIFTRT
   20506 	       && (mode == V2DImode || mode == V4DImode)
   20507 	       && !TARGET_XOP
   20508 	       && !TARGET_AVX512VL)
   20509 	{
   20510 	  int count = 4;
   20511 	  if (constant_op1 && op1_val == 63 && TARGET_SSE4_2)
   20512 	    count = 2;
   20513 	  else if (constant_op1)
   20514 	    count = 3;
   20515 	  return ix86_vec_cost (mode, cost->sse_op * count);
   20516 	}
   20517       else
   20518 	return ix86_vec_cost (mode, cost->sse_op);
   20519     }
   20520   if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
   20521     {
   20522       if (constant_op1)
   20523 	{
   20524 	  if (op1_val > 32)
   20525 	    return cost->shift_const + COSTS_N_INSNS (2);
   20526 	  else
   20527 	    return cost->shift_const * 2;
   20528 	}
   20529       else
   20530 	{
   20531 	  if (and_in_op1)
   20532 	    return cost->shift_var * 2;
   20533 	  else
   20534 	    return cost->shift_var * 6 + COSTS_N_INSNS (2);
   20535 	}
   20536     }
   20537   else
   20538     {
   20539       if (constant_op1)
   20540 	return cost->shift_const;
   20541       else if (shift_and_truncate)
   20542 	{
   20543 	  if (skip_op0)
   20544 	    *skip_op0 = *skip_op1 = true;
   20545 	  /* Return the cost after shift-and truncation.  */
   20546 	  return cost->shift_var;
   20547 	}
   20548       else
   20549 	return cost->shift_var;
   20550     }
   20551 }
   20552 
   20553 /* Compute a (partial) cost for rtx X.  Return true if the complete
   20554    cost has been computed, and false if subexpressions should be
   20555    scanned.  In either case, *TOTAL contains the cost result.  */
   20556 
   20557 static bool
   20558 ix86_rtx_costs (rtx x, machine_mode mode, int outer_code_i, int opno,
   20559 		int *total, bool speed)
   20560 {
   20561   rtx mask;
   20562   enum rtx_code code = GET_CODE (x);
   20563   enum rtx_code outer_code = (enum rtx_code) outer_code_i;
   20564   const struct processor_costs *cost
   20565     = speed ? ix86_tune_cost : &ix86_size_cost;
   20566   int src_cost;
   20567 
   20568   switch (code)
   20569     {
   20570     case SET:
   20571       if (register_operand (SET_DEST (x), VOIDmode)
   20572 	  && register_operand (SET_SRC (x), VOIDmode))
   20573 	{
   20574 	  *total = ix86_set_reg_reg_cost (GET_MODE (SET_DEST (x)));
   20575 	  return true;
   20576 	}
   20577 
   20578       if (register_operand (SET_SRC (x), VOIDmode))
   20579 	/* Avoid potentially incorrect high cost from rtx_costs
   20580 	   for non-tieable SUBREGs.  */
   20581 	src_cost = 0;
   20582       else
   20583 	{
   20584 	  src_cost = rtx_cost (SET_SRC (x), mode, SET, 1, speed);
   20585 
   20586 	  if (CONSTANT_P (SET_SRC (x)))
   20587 	    /* Constant costs assume a base value of COSTS_N_INSNS (1) and add
   20588 	       a small value, possibly zero for cheap constants.  */
   20589 	    src_cost += COSTS_N_INSNS (1);
   20590 	}
   20591 
   20592       *total = src_cost + rtx_cost (SET_DEST (x), mode, SET, 0, speed);
   20593       return true;
   20594 
   20595     case CONST_INT:
   20596     case CONST:
   20597     case LABEL_REF:
   20598     case SYMBOL_REF:
   20599       if (x86_64_immediate_operand (x, VOIDmode))
   20600 	*total = 0;
   20601      else
   20602 	*total = 1;
   20603       return true;
   20604 
   20605     case CONST_DOUBLE:
   20606       if (IS_STACK_MODE (mode))
   20607 	switch (standard_80387_constant_p (x))
   20608 	  {
   20609 	  case -1:
   20610 	  case 0:
   20611 	    break;
   20612 	  case 1: /* 0.0 */
   20613 	    *total = 1;
   20614 	    return true;
   20615 	  default: /* Other constants */
   20616 	    *total = 2;
   20617 	    return true;
   20618 	  }
   20619       /* FALLTHRU */
   20620 
   20621     case CONST_VECTOR:
   20622       switch (standard_sse_constant_p (x, mode))
   20623 	{
   20624 	case 0:
   20625 	  break;
   20626 	case 1:  /* 0: xor eliminates false dependency */
   20627 	  *total = 0;
   20628 	  return true;
   20629 	default: /* -1: cmp contains false dependency */
   20630 	  *total = 1;
   20631 	  return true;
   20632 	}
   20633       /* FALLTHRU */
   20634 
   20635     case CONST_WIDE_INT:
   20636       /* Fall back to (MEM (SYMBOL_REF)), since that's where
   20637 	 it'll probably end up.  Add a penalty for size.  */
   20638       *total = (COSTS_N_INSNS (1)
   20639 		+ (!TARGET_64BIT && flag_pic)
   20640 		+ (GET_MODE_SIZE (mode) <= 4
   20641 		   ? 0 : GET_MODE_SIZE (mode) <= 8 ? 1 : 2));
   20642       return true;
   20643 
   20644     case ZERO_EXTEND:
   20645       /* The zero extensions is often completely free on x86_64, so make
   20646 	 it as cheap as possible.  */
   20647       if (TARGET_64BIT && mode == DImode
   20648 	  && GET_MODE (XEXP (x, 0)) == SImode)
   20649 	*total = 1;
   20650       else if (TARGET_ZERO_EXTEND_WITH_AND)
   20651 	*total = cost->add;
   20652       else
   20653 	*total = cost->movzx;
   20654       return false;
   20655 
   20656     case SIGN_EXTEND:
   20657       *total = cost->movsx;
   20658       return false;
   20659 
   20660     case ASHIFT:
   20661       if (SCALAR_INT_MODE_P (mode)
   20662 	  && GET_MODE_SIZE (mode) < UNITS_PER_WORD
   20663 	  && CONST_INT_P (XEXP (x, 1)))
   20664 	{
   20665 	  HOST_WIDE_INT value = INTVAL (XEXP (x, 1));
   20666 	  if (value == 1)
   20667 	    {
   20668 	      *total = cost->add;
   20669 	      return false;
   20670 	    }
   20671 	  if ((value == 2 || value == 3)
   20672 	      && cost->lea <= cost->shift_const)
   20673 	    {
   20674 	      *total = cost->lea;
   20675 	      return false;
   20676 	    }
   20677 	}
   20678       /* FALLTHRU */
   20679 
   20680     case ROTATE:
   20681     case ASHIFTRT:
   20682     case LSHIFTRT:
   20683     case ROTATERT:
   20684       bool skip_op0, skip_op1;
   20685       *total = ix86_shift_rotate_cost (cost, code, mode,
   20686 				       CONSTANT_P (XEXP (x, 1)),
   20687 				       CONST_INT_P (XEXP (x, 1))
   20688 					 ? INTVAL (XEXP (x, 1)) : -1,
   20689 				       speed,
   20690 				       GET_CODE (XEXP (x, 1)) == AND,
   20691 				       SUBREG_P (XEXP (x, 1))
   20692 				       && GET_CODE (XEXP (XEXP (x, 1),
   20693 							  0)) == AND,
   20694 				       &skip_op0, &skip_op1);
   20695       if (skip_op0 || skip_op1)
   20696 	{
   20697 	  if (!skip_op0)
   20698 	    *total += rtx_cost (XEXP (x, 0), mode, code, 0, speed);
   20699 	  if (!skip_op1)
   20700 	    *total += rtx_cost (XEXP (x, 1), mode, code, 0, speed);
   20701 	  return true;
   20702 	}
   20703       return false;
   20704 
   20705     case FMA:
   20706       {
   20707 	rtx sub;
   20708 
   20709         gcc_assert (FLOAT_MODE_P (mode));
   20710         gcc_assert (TARGET_FMA || TARGET_FMA4 || TARGET_AVX512F);
   20711 
   20712         *total = ix86_vec_cost (mode,
   20713 				GET_MODE_INNER (mode) == SFmode
   20714 				? cost->fmass : cost->fmasd);
   20715 	*total += rtx_cost (XEXP (x, 1), mode, FMA, 1, speed);
   20716 
   20717         /* Negate in op0 or op2 is free: FMS, FNMA, FNMS.  */
   20718 	sub = XEXP (x, 0);
   20719 	if (GET_CODE (sub) == NEG)
   20720 	  sub = XEXP (sub, 0);
   20721 	*total += rtx_cost (sub, mode, FMA, 0, speed);
   20722 
   20723 	sub = XEXP (x, 2);
   20724 	if (GET_CODE (sub) == NEG)
   20725 	  sub = XEXP (sub, 0);
   20726 	*total += rtx_cost (sub, mode, FMA, 2, speed);
   20727 	return true;
   20728       }
   20729 
   20730     case MULT:
   20731       if (!FLOAT_MODE_P (mode) && !VECTOR_MODE_P (mode))
   20732 	{
   20733 	  rtx op0 = XEXP (x, 0);
   20734 	  rtx op1 = XEXP (x, 1);
   20735 	  int nbits;
   20736 	  if (CONST_INT_P (XEXP (x, 1)))
   20737 	    {
   20738 	      unsigned HOST_WIDE_INT value = INTVAL (XEXP (x, 1));
   20739 	      for (nbits = 0; value != 0; value &= value - 1)
   20740 	        nbits++;
   20741 	    }
   20742 	  else
   20743 	    /* This is arbitrary.  */
   20744 	    nbits = 7;
   20745 
   20746 	  /* Compute costs correctly for widening multiplication.  */
   20747 	  if ((GET_CODE (op0) == SIGN_EXTEND || GET_CODE (op0) == ZERO_EXTEND)
   20748 	      && GET_MODE_SIZE (GET_MODE (XEXP (op0, 0))) * 2
   20749 	         == GET_MODE_SIZE (mode))
   20750 	    {
   20751 	      int is_mulwiden = 0;
   20752 	      machine_mode inner_mode = GET_MODE (op0);
   20753 
   20754 	      if (GET_CODE (op0) == GET_CODE (op1))
   20755 		is_mulwiden = 1, op1 = XEXP (op1, 0);
   20756 	      else if (CONST_INT_P (op1))
   20757 		{
   20758 		  if (GET_CODE (op0) == SIGN_EXTEND)
   20759 		    is_mulwiden = trunc_int_for_mode (INTVAL (op1), inner_mode)
   20760 			          == INTVAL (op1);
   20761 		  else
   20762 		    is_mulwiden = !(INTVAL (op1) & ~GET_MODE_MASK (inner_mode));
   20763 	        }
   20764 
   20765 	      if (is_mulwiden)
   20766 	        op0 = XEXP (op0, 0), mode = GET_MODE (op0);
   20767 	    }
   20768 
   20769   	  *total = (cost->mult_init[MODE_INDEX (mode)]
   20770 		    + nbits * cost->mult_bit
   20771 	            + rtx_cost (op0, mode, outer_code, opno, speed)
   20772 		    + rtx_cost (op1, mode, outer_code, opno, speed));
   20773 
   20774           return true;
   20775 	}
   20776       *total = ix86_multiplication_cost (cost, mode);
   20777       return false;
   20778 
   20779     case DIV:
   20780     case UDIV:
   20781     case MOD:
   20782     case UMOD:
   20783       *total = ix86_division_cost (cost, mode);
   20784       return false;
   20785 
   20786     case PLUS:
   20787       if (GET_MODE_CLASS (mode) == MODE_INT
   20788 	  && GET_MODE_SIZE (mode) <= UNITS_PER_WORD)
   20789 	{
   20790 	  if (GET_CODE (XEXP (x, 0)) == PLUS
   20791 	      && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT
   20792 	      && CONST_INT_P (XEXP (XEXP (XEXP (x, 0), 0), 1))
   20793 	      && CONSTANT_P (XEXP (x, 1)))
   20794 	    {
   20795 	      HOST_WIDE_INT val = INTVAL (XEXP (XEXP (XEXP (x, 0), 0), 1));
   20796 	      if (val == 2 || val == 4 || val == 8)
   20797 		{
   20798 		  *total = cost->lea;
   20799 		  *total += rtx_cost (XEXP (XEXP (x, 0), 1), mode,
   20800 				      outer_code, opno, speed);
   20801 		  *total += rtx_cost (XEXP (XEXP (XEXP (x, 0), 0), 0), mode,
   20802 				      outer_code, opno, speed);
   20803 		  *total += rtx_cost (XEXP (x, 1), mode,
   20804 				      outer_code, opno, speed);
   20805 		  return true;
   20806 		}
   20807 	    }
   20808 	  else if (GET_CODE (XEXP (x, 0)) == MULT
   20809 		   && CONST_INT_P (XEXP (XEXP (x, 0), 1)))
   20810 	    {
   20811 	      HOST_WIDE_INT val = INTVAL (XEXP (XEXP (x, 0), 1));
   20812 	      if (val == 2 || val == 4 || val == 8)
   20813 		{
   20814 		  *total = cost->lea;
   20815 		  *total += rtx_cost (XEXP (XEXP (x, 0), 0), mode,
   20816 				      outer_code, opno, speed);
   20817 		  *total += rtx_cost (XEXP (x, 1), mode,
   20818 				      outer_code, opno, speed);
   20819 		  return true;
   20820 		}
   20821 	    }
   20822 	  else if (GET_CODE (XEXP (x, 0)) == PLUS)
   20823 	    {
   20824 	      rtx op = XEXP (XEXP (x, 0), 0);
   20825 
   20826 	      /* Add with carry, ignore the cost of adding a carry flag.  */
   20827 	      if (ix86_carry_flag_operator (op, mode)
   20828 		  || ix86_carry_flag_unset_operator (op, mode))
   20829 		*total = cost->add;
   20830 	      else
   20831 		{
   20832 		  *total = cost->lea;
   20833 		  *total += rtx_cost (op, mode,
   20834 				      outer_code, opno, speed);
   20835 		}
   20836 
   20837 	      *total += rtx_cost (XEXP (XEXP (x, 0), 1), mode,
   20838 				  outer_code, opno, speed);
   20839 	      *total += rtx_cost (XEXP (x, 1), mode,
   20840 				  outer_code, opno, speed);
   20841 	      return true;
   20842 	    }
   20843 	}
   20844       /* FALLTHRU */
   20845 
   20846     case MINUS:
   20847       /* Subtract with borrow, ignore the cost of subtracting a carry flag.  */
   20848       if (GET_MODE_CLASS (mode) == MODE_INT
   20849 	  && GET_MODE_SIZE (mode) <= UNITS_PER_WORD
   20850 	  && GET_CODE (XEXP (x, 0)) == MINUS
   20851 	  && (ix86_carry_flag_operator (XEXP (XEXP (x, 0), 1), mode)
   20852 	      || ix86_carry_flag_unset_operator (XEXP (XEXP (x, 0), 1), mode)))
   20853 	{
   20854 	  *total = cost->add;
   20855 	  *total += rtx_cost (XEXP (XEXP (x, 0), 0), mode,
   20856 			      outer_code, opno, speed);
   20857 	  *total += rtx_cost (XEXP (x, 1), mode,
   20858 			      outer_code, opno, speed);
   20859 	  return true;
   20860 	}
   20861 
   20862       if (SSE_FLOAT_MODE_SSEMATH_OR_HF_P (mode))
   20863 	{
   20864 	  *total = cost->addss;
   20865 	  return false;
   20866 	}
   20867       else if (X87_FLOAT_MODE_P (mode))
   20868 	{
   20869 	  *total = cost->fadd;
   20870 	  return false;
   20871 	}
   20872       else if (FLOAT_MODE_P (mode))
   20873 	{
   20874 	  *total = ix86_vec_cost (mode, cost->addss);
   20875 	  return false;
   20876 	}
   20877       /* FALLTHRU */
   20878 
   20879     case AND:
   20880     case IOR:
   20881     case XOR:
   20882       if (GET_MODE_CLASS (mode) == MODE_INT
   20883 	  && GET_MODE_SIZE (mode) > UNITS_PER_WORD)
   20884 	{
   20885 	  *total = (cost->add * 2
   20886 		    + (rtx_cost (XEXP (x, 0), mode, outer_code, opno, speed)
   20887 		       << (GET_MODE (XEXP (x, 0)) != DImode))
   20888 		    + (rtx_cost (XEXP (x, 1), mode, outer_code, opno, speed)
   20889 	               << (GET_MODE (XEXP (x, 1)) != DImode)));
   20890 	  return true;
   20891 	}
   20892       else if (code == AND
   20893 	       && address_no_seg_operand (x, mode))
   20894 	{
   20895 	  *total = cost->lea;
   20896 	  return true;
   20897 	}
   20898       /* FALLTHRU */
   20899 
   20900     case NEG:
   20901       if (SSE_FLOAT_MODE_SSEMATH_OR_HF_P (mode))
   20902 	{
   20903 	  *total = cost->sse_op;
   20904 	  return false;
   20905 	}
   20906       else if (X87_FLOAT_MODE_P (mode))
   20907 	{
   20908 	  *total = cost->fchs;
   20909 	  return false;
   20910 	}
   20911       else if (FLOAT_MODE_P (mode))
   20912 	{
   20913 	  *total = ix86_vec_cost (mode, cost->sse_op);
   20914 	  return false;
   20915 	}
   20916       /* FALLTHRU */
   20917 
   20918     case NOT:
   20919       if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
   20920 	*total = ix86_vec_cost (mode, cost->sse_op);
   20921       else if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
   20922 	*total = cost->add * 2;
   20923       else
   20924 	*total = cost->add;
   20925       return false;
   20926 
   20927     case COMPARE:
   20928       rtx op0, op1;
   20929       op0 = XEXP (x, 0);
   20930       op1 = XEXP (x, 1);
   20931       if (GET_CODE (op0) == ZERO_EXTRACT
   20932 	  && XEXP (op0, 1) == const1_rtx
   20933 	  && CONST_INT_P (XEXP (op0, 2))
   20934 	  && op1 == const0_rtx)
   20935 	{
   20936 	  /* This kind of construct is implemented using test[bwl].
   20937 	     Treat it as if we had an AND.  */
   20938 	  mode = GET_MODE (XEXP (op0, 0));
   20939 	  *total = (cost->add
   20940 		    + rtx_cost (XEXP (op0, 0), mode, outer_code,
   20941 				opno, speed)
   20942 		    + rtx_cost (const1_rtx, mode, outer_code, opno, speed));
   20943 	  return true;
   20944 	}
   20945 
   20946       if (GET_CODE (op0) == PLUS && rtx_equal_p (XEXP (op0, 0), op1))
   20947 	{
   20948 	  /* This is an overflow detection, count it as a normal compare.  */
   20949 	  *total = rtx_cost (op0, GET_MODE (op0), COMPARE, 0, speed);
   20950 	  return true;
   20951 	}
   20952 
   20953       rtx geu;
   20954       /* Match x
   20955 	 (compare:CCC (neg:QI (geu:QI (reg:CC_CCC FLAGS_REG) (const_int 0)))
   20956 		      (ltu:QI (reg:CC_CCC FLAGS_REG) (const_int 0)))  */
   20957       if (mode == CCCmode
   20958 	  && GET_CODE (op0) == NEG
   20959 	  && GET_CODE (geu = XEXP (op0, 0)) == GEU
   20960 	  && REG_P (XEXP (geu, 0))
   20961 	  && (GET_MODE (XEXP (geu, 0)) == CCCmode
   20962 	      || GET_MODE (XEXP (geu, 0)) == CCmode)
   20963 	  && REGNO (XEXP (geu, 0)) == FLAGS_REG
   20964 	  && XEXP (geu, 1) == const0_rtx
   20965 	  && GET_CODE (op1) == LTU
   20966 	  && REG_P (XEXP (op1, 0))
   20967 	  && GET_MODE (XEXP (op1, 0)) == GET_MODE (XEXP (geu, 0))
   20968 	  && REGNO (XEXP (op1, 0)) == FLAGS_REG
   20969 	  && XEXP (op1, 1) == const0_rtx)
   20970 	{
   20971 	  /* This is *setcc_qi_addqi3_cconly_overflow_1_* patterns, a nop.  */
   20972 	  *total = 0;
   20973 	  return true;
   20974 	}
   20975 
   20976       /* The embedded comparison operand is completely free.  */
   20977       if (!general_operand (op0, GET_MODE (op0)) && op1 == const0_rtx)
   20978 	*total = 0;
   20979 
   20980       return false;
   20981 
   20982     case FLOAT_EXTEND:
   20983       if (!SSE_FLOAT_MODE_SSEMATH_OR_HF_P (mode))
   20984 	*total = 0;
   20985       else
   20986         *total = ix86_vec_cost (mode, cost->addss);
   20987       return false;
   20988 
   20989     case FLOAT_TRUNCATE:
   20990       if (!SSE_FLOAT_MODE_SSEMATH_OR_HF_P (mode))
   20991 	*total = cost->fadd;
   20992       else
   20993         *total = ix86_vec_cost (mode, cost->addss);
   20994       return false;
   20995 
   20996     case ABS:
   20997       /* SSE requires memory load for the constant operand. It may make
   20998 	 sense to account for this.  Of course the constant operand may or
   20999 	 may not be reused. */
   21000       if (SSE_FLOAT_MODE_SSEMATH_OR_HF_P (mode))
   21001 	*total = cost->sse_op;
   21002       else if (X87_FLOAT_MODE_P (mode))
   21003 	*total = cost->fabs;
   21004       else if (FLOAT_MODE_P (mode))
   21005 	*total = ix86_vec_cost (mode, cost->sse_op);
   21006       return false;
   21007 
   21008     case SQRT:
   21009       if (SSE_FLOAT_MODE_SSEMATH_OR_HF_P (mode))
   21010 	*total = mode == SFmode ? cost->sqrtss : cost->sqrtsd;
   21011       else if (X87_FLOAT_MODE_P (mode))
   21012 	*total = cost->fsqrt;
   21013       else if (FLOAT_MODE_P (mode))
   21014 	*total = ix86_vec_cost (mode,
   21015 				mode == SFmode ? cost->sqrtss : cost->sqrtsd);
   21016       return false;
   21017 
   21018     case UNSPEC:
   21019       if (XINT (x, 1) == UNSPEC_TP)
   21020 	*total = 0;
   21021       else if (XINT(x, 1) == UNSPEC_VTERNLOG)
   21022 	{
   21023 	  *total = cost->sse_op;
   21024 	  return true;
   21025 	}
   21026       return false;
   21027 
   21028     case VEC_SELECT:
   21029     case VEC_CONCAT:
   21030     case VEC_DUPLICATE:
   21031       /* ??? Assume all of these vector manipulation patterns are
   21032 	 recognizable.  In which case they all pretty much have the
   21033 	 same cost.  */
   21034      *total = cost->sse_op;
   21035      return true;
   21036     case VEC_MERGE:
   21037       mask = XEXP (x, 2);
   21038       /* This is masked instruction, assume the same cost,
   21039 	 as nonmasked variant.  */
   21040       if (TARGET_AVX512F && register_operand (mask, GET_MODE (mask)))
   21041 	*total = rtx_cost (XEXP (x, 0), mode, outer_code, opno, speed);
   21042       else
   21043 	*total = cost->sse_op;
   21044       return true;
   21045 
   21046     case MEM:
   21047       /* An insn that accesses memory is slightly more expensive
   21048          than one that does not.  */
   21049       if (speed)
   21050         *total += 1;
   21051       return false;
   21052 
   21053     default:
   21054       return false;
   21055     }
   21056 }
   21057 
   21058 #if TARGET_MACHO
   21059 
   21060 static int current_machopic_label_num;
   21061 
   21062 /* Given a symbol name and its associated stub, write out the
   21063    definition of the stub.  */
   21064 
   21065 void
   21066 machopic_output_stub (FILE *file, const char *symb, const char *stub)
   21067 {
   21068   unsigned int length;
   21069   char *binder_name, *symbol_name, lazy_ptr_name[32];
   21070   int label = ++current_machopic_label_num;
   21071 
   21072   /* For 64-bit we shouldn't get here.  */
   21073   gcc_assert (!TARGET_64BIT);
   21074 
   21075   /* Lose our funky encoding stuff so it doesn't contaminate the stub.  */
   21076   symb = targetm.strip_name_encoding (symb);
   21077 
   21078   length = strlen (stub);
   21079   binder_name = XALLOCAVEC (char, length + 32);
   21080   GEN_BINDER_NAME_FOR_STUB (binder_name, stub, length);
   21081 
   21082   length = strlen (symb);
   21083   symbol_name = XALLOCAVEC (char, length + 32);
   21084   GEN_SYMBOL_NAME_FOR_SYMBOL (symbol_name, symb, length);
   21085 
   21086   sprintf (lazy_ptr_name, "L%d$lz", label);
   21087 
   21088   if (MACHOPIC_ATT_STUB)
   21089     switch_to_section (darwin_sections[machopic_picsymbol_stub3_section]);
   21090   else if (MACHOPIC_PURE)
   21091     switch_to_section (darwin_sections[machopic_picsymbol_stub2_section]);
   21092   else
   21093     switch_to_section (darwin_sections[machopic_symbol_stub_section]);
   21094 
   21095   fprintf (file, "%s:\n", stub);
   21096   fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
   21097 
   21098   if (MACHOPIC_ATT_STUB)
   21099     {
   21100       fprintf (file, "\thlt ; hlt ; hlt ; hlt ; hlt\n");
   21101     }
   21102   else if (MACHOPIC_PURE)
   21103     {
   21104       /* PIC stub.  */
   21105       /* 25-byte PIC stub using "CALL get_pc_thunk".  */
   21106       rtx tmp = gen_rtx_REG (SImode, 2 /* ECX */);
   21107       output_set_got (tmp, NULL_RTX);	/* "CALL ___<cpu>.get_pc_thunk.cx".  */
   21108       fprintf (file, "LPC$%d:\tmovl\t%s-LPC$%d(%%ecx),%%ecx\n",
   21109 	       label, lazy_ptr_name, label);
   21110       fprintf (file, "\tjmp\t*%%ecx\n");
   21111     }
   21112   else
   21113     fprintf (file, "\tjmp\t*%s\n", lazy_ptr_name);
   21114 
   21115   /* The AT&T-style ("self-modifying") stub is not lazily bound, thus
   21116      it needs no stub-binding-helper.  */
   21117   if (MACHOPIC_ATT_STUB)
   21118     return;
   21119 
   21120   fprintf (file, "%s:\n", binder_name);
   21121 
   21122   if (MACHOPIC_PURE)
   21123     {
   21124       fprintf (file, "\tlea\t%s-%s(%%ecx),%%ecx\n", lazy_ptr_name, binder_name);
   21125       fprintf (file, "\tpushl\t%%ecx\n");
   21126     }
   21127   else
   21128     fprintf (file, "\tpushl\t$%s\n", lazy_ptr_name);
   21129 
   21130   fputs ("\tjmp\tdyld_stub_binding_helper\n", file);
   21131 
   21132   /* N.B. Keep the correspondence of these
   21133      'symbol_ptr/symbol_ptr2/symbol_ptr3' sections consistent with the
   21134      old-pic/new-pic/non-pic stubs; altering this will break
   21135      compatibility with existing dylibs.  */
   21136   if (MACHOPIC_PURE)
   21137     {
   21138       /* 25-byte PIC stub using "CALL get_pc_thunk".  */
   21139       switch_to_section (darwin_sections[machopic_lazy_symbol_ptr2_section]);
   21140     }
   21141   else
   21142     /* 16-byte -mdynamic-no-pic stub.  */
   21143     switch_to_section(darwin_sections[machopic_lazy_symbol_ptr3_section]);
   21144 
   21145   fprintf (file, "%s:\n", lazy_ptr_name);
   21146   fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
   21147   fprintf (file, ASM_LONG "%s\n", binder_name);
   21148 }
   21149 #endif /* TARGET_MACHO */
   21150 
   21151 /* Order the registers for register allocator.  */
   21152 
   21153 void
   21154 x86_order_regs_for_local_alloc (void)
   21155 {
   21156    int pos = 0;
   21157    int i;
   21158 
   21159    /* First allocate the local general purpose registers.  */
   21160    for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
   21161      if (GENERAL_REGNO_P (i) && call_used_or_fixed_reg_p (i))
   21162 	reg_alloc_order [pos++] = i;
   21163 
   21164    /* Global general purpose registers.  */
   21165    for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
   21166      if (GENERAL_REGNO_P (i) && !call_used_or_fixed_reg_p (i))
   21167 	reg_alloc_order [pos++] = i;
   21168 
   21169    /* x87 registers come first in case we are doing FP math
   21170       using them.  */
   21171    if (!TARGET_SSE_MATH)
   21172      for (i = FIRST_STACK_REG; i <= LAST_STACK_REG; i++)
   21173        reg_alloc_order [pos++] = i;
   21174 
   21175    /* SSE registers.  */
   21176    for (i = FIRST_SSE_REG; i <= LAST_SSE_REG; i++)
   21177      reg_alloc_order [pos++] = i;
   21178    for (i = FIRST_REX_SSE_REG; i <= LAST_REX_SSE_REG; i++)
   21179      reg_alloc_order [pos++] = i;
   21180 
   21181    /* Extended REX SSE registers.  */
   21182    for (i = FIRST_EXT_REX_SSE_REG; i <= LAST_EXT_REX_SSE_REG; i++)
   21183      reg_alloc_order [pos++] = i;
   21184 
   21185    /* Mask register.  */
   21186    for (i = FIRST_MASK_REG; i <= LAST_MASK_REG; i++)
   21187      reg_alloc_order [pos++] = i;
   21188 
   21189    /* x87 registers.  */
   21190    if (TARGET_SSE_MATH)
   21191      for (i = FIRST_STACK_REG; i <= LAST_STACK_REG; i++)
   21192        reg_alloc_order [pos++] = i;
   21193 
   21194    for (i = FIRST_MMX_REG; i <= LAST_MMX_REG; i++)
   21195      reg_alloc_order [pos++] = i;
   21196 
   21197    /* Initialize the rest of array as we do not allocate some registers
   21198       at all.  */
   21199    while (pos < FIRST_PSEUDO_REGISTER)
   21200      reg_alloc_order [pos++] = 0;
   21201 }
   21202 
   21203 static bool
   21204 ix86_ms_bitfield_layout_p (const_tree record_type)
   21205 {
   21206   return ((TARGET_MS_BITFIELD_LAYOUT
   21207 	   && !lookup_attribute ("gcc_struct", TYPE_ATTRIBUTES (record_type)))
   21208           || lookup_attribute ("ms_struct", TYPE_ATTRIBUTES (record_type)));
   21209 }
   21210 
   21211 /* Returns an expression indicating where the this parameter is
   21212    located on entry to the FUNCTION.  */
   21213 
   21214 static rtx
   21215 x86_this_parameter (tree function)
   21216 {
   21217   tree type = TREE_TYPE (function);
   21218   bool aggr = aggregate_value_p (TREE_TYPE (type), type) != 0;
   21219   int nregs;
   21220 
   21221   if (TARGET_64BIT)
   21222     {
   21223       const int *parm_regs;
   21224 
   21225       if (ix86_function_type_abi (type) == MS_ABI)
   21226         parm_regs = x86_64_ms_abi_int_parameter_registers;
   21227       else
   21228         parm_regs = x86_64_int_parameter_registers;
   21229       return gen_rtx_REG (Pmode, parm_regs[aggr]);
   21230     }
   21231 
   21232   nregs = ix86_function_regparm (type, function);
   21233 
   21234   if (nregs > 0 && !stdarg_p (type))
   21235     {
   21236       int regno;
   21237       unsigned int ccvt = ix86_get_callcvt (type);
   21238 
   21239       if ((ccvt & IX86_CALLCVT_FASTCALL) != 0)
   21240 	regno = aggr ? DX_REG : CX_REG;
   21241       else if ((ccvt & IX86_CALLCVT_THISCALL) != 0)
   21242         {
   21243 	  regno = CX_REG;
   21244 	  if (aggr)
   21245 	    return gen_rtx_MEM (SImode,
   21246 				plus_constant (Pmode, stack_pointer_rtx, 4));
   21247 	}
   21248       else
   21249         {
   21250 	  regno = AX_REG;
   21251 	  if (aggr)
   21252 	    {
   21253 	      regno = DX_REG;
   21254 	      if (nregs == 1)
   21255 		return gen_rtx_MEM (SImode,
   21256 				    plus_constant (Pmode,
   21257 						   stack_pointer_rtx, 4));
   21258 	    }
   21259 	}
   21260       return gen_rtx_REG (SImode, regno);
   21261     }
   21262 
   21263   return gen_rtx_MEM (SImode, plus_constant (Pmode, stack_pointer_rtx,
   21264 					     aggr ? 8 : 4));
   21265 }
   21266 
   21267 /* Determine whether x86_output_mi_thunk can succeed.  */
   21268 
   21269 static bool
   21270 x86_can_output_mi_thunk (const_tree, HOST_WIDE_INT, HOST_WIDE_INT vcall_offset,
   21271 			 const_tree function)
   21272 {
   21273   /* 64-bit can handle anything.  */
   21274   if (TARGET_64BIT)
   21275     return true;
   21276 
   21277   /* For 32-bit, everything's fine if we have one free register.  */
   21278   if (ix86_function_regparm (TREE_TYPE (function), function) < 3)
   21279     return true;
   21280 
   21281   /* Need a free register for vcall_offset.  */
   21282   if (vcall_offset)
   21283     return false;
   21284 
   21285   /* Need a free register for GOT references.  */
   21286   if (flag_pic && !targetm.binds_local_p (function))
   21287     return false;
   21288 
   21289   /* Otherwise ok.  */
   21290   return true;
   21291 }
   21292 
   21293 /* Output the assembler code for a thunk function.  THUNK_DECL is the
   21294    declaration for the thunk function itself, FUNCTION is the decl for
   21295    the target function.  DELTA is an immediate constant offset to be
   21296    added to THIS.  If VCALL_OFFSET is nonzero, the word at
   21297    *(*this + vcall_offset) should be added to THIS.  */
   21298 
   21299 static void
   21300 x86_output_mi_thunk (FILE *file, tree thunk_fndecl, HOST_WIDE_INT delta,
   21301 		     HOST_WIDE_INT vcall_offset, tree function)
   21302 {
   21303   const char *fnname = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (thunk_fndecl));
   21304   rtx this_param = x86_this_parameter (function);
   21305   rtx this_reg, tmp, fnaddr;
   21306   unsigned int tmp_regno;
   21307   rtx_insn *insn;
   21308   int saved_flag_force_indirect_call = flag_force_indirect_call;
   21309 
   21310   if (TARGET_64BIT)
   21311     tmp_regno = R10_REG;
   21312   else
   21313     {
   21314       unsigned int ccvt = ix86_get_callcvt (TREE_TYPE (function));
   21315       if ((ccvt & IX86_CALLCVT_FASTCALL) != 0)
   21316 	tmp_regno = AX_REG;
   21317       else if ((ccvt & IX86_CALLCVT_THISCALL) != 0)
   21318 	tmp_regno = DX_REG;
   21319       else
   21320 	tmp_regno = CX_REG;
   21321 
   21322       if (flag_pic)
   21323   flag_force_indirect_call = 0;
   21324     }
   21325 
   21326   emit_note (NOTE_INSN_PROLOGUE_END);
   21327 
   21328   /* CET is enabled, insert EB instruction.  */
   21329   if ((flag_cf_protection & CF_BRANCH))
   21330     emit_insn (gen_nop_endbr ());
   21331 
   21332   /* If VCALL_OFFSET, we'll need THIS in a register.  Might as well
   21333      pull it in now and let DELTA benefit.  */
   21334   if (REG_P (this_param))
   21335     this_reg = this_param;
   21336   else if (vcall_offset)
   21337     {
   21338       /* Put the this parameter into %eax.  */
   21339       this_reg = gen_rtx_REG (Pmode, AX_REG);
   21340       emit_move_insn (this_reg, this_param);
   21341     }
   21342   else
   21343     this_reg = NULL_RTX;
   21344 
   21345   /* Adjust the this parameter by a fixed constant.  */
   21346   if (delta)
   21347     {
   21348       rtx delta_rtx = GEN_INT (delta);
   21349       rtx delta_dst = this_reg ? this_reg : this_param;
   21350 
   21351       if (TARGET_64BIT)
   21352 	{
   21353 	  if (!x86_64_general_operand (delta_rtx, Pmode))
   21354 	    {
   21355 	      tmp = gen_rtx_REG (Pmode, tmp_regno);
   21356 	      emit_move_insn (tmp, delta_rtx);
   21357 	      delta_rtx = tmp;
   21358 	    }
   21359 	}
   21360 
   21361       ix86_emit_binop (PLUS, Pmode, delta_dst, delta_rtx);
   21362     }
   21363 
   21364   /* Adjust the this parameter by a value stored in the vtable.  */
   21365   if (vcall_offset)
   21366     {
   21367       rtx vcall_addr, vcall_mem, this_mem;
   21368 
   21369       tmp = gen_rtx_REG (Pmode, tmp_regno);
   21370 
   21371       this_mem = gen_rtx_MEM (ptr_mode, this_reg);
   21372       if (Pmode != ptr_mode)
   21373 	this_mem = gen_rtx_ZERO_EXTEND (Pmode, this_mem);
   21374       emit_move_insn (tmp, this_mem);
   21375 
   21376       /* Adjust the this parameter.  */
   21377       vcall_addr = plus_constant (Pmode, tmp, vcall_offset);
   21378       if (TARGET_64BIT
   21379 	  && !ix86_legitimate_address_p (ptr_mode, vcall_addr, true))
   21380 	{
   21381 	  rtx tmp2 = gen_rtx_REG (Pmode, R11_REG);
   21382 	  emit_move_insn (tmp2, GEN_INT (vcall_offset));
   21383 	  vcall_addr = gen_rtx_PLUS (Pmode, tmp, tmp2);
   21384 	}
   21385 
   21386       vcall_mem = gen_rtx_MEM (ptr_mode, vcall_addr);
   21387       if (Pmode != ptr_mode)
   21388 	emit_insn (gen_addsi_1_zext (this_reg,
   21389 				     gen_rtx_REG (ptr_mode,
   21390 						  REGNO (this_reg)),
   21391 				     vcall_mem));
   21392       else
   21393 	ix86_emit_binop (PLUS, Pmode, this_reg, vcall_mem);
   21394     }
   21395 
   21396   /* If necessary, drop THIS back to its stack slot.  */
   21397   if (this_reg && this_reg != this_param)
   21398     emit_move_insn (this_param, this_reg);
   21399 
   21400   fnaddr = XEXP (DECL_RTL (function), 0);
   21401   if (TARGET_64BIT)
   21402     {
   21403       if (!flag_pic || targetm.binds_local_p (function)
   21404 	  || TARGET_PECOFF)
   21405 	;
   21406       else
   21407 	{
   21408 	  tmp = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, fnaddr), UNSPEC_GOTPCREL);
   21409 	  tmp = gen_rtx_CONST (Pmode, tmp);
   21410 	  fnaddr = gen_const_mem (Pmode, tmp);
   21411 	}
   21412     }
   21413   else
   21414     {
   21415       if (!flag_pic || targetm.binds_local_p (function))
   21416 	;
   21417 #if TARGET_MACHO
   21418       else if (TARGET_MACHO)
   21419 	{
   21420 	  fnaddr = machopic_indirect_call_target (DECL_RTL (function));
   21421 	  fnaddr = XEXP (fnaddr, 0);
   21422 	}
   21423 #endif /* TARGET_MACHO */
   21424       else
   21425 	{
   21426 	  tmp = gen_rtx_REG (Pmode, CX_REG);
   21427 	  output_set_got (tmp, NULL_RTX);
   21428 
   21429 	  fnaddr = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, fnaddr), UNSPEC_GOT);
   21430 	  fnaddr = gen_rtx_CONST (Pmode, fnaddr);
   21431 	  fnaddr = gen_rtx_PLUS (Pmode, tmp, fnaddr);
   21432 	  fnaddr = gen_const_mem (Pmode, fnaddr);
   21433 	}
   21434     }
   21435 
   21436   /* Our sibling call patterns do not allow memories, because we have no
   21437      predicate that can distinguish between frame and non-frame memory.
   21438      For our purposes here, we can get away with (ab)using a jump pattern,
   21439      because we're going to do no optimization.  */
   21440   if (MEM_P (fnaddr))
   21441     {
   21442       if (sibcall_insn_operand (fnaddr, word_mode))
   21443 	{
   21444 	  fnaddr = XEXP (DECL_RTL (function), 0);
   21445 	  tmp = gen_rtx_MEM (QImode, fnaddr);
   21446 	  tmp = gen_rtx_CALL (VOIDmode, tmp, const0_rtx);
   21447 	  tmp = emit_call_insn (tmp);
   21448 	  SIBLING_CALL_P (tmp) = 1;
   21449 	}
   21450       else
   21451 	emit_jump_insn (gen_indirect_jump (fnaddr));
   21452     }
   21453   else
   21454     {
   21455       if (ix86_cmodel == CM_LARGE_PIC && SYMBOLIC_CONST (fnaddr))
   21456 	{
   21457 	  // CM_LARGE_PIC always uses pseudo PIC register which is
   21458 	  // uninitialized.  Since FUNCTION is local and calling it
   21459 	  // doesn't go through PLT, we use scratch register %r11 as
   21460 	  // PIC register and initialize it here.
   21461 	  pic_offset_table_rtx = gen_rtx_REG (Pmode, R11_REG);
   21462 	  ix86_init_large_pic_reg (tmp_regno);
   21463 	  fnaddr = legitimize_pic_address (fnaddr,
   21464 					   gen_rtx_REG (Pmode, tmp_regno));
   21465 	}
   21466 
   21467       if (!sibcall_insn_operand (fnaddr, word_mode))
   21468 	{
   21469 	  tmp = gen_rtx_REG (word_mode, tmp_regno);
   21470 	  if (GET_MODE (fnaddr) != word_mode)
   21471 	    fnaddr = gen_rtx_ZERO_EXTEND (word_mode, fnaddr);
   21472 	  emit_move_insn (tmp, fnaddr);
   21473 	  fnaddr = tmp;
   21474 	}
   21475 
   21476       tmp = gen_rtx_MEM (QImode, fnaddr);
   21477       tmp = gen_rtx_CALL (VOIDmode, tmp, const0_rtx);
   21478       tmp = emit_call_insn (tmp);
   21479       SIBLING_CALL_P (tmp) = 1;
   21480     }
   21481   emit_barrier ();
   21482 
   21483   /* Emit just enough of rest_of_compilation to get the insns emitted.  */
   21484   insn = get_insns ();
   21485   shorten_branches (insn);
   21486   assemble_start_function (thunk_fndecl, fnname);
   21487   final_start_function (insn, file, 1);
   21488   final (insn, file, 1);
   21489   final_end_function ();
   21490   assemble_end_function (thunk_fndecl, fnname);
   21491 
   21492   flag_force_indirect_call = saved_flag_force_indirect_call;
   21493 }
   21494 
   21495 static void
   21496 x86_file_start (void)
   21497 {
   21498   default_file_start ();
   21499   if (TARGET_16BIT)
   21500     fputs ("\t.code16gcc\n", asm_out_file);
   21501 #if TARGET_MACHO
   21502   darwin_file_start ();
   21503 #endif
   21504   if (X86_FILE_START_VERSION_DIRECTIVE)
   21505     fputs ("\t.version\t\"01.01\"\n", asm_out_file);
   21506   if (X86_FILE_START_FLTUSED)
   21507     fputs ("\t.global\t__fltused\n", asm_out_file);
   21508   if (ix86_asm_dialect == ASM_INTEL)
   21509     fputs ("\t.intel_syntax noprefix\n", asm_out_file);
   21510 }
   21511 
   21512 int
   21513 x86_field_alignment (tree type, int computed)
   21514 {
   21515   machine_mode mode;
   21516 
   21517   if (TARGET_64BIT || TARGET_ALIGN_DOUBLE)
   21518     return computed;
   21519   if (TARGET_IAMCU)
   21520     return iamcu_alignment (type, computed);
   21521   type = strip_array_types (type);
   21522   mode = TYPE_MODE (type);
   21523   if (mode == DFmode || mode == DCmode
   21524       || GET_MODE_CLASS (mode) == MODE_INT
   21525       || GET_MODE_CLASS (mode) == MODE_COMPLEX_INT)
   21526     {
   21527       if (TYPE_ATOMIC (type) && computed > 32)
   21528 	{
   21529 	  static bool warned;
   21530 
   21531 	  if (!warned && warn_psabi)
   21532 	    {
   21533 	      const char *url
   21534 		= CHANGES_ROOT_URL "gcc-11/changes.html#ia32_atomic";
   21535 
   21536 	      warned = true;
   21537 	      inform (input_location, "the alignment of %<_Atomic %T%> "
   21538 				      "fields changed in %{GCC 11.1%}",
   21539 		      TYPE_MAIN_VARIANT (type), url);
   21540 	    }
   21541 	}
   21542       else
   21543       return MIN (32, computed);
   21544     }
   21545   return computed;
   21546 }
   21547 
   21548 /* Print call to TARGET to FILE.  */
   21549 
   21550 static void
   21551 x86_print_call_or_nop (FILE *file, const char *target)
   21552 {
   21553   if (flag_nop_mcount || !strcmp (target, "nop"))
   21554     /* 5 byte nop: nopl 0(%[re]ax,%[re]ax,1) */
   21555     fprintf (file, "1:" ASM_BYTE "0x0f, 0x1f, 0x44, 0x00, 0x00\n");
   21556   else
   21557     fprintf (file, "1:\tcall\t%s\n", target);
   21558 }
   21559 
   21560 static bool
   21561 current_fentry_name (const char **name)
   21562 {
   21563   tree attr = lookup_attribute ("fentry_name",
   21564 				DECL_ATTRIBUTES (current_function_decl));
   21565   if (!attr)
   21566     return false;
   21567   *name = TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr)));
   21568   return true;
   21569 }
   21570 
   21571 static bool
   21572 current_fentry_section (const char **name)
   21573 {
   21574   tree attr = lookup_attribute ("fentry_section",
   21575 				DECL_ATTRIBUTES (current_function_decl));
   21576   if (!attr)
   21577     return false;
   21578   *name = TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr)));
   21579   return true;
   21580 }
   21581 
   21582 /* Output assembler code to FILE to increment profiler label # LABELNO
   21583    for profiling a function entry.  */
   21584 void
   21585 x86_function_profiler (FILE *file, int labelno ATTRIBUTE_UNUSED)
   21586 {
   21587   if (cfun->machine->insn_queued_at_entrance)
   21588     {
   21589       if (cfun->machine->insn_queued_at_entrance == TYPE_ENDBR)
   21590 	fprintf (file, "\t%s\n", TARGET_64BIT ? "endbr64" : "endbr32");
   21591       unsigned int patch_area_size
   21592 	= crtl->patch_area_size - crtl->patch_area_entry;
   21593       if (patch_area_size)
   21594 	ix86_output_patchable_area (patch_area_size,
   21595 				    crtl->patch_area_entry == 0);
   21596     }
   21597 
   21598   const char *mcount_name = MCOUNT_NAME;
   21599 
   21600   if (current_fentry_name (&mcount_name))
   21601     ;
   21602   else if (fentry_name)
   21603     mcount_name = fentry_name;
   21604   else if (flag_fentry)
   21605     mcount_name = MCOUNT_NAME_BEFORE_PROLOGUE;
   21606 
   21607   if (TARGET_64BIT)
   21608     {
   21609 #ifndef NO_PROFILE_COUNTERS
   21610       if (ASSEMBLER_DIALECT == ASM_INTEL)
   21611 	fprintf (file, "\tlea\tr11, %sP%d[rip]\n", LPREFIX, labelno);
   21612       else
   21613 	fprintf (file, "\tleaq\t%sP%d(%%rip), %%r11\n", LPREFIX, labelno);
   21614 #endif
   21615 
   21616       if (!TARGET_PECOFF)
   21617 	{
   21618 	  switch (ix86_cmodel)
   21619 	    {
   21620 	    case CM_LARGE:
   21621 	      /* NB: R10 is caller-saved.  Although it can be used as a
   21622 		 static chain register, it is preserved when calling
   21623 		 mcount for nested functions.  */
   21624 	      if (ASSEMBLER_DIALECT == ASM_INTEL)
   21625 		fprintf (file, "1:\tmovabs\tr10, OFFSET FLAT:%s\n"
   21626 			       "\tcall\tr10\n", mcount_name);
   21627 	      else
   21628 		fprintf (file, "1:\tmovabsq\t$%s, %%r10\n\tcall\t*%%r10\n",
   21629 			 mcount_name);
   21630 	      break;
   21631 	    case CM_LARGE_PIC:
   21632 #ifdef NO_PROFILE_COUNTERS
   21633 	      if (ASSEMBLER_DIALECT == ASM_INTEL)
   21634 		{
   21635 		  fprintf (file, "1:movabs\tr11, "
   21636 				 "OFFSET FLAT:_GLOBAL_OFFSET_TABLE_-1b\n");
   21637 		  fprintf (file, "\tlea\tr10, 1b[rip]\n");
   21638 		  fprintf (file, "\tadd\tr10, r11\n");
   21639 		  fprintf (file, "\tmovabs\tr11, OFFSET FLAT:%s@PLTOFF\n",
   21640 			   mcount_name);
   21641 		  fprintf (file, "\tadd\tr10, r11\n");
   21642 		  fprintf (file, "\tcall\tr10\n");
   21643 		  break;
   21644 		}
   21645 	      fprintf (file,
   21646 		       "1:\tmovabsq\t$_GLOBAL_OFFSET_TABLE_-1b, %%r11\n");
   21647 	      fprintf (file, "\tleaq\t1b(%%rip), %%r10\n");
   21648 	      fprintf (file, "\taddq\t%%r11, %%r10\n");
   21649 	      fprintf (file, "\tmovabsq\t$%s@PLTOFF, %%r11\n", mcount_name);
   21650 	      fprintf (file, "\taddq\t%%r11, %%r10\n");
   21651 	      fprintf (file, "\tcall\t*%%r10\n");
   21652 #else
   21653 	      sorry ("profiling %<-mcmodel=large%> with PIC is not supported");
   21654 #endif
   21655 	      break;
   21656 	    case CM_SMALL_PIC:
   21657 	    case CM_MEDIUM_PIC:
   21658 	      if (ASSEMBLER_DIALECT == ASM_INTEL)
   21659 		fprintf (file, "1:\tcall\t[QWORD PTR %s@GOTPCREL[rip]]\n",
   21660 			 mcount_name);
   21661 	      else
   21662 		fprintf (file, "1:\tcall\t*%s@GOTPCREL(%%rip)\n", mcount_name);
   21663 	      break;
   21664 	    default:
   21665 	      x86_print_call_or_nop (file, mcount_name);
   21666 	      break;
   21667 	    }
   21668 	}
   21669       else
   21670 	x86_print_call_or_nop (file, mcount_name);
   21671     }
   21672   else if (flag_pic)
   21673     {
   21674 #ifndef NO_PROFILE_COUNTERS
   21675       if (ASSEMBLER_DIALECT == ASM_INTEL)
   21676 	fprintf (file,
   21677 		 "\tlea\t" PROFILE_COUNT_REGISTER ", %sP%d@GOTOFF[ebx]\n",
   21678 		 LPREFIX, labelno);
   21679       else
   21680 	fprintf (file,
   21681 		 "\tleal\t%sP%d@GOTOFF(%%ebx), %%" PROFILE_COUNT_REGISTER "\n",
   21682 		 LPREFIX, labelno);
   21683 #endif
   21684       if (ASSEMBLER_DIALECT == ASM_INTEL)
   21685 	fprintf (file, "1:\tcall\t[DWORD PTR %s@GOT[ebx]]\n", mcount_name);
   21686       else
   21687 	fprintf (file, "1:\tcall\t*%s@GOT(%%ebx)\n", mcount_name);
   21688     }
   21689   else
   21690     {
   21691 #ifndef NO_PROFILE_COUNTERS
   21692       if (ASSEMBLER_DIALECT == ASM_INTEL)
   21693 	fprintf (file,
   21694 		 "\tmov\t" PROFILE_COUNT_REGISTER ", OFFSET FLAT:%sP%d\n",
   21695 		 LPREFIX, labelno);
   21696       else
   21697 	fprintf (file, "\tmovl\t$%sP%d, %%" PROFILE_COUNT_REGISTER "\n",
   21698 		 LPREFIX, labelno);
   21699 #endif
   21700       x86_print_call_or_nop (file, mcount_name);
   21701     }
   21702 
   21703   if (flag_record_mcount
   21704       || lookup_attribute ("fentry_section",
   21705 			   DECL_ATTRIBUTES (current_function_decl)))
   21706     {
   21707       const char *sname = "__mcount_loc";
   21708 
   21709       if (current_fentry_section (&sname))
   21710 	;
   21711       else if (fentry_section)
   21712 	sname = fentry_section;
   21713 
   21714       fprintf (file, "\t.section %s, \"a\",@progbits\n", sname);
   21715       fprintf (file, "\t.%s 1b\n", TARGET_64BIT ? "quad" : "long");
   21716       fprintf (file, "\t.previous\n");
   21717     }
   21718 }
   21719 
   21720 /* We don't have exact information about the insn sizes, but we may assume
   21721    quite safely that we are informed about all 1 byte insns and memory
   21722    address sizes.  This is enough to eliminate unnecessary padding in
   21723    99% of cases.  */
   21724 
   21725 int
   21726 ix86_min_insn_size (rtx_insn *insn)
   21727 {
   21728   int l = 0, len;
   21729 
   21730   if (!INSN_P (insn) || !active_insn_p (insn))
   21731     return 0;
   21732 
   21733   /* Discard alignments we've emit and jump instructions.  */
   21734   if (GET_CODE (PATTERN (insn)) == UNSPEC_VOLATILE
   21735       && XINT (PATTERN (insn), 1) == UNSPECV_ALIGN)
   21736     return 0;
   21737 
   21738   /* Important case - calls are always 5 bytes.
   21739      It is common to have many calls in the row.  */
   21740   if (CALL_P (insn)
   21741       && symbolic_reference_mentioned_p (PATTERN (insn))
   21742       && !SIBLING_CALL_P (insn))
   21743     return 5;
   21744   len = get_attr_length (insn);
   21745   if (len <= 1)
   21746     return 1;
   21747 
   21748   /* For normal instructions we rely on get_attr_length being exact,
   21749      with a few exceptions.  */
   21750   if (!JUMP_P (insn))
   21751     {
   21752       enum attr_type type = get_attr_type (insn);
   21753 
   21754       switch (type)
   21755 	{
   21756 	case TYPE_MULTI:
   21757 	  if (GET_CODE (PATTERN (insn)) == ASM_INPUT
   21758 	      || asm_noperands (PATTERN (insn)) >= 0)
   21759 	    return 0;
   21760 	  break;
   21761 	case TYPE_OTHER:
   21762 	case TYPE_FCMP:
   21763 	  break;
   21764 	default:
   21765 	  /* Otherwise trust get_attr_length.  */
   21766 	  return len;
   21767 	}
   21768 
   21769       l = get_attr_length_address (insn);
   21770       if (l < 4 && symbolic_reference_mentioned_p (PATTERN (insn)))
   21771 	l = 4;
   21772     }
   21773   if (l)
   21774     return 1+l;
   21775   else
   21776     return 2;
   21777 }
   21778 
   21779 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
   21780 
   21781 /* AMD K8 core mispredicts jumps when there are more than 3 jumps in 16 byte
   21782    window.  */
   21783 
   21784 static void
   21785 ix86_avoid_jump_mispredicts (void)
   21786 {
   21787   rtx_insn *insn, *start = get_insns ();
   21788   int nbytes = 0, njumps = 0;
   21789   bool isjump = false;
   21790 
   21791   /* Look for all minimal intervals of instructions containing 4 jumps.
   21792      The intervals are bounded by START and INSN.  NBYTES is the total
   21793      size of instructions in the interval including INSN and not including
   21794      START.  When the NBYTES is smaller than 16 bytes, it is possible
   21795      that the end of START and INSN ends up in the same 16byte page.
   21796 
   21797      The smallest offset in the page INSN can start is the case where START
   21798      ends on the offset 0.  Offset of INSN is then NBYTES - sizeof (INSN).
   21799      We add p2align to 16byte window with maxskip 15 - NBYTES + sizeof (INSN).
   21800 
   21801      Don't consider asm goto as jump, while it can contain a jump, it doesn't
   21802      have to, control transfer to label(s) can be performed through other
   21803      means, and also we estimate minimum length of all asm stmts as 0.  */
   21804   for (insn = start; insn; insn = NEXT_INSN (insn))
   21805     {
   21806       int min_size;
   21807 
   21808       if (LABEL_P (insn))
   21809 	{
   21810 	  align_flags alignment = label_to_alignment (insn);
   21811 	  int align = alignment.levels[0].log;
   21812 	  int max_skip = alignment.levels[0].maxskip;
   21813 
   21814 	  if (max_skip > 15)
   21815 	    max_skip = 15;
   21816 	  /* If align > 3, only up to 16 - max_skip - 1 bytes can be
   21817 	     already in the current 16 byte page, because otherwise
   21818 	     ASM_OUTPUT_MAX_SKIP_ALIGN could skip max_skip or fewer
   21819 	     bytes to reach 16 byte boundary.  */
   21820 	  if (align <= 0
   21821 	      || (align <= 3 && max_skip != (1 << align) - 1))
   21822 	    max_skip = 0;
   21823 	  if (dump_file)
   21824 	    fprintf (dump_file, "Label %i with max_skip %i\n",
   21825 		     INSN_UID (insn), max_skip);
   21826 	  if (max_skip)
   21827 	    {
   21828 	      while (nbytes + max_skip >= 16)
   21829 		{
   21830 		  start = NEXT_INSN (start);
   21831 		  if ((JUMP_P (start) && asm_noperands (PATTERN (start)) < 0)
   21832 		      || CALL_P (start))
   21833 		    njumps--, isjump = true;
   21834 		  else
   21835 		    isjump = false;
   21836 		  nbytes -= ix86_min_insn_size (start);
   21837 		}
   21838 	    }
   21839 	  continue;
   21840 	}
   21841 
   21842       min_size = ix86_min_insn_size (insn);
   21843       nbytes += min_size;
   21844       if (dump_file)
   21845 	fprintf (dump_file, "Insn %i estimated to %i bytes\n",
   21846 		 INSN_UID (insn), min_size);
   21847       if ((JUMP_P (insn) && asm_noperands (PATTERN (insn)) < 0)
   21848 	  || CALL_P (insn))
   21849 	njumps++;
   21850       else
   21851 	continue;
   21852 
   21853       while (njumps > 3)
   21854 	{
   21855 	  start = NEXT_INSN (start);
   21856 	  if ((JUMP_P (start) && asm_noperands (PATTERN (start)) < 0)
   21857 	      || CALL_P (start))
   21858 	    njumps--, isjump = true;
   21859 	  else
   21860 	    isjump = false;
   21861 	  nbytes -= ix86_min_insn_size (start);
   21862 	}
   21863       gcc_assert (njumps >= 0);
   21864       if (dump_file)
   21865         fprintf (dump_file, "Interval %i to %i has %i bytes\n",
   21866 		 INSN_UID (start), INSN_UID (insn), nbytes);
   21867 
   21868       if (njumps == 3 && isjump && nbytes < 16)
   21869 	{
   21870 	  int padsize = 15 - nbytes + ix86_min_insn_size (insn);
   21871 
   21872 	  if (dump_file)
   21873 	    fprintf (dump_file, "Padding insn %i by %i bytes!\n",
   21874 		     INSN_UID (insn), padsize);
   21875           emit_insn_before (gen_pad (GEN_INT (padsize)), insn);
   21876 	}
   21877     }
   21878 }
   21879 #endif
   21880 
   21881 /* AMD Athlon works faster
   21882    when RET is not destination of conditional jump or directly preceded
   21883    by other jump instruction.  We avoid the penalty by inserting NOP just
   21884    before the RET instructions in such cases.  */
   21885 static void
   21886 ix86_pad_returns (void)
   21887 {
   21888   edge e;
   21889   edge_iterator ei;
   21890 
   21891   FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR_FOR_FN (cfun)->preds)
   21892     {
   21893       basic_block bb = e->src;
   21894       rtx_insn *ret = BB_END (bb);
   21895       rtx_insn *prev;
   21896       bool replace = false;
   21897 
   21898       if (!JUMP_P (ret) || !ANY_RETURN_P (PATTERN (ret))
   21899 	  || optimize_bb_for_size_p (bb))
   21900 	continue;
   21901       for (prev = PREV_INSN (ret); prev; prev = PREV_INSN (prev))
   21902 	if (active_insn_p (prev) || LABEL_P (prev))
   21903 	  break;
   21904       if (prev && LABEL_P (prev))
   21905 	{
   21906 	  edge e;
   21907 	  edge_iterator ei;
   21908 
   21909 	  FOR_EACH_EDGE (e, ei, bb->preds)
   21910 	    if (EDGE_FREQUENCY (e) && e->src->index >= 0
   21911 		&& !(e->flags & EDGE_FALLTHRU))
   21912 	      {
   21913 		replace = true;
   21914 		break;
   21915 	      }
   21916 	}
   21917       if (!replace)
   21918 	{
   21919 	  prev = prev_active_insn (ret);
   21920 	  if (prev
   21921 	      && ((JUMP_P (prev) && any_condjump_p (prev))
   21922 		  || CALL_P (prev)))
   21923 	    replace = true;
   21924 	  /* Empty functions get branch mispredict even when
   21925 	     the jump destination is not visible to us.  */
   21926 	  if (!prev && !optimize_function_for_size_p (cfun))
   21927 	    replace = true;
   21928 	}
   21929       if (replace)
   21930 	{
   21931 	  emit_jump_insn_before (gen_simple_return_internal_long (), ret);
   21932 	  delete_insn (ret);
   21933 	}
   21934     }
   21935 }
   21936 
   21937 /* Count the minimum number of instructions in BB.  Return 4 if the
   21938    number of instructions >= 4.  */
   21939 
   21940 static int
   21941 ix86_count_insn_bb (basic_block bb)
   21942 {
   21943   rtx_insn *insn;
   21944   int insn_count = 0;
   21945 
   21946   /* Count number of instructions in this block.  Return 4 if the number
   21947      of instructions >= 4.  */
   21948   FOR_BB_INSNS (bb, insn)
   21949     {
   21950       /* Only happen in exit blocks.  */
   21951       if (JUMP_P (insn)
   21952 	  && ANY_RETURN_P (PATTERN (insn)))
   21953 	break;
   21954 
   21955       if (NONDEBUG_INSN_P (insn)
   21956 	  && GET_CODE (PATTERN (insn)) != USE
   21957 	  && GET_CODE (PATTERN (insn)) != CLOBBER)
   21958 	{
   21959 	  insn_count++;
   21960 	  if (insn_count >= 4)
   21961 	    return insn_count;
   21962 	}
   21963     }
   21964 
   21965   return insn_count;
   21966 }
   21967 
   21968 
   21969 /* Count the minimum number of instructions in code path in BB.
   21970    Return 4 if the number of instructions >= 4.  */
   21971 
   21972 static int
   21973 ix86_count_insn (basic_block bb)
   21974 {
   21975   edge e;
   21976   edge_iterator ei;
   21977   int min_prev_count;
   21978 
   21979   /* Only bother counting instructions along paths with no
   21980      more than 2 basic blocks between entry and exit.  Given
   21981      that BB has an edge to exit, determine if a predecessor
   21982      of BB has an edge from entry.  If so, compute the number
   21983      of instructions in the predecessor block.  If there
   21984      happen to be multiple such blocks, compute the minimum.  */
   21985   min_prev_count = 4;
   21986   FOR_EACH_EDGE (e, ei, bb->preds)
   21987     {
   21988       edge prev_e;
   21989       edge_iterator prev_ei;
   21990 
   21991       if (e->src == ENTRY_BLOCK_PTR_FOR_FN (cfun))
   21992 	{
   21993 	  min_prev_count = 0;
   21994 	  break;
   21995 	}
   21996       FOR_EACH_EDGE (prev_e, prev_ei, e->src->preds)
   21997 	{
   21998 	  if (prev_e->src == ENTRY_BLOCK_PTR_FOR_FN (cfun))
   21999 	    {
   22000 	      int count = ix86_count_insn_bb (e->src);
   22001 	      if (count < min_prev_count)
   22002 		min_prev_count = count;
   22003 	      break;
   22004 	    }
   22005 	}
   22006     }
   22007 
   22008   if (min_prev_count < 4)
   22009     min_prev_count += ix86_count_insn_bb (bb);
   22010 
   22011   return min_prev_count;
   22012 }
   22013 
   22014 /* Pad short function to 4 instructions.   */
   22015 
   22016 static void
   22017 ix86_pad_short_function (void)
   22018 {
   22019   edge e;
   22020   edge_iterator ei;
   22021 
   22022   FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR_FOR_FN (cfun)->preds)
   22023     {
   22024       rtx_insn *ret = BB_END (e->src);
   22025       if (JUMP_P (ret) && ANY_RETURN_P (PATTERN (ret)))
   22026 	{
   22027 	  int insn_count = ix86_count_insn (e->src);
   22028 
   22029 	  /* Pad short function.  */
   22030 	  if (insn_count < 4)
   22031 	    {
   22032 	      rtx_insn *insn = ret;
   22033 
   22034 	      /* Find epilogue.  */
   22035 	      while (insn
   22036 		     && (!NOTE_P (insn)
   22037 			 || NOTE_KIND (insn) != NOTE_INSN_EPILOGUE_BEG))
   22038 		insn = PREV_INSN (insn);
   22039 
   22040 	      if (!insn)
   22041 		insn = ret;
   22042 
   22043 	      /* Two NOPs count as one instruction.  */
   22044 	      insn_count = 2 * (4 - insn_count);
   22045 	      emit_insn_before (gen_nops (GEN_INT (insn_count)), insn);
   22046 	    }
   22047 	}
   22048     }
   22049 }
   22050 
   22051 /* Fix up a Windows system unwinder issue.  If an EH region falls through into
   22052    the epilogue, the Windows system unwinder will apply epilogue logic and
   22053    produce incorrect offsets.  This can be avoided by adding a nop between
   22054    the last insn that can throw and the first insn of the epilogue.  */
   22055 
   22056 static void
   22057 ix86_seh_fixup_eh_fallthru (void)
   22058 {
   22059   edge e;
   22060   edge_iterator ei;
   22061 
   22062   FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR_FOR_FN (cfun)->preds)
   22063     {
   22064       rtx_insn *insn, *next;
   22065 
   22066       /* Find the beginning of the epilogue.  */
   22067       for (insn = BB_END (e->src); insn != NULL; insn = PREV_INSN (insn))
   22068 	if (NOTE_P (insn) && NOTE_KIND (insn) == NOTE_INSN_EPILOGUE_BEG)
   22069 	  break;
   22070       if (insn == NULL)
   22071 	continue;
   22072 
   22073       /* We only care about preceding insns that can throw.  */
   22074       insn = prev_active_insn (insn);
   22075       if (insn == NULL || !can_throw_internal (insn))
   22076 	continue;
   22077 
   22078       /* Do not separate calls from their debug information.  */
   22079       for (next = NEXT_INSN (insn); next != NULL; next = NEXT_INSN (next))
   22080 	if (NOTE_P (next) && NOTE_KIND (next) == NOTE_INSN_VAR_LOCATION)
   22081 	  insn = next;
   22082 	else
   22083 	  break;
   22084 
   22085       emit_insn_after (gen_nops (const1_rtx), insn);
   22086     }
   22087 }
   22088 /* Split vector load from parm_decl to elemental loads to avoid STLF
   22089    stalls.  */
   22090 static void
   22091 ix86_split_stlf_stall_load ()
   22092 {
   22093   rtx_insn* insn, *start = get_insns ();
   22094   unsigned window = 0;
   22095 
   22096   for (insn = start; insn; insn = NEXT_INSN (insn))
   22097     {
   22098       if (!NONDEBUG_INSN_P (insn))
   22099 	continue;
   22100       window++;
   22101       /* Insert 64 vaddps %xmm18, %xmm19, %xmm20(no dependence between each
   22102 	 other, just emulate for pipeline) before stalled load, stlf stall
   22103 	 case is as fast as no stall cases on CLX.
   22104 	 Since CFG is freed before machine_reorg, just do a rough
   22105 	 calculation of the window according to the layout.  */
   22106       if (window > (unsigned) x86_stlf_window_ninsns)
   22107 	return;
   22108 
   22109       if (any_uncondjump_p (insn)
   22110 	  || ANY_RETURN_P (PATTERN (insn))
   22111 	  || CALL_P (insn))
   22112 	return;
   22113 
   22114       rtx set = single_set (insn);
   22115       if (!set)
   22116 	continue;
   22117       rtx src = SET_SRC (set);
   22118       if (!MEM_P (src)
   22119 	  /* Only handle V2DFmode load since it doesn't need any scratch
   22120 	     register.  */
   22121 	  || GET_MODE (src) != E_V2DFmode
   22122 	  || !MEM_EXPR (src)
   22123 	  || TREE_CODE (get_base_address (MEM_EXPR (src))) != PARM_DECL)
   22124 	continue;
   22125 
   22126       rtx zero = CONST0_RTX (V2DFmode);
   22127       rtx dest = SET_DEST (set);
   22128       rtx m = adjust_address (src, DFmode, 0);
   22129       rtx loadlpd = gen_sse2_loadlpd (dest, zero, m);
   22130       emit_insn_before (loadlpd, insn);
   22131       m = adjust_address (src, DFmode, 8);
   22132       rtx loadhpd = gen_sse2_loadhpd (dest, dest, m);
   22133       if (dump_file && (dump_flags & TDF_DETAILS))
   22134 	{
   22135 	  fputs ("Due to potential STLF stall, split instruction:\n",
   22136 		 dump_file);
   22137 	  print_rtl_single (dump_file, insn);
   22138 	  fputs ("To:\n", dump_file);
   22139 	  print_rtl_single (dump_file, loadlpd);
   22140 	  print_rtl_single (dump_file, loadhpd);
   22141 	}
   22142       PATTERN (insn) = loadhpd;
   22143       INSN_CODE (insn) = -1;
   22144       gcc_assert (recog_memoized (insn) != -1);
   22145     }
   22146 }
   22147 
   22148 /* Implement machine specific optimizations.  We implement padding of returns
   22149    for K8 CPUs and pass to avoid 4 jumps in the single 16 byte window.  */
   22150 static void
   22151 ix86_reorg (void)
   22152 {
   22153   /* We are freeing block_for_insn in the toplev to keep compatibility
   22154      with old MDEP_REORGS that are not CFG based.  Recompute it now.  */
   22155   compute_bb_for_insn ();
   22156 
   22157   if (TARGET_SEH && current_function_has_exception_handlers ())
   22158     ix86_seh_fixup_eh_fallthru ();
   22159 
   22160   if (optimize && optimize_function_for_speed_p (cfun))
   22161     {
   22162       if (TARGET_SSE2)
   22163 	ix86_split_stlf_stall_load ();
   22164       if (TARGET_PAD_SHORT_FUNCTION)
   22165 	ix86_pad_short_function ();
   22166       else if (TARGET_PAD_RETURNS)
   22167 	ix86_pad_returns ();
   22168 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
   22169       if (TARGET_FOUR_JUMP_LIMIT)
   22170 	ix86_avoid_jump_mispredicts ();
   22171 #endif
   22172     }
   22173 }
   22174 
   22175 /* Return nonzero when QImode register that must be represented via REX prefix
   22176    is used.  */
   22177 bool
   22178 x86_extended_QIreg_mentioned_p (rtx_insn *insn)
   22179 {
   22180   int i;
   22181   extract_insn_cached (insn);
   22182   for (i = 0; i < recog_data.n_operands; i++)
   22183     if (GENERAL_REG_P (recog_data.operand[i])
   22184 	&& !QI_REGNO_P (REGNO (recog_data.operand[i])))
   22185        return true;
   22186   return false;
   22187 }
   22188 
   22189 /* Return true when INSN mentions register that must be encoded using REX
   22190    prefix.  */
   22191 bool
   22192 x86_extended_reg_mentioned_p (rtx insn)
   22193 {
   22194   subrtx_iterator::array_type array;
   22195   FOR_EACH_SUBRTX (iter, array, INSN_P (insn) ? PATTERN (insn) : insn, NONCONST)
   22196     {
   22197       const_rtx x = *iter;
   22198       if (REG_P (x)
   22199 	  && (REX_INT_REGNO_P (REGNO (x)) || REX_SSE_REGNO_P (REGNO (x))))
   22200 	return true;
   22201     }
   22202   return false;
   22203 }
   22204 
   22205 /* If profitable, negate (without causing overflow) integer constant
   22206    of mode MODE at location LOC.  Return true in this case.  */
   22207 bool
   22208 x86_maybe_negate_const_int (rtx *loc, machine_mode mode)
   22209 {
   22210   HOST_WIDE_INT val;
   22211 
   22212   if (!CONST_INT_P (*loc))
   22213     return false;
   22214 
   22215   switch (mode)
   22216     {
   22217     case E_DImode:
   22218       /* DImode x86_64 constants must fit in 32 bits.  */
   22219       gcc_assert (x86_64_immediate_operand (*loc, mode));
   22220 
   22221       mode = SImode;
   22222       break;
   22223 
   22224     case E_SImode:
   22225     case E_HImode:
   22226     case E_QImode:
   22227       break;
   22228 
   22229     default:
   22230       gcc_unreachable ();
   22231     }
   22232 
   22233   /* Avoid overflows.  */
   22234   if (mode_signbit_p (mode, *loc))
   22235     return false;
   22236 
   22237   val = INTVAL (*loc);
   22238 
   22239   /* Make things pretty and `subl $4,%eax' rather than `addl $-4,%eax'.
   22240      Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
   22241   if ((val < 0 && val != -128)
   22242       || val == 128)
   22243     {
   22244       *loc = GEN_INT (-val);
   22245       return true;
   22246     }
   22247 
   22248   return false;
   22249 }
   22250 
   22251 /* Generate an unsigned DImode/SImode to FP conversion.  This is the same code
   22252    optabs would emit if we didn't have TFmode patterns.  */
   22253 
   22254 void
   22255 x86_emit_floatuns (rtx operands[2])
   22256 {
   22257   rtx_code_label *neglab, *donelab;
   22258   rtx i0, i1, f0, in, out;
   22259   machine_mode mode, inmode;
   22260 
   22261   inmode = GET_MODE (operands[1]);
   22262   gcc_assert (inmode == SImode || inmode == DImode);
   22263 
   22264   out = operands[0];
   22265   in = force_reg (inmode, operands[1]);
   22266   mode = GET_MODE (out);
   22267   neglab = gen_label_rtx ();
   22268   donelab = gen_label_rtx ();
   22269   f0 = gen_reg_rtx (mode);
   22270 
   22271   emit_cmp_and_jump_insns (in, const0_rtx, LT, const0_rtx, inmode, 0, neglab);
   22272 
   22273   expand_float (out, in, 0);
   22274 
   22275   emit_jump_insn (gen_jump (donelab));
   22276   emit_barrier ();
   22277 
   22278   emit_label (neglab);
   22279 
   22280   i0 = expand_simple_binop (inmode, LSHIFTRT, in, const1_rtx, NULL,
   22281 			    1, OPTAB_DIRECT);
   22282   i1 = expand_simple_binop (inmode, AND, in, const1_rtx, NULL,
   22283 			    1, OPTAB_DIRECT);
   22284   i0 = expand_simple_binop (inmode, IOR, i0, i1, i0, 1, OPTAB_DIRECT);
   22285 
   22286   expand_float (f0, i0, 0);
   22287 
   22288   emit_insn (gen_rtx_SET (out, gen_rtx_PLUS (mode, f0, f0)));
   22289 
   22290   emit_label (donelab);
   22291 }
   22292 
   22293 /* Target hook for scalar_mode_supported_p.  */
   22295 static bool
   22296 ix86_scalar_mode_supported_p (scalar_mode mode)
   22297 {
   22298   if (DECIMAL_FLOAT_MODE_P (mode))
   22299     return default_decimal_float_supported_p ();
   22300   else if (mode == TFmode)
   22301     return true;
   22302   else if (mode == HFmode && TARGET_SSE2)
   22303     return true;
   22304   else
   22305     return default_scalar_mode_supported_p (mode);
   22306 }
   22307 
   22308 /* Implement TARGET_LIBGCC_FLOATING_POINT_MODE_SUPPORTED_P - return TRUE
   22309    if MODE is HFmode, and punt to the generic implementation otherwise.  */
   22310 
   22311 static bool
   22312 ix86_libgcc_floating_mode_supported_p (scalar_float_mode mode)
   22313 {
   22314   /* NB: Always return TRUE for HFmode so that the _Float16 type will
   22315      be defined by the C front-end for AVX512FP16 intrinsics.  We will
   22316      issue an error in ix86_expand_move for HFmode if AVX512FP16 isn't
   22317      enabled.  */
   22318   return ((mode == HFmode && TARGET_SSE2)
   22319 	  ? true
   22320 	  : default_libgcc_floating_mode_supported_p (mode));
   22321 }
   22322 
   22323 /* Implements target hook vector_mode_supported_p.  */
   22324 static bool
   22325 ix86_vector_mode_supported_p (machine_mode mode)
   22326 {
   22327   /* For ia32, scalar TImode isn't supported and so V1TImode shouldn't be
   22328      either.  */
   22329   if (!TARGET_64BIT && GET_MODE_INNER (mode) == TImode)
   22330     return false;
   22331   if (TARGET_SSE && VALID_SSE_REG_MODE (mode))
   22332     return true;
   22333   if (TARGET_SSE2 && VALID_SSE2_REG_MODE (mode))
   22334     return true;
   22335   if (TARGET_AVX && VALID_AVX256_REG_MODE (mode))
   22336     return true;
   22337   if (TARGET_AVX512F && VALID_AVX512F_REG_MODE (mode))
   22338     return true;
   22339   if ((TARGET_MMX || TARGET_MMX_WITH_SSE)
   22340       && VALID_MMX_REG_MODE (mode))
   22341     return true;
   22342   if ((TARGET_3DNOW || TARGET_MMX_WITH_SSE)
   22343       && VALID_MMX_REG_MODE_3DNOW (mode))
   22344     return true;
   22345   if (mode == V2QImode)
   22346     return true;
   22347   return false;
   22348 }
   22349 
   22350 /* Target hook for c_mode_for_suffix.  */
   22351 static machine_mode
   22352 ix86_c_mode_for_suffix (char suffix)
   22353 {
   22354   if (suffix == 'q')
   22355     return TFmode;
   22356   if (suffix == 'w')
   22357     return XFmode;
   22358 
   22359   return VOIDmode;
   22360 }
   22361 
   22362 /* Worker function for TARGET_MD_ASM_ADJUST.
   22363 
   22364    We implement asm flag outputs, and maintain source compatibility
   22365    with the old cc0-based compiler.  */
   22366 
   22367 static rtx_insn *
   22368 ix86_md_asm_adjust (vec<rtx> &outputs, vec<rtx> & /*inputs*/,
   22369 		    vec<machine_mode> & /*input_modes*/,
   22370 		    vec<const char *> &constraints, vec<rtx> &clobbers,
   22371 		    HARD_REG_SET &clobbered_regs, location_t loc)
   22372 {
   22373   bool saw_asm_flag = false;
   22374 
   22375   start_sequence ();
   22376   for (unsigned i = 0, n = outputs.length (); i < n; ++i)
   22377     {
   22378       const char *con = constraints[i];
   22379       if (!startswith (con, "=@cc"))
   22380 	continue;
   22381       con += 4;
   22382       if (strchr (con, ',') != NULL)
   22383 	{
   22384 	  error_at (loc, "alternatives not allowed in %<asm%> flag output");
   22385 	  continue;
   22386 	}
   22387 
   22388       bool invert = false;
   22389       if (con[0] == 'n')
   22390 	invert = true, con++;
   22391 
   22392       machine_mode mode = CCmode;
   22393       rtx_code code = UNKNOWN;
   22394 
   22395       switch (con[0])
   22396 	{
   22397 	case 'a':
   22398 	  if (con[1] == 0)
   22399 	    mode = CCAmode, code = EQ;
   22400 	  else if (con[1] == 'e' && con[2] == 0)
   22401 	    mode = CCCmode, code = NE;
   22402 	  break;
   22403 	case 'b':
   22404 	  if (con[1] == 0)
   22405 	    mode = CCCmode, code = EQ;
   22406 	  else if (con[1] == 'e' && con[2] == 0)
   22407 	    mode = CCAmode, code = NE;
   22408 	  break;
   22409 	case 'c':
   22410 	  if (con[1] == 0)
   22411 	    mode = CCCmode, code = EQ;
   22412 	  break;
   22413 	case 'e':
   22414 	  if (con[1] == 0)
   22415 	    mode = CCZmode, code = EQ;
   22416 	  break;
   22417 	case 'g':
   22418 	  if (con[1] == 0)
   22419 	    mode = CCGCmode, code = GT;
   22420 	  else if (con[1] == 'e' && con[2] == 0)
   22421 	    mode = CCGCmode, code = GE;
   22422 	  break;
   22423 	case 'l':
   22424 	  if (con[1] == 0)
   22425 	    mode = CCGCmode, code = LT;
   22426 	  else if (con[1] == 'e' && con[2] == 0)
   22427 	    mode = CCGCmode, code = LE;
   22428 	  break;
   22429 	case 'o':
   22430 	  if (con[1] == 0)
   22431 	    mode = CCOmode, code = EQ;
   22432 	  break;
   22433 	case 'p':
   22434 	  if (con[1] == 0)
   22435 	    mode = CCPmode, code = EQ;
   22436 	  break;
   22437 	case 's':
   22438 	  if (con[1] == 0)
   22439 	    mode = CCSmode, code = EQ;
   22440 	  break;
   22441 	case 'z':
   22442 	  if (con[1] == 0)
   22443 	    mode = CCZmode, code = EQ;
   22444 	  break;
   22445 	}
   22446       if (code == UNKNOWN)
   22447 	{
   22448 	  error_at (loc, "unknown %<asm%> flag output %qs", constraints[i]);
   22449 	  continue;
   22450 	}
   22451       if (invert)
   22452 	code = reverse_condition (code);
   22453 
   22454       rtx dest = outputs[i];
   22455       if (!saw_asm_flag)
   22456 	{
   22457 	  /* This is the first asm flag output.  Here we put the flags
   22458 	     register in as the real output and adjust the condition to
   22459 	     allow it.  */
   22460 	  constraints[i] = "=Bf";
   22461 	  outputs[i] = gen_rtx_REG (CCmode, FLAGS_REG);
   22462 	  saw_asm_flag = true;
   22463 	}
   22464       else
   22465 	{
   22466 	  /* We don't need the flags register as output twice.  */
   22467 	  constraints[i] = "=X";
   22468 	  outputs[i] = gen_rtx_SCRATCH (SImode);
   22469 	}
   22470 
   22471       rtx x = gen_rtx_REG (mode, FLAGS_REG);
   22472       x = gen_rtx_fmt_ee (code, QImode, x, const0_rtx);
   22473 
   22474       machine_mode dest_mode = GET_MODE (dest);
   22475       if (!SCALAR_INT_MODE_P (dest_mode))
   22476 	{
   22477 	  error_at (loc, "invalid type for %<asm%> flag output");
   22478 	  continue;
   22479 	}
   22480 
   22481       if (dest_mode == QImode)
   22482 	emit_insn (gen_rtx_SET (dest, x));
   22483       else
   22484 	{
   22485 	  rtx reg = gen_reg_rtx (QImode);
   22486 	  emit_insn (gen_rtx_SET (reg, x));
   22487 
   22488 	  reg = convert_to_mode (dest_mode, reg, 1);
   22489 	  emit_move_insn (dest, reg);
   22490 	}
   22491     }
   22492 
   22493   rtx_insn *seq = get_insns ();
   22494   end_sequence ();
   22495 
   22496   if (saw_asm_flag)
   22497     return seq;
   22498   else
   22499     {
   22500       /* If we had no asm flag outputs, clobber the flags.  */
   22501       clobbers.safe_push (gen_rtx_REG (CCmode, FLAGS_REG));
   22502       SET_HARD_REG_BIT (clobbered_regs, FLAGS_REG);
   22503       return NULL;
   22504     }
   22505 }
   22506 
   22507 /* Implements target vector targetm.asm.encode_section_info.  */
   22508 
   22509 static void ATTRIBUTE_UNUSED
   22510 ix86_encode_section_info (tree decl, rtx rtl, int first)
   22511 {
   22512   default_encode_section_info (decl, rtl, first);
   22513 
   22514   if (ix86_in_large_data_p (decl))
   22515     SYMBOL_REF_FLAGS (XEXP (rtl, 0)) |= SYMBOL_FLAG_FAR_ADDR;
   22516 }
   22517 
   22518 /* Worker function for REVERSE_CONDITION.  */
   22519 
   22520 enum rtx_code
   22521 ix86_reverse_condition (enum rtx_code code, machine_mode mode)
   22522 {
   22523   return (mode == CCFPmode
   22524 	  ? reverse_condition_maybe_unordered (code)
   22525 	  : reverse_condition (code));
   22526 }
   22527 
   22528 /* Output code to perform an x87 FP register move, from OPERANDS[1]
   22529    to OPERANDS[0].  */
   22530 
   22531 const char *
   22532 output_387_reg_move (rtx_insn *insn, rtx *operands)
   22533 {
   22534   if (REG_P (operands[0]))
   22535     {
   22536       if (REG_P (operands[1])
   22537 	  && find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
   22538 	{
   22539 	  if (REGNO (operands[0]) == FIRST_STACK_REG)
   22540 	    return output_387_ffreep (operands, 0);
   22541 	  return "fstp\t%y0";
   22542 	}
   22543       if (STACK_TOP_P (operands[0]))
   22544 	return "fld%Z1\t%y1";
   22545       return "fst\t%y0";
   22546     }
   22547   else if (MEM_P (operands[0]))
   22548     {
   22549       gcc_assert (REG_P (operands[1]));
   22550       if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
   22551 	return "fstp%Z0\t%y0";
   22552       else
   22553 	{
   22554 	  /* There is no non-popping store to memory for XFmode.
   22555 	     So if we need one, follow the store with a load.  */
   22556 	  if (GET_MODE (operands[0]) == XFmode)
   22557 	    return "fstp%Z0\t%y0\n\tfld%Z0\t%y0";
   22558 	  else
   22559 	    return "fst%Z0\t%y0";
   22560 	}
   22561     }
   22562   else
   22563     gcc_unreachable();
   22564 }
   22565 #ifdef TARGET_SOLARIS
   22566 /* Solaris implementation of TARGET_ASM_NAMED_SECTION.  */
   22567 
   22568 static void
   22569 i386_solaris_elf_named_section (const char *name, unsigned int flags,
   22570 				tree decl)
   22571 {
   22572   /* With Binutils 2.15, the "@unwind" marker must be specified on
   22573      every occurrence of the ".eh_frame" section, not just the first
   22574      one.  */
   22575   if (TARGET_64BIT
   22576       && strcmp (name, ".eh_frame") == 0)
   22577     {
   22578       fprintf (asm_out_file, "\t.section\t%s,\"%s\",@unwind\n", name,
   22579 	       flags & SECTION_WRITE ? "aw" : "a");
   22580       return;
   22581     }
   22582 
   22583 #ifndef USE_GAS
   22584   if (HAVE_COMDAT_GROUP && flags & SECTION_LINKONCE)
   22585     {
   22586       solaris_elf_asm_comdat_section (name, flags, decl);
   22587       return;
   22588     }
   22589 
   22590   /* Solaris/x86 as uses the same syntax for the SHF_EXCLUDE flags as the
   22591      SPARC assembler.  One cannot mix single-letter flags and #exclude, so
   22592      only emit the latter here.  */
   22593   if (flags & SECTION_EXCLUDE)
   22594     {
   22595       fprintf (asm_out_file, "\t.section\t%s,#exclude\n", name);
   22596       return;
   22597     }
   22598 #endif
   22599 
   22600   default_elf_asm_named_section (name, flags, decl);
   22601 }
   22602 #endif /* TARGET_SOLARIS */
   22603 
   22604 /* Return the mangling of TYPE if it is an extended fundamental type.  */
   22605 
   22606 static const char *
   22607 ix86_mangle_type (const_tree type)
   22608 {
   22609   type = TYPE_MAIN_VARIANT (type);
   22610 
   22611   if (TREE_CODE (type) != VOID_TYPE && TREE_CODE (type) != BOOLEAN_TYPE
   22612       && TREE_CODE (type) != INTEGER_TYPE && TREE_CODE (type) != REAL_TYPE)
   22613     return NULL;
   22614 
   22615   switch (TYPE_MODE (type))
   22616     {
   22617     case E_HFmode:
   22618       /* _Float16 is "DF16_".
   22619 	 Align with clang's decision in https://reviews.llvm.org/D33719. */
   22620       return "DF16_";
   22621     case E_TFmode:
   22622       /* __float128 is "g".  */
   22623       return "g";
   22624     case E_XFmode:
   22625       /* "long double" or __float80 is "e".  */
   22626       return "e";
   22627     default:
   22628       return NULL;
   22629     }
   22630 }
   22631 
   22632 static GTY(()) tree ix86_tls_stack_chk_guard_decl;
   22633 
   22634 static tree
   22635 ix86_stack_protect_guard (void)
   22636 {
   22637   if (TARGET_SSP_TLS_GUARD)
   22638     {
   22639       tree type_node = lang_hooks.types.type_for_mode (ptr_mode, 1);
   22640       int qual = ENCODE_QUAL_ADDR_SPACE (ix86_stack_protector_guard_reg);
   22641       tree type = build_qualified_type (type_node, qual);
   22642       tree t;
   22643 
   22644       if (OPTION_SET_P (ix86_stack_protector_guard_symbol_str))
   22645 	{
   22646 	  t = ix86_tls_stack_chk_guard_decl;
   22647 
   22648 	  if (t == NULL)
   22649 	    {
   22650 	      rtx x;
   22651 
   22652 	      t = build_decl
   22653 		(UNKNOWN_LOCATION, VAR_DECL,
   22654 		 get_identifier (ix86_stack_protector_guard_symbol_str),
   22655 		 type);
   22656 	      TREE_STATIC (t) = 1;
   22657 	      TREE_PUBLIC (t) = 1;
   22658 	      DECL_EXTERNAL (t) = 1;
   22659 	      TREE_USED (t) = 1;
   22660 	      TREE_THIS_VOLATILE (t) = 1;
   22661 	      DECL_ARTIFICIAL (t) = 1;
   22662 	      DECL_IGNORED_P (t) = 1;
   22663 
   22664 	      /* Do not share RTL as the declaration is visible outside of
   22665 		 current function.  */
   22666 	      x = DECL_RTL (t);
   22667 	      RTX_FLAG (x, used) = 1;
   22668 
   22669 	      ix86_tls_stack_chk_guard_decl = t;
   22670 	    }
   22671 	}
   22672       else
   22673 	{
   22674 	  tree asptrtype = build_pointer_type (type);
   22675 
   22676 	  t = build_int_cst (asptrtype, ix86_stack_protector_guard_offset);
   22677 	  t = build2 (MEM_REF, asptrtype, t,
   22678 		      build_int_cst (asptrtype, 0));
   22679 	  TREE_THIS_VOLATILE (t) = 1;
   22680 	}
   22681 
   22682       return t;
   22683     }
   22684 
   22685   return default_stack_protect_guard ();
   22686 }
   22687 
   22688 static bool
   22689 ix86_stack_protect_runtime_enabled_p (void)
   22690 {
   22691   /* Naked functions should not enable stack protector.  */
   22692   return !ix86_function_naked (current_function_decl);
   22693 }
   22694 
   22695 /* For 32-bit code we can save PIC register setup by using
   22696    __stack_chk_fail_local hidden function instead of calling
   22697    __stack_chk_fail directly.  64-bit code doesn't need to setup any PIC
   22698    register, so it is better to call __stack_chk_fail directly.  */
   22699 
   22700 static tree ATTRIBUTE_UNUSED
   22701 ix86_stack_protect_fail (void)
   22702 {
   22703   return TARGET_64BIT
   22704 	 ? default_external_stack_protect_fail ()
   22705 	 : default_hidden_stack_protect_fail ();
   22706 }
   22707 
   22708 /* Select a format to encode pointers in exception handling data.  CODE
   22709    is 0 for data, 1 for code labels, 2 for function pointers.  GLOBAL is
   22710    true if the symbol may be affected by dynamic relocations.
   22711 
   22712    ??? All x86 object file formats are capable of representing this.
   22713    After all, the relocation needed is the same as for the call insn.
   22714    Whether or not a particular assembler allows us to enter such, I
   22715    guess we'll have to see.  */
   22716 
   22717 int
   22718 asm_preferred_eh_data_format (int code, int global)
   22719 {
   22720   /* PE-COFF is effectively always -fPIC because of the .reloc section.  */
   22721   if (flag_pic || TARGET_PECOFF || !ix86_direct_extern_access)
   22722     {
   22723       int type = DW_EH_PE_sdata8;
   22724       if (ptr_mode == SImode
   22725 	  || ix86_cmodel == CM_SMALL_PIC
   22726 	  || (ix86_cmodel == CM_MEDIUM_PIC && (global || code)))
   22727 	type = DW_EH_PE_sdata4;
   22728       return (global ? DW_EH_PE_indirect : 0) | DW_EH_PE_pcrel | type;
   22729     }
   22730 
   22731   if (ix86_cmodel == CM_SMALL
   22732       || (ix86_cmodel == CM_MEDIUM && code))
   22733     return DW_EH_PE_udata4;
   22734 
   22735   return DW_EH_PE_absptr;
   22736 }
   22737 
   22738 /* Implement targetm.vectorize.builtin_vectorization_cost.  */
   22740 static int
   22741 ix86_builtin_vectorization_cost (enum vect_cost_for_stmt type_of_cost,
   22742                                  tree vectype, int)
   22743 {
   22744   bool fp = false;
   22745   machine_mode mode = TImode;
   22746   int index;
   22747   if (vectype != NULL)
   22748     {
   22749       fp = FLOAT_TYPE_P (vectype);
   22750       mode = TYPE_MODE (vectype);
   22751     }
   22752 
   22753   switch (type_of_cost)
   22754     {
   22755       case scalar_stmt:
   22756         return fp ? ix86_cost->addss : COSTS_N_INSNS (1);
   22757 
   22758       case scalar_load:
   22759 	/* load/store costs are relative to register move which is 2. Recompute
   22760  	   it to COSTS_N_INSNS so everything have same base.  */
   22761         return COSTS_N_INSNS (fp ? ix86_cost->sse_load[0]
   22762 			      : ix86_cost->int_load [2]) / 2;
   22763 
   22764       case scalar_store:
   22765         return COSTS_N_INSNS (fp ? ix86_cost->sse_store[0]
   22766 			      : ix86_cost->int_store [2]) / 2;
   22767 
   22768       case vector_stmt:
   22769         return ix86_vec_cost (mode,
   22770 			      fp ? ix86_cost->addss : ix86_cost->sse_op);
   22771 
   22772       case vector_load:
   22773 	index = sse_store_index (mode);
   22774 	/* See PR82713 - we may end up being called on non-vector type.  */
   22775 	if (index < 0)
   22776 	  index = 2;
   22777         return COSTS_N_INSNS (ix86_cost->sse_load[index]) / 2;
   22778 
   22779       case vector_store:
   22780 	index = sse_store_index (mode);
   22781 	/* See PR82713 - we may end up being called on non-vector type.  */
   22782 	if (index < 0)
   22783 	  index = 2;
   22784         return COSTS_N_INSNS (ix86_cost->sse_store[index]) / 2;
   22785 
   22786       case vec_to_scalar:
   22787       case scalar_to_vec:
   22788         return ix86_vec_cost (mode, ix86_cost->sse_op);
   22789 
   22790       /* We should have separate costs for unaligned loads and gather/scatter.
   22791 	 Do that incrementally.  */
   22792       case unaligned_load:
   22793 	index = sse_store_index (mode);
   22794 	/* See PR82713 - we may end up being called on non-vector type.  */
   22795 	if (index < 0)
   22796 	  index = 2;
   22797         return COSTS_N_INSNS (ix86_cost->sse_unaligned_load[index]) / 2;
   22798 
   22799       case unaligned_store:
   22800 	index = sse_store_index (mode);
   22801 	/* See PR82713 - we may end up being called on non-vector type.  */
   22802 	if (index < 0)
   22803 	  index = 2;
   22804         return COSTS_N_INSNS (ix86_cost->sse_unaligned_store[index]) / 2;
   22805 
   22806       case vector_gather_load:
   22807         return ix86_vec_cost (mode,
   22808 			      COSTS_N_INSNS
   22809 				 (ix86_cost->gather_static
   22810 				  + ix86_cost->gather_per_elt
   22811 				    * TYPE_VECTOR_SUBPARTS (vectype)) / 2);
   22812 
   22813       case vector_scatter_store:
   22814         return ix86_vec_cost (mode,
   22815 			      COSTS_N_INSNS
   22816 				 (ix86_cost->scatter_static
   22817 				  + ix86_cost->scatter_per_elt
   22818 				    * TYPE_VECTOR_SUBPARTS (vectype)) / 2);
   22819 
   22820       case cond_branch_taken:
   22821         return ix86_cost->cond_taken_branch_cost;
   22822 
   22823       case cond_branch_not_taken:
   22824         return ix86_cost->cond_not_taken_branch_cost;
   22825 
   22826       case vec_perm:
   22827       case vec_promote_demote:
   22828         return ix86_vec_cost (mode, ix86_cost->sse_op);
   22829 
   22830       case vec_construct:
   22831 	{
   22832 	  int n = TYPE_VECTOR_SUBPARTS (vectype);
   22833 	  /* N - 1 element inserts into an SSE vector, the possible
   22834 	     GPR -> XMM move is accounted for in add_stmt_cost.  */
   22835 	  if (GET_MODE_BITSIZE (mode) <= 128)
   22836 	    return (n - 1) * ix86_cost->sse_op;
   22837 	  /* One vinserti128 for combining two SSE vectors for AVX256.  */
   22838 	  else if (GET_MODE_BITSIZE (mode) == 256)
   22839 	    return ((n - 2) * ix86_cost->sse_op
   22840 		    + ix86_vec_cost (mode, ix86_cost->addss));
   22841 	  /* One vinserti64x4 and two vinserti128 for combining SSE
   22842 	     and AVX256 vectors to AVX512.  */
   22843 	  else if (GET_MODE_BITSIZE (mode) == 512)
   22844 	    return ((n - 4) * ix86_cost->sse_op
   22845 		    + 3 * ix86_vec_cost (mode, ix86_cost->addss));
   22846 	  gcc_unreachable ();
   22847 	}
   22848 
   22849       default:
   22850         gcc_unreachable ();
   22851     }
   22852 }
   22853 
   22854 
   22855 /* This function returns the calling abi specific va_list type node.
   22857    It returns  the FNDECL specific va_list type.  */
   22858 
   22859 static tree
   22860 ix86_fn_abi_va_list (tree fndecl)
   22861 {
   22862   if (!TARGET_64BIT)
   22863     return va_list_type_node;
   22864   gcc_assert (fndecl != NULL_TREE);
   22865 
   22866   if (ix86_function_abi ((const_tree) fndecl) == MS_ABI)
   22867     return ms_va_list_type_node;
   22868   else
   22869     return sysv_va_list_type_node;
   22870 }
   22871 
   22872 /* Returns the canonical va_list type specified by TYPE. If there
   22873    is no valid TYPE provided, it return NULL_TREE.  */
   22874 
   22875 static tree
   22876 ix86_canonical_va_list_type (tree type)
   22877 {
   22878   if (TARGET_64BIT)
   22879     {
   22880       if (lookup_attribute ("ms_abi va_list", TYPE_ATTRIBUTES (type)))
   22881 	return ms_va_list_type_node;
   22882 
   22883       if ((TREE_CODE (type) == ARRAY_TYPE
   22884 	   && integer_zerop (array_type_nelts (type)))
   22885 	  || POINTER_TYPE_P (type))
   22886 	{
   22887 	  tree elem_type = TREE_TYPE (type);
   22888 	  if (TREE_CODE (elem_type) == RECORD_TYPE
   22889 	      && lookup_attribute ("sysv_abi va_list",
   22890 				   TYPE_ATTRIBUTES (elem_type)))
   22891 	    return sysv_va_list_type_node;
   22892 	}
   22893 
   22894       return NULL_TREE;
   22895     }
   22896 
   22897   return std_canonical_va_list_type (type);
   22898 }
   22899 
   22900 /* Iterate through the target-specific builtin types for va_list.
   22901    IDX denotes the iterator, *PTREE is set to the result type of
   22902    the va_list builtin, and *PNAME to its internal type.
   22903    Returns zero if there is no element for this index, otherwise
   22904    IDX should be increased upon the next call.
   22905    Note, do not iterate a base builtin's name like __builtin_va_list.
   22906    Used from c_common_nodes_and_builtins.  */
   22907 
   22908 static int
   22909 ix86_enum_va_list (int idx, const char **pname, tree *ptree)
   22910 {
   22911   if (TARGET_64BIT)
   22912     {
   22913       switch (idx)
   22914 	{
   22915 	default:
   22916 	  break;
   22917 
   22918 	case 0:
   22919 	  *ptree = ms_va_list_type_node;
   22920 	  *pname = "__builtin_ms_va_list";
   22921 	  return 1;
   22922 
   22923 	case 1:
   22924 	  *ptree = sysv_va_list_type_node;
   22925 	  *pname = "__builtin_sysv_va_list";
   22926 	  return 1;
   22927 	}
   22928     }
   22929 
   22930   return 0;
   22931 }
   22932 
   22933 #undef TARGET_SCHED_DISPATCH
   22934 #define TARGET_SCHED_DISPATCH ix86_bd_has_dispatch
   22935 #undef TARGET_SCHED_DISPATCH_DO
   22936 #define TARGET_SCHED_DISPATCH_DO ix86_bd_do_dispatch
   22937 #undef TARGET_SCHED_REASSOCIATION_WIDTH
   22938 #define TARGET_SCHED_REASSOCIATION_WIDTH ix86_reassociation_width
   22939 #undef TARGET_SCHED_REORDER
   22940 #define TARGET_SCHED_REORDER ix86_atom_sched_reorder
   22941 #undef TARGET_SCHED_ADJUST_PRIORITY
   22942 #define TARGET_SCHED_ADJUST_PRIORITY ix86_adjust_priority
   22943 #undef TARGET_SCHED_DEPENDENCIES_EVALUATION_HOOK
   22944 #define TARGET_SCHED_DEPENDENCIES_EVALUATION_HOOK \
   22945   ix86_dependencies_evaluation_hook
   22946 
   22947 
   22948 /* Implementation of reassociation_width target hook used by
   22949    reassoc phase to identify parallelism level in reassociated
   22950    tree.  Statements tree_code is passed in OPC.  Arguments type
   22951    is passed in MODE.  */
   22952 
   22953 static int
   22954 ix86_reassociation_width (unsigned int op, machine_mode mode)
   22955 {
   22956   int width = 1;
   22957   /* Vector part.  */
   22958   if (VECTOR_MODE_P (mode))
   22959     {
   22960       int div = 1;
   22961       if (INTEGRAL_MODE_P (mode))
   22962 	width = ix86_cost->reassoc_vec_int;
   22963       else if (FLOAT_MODE_P (mode))
   22964 	width = ix86_cost->reassoc_vec_fp;
   22965 
   22966       if (width == 1)
   22967 	return 1;
   22968 
   22969       /* Znver1-4 Integer vector instructions execute in FP unit
   22970 	 and can execute 3 additions and one multiplication per cycle.  */
   22971       if ((ix86_tune == PROCESSOR_ZNVER1 || ix86_tune == PROCESSOR_ZNVER2
   22972 	   || ix86_tune == PROCESSOR_ZNVER3 || ix86_tune == PROCESSOR_ZNVER4)
   22973    	  && INTEGRAL_MODE_P (mode) && op != PLUS && op != MINUS)
   22974 	return 1;
   22975       /* Znver5 can do 2 integer multiplications per cycle with latency
   22976 	 of 3.  */
   22977       if (ix86_tune == PROCESSOR_ZNVER5
   22978 	  && INTEGRAL_MODE_P (mode) && op != PLUS && op != MINUS)
   22979 	width = 6;
   22980 
   22981       /* Account for targets that splits wide vectors into multiple parts.  */
   22982       if (TARGET_AVX512_SPLIT_REGS && GET_MODE_BITSIZE (mode) > 256)
   22983 	div = GET_MODE_BITSIZE (mode) / 256;
   22984       else if (TARGET_AVX256_SPLIT_REGS && GET_MODE_BITSIZE (mode) > 128)
   22985 	div = GET_MODE_BITSIZE (mode) / 128;
   22986       else if (TARGET_SSE_SPLIT_REGS && GET_MODE_BITSIZE (mode) > 64)
   22987 	div = GET_MODE_BITSIZE (mode) / 64;
   22988       width = (width + div - 1) / div;
   22989     }
   22990   /* Scalar part.  */
   22991   else if (INTEGRAL_MODE_P (mode))
   22992     width = ix86_cost->reassoc_int;
   22993   else if (FLOAT_MODE_P (mode))
   22994     width = ix86_cost->reassoc_fp;
   22995 
   22996   /* Avoid using too many registers in 32bit mode.  */
   22997   if (!TARGET_64BIT && width > 2)
   22998     width = 2;
   22999   return width;
   23000 }
   23001 
   23002 /* ??? No autovectorization into MMX or 3DNOW until we can reliably
   23003    place emms and femms instructions.  */
   23004 
   23005 static machine_mode
   23006 ix86_preferred_simd_mode (scalar_mode mode)
   23007 {
   23008   if (!TARGET_SSE)
   23009     return word_mode;
   23010 
   23011   switch (mode)
   23012     {
   23013     case E_QImode:
   23014       if (TARGET_AVX512BW && !TARGET_PREFER_AVX256)
   23015 	return V64QImode;
   23016       else if (TARGET_AVX && !TARGET_PREFER_AVX128)
   23017 	return V32QImode;
   23018       else
   23019 	return V16QImode;
   23020 
   23021     case E_HImode:
   23022       if (TARGET_AVX512BW && !TARGET_PREFER_AVX256)
   23023 	return V32HImode;
   23024       else if (TARGET_AVX && !TARGET_PREFER_AVX128)
   23025 	return V16HImode;
   23026       else
   23027 	return V8HImode;
   23028 
   23029     case E_SImode:
   23030       if (TARGET_AVX512F && !TARGET_PREFER_AVX256)
   23031 	return V16SImode;
   23032       else if (TARGET_AVX && !TARGET_PREFER_AVX128)
   23033 	return V8SImode;
   23034       else
   23035 	return V4SImode;
   23036 
   23037     case E_DImode:
   23038       if (TARGET_AVX512F && !TARGET_PREFER_AVX256)
   23039 	return V8DImode;
   23040       else if (TARGET_AVX && !TARGET_PREFER_AVX128)
   23041 	return V4DImode;
   23042       else
   23043 	return V2DImode;
   23044 
   23045     case E_HFmode:
   23046       if (TARGET_AVX512FP16)
   23047 	{
   23048 	  if (TARGET_AVX512VL)
   23049 	    {
   23050 	      if (TARGET_PREFER_AVX128)
   23051 		return V8HFmode;
   23052 	      else if (TARGET_PREFER_AVX256)
   23053 		return V16HFmode;
   23054 	    }
   23055 	  return V32HFmode;
   23056 	}
   23057       return word_mode;
   23058 
   23059     case E_SFmode:
   23060       if (TARGET_AVX512F && !TARGET_PREFER_AVX256)
   23061 	return V16SFmode;
   23062       else if (TARGET_AVX && !TARGET_PREFER_AVX128)
   23063 	return V8SFmode;
   23064       else
   23065 	return V4SFmode;
   23066 
   23067     case E_DFmode:
   23068       if (TARGET_AVX512F && !TARGET_PREFER_AVX256)
   23069 	return V8DFmode;
   23070       else if (TARGET_AVX && !TARGET_PREFER_AVX128)
   23071 	return V4DFmode;
   23072       else if (TARGET_SSE2)
   23073 	return V2DFmode;
   23074       /* FALLTHRU */
   23075 
   23076     default:
   23077       return word_mode;
   23078     }
   23079 }
   23080 
   23081 /* If AVX is enabled then try vectorizing with both 256bit and 128bit
   23082    vectors.  If AVX512F is enabled then try vectorizing with 512bit,
   23083    256bit and 128bit vectors.  */
   23084 
   23085 static unsigned int
   23086 ix86_autovectorize_vector_modes (vector_modes *modes, bool all)
   23087 {
   23088   if (TARGET_AVX512F && !TARGET_PREFER_AVX256)
   23089     {
   23090       modes->safe_push (V64QImode);
   23091       modes->safe_push (V32QImode);
   23092       modes->safe_push (V16QImode);
   23093     }
   23094   else if (TARGET_AVX512F && all)
   23095     {
   23096       modes->safe_push (V32QImode);
   23097       modes->safe_push (V16QImode);
   23098       modes->safe_push (V64QImode);
   23099     }
   23100   else if (TARGET_AVX && !TARGET_PREFER_AVX128)
   23101     {
   23102       modes->safe_push (V32QImode);
   23103       modes->safe_push (V16QImode);
   23104     }
   23105   else if (TARGET_AVX && all)
   23106     {
   23107       modes->safe_push (V16QImode);
   23108       modes->safe_push (V32QImode);
   23109     }
   23110   else if (TARGET_SSE2)
   23111     modes->safe_push (V16QImode);
   23112 
   23113   if (TARGET_MMX_WITH_SSE)
   23114     modes->safe_push (V8QImode);
   23115 
   23116   if (TARGET_SSE2)
   23117     modes->safe_push (V4QImode);
   23118 
   23119   return 0;
   23120 }
   23121 
   23122 /* Implemenation of targetm.vectorize.get_mask_mode.  */
   23123 
   23124 static opt_machine_mode
   23125 ix86_get_mask_mode (machine_mode data_mode)
   23126 {
   23127   unsigned vector_size = GET_MODE_SIZE (data_mode);
   23128   unsigned nunits = GET_MODE_NUNITS (data_mode);
   23129   unsigned elem_size = vector_size / nunits;
   23130 
   23131   /* Scalar mask case.  */
   23132   if ((TARGET_AVX512F && vector_size == 64)
   23133       || (TARGET_AVX512VL && (vector_size == 32 || vector_size == 16)))
   23134     {
   23135       if (elem_size == 4
   23136 	  || elem_size == 8
   23137 	  || (TARGET_AVX512BW && (elem_size == 1 || elem_size == 2)))
   23138 	return smallest_int_mode_for_size (nunits);
   23139     }
   23140 
   23141   scalar_int_mode elem_mode
   23142     = smallest_int_mode_for_size (elem_size * BITS_PER_UNIT);
   23143 
   23144   gcc_assert (elem_size * nunits == vector_size);
   23145 
   23146   return mode_for_vector (elem_mode, nunits);
   23147 }
   23148 
   23149 
   23150 
   23152 /* Return class of registers which could be used for pseudo of MODE
   23153    and of class RCLASS for spilling instead of memory.  Return NO_REGS
   23154    if it is not possible or non-profitable.  */
   23155 
   23156 /* Disabled due to PRs 70902, 71453, 71555, 71596 and 71657.  */
   23157 
   23158 static reg_class_t
   23159 ix86_spill_class (reg_class_t rclass, machine_mode mode)
   23160 {
   23161   if (0 && TARGET_GENERAL_REGS_SSE_SPILL
   23162       && TARGET_SSE2
   23163       && TARGET_INTER_UNIT_MOVES_TO_VEC
   23164       && TARGET_INTER_UNIT_MOVES_FROM_VEC
   23165       && (mode == SImode || (TARGET_64BIT && mode == DImode))
   23166       && INTEGER_CLASS_P (rclass))
   23167     return ALL_SSE_REGS;
   23168   return NO_REGS;
   23169 }
   23170 
   23171 /* Implement TARGET_MAX_NOCE_IFCVT_SEQ_COST.  Like the default implementation,
   23172    but returns a lower bound.  */
   23173 
   23174 static unsigned int
   23175 ix86_max_noce_ifcvt_seq_cost (edge e)
   23176 {
   23177   bool predictable_p = predictable_edge_p (e);
   23178   if (predictable_p)
   23179     {
   23180       if (OPTION_SET_P (param_max_rtl_if_conversion_predictable_cost))
   23181 	return param_max_rtl_if_conversion_predictable_cost;
   23182     }
   23183   else
   23184     {
   23185       if (OPTION_SET_P (param_max_rtl_if_conversion_unpredictable_cost))
   23186 	return param_max_rtl_if_conversion_unpredictable_cost;
   23187     }
   23188 
   23189   return BRANCH_COST (true, predictable_p) * COSTS_N_INSNS (2);
   23190 }
   23191 
   23192 /* Return true if SEQ is a good candidate as a replacement for the
   23193    if-convertible sequence described in IF_INFO.  */
   23194 
   23195 static bool
   23196 ix86_noce_conversion_profitable_p (rtx_insn *seq, struct noce_if_info *if_info)
   23197 {
   23198   if (TARGET_ONE_IF_CONV_INSN && if_info->speed_p)
   23199     {
   23200       int cmov_cnt = 0;
   23201       /* Punt if SEQ contains more than one CMOV or FCMOV instruction.
   23202 	 Maybe we should allow even more conditional moves as long as they
   23203 	 are used far enough not to stall the CPU, or also consider
   23204 	 IF_INFO->TEST_BB succ edge probabilities.  */
   23205       for (rtx_insn *insn = seq; insn; insn = NEXT_INSN (insn))
   23206 	{
   23207 	  rtx set = single_set (insn);
   23208 	  if (!set)
   23209 	    continue;
   23210 	  if (GET_CODE (SET_SRC (set)) != IF_THEN_ELSE)
   23211 	    continue;
   23212 	  rtx src = SET_SRC (set);
   23213 	  machine_mode mode = GET_MODE (src);
   23214 	  if (GET_MODE_CLASS (mode) != MODE_INT
   23215 	      && GET_MODE_CLASS (mode) != MODE_FLOAT)
   23216 	    continue;
   23217 	  if ((!REG_P (XEXP (src, 1)) && !MEM_P (XEXP (src, 1)))
   23218 	      || (!REG_P (XEXP (src, 2)) && !MEM_P (XEXP (src, 2))))
   23219 	    continue;
   23220 	  /* insn is CMOV or FCMOV.  */
   23221 	  if (++cmov_cnt > 1)
   23222 	    return false;
   23223 	}
   23224     }
   23225   return default_noce_conversion_profitable_p (seq, if_info);
   23226 }
   23227 
   23228 /* x86-specific vector costs.  */
   23229 class ix86_vector_costs : public vector_costs
   23230 {
   23231   using vector_costs::vector_costs;
   23232 
   23233   unsigned int add_stmt_cost (int count, vect_cost_for_stmt kind,
   23234 			      stmt_vec_info stmt_info, slp_tree node,
   23235 			      tree vectype, int misalign,
   23236 			      vect_cost_model_location where) override;
   23237 };
   23238 
   23239 /* Implement targetm.vectorize.create_costs.  */
   23240 
   23241 static vector_costs *
   23242 ix86_vectorize_create_costs (vec_info *vinfo, bool costing_for_scalar)
   23243 {
   23244   return new ix86_vector_costs (vinfo, costing_for_scalar);
   23245 }
   23246 
   23247 unsigned
   23248 ix86_vector_costs::add_stmt_cost (int count, vect_cost_for_stmt kind,
   23249 				  stmt_vec_info stmt_info, slp_tree node,
   23250 				  tree vectype, int misalign,
   23251 				  vect_cost_model_location where)
   23252 {
   23253   unsigned retval = 0;
   23254   bool scalar_p
   23255     = (kind == scalar_stmt || kind == scalar_load || kind == scalar_store);
   23256   int stmt_cost = - 1;
   23257 
   23258   bool fp = false;
   23259   machine_mode mode = scalar_p ? SImode : TImode;
   23260 
   23261   if (vectype != NULL)
   23262     {
   23263       fp = FLOAT_TYPE_P (vectype);
   23264       mode = TYPE_MODE (vectype);
   23265       if (scalar_p)
   23266 	mode = TYPE_MODE (TREE_TYPE (vectype));
   23267     }
   23268 
   23269   if ((kind == vector_stmt || kind == scalar_stmt)
   23270       && stmt_info
   23271       && stmt_info->stmt && gimple_code (stmt_info->stmt) == GIMPLE_ASSIGN)
   23272     {
   23273       tree_code subcode = gimple_assign_rhs_code (stmt_info->stmt);
   23274       /*machine_mode inner_mode = mode;
   23275       if (VECTOR_MODE_P (mode))
   23276 	inner_mode = GET_MODE_INNER (mode);*/
   23277 
   23278       switch (subcode)
   23279 	{
   23280 	case PLUS_EXPR:
   23281 	case POINTER_PLUS_EXPR:
   23282 	case MINUS_EXPR:
   23283 	  if (kind == scalar_stmt)
   23284 	    {
   23285 	      if (SSE_FLOAT_MODE_SSEMATH_OR_HF_P (mode))
   23286 		stmt_cost = ix86_cost->addss;
   23287 	      else if (X87_FLOAT_MODE_P (mode))
   23288 		stmt_cost = ix86_cost->fadd;
   23289 	      else
   23290 	        stmt_cost = ix86_cost->add;
   23291 	    }
   23292 	  else
   23293 	    stmt_cost = ix86_vec_cost (mode, fp ? ix86_cost->addss
   23294 				       : ix86_cost->sse_op);
   23295 	  break;
   23296 
   23297 	case MULT_EXPR:
   23298 	  /* For MULT_HIGHPART_EXPR, x86 only supports pmulhw,
   23299 	     take it as MULT_EXPR.  */
   23300 	case MULT_HIGHPART_EXPR:
   23301 	  stmt_cost = ix86_multiplication_cost (ix86_cost, mode);
   23302 	  break;
   23303 	  /* There's no direct instruction for WIDEN_MULT_EXPR,
   23304 	     take emulation into account.  */
   23305 	case WIDEN_MULT_EXPR:
   23306 	  stmt_cost = ix86_widen_mult_cost (ix86_cost, mode,
   23307 					    TYPE_UNSIGNED (vectype));
   23308 	  break;
   23309 
   23310 	case NEGATE_EXPR:
   23311 	  if (SSE_FLOAT_MODE_SSEMATH_OR_HF_P (mode))
   23312 	    stmt_cost = ix86_cost->sse_op;
   23313 	  else if (X87_FLOAT_MODE_P (mode))
   23314 	    stmt_cost = ix86_cost->fchs;
   23315 	  else if (VECTOR_MODE_P (mode))
   23316 	    stmt_cost = ix86_vec_cost (mode, ix86_cost->sse_op);
   23317 	  else
   23318 	    stmt_cost = ix86_cost->add;
   23319 	  break;
   23320 	case TRUNC_DIV_EXPR:
   23321 	case CEIL_DIV_EXPR:
   23322 	case FLOOR_DIV_EXPR:
   23323 	case ROUND_DIV_EXPR:
   23324 	case TRUNC_MOD_EXPR:
   23325 	case CEIL_MOD_EXPR:
   23326 	case FLOOR_MOD_EXPR:
   23327 	case RDIV_EXPR:
   23328 	case ROUND_MOD_EXPR:
   23329 	case EXACT_DIV_EXPR:
   23330 	  stmt_cost = ix86_division_cost (ix86_cost, mode);
   23331 	  break;
   23332 
   23333 	case RSHIFT_EXPR:
   23334 	case LSHIFT_EXPR:
   23335 	case LROTATE_EXPR:
   23336 	case RROTATE_EXPR:
   23337 	  {
   23338 	    tree op1 = gimple_assign_rhs1 (stmt_info->stmt);
   23339 	    tree op2 = gimple_assign_rhs2 (stmt_info->stmt);
   23340 	    stmt_cost = ix86_shift_rotate_cost
   23341 			   (ix86_cost,
   23342 			    (subcode == RSHIFT_EXPR
   23343 			     && !TYPE_UNSIGNED (TREE_TYPE (op1)))
   23344 			    ? ASHIFTRT : LSHIFTRT, mode,
   23345 		            TREE_CODE (op2) == INTEGER_CST,
   23346 			    cst_and_fits_in_hwi (op2)
   23347 			    ? int_cst_value (op2) : -1,
   23348 		            true, false, false, NULL, NULL);
   23349 	  }
   23350 	  break;
   23351 	case NOP_EXPR:
   23352 	  /* Only sign-conversions are free.  */
   23353 	  if (tree_nop_conversion_p
   23354 	        (TREE_TYPE (gimple_assign_lhs (stmt_info->stmt)),
   23355 		 TREE_TYPE (gimple_assign_rhs1 (stmt_info->stmt))))
   23356 	    stmt_cost = 0;
   23357 	  break;
   23358 
   23359 	case BIT_IOR_EXPR:
   23360 	case ABS_EXPR:
   23361 	case ABSU_EXPR:
   23362 	case MIN_EXPR:
   23363 	case MAX_EXPR:
   23364 	case BIT_XOR_EXPR:
   23365 	case BIT_AND_EXPR:
   23366 	case BIT_NOT_EXPR:
   23367 	  if (SSE_FLOAT_MODE_SSEMATH_OR_HF_P (mode))
   23368 	    stmt_cost = ix86_cost->sse_op;
   23369 	  else if (VECTOR_MODE_P (mode))
   23370 	    stmt_cost = ix86_vec_cost (mode, ix86_cost->sse_op);
   23371 	  else
   23372 	    stmt_cost = ix86_cost->add;
   23373 	  break;
   23374 	default:
   23375 	  break;
   23376 	}
   23377     }
   23378 
   23379   combined_fn cfn;
   23380   if ((kind == vector_stmt || kind == scalar_stmt)
   23381       && stmt_info
   23382       && stmt_info->stmt
   23383       && (cfn = gimple_call_combined_fn (stmt_info->stmt)) != CFN_LAST)
   23384     switch (cfn)
   23385       {
   23386       case CFN_FMA:
   23387 	stmt_cost = ix86_vec_cost (mode,
   23388 				   mode == SFmode ? ix86_cost->fmass
   23389 				   : ix86_cost->fmasd);
   23390 	break;
   23391       case CFN_MULH:
   23392 	stmt_cost = ix86_multiplication_cost (ix86_cost, mode);
   23393 	break;
   23394       default:
   23395 	break;
   23396       }
   23397 
   23398   /* If we do elementwise loads into a vector then we are bound by
   23399      latency and execution resources for the many scalar loads
   23400      (AGU and load ports).  Try to account for this by scaling the
   23401      construction cost by the number of elements involved.  */
   23402   if ((kind == vec_construct || kind == vec_to_scalar)
   23403       && stmt_info
   23404       && (STMT_VINFO_TYPE (stmt_info) == load_vec_info_type
   23405 	  || STMT_VINFO_TYPE (stmt_info) == store_vec_info_type)
   23406       && STMT_VINFO_MEMORY_ACCESS_TYPE (stmt_info) == VMAT_ELEMENTWISE
   23407       && TREE_CODE (DR_STEP (STMT_VINFO_DATA_REF (stmt_info))) != INTEGER_CST)
   23408     {
   23409       stmt_cost = ix86_builtin_vectorization_cost (kind, vectype, misalign);
   23410       stmt_cost *= (TYPE_VECTOR_SUBPARTS (vectype) + 1);
   23411     }
   23412   else if (kind == vec_construct
   23413 	   && node
   23414 	   && SLP_TREE_DEF_TYPE (node) == vect_external_def
   23415 	   && INTEGRAL_TYPE_P (TREE_TYPE (vectype)))
   23416     {
   23417       stmt_cost = ix86_builtin_vectorization_cost (kind, vectype, misalign);
   23418       unsigned i;
   23419       tree op;
   23420       FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_OPS (node), i, op)
   23421 	if (TREE_CODE (op) == SSA_NAME)
   23422 	  TREE_VISITED (op) = 0;
   23423       FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_OPS (node), i, op)
   23424 	{
   23425 	  if (TREE_CODE (op) != SSA_NAME
   23426 	      || TREE_VISITED (op))
   23427 	    continue;
   23428 	  TREE_VISITED (op) = 1;
   23429 	  gimple *def = SSA_NAME_DEF_STMT (op);
   23430 	  tree tem;
   23431 	  if (is_gimple_assign (def)
   23432 	      && CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (def))
   23433 	      && ((tem = gimple_assign_rhs1 (def)), true)
   23434 	      && TREE_CODE (tem) == SSA_NAME
   23435 	      /* A sign-change expands to nothing.  */
   23436 	      && tree_nop_conversion_p (TREE_TYPE (gimple_assign_lhs (def)),
   23437 					TREE_TYPE (tem)))
   23438 	    def = SSA_NAME_DEF_STMT (tem);
   23439 	  /* When the component is loaded from memory we can directly
   23440 	     move it to a vector register, otherwise we have to go
   23441 	     via a GPR or via vpinsr which involves similar cost.
   23442 	     Likewise with a BIT_FIELD_REF extracting from a vector
   23443 	     register we can hope to avoid using a GPR.  */
   23444 	  if (!is_gimple_assign (def)
   23445 	      || (!gimple_assign_load_p (def)
   23446 		  && (gimple_assign_rhs_code (def) != BIT_FIELD_REF
   23447 		      || !VECTOR_TYPE_P (TREE_TYPE
   23448 				(TREE_OPERAND (gimple_assign_rhs1 (def), 0))))))
   23449 	    stmt_cost += ix86_cost->sse_to_integer;
   23450 	}
   23451       FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_OPS (node), i, op)
   23452 	if (TREE_CODE (op) == SSA_NAME)
   23453 	  TREE_VISITED (op) = 0;
   23454     }
   23455   if (stmt_cost == -1)
   23456     stmt_cost = ix86_builtin_vectorization_cost (kind, vectype, misalign);
   23457 
   23458   /* Penalize DFmode vector operations for Bonnell.  */
   23459   if (TARGET_CPU_P (BONNELL) && kind == vector_stmt
   23460       && vectype && GET_MODE_INNER (TYPE_MODE (vectype)) == DFmode)
   23461     stmt_cost *= 5;  /* FIXME: The value here is arbitrary.  */
   23462 
   23463   /* Statements in an inner loop relative to the loop being
   23464      vectorized are weighted more heavily.  The value here is
   23465      arbitrary and could potentially be improved with analysis.  */
   23466   retval = adjust_cost_for_freq (stmt_info, where, count * stmt_cost);
   23467 
   23468   /* We need to multiply all vector stmt cost by 1.7 (estimated cost)
   23469      for Silvermont as it has out of order integer pipeline and can execute
   23470      2 scalar instruction per tick, but has in order SIMD pipeline.  */
   23471   if ((TARGET_CPU_P (SILVERMONT) || TARGET_CPU_P (GOLDMONT)
   23472        || TARGET_CPU_P (GOLDMONT_PLUS) || TARGET_CPU_P (INTEL))
   23473       && stmt_info && stmt_info->stmt)
   23474     {
   23475       tree lhs_op = gimple_get_lhs (stmt_info->stmt);
   23476       if (lhs_op && TREE_CODE (TREE_TYPE (lhs_op)) == INTEGER_TYPE)
   23477 	retval = (retval * 17) / 10;
   23478     }
   23479 
   23480   m_costs[where] += retval;
   23481 
   23482   return retval;
   23483 }
   23484 
   23485 /* Validate target specific memory model bits in VAL. */
   23486 
   23487 static unsigned HOST_WIDE_INT
   23488 ix86_memmodel_check (unsigned HOST_WIDE_INT val)
   23489 {
   23490   enum memmodel model = memmodel_from_int (val);
   23491   bool strong;
   23492 
   23493   if (val & ~(unsigned HOST_WIDE_INT)(IX86_HLE_ACQUIRE|IX86_HLE_RELEASE
   23494 				      |MEMMODEL_MASK)
   23495       || ((val & IX86_HLE_ACQUIRE) && (val & IX86_HLE_RELEASE)))
   23496     {
   23497       warning (OPT_Winvalid_memory_model,
   23498 	       "unknown architecture specific memory model");
   23499       return MEMMODEL_SEQ_CST;
   23500     }
   23501   strong = (is_mm_acq_rel (model) || is_mm_seq_cst (model));
   23502   if (val & IX86_HLE_ACQUIRE && !(is_mm_acquire (model) || strong))
   23503     {
   23504       warning (OPT_Winvalid_memory_model,
   23505 	      "%<HLE_ACQUIRE%> not used with %<ACQUIRE%> or stronger "
   23506 	       "memory model");
   23507       return MEMMODEL_SEQ_CST | IX86_HLE_ACQUIRE;
   23508     }
   23509   if (val & IX86_HLE_RELEASE && !(is_mm_release (model) || strong))
   23510     {
   23511       warning (OPT_Winvalid_memory_model,
   23512 	      "%<HLE_RELEASE%> not used with %<RELEASE%> or stronger "
   23513 	       "memory model");
   23514       return MEMMODEL_SEQ_CST | IX86_HLE_RELEASE;
   23515     }
   23516   return val;
   23517 }
   23518 
   23519 /* Set CLONEI->vecsize_mangle, CLONEI->mask_mode, CLONEI->vecsize_int,
   23520    CLONEI->vecsize_float and if CLONEI->simdlen is 0, also
   23521    CLONEI->simdlen.  Return 0 if SIMD clones shouldn't be emitted,
   23522    or number of vecsize_mangle variants that should be emitted.  */
   23523 
   23524 static int
   23525 ix86_simd_clone_compute_vecsize_and_simdlen (struct cgraph_node *node,
   23526 					     struct cgraph_simd_clone *clonei,
   23527 					     tree base_type, int num)
   23528 {
   23529   int ret = 1;
   23530 
   23531   if (clonei->simdlen
   23532       && (clonei->simdlen < 2
   23533 	  || clonei->simdlen > 1024
   23534 	  || (clonei->simdlen & (clonei->simdlen - 1)) != 0))
   23535     {
   23536       warning_at (DECL_SOURCE_LOCATION (node->decl), 0,
   23537 		  "unsupported simdlen %wd", clonei->simdlen.to_constant ());
   23538       return 0;
   23539     }
   23540 
   23541   tree ret_type = TREE_TYPE (TREE_TYPE (node->decl));
   23542   if (TREE_CODE (ret_type) != VOID_TYPE)
   23543     switch (TYPE_MODE (ret_type))
   23544       {
   23545       case E_QImode:
   23546       case E_HImode:
   23547       case E_SImode:
   23548       case E_DImode:
   23549       case E_SFmode:
   23550       case E_DFmode:
   23551       /* case E_SCmode: */
   23552       /* case E_DCmode: */
   23553 	if (!AGGREGATE_TYPE_P (ret_type))
   23554 	  break;
   23555 	/* FALLTHRU */
   23556       default:
   23557 	warning_at (DECL_SOURCE_LOCATION (node->decl), 0,
   23558 		    "unsupported return type %qT for simd", ret_type);
   23559 	return 0;
   23560       }
   23561 
   23562   tree t;
   23563   int i;
   23564   tree type_arg_types = TYPE_ARG_TYPES (TREE_TYPE (node->decl));
   23565   bool decl_arg_p = (node->definition || type_arg_types == NULL_TREE);
   23566 
   23567   for (t = (decl_arg_p ? DECL_ARGUMENTS (node->decl) : type_arg_types), i = 0;
   23568        t && t != void_list_node; t = TREE_CHAIN (t), i++)
   23569     {
   23570       tree arg_type = decl_arg_p ? TREE_TYPE (t) : TREE_VALUE (t);
   23571       switch (TYPE_MODE (arg_type))
   23572 	{
   23573 	case E_QImode:
   23574 	case E_HImode:
   23575 	case E_SImode:
   23576 	case E_DImode:
   23577 	case E_SFmode:
   23578 	case E_DFmode:
   23579 	/* case E_SCmode: */
   23580 	/* case E_DCmode: */
   23581 	  if (!AGGREGATE_TYPE_P (arg_type))
   23582 	    break;
   23583 	  /* FALLTHRU */
   23584 	default:
   23585 	  if (clonei->args[i].arg_type == SIMD_CLONE_ARG_TYPE_UNIFORM)
   23586 	    break;
   23587 	  warning_at (DECL_SOURCE_LOCATION (node->decl), 0,
   23588 		      "unsupported argument type %qT for simd", arg_type);
   23589 	  return 0;
   23590 	}
   23591     }
   23592 
   23593   if (!TREE_PUBLIC (node->decl))
   23594     {
   23595       /* If the function isn't exported, we can pick up just one ISA
   23596 	 for the clones.  */
   23597       if (TARGET_AVX512F)
   23598 	clonei->vecsize_mangle = 'e';
   23599       else if (TARGET_AVX2)
   23600 	clonei->vecsize_mangle = 'd';
   23601       else if (TARGET_AVX)
   23602 	clonei->vecsize_mangle = 'c';
   23603       else
   23604 	clonei->vecsize_mangle = 'b';
   23605       ret = 1;
   23606     }
   23607   else
   23608     {
   23609       clonei->vecsize_mangle = "bcde"[num];
   23610       ret = 4;
   23611     }
   23612   clonei->mask_mode = VOIDmode;
   23613   switch (clonei->vecsize_mangle)
   23614     {
   23615     case 'b':
   23616       clonei->vecsize_int = 128;
   23617       clonei->vecsize_float = 128;
   23618       break;
   23619     case 'c':
   23620       clonei->vecsize_int = 128;
   23621       clonei->vecsize_float = 256;
   23622       break;
   23623     case 'd':
   23624       clonei->vecsize_int = 256;
   23625       clonei->vecsize_float = 256;
   23626       break;
   23627     case 'e':
   23628       clonei->vecsize_int = 512;
   23629       clonei->vecsize_float = 512;
   23630       if (TYPE_MODE (base_type) == QImode)
   23631 	clonei->mask_mode = DImode;
   23632       else
   23633 	clonei->mask_mode = SImode;
   23634       break;
   23635     }
   23636   if (clonei->simdlen == 0)
   23637     {
   23638       if (SCALAR_INT_MODE_P (TYPE_MODE (base_type)))
   23639 	clonei->simdlen = clonei->vecsize_int;
   23640       else
   23641 	clonei->simdlen = clonei->vecsize_float;
   23642       clonei->simdlen = clonei->simdlen
   23643 			/ GET_MODE_BITSIZE (TYPE_MODE (base_type));
   23644     }
   23645   else if (clonei->simdlen > 16)
   23646     {
   23647       /* For compatibility with ICC, use the same upper bounds
   23648 	 for simdlen.  In particular, for CTYPE below, use the return type,
   23649 	 unless the function returns void, in that case use the characteristic
   23650 	 type.  If it is possible for given SIMDLEN to pass CTYPE value
   23651 	 in registers (8 [XYZ]MM* regs for 32-bit code, 16 [XYZ]MM* regs
   23652 	 for 64-bit code), accept that SIMDLEN, otherwise warn and don't
   23653 	 emit corresponding clone.  */
   23654       tree ctype = ret_type;
   23655       if (TREE_CODE (ret_type) == VOID_TYPE)
   23656 	ctype = base_type;
   23657       int cnt = GET_MODE_BITSIZE (TYPE_MODE (ctype)) * clonei->simdlen;
   23658       if (SCALAR_INT_MODE_P (TYPE_MODE (ctype)))
   23659 	cnt /= clonei->vecsize_int;
   23660       else
   23661 	cnt /= clonei->vecsize_float;
   23662       if (cnt > (TARGET_64BIT ? 16 : 8))
   23663 	{
   23664 	  warning_at (DECL_SOURCE_LOCATION (node->decl), 0,
   23665 		      "unsupported simdlen %wd",
   23666 		      clonei->simdlen.to_constant ());
   23667 	  return 0;
   23668 	}
   23669       }
   23670   return ret;
   23671 }
   23672 
   23673 /* If SIMD clone NODE can't be used in a vectorized loop
   23674    in current function, return -1, otherwise return a badness of using it
   23675    (0 if it is most desirable from vecsize_mangle point of view, 1
   23676    slightly less desirable, etc.).  */
   23677 
   23678 static int
   23679 ix86_simd_clone_usable (struct cgraph_node *node)
   23680 {
   23681   switch (node->simdclone->vecsize_mangle)
   23682     {
   23683     case 'b':
   23684       if (!TARGET_SSE2)
   23685 	return -1;
   23686       if (!TARGET_AVX)
   23687 	return 0;
   23688       return TARGET_AVX512F ? 3 : TARGET_AVX2 ? 2 : 1;
   23689     case 'c':
   23690       if (!TARGET_AVX)
   23691 	return -1;
   23692       return TARGET_AVX512F ? 2 : TARGET_AVX2 ? 1 : 0;
   23693     case 'd':
   23694       if (!TARGET_AVX2)
   23695 	return -1;
   23696       return TARGET_AVX512F ? 1 : 0;
   23697     case 'e':
   23698       if (!TARGET_AVX512F)
   23699 	return -1;
   23700       return 0;
   23701     default:
   23702       gcc_unreachable ();
   23703     }
   23704 }
   23705 
   23706 /* This function adjusts the unroll factor based on
   23707    the hardware capabilities. For ex, bdver3 has
   23708    a loop buffer which makes unrolling of smaller
   23709    loops less important. This function decides the
   23710    unroll factor using number of memory references
   23711    (value 32 is used) as a heuristic. */
   23712 
   23713 static unsigned
   23714 ix86_loop_unroll_adjust (unsigned nunroll, class loop *loop)
   23715 {
   23716   basic_block *bbs;
   23717   rtx_insn *insn;
   23718   unsigned i;
   23719   unsigned mem_count = 0;
   23720 
   23721   if (!TARGET_ADJUST_UNROLL)
   23722      return nunroll;
   23723 
   23724   /* Count the number of memory references within the loop body.
   23725      This value determines the unrolling factor for bdver3 and bdver4
   23726      architectures. */
   23727   subrtx_iterator::array_type array;
   23728   bbs = get_loop_body (loop);
   23729   for (i = 0; i < loop->num_nodes; i++)
   23730     FOR_BB_INSNS (bbs[i], insn)
   23731       if (NONDEBUG_INSN_P (insn))
   23732 	FOR_EACH_SUBRTX (iter, array, PATTERN (insn), NONCONST)
   23733 	  if (const_rtx x = *iter)
   23734 	    if (MEM_P (x))
   23735 	      {
   23736 		machine_mode mode = GET_MODE (x);
   23737 		unsigned int n_words = GET_MODE_SIZE (mode) / UNITS_PER_WORD;
   23738 		if (n_words > 4)
   23739 		  mem_count += 2;
   23740 		else
   23741 		  mem_count += 1;
   23742 	      }
   23743   free (bbs);
   23744 
   23745   if (mem_count && mem_count <=32)
   23746     return MIN (nunroll, 32 / mem_count);
   23747 
   23748   return nunroll;
   23749 }
   23750 
   23751 
   23752 /* Implement TARGET_FLOAT_EXCEPTIONS_ROUNDING_SUPPORTED_P.  */
   23753 
   23754 static bool
   23755 ix86_float_exceptions_rounding_supported_p (void)
   23756 {
   23757   /* For x87 floating point with standard excess precision handling,
   23758      there is no adddf3 pattern (since x87 floating point only has
   23759      XFmode operations) so the default hook implementation gets this
   23760      wrong.  */
   23761   return TARGET_80387 || (TARGET_SSE && TARGET_SSE_MATH);
   23762 }
   23763 
   23764 /* Implement TARGET_ATOMIC_ASSIGN_EXPAND_FENV.  */
   23765 
   23766 static void
   23767 ix86_atomic_assign_expand_fenv (tree *hold, tree *clear, tree *update)
   23768 {
   23769   if (!TARGET_80387 && !(TARGET_SSE && TARGET_SSE_MATH))
   23770     return;
   23771   tree exceptions_var = create_tmp_var_raw (integer_type_node);
   23772   if (TARGET_80387)
   23773     {
   23774       tree fenv_index_type = build_index_type (size_int (6));
   23775       tree fenv_type = build_array_type (unsigned_type_node, fenv_index_type);
   23776       tree fenv_var = create_tmp_var_raw (fenv_type);
   23777       TREE_ADDRESSABLE (fenv_var) = 1;
   23778       tree fenv_ptr = build_pointer_type (fenv_type);
   23779       tree fenv_addr = build1 (ADDR_EXPR, fenv_ptr, fenv_var);
   23780       fenv_addr = fold_convert (ptr_type_node, fenv_addr);
   23781       tree fnstenv = get_ix86_builtin (IX86_BUILTIN_FNSTENV);
   23782       tree fldenv = get_ix86_builtin (IX86_BUILTIN_FLDENV);
   23783       tree fnstsw = get_ix86_builtin (IX86_BUILTIN_FNSTSW);
   23784       tree fnclex = get_ix86_builtin (IX86_BUILTIN_FNCLEX);
   23785       tree hold_fnstenv = build_call_expr (fnstenv, 1, fenv_addr);
   23786       tree hold_fnclex = build_call_expr (fnclex, 0);
   23787       fenv_var = build4 (TARGET_EXPR, fenv_type, fenv_var, hold_fnstenv,
   23788 			 NULL_TREE, NULL_TREE);
   23789       *hold = build2 (COMPOUND_EXPR, void_type_node, fenv_var,
   23790 		      hold_fnclex);
   23791       *clear = build_call_expr (fnclex, 0);
   23792       tree sw_var = create_tmp_var_raw (short_unsigned_type_node);
   23793       tree fnstsw_call = build_call_expr (fnstsw, 0);
   23794       tree sw_mod = build4 (TARGET_EXPR, short_unsigned_type_node, sw_var,
   23795 			    fnstsw_call, NULL_TREE, NULL_TREE);
   23796       tree exceptions_x87 = fold_convert (integer_type_node, sw_var);
   23797       tree update_mod = build4 (TARGET_EXPR, integer_type_node,
   23798 				exceptions_var, exceptions_x87,
   23799 				NULL_TREE, NULL_TREE);
   23800       *update = build2 (COMPOUND_EXPR, integer_type_node,
   23801 			sw_mod, update_mod);
   23802       tree update_fldenv = build_call_expr (fldenv, 1, fenv_addr);
   23803       *update = build2 (COMPOUND_EXPR, void_type_node, *update, update_fldenv);
   23804     }
   23805   if (TARGET_SSE && TARGET_SSE_MATH)
   23806     {
   23807       tree mxcsr_orig_var = create_tmp_var_raw (unsigned_type_node);
   23808       tree mxcsr_mod_var = create_tmp_var_raw (unsigned_type_node);
   23809       tree stmxcsr = get_ix86_builtin (IX86_BUILTIN_STMXCSR);
   23810       tree ldmxcsr = get_ix86_builtin (IX86_BUILTIN_LDMXCSR);
   23811       tree stmxcsr_hold_call = build_call_expr (stmxcsr, 0);
   23812       tree hold_assign_orig = build4 (TARGET_EXPR, unsigned_type_node,
   23813 				      mxcsr_orig_var, stmxcsr_hold_call,
   23814 				      NULL_TREE, NULL_TREE);
   23815       tree hold_mod_val = build2 (BIT_IOR_EXPR, unsigned_type_node,
   23816 				  mxcsr_orig_var,
   23817 				  build_int_cst (unsigned_type_node, 0x1f80));
   23818       hold_mod_val = build2 (BIT_AND_EXPR, unsigned_type_node, hold_mod_val,
   23819 			     build_int_cst (unsigned_type_node, 0xffffffc0));
   23820       tree hold_assign_mod = build4 (TARGET_EXPR, unsigned_type_node,
   23821 				     mxcsr_mod_var, hold_mod_val,
   23822 				     NULL_TREE, NULL_TREE);
   23823       tree ldmxcsr_hold_call = build_call_expr (ldmxcsr, 1, mxcsr_mod_var);
   23824       tree hold_all = build2 (COMPOUND_EXPR, unsigned_type_node,
   23825 			      hold_assign_orig, hold_assign_mod);
   23826       hold_all = build2 (COMPOUND_EXPR, void_type_node, hold_all,
   23827 			 ldmxcsr_hold_call);
   23828       if (*hold)
   23829 	*hold = build2 (COMPOUND_EXPR, void_type_node, *hold, hold_all);
   23830       else
   23831 	*hold = hold_all;
   23832       tree ldmxcsr_clear_call = build_call_expr (ldmxcsr, 1, mxcsr_mod_var);
   23833       if (*clear)
   23834 	*clear = build2 (COMPOUND_EXPR, void_type_node, *clear,
   23835 			 ldmxcsr_clear_call);
   23836       else
   23837 	*clear = ldmxcsr_clear_call;
   23838       tree stxmcsr_update_call = build_call_expr (stmxcsr, 0);
   23839       tree exceptions_sse = fold_convert (integer_type_node,
   23840 					  stxmcsr_update_call);
   23841       if (*update)
   23842 	{
   23843 	  tree exceptions_mod = build2 (BIT_IOR_EXPR, integer_type_node,
   23844 					exceptions_var, exceptions_sse);
   23845 	  tree exceptions_assign = build2 (MODIFY_EXPR, integer_type_node,
   23846 					   exceptions_var, exceptions_mod);
   23847 	  *update = build2 (COMPOUND_EXPR, integer_type_node, *update,
   23848 			    exceptions_assign);
   23849 	}
   23850       else
   23851 	*update = build4 (TARGET_EXPR, integer_type_node, exceptions_var,
   23852 			  exceptions_sse, NULL_TREE, NULL_TREE);
   23853       tree ldmxcsr_update_call = build_call_expr (ldmxcsr, 1, mxcsr_orig_var);
   23854       *update = build2 (COMPOUND_EXPR, void_type_node, *update,
   23855 			ldmxcsr_update_call);
   23856     }
   23857   tree atomic_feraiseexcept
   23858     = builtin_decl_implicit (BUILT_IN_ATOMIC_FERAISEEXCEPT);
   23859   tree atomic_feraiseexcept_call = build_call_expr (atomic_feraiseexcept,
   23860 						    1, exceptions_var);
   23861   *update = build2 (COMPOUND_EXPR, void_type_node, *update,
   23862 		    atomic_feraiseexcept_call);
   23863 }
   23864 
   23865 #if !TARGET_MACHO && !TARGET_DLLIMPORT_DECL_ATTRIBUTES
   23866 /* For i386, common symbol is local only for non-PIE binaries.  For
   23867    x86-64, common symbol is local only for non-PIE binaries or linker
   23868    supports copy reloc in PIE binaries.   */
   23869 
   23870 static bool
   23871 ix86_binds_local_p (const_tree exp)
   23872 {
   23873   bool direct_extern_access
   23874     = (ix86_direct_extern_access
   23875        && !(VAR_OR_FUNCTION_DECL_P (exp)
   23876 	    && lookup_attribute ("nodirect_extern_access",
   23877 				 DECL_ATTRIBUTES (exp))));
   23878   if (!direct_extern_access)
   23879     ix86_has_no_direct_extern_access = true;
   23880   return default_binds_local_p_3 (exp, flag_shlib != 0, true,
   23881 				  direct_extern_access,
   23882 				  (direct_extern_access
   23883 				   && (!flag_pic
   23884 				       || (TARGET_64BIT
   23885 					   && HAVE_LD_PIE_COPYRELOC != 0))));
   23886 }
   23887 
   23888 /* If flag_pic or ix86_direct_extern_access is false, then neither
   23889    local nor global relocs should be placed in readonly memory.  */
   23890 
   23891 static int
   23892 ix86_reloc_rw_mask (void)
   23893 {
   23894   return (flag_pic || !ix86_direct_extern_access) ? 3 : 0;
   23895 }
   23896 #endif
   23897 
   23898 /* If MEM is in the form of [base+offset], extract the two parts
   23899    of address and set to BASE and OFFSET, otherwise return false.  */
   23900 
   23901 static bool
   23902 extract_base_offset_in_addr (rtx mem, rtx *base, rtx *offset)
   23903 {
   23904   rtx addr;
   23905 
   23906   gcc_assert (MEM_P (mem));
   23907 
   23908   addr = XEXP (mem, 0);
   23909 
   23910   if (GET_CODE (addr) == CONST)
   23911     addr = XEXP (addr, 0);
   23912 
   23913   if (REG_P (addr) || GET_CODE (addr) == SYMBOL_REF)
   23914     {
   23915       *base = addr;
   23916       *offset = const0_rtx;
   23917       return true;
   23918     }
   23919 
   23920   if (GET_CODE (addr) == PLUS
   23921       && (REG_P (XEXP (addr, 0))
   23922 	  || GET_CODE (XEXP (addr, 0)) == SYMBOL_REF)
   23923       && CONST_INT_P (XEXP (addr, 1)))
   23924     {
   23925       *base = XEXP (addr, 0);
   23926       *offset = XEXP (addr, 1);
   23927       return true;
   23928     }
   23929 
   23930   return false;
   23931 }
   23932 
   23933 /* Given OPERANDS of consecutive load/store, check if we can merge
   23934    them into move multiple.  LOAD is true if they are load instructions.
   23935    MODE is the mode of memory operands.  */
   23936 
   23937 bool
   23938 ix86_operands_ok_for_move_multiple (rtx *operands, bool load,
   23939 				    machine_mode mode)
   23940 {
   23941   HOST_WIDE_INT offval_1, offval_2, msize;
   23942   rtx mem_1, mem_2, reg_1, reg_2, base_1, base_2, offset_1, offset_2;
   23943 
   23944   if (load)
   23945     {
   23946       mem_1 = operands[1];
   23947       mem_2 = operands[3];
   23948       reg_1 = operands[0];
   23949       reg_2 = operands[2];
   23950     }
   23951   else
   23952     {
   23953       mem_1 = operands[0];
   23954       mem_2 = operands[2];
   23955       reg_1 = operands[1];
   23956       reg_2 = operands[3];
   23957     }
   23958 
   23959   gcc_assert (REG_P (reg_1) && REG_P (reg_2));
   23960 
   23961   if (REGNO (reg_1) != REGNO (reg_2))
   23962     return false;
   23963 
   23964   /* Check if the addresses are in the form of [base+offset].  */
   23965   if (!extract_base_offset_in_addr (mem_1, &base_1, &offset_1))
   23966     return false;
   23967   if (!extract_base_offset_in_addr (mem_2, &base_2, &offset_2))
   23968     return false;
   23969 
   23970   /* Check if the bases are the same.  */
   23971   if (!rtx_equal_p (base_1, base_2))
   23972     return false;
   23973 
   23974   offval_1 = INTVAL (offset_1);
   23975   offval_2 = INTVAL (offset_2);
   23976   msize = GET_MODE_SIZE (mode);
   23977   /* Check if mem_1 is adjacent to mem_2 and mem_1 has lower address.  */
   23978   if (offval_1 + msize != offval_2)
   23979     return false;
   23980 
   23981   return true;
   23982 }
   23983 
   23984 /* Implement the TARGET_OPTAB_SUPPORTED_P hook.  */
   23985 
   23986 static bool
   23987 ix86_optab_supported_p (int op, machine_mode mode1, machine_mode,
   23988 			optimization_type opt_type)
   23989 {
   23990   switch (op)
   23991     {
   23992     case asin_optab:
   23993     case acos_optab:
   23994     case log1p_optab:
   23995     case exp_optab:
   23996     case exp10_optab:
   23997     case exp2_optab:
   23998     case expm1_optab:
   23999     case ldexp_optab:
   24000     case scalb_optab:
   24001     case round_optab:
   24002       return opt_type == OPTIMIZE_FOR_SPEED;
   24003 
   24004     case rint_optab:
   24005       if (SSE_FLOAT_MODE_P (mode1)
   24006 	  && TARGET_SSE_MATH
   24007 	  && !flag_trapping_math
   24008 	  && !TARGET_SSE4_1
   24009 	  && mode1 != HFmode)
   24010 	return opt_type == OPTIMIZE_FOR_SPEED;
   24011       return true;
   24012 
   24013     case floor_optab:
   24014     case ceil_optab:
   24015     case btrunc_optab:
   24016       if (((SSE_FLOAT_MODE_P (mode1)
   24017 	    && TARGET_SSE_MATH
   24018 	    && TARGET_SSE4_1)
   24019 	   || mode1 == HFmode)
   24020 	  && !flag_trapping_math)
   24021 	return true;
   24022       return opt_type == OPTIMIZE_FOR_SPEED;
   24023 
   24024     case rsqrt_optab:
   24025       return opt_type == OPTIMIZE_FOR_SPEED && use_rsqrt_p (mode1);
   24026 
   24027     default:
   24028       return true;
   24029     }
   24030 }
   24031 
   24032 /* Implement the TARGET_GEN_MEMSET_SCRATCH_RTX hook.  Return a scratch
   24033    register in MODE for vector load and store.  */
   24034 
   24035 rtx
   24036 ix86_gen_scratch_sse_rtx (machine_mode mode)
   24037 {
   24038   return gen_reg_rtx (mode);
   24039 }
   24040 
   24041 /* Address space support.
   24042 
   24043    This is not "far pointers" in the 16-bit sense, but an easy way
   24044    to use %fs and %gs segment prefixes.  Therefore:
   24045 
   24046     (a) All address spaces have the same modes,
   24047     (b) All address spaces have the same addresss forms,
   24048     (c) While %fs and %gs are technically subsets of the generic
   24049         address space, they are probably not subsets of each other.
   24050     (d) Since we have no access to the segment base register values
   24051         without resorting to a system call, we cannot convert a
   24052         non-default address space to a default address space.
   24053         Therefore we do not claim %fs or %gs are subsets of generic.
   24054 
   24055    Therefore we can (mostly) use the default hooks.  */
   24056 
   24057 /* All use of segmentation is assumed to make address 0 valid.  */
   24058 
   24059 static bool
   24060 ix86_addr_space_zero_address_valid (addr_space_t as)
   24061 {
   24062   return as != ADDR_SPACE_GENERIC;
   24063 }
   24064 
   24065 static void
   24066 ix86_init_libfuncs (void)
   24067 {
   24068   if (TARGET_64BIT)
   24069     {
   24070       set_optab_libfunc (sdivmod_optab, TImode, "__divmodti4");
   24071       set_optab_libfunc (udivmod_optab, TImode, "__udivmodti4");
   24072     }
   24073   else
   24074     {
   24075       set_optab_libfunc (sdivmod_optab, DImode, "__divmoddi4");
   24076       set_optab_libfunc (udivmod_optab, DImode, "__udivmoddi4");
   24077     }
   24078 
   24079 #if TARGET_MACHO
   24080   darwin_rename_builtins ();
   24081 #endif
   24082 }
   24083 
   24084 /* Set the value of FLT_EVAL_METHOD in float.h.  When using only the
   24085    FPU, assume that the fpcw is set to extended precision; when using
   24086    only SSE, rounding is correct; when using both SSE and the FPU,
   24087    the rounding precision is indeterminate, since either may be chosen
   24088    apparently at random.  */
   24089 
   24090 static enum flt_eval_method
   24091 ix86_get_excess_precision (enum excess_precision_type type)
   24092 {
   24093   switch (type)
   24094     {
   24095       case EXCESS_PRECISION_TYPE_FAST:
   24096 	/* The fastest type to promote to will always be the native type,
   24097 	   whether that occurs with implicit excess precision or
   24098 	   otherwise.  */
   24099 	return TARGET_AVX512FP16
   24100 	       ? FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16
   24101 	       : FLT_EVAL_METHOD_PROMOTE_TO_FLOAT;
   24102       case EXCESS_PRECISION_TYPE_STANDARD:
   24103       case EXCESS_PRECISION_TYPE_IMPLICIT:
   24104 	/* Otherwise, the excess precision we want when we are
   24105 	   in a standards compliant mode, and the implicit precision we
   24106 	   provide would be identical were it not for the unpredictable
   24107 	   cases.  */
   24108 	if (TARGET_AVX512FP16 && TARGET_SSE_MATH)
   24109 	  return FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16;
   24110 	else if (!TARGET_80387)
   24111 	  return FLT_EVAL_METHOD_PROMOTE_TO_FLOAT;
   24112 	else if (!TARGET_MIX_SSE_I387)
   24113 	  {
   24114 	    if (!(TARGET_SSE && TARGET_SSE_MATH))
   24115 	      return FLT_EVAL_METHOD_PROMOTE_TO_LONG_DOUBLE;
   24116 	    else if (TARGET_SSE2)
   24117 	      return FLT_EVAL_METHOD_PROMOTE_TO_FLOAT;
   24118 	  }
   24119 
   24120 	/* If we are in standards compliant mode, but we know we will
   24121 	   calculate in unpredictable precision, return
   24122 	   FLT_EVAL_METHOD_FLOAT.  There is no reason to introduce explicit
   24123 	   excess precision if the target can't guarantee it will honor
   24124 	   it.  */
   24125 	return (type == EXCESS_PRECISION_TYPE_STANDARD
   24126 		? FLT_EVAL_METHOD_PROMOTE_TO_FLOAT
   24127 		: FLT_EVAL_METHOD_UNPREDICTABLE);
   24128       case EXCESS_PRECISION_TYPE_FLOAT16:
   24129 	if (TARGET_80387
   24130 	    && !(TARGET_SSE_MATH && TARGET_SSE))
   24131 	  error ("%<-fexcess-precision=16%> is not compatible with %<-mfpmath=387%>");
   24132 	return FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16;
   24133       default:
   24134 	gcc_unreachable ();
   24135     }
   24136 
   24137   return FLT_EVAL_METHOD_UNPREDICTABLE;
   24138 }
   24139 
   24140 /* Implement PUSH_ROUNDING.  On 386, we have pushw instruction that
   24141    decrements by exactly 2 no matter what the position was, there is no pushb.
   24142 
   24143    But as CIE data alignment factor on this arch is -4 for 32bit targets
   24144    and -8 for 64bit targets, we need to make sure all stack pointer adjustments
   24145    are in multiple of 4 for 32bit targets and 8 for 64bit targets.  */
   24146 
   24147 poly_int64
   24148 ix86_push_rounding (poly_int64 bytes)
   24149 {
   24150   return ROUND_UP (bytes, UNITS_PER_WORD);
   24151 }
   24152 
   24153 /* Target-specific selftests.  */
   24154 
   24155 #if CHECKING_P
   24156 
   24157 namespace selftest {
   24158 
   24159 /* Verify that hard regs are dumped as expected (in compact mode).  */
   24160 
   24161 static void
   24162 ix86_test_dumping_hard_regs ()
   24163 {
   24164   ASSERT_RTL_DUMP_EQ ("(reg:SI ax)", gen_raw_REG (SImode, 0));
   24165   ASSERT_RTL_DUMP_EQ ("(reg:SI dx)", gen_raw_REG (SImode, 1));
   24166 }
   24167 
   24168 /* Test dumping an insn with repeated references to the same SCRATCH,
   24169    to verify the rtx_reuse code.  */
   24170 
   24171 static void
   24172 ix86_test_dumping_memory_blockage ()
   24173 {
   24174   set_new_first_and_last_insn (NULL, NULL);
   24175 
   24176   rtx pat = gen_memory_blockage ();
   24177   rtx_reuse_manager r;
   24178   r.preprocess (pat);
   24179 
   24180   /* Verify that the repeated references to the SCRATCH show use
   24181      reuse IDS.  The first should be prefixed with a reuse ID,
   24182      and the second should be dumped as a "reuse_rtx" of that ID.
   24183      The expected string assumes Pmode == DImode.  */
   24184   if (Pmode == DImode)
   24185     ASSERT_RTL_DUMP_EQ_WITH_REUSE
   24186       ("(cinsn 1 (set (mem/v:BLK (0|scratch:DI) [0  A8])\n"
   24187        "        (unspec:BLK [\n"
   24188        "                (mem/v:BLK (reuse_rtx 0) [0  A8])\n"
   24189        "            ] UNSPEC_MEMORY_BLOCKAGE)))\n", pat, &r);
   24190 }
   24191 
   24192 /* Verify loading an RTL dump; specifically a dump of copying
   24193    a param on x86_64 from a hard reg into the frame.
   24194    This test is target-specific since the dump contains target-specific
   24195    hard reg names.  */
   24196 
   24197 static void
   24198 ix86_test_loading_dump_fragment_1 ()
   24199 {
   24200   rtl_dump_test t (SELFTEST_LOCATION,
   24201 		   locate_file ("x86_64/copy-hard-reg-into-frame.rtl"));
   24202 
   24203   rtx_insn *insn = get_insn_by_uid (1);
   24204 
   24205   /* The block structure and indentation here is purely for
   24206      readability; it mirrors the structure of the rtx.  */
   24207   tree mem_expr;
   24208   {
   24209     rtx pat = PATTERN (insn);
   24210     ASSERT_EQ (SET, GET_CODE (pat));
   24211     {
   24212       rtx dest = SET_DEST (pat);
   24213       ASSERT_EQ (MEM, GET_CODE (dest));
   24214       /* Verify the "/c" was parsed.  */
   24215       ASSERT_TRUE (RTX_FLAG (dest, call));
   24216       ASSERT_EQ (SImode, GET_MODE (dest));
   24217       {
   24218 	rtx addr = XEXP (dest, 0);
   24219 	ASSERT_EQ (PLUS, GET_CODE (addr));
   24220 	ASSERT_EQ (DImode, GET_MODE (addr));
   24221 	{
   24222 	  rtx lhs = XEXP (addr, 0);
   24223 	  /* Verify that the "frame" REG was consolidated.  */
   24224 	  ASSERT_RTX_PTR_EQ (frame_pointer_rtx, lhs);
   24225 	}
   24226 	{
   24227 	  rtx rhs = XEXP (addr, 1);
   24228 	  ASSERT_EQ (CONST_INT, GET_CODE (rhs));
   24229 	  ASSERT_EQ (-4, INTVAL (rhs));
   24230 	}
   24231       }
   24232       /* Verify the "[1 i+0 S4 A32]" was parsed.  */
   24233       ASSERT_EQ (1, MEM_ALIAS_SET (dest));
   24234       /* "i" should have been handled by synthesizing a global int
   24235 	 variable named "i".  */
   24236       mem_expr = MEM_EXPR (dest);
   24237       ASSERT_NE (mem_expr, NULL);
   24238       ASSERT_EQ (VAR_DECL, TREE_CODE (mem_expr));
   24239       ASSERT_EQ (integer_type_node, TREE_TYPE (mem_expr));
   24240       ASSERT_EQ (IDENTIFIER_NODE, TREE_CODE (DECL_NAME (mem_expr)));
   24241       ASSERT_STREQ ("i", IDENTIFIER_POINTER (DECL_NAME (mem_expr)));
   24242       /* "+0".  */
   24243       ASSERT_TRUE (MEM_OFFSET_KNOWN_P (dest));
   24244       ASSERT_EQ (0, MEM_OFFSET (dest));
   24245       /* "S4".  */
   24246       ASSERT_EQ (4, MEM_SIZE (dest));
   24247       /* "A32.  */
   24248       ASSERT_EQ (32, MEM_ALIGN (dest));
   24249     }
   24250     {
   24251       rtx src = SET_SRC (pat);
   24252       ASSERT_EQ (REG, GET_CODE (src));
   24253       ASSERT_EQ (SImode, GET_MODE (src));
   24254       ASSERT_EQ (5, REGNO (src));
   24255       tree reg_expr = REG_EXPR (src);
   24256       /* "i" here should point to the same var as for the MEM_EXPR.  */
   24257       ASSERT_EQ (reg_expr, mem_expr);
   24258     }
   24259   }
   24260 }
   24261 
   24262 /* Verify that the RTL loader copes with a call_insn dump.
   24263    This test is target-specific since the dump contains a target-specific
   24264    hard reg name.  */
   24265 
   24266 static void
   24267 ix86_test_loading_call_insn ()
   24268 {
   24269   /* The test dump includes register "xmm0", where requires TARGET_SSE
   24270      to exist.  */
   24271   if (!TARGET_SSE)
   24272     return;
   24273 
   24274   rtl_dump_test t (SELFTEST_LOCATION, locate_file ("x86_64/call-insn.rtl"));
   24275 
   24276   rtx_insn *insn = get_insns ();
   24277   ASSERT_EQ (CALL_INSN, GET_CODE (insn));
   24278 
   24279   /* "/j".  */
   24280   ASSERT_TRUE (RTX_FLAG (insn, jump));
   24281 
   24282   rtx pat = PATTERN (insn);
   24283   ASSERT_EQ (CALL, GET_CODE (SET_SRC (pat)));
   24284 
   24285   /* Verify REG_NOTES.  */
   24286   {
   24287     /* "(expr_list:REG_CALL_DECL".   */
   24288     ASSERT_EQ (EXPR_LIST, GET_CODE (REG_NOTES (insn)));
   24289     rtx_expr_list *note0 = as_a <rtx_expr_list *> (REG_NOTES (insn));
   24290     ASSERT_EQ (REG_CALL_DECL, REG_NOTE_KIND (note0));
   24291 
   24292     /* "(expr_list:REG_EH_REGION (const_int 0 [0])".  */
   24293     rtx_expr_list *note1 = note0->next ();
   24294     ASSERT_EQ (REG_EH_REGION, REG_NOTE_KIND (note1));
   24295 
   24296     ASSERT_EQ (NULL, note1->next ());
   24297   }
   24298 
   24299   /* Verify CALL_INSN_FUNCTION_USAGE.  */
   24300   {
   24301     /* "(expr_list:DF (use (reg:DF 21 xmm0))".  */
   24302     rtx_expr_list *usage
   24303       = as_a <rtx_expr_list *> (CALL_INSN_FUNCTION_USAGE (insn));
   24304     ASSERT_EQ (EXPR_LIST, GET_CODE (usage));
   24305     ASSERT_EQ (DFmode, GET_MODE (usage));
   24306     ASSERT_EQ (USE, GET_CODE (usage->element ()));
   24307     ASSERT_EQ (NULL, usage->next ());
   24308   }
   24309 }
   24310 
   24311 /* Verify that the RTL loader copes a dump from print_rtx_function.
   24312    This test is target-specific since the dump contains target-specific
   24313    hard reg names.  */
   24314 
   24315 static void
   24316 ix86_test_loading_full_dump ()
   24317 {
   24318   rtl_dump_test t (SELFTEST_LOCATION, locate_file ("x86_64/times-two.rtl"));
   24319 
   24320   ASSERT_STREQ ("times_two", IDENTIFIER_POINTER (DECL_NAME (cfun->decl)));
   24321 
   24322   rtx_insn *insn_1 = get_insn_by_uid (1);
   24323   ASSERT_EQ (NOTE, GET_CODE (insn_1));
   24324 
   24325   rtx_insn *insn_7 = get_insn_by_uid (7);
   24326   ASSERT_EQ (INSN, GET_CODE (insn_7));
   24327   ASSERT_EQ (PARALLEL, GET_CODE (PATTERN (insn_7)));
   24328 
   24329   rtx_insn *insn_15 = get_insn_by_uid (15);
   24330   ASSERT_EQ (INSN, GET_CODE (insn_15));
   24331   ASSERT_EQ (USE, GET_CODE (PATTERN (insn_15)));
   24332 
   24333   /* Verify crtl->return_rtx.  */
   24334   ASSERT_EQ (REG, GET_CODE (crtl->return_rtx));
   24335   ASSERT_EQ (0, REGNO (crtl->return_rtx));
   24336   ASSERT_EQ (SImode, GET_MODE (crtl->return_rtx));
   24337 }
   24338 
   24339 /* Verify that the RTL loader copes with UNSPEC and UNSPEC_VOLATILE insns.
   24340    In particular, verify that it correctly loads the 2nd operand.
   24341    This test is target-specific since these are machine-specific
   24342    operands (and enums).  */
   24343 
   24344 static void
   24345 ix86_test_loading_unspec ()
   24346 {
   24347   rtl_dump_test t (SELFTEST_LOCATION, locate_file ("x86_64/unspec.rtl"));
   24348 
   24349   ASSERT_STREQ ("test_unspec", IDENTIFIER_POINTER (DECL_NAME (cfun->decl)));
   24350 
   24351   ASSERT_TRUE (cfun);
   24352 
   24353   /* Test of an UNSPEC.  */
   24354    rtx_insn *insn = get_insns ();
   24355   ASSERT_EQ (INSN, GET_CODE (insn));
   24356   rtx set = single_set (insn);
   24357   ASSERT_NE (NULL, set);
   24358   rtx dst = SET_DEST (set);
   24359   ASSERT_EQ (MEM, GET_CODE (dst));
   24360   rtx src = SET_SRC (set);
   24361   ASSERT_EQ (UNSPEC, GET_CODE (src));
   24362   ASSERT_EQ (BLKmode, GET_MODE (src));
   24363   ASSERT_EQ (UNSPEC_MEMORY_BLOCKAGE, XINT (src, 1));
   24364 
   24365   rtx v0 = XVECEXP (src, 0, 0);
   24366 
   24367   /* Verify that the two uses of the first SCRATCH have pointer
   24368      equality.  */
   24369   rtx scratch_a = XEXP (dst, 0);
   24370   ASSERT_EQ (SCRATCH, GET_CODE (scratch_a));
   24371 
   24372   rtx scratch_b = XEXP (v0, 0);
   24373   ASSERT_EQ (SCRATCH, GET_CODE (scratch_b));
   24374 
   24375   ASSERT_EQ (scratch_a, scratch_b);
   24376 
   24377   /* Verify that the two mems are thus treated as equal.  */
   24378   ASSERT_TRUE (rtx_equal_p (dst, v0));
   24379 
   24380   /* Verify that the insn is recognized.  */
   24381   ASSERT_NE(-1, recog_memoized (insn));
   24382 
   24383   /* Test of an UNSPEC_VOLATILE, which has its own enum values.  */
   24384   insn = NEXT_INSN (insn);
   24385   ASSERT_EQ (INSN, GET_CODE (insn));
   24386 
   24387   set = single_set (insn);
   24388   ASSERT_NE (NULL, set);
   24389 
   24390   src = SET_SRC (set);
   24391   ASSERT_EQ (UNSPEC_VOLATILE, GET_CODE (src));
   24392   ASSERT_EQ (UNSPECV_RDTSCP, XINT (src, 1));
   24393 }
   24394 
   24395 /* Run all target-specific selftests.  */
   24396 
   24397 static void
   24398 ix86_run_selftests (void)
   24399 {
   24400   ix86_test_dumping_hard_regs ();
   24401   ix86_test_dumping_memory_blockage ();
   24402 
   24403   /* Various tests of loading RTL dumps, here because they contain
   24404      ix86-isms (e.g. names of hard regs).  */
   24405   ix86_test_loading_dump_fragment_1 ();
   24406   ix86_test_loading_call_insn ();
   24407   ix86_test_loading_full_dump ();
   24408   ix86_test_loading_unspec ();
   24409 }
   24410 
   24411 } // namespace selftest
   24412 
   24413 #endif /* CHECKING_P */
   24414 
   24415 /* Initialize the GCC target structure.  */
   24416 #undef TARGET_RETURN_IN_MEMORY
   24417 #define TARGET_RETURN_IN_MEMORY ix86_return_in_memory
   24418 
   24419 #undef TARGET_LEGITIMIZE_ADDRESS
   24420 #define TARGET_LEGITIMIZE_ADDRESS ix86_legitimize_address
   24421 
   24422 #undef TARGET_ATTRIBUTE_TABLE
   24423 #define TARGET_ATTRIBUTE_TABLE ix86_attribute_table
   24424 #undef TARGET_FUNCTION_ATTRIBUTE_INLINABLE_P
   24425 #define TARGET_FUNCTION_ATTRIBUTE_INLINABLE_P hook_bool_const_tree_true
   24426 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
   24427 #  undef TARGET_MERGE_DECL_ATTRIBUTES
   24428 #  define TARGET_MERGE_DECL_ATTRIBUTES merge_dllimport_decl_attributes
   24429 #endif
   24430 
   24431 #undef TARGET_COMP_TYPE_ATTRIBUTES
   24432 #define TARGET_COMP_TYPE_ATTRIBUTES ix86_comp_type_attributes
   24433 
   24434 #undef TARGET_INIT_BUILTINS
   24435 #define TARGET_INIT_BUILTINS ix86_init_builtins
   24436 #undef TARGET_BUILTIN_DECL
   24437 #define TARGET_BUILTIN_DECL ix86_builtin_decl
   24438 #undef TARGET_EXPAND_BUILTIN
   24439 #define TARGET_EXPAND_BUILTIN ix86_expand_builtin
   24440 
   24441 #undef TARGET_VECTORIZE_BUILTIN_VECTORIZED_FUNCTION
   24442 #define TARGET_VECTORIZE_BUILTIN_VECTORIZED_FUNCTION \
   24443   ix86_builtin_vectorized_function
   24444 
   24445 #undef TARGET_VECTORIZE_BUILTIN_GATHER
   24446 #define TARGET_VECTORIZE_BUILTIN_GATHER ix86_vectorize_builtin_gather
   24447 
   24448 #undef TARGET_VECTORIZE_BUILTIN_SCATTER
   24449 #define TARGET_VECTORIZE_BUILTIN_SCATTER ix86_vectorize_builtin_scatter
   24450 
   24451 #undef TARGET_BUILTIN_RECIPROCAL
   24452 #define TARGET_BUILTIN_RECIPROCAL ix86_builtin_reciprocal
   24453 
   24454 #undef TARGET_ASM_FUNCTION_EPILOGUE
   24455 #define TARGET_ASM_FUNCTION_EPILOGUE ix86_output_function_epilogue
   24456 
   24457 #undef TARGET_ASM_PRINT_PATCHABLE_FUNCTION_ENTRY
   24458 #define TARGET_ASM_PRINT_PATCHABLE_FUNCTION_ENTRY \
   24459   ix86_print_patchable_function_entry
   24460 
   24461 #undef TARGET_ENCODE_SECTION_INFO
   24462 #ifndef SUBTARGET_ENCODE_SECTION_INFO
   24463 #define TARGET_ENCODE_SECTION_INFO ix86_encode_section_info
   24464 #else
   24465 #define TARGET_ENCODE_SECTION_INFO SUBTARGET_ENCODE_SECTION_INFO
   24466 #endif
   24467 
   24468 #undef TARGET_ASM_OPEN_PAREN
   24469 #define TARGET_ASM_OPEN_PAREN ""
   24470 #undef TARGET_ASM_CLOSE_PAREN
   24471 #define TARGET_ASM_CLOSE_PAREN ""
   24472 
   24473 #undef TARGET_ASM_BYTE_OP
   24474 #define TARGET_ASM_BYTE_OP ASM_BYTE
   24475 
   24476 #undef TARGET_ASM_ALIGNED_HI_OP
   24477 #define TARGET_ASM_ALIGNED_HI_OP ASM_SHORT
   24478 #undef TARGET_ASM_ALIGNED_SI_OP
   24479 #define TARGET_ASM_ALIGNED_SI_OP ASM_LONG
   24480 #ifdef ASM_QUAD
   24481 #undef TARGET_ASM_ALIGNED_DI_OP
   24482 #define TARGET_ASM_ALIGNED_DI_OP ASM_QUAD
   24483 #endif
   24484 
   24485 #undef TARGET_PROFILE_BEFORE_PROLOGUE
   24486 #define TARGET_PROFILE_BEFORE_PROLOGUE ix86_profile_before_prologue
   24487 
   24488 #undef TARGET_MANGLE_DECL_ASSEMBLER_NAME
   24489 #define TARGET_MANGLE_DECL_ASSEMBLER_NAME ix86_mangle_decl_assembler_name
   24490 
   24491 #undef TARGET_ASM_UNALIGNED_HI_OP
   24492 #define TARGET_ASM_UNALIGNED_HI_OP TARGET_ASM_ALIGNED_HI_OP
   24493 #undef TARGET_ASM_UNALIGNED_SI_OP
   24494 #define TARGET_ASM_UNALIGNED_SI_OP TARGET_ASM_ALIGNED_SI_OP
   24495 #undef TARGET_ASM_UNALIGNED_DI_OP
   24496 #define TARGET_ASM_UNALIGNED_DI_OP TARGET_ASM_ALIGNED_DI_OP
   24497 
   24498 #undef TARGET_PRINT_OPERAND
   24499 #define TARGET_PRINT_OPERAND ix86_print_operand
   24500 #undef TARGET_PRINT_OPERAND_ADDRESS
   24501 #define TARGET_PRINT_OPERAND_ADDRESS ix86_print_operand_address
   24502 #undef TARGET_PRINT_OPERAND_PUNCT_VALID_P
   24503 #define TARGET_PRINT_OPERAND_PUNCT_VALID_P ix86_print_operand_punct_valid_p
   24504 #undef TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA
   24505 #define TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA i386_asm_output_addr_const_extra
   24506 
   24507 #undef TARGET_SCHED_INIT_GLOBAL
   24508 #define TARGET_SCHED_INIT_GLOBAL ix86_sched_init_global
   24509 #undef TARGET_SCHED_ADJUST_COST
   24510 #define TARGET_SCHED_ADJUST_COST ix86_adjust_cost
   24511 #undef TARGET_SCHED_ISSUE_RATE
   24512 #define TARGET_SCHED_ISSUE_RATE ix86_issue_rate
   24513 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
   24514 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD \
   24515   ia32_multipass_dfa_lookahead
   24516 #undef TARGET_SCHED_MACRO_FUSION_P
   24517 #define TARGET_SCHED_MACRO_FUSION_P ix86_macro_fusion_p
   24518 #undef TARGET_SCHED_MACRO_FUSION_PAIR_P
   24519 #define TARGET_SCHED_MACRO_FUSION_PAIR_P ix86_macro_fusion_pair_p
   24520 
   24521 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
   24522 #define TARGET_FUNCTION_OK_FOR_SIBCALL ix86_function_ok_for_sibcall
   24523 
   24524 #undef TARGET_MEMMODEL_CHECK
   24525 #define TARGET_MEMMODEL_CHECK ix86_memmodel_check
   24526 
   24527 #undef TARGET_ATOMIC_ASSIGN_EXPAND_FENV
   24528 #define TARGET_ATOMIC_ASSIGN_EXPAND_FENV ix86_atomic_assign_expand_fenv
   24529 
   24530 #ifdef HAVE_AS_TLS
   24531 #undef TARGET_HAVE_TLS
   24532 #define TARGET_HAVE_TLS true
   24533 #endif
   24534 #undef TARGET_CANNOT_FORCE_CONST_MEM
   24535 #define TARGET_CANNOT_FORCE_CONST_MEM ix86_cannot_force_const_mem
   24536 #undef TARGET_USE_BLOCKS_FOR_CONSTANT_P
   24537 #define TARGET_USE_BLOCKS_FOR_CONSTANT_P hook_bool_mode_const_rtx_true
   24538 
   24539 #undef TARGET_DELEGITIMIZE_ADDRESS
   24540 #define TARGET_DELEGITIMIZE_ADDRESS ix86_delegitimize_address
   24541 
   24542 #undef TARGET_CONST_NOT_OK_FOR_DEBUG_P
   24543 #define TARGET_CONST_NOT_OK_FOR_DEBUG_P ix86_const_not_ok_for_debug_p
   24544 
   24545 #undef TARGET_MS_BITFIELD_LAYOUT_P
   24546 #define TARGET_MS_BITFIELD_LAYOUT_P ix86_ms_bitfield_layout_p
   24547 
   24548 #if TARGET_MACHO
   24549 #undef TARGET_BINDS_LOCAL_P
   24550 #define TARGET_BINDS_LOCAL_P darwin_binds_local_p
   24551 #else
   24552 #undef TARGET_BINDS_LOCAL_P
   24553 #define TARGET_BINDS_LOCAL_P ix86_binds_local_p
   24554 #endif
   24555 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
   24556 #undef TARGET_BINDS_LOCAL_P
   24557 #define TARGET_BINDS_LOCAL_P i386_pe_binds_local_p
   24558 #endif
   24559 
   24560 #undef TARGET_ASM_OUTPUT_MI_THUNK
   24561 #define TARGET_ASM_OUTPUT_MI_THUNK x86_output_mi_thunk
   24562 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
   24563 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK x86_can_output_mi_thunk
   24564 
   24565 #undef TARGET_ASM_FILE_START
   24566 #define TARGET_ASM_FILE_START x86_file_start
   24567 
   24568 #undef TARGET_OPTION_OVERRIDE
   24569 #define TARGET_OPTION_OVERRIDE ix86_option_override
   24570 
   24571 #undef TARGET_REGISTER_MOVE_COST
   24572 #define TARGET_REGISTER_MOVE_COST ix86_register_move_cost
   24573 #undef TARGET_MEMORY_MOVE_COST
   24574 #define TARGET_MEMORY_MOVE_COST ix86_memory_move_cost
   24575 #undef TARGET_RTX_COSTS
   24576 #define TARGET_RTX_COSTS ix86_rtx_costs
   24577 #undef TARGET_ADDRESS_COST
   24578 #define TARGET_ADDRESS_COST ix86_address_cost
   24579 
   24580 #undef TARGET_OVERLAP_OP_BY_PIECES_P
   24581 #define TARGET_OVERLAP_OP_BY_PIECES_P hook_bool_void_true
   24582 
   24583 #undef TARGET_FLAGS_REGNUM
   24584 #define TARGET_FLAGS_REGNUM FLAGS_REG
   24585 #undef TARGET_FIXED_CONDITION_CODE_REGS
   24586 #define TARGET_FIXED_CONDITION_CODE_REGS ix86_fixed_condition_code_regs
   24587 #undef TARGET_CC_MODES_COMPATIBLE
   24588 #define TARGET_CC_MODES_COMPATIBLE ix86_cc_modes_compatible
   24589 
   24590 #undef TARGET_MACHINE_DEPENDENT_REORG
   24591 #define TARGET_MACHINE_DEPENDENT_REORG ix86_reorg
   24592 
   24593 #undef TARGET_BUILD_BUILTIN_VA_LIST
   24594 #define TARGET_BUILD_BUILTIN_VA_LIST ix86_build_builtin_va_list
   24595 
   24596 #undef TARGET_FOLD_BUILTIN
   24597 #define TARGET_FOLD_BUILTIN ix86_fold_builtin
   24598 
   24599 #undef TARGET_GIMPLE_FOLD_BUILTIN
   24600 #define TARGET_GIMPLE_FOLD_BUILTIN ix86_gimple_fold_builtin
   24601 
   24602 #undef TARGET_COMPARE_VERSION_PRIORITY
   24603 #define TARGET_COMPARE_VERSION_PRIORITY ix86_compare_version_priority
   24604 
   24605 #undef TARGET_GENERATE_VERSION_DISPATCHER_BODY
   24606 #define TARGET_GENERATE_VERSION_DISPATCHER_BODY \
   24607   ix86_generate_version_dispatcher_body
   24608 
   24609 #undef TARGET_GET_FUNCTION_VERSIONS_DISPATCHER
   24610 #define TARGET_GET_FUNCTION_VERSIONS_DISPATCHER \
   24611   ix86_get_function_versions_dispatcher
   24612 
   24613 #undef TARGET_ENUM_VA_LIST_P
   24614 #define TARGET_ENUM_VA_LIST_P ix86_enum_va_list
   24615 
   24616 #undef TARGET_FN_ABI_VA_LIST
   24617 #define TARGET_FN_ABI_VA_LIST ix86_fn_abi_va_list
   24618 
   24619 #undef TARGET_CANONICAL_VA_LIST_TYPE
   24620 #define TARGET_CANONICAL_VA_LIST_TYPE ix86_canonical_va_list_type
   24621 
   24622 #undef TARGET_EXPAND_BUILTIN_VA_START
   24623 #define TARGET_EXPAND_BUILTIN_VA_START ix86_va_start
   24624 
   24625 #undef TARGET_MD_ASM_ADJUST
   24626 #define TARGET_MD_ASM_ADJUST ix86_md_asm_adjust
   24627 
   24628 #undef TARGET_C_EXCESS_PRECISION
   24629 #define TARGET_C_EXCESS_PRECISION ix86_get_excess_precision
   24630 #undef TARGET_PROMOTE_PROTOTYPES
   24631 #define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
   24632 #undef TARGET_PUSH_ARGUMENT
   24633 #define TARGET_PUSH_ARGUMENT ix86_push_argument
   24634 #undef TARGET_SETUP_INCOMING_VARARGS
   24635 #define TARGET_SETUP_INCOMING_VARARGS ix86_setup_incoming_varargs
   24636 #undef TARGET_MUST_PASS_IN_STACK
   24637 #define TARGET_MUST_PASS_IN_STACK ix86_must_pass_in_stack
   24638 #undef TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS
   24639 #define TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS ix86_allocate_stack_slots_for_args
   24640 #undef TARGET_FUNCTION_ARG_ADVANCE
   24641 #define TARGET_FUNCTION_ARG_ADVANCE ix86_function_arg_advance
   24642 #undef TARGET_FUNCTION_ARG
   24643 #define TARGET_FUNCTION_ARG ix86_function_arg
   24644 #undef TARGET_INIT_PIC_REG
   24645 #define TARGET_INIT_PIC_REG ix86_init_pic_reg
   24646 #undef TARGET_USE_PSEUDO_PIC_REG
   24647 #define TARGET_USE_PSEUDO_PIC_REG ix86_use_pseudo_pic_reg
   24648 #undef TARGET_FUNCTION_ARG_BOUNDARY
   24649 #define TARGET_FUNCTION_ARG_BOUNDARY ix86_function_arg_boundary
   24650 #undef TARGET_PASS_BY_REFERENCE
   24651 #define TARGET_PASS_BY_REFERENCE ix86_pass_by_reference
   24652 #undef TARGET_INTERNAL_ARG_POINTER
   24653 #define TARGET_INTERNAL_ARG_POINTER ix86_internal_arg_pointer
   24654 #undef TARGET_UPDATE_STACK_BOUNDARY
   24655 #define TARGET_UPDATE_STACK_BOUNDARY ix86_update_stack_boundary
   24656 #undef TARGET_GET_DRAP_RTX
   24657 #define TARGET_GET_DRAP_RTX ix86_get_drap_rtx
   24658 #undef TARGET_STRICT_ARGUMENT_NAMING
   24659 #define TARGET_STRICT_ARGUMENT_NAMING hook_bool_CUMULATIVE_ARGS_true
   24660 #undef TARGET_STATIC_CHAIN
   24661 #define TARGET_STATIC_CHAIN ix86_static_chain
   24662 #undef TARGET_TRAMPOLINE_INIT
   24663 #define TARGET_TRAMPOLINE_INIT ix86_trampoline_init
   24664 #undef TARGET_RETURN_POPS_ARGS
   24665 #define TARGET_RETURN_POPS_ARGS ix86_return_pops_args
   24666 
   24667 #undef TARGET_WARN_FUNC_RETURN
   24668 #define TARGET_WARN_FUNC_RETURN ix86_warn_func_return
   24669 
   24670 #undef TARGET_LEGITIMATE_COMBINED_INSN
   24671 #define TARGET_LEGITIMATE_COMBINED_INSN ix86_legitimate_combined_insn
   24672 
   24673 #undef TARGET_ASAN_SHADOW_OFFSET
   24674 #define TARGET_ASAN_SHADOW_OFFSET ix86_asan_shadow_offset
   24675 
   24676 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
   24677 #define TARGET_GIMPLIFY_VA_ARG_EXPR ix86_gimplify_va_arg
   24678 
   24679 #undef TARGET_SCALAR_MODE_SUPPORTED_P
   24680 #define TARGET_SCALAR_MODE_SUPPORTED_P ix86_scalar_mode_supported_p
   24681 
   24682 #undef TARGET_LIBGCC_FLOATING_MODE_SUPPORTED_P
   24683 #define TARGET_LIBGCC_FLOATING_MODE_SUPPORTED_P	\
   24684 ix86_libgcc_floating_mode_supported_p
   24685 
   24686 #undef TARGET_VECTOR_MODE_SUPPORTED_P
   24687 #define TARGET_VECTOR_MODE_SUPPORTED_P ix86_vector_mode_supported_p
   24688 
   24689 #undef TARGET_C_MODE_FOR_SUFFIX
   24690 #define TARGET_C_MODE_FOR_SUFFIX ix86_c_mode_for_suffix
   24691 
   24692 #ifdef HAVE_AS_TLS
   24693 #undef TARGET_ASM_OUTPUT_DWARF_DTPREL
   24694 #define TARGET_ASM_OUTPUT_DWARF_DTPREL i386_output_dwarf_dtprel
   24695 #endif
   24696 
   24697 #ifdef SUBTARGET_INSERT_ATTRIBUTES
   24698 #undef TARGET_INSERT_ATTRIBUTES
   24699 #define TARGET_INSERT_ATTRIBUTES SUBTARGET_INSERT_ATTRIBUTES
   24700 #endif
   24701 
   24702 #undef TARGET_MANGLE_TYPE
   24703 #define TARGET_MANGLE_TYPE ix86_mangle_type
   24704 
   24705 #undef TARGET_STACK_PROTECT_GUARD
   24706 #define TARGET_STACK_PROTECT_GUARD ix86_stack_protect_guard
   24707 
   24708 #undef TARGET_STACK_PROTECT_RUNTIME_ENABLED_P
   24709 #define TARGET_STACK_PROTECT_RUNTIME_ENABLED_P \
   24710   ix86_stack_protect_runtime_enabled_p
   24711 
   24712 #if !TARGET_MACHO
   24713 #undef TARGET_STACK_PROTECT_FAIL
   24714 #define TARGET_STACK_PROTECT_FAIL ix86_stack_protect_fail
   24715 #endif
   24716 
   24717 #undef TARGET_FUNCTION_VALUE
   24718 #define TARGET_FUNCTION_VALUE ix86_function_value
   24719 
   24720 #undef TARGET_FUNCTION_VALUE_REGNO_P
   24721 #define TARGET_FUNCTION_VALUE_REGNO_P ix86_function_value_regno_p
   24722 
   24723 #undef TARGET_ZERO_CALL_USED_REGS
   24724 #define TARGET_ZERO_CALL_USED_REGS ix86_zero_call_used_regs
   24725 
   24726 #undef TARGET_PROMOTE_FUNCTION_MODE
   24727 #define TARGET_PROMOTE_FUNCTION_MODE ix86_promote_function_mode
   24728 
   24729 #undef  TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE
   24730 #define TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE ix86_override_options_after_change
   24731 
   24732 #undef TARGET_MEMBER_TYPE_FORCES_BLK
   24733 #define TARGET_MEMBER_TYPE_FORCES_BLK ix86_member_type_forces_blk
   24734 
   24735 #undef TARGET_INSTANTIATE_DECLS
   24736 #define TARGET_INSTANTIATE_DECLS ix86_instantiate_decls
   24737 
   24738 #undef TARGET_SECONDARY_RELOAD
   24739 #define TARGET_SECONDARY_RELOAD ix86_secondary_reload
   24740 #undef TARGET_SECONDARY_MEMORY_NEEDED
   24741 #define TARGET_SECONDARY_MEMORY_NEEDED ix86_secondary_memory_needed
   24742 #undef TARGET_SECONDARY_MEMORY_NEEDED_MODE
   24743 #define TARGET_SECONDARY_MEMORY_NEEDED_MODE ix86_secondary_memory_needed_mode
   24744 
   24745 #undef TARGET_CLASS_MAX_NREGS
   24746 #define TARGET_CLASS_MAX_NREGS ix86_class_max_nregs
   24747 
   24748 #undef TARGET_PREFERRED_RELOAD_CLASS
   24749 #define TARGET_PREFERRED_RELOAD_CLASS ix86_preferred_reload_class
   24750 #undef TARGET_PREFERRED_OUTPUT_RELOAD_CLASS
   24751 #define TARGET_PREFERRED_OUTPUT_RELOAD_CLASS ix86_preferred_output_reload_class
   24752 #undef TARGET_CLASS_LIKELY_SPILLED_P
   24753 #define TARGET_CLASS_LIKELY_SPILLED_P ix86_class_likely_spilled_p
   24754 
   24755 #undef TARGET_VECTORIZE_BUILTIN_VECTORIZATION_COST
   24756 #define TARGET_VECTORIZE_BUILTIN_VECTORIZATION_COST \
   24757   ix86_builtin_vectorization_cost
   24758 #undef TARGET_VECTORIZE_VEC_PERM_CONST
   24759 #define TARGET_VECTORIZE_VEC_PERM_CONST ix86_vectorize_vec_perm_const
   24760 #undef TARGET_VECTORIZE_PREFERRED_SIMD_MODE
   24761 #define TARGET_VECTORIZE_PREFERRED_SIMD_MODE \
   24762   ix86_preferred_simd_mode
   24763 #undef TARGET_VECTORIZE_SPLIT_REDUCTION
   24764 #define TARGET_VECTORIZE_SPLIT_REDUCTION \
   24765   ix86_split_reduction
   24766 #undef TARGET_VECTORIZE_AUTOVECTORIZE_VECTOR_MODES
   24767 #define TARGET_VECTORIZE_AUTOVECTORIZE_VECTOR_MODES \
   24768   ix86_autovectorize_vector_modes
   24769 #undef TARGET_VECTORIZE_GET_MASK_MODE
   24770 #define TARGET_VECTORIZE_GET_MASK_MODE ix86_get_mask_mode
   24771 #undef TARGET_VECTORIZE_CREATE_COSTS
   24772 #define TARGET_VECTORIZE_CREATE_COSTS ix86_vectorize_create_costs
   24773 
   24774 #undef TARGET_SET_CURRENT_FUNCTION
   24775 #define TARGET_SET_CURRENT_FUNCTION ix86_set_current_function
   24776 
   24777 #undef TARGET_OPTION_VALID_ATTRIBUTE_P
   24778 #define TARGET_OPTION_VALID_ATTRIBUTE_P ix86_valid_target_attribute_p
   24779 
   24780 #undef TARGET_OPTION_SAVE
   24781 #define TARGET_OPTION_SAVE ix86_function_specific_save
   24782 
   24783 #undef TARGET_OPTION_RESTORE
   24784 #define TARGET_OPTION_RESTORE ix86_function_specific_restore
   24785 
   24786 #undef TARGET_OPTION_POST_STREAM_IN
   24787 #define TARGET_OPTION_POST_STREAM_IN ix86_function_specific_post_stream_in
   24788 
   24789 #undef TARGET_OPTION_PRINT
   24790 #define TARGET_OPTION_PRINT ix86_function_specific_print
   24791 
   24792 #undef TARGET_OPTION_FUNCTION_VERSIONS
   24793 #define TARGET_OPTION_FUNCTION_VERSIONS common_function_versions
   24794 
   24795 #undef TARGET_CAN_INLINE_P
   24796 #define TARGET_CAN_INLINE_P ix86_can_inline_p
   24797 
   24798 #undef TARGET_LEGITIMATE_ADDRESS_P
   24799 #define TARGET_LEGITIMATE_ADDRESS_P ix86_legitimate_address_p
   24800 
   24801 #undef TARGET_REGISTER_PRIORITY
   24802 #define TARGET_REGISTER_PRIORITY ix86_register_priority
   24803 
   24804 #undef TARGET_REGISTER_USAGE_LEVELING_P
   24805 #define TARGET_REGISTER_USAGE_LEVELING_P hook_bool_void_true
   24806 
   24807 #undef TARGET_LEGITIMATE_CONSTANT_P
   24808 #define TARGET_LEGITIMATE_CONSTANT_P ix86_legitimate_constant_p
   24809 
   24810 #undef TARGET_COMPUTE_FRAME_LAYOUT
   24811 #define TARGET_COMPUTE_FRAME_LAYOUT ix86_compute_frame_layout
   24812 
   24813 #undef TARGET_FRAME_POINTER_REQUIRED
   24814 #define TARGET_FRAME_POINTER_REQUIRED ix86_frame_pointer_required
   24815 
   24816 #undef TARGET_CAN_ELIMINATE
   24817 #define TARGET_CAN_ELIMINATE ix86_can_eliminate
   24818 
   24819 #undef TARGET_EXTRA_LIVE_ON_ENTRY
   24820 #define TARGET_EXTRA_LIVE_ON_ENTRY ix86_live_on_entry
   24821 
   24822 #undef TARGET_ASM_CODE_END
   24823 #define TARGET_ASM_CODE_END ix86_code_end
   24824 
   24825 #undef TARGET_CONDITIONAL_REGISTER_USAGE
   24826 #define TARGET_CONDITIONAL_REGISTER_USAGE ix86_conditional_register_usage
   24827 
   24828 #undef TARGET_CANONICALIZE_COMPARISON
   24829 #define TARGET_CANONICALIZE_COMPARISON ix86_canonicalize_comparison
   24830 
   24831 #undef TARGET_LOOP_UNROLL_ADJUST
   24832 #define TARGET_LOOP_UNROLL_ADJUST ix86_loop_unroll_adjust
   24833 
   24834 /* Disabled due to PRs 70902, 71453, 71555, 71596 and 71657.  */
   24835 #undef TARGET_SPILL_CLASS
   24836 #define TARGET_SPILL_CLASS ix86_spill_class
   24837 
   24838 #undef TARGET_SIMD_CLONE_COMPUTE_VECSIZE_AND_SIMDLEN
   24839 #define TARGET_SIMD_CLONE_COMPUTE_VECSIZE_AND_SIMDLEN \
   24840   ix86_simd_clone_compute_vecsize_and_simdlen
   24841 
   24842 #undef TARGET_SIMD_CLONE_ADJUST
   24843 #define TARGET_SIMD_CLONE_ADJUST ix86_simd_clone_adjust
   24844 
   24845 #undef TARGET_SIMD_CLONE_USABLE
   24846 #define TARGET_SIMD_CLONE_USABLE ix86_simd_clone_usable
   24847 
   24848 #undef TARGET_OMP_DEVICE_KIND_ARCH_ISA
   24849 #define TARGET_OMP_DEVICE_KIND_ARCH_ISA ix86_omp_device_kind_arch_isa
   24850 
   24851 #undef TARGET_FLOAT_EXCEPTIONS_ROUNDING_SUPPORTED_P
   24852 #define TARGET_FLOAT_EXCEPTIONS_ROUNDING_SUPPORTED_P \
   24853   ix86_float_exceptions_rounding_supported_p
   24854 
   24855 #undef TARGET_MODE_EMIT
   24856 #define TARGET_MODE_EMIT ix86_emit_mode_set
   24857 
   24858 #undef TARGET_MODE_NEEDED
   24859 #define TARGET_MODE_NEEDED ix86_mode_needed
   24860 
   24861 #undef TARGET_MODE_AFTER
   24862 #define TARGET_MODE_AFTER ix86_mode_after
   24863 
   24864 #undef TARGET_MODE_ENTRY
   24865 #define TARGET_MODE_ENTRY ix86_mode_entry
   24866 
   24867 #undef TARGET_MODE_EXIT
   24868 #define TARGET_MODE_EXIT ix86_mode_exit
   24869 
   24870 #undef TARGET_MODE_PRIORITY
   24871 #define TARGET_MODE_PRIORITY ix86_mode_priority
   24872 
   24873 #undef TARGET_CALL_FUSAGE_CONTAINS_NON_CALLEE_CLOBBERS
   24874 #define TARGET_CALL_FUSAGE_CONTAINS_NON_CALLEE_CLOBBERS true
   24875 
   24876 #undef TARGET_OFFLOAD_OPTIONS
   24877 #define TARGET_OFFLOAD_OPTIONS \
   24878   ix86_offload_options
   24879 
   24880 #undef TARGET_ABSOLUTE_BIGGEST_ALIGNMENT
   24881 #define TARGET_ABSOLUTE_BIGGEST_ALIGNMENT 512
   24882 
   24883 #undef TARGET_OPTAB_SUPPORTED_P
   24884 #define TARGET_OPTAB_SUPPORTED_P ix86_optab_supported_p
   24885 
   24886 #undef TARGET_HARD_REGNO_SCRATCH_OK
   24887 #define TARGET_HARD_REGNO_SCRATCH_OK ix86_hard_regno_scratch_ok
   24888 
   24889 #undef TARGET_CUSTOM_FUNCTION_DESCRIPTORS
   24890 #define TARGET_CUSTOM_FUNCTION_DESCRIPTORS 1
   24891 
   24892 #undef TARGET_ADDR_SPACE_ZERO_ADDRESS_VALID
   24893 #define TARGET_ADDR_SPACE_ZERO_ADDRESS_VALID ix86_addr_space_zero_address_valid
   24894 
   24895 #undef TARGET_INIT_LIBFUNCS
   24896 #define TARGET_INIT_LIBFUNCS ix86_init_libfuncs
   24897 
   24898 #undef TARGET_EXPAND_DIVMOD_LIBFUNC
   24899 #define TARGET_EXPAND_DIVMOD_LIBFUNC ix86_expand_divmod_libfunc
   24900 
   24901 #undef TARGET_MAX_NOCE_IFCVT_SEQ_COST
   24902 #define TARGET_MAX_NOCE_IFCVT_SEQ_COST ix86_max_noce_ifcvt_seq_cost
   24903 
   24904 #undef TARGET_NOCE_CONVERSION_PROFITABLE_P
   24905 #define TARGET_NOCE_CONVERSION_PROFITABLE_P ix86_noce_conversion_profitable_p
   24906 
   24907 #undef TARGET_HARD_REGNO_NREGS
   24908 #define TARGET_HARD_REGNO_NREGS ix86_hard_regno_nregs
   24909 #undef TARGET_HARD_REGNO_MODE_OK
   24910 #define TARGET_HARD_REGNO_MODE_OK ix86_hard_regno_mode_ok
   24911 
   24912 #undef TARGET_MODES_TIEABLE_P
   24913 #define TARGET_MODES_TIEABLE_P ix86_modes_tieable_p
   24914 
   24915 #undef TARGET_HARD_REGNO_CALL_PART_CLOBBERED
   24916 #define TARGET_HARD_REGNO_CALL_PART_CLOBBERED \
   24917   ix86_hard_regno_call_part_clobbered
   24918 
   24919 #undef TARGET_INSN_CALLEE_ABI
   24920 #define TARGET_INSN_CALLEE_ABI ix86_insn_callee_abi
   24921 
   24922 #undef TARGET_CAN_CHANGE_MODE_CLASS
   24923 #define TARGET_CAN_CHANGE_MODE_CLASS ix86_can_change_mode_class
   24924 
   24925 #undef TARGET_LOWER_LOCAL_DECL_ALIGNMENT
   24926 #define TARGET_LOWER_LOCAL_DECL_ALIGNMENT ix86_lower_local_decl_alignment
   24927 
   24928 #undef TARGET_STATIC_RTX_ALIGNMENT
   24929 #define TARGET_STATIC_RTX_ALIGNMENT ix86_static_rtx_alignment
   24930 #undef TARGET_CONSTANT_ALIGNMENT
   24931 #define TARGET_CONSTANT_ALIGNMENT ix86_constant_alignment
   24932 
   24933 #undef TARGET_EMPTY_RECORD_P
   24934 #define TARGET_EMPTY_RECORD_P ix86_is_empty_record
   24935 
   24936 #undef TARGET_WARN_PARAMETER_PASSING_ABI
   24937 #define TARGET_WARN_PARAMETER_PASSING_ABI ix86_warn_parameter_passing_abi
   24938 
   24939 #undef TARGET_GET_MULTILIB_ABI_NAME
   24940 #define TARGET_GET_MULTILIB_ABI_NAME \
   24941   ix86_get_multilib_abi_name
   24942 
   24943 #undef TARGET_IFUNC_REF_LOCAL_OK
   24944 #define TARGET_IFUNC_REF_LOCAL_OK hook_bool_void_true
   24945 
   24946 #if !TARGET_MACHO && !TARGET_DLLIMPORT_DECL_ATTRIBUTES
   24947 # undef TARGET_ASM_RELOC_RW_MASK
   24948 # define TARGET_ASM_RELOC_RW_MASK ix86_reloc_rw_mask
   24949 #endif
   24950 
   24951 static bool ix86_libc_has_fast_function (int fcode ATTRIBUTE_UNUSED)
   24952 {
   24953 #ifdef OPTION_GLIBC
   24954   if (OPTION_GLIBC)
   24955     return (built_in_function)fcode == BUILT_IN_MEMPCPY;
   24956   else
   24957     return false;
   24958 #else
   24959   return false;
   24960 #endif
   24961 }
   24962 
   24963 #undef TARGET_LIBC_HAS_FAST_FUNCTION
   24964 #define TARGET_LIBC_HAS_FAST_FUNCTION ix86_libc_has_fast_function
   24965 
   24966 #undef TARGET_GEN_MEMSET_SCRATCH_RTX
   24967 #define TARGET_GEN_MEMSET_SCRATCH_RTX ix86_gen_scratch_sse_rtx
   24968 
   24969 #if CHECKING_P
   24970 #undef TARGET_RUN_TARGET_SELFTESTS
   24971 #define TARGET_RUN_TARGET_SELFTESTS selftest::ix86_run_selftests
   24972 #endif /* #if CHECKING_P */
   24973 
   24974 struct gcc_target targetm = TARGET_INITIALIZER;
   24975 
   24976 #include "gt-i386.h"
   24978