LCOV - code coverage report
Current view: top level - gcc/config/i386 - i386-features.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 89.7 % 2102 1885
Test Date: 2025-06-21 16:26:05 Functions: 98.8 % 83 82
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* Copyright (C) 1988-2025 Free Software Foundation, Inc.
       2                 :             : 
       3                 :             : This file is part of GCC.
       4                 :             : 
       5                 :             : GCC is free software; you can redistribute it and/or modify
       6                 :             : it under the terms of the GNU General Public License as published by
       7                 :             : the Free Software Foundation; either version 3, or (at your option)
       8                 :             : any later version.
       9                 :             : 
      10                 :             : GCC is distributed in the hope that it will be useful,
      11                 :             : but WITHOUT ANY WARRANTY; without even the implied warranty of
      12                 :             : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      13                 :             : GNU General Public License for more details.
      14                 :             : 
      15                 :             : You should have received a copy of the GNU General Public License
      16                 :             : along with GCC; see the file COPYING3.  If not see
      17                 :             : <http://www.gnu.org/licenses/>.  */
      18                 :             : 
      19                 :             : #define IN_TARGET_CODE 1
      20                 :             : 
      21                 :             : #include "config.h"
      22                 :             : #include "system.h"
      23                 :             : #include "coretypes.h"
      24                 :             : #include "backend.h"
      25                 :             : #include "rtl.h"
      26                 :             : #include "tree.h"
      27                 :             : #include "memmodel.h"
      28                 :             : #include "gimple.h"
      29                 :             : #include "cfghooks.h"
      30                 :             : #include "cfgloop.h"
      31                 :             : #include "df.h"
      32                 :             : #include "tm_p.h"
      33                 :             : #include "stringpool.h"
      34                 :             : #include "expmed.h"
      35                 :             : #include "optabs.h"
      36                 :             : #include "regs.h"
      37                 :             : #include "emit-rtl.h"
      38                 :             : #include "recog.h"
      39                 :             : #include "cgraph.h"
      40                 :             : #include "diagnostic.h"
      41                 :             : #include "cfgbuild.h"
      42                 :             : #include "alias.h"
      43                 :             : #include "fold-const.h"
      44                 :             : #include "attribs.h"
      45                 :             : #include "calls.h"
      46                 :             : #include "stor-layout.h"
      47                 :             : #include "varasm.h"
      48                 :             : #include "output.h"
      49                 :             : #include "insn-attr.h"
      50                 :             : #include "flags.h"
      51                 :             : #include "except.h"
      52                 :             : #include "explow.h"
      53                 :             : #include "expr.h"
      54                 :             : #include "cfgrtl.h"
      55                 :             : #include "common/common-target.h"
      56                 :             : #include "langhooks.h"
      57                 :             : #include "reload.h"
      58                 :             : #include "gimplify.h"
      59                 :             : #include "dwarf2.h"
      60                 :             : #include "tm-constrs.h"
      61                 :             : #include "cselib.h"
      62                 :             : #include "sched-int.h"
      63                 :             : #include "opts.h"
      64                 :             : #include "tree-pass.h"
      65                 :             : #include "context.h"
      66                 :             : #include "pass_manager.h"
      67                 :             : #include "target-globals.h"
      68                 :             : #include "gimple-iterator.h"
      69                 :             : #include "shrink-wrap.h"
      70                 :             : #include "builtins.h"
      71                 :             : #include "rtl-iter.h"
      72                 :             : #include "tree-iterator.h"
      73                 :             : #include "dbgcnt.h"
      74                 :             : #include "case-cfn-macros.h"
      75                 :             : #include "dojump.h"
      76                 :             : #include "fold-const-call.h"
      77                 :             : #include "tree-vrp.h"
      78                 :             : #include "tree-ssanames.h"
      79                 :             : #include "selftest.h"
      80                 :             : #include "selftest-rtl.h"
      81                 :             : #include "print-rtl.h"
      82                 :             : #include "intl.h"
      83                 :             : #include "ifcvt.h"
      84                 :             : #include "symbol-summary.h"
      85                 :             : #include "sreal.h"
      86                 :             : #include "ipa-cp.h"
      87                 :             : #include "ipa-prop.h"
      88                 :             : #include "ipa-fnsummary.h"
      89                 :             : #include "wide-int-bitmask.h"
      90                 :             : #include "tree-vector-builder.h"
      91                 :             : #include "debug.h"
      92                 :             : #include "dwarf2out.h"
      93                 :             : #include "i386-builtins.h"
      94                 :             : #include "i386-features.h"
      95                 :             : #include "i386-expand.h"
      96                 :             : 
      97                 :             : const char * const xlogue_layout::STUB_BASE_NAMES[XLOGUE_STUB_COUNT] = {
      98                 :             :   "savms64",
      99                 :             :   "resms64",
     100                 :             :   "resms64x",
     101                 :             :   "savms64f",
     102                 :             :   "resms64f",
     103                 :             :   "resms64fx"
     104                 :             : };
     105                 :             : 
     106                 :             : const unsigned xlogue_layout::REG_ORDER[xlogue_layout::MAX_REGS] = {
     107                 :             : /* The below offset values are where each register is stored for the layout
     108                 :             :    relative to incoming stack pointer.  The value of each m_regs[].offset will
     109                 :             :    be relative to the incoming base pointer (rax or rsi) used by the stub.
     110                 :             : 
     111                 :             :     s_instances:   0            1               2               3
     112                 :             :     Offset:                                     realigned or    aligned + 8
     113                 :             :     Register       aligned      aligned + 8     aligned w/HFP   w/HFP   */
     114                 :             :     XMM15_REG,  /* 0x10         0x18            0x10            0x18    */
     115                 :             :     XMM14_REG,  /* 0x20         0x28            0x20            0x28    */
     116                 :             :     XMM13_REG,  /* 0x30         0x38            0x30            0x38    */
     117                 :             :     XMM12_REG,  /* 0x40         0x48            0x40            0x48    */
     118                 :             :     XMM11_REG,  /* 0x50         0x58            0x50            0x58    */
     119                 :             :     XMM10_REG,  /* 0x60         0x68            0x60            0x68    */
     120                 :             :     XMM9_REG,   /* 0x70         0x78            0x70            0x78    */
     121                 :             :     XMM8_REG,   /* 0x80         0x88            0x80            0x88    */
     122                 :             :     XMM7_REG,   /* 0x90         0x98            0x90            0x98    */
     123                 :             :     XMM6_REG,   /* 0xa0         0xa8            0xa0            0xa8    */
     124                 :             :     SI_REG,     /* 0xa8         0xb0            0xa8            0xb0    */
     125                 :             :     DI_REG,     /* 0xb0         0xb8            0xb0            0xb8    */
     126                 :             :     BX_REG,     /* 0xb8         0xc0            0xb8            0xc0    */
     127                 :             :     BP_REG,     /* 0xc0         0xc8            N/A             N/A     */
     128                 :             :     R12_REG,    /* 0xc8         0xd0            0xc0            0xc8    */
     129                 :             :     R13_REG,    /* 0xd0         0xd8            0xc8            0xd0    */
     130                 :             :     R14_REG,    /* 0xd8         0xe0            0xd0            0xd8    */
     131                 :             :     R15_REG,    /* 0xe0         0xe8            0xd8            0xe0    */
     132                 :             : };
     133                 :             : 
     134                 :             : /* Instantiate static const values.  */
     135                 :             : const HOST_WIDE_INT xlogue_layout::STUB_INDEX_OFFSET;
     136                 :             : const unsigned xlogue_layout::MIN_REGS;
     137                 :             : const unsigned xlogue_layout::MAX_REGS;
     138                 :             : const unsigned xlogue_layout::MAX_EXTRA_REGS;
     139                 :             : const unsigned xlogue_layout::VARIANT_COUNT;
     140                 :             : const unsigned xlogue_layout::STUB_NAME_MAX_LEN;
     141                 :             : 
     142                 :             : /* Initialize xlogue_layout::s_stub_names to zero.  */
     143                 :             : char xlogue_layout::s_stub_names[2][XLOGUE_STUB_COUNT][VARIANT_COUNT]
     144                 :             :                                 [STUB_NAME_MAX_LEN];
     145                 :             : 
     146                 :             : /* Instantiates all xlogue_layout instances.  */
     147                 :             : const xlogue_layout xlogue_layout::s_instances[XLOGUE_SET_COUNT] = {
     148                 :             :   xlogue_layout (0, false),
     149                 :             :   xlogue_layout (8, false),
     150                 :             :   xlogue_layout (0, true),
     151                 :             :   xlogue_layout (8, true)
     152                 :             : };
     153                 :             : 
     154                 :             : /* Return an appropriate const instance of xlogue_layout based upon values
     155                 :             :    in cfun->machine and crtl.  */
     156                 :             : const class xlogue_layout &
     157                 :       49891 : xlogue_layout::get_instance ()
     158                 :             : {
     159                 :       49891 :   enum xlogue_stub_sets stub_set;
     160                 :       49891 :   bool aligned_plus_8 = cfun->machine->call_ms2sysv_pad_in;
     161                 :             : 
     162                 :       49891 :   if (stack_realign_fp)
     163                 :             :     stub_set = XLOGUE_SET_HFP_ALIGNED_OR_REALIGN;
     164                 :       40910 :   else if (frame_pointer_needed)
     165                 :       25246 :     stub_set = aligned_plus_8
     166                 :       31552 :               ? XLOGUE_SET_HFP_ALIGNED_PLUS_8
     167                 :             :               : XLOGUE_SET_HFP_ALIGNED_OR_REALIGN;
     168                 :             :   else
     169                 :        9358 :     stub_set = aligned_plus_8 ? XLOGUE_SET_ALIGNED_PLUS_8 : XLOGUE_SET_ALIGNED;
     170                 :             : 
     171                 :       49891 :   return s_instances[stub_set];
     172                 :             : }
     173                 :             : 
     174                 :             : /* Determine how many clobbered registers can be saved by the stub.
     175                 :             :    Returns the count of registers the stub will save and restore.  */
     176                 :             : unsigned
     177                 :       35225 : xlogue_layout::count_stub_managed_regs ()
     178                 :             : {
     179                 :       35225 :   bool hfp = frame_pointer_needed || stack_realign_fp;
     180                 :       35225 :   unsigned i, count;
     181                 :       35225 :   unsigned regno;
     182                 :             : 
     183                 :       94890 :   for (count = i = MIN_REGS; i < MAX_REGS; ++i)
     184                 :             :     {
     185                 :       93670 :       regno = REG_ORDER[i];
     186                 :       93670 :       if (regno == BP_REG && hfp)
     187                 :       18200 :         continue;
     188                 :       75470 :       if (!ix86_save_reg (regno, false, false))
     189                 :             :         break;
     190                 :       41465 :       ++count;
     191                 :             :     }
     192                 :       35225 :   return count;
     193                 :             : }
     194                 :             : 
     195                 :             : /* Determine if register REGNO is a stub managed register given the
     196                 :             :    total COUNT of stub managed registers.  */
     197                 :             : bool
     198                 :     2650688 : xlogue_layout::is_stub_managed_reg (unsigned regno, unsigned count)
     199                 :             : {
     200                 :     2650688 :   bool hfp = frame_pointer_needed || stack_realign_fp;
     201                 :     2650688 :   unsigned i;
     202                 :             : 
     203                 :    34587805 :   for (i = 0; i < count; ++i)
     204                 :             :     {
     205                 :    32436986 :       gcc_assert (i < MAX_REGS);
     206                 :    32436986 :       if (REG_ORDER[i] == BP_REG && hfp)
     207                 :      522627 :         ++count;
     208                 :    31914359 :       else if (REG_ORDER[i] == regno)
     209                 :             :         return true;
     210                 :             :     }
     211                 :             :   return false;
     212                 :             : }
     213                 :             : 
     214                 :             : /* Constructor for xlogue_layout.  */
     215                 :     1136080 : xlogue_layout::xlogue_layout (HOST_WIDE_INT stack_align_off_in, bool hfp)
     216                 :     1136080 :   : m_hfp (hfp) , m_nregs (hfp ? 17 : 18),
     217                 :     1136080 :     m_stack_align_off_in (stack_align_off_in)
     218                 :             : {
     219                 :     1136080 :   HOST_WIDE_INT offset = stack_align_off_in;
     220                 :     1136080 :   unsigned i, j;
     221                 :             : 
     222                 :    21585520 :   for (i = j = 0; i < MAX_REGS; ++i)
     223                 :             :     {
     224                 :    20449440 :       unsigned regno = REG_ORDER[i];
     225                 :             : 
     226                 :    20449440 :       if (regno == BP_REG && hfp)
     227                 :      568040 :         continue;
     228                 :    19881400 :       if (SSE_REGNO_P (regno))
     229                 :             :         {
     230                 :    11360800 :           offset += 16;
     231                 :             :           /* Verify that SSE regs are always aligned.  */
     232                 :    11360800 :           gcc_assert (!((stack_align_off_in + offset) & 15));
     233                 :             :         }
     234                 :             :       else
     235                 :     8520600 :         offset += 8;
     236                 :             : 
     237                 :    19881400 :       m_regs[j].regno    = regno;
     238                 :    19881400 :       m_regs[j++].offset = offset - STUB_INDEX_OFFSET;
     239                 :             :     }
     240                 :     1136080 :   gcc_assert (j == m_nregs);
     241                 :     1136080 : }
     242                 :             : 
     243                 :             : const char *
     244                 :       14666 : xlogue_layout::get_stub_name (enum xlogue_stub stub,
     245                 :             :                               unsigned n_extra_regs)
     246                 :             : {
     247                 :       14666 :   const int have_avx = TARGET_AVX;
     248                 :       14666 :   char *name = s_stub_names[!!have_avx][stub][n_extra_regs];
     249                 :             : 
     250                 :             :   /* Lazy init */
     251                 :       14666 :   if (!*name)
     252                 :             :     {
     253                 :         362 :       int res = snprintf (name, STUB_NAME_MAX_LEN, "__%s_%s_%u",
     254                 :             :                           (have_avx ? "avx" : "sse"),
     255                 :         181 :                           STUB_BASE_NAMES[stub],
     256                 :             :                           MIN_REGS + n_extra_regs);
     257                 :         181 :       gcc_checking_assert (res < (int)STUB_NAME_MAX_LEN);
     258                 :             :     }
     259                 :             : 
     260                 :       14666 :   return name;
     261                 :             : }
     262                 :             : 
     263                 :             : /* Return rtx of a symbol ref for the entry point (based upon
     264                 :             :    cfun->machine->call_ms2sysv_extra_regs) of the specified stub.  */
     265                 :             : rtx
     266                 :       14666 : xlogue_layout::get_stub_rtx (enum xlogue_stub stub)
     267                 :             : {
     268                 :       14666 :   const unsigned n_extra_regs = cfun->machine->call_ms2sysv_extra_regs;
     269                 :       14666 :   gcc_checking_assert (n_extra_regs <= MAX_EXTRA_REGS);
     270                 :       14666 :   gcc_assert (stub < XLOGUE_STUB_COUNT);
     271                 :       14666 :   gcc_assert (crtl->stack_realign_finalized);
     272                 :             : 
     273                 :       14666 :   return gen_rtx_SYMBOL_REF (Pmode, get_stub_name (stub, n_extra_regs));
     274                 :             : }
     275                 :             : 
     276                 :             : unsigned scalar_chain::max_id = 0;
     277                 :             : 
     278                 :             : namespace {
     279                 :             : 
     280                 :             : /* Initialize new chain.  */
     281                 :             : 
     282                 :     6466932 : scalar_chain::scalar_chain (enum machine_mode smode_, enum machine_mode vmode_)
     283                 :             : {
     284                 :     6466932 :   smode = smode_;
     285                 :     6466932 :   vmode = vmode_;
     286                 :             : 
     287                 :     6466932 :   chain_id = ++max_id;
     288                 :             : 
     289                 :     6466932 :    if (dump_file)
     290                 :         138 :     fprintf (dump_file, "Created a new instruction chain #%d\n", chain_id);
     291                 :             : 
     292                 :     6466932 :   bitmap_obstack_initialize (NULL);
     293                 :     6466932 :   insns = BITMAP_ALLOC (NULL);
     294                 :     6466932 :   defs = BITMAP_ALLOC (NULL);
     295                 :     6466932 :   defs_conv = BITMAP_ALLOC (NULL);
     296                 :     6466932 :   insns_conv = BITMAP_ALLOC (NULL);
     297                 :     6466932 :   queue = NULL;
     298                 :             : 
     299                 :     6466932 :   cost_sse_integer = 0;
     300                 :     6466932 :   weighted_cost_sse_integer = 0 ;
     301                 :     6466932 :   max_visits = x86_stv_max_visits;
     302                 :     6466932 : }
     303                 :             : 
     304                 :             : /* Free chain's data.  */
     305                 :             : 
     306                 :     6466932 : scalar_chain::~scalar_chain ()
     307                 :             : {
     308                 :     6466932 :   BITMAP_FREE (insns);
     309                 :     6466932 :   BITMAP_FREE (defs);
     310                 :     6466932 :   BITMAP_FREE (defs_conv);
     311                 :     6466932 :   BITMAP_FREE (insns_conv);
     312                 :     6466932 :   bitmap_obstack_release (NULL);
     313                 :     6466932 : }
     314                 :             : 
     315                 :             : /* Add instruction into chains' queue.  */
     316                 :             : 
     317                 :             : void
     318                 :     8003827 : scalar_chain::add_to_queue (unsigned insn_uid)
     319                 :             : {
     320                 :     8003827 :   if (!bitmap_set_bit (queue, insn_uid))
     321                 :             :     return;
     322                 :             : 
     323                 :     6212702 :   if (dump_file)
     324                 :         137 :     fprintf (dump_file, "  Adding insn %d into chain's #%d queue\n",
     325                 :             :              insn_uid, chain_id);
     326                 :             : }
     327                 :             : 
     328                 :             : /* For DImode conversion, mark register defined by DEF as requiring
     329                 :             :    conversion.  */
     330                 :             : 
     331                 :             : void
     332                 :     9526431 : scalar_chain::mark_dual_mode_def (df_ref def)
     333                 :             : {
     334                 :     9526431 :   gcc_assert (DF_REF_REG_DEF_P (def));
     335                 :             : 
     336                 :             :   /* Record the def/insn pair so we can later efficiently iterate over
     337                 :             :      the defs to convert on insns not in the chain.  */
     338                 :     9526431 :   bool reg_new = bitmap_set_bit (defs_conv, DF_REF_REGNO (def));
     339                 :     9526431 :   basic_block bb = BLOCK_FOR_INSN (DF_REF_INSN (def));
     340                 :     9526431 :   profile_count entry_count = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count;
     341                 :     9526431 :   bool speed_p = optimize_bb_for_speed_p (bb);
     342                 :     9526431 :   int cost = 0;
     343                 :             : 
     344                 :     9526431 :   if (!bitmap_bit_p (insns, DF_REF_INSN_UID (def)))
     345                 :             :     {
     346                 :     2768470 :       if (!bitmap_set_bit (insns_conv, DF_REF_INSN_UID (def))
     347                 :     2768470 :           && !reg_new)
     348                 :     1374109 :         return;
     349                 :             : 
     350                 :             :       /* Cost integer to sse moves.  */
     351                 :     2522157 :       if (speed_p)
     352                 :     2252183 :         cost = COSTS_N_INSNS (ix86_cost->integer_to_sse) / 2;
     353                 :      269974 :       else if (TARGET_64BIT || smode == SImode)
     354                 :             :         cost = COSTS_N_BYTES (4);
     355                 :             :       /* vmovd (4 bytes) + vpinsrd (6 bytes).  */
     356                 :       18440 :       else if (TARGET_SSE4_1)
     357                 :             :         cost = COSTS_N_BYTES (10);
     358                 :             :       /* movd (4 bytes) + movd (4 bytes) + unpckldq (4 bytes).  */
     359                 :             :       else
     360                 :     8152322 :         cost = COSTS_N_BYTES (12);
     361                 :             :     }
     362                 :             :   else
     363                 :             :     {
     364                 :     6757961 :       if (!reg_new)
     365                 :             :         return;
     366                 :             : 
     367                 :             :       /* Cost sse to integer moves.  */
     368                 :     5630165 :       if (speed_p)
     369                 :     5084796 :         cost = COSTS_N_INSNS (ix86_cost->sse_to_integer) / 2;
     370                 :      545369 :       else if (TARGET_64BIT || smode == SImode)
     371                 :             :         cost = COSTS_N_BYTES (4);
     372                 :             :       /* vmovd (4 bytes) + vpextrd (6 bytes).  */
     373                 :        2960 :       else if (TARGET_SSE4_1)
     374                 :             :         cost = COSTS_N_BYTES (10);
     375                 :             :       /* movd (4 bytes) + psrlq (5 bytes) + movd (4 bytes).  */
     376                 :             :       else
     377                 :     8152322 :         cost = COSTS_N_BYTES (13);
     378                 :             :     }
     379                 :             : 
     380                 :     8152322 :   if (speed_p)
     381                 :     7336979 :     weighted_cost_sse_integer += bb->count.to_sreal_scale (entry_count) * cost;
     382                 :             : 
     383                 :     8152322 :   cost_sse_integer += cost;
     384                 :             : 
     385                 :     8152322 :   if (dump_file)
     386                 :         236 :     fprintf (dump_file,
     387                 :             :              "  Mark r%d def in insn %d as requiring both modes in chain #%d\n",
     388                 :         236 :              DF_REF_REGNO (def), DF_REF_INSN_UID (def), chain_id);
     389                 :             : }
     390                 :             : 
     391                 :             : /* Check REF's chain to add new insns into a queue
     392                 :             :    and find registers requiring conversion.  Return true if OK, false
     393                 :             :    if the analysis was aborted.  */
     394                 :             : 
     395                 :             : bool
     396                 :    17895541 : scalar_chain::analyze_register_chain (bitmap candidates, df_ref ref,
     397                 :             :                                       bitmap disallowed)
     398                 :             : {
     399                 :    17895541 :   df_link *chain;
     400                 :    17895541 :   bool mark_def = false;
     401                 :             : 
     402                 :    17895541 :   gcc_checking_assert (bitmap_bit_p (insns, DF_REF_INSN_UID (ref)));
     403                 :             : 
     404                 :    61153718 :   for (chain = DF_REF_CHAIN (ref); chain; chain = chain->next)
     405                 :             :     {
     406                 :    43258692 :       unsigned uid = DF_REF_INSN_UID (chain->ref);
     407                 :             : 
     408                 :    43258692 :       if (!NONDEBUG_INSN_P (DF_REF_INSN (chain->ref)))
     409                 :     7615438 :         continue;
     410                 :             : 
     411                 :    35643254 :       if (--max_visits == 0)
     412                 :             :         return false;
     413                 :             : 
     414                 :    35642739 :       if (!DF_REF_REG_MEM_P (chain->ref))
     415                 :             :         {
     416                 :    29960119 :           if (bitmap_bit_p (insns, uid))
     417                 :     9345647 :             continue;
     418                 :             : 
     419                 :    20614472 :           if (bitmap_bit_p (candidates, uid))
     420                 :             :             {
     421                 :     8003827 :               add_to_queue (uid);
     422                 :     8003827 :               continue;
     423                 :             :             }
     424                 :             : 
     425                 :             :           /* If we run into parts of an aborted chain discovery abort.  */
     426                 :    12610645 :           if (bitmap_bit_p (disallowed, uid))
     427                 :             :             return false;
     428                 :             :         }
     429                 :             : 
     430                 :    18293265 :       if (DF_REF_REG_DEF_P (chain->ref))
     431                 :             :         {
     432                 :     2768470 :           if (dump_file)
     433                 :         127 :             fprintf (dump_file, "  r%d def in insn %d isn't convertible\n",
     434                 :             :                      DF_REF_REGNO (chain->ref), uid);
     435                 :     2768470 :           mark_dual_mode_def (chain->ref);
     436                 :             :         }
     437                 :             :       else
     438                 :             :         {
     439                 :    15524795 :           if (dump_file)
     440                 :         534 :             fprintf (dump_file, "  r%d use in insn %d isn't convertible\n",
     441                 :             :                      DF_REF_REGNO (chain->ref), uid);
     442                 :             :           mark_def = true;
     443                 :             :         }
     444                 :             :     }
     445                 :             : 
     446                 :    17895026 :   if (mark_def)
     447                 :     6757961 :     mark_dual_mode_def (ref);
     448                 :             : 
     449                 :             :   return true;
     450                 :             : }
     451                 :             : 
     452                 :             : /* Add instruction into a chain.  Return true if OK, false if the search
     453                 :             :    was aborted.  */
     454                 :             : 
     455                 :             : bool
     456                 :    12679634 : scalar_chain::add_insn (bitmap candidates, unsigned int insn_uid,
     457                 :             :                         bitmap disallowed)
     458                 :             : {
     459                 :    12679634 :   if (!bitmap_set_bit (insns, insn_uid))
     460                 :             :     return true;
     461                 :             : 
     462                 :    12679634 :   if (dump_file)
     463                 :         275 :     fprintf (dump_file, "  Adding insn %d to chain #%d\n", insn_uid, chain_id);
     464                 :             : 
     465                 :    12679634 :   rtx_insn *insn = DF_INSN_UID_GET (insn_uid)->insn;
     466                 :    12679634 :   rtx def_set = single_set (insn);
     467                 :    12679634 :   if (def_set && REG_P (SET_DEST (def_set))
     468                 :    22495280 :       && !HARD_REGISTER_P (SET_DEST (def_set)))
     469                 :     9815638 :     bitmap_set_bit (defs, REGNO (SET_DEST (def_set)));
     470                 :             : 
     471                 :             :   /* ???  The following is quadratic since analyze_register_chain
     472                 :             :      iterates over all refs to look for dual-mode regs.  Instead this
     473                 :             :      should be done separately for all regs mentioned in the chain once.  */
     474                 :    12679634 :   df_ref ref;
     475                 :    25923818 :   for (ref = DF_INSN_UID_DEFS (insn_uid); ref; ref = DF_REF_NEXT_LOC (ref))
     476                 :    13244632 :     if (!HARD_REGISTER_P (DF_REF_REG (ref)))
     477                 :     9815638 :       if (!analyze_register_chain (candidates, ref, disallowed))
     478                 :             :         return false;
     479                 :             : 
     480                 :             :   /* The operand(s) of VEC_SELECT don't need to be converted/convertible.  */
     481                 :    12679186 :   if (def_set && GET_CODE (SET_SRC (def_set)) == VEC_SELECT)
     482                 :             :     return true;
     483                 :             : 
     484                 :    27688151 :   for (ref = DF_INSN_UID_USES (insn_uid); ref; ref = DF_REF_NEXT_LOC (ref))
     485                 :    15044321 :     if (!DF_REF_REG_MEM_P (ref))
     486                 :     8079903 :       if (!analyze_register_chain (candidates, ref, disallowed))
     487                 :             :         return false;
     488                 :             : 
     489                 :             :   return true;
     490                 :             : }
     491                 :             : 
     492                 :             : /* Build new chain starting from insn INSN_UID recursively
     493                 :             :    adding all dependent uses and definitions.  Return true if OK, false
     494                 :             :    if the chain discovery was aborted.  */
     495                 :             : 
     496                 :             : bool
     497                 :     6466932 : scalar_chain::build (bitmap candidates, unsigned insn_uid, bitmap disallowed)
     498                 :             : {
     499                 :     6466932 :   queue = BITMAP_ALLOC (NULL);
     500                 :     6466932 :   bitmap_set_bit (queue, insn_uid);
     501                 :             : 
     502                 :     6466932 :   if (dump_file)
     503                 :         138 :     fprintf (dump_file, "Building chain #%d...\n", chain_id);
     504                 :             : 
     505                 :    19146051 :   while (!bitmap_empty_p (queue))
     506                 :             :     {
     507                 :    12679634 :       insn_uid = bitmap_first_set_bit (queue);
     508                 :    12679634 :       bitmap_clear_bit (queue, insn_uid);
     509                 :    12679634 :       bitmap_clear_bit (candidates, insn_uid);
     510                 :    12679634 :       if (!add_insn (candidates, insn_uid, disallowed))
     511                 :             :         {
     512                 :             :           /* If we aborted the search put sofar found insn on the set of
     513                 :             :              disallowed insns so that further searches reaching them also
     514                 :             :              abort and thus we abort the whole but yet undiscovered chain.  */
     515                 :         515 :           bitmap_ior_into (disallowed, insns);
     516                 :         515 :           if (dump_file)
     517                 :           0 :             fprintf (dump_file, "Aborted chain #%d discovery\n", chain_id);
     518                 :         515 :           BITMAP_FREE (queue);
     519                 :         515 :           return false;
     520                 :             :         }
     521                 :             :     }
     522                 :             : 
     523                 :     6466417 :   if (dump_file)
     524                 :             :     {
     525                 :         138 :       fprintf (dump_file, "Collected chain #%d...\n", chain_id);
     526                 :         138 :       fprintf (dump_file, "  insns: ");
     527                 :         138 :       dump_bitmap (dump_file, insns);
     528                 :         138 :       if (!bitmap_empty_p (defs_conv))
     529                 :             :         {
     530                 :         138 :           bitmap_iterator bi;
     531                 :         138 :           unsigned id;
     532                 :         138 :           const char *comma = "";
     533                 :         138 :           fprintf (dump_file, "  defs to convert: ");
     534                 :         364 :           EXECUTE_IF_SET_IN_BITMAP (defs_conv, 0, id, bi)
     535                 :             :             {
     536                 :         226 :               fprintf (dump_file, "%sr%d", comma, id);
     537                 :         226 :               comma = ", ";
     538                 :             :             }
     539                 :         138 :           fprintf (dump_file, "\n");
     540                 :             :         }
     541                 :             :     }
     542                 :             : 
     543                 :     6466417 :   BITMAP_FREE (queue);
     544                 :             : 
     545                 :     6466417 :   return true;
     546                 :             : }
     547                 :             : 
     548                 :             : /* Return a cost of building a vector costant
     549                 :             :    instead of using a scalar one.  */
     550                 :             : 
     551                 :             : int
     552                 :     2693896 : general_scalar_chain::vector_const_cost (rtx exp, basic_block bb)
     553                 :             : {
     554                 :     2693896 :   gcc_assert (CONST_INT_P (exp));
     555                 :             : 
     556                 :     2693896 :   if (standard_sse_constant_p (exp, vmode))
     557                 :      619247 :     return ix86_cost->sse_op;
     558                 :     2074649 :   if (optimize_bb_for_size_p (bb))
     559                 :             :     return COSTS_N_BYTES (8);
     560                 :             :   /* We have separate costs for SImode and DImode, use SImode costs
     561                 :             :      for smaller modes.  */
     562                 :     2504439 :   return COSTS_N_INSNS (ix86_cost->sse_load[smode == DImode ? 1 : 0]) / 2;
     563                 :             : }
     564                 :             : 
     565                 :             : /* Return true if it's cost profitable for chain conversion.  */
     566                 :             : 
     567                 :             : bool
     568                 :     6014612 : general_scalar_chain::compute_convert_gain ()
     569                 :             : {
     570                 :     6014612 :   bitmap_iterator bi;
     571                 :     6014612 :   unsigned insn_uid;
     572                 :     6014612 :   int gain = 0;
     573                 :     6014612 :   sreal weighted_gain = 0;
     574                 :             : 
     575                 :     6014612 :   if (dump_file)
     576                 :         138 :     fprintf (dump_file, "Computing gain for chain #%d...\n", chain_id);
     577                 :             : 
     578                 :             :   /* SSE costs distinguish between SImode and DImode loads/stores, for
     579                 :             :      int costs factor in the number of GPRs involved.  When supporting
     580                 :             :      smaller modes than SImode the int load/store costs need to be
     581                 :             :      adjusted as well.  */
     582                 :     6014612 :   unsigned sse_cost_idx = smode == DImode ? 1 : 0;
     583                 :     6014612 :   int m = smode == DImode ? (TARGET_64BIT ? 1 : 2) : 1;
     584                 :             : 
     585                 :    17799778 :   EXECUTE_IF_SET_IN_BITMAP (insns, 0, insn_uid, bi)
     586                 :             :     {
     587                 :    11785166 :       rtx_insn *insn = DF_INSN_UID_GET (insn_uid)->insn;
     588                 :    11785166 :       rtx def_set = single_set (insn);
     589                 :    11785166 :       rtx src = SET_SRC (def_set);
     590                 :    11785166 :       rtx dst = SET_DEST (def_set);
     591                 :    11785166 :       basic_block bb = BLOCK_FOR_INSN (insn);
     592                 :    11785166 :       int igain = 0;
     593                 :    11785166 :       profile_count entry_count = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count;
     594                 :    11785166 :       bool speed_p = optimize_bb_for_speed_p (bb);
     595                 :    11785166 :       sreal bb_freq = bb->count.to_sreal_scale (entry_count);
     596                 :             : 
     597                 :    11785166 :       if (REG_P (src) && REG_P (dst))
     598                 :             :         {
     599                 :      956699 :           if (!speed_p)
     600                 :             :             /* reg-reg move is 2 bytes, while SSE 3.  */
     601                 :      194923 :             igain += COSTS_N_BYTES (2 * m - 3);
     602                 :             :           else
     603                 :             :             /* Move costs are normalized to reg-reg move having cost 2.  */
     604                 :      761776 :             igain += COSTS_N_INSNS (2 * m - ix86_cost->xmm_move) / 2;
     605                 :             :         }
     606                 :    10828467 :       else if (REG_P (src) && MEM_P (dst))
     607                 :             :         {
     608                 :     2309919 :           if (!speed_p)
     609                 :             :             /* Integer load/store is 3+ bytes and SSE 4+.  */
     610                 :      178233 :             igain += COSTS_N_BYTES (3 * m - 4);
     611                 :             :           else
     612                 :     2131686 :             igain
     613                 :     2131686 :               += COSTS_N_INSNS (m * ix86_cost->int_store[2]
     614                 :             :                                 - ix86_cost->sse_store[sse_cost_idx]) / 2;
     615                 :             :         }
     616                 :     8518548 :       else if (MEM_P (src) && REG_P (dst))
     617                 :             :         {
     618                 :     3846838 :           if (!speed_p)
     619                 :      346853 :             igain += COSTS_N_BYTES (3 * m - 4);
     620                 :             :           else
     621                 :     3499985 :             igain += COSTS_N_INSNS (m * ix86_cost->int_load[2]
     622                 :             :                                     - ix86_cost->sse_load[sse_cost_idx]) / 2;
     623                 :             :         }
     624                 :             :       else
     625                 :             :         {
     626                 :             :           /* For operations on memory operands, include the overhead
     627                 :             :              of explicit load and store instructions.  */
     628                 :     4671710 :           if (MEM_P (dst))
     629                 :             :             {
     630                 :       63803 :               if (!speed_p)
     631                 :             :                 /* ??? This probably should account size difference
     632                 :             :                    of SSE and integer load rather than full SSE load.  */
     633                 :             :                 igain -= COSTS_N_BYTES (8);
     634                 :             :               else
     635                 :             :                 {
     636                 :       54736 :                   int cost = (m * (ix86_cost->int_load[2]
     637                 :       54736 :                                    + ix86_cost->int_store[2])
     638                 :       54736 :                              - (ix86_cost->sse_load[sse_cost_idx] +
     639                 :       54736 :                                 ix86_cost->sse_store[sse_cost_idx]));
     640                 :       54736 :                   igain += COSTS_N_INSNS (cost) / 2;
     641                 :             :                 }
     642                 :             :             }
     643                 :             : 
     644                 :     4671710 :           switch (GET_CODE (src))
     645                 :             :             {
     646                 :      477549 :             case ASHIFT:
     647                 :      477549 :             case ASHIFTRT:
     648                 :      477549 :             case LSHIFTRT:
     649                 :      477549 :               if (m == 2)
     650                 :             :                 {
     651                 :       17087 :                   if (INTVAL (XEXP (src, 1)) >= 32)
     652                 :       11543 :                     igain += ix86_cost->add;
     653                 :             :                   /* Gain for extend highpart case.  */
     654                 :        5544 :                   else if (GET_CODE (XEXP (src, 0)) == ASHIFT)
     655                 :           0 :                     igain += ix86_cost->shift_const - ix86_cost->sse_op;
     656                 :             :                   else
     657                 :        5544 :                     igain += ix86_cost->shift_const;
     658                 :             :                 }
     659                 :             : 
     660                 :      477549 :               igain += ix86_cost->shift_const - ix86_cost->sse_op;
     661                 :             : 
     662                 :      477549 :               if (CONST_INT_P (XEXP (src, 0)))
     663                 :           0 :                 igain -= vector_const_cost (XEXP (src, 0), bb);
     664                 :             :               break;
     665                 :             : 
     666                 :        3745 :             case ROTATE:
     667                 :        3745 :             case ROTATERT:
     668                 :        3745 :               igain += m * ix86_cost->shift_const;
     669                 :        3745 :               if (TARGET_AVX512VL)
     670                 :         192 :                 igain -= ix86_cost->sse_op;
     671                 :        3553 :               else if (smode == DImode)
     672                 :             :                 {
     673                 :         569 :                   int bits = INTVAL (XEXP (src, 1));
     674                 :         569 :                   if ((bits & 0x0f) == 0)
     675                 :         105 :                     igain -= ix86_cost->sse_op;
     676                 :         464 :                   else if ((bits & 0x07) == 0)
     677                 :          27 :                     igain -= 2 * ix86_cost->sse_op;
     678                 :             :                   else
     679                 :         437 :                     igain -= 3 * ix86_cost->sse_op;
     680                 :             :                 }
     681                 :        2984 :               else if (INTVAL (XEXP (src, 1)) == 16)
     682                 :         229 :                 igain -= ix86_cost->sse_op;
     683                 :             :               else
     684                 :        2755 :                 igain -= 2 * ix86_cost->sse_op;
     685                 :             :               break;
     686                 :             : 
     687                 :     2867679 :             case AND:
     688                 :     2867679 :             case IOR:
     689                 :     2867679 :             case XOR:
     690                 :     2867679 :             case PLUS:
     691                 :     2867679 :             case MINUS:
     692                 :     2867679 :               igain += m * ix86_cost->add - ix86_cost->sse_op;
     693                 :             :               /* Additional gain for andnot for targets without BMI.  */
     694                 :     2867679 :               if (GET_CODE (XEXP (src, 0)) == NOT
     695                 :        3599 :                   && !TARGET_BMI)
     696                 :        3590 :                 igain += m * ix86_cost->add;
     697                 :             : 
     698                 :     2867679 :               if (CONST_INT_P (XEXP (src, 0)))
     699                 :           0 :                 igain -= vector_const_cost (XEXP (src, 0), bb);
     700                 :     2867679 :               if (CONST_INT_P (XEXP (src, 1)))
     701                 :     1704030 :                 igain -= vector_const_cost (XEXP (src, 1), bb);
     702                 :     2867679 :               if (MEM_P (XEXP (src, 1)))
     703                 :             :                 {
     704                 :      101649 :                   if (!speed_p)
     705                 :       21067 :                     igain -= COSTS_N_BYTES (m == 2 ? 3 : 5);
     706                 :             :                   else
     707                 :       91111 :                     igain += COSTS_N_INSNS
     708                 :             :                                (m * ix86_cost->int_load[2]
     709                 :             :                                  - ix86_cost->sse_load[sse_cost_idx]) / 2;
     710                 :             :                 }
     711                 :             :               break;
     712                 :             : 
     713                 :       51646 :             case NEG:
     714                 :       51646 :             case NOT:
     715                 :       51646 :               igain -= ix86_cost->sse_op + COSTS_N_INSNS (1);
     716                 :             : 
     717                 :       51646 :               if (GET_CODE (XEXP (src, 0)) != ABS)
     718                 :             :                 {
     719                 :       51646 :                   igain += m * ix86_cost->add;
     720                 :       51646 :                   break;
     721                 :             :                 }
     722                 :             :               /* FALLTHRU */
     723                 :             : 
     724                 :        1028 :             case ABS:
     725                 :        1028 :             case SMAX:
     726                 :        1028 :             case SMIN:
     727                 :        1028 :             case UMAX:
     728                 :        1028 :             case UMIN:
     729                 :             :               /* We do not have any conditional move cost, estimate it as a
     730                 :             :                  reg-reg move.  Comparisons are costed as adds.  */
     731                 :        1028 :               igain += m * (COSTS_N_INSNS (2) + ix86_cost->add);
     732                 :             :               /* Integer SSE ops are all costed the same.  */
     733                 :        1028 :               igain -= ix86_cost->sse_op;
     734                 :        1028 :               break;
     735                 :             : 
     736                 :           0 :             case COMPARE:
     737                 :           0 :               if (XEXP (src, 1) != const0_rtx)
     738                 :             :                 {
     739                 :             :                   /* cmp vs. pxor;pshufd;ptest.  */
     740                 :           0 :                   igain += COSTS_N_INSNS (m - 3);
     741                 :             :                 }
     742                 :           0 :               else if (GET_CODE (XEXP (src, 0)) != AND)
     743                 :             :                 {
     744                 :             :                   /* test vs. pshufd;ptest.  */
     745                 :           0 :                   igain += COSTS_N_INSNS (m - 2);
     746                 :             :                 }
     747                 :           0 :               else if (GET_CODE (XEXP (XEXP (src, 0), 0)) != NOT)
     748                 :             :                 {
     749                 :             :                   /* and;test vs. pshufd;ptest.  */
     750                 :           0 :                   igain += COSTS_N_INSNS (2 * m - 2);
     751                 :             :                 }
     752                 :           0 :               else if (TARGET_BMI)
     753                 :             :                 {
     754                 :             :                   /* andn;test vs. pandn;pshufd;ptest.  */
     755                 :           0 :                   igain += COSTS_N_INSNS (2 * m - 3);
     756                 :             :                 }
     757                 :             :               else
     758                 :             :                 {
     759                 :             :                   /* not;and;test vs. pandn;pshufd;ptest.  */
     760                 :           0 :                   igain += COSTS_N_INSNS (3 * m - 3);
     761                 :             :                 }
     762                 :             :               break;
     763                 :             : 
     764                 :     1234774 :             case CONST_INT:
     765                 :     1234774 :               if (REG_P (dst))
     766                 :             :                 {
     767                 :     1234774 :                   if (!speed_p)
     768                 :             :                     {
     769                 :             :                       /* xor (2 bytes) vs. xorps (3 bytes).  */
     770                 :      244908 :                       if (src == const0_rtx)
     771                 :      139405 :                         igain -= COSTS_N_BYTES (1);
     772                 :             :                       /* movdi_internal vs. movv2di_internal.  */
     773                 :             :                       /* => mov (5 bytes) vs. movaps (7 bytes).  */
     774                 :      105503 :                       else if (x86_64_immediate_operand (src, SImode))
     775                 :       93295 :                         igain -= COSTS_N_BYTES (2);
     776                 :             :                       else
     777                 :             :                         /* ??? Larger immediate constants are placed in the
     778                 :             :                            constant pool, where the size benefit/impact of
     779                 :             :                            STV conversion is affected by whether and how
     780                 :             :                            often each constant pool entry is shared/reused.
     781                 :             :                            The value below is empirically derived from the
     782                 :             :                            CSiBE benchmark (and the optimal value may drift
     783                 :             :                            over time).  */
     784                 :             :                         igain += COSTS_N_BYTES (0);
     785                 :             :                     }
     786                 :             :                   else
     787                 :             :                     {
     788                 :             :                       /* DImode can be immediate for TARGET_64BIT
     789                 :             :                          and SImode always.  */
     790                 :      989866 :                       igain += m * COSTS_N_INSNS (1);
     791                 :      989866 :                       igain -= vector_const_cost (src, bb);
     792                 :             :                     }
     793                 :             :                 }
     794                 :           0 :               else if (MEM_P (dst))
     795                 :             :                 {
     796                 :           0 :                   igain += (m * ix86_cost->int_store[2]
     797                 :           0 :                             - ix86_cost->sse_store[sse_cost_idx]);
     798                 :           0 :                   igain -= vector_const_cost (src, bb);
     799                 :             :                 }
     800                 :             :               break;
     801                 :             : 
     802                 :       35289 :             case VEC_SELECT:
     803                 :       35289 :               if (XVECEXP (XEXP (src, 1), 0, 0) == const0_rtx)
     804                 :             :                 {
     805                 :             :                   // movd (4 bytes) replaced with movdqa (4 bytes).
     806                 :       26900 :                   if (!!speed_p)
     807                 :       24187 :                     igain += COSTS_N_INSNS (ix86_cost->sse_to_integer
     808                 :             :                                             - ix86_cost->xmm_move) / 2;
     809                 :             :                 }
     810                 :             :               else
     811                 :             :                 {
     812                 :             :                   // pshufd; movd replaced with pshufd.
     813                 :        8389 :                   if (!speed_p)
     814                 :         599 :                     igain += COSTS_N_BYTES (4);
     815                 :             :                   else
     816                 :        7790 :                     igain += ix86_cost->sse_to_integer;
     817                 :             :                 }
     818                 :             :               break;
     819                 :             : 
     820                 :           0 :             default:
     821                 :           0 :               gcc_unreachable ();
     822                 :             :             }
     823                 :             :         }
     824                 :             : 
     825                 :    11782453 :       if (speed_p)
     826                 :    10541150 :         weighted_gain += bb_freq * igain;
     827                 :    11785166 :       gain += igain;
     828                 :             : 
     829                 :    11785166 :       if (igain != 0 && dump_file)
     830                 :             :         {
     831                 :          99 :           fprintf (dump_file, "  Instruction gain %d with bb_freq %.2f for",
     832                 :             :                    igain, bb_freq.to_double ());
     833                 :          99 :           dump_insn_slim (dump_file, insn);
     834                 :             :         }
     835                 :             :     }
     836                 :             : 
     837                 :     6014612 :   if (dump_file)
     838                 :             :     {
     839                 :         138 :       fprintf (dump_file, "  Instruction conversion gain: %d, \n",
     840                 :             :                gain);
     841                 :         138 :       fprintf (dump_file, "  Registers conversion cost: %d\n",
     842                 :             :                cost_sse_integer);
     843                 :         138 :       fprintf (dump_file, "  Weighted instruction conversion gain: %.2f, \n",
     844                 :             :                weighted_gain.to_double ());
     845                 :         138 :       fprintf (dump_file, "  Weighted registers conversion cost: %.2f\n",
     846                 :             :                weighted_cost_sse_integer.to_double ());
     847                 :             :     }
     848                 :             : 
     849                 :     6014612 :   if (weighted_gain != weighted_cost_sse_integer)
     850                 :     4897570 :     return weighted_gain > weighted_cost_sse_integer;
     851                 :             :   else
     852                 :     1117042 :     return gain > cost_sse_integer;;
     853                 :             : }
     854                 :             : 
     855                 :             : /* Insert generated conversion instruction sequence INSNS
     856                 :             :    after instruction AFTER.  New BB may be required in case
     857                 :             :    instruction has EH region attached.  */
     858                 :             : 
     859                 :             : void
     860                 :       29416 : scalar_chain::emit_conversion_insns (rtx insns, rtx_insn *after)
     861                 :             : {
     862                 :       29416 :   if (!control_flow_insn_p (after))
     863                 :             :     {
     864                 :       29248 :       emit_insn_after (insns, after);
     865                 :       29248 :       return;
     866                 :             :     }
     867                 :             : 
     868                 :         168 :   basic_block bb = BLOCK_FOR_INSN (after);
     869                 :         168 :   edge e = find_fallthru_edge (bb->succs);
     870                 :         168 :   gcc_assert (e);
     871                 :             : 
     872                 :         168 :   basic_block new_bb = split_edge (e);
     873                 :         168 :   emit_insn_after (insns, BB_HEAD (new_bb));
     874                 :             : }
     875                 :             : 
     876                 :             : } // anon namespace
     877                 :             : 
     878                 :             : /* Generate the canonical SET_SRC to move GPR to a VMODE vector register,
     879                 :             :    zeroing the upper parts.  */
     880                 :             : 
     881                 :             : static rtx
     882                 :      179290 : gen_gpr_to_xmm_move_src (enum machine_mode vmode, rtx gpr)
     883                 :             : {
     884                 :      358580 :   switch (GET_MODE_NUNITS (vmode))
     885                 :             :     {
     886                 :          12 :     case 1:
     887                 :          12 :       return gen_rtx_SUBREG (vmode, gpr, 0);
     888                 :      178807 :     case 2:
     889                 :      357614 :       return gen_rtx_VEC_CONCAT (vmode, gpr,
     890                 :             :                                  CONST0_RTX (GET_MODE_INNER (vmode)));
     891                 :         471 :     default:
     892                 :         471 :       return gen_rtx_VEC_MERGE (vmode, gen_rtx_VEC_DUPLICATE (vmode, gpr),
     893                 :             :                                 CONST0_RTX (vmode), GEN_INT (HOST_WIDE_INT_1U));
     894                 :             :     }
     895                 :             : }
     896                 :             : 
     897                 :             : /* Make vector copies for all register REGNO definitions
     898                 :             :    and replace its uses in a chain.  */
     899                 :             : 
     900                 :             : void
     901                 :        7872 : scalar_chain::make_vector_copies (rtx_insn *insn, rtx reg)
     902                 :             : {
     903                 :        7872 :   rtx vreg = *defs_map.get (reg);
     904                 :             : 
     905                 :        7872 :   start_sequence ();
     906                 :        7872 :   if (!TARGET_INTER_UNIT_MOVES_TO_VEC)
     907                 :             :     {
     908                 :           0 :       rtx tmp = assign_386_stack_local (smode, SLOT_STV_TEMP);
     909                 :           0 :       if (smode == DImode && !TARGET_64BIT)
     910                 :             :         {
     911                 :           0 :           emit_move_insn (adjust_address (tmp, SImode, 0),
     912                 :             :                           gen_rtx_SUBREG (SImode, reg, 0));
     913                 :           0 :           emit_move_insn (adjust_address (tmp, SImode, 4),
     914                 :             :                           gen_rtx_SUBREG (SImode, reg, 4));
     915                 :             :         }
     916                 :             :       else
     917                 :           0 :         emit_move_insn (copy_rtx (tmp), reg);
     918                 :           0 :       emit_insn (gen_rtx_SET (gen_rtx_SUBREG (vmode, vreg, 0),
     919                 :             :                               gen_gpr_to_xmm_move_src (vmode, tmp)));
     920                 :             :     }
     921                 :        7872 :   else if (!TARGET_64BIT && smode == DImode)
     922                 :             :     {
     923                 :        7824 :       if (TARGET_SSE4_1)
     924                 :             :         {
     925                 :         356 :           emit_insn (gen_sse2_loadld (gen_rtx_SUBREG (V4SImode, vreg, 0),
     926                 :             :                                       CONST0_RTX (V4SImode),
     927                 :             :                                       gen_rtx_SUBREG (SImode, reg, 0)));
     928                 :         356 :           emit_insn (gen_sse4_1_pinsrd (gen_rtx_SUBREG (V4SImode, vreg, 0),
     929                 :             :                                         gen_rtx_SUBREG (V4SImode, vreg, 0),
     930                 :             :                                         gen_rtx_SUBREG (SImode, reg, 4),
     931                 :             :                                         GEN_INT (2)));
     932                 :             :         }
     933                 :             :       else
     934                 :             :         {
     935                 :        7468 :           rtx tmp = gen_reg_rtx (DImode);
     936                 :        7468 :           emit_insn (gen_sse2_loadld (gen_rtx_SUBREG (V4SImode, vreg, 0),
     937                 :             :                                       CONST0_RTX (V4SImode),
     938                 :             :                                       gen_rtx_SUBREG (SImode, reg, 0)));
     939                 :        7468 :           emit_insn (gen_sse2_loadld (gen_rtx_SUBREG (V4SImode, tmp, 0),
     940                 :             :                                       CONST0_RTX (V4SImode),
     941                 :             :                                       gen_rtx_SUBREG (SImode, reg, 4)));
     942                 :        7468 :           emit_insn (gen_vec_interleave_lowv4si
     943                 :             :                      (gen_rtx_SUBREG (V4SImode, vreg, 0),
     944                 :             :                       gen_rtx_SUBREG (V4SImode, vreg, 0),
     945                 :             :                       gen_rtx_SUBREG (V4SImode, tmp, 0)));
     946                 :             :         }
     947                 :             :     }
     948                 :             :   else
     949                 :          48 :     emit_insn (gen_rtx_SET (gen_rtx_SUBREG (vmode, vreg, 0),
     950                 :             :                             gen_gpr_to_xmm_move_src (vmode, reg)));
     951                 :        7872 :   rtx_insn *seq = end_sequence ();
     952                 :        7872 :   emit_conversion_insns (seq, insn);
     953                 :             : 
     954                 :        7872 :   if (dump_file)
     955                 :           0 :     fprintf (dump_file,
     956                 :             :              "  Copied r%d to a vector register r%d for insn %d\n",
     957                 :           0 :              REGNO (reg), REGNO (vreg), INSN_UID (insn));
     958                 :        7872 : }
     959                 :             : 
     960                 :             : /* Copy the definition SRC of INSN inside the chain to DST for
     961                 :             :    scalar uses outside of the chain.  */
     962                 :             : 
     963                 :             : void
     964                 :       20792 : scalar_chain::convert_reg (rtx_insn *insn, rtx dst, rtx src)
     965                 :             : {
     966                 :       20792 :   start_sequence ();
     967                 :       20792 :   if (!TARGET_INTER_UNIT_MOVES_FROM_VEC)
     968                 :             :     {
     969                 :           0 :       rtx tmp = assign_386_stack_local (smode, SLOT_STV_TEMP);
     970                 :           0 :       emit_move_insn (tmp, src);
     971                 :           0 :       if (!TARGET_64BIT && smode == DImode)
     972                 :             :         {
     973                 :           0 :           emit_move_insn (gen_rtx_SUBREG (SImode, dst, 0),
     974                 :             :                           adjust_address (tmp, SImode, 0));
     975                 :           0 :           emit_move_insn (gen_rtx_SUBREG (SImode, dst, 4),
     976                 :             :                           adjust_address (tmp, SImode, 4));
     977                 :             :         }
     978                 :             :       else
     979                 :           0 :         emit_move_insn (dst, copy_rtx (tmp));
     980                 :             :     }
     981                 :       20792 :   else if (!TARGET_64BIT && smode == DImode)
     982                 :             :     {
     983                 :       20420 :       if (TARGET_SSE4_1)
     984                 :             :         {
     985                 :           0 :           rtx tmp = gen_rtx_PARALLEL (VOIDmode,
     986                 :             :                                       gen_rtvec (1, const0_rtx));
     987                 :           0 :           emit_insn
     988                 :           0 :               (gen_rtx_SET
     989                 :             :                (gen_rtx_SUBREG (SImode, dst, 0),
     990                 :             :                 gen_rtx_VEC_SELECT (SImode,
     991                 :             :                                     gen_rtx_SUBREG (V4SImode, src, 0),
     992                 :             :                                     tmp)));
     993                 :             : 
     994                 :           0 :           tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (1, const1_rtx));
     995                 :           0 :           emit_insn
     996                 :           0 :               (gen_rtx_SET
     997                 :             :                (gen_rtx_SUBREG (SImode, dst, 4),
     998                 :             :                 gen_rtx_VEC_SELECT (SImode,
     999                 :             :                                     gen_rtx_SUBREG (V4SImode, src, 0),
    1000                 :             :                                     tmp)));
    1001                 :             :         }
    1002                 :             :       else
    1003                 :             :         {
    1004                 :       20420 :           rtx vcopy = gen_reg_rtx (V2DImode);
    1005                 :       20420 :           emit_move_insn (vcopy, gen_rtx_SUBREG (V2DImode, src, 0));
    1006                 :       20420 :           emit_move_insn (gen_rtx_SUBREG (SImode, dst, 0),
    1007                 :             :                           gen_rtx_SUBREG (SImode, vcopy, 0));
    1008                 :       20420 :           emit_move_insn (vcopy,
    1009                 :             :                           gen_rtx_LSHIFTRT (V2DImode,
    1010                 :             :                                             vcopy, GEN_INT (32)));
    1011                 :       20420 :           emit_move_insn (gen_rtx_SUBREG (SImode, dst, 4),
    1012                 :             :                           gen_rtx_SUBREG (SImode, vcopy, 0));
    1013                 :             :         }
    1014                 :             :     }
    1015                 :             :   else
    1016                 :         372 :     emit_move_insn (dst, src);
    1017                 :             : 
    1018                 :       20792 :   rtx_insn *seq = end_sequence ();
    1019                 :       20792 :   emit_conversion_insns (seq, insn);
    1020                 :             : 
    1021                 :       20792 :   if (dump_file)
    1022                 :           0 :     fprintf (dump_file,
    1023                 :             :              "  Copied r%d to a scalar register r%d for insn %d\n",
    1024                 :           0 :              REGNO (src), REGNO (dst), INSN_UID (insn));
    1025                 :       20792 : }
    1026                 :             : 
    1027                 :             : /* Helper function to convert immediate constant X to vmode.  */
    1028                 :             : static rtx
    1029                 :       44195 : smode_convert_cst (rtx x, enum machine_mode vmode)
    1030                 :             : {
    1031                 :             :   /* Prefer all ones vector in case of -1.  */
    1032                 :       44195 :   if (constm1_operand (x, GET_MODE (x)))
    1033                 :         900 :     return CONSTM1_RTX (vmode);
    1034                 :             : 
    1035                 :       43295 :   unsigned n = GET_MODE_NUNITS (vmode);
    1036                 :       43295 :   rtx *v = XALLOCAVEC (rtx, n);
    1037                 :       43295 :   v[0] = x;
    1038                 :       49045 :   for (unsigned i = 1; i < n; ++i)
    1039                 :        5750 :     v[i] = const0_rtx;
    1040                 :       43295 :   return gen_rtx_CONST_VECTOR (vmode, gen_rtvec_v (n, v));
    1041                 :             : }
    1042                 :             : 
    1043                 :             : /* Convert operand OP in INSN.  We should handle
    1044                 :             :    memory operands and uninitialized registers.
    1045                 :             :    All other register uses are converted during
    1046                 :             :    registers conversion.  */
    1047                 :             : 
    1048                 :             : void
    1049                 :      252196 : scalar_chain::convert_op (rtx *op, rtx_insn *insn)
    1050                 :             : {
    1051                 :      252196 :   rtx tmp;
    1052                 :             : 
    1053                 :      252196 :   if (GET_MODE (*op) == V1TImode)
    1054                 :             :     return;
    1055                 :             : 
    1056                 :      252169 :   *op = copy_rtx_if_shared (*op);
    1057                 :             : 
    1058                 :      252169 :   if (GET_CODE (*op) == NOT
    1059                 :      252169 :       || GET_CODE (*op) == ASHIFT)
    1060                 :             :     {
    1061                 :        3490 :       convert_op (&XEXP (*op, 0), insn);
    1062                 :        3490 :       PUT_MODE (*op, vmode);
    1063                 :             :     }
    1064                 :             :   else if (MEM_P (*op))
    1065                 :             :     {
    1066                 :      179242 :       rtx_insn *movabs = NULL;
    1067                 :             : 
    1068                 :             :       /* Emit MOVABS to load from a 64-bit absolute address to a GPR.  */
    1069                 :      179242 :       if (!memory_operand (*op, GET_MODE (*op)))
    1070                 :             :         {
    1071                 :           0 :           tmp = gen_reg_rtx (GET_MODE (*op));
    1072                 :           0 :           movabs = emit_insn_before (gen_rtx_SET (tmp, *op), insn);
    1073                 :             : 
    1074                 :           0 :           *op = tmp;
    1075                 :             :         }
    1076                 :             : 
    1077                 :      179242 :       tmp = gen_rtx_SUBREG (vmode, gen_reg_rtx (GET_MODE (*op)), 0);
    1078                 :             : 
    1079                 :      179242 :       rtx_insn *eh_insn
    1080                 :      179242 :         = emit_insn_before (gen_rtx_SET (copy_rtx (tmp),
    1081                 :             :                                          gen_gpr_to_xmm_move_src (vmode, *op)),
    1082                 :      179242 :                             insn);
    1083                 :             : 
    1084                 :      179242 :       if (cfun->can_throw_non_call_exceptions)
    1085                 :             :         {
    1086                 :             :           /* Handle REG_EH_REGION note.  */
    1087                 :      175903 :           rtx note = find_reg_note (insn, REG_EH_REGION, NULL_RTX);
    1088                 :      175903 :           if (note)
    1089                 :             :             {
    1090                 :        4744 :               if (movabs)
    1091                 :           0 :                 eh_insn = movabs;
    1092                 :        4744 :               control_flow_insns.safe_push (eh_insn);
    1093                 :        4744 :               add_reg_note (eh_insn, REG_EH_REGION, XEXP (note, 0));
    1094                 :             :             }
    1095                 :             :         }
    1096                 :             : 
    1097                 :      179242 :       *op = tmp;
    1098                 :             : 
    1099                 :      179242 :       if (dump_file)
    1100                 :           0 :         fprintf (dump_file, "  Preloading operand for insn %d into r%d\n",
    1101                 :           0 :                  INSN_UID (insn), reg_or_subregno (tmp));
    1102                 :             :     }
    1103                 :             :   else if (REG_P (*op))
    1104                 :       63010 :     *op = gen_rtx_SUBREG (vmode, *op, 0);
    1105                 :             :   else if (CONST_SCALAR_INT_P (*op))
    1106                 :             :     {
    1107                 :        6427 :       rtx vec_cst = smode_convert_cst (*op, vmode);
    1108                 :             : 
    1109                 :        6427 :       if (!standard_sse_constant_p (vec_cst, vmode))
    1110                 :             :         {
    1111                 :        2717 :           start_sequence ();
    1112                 :        2717 :           vec_cst = validize_mem (force_const_mem (vmode, vec_cst));
    1113                 :        2717 :           rtx_insn *seq = end_sequence ();
    1114                 :        2717 :           emit_insn_before (seq, insn);
    1115                 :             :         }
    1116                 :             : 
    1117                 :        6427 :       tmp = gen_rtx_SUBREG (vmode, gen_reg_rtx (smode), 0);
    1118                 :             : 
    1119                 :        6427 :       emit_insn_before (gen_move_insn (copy_rtx (tmp), vec_cst), insn);
    1120                 :        6427 :       *op = tmp;
    1121                 :             :     }
    1122                 :             :   else
    1123                 :             :     {
    1124                 :           0 :       gcc_assert (SUBREG_P (*op));
    1125                 :           0 :       gcc_assert (GET_MODE (*op) == vmode);
    1126                 :             :     }
    1127                 :             : }
    1128                 :             : 
    1129                 :             : /* Convert CCZmode COMPARE to vector mode.  */
    1130                 :             : 
    1131                 :             : rtx
    1132                 :           6 : scalar_chain::convert_compare (rtx op1, rtx op2, rtx_insn *insn)
    1133                 :             : {
    1134                 :           6 :   rtx src, tmp;
    1135                 :             : 
    1136                 :             :   /* Handle any REG_EQUAL notes.  */
    1137                 :           6 :   tmp = find_reg_equal_equiv_note (insn);
    1138                 :           6 :   if (tmp)
    1139                 :             :     {
    1140                 :           1 :       if (GET_CODE (XEXP (tmp, 0)) == COMPARE
    1141                 :           1 :           && GET_MODE (XEXP (tmp, 0)) == CCZmode
    1142                 :           1 :           && REG_P (XEXP (XEXP (tmp, 0), 0)))
    1143                 :             :         {
    1144                 :           1 :           rtx *op = &XEXP (XEXP (tmp, 0), 1);
    1145                 :           1 :           if (CONST_SCALAR_INT_P (*op))
    1146                 :             :             {
    1147                 :           1 :               if (constm1_operand (*op, GET_MODE (*op)))
    1148                 :           0 :                 *op = CONSTM1_RTX (vmode);
    1149                 :             :               else
    1150                 :             :                 {
    1151                 :           1 :                   unsigned n = GET_MODE_NUNITS (vmode);
    1152                 :           1 :                   rtx *v = XALLOCAVEC (rtx, n);
    1153                 :           1 :                   v[0] = *op;
    1154                 :           1 :                   for (unsigned i = 1; i < n; ++i)
    1155                 :           0 :                     v[i] = const0_rtx;
    1156                 :           1 :                   *op = gen_rtx_CONST_VECTOR (vmode, gen_rtvec_v (n, v));
    1157                 :             :                 }
    1158                 :             :               tmp = NULL_RTX;
    1159                 :             :             }
    1160                 :           0 :           else if (REG_P (*op))
    1161                 :             :             tmp = NULL_RTX;
    1162                 :             :         }
    1163                 :             : 
    1164                 :             :       if (tmp)
    1165                 :           0 :         remove_note (insn, tmp);
    1166                 :             :     }
    1167                 :             : 
    1168                 :             :   /* Comparison against anything other than zero, requires an XOR.  */
    1169                 :           6 :   if (op2 != const0_rtx)
    1170                 :             :     {
    1171                 :           4 :       convert_op (&op1, insn);
    1172                 :           4 :       convert_op (&op2, insn);
    1173                 :             :       /* If both operands are MEMs, explicitly load the OP1 into TMP.  */
    1174                 :           4 :       if (MEM_P (op1) && MEM_P (op2))
    1175                 :             :         {
    1176                 :           0 :           tmp = gen_reg_rtx (vmode);
    1177                 :           0 :           emit_insn_before (gen_rtx_SET (tmp, op1), insn);
    1178                 :           0 :           src = tmp;
    1179                 :             :         }
    1180                 :             :       else
    1181                 :             :         src = op1;
    1182                 :           4 :       src = gen_rtx_XOR (vmode, src, op2);
    1183                 :             :     }
    1184                 :           2 :   else if (GET_CODE (op1) == AND
    1185                 :           0 :            && GET_CODE (XEXP (op1, 0)) == NOT)
    1186                 :             :     {
    1187                 :           0 :       rtx op11 = XEXP (XEXP (op1, 0), 0);
    1188                 :           0 :       rtx op12 = XEXP (op1, 1);
    1189                 :           0 :       convert_op (&op11, insn);
    1190                 :           0 :       convert_op (&op12, insn);
    1191                 :           0 :       if (!REG_P (op11))
    1192                 :             :         {
    1193                 :           0 :           tmp = gen_reg_rtx (vmode);
    1194                 :           0 :           emit_insn_before (gen_rtx_SET (tmp, op11), insn);
    1195                 :           0 :           op11 = tmp;
    1196                 :             :         }
    1197                 :           0 :       src = gen_rtx_AND (vmode, gen_rtx_NOT (vmode, op11), op12);
    1198                 :           0 :     }
    1199                 :           2 :   else if (GET_CODE (op1) == AND)
    1200                 :             :     {
    1201                 :           0 :       rtx op11 = XEXP (op1, 0);
    1202                 :           0 :       rtx op12 = XEXP (op1, 1);
    1203                 :           0 :       convert_op (&op11, insn);
    1204                 :           0 :       convert_op (&op12, insn);
    1205                 :           0 :       if (!REG_P (op11))
    1206                 :             :         {
    1207                 :           0 :           tmp = gen_reg_rtx (vmode);
    1208                 :           0 :           emit_insn_before (gen_rtx_SET (tmp, op11), insn);
    1209                 :           0 :           op11 = tmp;
    1210                 :             :         }
    1211                 :           0 :       return gen_rtx_UNSPEC (CCZmode, gen_rtvec (2, op11, op12),
    1212                 :             :                              UNSPEC_PTEST);
    1213                 :             :     }
    1214                 :             :   else
    1215                 :             :     {
    1216                 :           2 :       convert_op (&op1, insn);
    1217                 :           2 :       src = op1;
    1218                 :             :     }
    1219                 :             : 
    1220                 :           6 :   if (!REG_P (src))
    1221                 :             :     {
    1222                 :           4 :       tmp = gen_reg_rtx (vmode);
    1223                 :           4 :       emit_insn_before (gen_rtx_SET (tmp, src), insn);
    1224                 :           4 :       src = tmp;
    1225                 :             :     }
    1226                 :             : 
    1227                 :           6 :   if (vmode == V2DImode)
    1228                 :             :     {
    1229                 :           0 :       tmp = gen_reg_rtx (vmode);
    1230                 :           0 :       emit_insn_before (gen_vec_interleave_lowv2di (tmp, src, src), insn);
    1231                 :           0 :       src = tmp;
    1232                 :             :     }
    1233                 :           6 :   else if (vmode == V4SImode)
    1234                 :             :     {
    1235                 :           0 :       tmp = gen_reg_rtx (vmode);
    1236                 :           0 :       emit_insn_before (gen_sse2_pshufd (tmp, src, const0_rtx), insn);
    1237                 :           0 :       src = tmp;
    1238                 :             :     }
    1239                 :             : 
    1240                 :           6 :   return gen_rtx_UNSPEC (CCZmode, gen_rtvec (2, src, src), UNSPEC_PTEST);
    1241                 :             : }
    1242                 :             : 
    1243                 :             : /* Helper function for converting INSN to vector mode.  */
    1244                 :             : 
    1245                 :             : void
    1246                 :     1316177 : scalar_chain::convert_insn_common (rtx_insn *insn)
    1247                 :             : {
    1248                 :             :   /* Generate copies for out-of-chain uses of defs and adjust debug uses.  */
    1249                 :     2003503 :   for (df_ref ref = DF_INSN_DEFS (insn); ref; ref = DF_REF_NEXT_LOC (ref))
    1250                 :      687326 :     if (bitmap_bit_p (defs_conv, DF_REF_REGNO (ref)))
    1251                 :             :       {
    1252                 :       22244 :         df_link *use;
    1253                 :       42667 :         for (use = DF_REF_CHAIN (ref); use; use = use->next)
    1254                 :       41215 :           if (NONDEBUG_INSN_P (DF_REF_INSN (use->ref))
    1255                 :       41215 :               && (DF_REF_REG_MEM_P (use->ref)
    1256                 :       36687 :                   || !bitmap_bit_p (insns, DF_REF_INSN_UID (use->ref))))
    1257                 :             :             break;
    1258                 :       22244 :         if (use)
    1259                 :       20792 :           convert_reg (insn, DF_REF_REG (ref),
    1260                 :       20792 :                        *defs_map.get (regno_reg_rtx [DF_REF_REGNO (ref)]));
    1261                 :        1452 :         else if (MAY_HAVE_DEBUG_BIND_INSNS)
    1262                 :             :           {
    1263                 :             :             /* If we generated a scalar copy we can leave debug-insns
    1264                 :             :                as-is, if not, we have to adjust them.  */
    1265                 :        1360 :             auto_vec<rtx_insn *, 5> to_reset_debug_insns;
    1266                 :        4154 :             for (use = DF_REF_CHAIN (ref); use; use = use->next)
    1267                 :        2794 :               if (DEBUG_INSN_P (DF_REF_INSN (use->ref)))
    1268                 :             :                 {
    1269                 :         895 :                   rtx_insn *debug_insn = DF_REF_INSN (use->ref);
    1270                 :             :                   /* If there's a reaching definition outside of the
    1271                 :             :                      chain we have to reset.  */
    1272                 :         895 :                   df_link *def;
    1273                 :        3771 :                   for (def = DF_REF_CHAIN (use->ref); def; def = def->next)
    1274                 :        3087 :                     if (!bitmap_bit_p (insns, DF_REF_INSN_UID (def->ref)))
    1275                 :             :                       break;
    1276                 :         895 :                   if (def)
    1277                 :         211 :                     to_reset_debug_insns.safe_push (debug_insn);
    1278                 :             :                   else
    1279                 :             :                     {
    1280                 :         684 :                       *DF_REF_REAL_LOC (use->ref)
    1281                 :         684 :                         = *defs_map.get (regno_reg_rtx [DF_REF_REGNO (ref)]);
    1282                 :         684 :                       df_insn_rescan (debug_insn);
    1283                 :             :                     }
    1284                 :             :                 }
    1285                 :             :             /* Have to do the reset outside of the DF_CHAIN walk to not
    1286                 :             :                disrupt it.  */
    1287                 :        2931 :             while (!to_reset_debug_insns.is_empty ())
    1288                 :             :               {
    1289                 :         211 :                 rtx_insn *debug_insn = to_reset_debug_insns.pop ();
    1290                 :         211 :                 INSN_VAR_LOCATION_LOC (debug_insn) = gen_rtx_UNKNOWN_VAR_LOC ();
    1291                 :         211 :                 df_insn_rescan_debug_internal (debug_insn);
    1292                 :             :               }
    1293                 :        1360 :           }
    1294                 :             :       }
    1295                 :             : 
    1296                 :             :   /* Replace uses in this insn with the defs we use in the chain.  */
    1297                 :     3283462 :   for (df_ref ref = DF_INSN_USES (insn); ref; ref = DF_REF_NEXT_LOC (ref))
    1298                 :     1967285 :     if (!DF_REF_REG_MEM_P (ref))
    1299                 :      708137 :       if (rtx *vreg = defs_map.get (regno_reg_rtx[DF_REF_REGNO (ref)]))
    1300                 :             :         {
    1301                 :             :           /* Also update a corresponding REG_DEAD note.  */
    1302                 :       33890 :           rtx note = find_reg_note (insn, REG_DEAD, DF_REF_REG (ref));
    1303                 :       33890 :           if (note)
    1304                 :       22443 :             XEXP (note, 0) = *vreg;
    1305                 :       33890 :           *DF_REF_REAL_LOC (ref) = *vreg;
    1306                 :             :         }
    1307                 :     1316177 : }
    1308                 :             : 
    1309                 :             : /* Convert INSN which is an SImode or DImode rotation by a constant
    1310                 :             :    to vector mode.  CODE is either ROTATE or ROTATERT with operands
    1311                 :             :    OP0 and OP1.  Returns the SET_SRC of the last instruction in the
    1312                 :             :    resulting sequence, which is emitted before INSN.  */
    1313                 :             : 
    1314                 :             : rtx
    1315                 :          92 : general_scalar_chain::convert_rotate (enum rtx_code code, rtx op0, rtx op1,
    1316                 :             :                                       rtx_insn *insn)
    1317                 :             : {
    1318                 :          92 :   int bits = INTVAL (op1);
    1319                 :          92 :   rtx pat, result;
    1320                 :             : 
    1321                 :          92 :   convert_op (&op0, insn);
    1322                 :          92 :   if (bits == 0)
    1323                 :           0 :     return op0;
    1324                 :             : 
    1325                 :          92 :   if (smode == DImode)
    1326                 :             :     {
    1327                 :          92 :       if (code == ROTATE)
    1328                 :          45 :         bits = 64 - bits;
    1329                 :          92 :       if (bits == 32)
    1330                 :             :         {
    1331                 :           0 :           rtx tmp1 = gen_reg_rtx (V4SImode);
    1332                 :           0 :           pat = gen_sse2_pshufd (tmp1, gen_lowpart (V4SImode, op0),
    1333                 :             :                                  GEN_INT (225));
    1334                 :           0 :           emit_insn_before (pat, insn);
    1335                 :           0 :           result = gen_lowpart (V2DImode, tmp1);
    1336                 :             :         }
    1337                 :          92 :       else if (TARGET_AVX512VL)
    1338                 :           0 :         result = simplify_gen_binary (code, V2DImode, op0, op1);
    1339                 :          92 :       else if (bits == 16 || bits == 48)
    1340                 :             :         {
    1341                 :           0 :           rtx tmp1 = gen_reg_rtx (V8HImode);
    1342                 :           0 :           pat = gen_sse2_pshuflw (tmp1, gen_lowpart (V8HImode, op0),
    1343                 :             :                                   GEN_INT (bits == 16 ? 57 : 147));
    1344                 :           0 :           emit_insn_before (pat, insn);
    1345                 :           0 :           result = gen_lowpart (V2DImode, tmp1);
    1346                 :             :         }
    1347                 :          92 :       else if ((bits & 0x07) == 0)
    1348                 :             :         {
    1349                 :           0 :           rtx tmp1 = gen_reg_rtx (V4SImode);
    1350                 :           0 :           pat = gen_sse2_pshufd (tmp1, gen_lowpart (V4SImode, op0),
    1351                 :             :                                  GEN_INT (68));
    1352                 :           0 :           emit_insn_before (pat, insn);
    1353                 :           0 :           rtx tmp2 = gen_reg_rtx (V1TImode);
    1354                 :           0 :           pat = gen_sse2_lshrv1ti3 (tmp2, gen_lowpart (V1TImode, tmp1),
    1355                 :             :                                     GEN_INT (bits));
    1356                 :           0 :           emit_insn_before (pat, insn);
    1357                 :           0 :           result = gen_lowpart (V2DImode, tmp2);
    1358                 :             :         }
    1359                 :             :       else
    1360                 :             :         {
    1361                 :          92 :           rtx tmp1 = gen_reg_rtx (V4SImode);
    1362                 :          92 :           pat = gen_sse2_pshufd (tmp1, gen_lowpart (V4SImode, op0),
    1363                 :             :                                  GEN_INT (20));
    1364                 :          92 :           emit_insn_before (pat, insn);
    1365                 :          92 :           rtx tmp2 = gen_reg_rtx (V2DImode);
    1366                 :          92 :           pat = gen_lshrv2di3 (tmp2, gen_lowpart (V2DImode, tmp1),
    1367                 :             :                                GEN_INT (bits & 31));
    1368                 :          92 :           emit_insn_before (pat, insn);
    1369                 :          92 :           rtx tmp3 = gen_reg_rtx (V4SImode);
    1370                 :         139 :           pat = gen_sse2_pshufd (tmp3, gen_lowpart (V4SImode, tmp2),
    1371                 :             :                                  GEN_INT (bits > 32 ? 34 : 136));
    1372                 :          92 :           emit_insn_before (pat, insn);
    1373                 :          92 :           result = gen_lowpart (V2DImode, tmp3);
    1374                 :             :         }
    1375                 :             :     }
    1376                 :           0 :   else if (bits == 16)
    1377                 :             :     {
    1378                 :           0 :       rtx tmp1 = gen_reg_rtx (V8HImode);
    1379                 :           0 :       pat = gen_sse2_pshuflw (tmp1, gen_lowpart (V8HImode, op0), GEN_INT (225));
    1380                 :           0 :       emit_insn_before (pat, insn);
    1381                 :           0 :       result = gen_lowpart (V4SImode, tmp1);
    1382                 :             :     }
    1383                 :           0 :   else if (TARGET_AVX512VL)
    1384                 :           0 :     result = simplify_gen_binary (code, V4SImode, op0, op1);
    1385                 :             :   else
    1386                 :             :     {
    1387                 :           0 :       if (code == ROTATE)
    1388                 :           0 :         bits = 32 - bits;
    1389                 :             : 
    1390                 :           0 :       rtx tmp1 = gen_reg_rtx (V4SImode);
    1391                 :           0 :       emit_insn_before (gen_sse2_pshufd (tmp1, op0, GEN_INT (224)), insn);
    1392                 :           0 :       rtx tmp2 = gen_reg_rtx (V2DImode);
    1393                 :           0 :       pat = gen_lshrv2di3 (tmp2, gen_lowpart (V2DImode, tmp1),
    1394                 :             :                            GEN_INT (bits));
    1395                 :           0 :       emit_insn_before (pat, insn);
    1396                 :           0 :       result = gen_lowpart (V4SImode, tmp2);
    1397                 :             :     }
    1398                 :             : 
    1399                 :             :   return result;
    1400                 :             : }
    1401                 :             : 
    1402                 :             : /* Convert INSN to vector mode.  */
    1403                 :             : 
    1404                 :             : void
    1405                 :      422562 : general_scalar_chain::convert_insn (rtx_insn *insn)
    1406                 :             : {
    1407                 :      422562 :   rtx def_set = single_set (insn);
    1408                 :      422562 :   rtx src = SET_SRC (def_set);
    1409                 :      422562 :   rtx dst = SET_DEST (def_set);
    1410                 :      422562 :   rtx subreg;
    1411                 :             : 
    1412                 :      422562 :   if (MEM_P (dst) && !REG_P (src))
    1413                 :             :     {
    1414                 :             :       /* There are no scalar integer instructions and therefore
    1415                 :             :          temporary register usage is required.  */
    1416                 :         752 :       rtx tmp = gen_reg_rtx (smode);
    1417                 :         752 :       emit_conversion_insns (gen_move_insn (dst, tmp), insn);
    1418                 :         752 :       dst = gen_rtx_SUBREG (vmode, tmp, 0);
    1419                 :         752 :     }
    1420                 :      421810 :   else if (REG_P (dst) && GET_MODE (dst) == smode)
    1421                 :             :     {
    1422                 :             :       /* Replace the definition with a SUBREG to the definition we
    1423                 :             :          use inside the chain.  */
    1424                 :      220127 :       rtx *vdef = defs_map.get (dst);
    1425                 :      220127 :       if (vdef)
    1426                 :       22244 :         dst = *vdef;
    1427                 :      220127 :       dst = gen_rtx_SUBREG (vmode, dst, 0);
    1428                 :             :       /* IRA doesn't like to have REG_EQUAL/EQUIV notes when the SET_DEST
    1429                 :             :          is a non-REG_P.  So kill those off.  */
    1430                 :      220127 :       rtx note = find_reg_equal_equiv_note (insn);
    1431                 :      220127 :       if (note)
    1432                 :        9303 :         remove_note (insn, note);
    1433                 :             :     }
    1434                 :             : 
    1435                 :      422562 :   switch (GET_CODE (src))
    1436                 :             :     {
    1437                 :       29351 :     case PLUS:
    1438                 :       29351 :     case MINUS:
    1439                 :       29351 :     case IOR:
    1440                 :       29351 :     case XOR:
    1441                 :       29351 :     case AND:
    1442                 :       29351 :     case SMAX:
    1443                 :       29351 :     case SMIN:
    1444                 :       29351 :     case UMAX:
    1445                 :       29351 :     case UMIN:
    1446                 :       29351 :       convert_op (&XEXP (src, 1), insn);
    1447                 :             :       /* FALLTHRU */
    1448                 :             : 
    1449                 :       36601 :     case ABS:
    1450                 :       36601 :     case ASHIFT:
    1451                 :       36601 :     case ASHIFTRT:
    1452                 :       36601 :     case LSHIFTRT:
    1453                 :       36601 :       convert_op (&XEXP (src, 0), insn);
    1454                 :       36601 :       PUT_MODE (src, vmode);
    1455                 :       36601 :       break;
    1456                 :             : 
    1457                 :          92 :     case ROTATE:
    1458                 :          92 :     case ROTATERT:
    1459                 :          92 :       src = convert_rotate (GET_CODE (src), XEXP (src, 0), XEXP (src, 1),
    1460                 :             :                             insn);
    1461                 :          92 :       break;
    1462                 :             : 
    1463                 :         397 :     case NEG:
    1464                 :         397 :       src = XEXP (src, 0);
    1465                 :             : 
    1466                 :         397 :       if (GET_CODE (src) == ABS)
    1467                 :             :         {
    1468                 :           0 :           src = XEXP (src, 0);
    1469                 :           0 :           convert_op (&src, insn);
    1470                 :           0 :           subreg = gen_reg_rtx (vmode);
    1471                 :           0 :           emit_insn_before (gen_rtx_SET (subreg,
    1472                 :             :                                          gen_rtx_ABS (vmode, src)), insn);
    1473                 :           0 :           src = subreg;
    1474                 :             :         }
    1475                 :             :       else
    1476                 :         397 :         convert_op (&src, insn);
    1477                 :             : 
    1478                 :         397 :       subreg = gen_reg_rtx (vmode);
    1479                 :         397 :       emit_insn_before (gen_move_insn (subreg, CONST0_RTX (vmode)), insn);
    1480                 :         397 :       src = gen_rtx_MINUS (vmode, subreg, src);
    1481                 :         397 :       break;
    1482                 :             : 
    1483                 :         254 :     case NOT:
    1484                 :         254 :       src = XEXP (src, 0);
    1485                 :         254 :       convert_op (&src, insn);
    1486                 :         254 :       subreg = gen_reg_rtx (vmode);
    1487                 :         254 :       emit_insn_before (gen_move_insn (subreg, CONSTM1_RTX (vmode)), insn);
    1488                 :         254 :       src = gen_rtx_XOR (vmode, src, subreg);
    1489                 :         254 :       break;
    1490                 :             : 
    1491                 :      177138 :     case MEM:
    1492                 :      177138 :       if (!REG_P (dst))
    1493                 :      177138 :         convert_op (&src, insn);
    1494                 :             :       break;
    1495                 :             : 
    1496                 :      203090 :     case REG:
    1497                 :      203090 :       if (!MEM_P (dst))
    1498                 :        1407 :         convert_op (&src, insn);
    1499                 :             :       break;
    1500                 :             : 
    1501                 :           0 :     case SUBREG:
    1502                 :           0 :       gcc_assert (GET_MODE (src) == vmode);
    1503                 :             :       break;
    1504                 :             : 
    1505                 :           0 :     case COMPARE:
    1506                 :           0 :       dst = gen_rtx_REG (CCZmode, FLAGS_REG);
    1507                 :           0 :       src = convert_compare (XEXP (src, 0), XEXP (src, 1), insn);
    1508                 :           0 :       break;
    1509                 :             : 
    1510                 :        3422 :     case CONST_INT:
    1511                 :        3422 :       convert_op (&src, insn);
    1512                 :        3422 :       break;
    1513                 :             : 
    1514                 :        1568 :     case VEC_SELECT:
    1515                 :        1568 :       if (XVECEXP (XEXP (src, 1), 0, 0) == const0_rtx)
    1516                 :        1248 :         src = XEXP (src, 0);
    1517                 :         320 :       else if (smode == DImode)
    1518                 :             :         {
    1519                 :         176 :           rtx tmp = gen_lowpart (V1TImode, XEXP (src, 0));
    1520                 :         176 :           dst = gen_lowpart (V1TImode, dst);
    1521                 :         176 :           src = gen_rtx_LSHIFTRT (V1TImode, tmp, GEN_INT (64));
    1522                 :             :         }
    1523                 :             :       else
    1524                 :             :         {
    1525                 :         144 :           rtx tmp = XVECEXP (XEXP (src, 1), 0, 0);
    1526                 :         144 :           rtvec vec = gen_rtvec (4, tmp, tmp, tmp, tmp);
    1527                 :         144 :           rtx par = gen_rtx_PARALLEL (VOIDmode, vec);
    1528                 :         144 :           src = gen_rtx_VEC_SELECT (vmode, XEXP (src, 0), par);
    1529                 :             :         }
    1530                 :             :       break;
    1531                 :             : 
    1532                 :           0 :     default:
    1533                 :           0 :       gcc_unreachable ();
    1534                 :             :     }
    1535                 :             : 
    1536                 :      422562 :   SET_SRC (def_set) = src;
    1537                 :      422562 :   SET_DEST (def_set) = dst;
    1538                 :             : 
    1539                 :             :   /* Drop possible dead definitions.  */
    1540                 :      422562 :   PATTERN (insn) = def_set;
    1541                 :             : 
    1542                 :      422562 :   INSN_CODE (insn) = -1;
    1543                 :      422562 :   int patt = recog_memoized (insn);
    1544                 :      422562 :   if  (patt == -1)
    1545                 :           0 :     fatal_insn_not_found (insn);
    1546                 :      422562 :   df_insn_rescan (insn);
    1547                 :      422562 : }
    1548                 :             : 
    1549                 :             : /* Helper function to compute gain for loading an immediate constant.
    1550                 :             :    Typically, two movabsq for TImode vs. vmovdqa for V1TImode, but
    1551                 :             :    with numerous special cases.  */
    1552                 :             : 
    1553                 :             : static int
    1554                 :           5 : timode_immed_const_gain (rtx cst, basic_block bb)
    1555                 :             : {
    1556                 :             :   /* movabsq vs. movabsq+vmovq+vunpacklqdq.  */
    1557                 :           5 :   if (CONST_WIDE_INT_P (cst)
    1558                 :           4 :       && CONST_WIDE_INT_NUNITS (cst) == 2
    1559                 :           9 :       && CONST_WIDE_INT_ELT (cst, 0) == CONST_WIDE_INT_ELT (cst, 1))
    1560                 :           0 :     return optimize_bb_for_size_p (bb) ? -COSTS_N_BYTES (9)
    1561                 :             :                                        : -COSTS_N_INSNS (2);
    1562                 :             :   /* 2x movabsq ~ vmovdqa.  */
    1563                 :             :   return 0;
    1564                 :             : }
    1565                 :             : 
    1566                 :             : /* Return true it's cost profitable for for chain conversion.  */
    1567                 :             : 
    1568                 :             : bool
    1569                 :      451805 : timode_scalar_chain::compute_convert_gain ()
    1570                 :             : {
    1571                 :             :   /* Assume that if we have to move TImode values between units,
    1572                 :             :      then transforming this chain isn't worth it.  */
    1573                 :      451805 :   if (cost_sse_integer)
    1574                 :             :     return false;
    1575                 :             : 
    1576                 :      451805 :   bitmap_iterator bi;
    1577                 :      451805 :   unsigned insn_uid;
    1578                 :             : 
    1579                 :             :   /* Split ties to prefer V1TImode when not optimizing for size.  */
    1580                 :      451805 :   int gain = optimize_size ? 0 : 1;
    1581                 :      451805 :   sreal weighted_gain  = 0;
    1582                 :             : 
    1583                 :      451805 :   if (dump_file)
    1584                 :           0 :     fprintf (dump_file, "Computing gain for chain #%d...\n", chain_id);
    1585                 :             : 
    1586                 :     1345758 :   EXECUTE_IF_SET_IN_BITMAP (insns, 0, insn_uid, bi)
    1587                 :             :     {
    1588                 :      893953 :       rtx_insn *insn = DF_INSN_UID_GET (insn_uid)->insn;
    1589                 :      893953 :       rtx def_set = single_set (insn);
    1590                 :      893953 :       rtx src = SET_SRC (def_set);
    1591                 :      893953 :       rtx dst = SET_DEST (def_set);
    1592                 :      893953 :       HOST_WIDE_INT op1val;
    1593                 :      893953 :       basic_block bb = BLOCK_FOR_INSN (insn);
    1594                 :      893953 :       int scost, vcost;
    1595                 :      893953 :       int igain = 0;
    1596                 :      893953 :       profile_count entry_count = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count;
    1597                 :      893953 :       bool speed_p = optimize_bb_for_speed_p (bb);
    1598                 :      893953 :       sreal bb_freq = bb->count.to_sreal_scale (entry_count);
    1599                 :             : 
    1600                 :      893953 :       switch (GET_CODE (src))
    1601                 :             :         {
    1602                 :      441895 :         case REG:
    1603                 :      441895 :           if (!speed_p)
    1604                 :       10610 :             igain = MEM_P (dst) ? COSTS_N_BYTES (6) : COSTS_N_BYTES (3);
    1605                 :             :           else
    1606                 :             :             igain = COSTS_N_INSNS (1);
    1607                 :             :           break;
    1608                 :             : 
    1609                 :      402700 :         case MEM:
    1610                 :      402700 :           igain = !speed_p ? COSTS_N_BYTES (7) : COSTS_N_INSNS (1);
    1611                 :             :           break;
    1612                 :             : 
    1613                 :       11124 :         case CONST_INT:
    1614                 :       11124 :           if (MEM_P (dst)
    1615                 :       11124 :               && standard_sse_constant_p (src, V1TImode))
    1616                 :       10629 :             igain = !speed_p ? COSTS_N_BYTES (11) : 1;
    1617                 :             :           break;
    1618                 :             : 
    1619                 :       37963 :         case CONST_WIDE_INT:
    1620                 :             :           /* 2 x mov vs. vmovdqa.  */
    1621                 :       37963 :           if (MEM_P (dst))
    1622                 :       37790 :             igain = !speed_p ? COSTS_N_BYTES (3) : COSTS_N_INSNS (1);
    1623                 :             :           break;
    1624                 :             : 
    1625                 :          17 :         case NOT:
    1626                 :          17 :           if (MEM_P (dst))
    1627                 :       11545 :             igain = -COSTS_N_INSNS (1);
    1628                 :             :           break;
    1629                 :             : 
    1630                 :          12 :         case AND:
    1631                 :          12 :         case XOR:
    1632                 :          12 :         case IOR:
    1633                 :          12 :           if (!MEM_P (dst))
    1634                 :           6 :             igain = COSTS_N_INSNS (1);
    1635                 :          12 :           if (CONST_SCALAR_INT_P (XEXP (src, 1)))
    1636                 :           5 :             igain += timode_immed_const_gain (XEXP (src, 1), bb);
    1637                 :             :           break;
    1638                 :             : 
    1639                 :         126 :         case ASHIFT:
    1640                 :         126 :         case LSHIFTRT:
    1641                 :             :           /* See ix86_expand_v1ti_shift.  */
    1642                 :         126 :           op1val = INTVAL (XEXP (src, 1));
    1643                 :         126 :           if (!speed_p)
    1644                 :             :             {
    1645                 :          10 :               if (op1val == 64 || op1val == 65)
    1646                 :             :                 scost = COSTS_N_BYTES (5);
    1647                 :          10 :               else if (op1val >= 66)
    1648                 :             :                 scost = COSTS_N_BYTES (6);
    1649                 :          10 :               else if (op1val == 1)
    1650                 :             :                 scost = COSTS_N_BYTES (8);
    1651                 :             :               else
    1652                 :             :                 scost = COSTS_N_BYTES (9);
    1653                 :             : 
    1654                 :           9 :               if ((op1val & 7) == 0)
    1655                 :             :                 vcost = COSTS_N_BYTES (5);
    1656                 :          10 :               else if (op1val > 64)
    1657                 :             :                 vcost = COSTS_N_BYTES (10);
    1658                 :             :               else
    1659                 :          10 :                 vcost = TARGET_AVX ? COSTS_N_BYTES (19) : COSTS_N_BYTES (23);
    1660                 :             :             }
    1661                 :             :           else
    1662                 :             :             {
    1663                 :         116 :               scost = COSTS_N_INSNS (2);
    1664                 :         116 :               if ((op1val & 7) == 0)
    1665                 :             :                 vcost = COSTS_N_INSNS (1);
    1666                 :         114 :               else if (op1val > 64)
    1667                 :             :                 vcost = COSTS_N_INSNS (2);
    1668                 :             :               else
    1669                 :         110 :                 vcost = TARGET_AVX ? COSTS_N_INSNS (4) : COSTS_N_INSNS (5);
    1670                 :             :             }
    1671                 :         126 :           igain = scost - vcost;
    1672                 :         126 :           break;
    1673                 :             : 
    1674                 :         103 :         case ASHIFTRT:
    1675                 :             :           /* See ix86_expand_v1ti_ashiftrt.  */
    1676                 :         103 :           op1val = INTVAL (XEXP (src, 1));
    1677                 :         103 :           if (!speed_p)
    1678                 :             :             {
    1679                 :           7 :               if (op1val == 64 || op1val == 127)
    1680                 :             :                 scost = COSTS_N_BYTES (7);
    1681                 :           7 :               else if (op1val == 1)
    1682                 :             :                 scost = COSTS_N_BYTES (8);
    1683                 :           7 :               else if (op1val == 65)
    1684                 :             :                 scost = COSTS_N_BYTES (10);
    1685                 :           7 :               else if (op1val >= 66)
    1686                 :             :                 scost = COSTS_N_BYTES (11);
    1687                 :             :               else
    1688                 :             :                 scost = COSTS_N_BYTES (9);
    1689                 :             : 
    1690                 :           0 :               if (op1val == 127)
    1691                 :             :                 vcost = COSTS_N_BYTES (10);
    1692                 :           7 :               else if (op1val == 64)
    1693                 :             :                 vcost = COSTS_N_BYTES (14);
    1694                 :           7 :               else if (op1val == 96)
    1695                 :             :                 vcost = COSTS_N_BYTES (18);
    1696                 :           7 :               else if (op1val >= 111)
    1697                 :             :                 vcost = COSTS_N_BYTES (15);
    1698                 :           7 :               else if (TARGET_AVX2 && op1val == 32)
    1699                 :             :                 vcost = COSTS_N_BYTES (16);
    1700                 :           7 :               else if (TARGET_SSE4_1 && op1val == 32)
    1701                 :             :                 vcost = COSTS_N_BYTES (20);
    1702                 :           7 :               else if (op1val >= 96)
    1703                 :             :                 vcost = COSTS_N_BYTES (23);
    1704                 :           7 :               else if ((op1val & 7) == 0)
    1705                 :             :                 vcost = COSTS_N_BYTES (28);
    1706                 :           7 :               else if (TARGET_AVX2 && op1val < 32)
    1707                 :             :                 vcost = COSTS_N_BYTES (30);
    1708                 :           7 :               else if (op1val == 1 || op1val >= 64)
    1709                 :             :                 vcost = COSTS_N_BYTES (42);
    1710                 :             :               else
    1711                 :           7 :                 vcost = COSTS_N_BYTES (47);
    1712                 :             :             }
    1713                 :             :           else
    1714                 :             :             {
    1715                 :          96 :               if (op1val >= 65 && op1val <= 126)
    1716                 :             :                 scost = COSTS_N_INSNS (3);
    1717                 :             :               else
    1718                 :          96 :                 scost = COSTS_N_INSNS (2);
    1719                 :             : 
    1720                 :          96 :               if (op1val == 127)
    1721                 :             :                 vcost = COSTS_N_INSNS (2);
    1722                 :          96 :               else if (op1val == 64)
    1723                 :             :                 vcost = COSTS_N_INSNS (3);
    1724                 :          96 :               else if (op1val == 96)
    1725                 :             :                 vcost = COSTS_N_INSNS (3);
    1726                 :          96 :               else if (op1val >= 111)
    1727                 :             :                 vcost = COSTS_N_INSNS (3);
    1728                 :          96 :               else if (TARGET_SSE4_1 && op1val == 32)
    1729                 :             :                 vcost = COSTS_N_INSNS (3);
    1730                 :          96 :               else if (TARGET_SSE4_1
    1731                 :           0 :                        && (op1val == 8 || op1val == 16 || op1val == 24))
    1732                 :             :                 vcost = COSTS_N_INSNS (3);
    1733                 :          96 :               else if (op1val >= 96)
    1734                 :             :                 vcost = COSTS_N_INSNS (4);
    1735                 :          96 :               else if (TARGET_SSE4_1 && (op1val == 28 || op1val == 80))
    1736                 :             :                 vcost = COSTS_N_INSNS (4);
    1737                 :          96 :               else if ((op1val & 7) == 0)
    1738                 :             :                 vcost = COSTS_N_INSNS (5);
    1739                 :          96 :               else if (TARGET_AVX2 && op1val < 32)
    1740                 :             :                 vcost = COSTS_N_INSNS (6);
    1741                 :          96 :               else if (TARGET_SSE4_1 && op1val < 15)
    1742                 :             :                 vcost = COSTS_N_INSNS (6);
    1743                 :          96 :               else if (op1val == 1 || op1val >= 64)
    1744                 :             :                 vcost = COSTS_N_INSNS (8);
    1745                 :             :               else
    1746                 :           0 :                 vcost = COSTS_N_INSNS (9);
    1747                 :             :             }
    1748                 :         103 :           igain = scost - vcost;
    1749                 :         103 :           break;
    1750                 :             : 
    1751                 :           5 :         case ROTATE:
    1752                 :           5 :         case ROTATERT:
    1753                 :             :           /* See ix86_expand_v1ti_rotate.  */
    1754                 :           5 :           op1val = INTVAL (XEXP (src, 1));
    1755                 :           5 :           if (!speed_p)
    1756                 :             :             {
    1757                 :           0 :               scost = COSTS_N_BYTES (13);
    1758                 :           0 :               if ((op1val & 31) == 0)
    1759                 :             :                 vcost = COSTS_N_BYTES (5);
    1760                 :           0 :               else if ((op1val & 7) == 0)
    1761                 :           0 :                 vcost = TARGET_AVX ? COSTS_N_BYTES (13) : COSTS_N_BYTES (18);
    1762                 :           0 :               else if (op1val > 32 && op1val < 96)
    1763                 :             :                 vcost = COSTS_N_BYTES (24);
    1764                 :             :               else
    1765                 :           0 :                 vcost = COSTS_N_BYTES (19);
    1766                 :             :             }
    1767                 :             :           else
    1768                 :             :             {
    1769                 :           5 :               scost = COSTS_N_INSNS (3);
    1770                 :           5 :               if ((op1val & 31) == 0)
    1771                 :             :                 vcost = COSTS_N_INSNS (1);
    1772                 :           3 :               else if ((op1val & 7) == 0)
    1773                 :           1 :                 vcost = TARGET_AVX ? COSTS_N_INSNS (3) : COSTS_N_INSNS (4);
    1774                 :           2 :               else if (op1val > 32 && op1val < 96)
    1775                 :             :                 vcost = COSTS_N_INSNS (5);
    1776                 :             :               else
    1777                 :           2 :                 vcost = COSTS_N_INSNS (1);
    1778                 :             :             }
    1779                 :           5 :           igain = scost - vcost;
    1780                 :           5 :           break;
    1781                 :             : 
    1782                 :           8 :         case COMPARE:
    1783                 :           8 :           if (XEXP (src, 1) == const0_rtx)
    1784                 :             :             {
    1785                 :           4 :               if (GET_CODE (XEXP (src, 0)) == AND)
    1786                 :             :                 /* and;and;or (9 bytes) vs. ptest (5 bytes).  */
    1787                 :             :                 igain = !speed_p ? COSTS_N_BYTES (4) : COSTS_N_INSNS (2);
    1788                 :             :               /* or (3 bytes) vs. ptest (5 bytes).  */
    1789                 :           4 :               else if (!speed_p)
    1790                 :           0 :                 igain = -COSTS_N_BYTES (2);
    1791                 :             :             }
    1792                 :           4 :           else if (XEXP (src, 1) == const1_rtx)
    1793                 :             :             /* and;cmp -1 (7 bytes) vs. pcmpeqd;pxor;ptest (13 bytes).  */
    1794                 :           0 :             igain = !speed_p ? -COSTS_N_BYTES (6) : -COSTS_N_INSNS (1);
    1795                 :             :           break;
    1796                 :             : 
    1797                 :             :         default:
    1798                 :             :           break;
    1799                 :             :         }
    1800                 :             : 
    1801                 :     1765075 :       gain += igain;
    1802                 :      893949 :       if (speed_p)
    1803                 :      871126 :         weighted_gain += bb_freq * igain;
    1804                 :             : 
    1805                 :      893953 :       if (igain != 0 && dump_file)
    1806                 :             :         {
    1807                 :           0 :           fprintf (dump_file, "  Instruction gain %d with bb_freq %.2f for ",
    1808                 :             :                    igain, bb_freq.to_double ());
    1809                 :           0 :           dump_insn_slim (dump_file, insn);
    1810                 :             :         }
    1811                 :             :     }
    1812                 :             : 
    1813                 :      451805 :   if (dump_file)
    1814                 :           0 :     fprintf (dump_file, "  Total gain: %d, weighted gain %.2f\n",
    1815                 :             :              gain, weighted_gain.to_double ());
    1816                 :             : 
    1817                 :      451805 :   if (weighted_gain > (sreal) 0)
    1818                 :             :     return true;
    1819                 :             :   else
    1820                 :       12735 :     return gain > 0;
    1821                 :             : }
    1822                 :             : 
    1823                 :             : /* Fix uses of converted REG in debug insns.  */
    1824                 :             : 
    1825                 :             : void
    1826                 :      403473 : timode_scalar_chain::fix_debug_reg_uses (rtx reg)
    1827                 :             : {
    1828                 :      403473 :   if (!flag_var_tracking)
    1829                 :             :     return;
    1830                 :             : 
    1831                 :      356472 :   df_ref ref, next;
    1832                 :      741686 :   for (ref = DF_REG_USE_CHAIN (REGNO (reg)); ref; ref = next)
    1833                 :             :     {
    1834                 :      385214 :       rtx_insn *insn = DF_REF_INSN (ref);
    1835                 :             :       /* Make sure the next ref is for a different instruction,
    1836                 :             :          so that we're not affected by the rescan.  */
    1837                 :      385214 :       next = DF_REF_NEXT_REG (ref);
    1838                 :      385214 :       while (next && DF_REF_INSN (next) == insn)
    1839                 :           0 :         next = DF_REF_NEXT_REG (next);
    1840                 :             : 
    1841                 :      385214 :       if (DEBUG_INSN_P (insn))
    1842                 :             :         {
    1843                 :             :           /* It may be a debug insn with a TImode variable in
    1844                 :             :              register.  */
    1845                 :             :           bool changed = false;
    1846                 :          22 :           for (; ref != next; ref = DF_REF_NEXT_REG (ref))
    1847                 :             :             {
    1848                 :          11 :               rtx *loc = DF_REF_LOC (ref);
    1849                 :          11 :               if (REG_P (*loc) && GET_MODE (*loc) == V1TImode)
    1850                 :             :                 {
    1851                 :          11 :                   *loc = gen_rtx_SUBREG (TImode, *loc, 0);
    1852                 :          11 :                   changed = true;
    1853                 :             :                 }
    1854                 :             :             }
    1855                 :          11 :           if (changed)
    1856                 :          11 :             df_insn_rescan (insn);
    1857                 :             :         }
    1858                 :             :     }
    1859                 :             : }
    1860                 :             : 
    1861                 :             : /* Convert INSN from TImode to V1T1mode.  */
    1862                 :             : 
    1863                 :             : void
    1864                 :      893615 : timode_scalar_chain::convert_insn (rtx_insn *insn)
    1865                 :             : {
    1866                 :      893615 :   rtx def_set = single_set (insn);
    1867                 :      893615 :   rtx src = SET_SRC (def_set);
    1868                 :      893615 :   rtx dst = SET_DEST (def_set);
    1869                 :      893615 :   rtx tmp;
    1870                 :             : 
    1871                 :      893615 :   switch (GET_CODE (dst))
    1872                 :             :     {
    1873                 :      403479 :     case REG:
    1874                 :      403479 :       if (GET_MODE (dst) == TImode)
    1875                 :             :         {
    1876                 :      402899 :           PUT_MODE (dst, V1TImode);
    1877                 :      402899 :           fix_debug_reg_uses (dst);
    1878                 :             :         }
    1879                 :      403479 :       if (GET_MODE (dst) == V1TImode)
    1880                 :             :         {
    1881                 :             :           /* It might potentially be helpful to convert REG_EQUAL notes,
    1882                 :             :              but for now we just remove them.  */
    1883                 :      403473 :           rtx note = find_reg_equal_equiv_note (insn);
    1884                 :      403473 :           if (note)
    1885                 :         443 :             remove_note (insn, note);
    1886                 :             :         }
    1887                 :             :       break;
    1888                 :      490136 :     case MEM:
    1889                 :      490136 :       PUT_MODE (dst, V1TImode);
    1890                 :      490136 :       break;
    1891                 :             : 
    1892                 :           0 :     default:
    1893                 :           0 :       gcc_unreachable ();
    1894                 :             :     }
    1895                 :             : 
    1896                 :      893615 :   switch (GET_CODE (src))
    1897                 :             :     {
    1898                 :      441849 :     case REG:
    1899                 :      441849 :       if (GET_MODE (src) == TImode)
    1900                 :             :         {
    1901                 :         574 :           PUT_MODE (src, V1TImode);
    1902                 :         574 :           fix_debug_reg_uses (src);
    1903                 :             :         }
    1904                 :             :       break;
    1905                 :             : 
    1906                 :      402652 :     case MEM:
    1907                 :      402652 :       PUT_MODE (src, V1TImode);
    1908                 :      402652 :       break;
    1909                 :             : 
    1910                 :       37962 :     case CONST_WIDE_INT:
    1911                 :       37962 :       if (NONDEBUG_INSN_P (insn))
    1912                 :             :         {
    1913                 :             :           /* Since there are no instructions to store 128-bit constant,
    1914                 :             :              temporary register usage is required.  */
    1915                 :       37962 :           bool use_move;
    1916                 :       37962 :           start_sequence ();
    1917                 :       37962 :           tmp = ix86_convert_const_wide_int_to_broadcast (TImode, src);
    1918                 :       37962 :           if (tmp)
    1919                 :             :             {
    1920                 :         194 :               src = lowpart_subreg (V1TImode, tmp, TImode);
    1921                 :         194 :               use_move = true;
    1922                 :             :             }
    1923                 :             :           else
    1924                 :             :             {
    1925                 :       37768 :               src = smode_convert_cst (src, V1TImode);
    1926                 :       37768 :               src = validize_mem (force_const_mem (V1TImode, src));
    1927                 :       37768 :               use_move = MEM_P (dst);
    1928                 :             :             }
    1929                 :       37962 :           rtx_insn *seq = end_sequence ();
    1930                 :       37962 :           if (seq)
    1931                 :         195 :             emit_insn_before (seq, insn);
    1932                 :       37962 :           if (use_move)
    1933                 :             :             {
    1934                 :       37791 :               tmp = gen_reg_rtx (V1TImode);
    1935                 :       37791 :               emit_insn_before (gen_rtx_SET (tmp, src), insn);
    1936                 :       37791 :               src = tmp;
    1937                 :             :             }
    1938                 :             :         }
    1939                 :             :       break;
    1940                 :             : 
    1941                 :       11123 :     case CONST_INT:
    1942                 :       11123 :       switch (standard_sse_constant_p (src, TImode))
    1943                 :             :         {
    1944                 :       10902 :         case 1:
    1945                 :       10902 :           src = CONST0_RTX (GET_MODE (dst));
    1946                 :       10902 :           break;
    1947                 :         221 :         case 2:
    1948                 :         221 :           src = CONSTM1_RTX (GET_MODE (dst));
    1949                 :         221 :           break;
    1950                 :           0 :         default:
    1951                 :           0 :           gcc_unreachable ();
    1952                 :             :         }
    1953                 :       11123 :       if (MEM_P (dst))
    1954                 :             :         {
    1955                 :       10629 :           tmp = gen_reg_rtx (V1TImode);
    1956                 :       10629 :           emit_insn_before (gen_rtx_SET (tmp, src), insn);
    1957                 :       10629 :           src = tmp;
    1958                 :             :         }
    1959                 :             :       break;
    1960                 :             : 
    1961                 :           8 :     case AND:
    1962                 :           8 :       if (GET_CODE (XEXP (src, 0)) == NOT)
    1963                 :             :         {
    1964                 :           0 :           convert_op (&XEXP (XEXP (src, 0), 0), insn);
    1965                 :           0 :           convert_op (&XEXP (src, 1), insn);
    1966                 :           0 :           PUT_MODE (XEXP (src, 0), V1TImode);
    1967                 :           0 :           PUT_MODE (src, V1TImode);
    1968                 :           0 :           break;
    1969                 :             :         }
    1970                 :             :       /* FALLTHRU */
    1971                 :             : 
    1972                 :          11 :     case XOR:
    1973                 :          11 :     case IOR:
    1974                 :          11 :       convert_op (&XEXP (src, 0), insn);
    1975                 :          11 :       convert_op (&XEXP (src, 1), insn);
    1976                 :          11 :       PUT_MODE (src, V1TImode);
    1977                 :          11 :       if (MEM_P (dst))
    1978                 :             :         {
    1979                 :           5 :           tmp = gen_reg_rtx (V1TImode);
    1980                 :           5 :           emit_insn_before (gen_rtx_SET (tmp, src), insn);
    1981                 :           5 :           src = tmp;
    1982                 :             :         }
    1983                 :             :       break;
    1984                 :             : 
    1985                 :           1 :     case NOT:
    1986                 :           1 :       src = XEXP (src, 0);
    1987                 :           1 :       convert_op (&src, insn);
    1988                 :           1 :       tmp = gen_reg_rtx (V1TImode);
    1989                 :           1 :       emit_insn_before (gen_move_insn (tmp, CONSTM1_RTX (V1TImode)), insn);
    1990                 :           1 :       src = gen_rtx_XOR (V1TImode, src, tmp);
    1991                 :           1 :       if (MEM_P (dst))
    1992                 :             :         {
    1993                 :           0 :           tmp = gen_reg_rtx (V1TImode);
    1994                 :           0 :           emit_insn_before (gen_rtx_SET (tmp, src), insn);
    1995                 :           0 :           src = tmp;
    1996                 :             :         }
    1997                 :             :       break;
    1998                 :             : 
    1999                 :           6 :     case COMPARE:
    2000                 :           6 :       dst = gen_rtx_REG (CCZmode, FLAGS_REG);
    2001                 :           6 :       src = convert_compare (XEXP (src, 0), XEXP (src, 1), insn);
    2002                 :           6 :       break;
    2003                 :             : 
    2004                 :          11 :     case ASHIFT:
    2005                 :          11 :     case LSHIFTRT:
    2006                 :          11 :     case ASHIFTRT:
    2007                 :          11 :     case ROTATERT:
    2008                 :          11 :     case ROTATE:
    2009                 :          11 :       convert_op (&XEXP (src, 0), insn);
    2010                 :          11 :       PUT_MODE (src, V1TImode);
    2011                 :          11 :       break;
    2012                 :             : 
    2013                 :           0 :     default:
    2014                 :           0 :       gcc_unreachable ();
    2015                 :             :     }
    2016                 :             : 
    2017                 :      893615 :   SET_SRC (def_set) = src;
    2018                 :      893615 :   SET_DEST (def_set) = dst;
    2019                 :             : 
    2020                 :             :   /* Drop possible dead definitions.  */
    2021                 :      893615 :   PATTERN (insn) = def_set;
    2022                 :             : 
    2023                 :      893615 :   INSN_CODE (insn) = -1;
    2024                 :      893615 :   recog_memoized (insn);
    2025                 :      893615 :   df_insn_rescan (insn);
    2026                 :      893615 : }
    2027                 :             : 
    2028                 :             : /* Generate copies from defs used by the chain but not defined therein.
    2029                 :             :    Also populates defs_map which is used later by convert_insn.  */
    2030                 :             : 
    2031                 :             : void
    2032                 :      630484 : scalar_chain::convert_registers ()
    2033                 :             : {
    2034                 :      630484 :   bitmap_iterator bi;
    2035                 :      630484 :   unsigned id;
    2036                 :      655129 :   EXECUTE_IF_SET_IN_BITMAP (defs_conv, 0, id, bi)
    2037                 :             :     {
    2038                 :       24645 :       rtx chain_reg = gen_reg_rtx (smode);
    2039                 :       24645 :       defs_map.put (regno_reg_rtx[id], chain_reg);
    2040                 :             :     }
    2041                 :      638356 :   EXECUTE_IF_SET_IN_BITMAP (insns_conv, 0, id, bi)
    2042                 :       19811 :     for (df_ref ref = DF_INSN_UID_DEFS (id); ref; ref = DF_REF_NEXT_LOC (ref))
    2043                 :       11939 :       if (bitmap_bit_p (defs_conv, DF_REF_REGNO (ref)))
    2044                 :        7872 :         make_vector_copies (DF_REF_INSN (ref), DF_REF_REAL_REG (ref));
    2045                 :      630484 : }
    2046                 :             : 
    2047                 :             : /* Convert whole chain creating required register
    2048                 :             :    conversions and copies.  */
    2049                 :             : 
    2050                 :             : int
    2051                 :      630484 : scalar_chain::convert ()
    2052                 :             : {
    2053                 :      630484 :   bitmap_iterator bi;
    2054                 :      630484 :   unsigned id;
    2055                 :      630484 :   int converted_insns = 0;
    2056                 :             : 
    2057                 :      630484 :   if (!dbg_cnt (stv_conversion))
    2058                 :             :     return 0;
    2059                 :             : 
    2060                 :      630484 :   if (dump_file)
    2061                 :           0 :     fprintf (dump_file, "Converting chain #%d...\n", chain_id);
    2062                 :             : 
    2063                 :      630484 :   convert_registers ();
    2064                 :             : 
    2065                 :     1946661 :   EXECUTE_IF_SET_IN_BITMAP (insns, 0, id, bi)
    2066                 :             :     {
    2067                 :     1316177 :       rtx_insn *insn = DF_INSN_UID_GET (id)->insn;
    2068                 :     1316177 :       convert_insn_common (insn);
    2069                 :     1316177 :       convert_insn (insn);
    2070                 :     1316177 :       converted_insns++;
    2071                 :             :     }
    2072                 :             : 
    2073                 :             :   return converted_insns;
    2074                 :             : }
    2075                 :             : 
    2076                 :             : /* Return the SET expression if INSN doesn't reference hard register.
    2077                 :             :    Return NULL if INSN uses or defines a hard register, excluding
    2078                 :             :    pseudo register pushes, hard register uses in a memory address,
    2079                 :             :    clobbers and flags definitions.  */
    2080                 :             : 
    2081                 :             : static rtx
    2082                 :   334762020 : pseudo_reg_set (rtx_insn *insn)
    2083                 :             : {
    2084                 :   334762020 :   rtx set = single_set (insn);
    2085                 :   334762020 :   if (!set)
    2086                 :             :     return NULL;
    2087                 :             : 
    2088                 :             :   /* Check pseudo register push first. */
    2089                 :   135199720 :   machine_mode mode = TARGET_64BIT ? TImode : DImode;
    2090                 :   135199720 :   if (REG_P (SET_SRC (set))
    2091                 :    37994117 :       && !HARD_REGISTER_P (SET_SRC (set))
    2092                 :   164739382 :       && push_operand (SET_DEST (set), mode))
    2093                 :             :     return set;
    2094                 :             : 
    2095                 :   134946540 :   df_ref ref;
    2096                 :   219406869 :   FOR_EACH_INSN_DEF (ref, insn)
    2097                 :   121483399 :     if (HARD_REGISTER_P (DF_REF_REAL_REG (ref))
    2098                 :    65057580 :         && !DF_REF_FLAGS_IS_SET (ref, DF_REF_MUST_CLOBBER)
    2099                 :   171822609 :         && DF_REF_REGNO (ref) != FLAGS_REG)
    2100                 :             :       return NULL;
    2101                 :             : 
    2102                 :   186735909 :   FOR_EACH_INSN_USE (ref, insn)
    2103                 :   114180041 :     if (!DF_REF_REG_MEM_P (ref) && HARD_REGISTER_P (DF_REF_REAL_REG (ref)))
    2104                 :             :       return NULL;
    2105                 :             : 
    2106                 :             :   return set;
    2107                 :             : }
    2108                 :             : 
    2109                 :             : /* Return true if the register REG is defined in a single DEF chain.
    2110                 :             :    If it is defined in more than one DEF chains, we may not be able
    2111                 :             :    to convert it in all chains.  */
    2112                 :             : 
    2113                 :             : static bool
    2114                 :     1138755 : single_def_chain_p (rtx reg)
    2115                 :             : {
    2116                 :     1138755 :   df_ref ref = DF_REG_DEF_CHAIN (REGNO (reg));
    2117                 :     1138755 :   if (!ref)
    2118                 :             :     return false;
    2119                 :     1138740 :   return DF_REF_NEXT_REG (ref) == nullptr;
    2120                 :             : }
    2121                 :             : 
    2122                 :             : /* Check if comparison INSN may be transformed into vector comparison.
    2123                 :             :    Currently we transform equality/inequality checks which look like:
    2124                 :             :    (set (reg:CCZ 17 flags) (compare:CCZ (reg:TI x) (reg:TI y)))  */
    2125                 :             : 
    2126                 :             : static bool
    2127                 :    12679842 : convertible_comparison_p (rtx_insn *insn, enum machine_mode mode)
    2128                 :             : {
    2129                 :    14063550 :   if (mode != (TARGET_64BIT ? TImode : DImode))
    2130                 :             :     return false;
    2131                 :             : 
    2132                 :     4636366 :   if (!TARGET_SSE4_1)
    2133                 :             :     return false;
    2134                 :             : 
    2135                 :      154568 :   rtx def_set = single_set (insn);
    2136                 :             : 
    2137                 :      154568 :   gcc_assert (def_set);
    2138                 :             : 
    2139                 :      154568 :   rtx src = SET_SRC (def_set);
    2140                 :      154568 :   rtx dst = SET_DEST (def_set);
    2141                 :             : 
    2142                 :      154568 :   gcc_assert (GET_CODE (src) == COMPARE);
    2143                 :             : 
    2144                 :      154568 :   if (GET_CODE (dst) != REG
    2145                 :      154568 :       || REGNO (dst) != FLAGS_REG
    2146                 :      309136 :       || GET_MODE (dst) != CCZmode)
    2147                 :             :     return false;
    2148                 :             : 
    2149                 :      113016 :   rtx op1 = XEXP (src, 0);
    2150                 :      113016 :   rtx op2 = XEXP (src, 1);
    2151                 :             : 
    2152                 :             :   /* *cmp<dwi>_doubleword.  */
    2153                 :      113016 :   if ((CONST_SCALAR_INT_P (op1)
    2154                 :      113016 :        || ((REG_P (op1) || MEM_P (op1))
    2155                 :      110747 :            && GET_MODE (op1) == mode))
    2156                 :          49 :       && (CONST_SCALAR_INT_P (op2)
    2157                 :           6 :           || ((REG_P (op2) || MEM_P (op2))
    2158                 :           4 :               && GET_MODE (op2) == mode)))
    2159                 :             :     return true;
    2160                 :             : 
    2161                 :             :   /* *testti_doubleword.  */
    2162                 :      112969 :   if (op2 == const0_rtx
    2163                 :       38483 :       && GET_CODE (op1) == AND
    2164                 :         152 :       && REG_P (XEXP (op1, 0)))
    2165                 :             :     {
    2166                 :         152 :       rtx op12 = XEXP (op1, 1);
    2167                 :         152 :       return GET_MODE (XEXP (op1, 0)) == TImode
    2168                 :         152 :              && (CONST_SCALAR_INT_P (op12)
    2169                 :           0 :                  || ((REG_P (op12) || MEM_P (op12))
    2170                 :           0 :                      && GET_MODE (op12) == TImode));
    2171                 :             :     }
    2172                 :             : 
    2173                 :             :   /* *test<dwi>_not_doubleword.  */
    2174                 :      112817 :   if (op2 == const0_rtx
    2175                 :       38331 :       && GET_CODE (op1) == AND
    2176                 :           0 :       && GET_CODE (XEXP (op1, 0)) == NOT)
    2177                 :             :     {
    2178                 :           0 :       rtx op11 = XEXP (XEXP (op1, 0), 0);
    2179                 :           0 :       rtx op12 = XEXP (op1, 1);
    2180                 :           0 :       return (REG_P (op11) || MEM_P (op11))
    2181                 :           0 :              && (REG_P (op12) || MEM_P (op12))
    2182                 :           0 :              && GET_MODE (op11) == mode
    2183                 :           0 :              && GET_MODE (op12) == mode;
    2184                 :             :     }
    2185                 :             : 
    2186                 :             :   return false;
    2187                 :             : }
    2188                 :             : 
    2189                 :             : /* The general version of scalar_to_vector_candidate_p.  */
    2190                 :             : 
    2191                 :             : static bool
    2192                 :   234045831 : general_scalar_to_vector_candidate_p (rtx_insn *insn, enum machine_mode mode)
    2193                 :             : {
    2194                 :   234045831 :   rtx def_set = pseudo_reg_set (insn);
    2195                 :             : 
    2196                 :   234045831 :   if (!def_set)
    2197                 :             :     return false;
    2198                 :             : 
    2199                 :    49254149 :   rtx src = SET_SRC (def_set);
    2200                 :    49254149 :   rtx dst = SET_DEST (def_set);
    2201                 :             : 
    2202                 :    49254149 :   if (GET_CODE (src) == COMPARE)
    2203                 :     8735330 :     return convertible_comparison_p (insn, mode);
    2204                 :             : 
    2205                 :             :   /* We are interested in "mode" only.  */
    2206                 :    40518819 :   if ((GET_MODE (src) != mode
    2207                 :    27506717 :        && !CONST_INT_P (src))
    2208                 :    18274674 :       || GET_MODE (dst) != mode)
    2209                 :             :     return false;
    2210                 :             : 
    2211                 :    15290511 :   if (!REG_P (dst) && !MEM_P (dst))
    2212                 :             :     return false;
    2213                 :             : 
    2214                 :    15052832 :   switch (GET_CODE (src))
    2215                 :             :     {
    2216                 :      527875 :     case ASHIFT:
    2217                 :      527875 :     case LSHIFTRT:
    2218                 :      527875 :     case ASHIFTRT:
    2219                 :      527875 :     case ROTATE:
    2220                 :      527875 :     case ROTATERT:
    2221                 :      527875 :       if (!CONST_INT_P (XEXP (src, 1))
    2222                 :     1019373 :           || !IN_RANGE (INTVAL (XEXP (src, 1)), 0, GET_MODE_BITSIZE (mode)-1))
    2223                 :             :         return false;
    2224                 :             : 
    2225                 :             :       /* Check for extend highpart case.  */
    2226                 :      491494 :       if (mode != DImode
    2227                 :      357168 :           || GET_CODE (src) != ASHIFTRT
    2228                 :       84628 :           || GET_CODE (XEXP (src, 0)) != ASHIFT)
    2229                 :             :         break;
    2230                 :             : 
    2231                 :     3701915 :       src = XEXP (src, 0);
    2232                 :             :       break;
    2233                 :             : 
    2234                 :       68161 :     case SMAX:
    2235                 :       68161 :     case SMIN:
    2236                 :       68161 :     case UMAX:
    2237                 :       68161 :     case UMIN:
    2238                 :       68161 :       if ((mode == DImode && !TARGET_AVX512VL)
    2239                 :       17202 :           || (mode == SImode && !TARGET_SSE4_1))
    2240                 :             :         return false;
    2241                 :             :       /* Fallthru.  */
    2242                 :             : 
    2243                 :     3265855 :     case AND:
    2244                 :     3265855 :     case IOR:
    2245                 :     3265855 :     case XOR:
    2246                 :     3265855 :     case PLUS:
    2247                 :     3265855 :     case MINUS:
    2248                 :     3265855 :       if (!REG_P (XEXP (src, 1))
    2249                 :             :           && !MEM_P (XEXP (src, 1))
    2250                 :             :           && !CONST_INT_P (XEXP (src, 1)))
    2251                 :             :         return false;
    2252                 :             : 
    2253                 :     3157049 :       if (GET_MODE (XEXP (src, 1)) != mode
    2254                 :     1840629 :           && !CONST_INT_P (XEXP (src, 1)))
    2255                 :             :         return false;
    2256                 :             : 
    2257                 :             :       /* Check for andnot case.  */
    2258                 :     3157049 :       if (GET_CODE (src) != AND
    2259                 :      218326 :           || GET_CODE (XEXP (src, 0)) != NOT)
    2260                 :             :         break;
    2261                 :             : 
    2262                 :     3701915 :       src = XEXP (src, 0);
    2263                 :             :       /* FALLTHRU */
    2264                 :             : 
    2265                 :             :     case NOT:
    2266                 :             :       break;
    2267                 :             : 
    2268                 :       25839 :     case NEG:
    2269                 :             :       /* Check for nabs case.  */
    2270                 :       25839 :       if (GET_CODE (XEXP (src, 0)) != ABS)
    2271                 :             :         break;
    2272                 :             : 
    2273                 :             :       src = XEXP (src, 0);
    2274                 :             :       /* FALLTHRU */
    2275                 :             : 
    2276                 :        3721 :     case ABS:
    2277                 :        3721 :       if ((mode == DImode && !TARGET_AVX512VL)
    2278                 :        1089 :           || (mode == SImode && !TARGET_SSSE3))
    2279                 :             :         return false;
    2280                 :             :       break;
    2281                 :             : 
    2282                 :             :     case REG:
    2283                 :             :       return true;
    2284                 :             : 
    2285                 :     6076889 :     case MEM:
    2286                 :     6076889 :     case CONST_INT:
    2287                 :     6076889 :       return REG_P (dst);
    2288                 :             : 
    2289                 :       54443 :     case VEC_SELECT:
    2290                 :             :       /* Excluding MEM_P (dst) avoids intefering with vpextr[dq].  */
    2291                 :       54443 :       return REG_P (dst)
    2292                 :       44149 :              && REG_P (XEXP (src, 0))
    2293                 :       51009 :              && GET_MODE (XEXP (src, 0)) == (mode == DImode ? V2DImode
    2294                 :             :                                                             : V4SImode)
    2295                 :       35289 :              && GET_CODE (XEXP (src, 1)) == PARALLEL
    2296                 :       35289 :              && XVECLEN (XEXP (src, 1), 0) == 1
    2297                 :       89732 :              && CONST_INT_P (XVECEXP (XEXP (src, 1), 0, 0));
    2298                 :             : 
    2299                 :             :     default:
    2300                 :             :       return false;
    2301                 :             :     }
    2302                 :             : 
    2303                 :     3701915 :   if (!REG_P (XEXP (src, 0))
    2304                 :             :       && !MEM_P (XEXP (src, 0))
    2305                 :             :       && !CONST_INT_P (XEXP (src, 0)))
    2306                 :             :     return false;
    2307                 :             : 
    2308                 :     3401896 :   if (GET_MODE (XEXP (src, 0)) != mode
    2309                 :           0 :       && !CONST_INT_P (XEXP (src, 0)))
    2310                 :             :     return false;
    2311                 :             : 
    2312                 :             :   return true;
    2313                 :             : }
    2314                 :             : 
    2315                 :             : /* Check for a suitable TImode memory operand.  */
    2316                 :             : 
    2317                 :             : static bool
    2318                 :       13135 : timode_mem_p (rtx x)
    2319                 :             : {
    2320                 :       13135 :   return MEM_P (x)
    2321                 :       13135 :          && (TARGET_SSE_UNALIGNED_LOAD_OPTIMAL
    2322                 :           0 :              || !misaligned_operand (x, TImode));
    2323                 :             : }
    2324                 :             : 
    2325                 :             : /* The TImode version of scalar_to_vector_candidate_p.  */
    2326                 :             : 
    2327                 :             : static bool
    2328                 :   100716189 : timode_scalar_to_vector_candidate_p (rtx_insn *insn)
    2329                 :             : {
    2330                 :   100716189 :   rtx def_set = pseudo_reg_set (insn);
    2331                 :             : 
    2332                 :   100716189 :   if (!def_set)
    2333                 :             :     return false;
    2334                 :             : 
    2335                 :    23554899 :   rtx src = SET_SRC (def_set);
    2336                 :    23554899 :   rtx dst = SET_DEST (def_set);
    2337                 :             : 
    2338                 :    23554899 :   if (GET_CODE (src) == COMPARE)
    2339                 :     3944512 :     return convertible_comparison_p (insn, TImode);
    2340                 :             : 
    2341                 :    19610387 :   if (GET_MODE (dst) != TImode
    2342                 :     1189974 :       || (GET_MODE (src) != TImode
    2343                 :       65345 :           && !CONST_SCALAR_INT_P (src)))
    2344                 :             :     return false;
    2345                 :             : 
    2346                 :     1189974 :   if (!REG_P (dst) && !MEM_P (dst))
    2347                 :             :     return false;
    2348                 :             : 
    2349                 :     1188523 :   if (MEM_P (dst)
    2350                 :      528439 :       && misaligned_operand (dst, TImode)
    2351                 :     1463108 :       && !TARGET_SSE_UNALIGNED_STORE_OPTIMAL)
    2352                 :             :     return false;
    2353                 :             : 
    2354                 :     1188518 :   if (REG_P (dst) && !single_def_chain_p (dst))
    2355                 :             :     return false;
    2356                 :             : 
    2357                 :     1022478 :   switch (GET_CODE (src))
    2358                 :             :     {
    2359                 :      478671 :     case REG:
    2360                 :      478671 :       return single_def_chain_p (src);
    2361                 :             : 
    2362                 :             :     case CONST_WIDE_INT:
    2363                 :             :       return true;
    2364                 :             : 
    2365                 :       12783 :     case CONST_INT:
    2366                 :             :       /* ??? Verify performance impact before enabling CONST_INT for
    2367                 :             :          __int128 store.  */
    2368                 :       12783 :       return standard_sse_constant_p (src, TImode);
    2369                 :             : 
    2370                 :      424992 :     case MEM:
    2371                 :             :       /* Memory must be aligned or unaligned load is optimal.  */
    2372                 :      424992 :       return (REG_P (dst)
    2373                 :      424992 :               && (!misaligned_operand (src, TImode)
    2374                 :      121975 :                   || TARGET_SSE_UNALIGNED_LOAD_OPTIMAL));
    2375                 :             : 
    2376                 :        4735 :     case AND:
    2377                 :        4735 :       if (!MEM_P (dst)
    2378                 :        4699 :           && GET_CODE (XEXP (src, 0)) == NOT
    2379                 :           0 :           && REG_P (XEXP (XEXP (src, 0), 0))
    2380                 :        4735 :           && (REG_P (XEXP (src, 1))
    2381                 :           0 :               || CONST_SCALAR_INT_P (XEXP (src, 1))
    2382                 :           0 :               || timode_mem_p (XEXP (src, 1))))
    2383                 :           0 :         return true;
    2384                 :        4735 :       return (REG_P (XEXP (src, 0))
    2385                 :          41 :               || timode_mem_p (XEXP (src, 0)))
    2386                 :        4776 :              && (REG_P (XEXP (src, 1))
    2387                 :        2906 :                  || CONST_SCALAR_INT_P (XEXP (src, 1))
    2388                 :          35 :                  || timode_mem_p (XEXP (src, 1)));
    2389                 :             : 
    2390                 :       14269 :     case IOR:
    2391                 :       14269 :     case XOR:
    2392                 :       14269 :       return (REG_P (XEXP (src, 0))
    2393                 :       13012 :               || timode_mem_p (XEXP (src, 0)))
    2394                 :       14277 :              && (REG_P (XEXP (src, 1))
    2395                 :         267 :                  || CONST_SCALAR_INT_P (XEXP (src, 1))
    2396                 :          31 :                  || timode_mem_p (XEXP (src, 1)));
    2397                 :             : 
    2398                 :         373 :     case NOT:
    2399                 :         373 :       return REG_P (XEXP (src, 0)) || timode_mem_p (XEXP (src, 0));
    2400                 :             : 
    2401                 :       13000 :     case ASHIFT:
    2402                 :       13000 :     case LSHIFTRT:
    2403                 :       13000 :     case ASHIFTRT:
    2404                 :       13000 :     case ROTATERT:
    2405                 :       13000 :     case ROTATE:
    2406                 :             :       /* Handle shifts/rotates by integer constants between 0 and 127.  */
    2407                 :       13000 :       return REG_P (XEXP (src, 0))
    2408                 :       12964 :              && CONST_INT_P (XEXP (src, 1))
    2409                 :       25617 :              && (INTVAL (XEXP (src, 1)) & ~0x7f) == 0;
    2410                 :             : 
    2411                 :             :     default:
    2412                 :             :       return false;
    2413                 :             :     }
    2414                 :             : }
    2415                 :             : 
    2416                 :             : /* For a register REGNO, scan instructions for its defs and uses.
    2417                 :             :    Put REGNO in REGS if a def or use isn't in CANDIDATES.  */
    2418                 :             : 
    2419                 :             : static void
    2420                 :     1238416 : timode_check_non_convertible_regs (bitmap candidates, bitmap regs,
    2421                 :             :                                    unsigned int regno)
    2422                 :             : {
    2423                 :             :   /* Do nothing if REGNO is already in REGS or is a hard reg.  */
    2424                 :     1238416 :   if (bitmap_bit_p (regs, regno)
    2425                 :     1238416 :       || HARD_REGISTER_NUM_P (regno))
    2426                 :             :     return;
    2427                 :             : 
    2428                 :     1225051 :   for (df_ref def = DF_REG_DEF_CHAIN (regno);
    2429                 :     2419160 :        def;
    2430                 :     1194109 :        def = DF_REF_NEXT_REG (def))
    2431                 :             :     {
    2432                 :     1225031 :       if (!bitmap_bit_p (candidates, DF_REF_INSN_UID (def)))
    2433                 :             :         {
    2434                 :       30922 :           if (dump_file)
    2435                 :           0 :             fprintf (dump_file,
    2436                 :             :                      "r%d has non convertible def in insn %d\n",
    2437                 :           0 :                      regno, DF_REF_INSN_UID (def));
    2438                 :             : 
    2439                 :       30922 :           bitmap_set_bit (regs, regno);
    2440                 :       30922 :           break;
    2441                 :             :         }
    2442                 :             :     }
    2443                 :             : 
    2444                 :     1225051 :   for (df_ref ref = DF_REG_USE_CHAIN (regno);
    2445                 :     2774691 :        ref;
    2446                 :     1549640 :        ref = DF_REF_NEXT_REG (ref))
    2447                 :             :     {
    2448                 :             :       /* Debug instructions are skipped.  */
    2449                 :     1605376 :       if (NONDEBUG_INSN_P (DF_REF_INSN (ref))
    2450                 :     1605376 :           && !bitmap_bit_p (candidates, DF_REF_INSN_UID (ref)))
    2451                 :             :         {
    2452                 :       55736 :           if (dump_file)
    2453                 :           0 :             fprintf (dump_file,
    2454                 :             :                      "r%d has non convertible use in insn %d\n",
    2455                 :           0 :                      regno, DF_REF_INSN_UID (ref));
    2456                 :             : 
    2457                 :       55736 :           bitmap_set_bit (regs, regno);
    2458                 :       55736 :           break;
    2459                 :             :         }
    2460                 :             :     }
    2461                 :             : }
    2462                 :             : 
    2463                 :             : /* For a given bitmap of insn UIDs scans all instructions and
    2464                 :             :    remove insn from CANDIDATES in case it has both convertible
    2465                 :             :    and not convertible definitions.
    2466                 :             : 
    2467                 :             :    All insns in a bitmap are conversion candidates according to
    2468                 :             :    scalar_to_vector_candidate_p.  Currently it implies all insns
    2469                 :             :    are single_set.  */
    2470                 :             : 
    2471                 :             : static void
    2472                 :      817021 : timode_remove_non_convertible_regs (bitmap candidates)
    2473                 :             : {
    2474                 :      817021 :   bitmap_iterator bi;
    2475                 :      817021 :   unsigned id;
    2476                 :      817021 :   bitmap regs = BITMAP_ALLOC (NULL);
    2477                 :      841246 :   bool changed;
    2478                 :             : 
    2479                 :      841246 :   do {
    2480                 :      841246 :     changed = false;
    2481                 :     2112438 :     EXECUTE_IF_SET_IN_BITMAP (candidates, 0, id, bi)
    2482                 :             :       {
    2483                 :     1271192 :         rtx_insn *insn = DF_INSN_UID_GET (id)->insn;
    2484                 :     1271192 :         df_ref ref;
    2485                 :             : 
    2486                 :     1891053 :         FOR_EACH_INSN_DEF (ref, insn)
    2487                 :      619861 :           if (!DF_REF_REG_MEM_P (ref)
    2488                 :      619861 :               && GET_MODE (DF_REF_REG (ref)) == TImode)
    2489                 :      596624 :             timode_check_non_convertible_regs (candidates, regs,
    2490                 :             :                                                DF_REF_REGNO (ref));
    2491                 :             : 
    2492                 :     3120002 :         FOR_EACH_INSN_USE (ref, insn)
    2493                 :     1848810 :           if (!DF_REF_REG_MEM_P (ref)
    2494                 :      641792 :               && GET_MODE (DF_REF_REG (ref)) == TImode)
    2495                 :      641792 :             timode_check_non_convertible_regs (candidates, regs,
    2496                 :             :                                                DF_REF_REGNO (ref));
    2497                 :             :       }
    2498                 :             : 
    2499                 :     1014260 :     EXECUTE_IF_SET_IN_BITMAP (regs, 0, id, bi)
    2500                 :             :       {
    2501                 :      173014 :         for (df_ref def = DF_REG_DEF_CHAIN (id);
    2502                 :      352826 :              def;
    2503                 :      179812 :              def = DF_REF_NEXT_REG (def))
    2504                 :      179812 :           if (bitmap_bit_p (candidates, DF_REF_INSN_UID (def)))
    2505                 :             :             {
    2506                 :       37144 :               if (dump_file)
    2507                 :           0 :                 fprintf (dump_file, "Removing insn %d from candidates list\n",
    2508                 :           0 :                          DF_REF_INSN_UID (def));
    2509                 :             : 
    2510                 :       37144 :               bitmap_clear_bit (candidates, DF_REF_INSN_UID (def));
    2511                 :       37144 :               changed = true;
    2512                 :             :             }
    2513                 :             : 
    2514                 :      173014 :         for (df_ref ref = DF_REG_USE_CHAIN (id);
    2515                 :      467666 :              ref;
    2516                 :      294652 :              ref = DF_REF_NEXT_REG (ref))
    2517                 :      294652 :           if (bitmap_bit_p (candidates, DF_REF_INSN_UID (ref)))
    2518                 :             :             {
    2519                 :       42175 :               if (dump_file)
    2520                 :           0 :                 fprintf (dump_file, "Removing insn %d from candidates list\n",
    2521                 :           0 :                          DF_REF_INSN_UID (ref));
    2522                 :             : 
    2523                 :       42175 :               bitmap_clear_bit (candidates, DF_REF_INSN_UID (ref));
    2524                 :       42175 :               changed = true;
    2525                 :             :             }
    2526                 :             :       }
    2527                 :             :   } while (changed);
    2528                 :             : 
    2529                 :      817021 :   BITMAP_FREE (regs);
    2530                 :      817021 : }
    2531                 :             : 
    2532                 :             : /* Main STV pass function.  Find and convert scalar
    2533                 :             :    instructions into vector mode when profitable.  */
    2534                 :             : 
    2535                 :             : static unsigned int
    2536                 :     1759252 : convert_scalars_to_vector (bool timode_p)
    2537                 :             : {
    2538                 :     1759252 :   basic_block bb;
    2539                 :     1759252 :   int converted_insns = 0;
    2540                 :     1759252 :   auto_vec<rtx_insn *> control_flow_insns;
    2541                 :             : 
    2542                 :     1759252 :   bitmap_obstack_initialize (NULL);
    2543                 :     1759252 :   const machine_mode cand_mode[3] = { SImode, DImode, TImode };
    2544                 :     1759252 :   const machine_mode cand_vmode[3] = { V4SImode, V2DImode, V1TImode };
    2545                 :     5277756 :   bitmap_head candidates[3];  /* { SImode, DImode, TImode } */
    2546                 :     7037008 :   for (unsigned i = 0; i < 3; ++i)
    2547                 :     5277756 :     bitmap_initialize (&candidates[i], &bitmap_default_obstack);
    2548                 :             : 
    2549                 :     1759252 :   calculate_dominance_info (CDI_DOMINATORS);
    2550                 :     1759252 :   df_set_flags (DF_DEFER_INSN_RESCAN | DF_RD_PRUNE_DEAD_DEFS);
    2551                 :     1759252 :   df_chain_add_problem (DF_DU_CHAIN | DF_UD_CHAIN);
    2552                 :     1759252 :   df_analyze ();
    2553                 :             : 
    2554                 :             :   /* Find all instructions we want to convert into vector mode.  */
    2555                 :     1759252 :   if (dump_file)
    2556                 :          44 :     fprintf (dump_file, "Searching for mode conversion candidates...\n");
    2557                 :             : 
    2558                 :    19639485 :   FOR_EACH_BB_FN (bb, cfun)
    2559                 :             :     {
    2560                 :    17880233 :       rtx_insn *insn;
    2561                 :   237409731 :       FOR_BB_INSNS (bb, insn)
    2562                 :   219529498 :         if (timode_p
    2563                 :   219529498 :             && timode_scalar_to_vector_candidate_p (insn))
    2564                 :             :           {
    2565                 :      973272 :             if (dump_file)
    2566                 :           0 :               fprintf (dump_file, "  insn %d is marked as a TImode candidate\n",
    2567                 :           0 :                        INSN_UID (insn));
    2568                 :             : 
    2569                 :      973272 :             bitmap_set_bit (&candidates[2], INSN_UID (insn));
    2570                 :             :           }
    2571                 :   218556226 :         else if (!timode_p)
    2572                 :             :           {
    2573                 :             :             /* Check {SI,DI}mode.  */
    2574                 :   341073459 :             for (unsigned i = 0; i <= 1; ++i)
    2575                 :   234045831 :               if (general_scalar_to_vector_candidate_p (insn, cand_mode[i]))
    2576                 :             :                 {
    2577                 :    11785681 :                   if (dump_file)
    2578                 :         550 :                     fprintf (dump_file, "  insn %d is marked as a %s candidate\n",
    2579                 :         275 :                              INSN_UID (insn), i == 0 ? "SImode" : "DImode");
    2580                 :             : 
    2581                 :    11785681 :                   bitmap_set_bit (&candidates[i], INSN_UID (insn));
    2582                 :    11785681 :                   break;
    2583                 :             :                 }
    2584                 :             :           }
    2585                 :             :     }
    2586                 :             : 
    2587                 :     1759252 :   if (timode_p)
    2588                 :      817021 :     timode_remove_non_convertible_regs (&candidates[2]);
    2589                 :             : 
    2590                 :     5555399 :   for (unsigned i = 0; i <= 2; ++i)
    2591                 :     4428682 :     if (!bitmap_empty_p (&candidates[i]))
    2592                 :             :       break;
    2593                 :     3796147 :     else if (i == 2 && dump_file)
    2594                 :          23 :       fprintf (dump_file, "There are no candidates for optimization.\n");
    2595                 :             : 
    2596                 :     7037008 :   for (unsigned i = 0; i <= 2; ++i)
    2597                 :             :     {
    2598                 :     5277756 :       auto_bitmap disallowed;
    2599                 :     5277756 :       bitmap_tree_view (&candidates[i]);
    2600                 :    17022444 :       while (!bitmap_empty_p (&candidates[i]))
    2601                 :             :         {
    2602                 :     6466932 :           unsigned uid = bitmap_first_set_bit (&candidates[i]);
    2603                 :     6466932 :           scalar_chain *chain;
    2604                 :             : 
    2605                 :     6466932 :           if (cand_mode[i] == TImode)
    2606                 :      451805 :             chain = new timode_scalar_chain;
    2607                 :             :           else
    2608                 :     6015127 :             chain = new general_scalar_chain (cand_mode[i], cand_vmode[i]);
    2609                 :             : 
    2610                 :             :           /* Find instructions chain we want to convert to vector mode.
    2611                 :             :              Check all uses and definitions to estimate all required
    2612                 :             :              conversions.  */
    2613                 :     6466932 :           if (chain->build (&candidates[i], uid, disallowed))
    2614                 :             :             {
    2615                 :     6466417 :               if (chain->compute_convert_gain ())
    2616                 :      630484 :                 converted_insns += chain->convert ();
    2617                 :     5835933 :               else if (dump_file)
    2618                 :         138 :                 fprintf (dump_file, "Chain #%d conversion is not profitable\n",
    2619                 :             :                          chain->chain_id);
    2620                 :             :             }
    2621                 :             : 
    2622                 :     6466932 :           rtx_insn* iter_insn;
    2623                 :     6466932 :           unsigned int ii;
    2624                 :     6471676 :           FOR_EACH_VEC_ELT (chain->control_flow_insns, ii, iter_insn)
    2625                 :        4744 :             control_flow_insns.safe_push (iter_insn);
    2626                 :             : 
    2627                 :     6466932 :           delete chain;
    2628                 :             :         }
    2629                 :     5277756 :     }
    2630                 :             : 
    2631                 :     1759252 :   if (dump_file)
    2632                 :          44 :     fprintf (dump_file, "Total insns converted: %d\n", converted_insns);
    2633                 :             : 
    2634                 :     7037008 :   for (unsigned i = 0; i <= 2; ++i)
    2635                 :     5277756 :     bitmap_release (&candidates[i]);
    2636                 :     1759252 :   bitmap_obstack_release (NULL);
    2637                 :     1759252 :   df_process_deferred_rescans ();
    2638                 :             : 
    2639                 :             :   /* Conversion means we may have 128bit register spills/fills
    2640                 :             :      which require aligned stack.  */
    2641                 :     1759252 :   if (converted_insns)
    2642                 :             :     {
    2643                 :      109538 :       if (crtl->stack_alignment_needed < 128)
    2644                 :        2154 :         crtl->stack_alignment_needed = 128;
    2645                 :      109538 :       if (crtl->stack_alignment_estimated < 128)
    2646                 :         188 :         crtl->stack_alignment_estimated = 128;
    2647                 :             : 
    2648                 :      109538 :       crtl->stack_realign_needed
    2649                 :      109538 :         = INCOMING_STACK_BOUNDARY < crtl->stack_alignment_estimated;
    2650                 :      109538 :       crtl->stack_realign_tried = crtl->stack_realign_needed;
    2651                 :             : 
    2652                 :      109538 :       crtl->stack_realign_processed = true;
    2653                 :             : 
    2654                 :      109538 :       if (!crtl->drap_reg)
    2655                 :             :         {
    2656                 :      109394 :           rtx drap_rtx = targetm.calls.get_drap_rtx ();
    2657                 :             : 
    2658                 :             :           /* stack_realign_drap and drap_rtx must match.  */
    2659                 :      109394 :           gcc_assert ((stack_realign_drap != 0) == (drap_rtx != NULL));
    2660                 :             : 
    2661                 :             :           /* Do nothing if NULL is returned,
    2662                 :             :              which means DRAP is not needed.  */
    2663                 :      109394 :           if (drap_rtx != NULL)
    2664                 :             :             {
    2665                 :           0 :               crtl->args.internal_arg_pointer = drap_rtx;
    2666                 :             : 
    2667                 :             :               /* Call fixup_tail_calls to clean up
    2668                 :             :                  REG_EQUIV note if DRAP is needed. */
    2669                 :           0 :               fixup_tail_calls ();
    2670                 :             :             }
    2671                 :             :         }
    2672                 :             : 
    2673                 :             :       /* Fix up DECL_RTL/DECL_INCOMING_RTL of arguments.  */
    2674                 :      109538 :       if (TARGET_64BIT)
    2675                 :       69905 :         for (tree parm = DECL_ARGUMENTS (current_function_decl);
    2676                 :      193018 :              parm; parm = DECL_CHAIN (parm))
    2677                 :             :           {
    2678                 :      123113 :             if (TYPE_MODE (TREE_TYPE (parm)) != TImode)
    2679                 :      106504 :               continue;
    2680                 :       16609 :             if (DECL_RTL_SET_P (parm)
    2681                 :       33218 :                 && GET_MODE (DECL_RTL (parm)) == V1TImode)
    2682                 :             :               {
    2683                 :         324 :                 rtx r = DECL_RTL (parm);
    2684                 :         324 :                 if (REG_P (r))
    2685                 :         324 :                   SET_DECL_RTL (parm, gen_rtx_SUBREG (TImode, r, 0));
    2686                 :             :               }
    2687                 :       16609 :             if (DECL_INCOMING_RTL (parm)
    2688                 :       16609 :                 && GET_MODE (DECL_INCOMING_RTL (parm)) == V1TImode)
    2689                 :             :               {
    2690                 :           0 :                 rtx r = DECL_INCOMING_RTL (parm);
    2691                 :           0 :                 if (REG_P (r))
    2692                 :           0 :                   DECL_INCOMING_RTL (parm) = gen_rtx_SUBREG (TImode, r, 0);
    2693                 :             :               }
    2694                 :             :           }
    2695                 :             : 
    2696                 :      109538 :       if (!control_flow_insns.is_empty ())
    2697                 :             :         {
    2698                 :        1347 :           free_dominance_info (CDI_DOMINATORS);
    2699                 :             : 
    2700                 :        1347 :           unsigned int i;
    2701                 :        1347 :           rtx_insn* insn;
    2702                 :        7438 :           FOR_EACH_VEC_ELT (control_flow_insns, i, insn)
    2703                 :        4744 :             if (control_flow_insn_p (insn))
    2704                 :             :               {
    2705                 :             :                 /* Split the block after insn.  There will be a fallthru
    2706                 :             :                    edge, which is OK so we keep it.  We have to create
    2707                 :             :                    the exception edges ourselves.  */
    2708                 :        4744 :                 bb = BLOCK_FOR_INSN (insn);
    2709                 :        4744 :                 split_block (bb, insn);
    2710                 :        4744 :                 rtl_make_eh_edge (NULL, bb, BB_END (bb));
    2711                 :             :               }
    2712                 :             :         }
    2713                 :             :     }
    2714                 :             : 
    2715                 :     1759252 :   return 0;
    2716                 :     1759252 : }
    2717                 :             : 
    2718                 :             : static unsigned int
    2719                 :       72623 : rest_of_handle_insert_vzeroupper (void)
    2720                 :             : {
    2721                 :             :   /* vzeroupper instructions are inserted immediately after reload and
    2722                 :             :      postreload_cse to clean up after it a little bit to account for possible
    2723                 :             :      spills from 256bit or 512bit registers.  The pass reuses mode switching
    2724                 :             :      infrastructure by re-running mode insertion pass, so disable entities
    2725                 :             :      that have already been processed.  */
    2726                 :      508361 :   for (int i = 0; i < MAX_386_ENTITIES; i++)
    2727                 :      435738 :     ix86_optimize_mode_switching[i] = 0;
    2728                 :             : 
    2729                 :       72623 :   ix86_optimize_mode_switching[AVX_U128] = 1;
    2730                 :             : 
    2731                 :             :   /* Call optimize_mode_switching.  */
    2732                 :       72623 :   g->get_passes ()->execute_pass_mode_switching ();
    2733                 :             : 
    2734                 :             :   /* LRA removes all REG_DEAD/REG_UNUSED notes and normally they
    2735                 :             :      reappear in the IL only at the start of pass_rtl_dse2, which does
    2736                 :             :      df_note_add_problem (); df_analyze ();
    2737                 :             :      The vzeroupper is scheduled after postreload_cse pass and mode
    2738                 :             :      switching computes the notes as well, the problem is that e.g.
    2739                 :             :      pass_gcse2 doesn't maintain the notes, see PR113059 and
    2740                 :             :      PR112760.  Remove the notes now to restore status quo ante
    2741                 :             :      until we figure out how to maintain the notes or what else
    2742                 :             :      to do.  */
    2743                 :       72623 :   basic_block bb;
    2744                 :       72623 :   rtx_insn *insn;
    2745                 :      387736 :   FOR_EACH_BB_FN (bb, cfun)
    2746                 :     4167018 :     FOR_BB_INSNS (bb, insn)
    2747                 :     3851905 :       if (NONDEBUG_INSN_P (insn))
    2748                 :             :         {
    2749                 :     2011867 :           rtx *pnote = &REG_NOTES (insn);
    2750                 :     3716790 :           while (*pnote != 0)
    2751                 :             :             {
    2752                 :     1704923 :               if (REG_NOTE_KIND (*pnote) == REG_DEAD
    2753                 :      779734 :                   || REG_NOTE_KIND (*pnote) == REG_UNUSED)
    2754                 :     1228041 :                 *pnote = XEXP (*pnote, 1);
    2755                 :             :               else
    2756                 :      476882 :                 pnote = &XEXP (*pnote, 1);
    2757                 :             :             }
    2758                 :             :         }
    2759                 :             : 
    2760                 :       72623 :   df_remove_problem (df_note);
    2761                 :       72623 :   df_analyze ();
    2762                 :       72623 :   return 0;
    2763                 :             : }
    2764                 :             : 
    2765                 :             : namespace {
    2766                 :             : 
    2767                 :             : const pass_data pass_data_insert_vzeroupper =
    2768                 :             : {
    2769                 :             :   RTL_PASS, /* type */
    2770                 :             :   "vzeroupper", /* name */
    2771                 :             :   OPTGROUP_NONE, /* optinfo_flags */
    2772                 :             :   TV_MACH_DEP, /* tv_id */
    2773                 :             :   0, /* properties_required */
    2774                 :             :   0, /* properties_provided */
    2775                 :             :   0, /* properties_destroyed */
    2776                 :             :   0, /* todo_flags_start */
    2777                 :             :   TODO_df_finish, /* todo_flags_finish */
    2778                 :             : };
    2779                 :             : 
    2780                 :             : class pass_insert_vzeroupper : public rtl_opt_pass
    2781                 :             : {
    2782                 :             : public:
    2783                 :      285081 :   pass_insert_vzeroupper(gcc::context *ctxt)
    2784                 :      570162 :     : rtl_opt_pass(pass_data_insert_vzeroupper, ctxt)
    2785                 :             :   {}
    2786                 :             : 
    2787                 :             :   /* opt_pass methods: */
    2788                 :     1449863 :   bool gate (function *) final override
    2789                 :             :     {
    2790                 :     1449863 :       return TARGET_AVX && TARGET_VZEROUPPER;
    2791                 :             :     }
    2792                 :             : 
    2793                 :       72623 :   unsigned int execute (function *) final override
    2794                 :             :     {
    2795                 :       72623 :       return rest_of_handle_insert_vzeroupper ();
    2796                 :             :     }
    2797                 :             : 
    2798                 :             : }; // class pass_insert_vzeroupper
    2799                 :             : 
    2800                 :             : const pass_data pass_data_stv =
    2801                 :             : {
    2802                 :             :   RTL_PASS, /* type */
    2803                 :             :   "stv", /* name */
    2804                 :             :   OPTGROUP_NONE, /* optinfo_flags */
    2805                 :             :   TV_MACH_DEP, /* tv_id */
    2806                 :             :   0, /* properties_required */
    2807                 :             :   0, /* properties_provided */
    2808                 :             :   0, /* properties_destroyed */
    2809                 :             :   0, /* todo_flags_start */
    2810                 :             :   TODO_df_finish, /* todo_flags_finish */
    2811                 :             : };
    2812                 :             : 
    2813                 :             : class pass_stv : public rtl_opt_pass
    2814                 :             : {
    2815                 :             : public:
    2816                 :      570162 :   pass_stv (gcc::context *ctxt)
    2817                 :      570162 :     : rtl_opt_pass (pass_data_stv, ctxt),
    2818                 :     1140324 :       timode_p (false)
    2819                 :             :   {}
    2820                 :             : 
    2821                 :             :   /* opt_pass methods: */
    2822                 :     2899726 :   bool gate (function *) final override
    2823                 :             :     {
    2824                 :     1449863 :       return ((!timode_p || TARGET_64BIT)
    2825                 :     4224072 :               && TARGET_STV && TARGET_SSE2 && optimize > 1);
    2826                 :             :     }
    2827                 :             : 
    2828                 :     1759252 :   unsigned int execute (function *) final override
    2829                 :             :     {
    2830                 :     1759252 :       return convert_scalars_to_vector (timode_p);
    2831                 :             :     }
    2832                 :             : 
    2833                 :      285081 :   opt_pass *clone () final override
    2834                 :             :     {
    2835                 :      285081 :       return new pass_stv (m_ctxt);
    2836                 :             :     }
    2837                 :             : 
    2838                 :      570162 :   void set_pass_param (unsigned int n, bool param) final override
    2839                 :             :     {
    2840                 :      570162 :       gcc_assert (n == 0);
    2841                 :      570162 :       timode_p = param;
    2842                 :      570162 :     }
    2843                 :             : 
    2844                 :             : private:
    2845                 :             :   bool timode_p;
    2846                 :             : }; // class pass_stv
    2847                 :             : 
    2848                 :             : } // anon namespace
    2849                 :             : 
    2850                 :             : rtl_opt_pass *
    2851                 :      285081 : make_pass_insert_vzeroupper (gcc::context *ctxt)
    2852                 :             : {
    2853                 :      285081 :   return new pass_insert_vzeroupper (ctxt);
    2854                 :             : }
    2855                 :             : 
    2856                 :             : rtl_opt_pass *
    2857                 :      285081 : make_pass_stv (gcc::context *ctxt)
    2858                 :             : {
    2859                 :      285081 :   return new pass_stv (ctxt);
    2860                 :             : }
    2861                 :             : 
    2862                 :             : /* Inserting ENDBR and pseudo patchable-area instructions.  */
    2863                 :             : 
    2864                 :             : static void
    2865                 :      199659 : rest_of_insert_endbr_and_patchable_area (bool need_endbr,
    2866                 :             :                                          unsigned int patchable_area_size)
    2867                 :             : {
    2868                 :      199659 :   rtx endbr;
    2869                 :      199659 :   rtx_insn *insn;
    2870                 :      199659 :   rtx_insn *endbr_insn = NULL;
    2871                 :      199659 :   basic_block bb;
    2872                 :             : 
    2873                 :      199659 :   if (need_endbr)
    2874                 :             :     {
    2875                 :             :       /* Currently emit EB if it's a tracking function, i.e. 'nocf_check'
    2876                 :             :          is absent among function attributes.  Later an optimization will
    2877                 :             :          be introduced to make analysis if an address of a static function
    2878                 :             :          is taken.  A static function whose address is not taken will get
    2879                 :             :          a nocf_check attribute.  This will allow to reduce the number of
    2880                 :             :          EB.  */
    2881                 :      199614 :       if (!lookup_attribute ("nocf_check",
    2882                 :      199614 :                              TYPE_ATTRIBUTES (TREE_TYPE (cfun->decl)))
    2883                 :      199604 :           && (!flag_manual_endbr
    2884                 :           8 :               || lookup_attribute ("cf_check",
    2885                 :           8 :                                    DECL_ATTRIBUTES (cfun->decl)))
    2886                 :      399217 :           && (!cgraph_node::get (cfun->decl)->only_called_directly_p ()
    2887                 :       27533 :               || ix86_cmodel == CM_LARGE
    2888                 :       27532 :               || ix86_cmodel == CM_LARGE_PIC
    2889                 :       27531 :               || flag_force_indirect_call
    2890                 :       27531 :               || (TARGET_DLLIMPORT_DECL_ATTRIBUTES
    2891                 :             :                   && DECL_DLLIMPORT_P (cfun->decl))))
    2892                 :             :         {
    2893                 :      172073 :           if (crtl->profile && flag_fentry)
    2894                 :             :             {
    2895                 :             :               /* Queue ENDBR insertion to x86_function_profiler.
    2896                 :             :                  NB: Any patchable-area insn will be inserted after
    2897                 :             :                  ENDBR.  */
    2898                 :           4 :               cfun->machine->insn_queued_at_entrance = TYPE_ENDBR;
    2899                 :             :             }
    2900                 :             :           else
    2901                 :             :             {
    2902                 :      172069 :               endbr = gen_nop_endbr ();
    2903                 :      172069 :               bb = ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb;
    2904                 :      172069 :               rtx_insn *insn = BB_HEAD (bb);
    2905                 :      172069 :               endbr_insn = emit_insn_before (endbr, insn);
    2906                 :             :             }
    2907                 :             :         }
    2908                 :             :     }
    2909                 :             : 
    2910                 :      199659 :   if (patchable_area_size)
    2911                 :             :     {
    2912                 :          51 :       if (crtl->profile && flag_fentry)
    2913                 :             :         {
    2914                 :             :           /* Queue patchable-area insertion to x86_function_profiler.
    2915                 :             :              NB: If there is a queued ENDBR, x86_function_profiler
    2916                 :             :              will also handle patchable-area.  */
    2917                 :           2 :           if (!cfun->machine->insn_queued_at_entrance)
    2918                 :           1 :             cfun->machine->insn_queued_at_entrance = TYPE_PATCHABLE_AREA;
    2919                 :             :         }
    2920                 :             :       else
    2921                 :             :         {
    2922                 :          49 :           rtx patchable_area
    2923                 :          49 :             = gen_patchable_area (GEN_INT (patchable_area_size),
    2924                 :          49 :                                   GEN_INT (crtl->patch_area_entry == 0));
    2925                 :          49 :           if (endbr_insn)
    2926                 :           3 :             emit_insn_after (patchable_area, endbr_insn);
    2927                 :             :           else
    2928                 :             :             {
    2929                 :          46 :               bb = ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb;
    2930                 :          46 :               insn = BB_HEAD (bb);
    2931                 :          46 :               emit_insn_before (patchable_area, insn);
    2932                 :             :             }
    2933                 :             :         }
    2934                 :             :     }
    2935                 :             : 
    2936                 :      199659 :   if (!need_endbr)
    2937                 :             :     return;
    2938                 :             : 
    2939                 :      199614 :   bb = 0;
    2940                 :     4156598 :   FOR_EACH_BB_FN (bb, cfun)
    2941                 :             :     {
    2942                 :    74008896 :       for (insn = BB_HEAD (bb); insn != NEXT_INSN (BB_END (bb));
    2943                 :    70051912 :            insn = NEXT_INSN (insn))
    2944                 :             :         {
    2945                 :    70051912 :           if (CALL_P (insn))
    2946                 :             :             {
    2947                 :     1422520 :               need_endbr = find_reg_note (insn, REG_SETJMP, NULL) != NULL;
    2948                 :     1422520 :               if (!need_endbr && !SIBLING_CALL_P (insn))
    2949                 :             :                 {
    2950                 :     1372069 :                   rtx call = get_call_rtx_from (insn);
    2951                 :     1372069 :                   rtx fnaddr = XEXP (call, 0);
    2952                 :     1372069 :                   tree fndecl = NULL_TREE;
    2953                 :             : 
    2954                 :             :                   /* Also generate ENDBRANCH for non-tail call which
    2955                 :             :                      may return via indirect branch.  */
    2956                 :     1372069 :                   if (GET_CODE (XEXP (fnaddr, 0)) == SYMBOL_REF)
    2957                 :     1305299 :                     fndecl = SYMBOL_REF_DECL (XEXP (fnaddr, 0));
    2958                 :     1305299 :                   if (fndecl == NULL_TREE)
    2959                 :       67808 :                     fndecl = MEM_EXPR (fnaddr);
    2960                 :       67808 :                   if (fndecl
    2961                 :     1368695 :                       && TREE_CODE (TREE_TYPE (fndecl)) != FUNCTION_TYPE
    2962                 :      628825 :                       && TREE_CODE (TREE_TYPE (fndecl)) != METHOD_TYPE)
    2963                 :             :                     fndecl = NULL_TREE;
    2964                 :     1372069 :                   if (fndecl && TYPE_ARG_TYPES (TREE_TYPE (fndecl)))
    2965                 :             :                     {
    2966                 :     1328037 :                       tree fntype = TREE_TYPE (fndecl);
    2967                 :     1328037 :                       if (lookup_attribute ("indirect_return",
    2968                 :     1328037 :                                             TYPE_ATTRIBUTES (fntype)))
    2969                 :             :                         need_endbr = true;
    2970                 :             :                     }
    2971                 :             :                 }
    2972                 :     1422508 :               if (!need_endbr)
    2973                 :     1422502 :                 continue;
    2974                 :             :               /* Generate ENDBRANCH after CALL, which can return more than
    2975                 :             :                  twice, setjmp-like functions.  */
    2976                 :             : 
    2977                 :          18 :               endbr = gen_nop_endbr ();
    2978                 :          18 :               emit_insn_after_setloc (endbr, insn, INSN_LOCATION (insn));
    2979                 :          18 :               continue;
    2980                 :          18 :             }
    2981                 :             : 
    2982                 :    68629392 :           if (JUMP_P (insn) && flag_cet_switch)
    2983                 :             :             {
    2984                 :           9 :               rtx target = JUMP_LABEL (insn);
    2985                 :           9 :               if (target == NULL_RTX || ANY_RETURN_P (target))
    2986                 :           5 :                 continue;
    2987                 :             : 
    2988                 :             :               /* Check the jump is a switch table.  */
    2989                 :           4 :               rtx_insn *label = as_a<rtx_insn *> (target);
    2990                 :           4 :               rtx_insn *table = next_insn (label);
    2991                 :           4 :               if (table == NULL_RTX || !JUMP_TABLE_DATA_P (table))
    2992                 :           2 :                 continue;
    2993                 :             : 
    2994                 :             :               /* For the indirect jump find out all places it jumps and insert
    2995                 :             :                  ENDBRANCH there.  It should be done under a special flag to
    2996                 :             :                  control ENDBRANCH generation for switch stmts.  */
    2997                 :           2 :               edge_iterator ei;
    2998                 :           2 :               edge e;
    2999                 :           2 :               basic_block dest_blk;
    3000                 :             : 
    3001                 :          24 :               FOR_EACH_EDGE (e, ei, bb->succs)
    3002                 :             :                 {
    3003                 :          22 :                   rtx_insn *insn;
    3004                 :             : 
    3005                 :          22 :                   dest_blk = e->dest;
    3006                 :          22 :                   insn = BB_HEAD (dest_blk);
    3007                 :          22 :                   gcc_assert (LABEL_P (insn));
    3008                 :          22 :                   endbr = gen_nop_endbr ();
    3009                 :          22 :                   emit_insn_after (endbr, insn);
    3010                 :             :                 }
    3011                 :           2 :               continue;
    3012                 :           2 :             }
    3013                 :             : 
    3014                 :    68629383 :           if (LABEL_P (insn) && LABEL_PRESERVE_P (insn))
    3015                 :             :             {
    3016                 :      146089 :               endbr = gen_nop_endbr ();
    3017                 :      146089 :               emit_insn_after (endbr, insn);
    3018                 :      146089 :               continue;
    3019                 :             :             }
    3020                 :             :         }
    3021                 :             :     }
    3022                 :             : 
    3023                 :             :   return;
    3024                 :             : }
    3025                 :             : 
    3026                 :             : namespace {
    3027                 :             : 
    3028                 :             : const pass_data pass_data_insert_endbr_and_patchable_area =
    3029                 :             : {
    3030                 :             :   RTL_PASS, /* type.  */
    3031                 :             :   "endbr_and_patchable_area", /* name.  */
    3032                 :             :   OPTGROUP_NONE, /* optinfo_flags.  */
    3033                 :             :   TV_MACH_DEP, /* tv_id.  */
    3034                 :             :   0, /* properties_required.  */
    3035                 :             :   0, /* properties_provided.  */
    3036                 :             :   0, /* properties_destroyed.  */
    3037                 :             :   0, /* todo_flags_start.  */
    3038                 :             :   0, /* todo_flags_finish.  */
    3039                 :             : };
    3040                 :             : 
    3041                 :             : class pass_insert_endbr_and_patchable_area : public rtl_opt_pass
    3042                 :             : {
    3043                 :             : public:
    3044                 :      285081 :   pass_insert_endbr_and_patchable_area (gcc::context *ctxt)
    3045                 :      570162 :     : rtl_opt_pass (pass_data_insert_endbr_and_patchable_area, ctxt)
    3046                 :             :   {}
    3047                 :             : 
    3048                 :             :   /* opt_pass methods: */
    3049                 :     1449863 :   bool gate (function *) final override
    3050                 :             :     {
    3051                 :     1449863 :       need_endbr = (flag_cf_protection & CF_BRANCH) != 0;
    3052                 :     1449863 :       patchable_area_size = crtl->patch_area_size - crtl->patch_area_entry;
    3053                 :     1449863 :       return need_endbr || patchable_area_size;
    3054                 :             :     }
    3055                 :             : 
    3056                 :      199659 :   unsigned int execute (function *) final override
    3057                 :             :     {
    3058                 :      199659 :       timevar_push (TV_MACH_DEP);
    3059                 :      199659 :       rest_of_insert_endbr_and_patchable_area (need_endbr,
    3060                 :             :                                                patchable_area_size);
    3061                 :      199659 :       timevar_pop (TV_MACH_DEP);
    3062                 :      199659 :       return 0;
    3063                 :             :     }
    3064                 :             : 
    3065                 :             : private:
    3066                 :             :   bool need_endbr;
    3067                 :             :   unsigned int patchable_area_size;
    3068                 :             : }; // class pass_insert_endbr_and_patchable_area
    3069                 :             : 
    3070                 :             : } // anon namespace
    3071                 :             : 
    3072                 :             : rtl_opt_pass *
    3073                 :      285081 : make_pass_insert_endbr_and_patchable_area (gcc::context *ctxt)
    3074                 :             : {
    3075                 :      285081 :   return new pass_insert_endbr_and_patchable_area (ctxt);
    3076                 :             : }
    3077                 :             : 
    3078                 :             : bool
    3079                 :     5929956 : ix86_rpad_gate ()
    3080                 :             : {
    3081                 :     5929956 :   return (TARGET_AVX
    3082                 :      404803 :           && TARGET_SSE_PARTIAL_REG_DEPENDENCY
    3083                 :      310303 :           && TARGET_SSE_MATH
    3084                 :      310081 :           && optimize
    3085                 :     6234975 :           && optimize_function_for_speed_p (cfun));
    3086                 :             : }
    3087                 :             : 
    3088                 :             : /* Generate a vector set, DEST = SRC, at entry of the nearest dominator
    3089                 :             :    for basic block map BBS, which is in the fake loop that contains the
    3090                 :             :    whole function, so that there is only a single vector set in the
    3091                 :             :    whole function.   */
    3092                 :             : 
    3093                 :             : static void
    3094                 :       19112 : ix86_place_single_vector_set (rtx dest, rtx src, bitmap bbs)
    3095                 :             : {
    3096                 :       19112 :   basic_block bb = nearest_common_dominator_for_set (CDI_DOMINATORS, bbs);
    3097                 :       19112 :   while (bb->loop_father->latch
    3098                 :       20941 :          != EXIT_BLOCK_PTR_FOR_FN (cfun))
    3099                 :        1829 :     bb = get_immediate_dominator (CDI_DOMINATORS,
    3100                 :             :                                   bb->loop_father->header);
    3101                 :             : 
    3102                 :       19112 :   rtx set = gen_rtx_SET (dest, src);
    3103                 :             : 
    3104                 :       19112 :   rtx_insn *insn = BB_HEAD (bb);
    3105                 :       95991 :   while (insn && !NONDEBUG_INSN_P (insn))
    3106                 :             :     {
    3107                 :       76883 :       if (insn == BB_END (bb))
    3108                 :             :         {
    3109                 :             :           insn = NULL;
    3110                 :             :           break;
    3111                 :             :         }
    3112                 :       76879 :       insn = NEXT_INSN (insn);
    3113                 :             :     }
    3114                 :             : 
    3115                 :       19112 :   if (insn == BB_HEAD (bb))
    3116                 :           0 :     emit_insn_before (set, insn);
    3117                 :             :   else
    3118                 :       19112 :     emit_insn_after (set, insn ? PREV_INSN (insn) : BB_END (bb));
    3119                 :       19112 : }
    3120                 :             : 
    3121                 :             : /* At entry of the nearest common dominator for basic blocks with
    3122                 :             :    conversions/rcp/sqrt/rsqrt/round, generate a single
    3123                 :             :         vxorps %xmmN, %xmmN, %xmmN
    3124                 :             :    for all
    3125                 :             :         vcvtss2sd  op, %xmmN, %xmmX
    3126                 :             :         vcvtsd2ss  op, %xmmN, %xmmX
    3127                 :             :         vcvtsi2ss  op, %xmmN, %xmmX
    3128                 :             :         vcvtsi2sd  op, %xmmN, %xmmX
    3129                 :             : 
    3130                 :             :    NB: We want to generate only a single vxorps to cover the whole
    3131                 :             :    function.  The LCM algorithm isn't appropriate here since it may
    3132                 :             :    place a vxorps inside the loop.  */
    3133                 :             : 
    3134                 :             : static unsigned int
    3135                 :       31529 : remove_partial_avx_dependency (void)
    3136                 :             : {
    3137                 :       31529 :   timevar_push (TV_MACH_DEP);
    3138                 :             : 
    3139                 :       31529 :   bitmap_obstack_initialize (NULL);
    3140                 :       31529 :   bitmap convert_bbs = BITMAP_ALLOC (NULL);
    3141                 :             : 
    3142                 :       31529 :   basic_block bb;
    3143                 :       31529 :   rtx_insn *insn, *set_insn;
    3144                 :       31529 :   rtx set;
    3145                 :       31529 :   rtx v4sf_const0 = NULL_RTX;
    3146                 :             : 
    3147                 :       31529 :   auto_vec<rtx_insn *> control_flow_insns;
    3148                 :             : 
    3149                 :             :   /* We create invalid RTL initially so defer rescans.  */
    3150                 :       31529 :   df_set_flags (DF_DEFER_INSN_RESCAN);
    3151                 :             : 
    3152                 :      288766 :   FOR_EACH_BB_FN (bb, cfun)
    3153                 :             :     {
    3154                 :     3424991 :       FOR_BB_INSNS (bb, insn)
    3155                 :             :         {
    3156                 :     3167754 :           if (!NONDEBUG_INSN_P (insn))
    3157                 :     1440202 :             continue;
    3158                 :             : 
    3159                 :     1727552 :           set = single_set (insn);
    3160                 :     1727552 :           if (!set)
    3161                 :       65070 :             continue;
    3162                 :             : 
    3163                 :     1662482 :           if (get_attr_avx_partial_xmm_update (insn)
    3164                 :             :               != AVX_PARTIAL_XMM_UPDATE_TRUE)
    3165                 :     1659504 :             continue;
    3166                 :             : 
    3167                 :             :           /* Convert PARTIAL_XMM_UPDATE_TRUE insns, DF -> SF, SF -> DF,
    3168                 :             :              SI -> SF, SI -> DF, DI -> SF, DI -> DF, sqrt, rsqrt, rcp,
    3169                 :             :              round, to vec_dup and vec_merge with subreg.  */
    3170                 :        2978 :           rtx src = SET_SRC (set);
    3171                 :        2978 :           rtx dest = SET_DEST (set);
    3172                 :        2978 :           machine_mode dest_mode = GET_MODE (dest);
    3173                 :        2978 :           bool convert_p = false;
    3174                 :        2978 :           switch (GET_CODE (src))
    3175                 :             :             {
    3176                 :        2874 :             case FLOAT:
    3177                 :        2874 :             case FLOAT_EXTEND:
    3178                 :        2874 :             case FLOAT_TRUNCATE:
    3179                 :        2874 :             case UNSIGNED_FLOAT:
    3180                 :        2874 :               convert_p = true;
    3181                 :        2874 :               break;
    3182                 :             :             default:
    3183                 :             :               break;
    3184                 :             :             }
    3185                 :             : 
    3186                 :             :           /* Only hanlde conversion here.  */
    3187                 :        2874 :           machine_mode src_mode
    3188                 :        2874 :             = convert_p ? GET_MODE (XEXP (src, 0)) : VOIDmode;
    3189                 :        2874 :           switch (src_mode)
    3190                 :             :             {
    3191                 :         172 :             case E_SFmode:
    3192                 :         172 :             case E_DFmode:
    3193                 :         172 :               if (TARGET_USE_VECTOR_FP_CONVERTS
    3194                 :         166 :                   || !TARGET_SSE_PARTIAL_REG_FP_CONVERTS_DEPENDENCY)
    3195                 :           8 :                 continue;
    3196                 :             :               break;
    3197                 :        2702 :             case E_SImode:
    3198                 :        2702 :             case E_DImode:
    3199                 :        2702 :               if (TARGET_USE_VECTOR_CONVERTS
    3200                 :        2690 :                   || !TARGET_SSE_PARTIAL_REG_CONVERTS_DEPENDENCY)
    3201                 :          14 :                 continue;
    3202                 :             :               break;
    3203                 :         104 :             case E_VOIDmode:
    3204                 :         104 :               gcc_assert (!convert_p);
    3205                 :             :               break;
    3206                 :           0 :             default:
    3207                 :           0 :               gcc_unreachable ();
    3208                 :             :             }
    3209                 :             : 
    3210                 :        2956 :           if (!v4sf_const0)
    3211                 :         960 :             v4sf_const0 = gen_reg_rtx (V4SFmode);
    3212                 :             : 
    3213                 :        2956 :           rtx zero;
    3214                 :        2956 :           machine_mode dest_vecmode;
    3215                 :        2956 :           switch (dest_mode)
    3216                 :             :             {
    3217                 :          90 :             case E_HFmode:
    3218                 :          90 :               dest_vecmode = V8HFmode;
    3219                 :          90 :               zero = gen_rtx_SUBREG (V8HFmode, v4sf_const0, 0);
    3220                 :          90 :               break;
    3221                 :             :             case E_SFmode:
    3222                 :             :               dest_vecmode = V4SFmode;
    3223                 :             :               zero = v4sf_const0;
    3224                 :             :               break;
    3225                 :        1007 :             case E_DFmode:
    3226                 :        1007 :               dest_vecmode = V2DFmode;
    3227                 :        1007 :               zero = gen_rtx_SUBREG (V2DFmode, v4sf_const0, 0);
    3228                 :        1007 :               break;
    3229                 :           0 :             default:
    3230                 :           0 :               gcc_unreachable ();
    3231                 :             :             }
    3232                 :             : 
    3233                 :             :           /* Change source to vector mode.  */
    3234                 :        2956 :           src = gen_rtx_VEC_DUPLICATE (dest_vecmode, src);
    3235                 :        2956 :           src = gen_rtx_VEC_MERGE (dest_vecmode, src, zero,
    3236                 :             :                                    GEN_INT (HOST_WIDE_INT_1U));
    3237                 :             :           /* Change destination to vector mode.  */
    3238                 :        2956 :           rtx vec = gen_reg_rtx (dest_vecmode);
    3239                 :             :           /* Generate an XMM vector SET.  */
    3240                 :        2956 :           set = gen_rtx_SET (vec, src);
    3241                 :        2956 :           set_insn = emit_insn_before (set, insn);
    3242                 :             : 
    3243                 :        2956 :           if (cfun->can_throw_non_call_exceptions)
    3244                 :             :             {
    3245                 :             :               /* Handle REG_EH_REGION note.  */
    3246                 :           0 :               rtx note = find_reg_note (insn, REG_EH_REGION, NULL_RTX);
    3247                 :           0 :               if (note)
    3248                 :             :                 {
    3249                 :           0 :                   control_flow_insns.safe_push (set_insn);
    3250                 :           0 :                   add_reg_note (set_insn, REG_EH_REGION, XEXP (note, 0));
    3251                 :             :                 }
    3252                 :             :             }
    3253                 :             : 
    3254                 :        2956 :           src = gen_rtx_SUBREG (dest_mode, vec, 0);
    3255                 :        2956 :           set = gen_rtx_SET (dest, src);
    3256                 :             : 
    3257                 :             :           /* Drop possible dead definitions.  */
    3258                 :        2956 :           PATTERN (insn) = set;
    3259                 :             : 
    3260                 :        2956 :           INSN_CODE (insn) = -1;
    3261                 :        2956 :           recog_memoized (insn);
    3262                 :        2956 :           df_insn_rescan (insn);
    3263                 :        2956 :           bitmap_set_bit (convert_bbs, bb->index);
    3264                 :             :         }
    3265                 :             :     }
    3266                 :             : 
    3267                 :       31529 :   if (v4sf_const0)
    3268                 :             :     {
    3269                 :             :       /* (Re-)discover loops so that bb->loop_father can be used in the
    3270                 :             :          analysis below.  */
    3271                 :         960 :       calculate_dominance_info (CDI_DOMINATORS);
    3272                 :         960 :       loop_optimizer_init (AVOID_CFG_MODIFICATIONS);
    3273                 :             : 
    3274                 :         960 :       ix86_place_single_vector_set (v4sf_const0,
    3275                 :             :                                     CONST0_RTX (V4SFmode),
    3276                 :             :                                     convert_bbs);
    3277                 :             : 
    3278                 :         960 :       loop_optimizer_finalize ();
    3279                 :             : 
    3280                 :         960 :       if (!control_flow_insns.is_empty ())
    3281                 :             :         {
    3282                 :           0 :           free_dominance_info (CDI_DOMINATORS);
    3283                 :             : 
    3284                 :           0 :           unsigned int i;
    3285                 :           0 :           FOR_EACH_VEC_ELT (control_flow_insns, i, insn)
    3286                 :           0 :             if (control_flow_insn_p (insn))
    3287                 :             :               {
    3288                 :             :                 /* Split the block after insn.  There will be a fallthru
    3289                 :             :                    edge, which is OK so we keep it.  We have to create
    3290                 :             :                    the exception edges ourselves.  */
    3291                 :           0 :                 bb = BLOCK_FOR_INSN (insn);
    3292                 :           0 :                 split_block (bb, insn);
    3293                 :           0 :                 rtl_make_eh_edge (NULL, bb, BB_END (bb));
    3294                 :             :               }
    3295                 :             :         }
    3296                 :             :     }
    3297                 :             : 
    3298                 :       31529 :   df_process_deferred_rescans ();
    3299                 :       31529 :   df_clear_flags (DF_DEFER_INSN_RESCAN);
    3300                 :       31529 :   bitmap_obstack_release (NULL);
    3301                 :       31529 :   BITMAP_FREE (convert_bbs);
    3302                 :             : 
    3303                 :       31529 :   timevar_pop (TV_MACH_DEP);
    3304                 :       31529 :   return 0;
    3305                 :       31529 : }
    3306                 :             : 
    3307                 :             : namespace {
    3308                 :             : 
    3309                 :             : const pass_data pass_data_remove_partial_avx_dependency =
    3310                 :             : {
    3311                 :             :   RTL_PASS, /* type */
    3312                 :             :   "rpad", /* name */
    3313                 :             :   OPTGROUP_NONE, /* optinfo_flags */
    3314                 :             :   TV_MACH_DEP, /* tv_id */
    3315                 :             :   0, /* properties_required */
    3316                 :             :   0, /* properties_provided */
    3317                 :             :   0, /* properties_destroyed */
    3318                 :             :   0, /* todo_flags_start */
    3319                 :             :   0, /* todo_flags_finish */
    3320                 :             : };
    3321                 :             : 
    3322                 :             : class pass_remove_partial_avx_dependency : public rtl_opt_pass
    3323                 :             : {
    3324                 :             : public:
    3325                 :      285081 :   pass_remove_partial_avx_dependency (gcc::context *ctxt)
    3326                 :      570162 :     : rtl_opt_pass (pass_data_remove_partial_avx_dependency, ctxt)
    3327                 :             :   {}
    3328                 :             : 
    3329                 :             :   /* opt_pass methods: */
    3330                 :     1449863 :   bool gate (function *) final override
    3331                 :             :     {
    3332                 :     1449863 :       return ix86_rpad_gate ();
    3333                 :             :     }
    3334                 :             : 
    3335                 :       31529 :   unsigned int execute (function *) final override
    3336                 :             :     {
    3337                 :       31529 :       return remove_partial_avx_dependency ();
    3338                 :             :     }
    3339                 :             : }; // class pass_rpad
    3340                 :             : 
    3341                 :             : } // anon namespace
    3342                 :             : 
    3343                 :             : rtl_opt_pass *
    3344                 :      285081 : make_pass_remove_partial_avx_dependency (gcc::context *ctxt)
    3345                 :             : {
    3346                 :      285081 :   return new pass_remove_partial_avx_dependency (ctxt);
    3347                 :             : }
    3348                 :             : 
    3349                 :             : /* Return a machine mode suitable for vector SIZE.  */
    3350                 :             : 
    3351                 :             : static machine_mode
    3352                 :       18533 : ix86_get_vector_load_mode (unsigned int size)
    3353                 :             : {
    3354                 :       18533 :   machine_mode mode;
    3355                 :       18533 :   if (size == 64)
    3356                 :             :     mode = V64QImode;
    3357                 :             :   else if (size == 32)
    3358                 :             :     mode = V32QImode;
    3359                 :             :   else if (size == 16)
    3360                 :             :     mode = V16QImode;
    3361                 :             :   else if (size == 8)
    3362                 :             :     mode = V8QImode;
    3363                 :             :   else if (size == 4)
    3364                 :             :     mode = V4QImode;
    3365                 :             :   else if (size == 2)
    3366                 :             :     mode = V2QImode;
    3367                 :             :   else
    3368                 :           0 :     gcc_unreachable ();
    3369                 :       18533 :   return mode;
    3370                 :             : }
    3371                 :             : 
    3372                 :             : /* Replace the source operand of instructions in VECTOR_INSNS with
    3373                 :             :    VECTOR_CONST in VECTOR_MODE.  */
    3374                 :             : 
    3375                 :             : static void
    3376                 :       18152 : replace_vector_const (machine_mode vector_mode, rtx vector_const,
    3377                 :             :                       auto_bitmap &vector_insns)
    3378                 :             : {
    3379                 :       18152 :   bitmap_iterator bi;
    3380                 :       18152 :   unsigned int id;
    3381                 :             : 
    3382                 :       91200 :   EXECUTE_IF_SET_IN_BITMAP (vector_insns, 0, id, bi)
    3383                 :             :     {
    3384                 :       73048 :       rtx_insn *insn = DF_INSN_UID_GET (id)->insn;
    3385                 :             : 
    3386                 :             :       /* Get the single SET instruction.  */
    3387                 :       73048 :       rtx set = single_set (insn);
    3388                 :       73048 :       rtx src = SET_SRC (set);
    3389                 :       73048 :       machine_mode mode = GET_MODE (src);
    3390                 :             : 
    3391                 :       73048 :       rtx replace;
    3392                 :             :       /* Replace the source operand with VECTOR_CONST.  */
    3393                 :       73048 :       if (SUBREG_P (src) || mode == vector_mode)
    3394                 :             :         replace = vector_const;
    3395                 :             :       else
    3396                 :             :         {
    3397                 :       52951 :           unsigned int size = GET_MODE_SIZE (mode);
    3398                 :       52951 :           if (size < ix86_regmode_natural_size (mode))
    3399                 :             :             {
    3400                 :             :               /* If the mode size is smaller than its natural size,
    3401                 :             :                  first insert an extra move with a QI vector SUBREG
    3402                 :             :                  of the same size to avoid validate_subreg failure.  */
    3403                 :         381 :               machine_mode vmode = ix86_get_vector_load_mode (size);
    3404                 :         381 :               rtx vreg;
    3405                 :         381 :               if (mode == vmode)
    3406                 :             :                 vreg = vector_const;
    3407                 :             :               else
    3408                 :             :                 {
    3409                 :          34 :                   vreg = gen_reg_rtx (vmode);
    3410                 :          34 :                   rtx vsubreg = gen_rtx_SUBREG (vmode, vector_const, 0);
    3411                 :          34 :                   rtx pat = gen_rtx_SET (vreg, vsubreg);
    3412                 :          34 :                   emit_insn_before (pat, insn);
    3413                 :             :                 }
    3414                 :         381 :               replace = gen_rtx_SUBREG (mode, vreg, 0);
    3415                 :             :             }
    3416                 :             :           else
    3417                 :       52570 :             replace = gen_rtx_SUBREG (mode, vector_const, 0);
    3418                 :             :         }
    3419                 :             : 
    3420                 :       73048 :       SET_SRC (set) = replace;
    3421                 :             :       /* Drop possible dead definitions.  */
    3422                 :       73048 :       PATTERN (insn) = set;
    3423                 :       73048 :       INSN_CODE (insn) = -1;
    3424                 :       73048 :       recog_memoized (insn);
    3425                 :       73048 :       df_insn_rescan (insn);
    3426                 :             :     }
    3427                 :       18152 : }
    3428                 :             : 
    3429                 :             : /* At entry of the nearest common dominator for basic blocks with vector
    3430                 :             :    CONST0_RTX and integer CONSTM1_RTX uses, generate a single widest
    3431                 :             :    vector set instruction for all CONST0_RTX and integer CONSTM1_RTX
    3432                 :             :    uses.
    3433                 :             : 
    3434                 :             :    NB: We want to generate only a single widest vector set to cover the
    3435                 :             :    whole function.  The LCM algorithm isn't appropriate here since it
    3436                 :             :    may place a vector set inside the loop.  */
    3437                 :             : 
    3438                 :             : static unsigned int
    3439                 :      959051 : remove_redundant_vector_load (void)
    3440                 :             : {
    3441                 :      959051 :   timevar_push (TV_MACH_DEP);
    3442                 :             : 
    3443                 :      959051 :   auto_bitmap zero_bbs;
    3444                 :      959051 :   auto_bitmap m1_bbs;
    3445                 :      959051 :   auto_bitmap zero_insns;
    3446                 :      959051 :   auto_bitmap m1_insns;
    3447                 :             : 
    3448                 :      959051 :   basic_block bb;
    3449                 :      959051 :   rtx_insn *insn;
    3450                 :      959051 :   unsigned HOST_WIDE_INT zero_count = 0;
    3451                 :      959051 :   unsigned HOST_WIDE_INT m1_count = 0;
    3452                 :      959051 :   unsigned int zero_size = 0;
    3453                 :      959051 :   unsigned int m1_size = 0;
    3454                 :             : 
    3455                 :      959051 :   df_set_flags (DF_DEFER_INSN_RESCAN);
    3456                 :             : 
    3457                 :    10874487 :   FOR_EACH_BB_FN (bb, cfun)
    3458                 :             :     {
    3459                 :   130789787 :       FOR_BB_INSNS (bb, insn)
    3460                 :             :         {
    3461                 :   120874351 :           if (!NONDEBUG_INSN_P (insn))
    3462                 :    67075727 :             continue;
    3463                 :             : 
    3464                 :    53798624 :           rtx set = single_set (insn);
    3465                 :    53798624 :           if (!set)
    3466                 :     3629333 :             continue;
    3467                 :             : 
    3468                 :             :           /* Record single set vector instruction with CONST0_RTX and
    3469                 :             :              CONSTM1_RTX source.  Record basic blocks with CONST0_RTX and
    3470                 :             :              CONSTM1_RTX.  Count CONST0_RTX and CONSTM1_RTX.  Record the
    3471                 :             :              maximum size of CONST0_RTX and CONSTM1_RTX.  */
    3472                 :             : 
    3473                 :    50169291 :           rtx dest = SET_DEST (set);
    3474                 :    50169291 :           machine_mode mode = GET_MODE (dest);
    3475                 :             :           /* Skip non-vector instruction.  */
    3476                 :    50169291 :           if (!VECTOR_MODE_P (mode))
    3477                 :    46862517 :             continue;
    3478                 :             : 
    3479                 :     3306774 :           rtx src = SET_SRC (set);
    3480                 :             :           /* Skip non-vector load instruction.  */
    3481                 :     3306774 :           if (!REG_P (dest) && !SUBREG_P (dest))
    3482                 :     1317145 :             continue;
    3483                 :             : 
    3484                 :     1989629 :           if (src == CONST0_RTX (mode))
    3485                 :             :             {
    3486                 :             :               /* Record vector instruction with CONST0_RTX.  */
    3487                 :       99112 :               bitmap_set_bit (zero_insns, INSN_UID (insn));
    3488                 :             : 
    3489                 :             :               /* Record the maximum vector size.  */
    3490                 :      198224 :               if (zero_size < GET_MODE_SIZE (mode))
    3491                 :       93266 :                 zero_size = GET_MODE_SIZE (mode);
    3492                 :             : 
    3493                 :             :               /* Record the basic block with CONST0_RTX.  */
    3494                 :       99112 :               bitmap_set_bit (zero_bbs, bb->index);
    3495                 :       99112 :               zero_count++;
    3496                 :             :             }
    3497                 :     1890517 :           else if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT
    3498                 :     1498145 :                    && src == CONSTM1_RTX (mode))
    3499                 :             :             {
    3500                 :             :               /* Record vector instruction with CONSTM1_RTX.  */
    3501                 :       10439 :               bitmap_set_bit (m1_insns, INSN_UID (insn));
    3502                 :             : 
    3503                 :             :               /* Record the maximum vector size.  */
    3504                 :       20878 :               if (m1_size < GET_MODE_SIZE (mode))
    3505                 :       16650 :                 m1_size = GET_MODE_SIZE (mode);
    3506                 :             : 
    3507                 :             :               /* Record the basic block with CONSTM1_RTX.  */
    3508                 :       10439 :               bitmap_set_bit (m1_bbs, bb->index);
    3509                 :       10439 :               m1_count++;
    3510                 :             :             }
    3511                 :             :         }
    3512                 :             :     }
    3513                 :             : 
    3514                 :      959051 :   if (zero_count > 1 || m1_count > 1)
    3515                 :             :     {
    3516                 :       17446 :       machine_mode zero_mode, m1_mode;
    3517                 :       17446 :       rtx vector_const0, vector_constm1;
    3518                 :             : 
    3519                 :       17446 :       if (zero_count > 1)
    3520                 :             :         {
    3521                 :       17003 :           zero_mode = ix86_get_vector_load_mode (zero_size);
    3522                 :       17003 :           vector_const0 = gen_reg_rtx (zero_mode);
    3523                 :       17003 :           replace_vector_const (zero_mode, vector_const0, zero_insns);
    3524                 :             :         }
    3525                 :             :       else
    3526                 :             :         {
    3527                 :             :           zero_mode = VOIDmode;
    3528                 :             :           vector_const0 = nullptr;
    3529                 :             :         }
    3530                 :             : 
    3531                 :       17446 :       if (m1_count > 1)
    3532                 :             :         {
    3533                 :        1149 :           m1_mode = ix86_get_vector_load_mode (m1_size);
    3534                 :        1149 :           vector_constm1 = gen_reg_rtx (m1_mode);
    3535                 :        1149 :           replace_vector_const (m1_mode, vector_constm1, m1_insns);
    3536                 :             :         }
    3537                 :             :       else
    3538                 :             :         {
    3539                 :             :           m1_mode = VOIDmode;
    3540                 :             :           vector_constm1 = nullptr;
    3541                 :             :         }
    3542                 :             : 
    3543                 :             :       /* (Re-)discover loops so that bb->loop_father can be used in the
    3544                 :             :          analysis below.  */
    3545                 :       17446 :       calculate_dominance_info (CDI_DOMINATORS);
    3546                 :       17446 :       loop_optimizer_init (AVOID_CFG_MODIFICATIONS);
    3547                 :             : 
    3548                 :       17446 :       if (vector_const0)
    3549                 :       17003 :         ix86_place_single_vector_set (vector_const0,
    3550                 :       17003 :                                       CONST0_RTX (zero_mode),
    3551                 :             :                                       zero_bbs);
    3552                 :             : 
    3553                 :       17446 :       if (vector_constm1)
    3554                 :        1149 :         ix86_place_single_vector_set (vector_constm1,
    3555                 :        1149 :                                       CONSTM1_RTX (m1_mode),
    3556                 :             :                                       m1_bbs);
    3557                 :             : 
    3558                 :       17446 :       loop_optimizer_finalize ();
    3559                 :             : 
    3560                 :       17446 :       df_process_deferred_rescans ();
    3561                 :             :     }
    3562                 :             : 
    3563                 :      959051 :   df_clear_flags (DF_DEFER_INSN_RESCAN);
    3564                 :             : 
    3565                 :      959051 :   timevar_pop (TV_MACH_DEP);
    3566                 :      959051 :   return 0;
    3567                 :      959051 : }
    3568                 :             : 
    3569                 :             : namespace {
    3570                 :             : 
    3571                 :             : const pass_data pass_data_remove_redundant_vector_load =
    3572                 :             : {
    3573                 :             :   RTL_PASS, /* type */
    3574                 :             :   "rrvl", /* name */
    3575                 :             :   OPTGROUP_NONE, /* optinfo_flags */
    3576                 :             :   TV_MACH_DEP, /* tv_id */
    3577                 :             :   0, /* properties_required */
    3578                 :             :   0, /* properties_provided */
    3579                 :             :   0, /* properties_destroyed */
    3580                 :             :   0, /* todo_flags_start */
    3581                 :             :   0, /* todo_flags_finish */
    3582                 :             : };
    3583                 :             : 
    3584                 :             : class pass_remove_redundant_vector_load : public rtl_opt_pass
    3585                 :             : {
    3586                 :             : public:
    3587                 :      285081 :   pass_remove_redundant_vector_load (gcc::context *ctxt)
    3588                 :      570162 :     : rtl_opt_pass (pass_data_remove_redundant_vector_load, ctxt)
    3589                 :             :   {}
    3590                 :             : 
    3591                 :             :   /* opt_pass methods: */
    3592                 :     1449863 :   bool gate (function *fun) final override
    3593                 :             :     {
    3594                 :     1449863 :       return (TARGET_SSE2
    3595                 :     1445668 :               && optimize
    3596                 :     2471345 :               && optimize_function_for_speed_p (fun));
    3597                 :             :     }
    3598                 :             : 
    3599                 :      959051 :   unsigned int execute (function *) final override
    3600                 :             :     {
    3601                 :      959051 :       return remove_redundant_vector_load ();
    3602                 :             :     }
    3603                 :             : }; // class pass_remove_redundant_vector_load
    3604                 :             : 
    3605                 :             : } // anon namespace
    3606                 :             : 
    3607                 :             : rtl_opt_pass *
    3608                 :      285081 : make_pass_remove_redundant_vector_load (gcc::context *ctxt)
    3609                 :             : {
    3610                 :      285081 :   return new pass_remove_redundant_vector_load (ctxt);
    3611                 :             : }
    3612                 :             : 
    3613                 :             : /* Convert legacy instructions that clobbers EFLAGS to APX_NF
    3614                 :             :    instructions when there are no flag set between a flag
    3615                 :             :    producer and user.  */
    3616                 :             : 
    3617                 :             : static unsigned int
    3618                 :         348 : ix86_apx_nf_convert (void)
    3619                 :             : {
    3620                 :         348 :   timevar_push (TV_MACH_DEP);
    3621                 :             : 
    3622                 :         348 :   basic_block bb;
    3623                 :         348 :   rtx_insn *insn;
    3624                 :         348 :   hash_map <rtx_insn *, rtx> converting_map;
    3625                 :         348 :   auto_vec <rtx_insn *> current_convert_list;
    3626                 :             : 
    3627                 :         348 :   bool converting_seq = false;
    3628                 :         348 :   rtx cc = gen_rtx_REG (CCmode, FLAGS_REG);
    3629                 :             : 
    3630                 :         737 :   FOR_EACH_BB_FN (bb, cfun)
    3631                 :             :     {
    3632                 :             :       /* Reset conversion for each bb.  */
    3633                 :         389 :       converting_seq = false;
    3634                 :        4447 :       FOR_BB_INSNS (bb, insn)
    3635                 :             :         {
    3636                 :        4058 :           if (!NONDEBUG_INSN_P (insn))
    3637                 :        4403 :             continue;
    3638                 :             : 
    3639                 :        3294 :           if (recog_memoized (insn) < 0)
    3640                 :         325 :             continue;
    3641                 :             : 
    3642                 :             :           /* Convert candidate insns after cstore, which should
    3643                 :             :              satisify the two conditions:
    3644                 :             :              1. Is not flag user or producer, only clobbers
    3645                 :             :              FLAGS_REG.
    3646                 :             :              2. Have corresponding nf pattern.  */
    3647                 :             : 
    3648                 :        2969 :           rtx pat = PATTERN (insn);
    3649                 :             : 
    3650                 :             :           /* Starting convertion at first cstorecc.  */
    3651                 :        2969 :           rtx set = NULL_RTX;
    3652                 :        2969 :           if (!converting_seq
    3653                 :        2566 :               && (set = single_set (insn))
    3654                 :        2515 :               && ix86_comparison_operator (SET_SRC (set), VOIDmode)
    3655                 :          63 :               && reg_overlap_mentioned_p (cc, SET_SRC (set))
    3656                 :        3029 :               && !reg_overlap_mentioned_p (cc, SET_DEST (set)))
    3657                 :             :             {
    3658                 :          60 :               converting_seq = true;
    3659                 :          60 :               current_convert_list.truncate (0);
    3660                 :             :             }
    3661                 :             :           /* Terminate at the next explicit flag set.  */
    3662                 :        2909 :           else if (reg_set_p (cc, pat)
    3663                 :        2909 :                    && GET_CODE (set_of (cc, pat)) != CLOBBER)
    3664                 :             :             converting_seq = false;
    3665                 :             : 
    3666                 :        2818 :           if (!converting_seq)
    3667                 :        2550 :             continue;
    3668                 :             : 
    3669                 :         419 :           if (get_attr_has_nf (insn)
    3670                 :         419 :               && GET_CODE (pat) == PARALLEL)
    3671                 :             :             {
    3672                 :             :               /* Record the insn to candidate map.  */
    3673                 :          17 :               current_convert_list.safe_push (insn);
    3674                 :          17 :               converting_map.put (insn, pat);
    3675                 :             :             }
    3676                 :             :           /* If the insn clobbers flags but has no nf_attr,
    3677                 :             :              revoke all previous candidates.  */
    3678                 :         402 :           else if (!get_attr_has_nf (insn)
    3679                 :         401 :                    && reg_set_p (cc, pat)
    3680                 :         402 :                    && GET_CODE (set_of (cc, pat)) == CLOBBER)
    3681                 :             :             {
    3682                 :           0 :               for (auto item : current_convert_list)
    3683                 :           0 :                 converting_map.remove (item);
    3684                 :           0 :               converting_seq = false;
    3685                 :             :             }
    3686                 :             :         }
    3687                 :             :     }
    3688                 :             : 
    3689                 :         348 :   if (!converting_map.is_empty ())
    3690                 :             :     {
    3691                 :          25 :       for (auto iter = converting_map.begin ();
    3692                 :          50 :            iter != converting_map.end (); ++iter)
    3693                 :             :         {
    3694                 :          17 :           rtx_insn *replace = (*iter).first;
    3695                 :          17 :           rtx pat = (*iter).second;
    3696                 :          17 :           int i, n = 0, len = XVECLEN (pat, 0);
    3697                 :          17 :           rtx *new_elems = XALLOCAVEC (rtx, len);
    3698                 :          17 :           rtx new_pat;
    3699                 :          51 :           for (i = 0; i < len; i++)
    3700                 :             :             {
    3701                 :          34 :               rtx temp = XVECEXP (pat, 0, i);
    3702                 :          51 :               if (! (GET_CODE (temp) == CLOBBER
    3703                 :          17 :                      && reg_overlap_mentioned_p (cc,
    3704                 :          17 :                                                  XEXP (temp, 0))))
    3705                 :             :                 {
    3706                 :          17 :                   new_elems[n] = temp;
    3707                 :          17 :                   n++;
    3708                 :             :                 }
    3709                 :             :             }
    3710                 :             : 
    3711                 :          17 :           if (n == 1)
    3712                 :          17 :             new_pat = new_elems[0];
    3713                 :             :           else
    3714                 :           0 :             new_pat =
    3715                 :           0 :               gen_rtx_PARALLEL (VOIDmode,
    3716                 :             :                                 gen_rtvec_v (n,
    3717                 :             :                                              new_elems));
    3718                 :             : 
    3719                 :          17 :           PATTERN (replace) = new_pat;
    3720                 :          17 :           INSN_CODE (replace) = -1;
    3721                 :          17 :           recog_memoized (replace);
    3722                 :          17 :           df_insn_rescan (replace);
    3723                 :             :         }
    3724                 :             :     }
    3725                 :             : 
    3726                 :         348 :   timevar_pop (TV_MACH_DEP);
    3727                 :         348 :   return 0;
    3728                 :         348 : }
    3729                 :             : 
    3730                 :             : 
    3731                 :             : namespace {
    3732                 :             : 
    3733                 :             : const pass_data pass_data_apx_nf_convert =
    3734                 :             : {
    3735                 :             :   RTL_PASS, /* type */
    3736                 :             :   "apx_nfcvt", /* name */
    3737                 :             :   OPTGROUP_NONE, /* optinfo_flags */
    3738                 :             :   TV_MACH_DEP, /* tv_id */
    3739                 :             :   0, /* properties_required */
    3740                 :             :   0, /* properties_provided */
    3741                 :             :   0, /* properties_destroyed */
    3742                 :             :   0, /* todo_flags_start */
    3743                 :             :   0, /* todo_flags_finish */
    3744                 :             : };
    3745                 :             : 
    3746                 :             : class pass_apx_nf_convert : public rtl_opt_pass
    3747                 :             : {
    3748                 :             : public:
    3749                 :      285081 :   pass_apx_nf_convert (gcc::context *ctxt)
    3750                 :      570162 :     : rtl_opt_pass (pass_data_apx_nf_convert, ctxt)
    3751                 :             :   {}
    3752                 :             : 
    3753                 :             :   /* opt_pass methods: */
    3754                 :     1449863 :   bool gate (function *) final override
    3755                 :             :     {
    3756                 :     1449863 :       return (TARGET_APX_NF
    3757                 :         438 :               && optimize
    3758                 :     1450294 :               && optimize_function_for_speed_p (cfun));
    3759                 :             :     }
    3760                 :             : 
    3761                 :         348 :   unsigned int execute (function *) final override
    3762                 :             :     {
    3763                 :         348 :       return ix86_apx_nf_convert ();
    3764                 :             :     }
    3765                 :             : }; // class pass_apx_nf_convert
    3766                 :             : 
    3767                 :             : } // anon namespace
    3768                 :             : 
    3769                 :             : rtl_opt_pass *
    3770                 :      285081 : make_pass_apx_nf_convert (gcc::context *ctxt)
    3771                 :             : {
    3772                 :      285081 :   return new pass_apx_nf_convert (ctxt);
    3773                 :             : }
    3774                 :             : 
    3775                 :             : /* When a hot loop can be fit into one cacheline,
    3776                 :             :    force align the loop without considering the max skip.  */
    3777                 :             : static void
    3778                 :      960864 : ix86_align_loops ()
    3779                 :             : {
    3780                 :      960864 :   basic_block bb;
    3781                 :             : 
    3782                 :             :   /* Don't do this when we don't know cache line size.  */
    3783                 :      960864 :   if (ix86_cost->prefetch_block == 0)
    3784                 :           9 :     return;
    3785                 :             : 
    3786                 :      960855 :   loop_optimizer_init (AVOID_CFG_MODIFICATIONS);
    3787                 :      960855 :   profile_count count_threshold = cfun->cfg->count_max / param_align_threshold;
    3788                 :    11330999 :   FOR_EACH_BB_FN (bb, cfun)
    3789                 :             :     {
    3790                 :    10370144 :       rtx_insn *label = BB_HEAD (bb);
    3791                 :    10370144 :       bool has_fallthru = 0;
    3792                 :    10370144 :       edge e;
    3793                 :    10370144 :       edge_iterator ei;
    3794                 :             : 
    3795                 :    10370144 :       if (!LABEL_P (label))
    3796                 :     5234878 :         continue;
    3797                 :             : 
    3798                 :     5140287 :       profile_count fallthru_count = profile_count::zero ();
    3799                 :     5140287 :       profile_count branch_count = profile_count::zero ();
    3800                 :             : 
    3801                 :    14908461 :       FOR_EACH_EDGE (e, ei, bb->preds)
    3802                 :             :         {
    3803                 :     9768174 :           if (e->flags & EDGE_FALLTHRU)
    3804                 :     2498582 :             has_fallthru = 1, fallthru_count += e->count ();
    3805                 :             :           else
    3806                 :     7269592 :             branch_count += e->count ();
    3807                 :             :         }
    3808                 :             : 
    3809                 :     5140287 :       if (!fallthru_count.initialized_p () || !branch_count.initialized_p ())
    3810                 :        5021 :         continue;
    3811                 :             : 
    3812                 :     5135266 :       if (bb->loop_father
    3813                 :     5135266 :           && bb->loop_father->latch != EXIT_BLOCK_PTR_FOR_FN (cfun)
    3814                 :     6464511 :           && (has_fallthru
    3815                 :     1329245 :               ? (!(single_succ_p (bb)
    3816                 :      145223 :                    && single_succ (bb) == EXIT_BLOCK_PTR_FOR_FN (cfun))
    3817                 :      918869 :                  && optimize_bb_for_speed_p (bb)
    3818                 :      834548 :                  && branch_count + fallthru_count > count_threshold
    3819                 :      723423 :                  && (branch_count > fallthru_count * param_align_loop_iterations))
    3820                 :             :               /* In case there'no fallthru for the loop.
    3821                 :             :                  Nops inserted won't be executed.  */
    3822                 :      410376 :               : (branch_count > count_threshold
    3823                 :      136706 :                  || (bb->count > bb->prev_bb->count * 10
    3824                 :       13192 :                      && (bb->prev_bb->count
    3825                 :     4600208 :                          <= ENTRY_BLOCK_PTR_FOR_FN (cfun)->count / 2)))))
    3826                 :             :         {
    3827                 :      548250 :           rtx_insn* insn, *end_insn;
    3828                 :      548250 :           HOST_WIDE_INT size = 0;
    3829                 :      548250 :           bool padding_p = true;
    3830                 :      548250 :           basic_block tbb = bb;
    3831                 :      548250 :           unsigned cond_branch_num = 0;
    3832                 :      548250 :           bool detect_tight_loop_p = false;
    3833                 :             : 
    3834                 :      863299 :           for (unsigned int i = 0; i != bb->loop_father->num_nodes;
    3835                 :      315049 :                i++, tbb = tbb->next_bb)
    3836                 :             :             {
    3837                 :             :               /* Only handle continuous cfg layout. */
    3838                 :      863299 :               if (bb->loop_father != tbb->loop_father)
    3839                 :             :                 {
    3840                 :             :                   padding_p = false;
    3841                 :             :                   break;
    3842                 :             :                 }
    3843                 :             : 
    3844                 :    10394067 :               FOR_BB_INSNS (tbb, insn)
    3845                 :             :                 {
    3846                 :     9737003 :                   if (!NONDEBUG_INSN_P (insn))
    3847                 :     5592941 :                     continue;
    3848                 :     4144062 :                   size += ix86_min_insn_size (insn);
    3849                 :             : 
    3850                 :             :                   /* We don't know size of inline asm.
    3851                 :             :                      Don't align loop for call.  */
    3852                 :     4144062 :                   if (asm_noperands (PATTERN (insn)) >= 0
    3853                 :     4144062 :                       || CALL_P (insn))
    3854                 :             :                     {
    3855                 :             :                       size = -1;
    3856                 :             :                       break;
    3857                 :             :                     }
    3858                 :             :                 }
    3859                 :             : 
    3860                 :      822781 :               if (size == -1 || size > ix86_cost->prefetch_block)
    3861                 :             :                 {
    3862                 :             :                   padding_p = false;
    3863                 :             :                   break;
    3864                 :             :                 }
    3865                 :             : 
    3866                 :     1452883 :               FOR_EACH_EDGE (e, ei, tbb->succs)
    3867                 :             :                 {
    3868                 :             :                   /* It could be part of the loop.  */
    3869                 :      999426 :                   if (e->dest == bb)
    3870                 :             :                     {
    3871                 :             :                       detect_tight_loop_p = true;
    3872                 :             :                       break;
    3873                 :             :                     }
    3874                 :             :                 }
    3875                 :             : 
    3876                 :      628114 :               if (detect_tight_loop_p)
    3877                 :             :                 break;
    3878                 :             : 
    3879                 :      453457 :               end_insn = BB_END (tbb);
    3880                 :      453457 :               if (JUMP_P (end_insn))
    3881                 :             :                 {
    3882                 :             :                   /* For decoded icache:
    3883                 :             :                      1. Up to two branches are allowed per Way.
    3884                 :             :                      2. A non-conditional branch is the last micro-op in a Way.
    3885                 :             :                   */
    3886                 :      366186 :                   if (onlyjump_p (end_insn)
    3887                 :      366186 :                       && (any_uncondjump_p (end_insn)
    3888                 :      311060 :                           || single_succ_p (tbb)))
    3889                 :             :                     {
    3890                 :             :                       padding_p = false;
    3891                 :             :                       break;
    3892                 :             :                     }
    3893                 :      311060 :                   else if (++cond_branch_num >= 2)
    3894                 :             :                     {
    3895                 :             :                       padding_p = false;
    3896                 :             :                       break;
    3897                 :             :                     }
    3898                 :             :                 }
    3899                 :             : 
    3900                 :             :             }
    3901                 :             : 
    3902                 :      548250 :           if (padding_p && detect_tight_loop_p)
    3903                 :             :             {
    3904                 :      349314 :               emit_insn_before (gen_max_skip_align (GEN_INT (ceil_log2 (size)),
    3905                 :             :                                                     GEN_INT (0)), label);
    3906                 :             :               /* End of function.  */
    3907                 :      174657 :               if (!tbb || tbb == EXIT_BLOCK_PTR_FOR_FN (cfun))
    3908                 :             :                 break;
    3909                 :             :               /* Skip bb which already fits into one cacheline.  */
    3910                 :             :               bb = tbb;
    3911                 :             :             }
    3912                 :             :         }
    3913                 :             :     }
    3914                 :             : 
    3915                 :      960855 :   loop_optimizer_finalize ();
    3916                 :      960855 :   free_dominance_info (CDI_DOMINATORS);
    3917                 :             : }
    3918                 :             : 
    3919                 :             : namespace {
    3920                 :             : 
    3921                 :             : const pass_data pass_data_align_tight_loops =
    3922                 :             : {
    3923                 :             :   RTL_PASS, /* type */
    3924                 :             :   "align_tight_loops", /* name */
    3925                 :             :   OPTGROUP_NONE, /* optinfo_flags */
    3926                 :             :   TV_MACH_DEP, /* tv_id */
    3927                 :             :   0, /* properties_required */
    3928                 :             :   0, /* properties_provided */
    3929                 :             :   0, /* properties_destroyed */
    3930                 :             :   0, /* todo_flags_start */
    3931                 :             :   0, /* todo_flags_finish */
    3932                 :             : };
    3933                 :             : 
    3934                 :             : class pass_align_tight_loops : public rtl_opt_pass
    3935                 :             : {
    3936                 :             : public:
    3937                 :      285081 :   pass_align_tight_loops (gcc::context *ctxt)
    3938                 :      570162 :     : rtl_opt_pass (pass_data_align_tight_loops, ctxt)
    3939                 :             :   {}
    3940                 :             : 
    3941                 :             :   /* opt_pass methods: */
    3942                 :     1449863 :   bool gate (function *) final override
    3943                 :             :     {
    3944                 :     1449863 :       return TARGET_ALIGN_TIGHT_LOOPS
    3945                 :     1449394 :              && optimize
    3946                 :     2473202 :              && optimize_function_for_speed_p (cfun);
    3947                 :             :     }
    3948                 :             : 
    3949                 :      960864 :   unsigned int execute (function *) final override
    3950                 :             :     {
    3951                 :      960864 :       timevar_push (TV_MACH_DEP);
    3952                 :             : #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
    3953                 :      960864 :       ix86_align_loops ();
    3954                 :             : #endif
    3955                 :      960864 :       timevar_pop (TV_MACH_DEP);
    3956                 :      960864 :       return 0;
    3957                 :             :     }
    3958                 :             : }; // class pass_align_tight_loops
    3959                 :             : 
    3960                 :             : } // anon namespace
    3961                 :             : 
    3962                 :             : rtl_opt_pass *
    3963                 :      285081 : make_pass_align_tight_loops (gcc::context *ctxt)
    3964                 :             : {
    3965                 :      285081 :   return new pass_align_tight_loops (ctxt);
    3966                 :             : }
    3967                 :             : 
    3968                 :             : /* This compares the priority of target features in function DECL1
    3969                 :             :    and DECL2.  It returns positive value if DECL1 is higher priority,
    3970                 :             :    negative value if DECL2 is higher priority and 0 if they are the
    3971                 :             :    same.  */
    3972                 :             : 
    3973                 :             : int
    3974                 :        5318 : ix86_compare_version_priority (tree decl1, tree decl2)
    3975                 :             : {
    3976                 :        5318 :   unsigned int priority1 = get_builtin_code_for_version (decl1, NULL);
    3977                 :        5318 :   unsigned int priority2 = get_builtin_code_for_version (decl2, NULL);
    3978                 :             : 
    3979                 :        5318 :   return (int)priority1 - (int)priority2;
    3980                 :             : }
    3981                 :             : 
    3982                 :             : /* V1 and V2 point to function versions with different priorities
    3983                 :             :    based on the target ISA.  This function compares their priorities.  */
    3984                 :             : 
    3985                 :             : static int
    3986                 :        6647 : feature_compare (const void *v1, const void *v2)
    3987                 :             : {
    3988                 :        6647 :   typedef struct _function_version_info
    3989                 :             :     {
    3990                 :             :       tree version_decl;
    3991                 :             :       tree predicate_chain;
    3992                 :             :       unsigned int dispatch_priority;
    3993                 :             :     } function_version_info;
    3994                 :             : 
    3995                 :        6647 :   const function_version_info c1 = *(const function_version_info *)v1;
    3996                 :        6647 :   const function_version_info c2 = *(const function_version_info *)v2;
    3997                 :        6647 :   return (c2.dispatch_priority - c1.dispatch_priority);
    3998                 :             : }
    3999                 :             : 
    4000                 :             : /* This adds a condition to the basic_block NEW_BB in function FUNCTION_DECL
    4001                 :             :    to return a pointer to VERSION_DECL if the outcome of the expression
    4002                 :             :    formed by PREDICATE_CHAIN is true.  This function will be called during
    4003                 :             :    version dispatch to decide which function version to execute.  It returns
    4004                 :             :    the basic block at the end, to which more conditions can be added.  */
    4005                 :             : 
    4006                 :             : static basic_block
    4007                 :         812 : add_condition_to_bb (tree function_decl, tree version_decl,
    4008                 :             :                      tree predicate_chain, basic_block new_bb)
    4009                 :             : {
    4010                 :         812 :   gimple *return_stmt;
    4011                 :         812 :   tree convert_expr, result_var;
    4012                 :         812 :   gimple *convert_stmt;
    4013                 :         812 :   gimple *call_cond_stmt;
    4014                 :         812 :   gimple *if_else_stmt;
    4015                 :             : 
    4016                 :         812 :   basic_block bb1, bb2, bb3;
    4017                 :         812 :   edge e12, e23;
    4018                 :             : 
    4019                 :         812 :   tree cond_var, and_expr_var = NULL_TREE;
    4020                 :         812 :   gimple_seq gseq;
    4021                 :             : 
    4022                 :         812 :   tree predicate_decl, predicate_arg;
    4023                 :             : 
    4024                 :         812 :   push_cfun (DECL_STRUCT_FUNCTION (function_decl));
    4025                 :             : 
    4026                 :         812 :   gcc_assert (new_bb != NULL);
    4027                 :         812 :   gseq = bb_seq (new_bb);
    4028                 :             : 
    4029                 :             : 
    4030                 :         812 :   convert_expr = build1 (CONVERT_EXPR, ptr_type_node,
    4031                 :             :                          build_fold_addr_expr (version_decl));
    4032                 :         812 :   result_var = create_tmp_var (ptr_type_node);
    4033                 :         812 :   convert_stmt = gimple_build_assign (result_var, convert_expr);
    4034                 :         812 :   return_stmt = gimple_build_return (result_var);
    4035                 :             : 
    4036                 :         812 :   if (predicate_chain == NULL_TREE)
    4037                 :             :     {
    4038                 :         195 :       gimple_seq_add_stmt (&gseq, convert_stmt);
    4039                 :         195 :       gimple_seq_add_stmt (&gseq, return_stmt);
    4040                 :         195 :       set_bb_seq (new_bb, gseq);
    4041                 :         195 :       gimple_set_bb (convert_stmt, new_bb);
    4042                 :         195 :       gimple_set_bb (return_stmt, new_bb);
    4043                 :         195 :       pop_cfun ();
    4044                 :         195 :       return new_bb;
    4045                 :             :     }
    4046                 :             : 
    4047                 :        1273 :   while (predicate_chain != NULL)
    4048                 :             :     {
    4049                 :         656 :       cond_var = create_tmp_var (integer_type_node);
    4050                 :         656 :       predicate_decl = TREE_PURPOSE (predicate_chain);
    4051                 :         656 :       predicate_arg = TREE_VALUE (predicate_chain);
    4052                 :         656 :       call_cond_stmt = gimple_build_call (predicate_decl, 1, predicate_arg);
    4053                 :         656 :       gimple_call_set_lhs (call_cond_stmt, cond_var);
    4054                 :             : 
    4055                 :         656 :       gimple_set_block (call_cond_stmt, DECL_INITIAL (function_decl));
    4056                 :         656 :       gimple_set_bb (call_cond_stmt, new_bb);
    4057                 :         656 :       gimple_seq_add_stmt (&gseq, call_cond_stmt);
    4058                 :             : 
    4059                 :         656 :       predicate_chain = TREE_CHAIN (predicate_chain);
    4060                 :             : 
    4061                 :         656 :       if (and_expr_var == NULL)
    4062                 :             :         and_expr_var = cond_var;
    4063                 :             :       else
    4064                 :             :         {
    4065                 :          39 :           gimple *assign_stmt;
    4066                 :             :           /* Use MIN_EXPR to check if any integer is zero?.
    4067                 :             :              and_expr_var = min_expr <cond_var, and_expr_var>  */
    4068                 :          39 :           assign_stmt = gimple_build_assign (and_expr_var,
    4069                 :             :                           build2 (MIN_EXPR, integer_type_node,
    4070                 :             :                                   cond_var, and_expr_var));
    4071                 :             : 
    4072                 :          39 :           gimple_set_block (assign_stmt, DECL_INITIAL (function_decl));
    4073                 :          39 :           gimple_set_bb (assign_stmt, new_bb);
    4074                 :          39 :           gimple_seq_add_stmt (&gseq, assign_stmt);
    4075                 :             :         }
    4076                 :             :     }
    4077                 :             : 
    4078                 :         617 :   if_else_stmt = gimple_build_cond (GT_EXPR, and_expr_var,
    4079                 :             :                                     integer_zero_node,
    4080                 :             :                                     NULL_TREE, NULL_TREE);
    4081                 :         617 :   gimple_set_block (if_else_stmt, DECL_INITIAL (function_decl));
    4082                 :         617 :   gimple_set_bb (if_else_stmt, new_bb);
    4083                 :         617 :   gimple_seq_add_stmt (&gseq, if_else_stmt);
    4084                 :             : 
    4085                 :         617 :   gimple_seq_add_stmt (&gseq, convert_stmt);
    4086                 :         617 :   gimple_seq_add_stmt (&gseq, return_stmt);
    4087                 :         617 :   set_bb_seq (new_bb, gseq);
    4088                 :             : 
    4089                 :         617 :   bb1 = new_bb;
    4090                 :         617 :   e12 = split_block (bb1, if_else_stmt);
    4091                 :         617 :   bb2 = e12->dest;
    4092                 :         617 :   e12->flags &= ~EDGE_FALLTHRU;
    4093                 :         617 :   e12->flags |= EDGE_TRUE_VALUE;
    4094                 :             : 
    4095                 :         617 :   e23 = split_block (bb2, return_stmt);
    4096                 :             : 
    4097                 :         617 :   gimple_set_bb (convert_stmt, bb2);
    4098                 :         617 :   gimple_set_bb (return_stmt, bb2);
    4099                 :             : 
    4100                 :         617 :   bb3 = e23->dest;
    4101                 :         617 :   make_edge (bb1, bb3, EDGE_FALSE_VALUE);
    4102                 :             : 
    4103                 :         617 :   remove_edge (e23);
    4104                 :         617 :   make_edge (bb2, EXIT_BLOCK_PTR_FOR_FN (cfun), 0);
    4105                 :             : 
    4106                 :         617 :   pop_cfun ();
    4107                 :             : 
    4108                 :         617 :   return bb3;
    4109                 :             : }
    4110                 :             : 
    4111                 :             : /* This function generates the dispatch function for
    4112                 :             :    multi-versioned functions.  DISPATCH_DECL is the function which will
    4113                 :             :    contain the dispatch logic.  FNDECLS are the function choices for
    4114                 :             :    dispatch, and is a tree chain.  EMPTY_BB is the basic block pointer
    4115                 :             :    in DISPATCH_DECL in which the dispatch code is generated.  */
    4116                 :             : 
    4117                 :             : static int
    4118                 :         195 : dispatch_function_versions (tree dispatch_decl,
    4119                 :             :                             void *fndecls_p,
    4120                 :             :                             basic_block *empty_bb)
    4121                 :             : {
    4122                 :         195 :   tree default_decl;
    4123                 :         195 :   gimple *ifunc_cpu_init_stmt;
    4124                 :         195 :   gimple_seq gseq;
    4125                 :         195 :   int ix;
    4126                 :         195 :   tree ele;
    4127                 :         195 :   vec<tree> *fndecls;
    4128                 :         195 :   unsigned int num_versions = 0;
    4129                 :         195 :   unsigned int actual_versions = 0;
    4130                 :         195 :   unsigned int i;
    4131                 :             : 
    4132                 :         195 :   struct _function_version_info
    4133                 :             :     {
    4134                 :             :       tree version_decl;
    4135                 :             :       tree predicate_chain;
    4136                 :             :       unsigned int dispatch_priority;
    4137                 :             :     }*function_version_info;
    4138                 :             : 
    4139                 :         195 :   gcc_assert (dispatch_decl != NULL
    4140                 :             :               && fndecls_p != NULL
    4141                 :             :               && empty_bb != NULL);
    4142                 :             : 
    4143                 :             :   /*fndecls_p is actually a vector.  */
    4144                 :         195 :   fndecls = static_cast<vec<tree> *> (fndecls_p);
    4145                 :             : 
    4146                 :             :   /* At least one more version other than the default.  */
    4147                 :         195 :   num_versions = fndecls->length ();
    4148                 :         195 :   gcc_assert (num_versions >= 2);
    4149                 :             : 
    4150                 :         195 :   function_version_info = (struct _function_version_info *)
    4151                 :         195 :     XNEWVEC (struct _function_version_info, (num_versions - 1));
    4152                 :             : 
    4153                 :             :   /* The first version in the vector is the default decl.  */
    4154                 :         195 :   default_decl = (*fndecls)[0];
    4155                 :             : 
    4156                 :         195 :   push_cfun (DECL_STRUCT_FUNCTION (dispatch_decl));
    4157                 :             : 
    4158                 :         195 :   gseq = bb_seq (*empty_bb);
    4159                 :             :   /* Function version dispatch is via IFUNC.  IFUNC resolvers fire before
    4160                 :             :      constructors, so explicity call __builtin_cpu_init here.  */
    4161                 :         195 :   ifunc_cpu_init_stmt
    4162                 :         195 :     = gimple_build_call_vec (get_ix86_builtin (IX86_BUILTIN_CPU_INIT), vNULL);
    4163                 :         195 :   gimple_seq_add_stmt (&gseq, ifunc_cpu_init_stmt);
    4164                 :         195 :   gimple_set_bb (ifunc_cpu_init_stmt, *empty_bb);
    4165                 :         195 :   set_bb_seq (*empty_bb, gseq);
    4166                 :             : 
    4167                 :         195 :   pop_cfun ();
    4168                 :             : 
    4169                 :             : 
    4170                 :         966 :   for (ix = 1; fndecls->iterate (ix, &ele); ++ix)
    4171                 :             :     {
    4172                 :         771 :       tree version_decl = ele;
    4173                 :         771 :       tree predicate_chain = NULL_TREE;
    4174                 :         771 :       unsigned int priority;
    4175                 :             :       /* Get attribute string, parse it and find the right predicate decl.
    4176                 :             :          The predicate function could be a lengthy combination of many
    4177                 :             :          features, like arch-type and various isa-variants.  */
    4178                 :         771 :       priority = get_builtin_code_for_version (version_decl,
    4179                 :             :                                                &predicate_chain);
    4180                 :             : 
    4181                 :         771 :       if (predicate_chain == NULL_TREE)
    4182                 :         154 :         continue;
    4183                 :             : 
    4184                 :         617 :       function_version_info [actual_versions].version_decl = version_decl;
    4185                 :         617 :       function_version_info [actual_versions].predicate_chain
    4186                 :         617 :          = predicate_chain;
    4187                 :         617 :       function_version_info [actual_versions].dispatch_priority = priority;
    4188                 :         617 :       actual_versions++;
    4189                 :             :     }
    4190                 :             : 
    4191                 :             :   /* Sort the versions according to descending order of dispatch priority.  The
    4192                 :             :      priority is based on the ISA.  This is not a perfect solution.  There
    4193                 :             :      could still be ambiguity.  If more than one function version is suitable
    4194                 :             :      to execute,  which one should be dispatched?  In future, allow the user
    4195                 :             :      to specify a dispatch  priority next to the version.  */
    4196                 :         195 :   qsort (function_version_info, actual_versions,
    4197                 :             :          sizeof (struct _function_version_info), feature_compare);
    4198                 :             : 
    4199                 :        1007 :   for  (i = 0; i < actual_versions; ++i)
    4200                 :         617 :     *empty_bb = add_condition_to_bb (dispatch_decl,
    4201                 :             :                                      function_version_info[i].version_decl,
    4202                 :         617 :                                      function_version_info[i].predicate_chain,
    4203                 :             :                                      *empty_bb);
    4204                 :             : 
    4205                 :             :   /* dispatch default version at the end.  */
    4206                 :         195 :   *empty_bb = add_condition_to_bb (dispatch_decl, default_decl,
    4207                 :             :                                    NULL, *empty_bb);
    4208                 :             : 
    4209                 :         195 :   free (function_version_info);
    4210                 :         195 :   return 0;
    4211                 :             : }
    4212                 :             : 
    4213                 :             : /* This function changes the assembler name for functions that are
    4214                 :             :    versions.  If DECL is a function version and has a "target"
    4215                 :             :    attribute, it appends the attribute string to its assembler name.  */
    4216                 :             : 
    4217                 :             : static tree
    4218                 :         825 : ix86_mangle_function_version_assembler_name (tree decl, tree id)
    4219                 :             : {
    4220                 :         825 :   tree version_attr;
    4221                 :         825 :   const char *orig_name, *version_string;
    4222                 :         825 :   char *attr_str, *assembler_name;
    4223                 :             : 
    4224                 :         825 :   if (DECL_DECLARED_INLINE_P (decl)
    4225                 :         879 :       && lookup_attribute ("gnu_inline",
    4226                 :          54 :                            DECL_ATTRIBUTES (decl)))
    4227                 :           0 :     error_at (DECL_SOURCE_LOCATION (decl),
    4228                 :             :               "function versions cannot be marked as %<gnu_inline%>,"
    4229                 :             :               " bodies have to be generated");
    4230                 :             : 
    4231                 :         825 :   if (DECL_VIRTUAL_P (decl)
    4232                 :        1650 :       || DECL_VINDEX (decl))
    4233                 :           0 :     sorry ("virtual function multiversioning not supported");
    4234                 :             : 
    4235                 :         825 :   version_attr = lookup_attribute ("target", DECL_ATTRIBUTES (decl));
    4236                 :             : 
    4237                 :             :   /* target attribute string cannot be NULL.  */
    4238                 :         825 :   gcc_assert (version_attr != NULL_TREE);
    4239                 :             : 
    4240                 :         825 :   orig_name = IDENTIFIER_POINTER (id);
    4241                 :         825 :   version_string
    4242                 :         825 :     = TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (version_attr)));
    4243                 :             : 
    4244                 :         825 :   if (strcmp (version_string, "default") == 0)
    4245                 :             :     return id;
    4246                 :             : 
    4247                 :         678 :   attr_str = sorted_attr_string (TREE_VALUE (version_attr));
    4248                 :         678 :   assembler_name = XNEWVEC (char, strlen (orig_name) + strlen (attr_str) + 2);
    4249                 :             : 
    4250                 :         678 :   sprintf (assembler_name, "%s.%s", orig_name, attr_str);
    4251                 :             : 
    4252                 :             :   /* Allow assembler name to be modified if already set.  */
    4253                 :         678 :   if (DECL_ASSEMBLER_NAME_SET_P (decl))
    4254                 :          12 :     SET_DECL_RTL (decl, NULL);
    4255                 :             : 
    4256                 :         678 :   tree ret = get_identifier (assembler_name);
    4257                 :         678 :   XDELETEVEC (attr_str);
    4258                 :         678 :   XDELETEVEC (assembler_name);
    4259                 :         678 :   return ret;
    4260                 :             : }
    4261                 :             : 
    4262                 :             : tree
    4263                 :   439011407 : ix86_mangle_decl_assembler_name (tree decl, tree id)
    4264                 :             : {
    4265                 :             :   /* For function version, add the target suffix to the assembler name.  */
    4266                 :   439011407 :   if (TREE_CODE (decl) == FUNCTION_DECL
    4267                 :   439011407 :       && DECL_FUNCTION_VERSIONED (decl))
    4268                 :         825 :     id = ix86_mangle_function_version_assembler_name (decl, id);
    4269                 :             : #ifdef SUBTARGET_MANGLE_DECL_ASSEMBLER_NAME
    4270                 :             :   id = SUBTARGET_MANGLE_DECL_ASSEMBLER_NAME (decl, id);
    4271                 :             : #endif
    4272                 :             : 
    4273                 :   439011407 :   return id;
    4274                 :             : }
    4275                 :             : 
    4276                 :             : /* Make a dispatcher declaration for the multi-versioned function DECL.
    4277                 :             :    Calls to DECL function will be replaced with calls to the dispatcher
    4278                 :             :    by the front-end.  Returns the decl of the dispatcher function.  */
    4279                 :             : 
    4280                 :             : tree
    4281                 :         321 : ix86_get_function_versions_dispatcher (void *decl)
    4282                 :             : {
    4283                 :         321 :   tree fn = (tree) decl;
    4284                 :         321 :   struct cgraph_node *node = NULL;
    4285                 :         321 :   struct cgraph_node *default_node = NULL;
    4286                 :         321 :   struct cgraph_function_version_info *node_v = NULL;
    4287                 :             : 
    4288                 :         321 :   tree dispatch_decl = NULL;
    4289                 :             : 
    4290                 :         321 :   struct cgraph_function_version_info *default_version_info = NULL;
    4291                 :             : 
    4292                 :         642 :   gcc_assert (fn != NULL && DECL_FUNCTION_VERSIONED (fn));
    4293                 :             : 
    4294                 :         321 :   node = cgraph_node::get (fn);
    4295                 :         321 :   gcc_assert (node != NULL);
    4296                 :             : 
    4297                 :         321 :   node_v = node->function_version ();
    4298                 :         321 :   gcc_assert (node_v != NULL);
    4299                 :             : 
    4300                 :         321 :   if (node_v->dispatcher_resolver != NULL)
    4301                 :             :     return node_v->dispatcher_resolver;
    4302                 :             : 
    4303                 :             :   /* The default node is always the beginning of the chain.  */
    4304                 :             :   default_version_info = node_v;
    4305                 :         651 :   while (default_version_info->prev != NULL)
    4306                 :             :     default_version_info = default_version_info->prev;
    4307                 :         207 :   default_node = default_version_info->this_node;
    4308                 :             : 
    4309                 :             :   /* If there is no default node, just return NULL.  */
    4310                 :         207 :   if (!is_function_default_version (default_node->decl))
    4311                 :             :     return NULL;
    4312                 :             : 
    4313                 :             : #if defined (ASM_OUTPUT_TYPE_DIRECTIVE)
    4314                 :         198 :   if (targetm.has_ifunc_p ())
    4315                 :             :     {
    4316                 :         198 :       struct cgraph_function_version_info *it_v = NULL;
    4317                 :         198 :       struct cgraph_node *dispatcher_node = NULL;
    4318                 :         198 :       struct cgraph_function_version_info *dispatcher_version_info = NULL;
    4319                 :             : 
    4320                 :             :       /* Right now, the dispatching is done via ifunc.  */
    4321                 :         198 :       dispatch_decl = make_dispatcher_decl (default_node->decl);
    4322                 :         198 :       TREE_NOTHROW (dispatch_decl) = TREE_NOTHROW (fn);
    4323                 :             : 
    4324                 :         198 :       dispatcher_node = cgraph_node::get_create (dispatch_decl);
    4325                 :         198 :       gcc_assert (dispatcher_node != NULL);
    4326                 :         198 :       dispatcher_node->dispatcher_function = 1;
    4327                 :         198 :       dispatcher_version_info
    4328                 :         198 :         = dispatcher_node->insert_new_function_version ();
    4329                 :         198 :       dispatcher_version_info->next = default_version_info;
    4330                 :         198 :       dispatcher_node->definition = 1;
    4331                 :             : 
    4332                 :             :       /* Set the dispatcher for all the versions.  */
    4333                 :         198 :       it_v = default_version_info;
    4334                 :        1170 :       while (it_v != NULL)
    4335                 :             :         {
    4336                 :         972 :           it_v->dispatcher_resolver = dispatch_decl;
    4337                 :         972 :           it_v = it_v->next;
    4338                 :             :         }
    4339                 :             :     }
    4340                 :             :   else
    4341                 :             : #endif
    4342                 :             :     {
    4343                 :           0 :       error_at (DECL_SOURCE_LOCATION (default_node->decl),
    4344                 :             :                 "multiversioning needs %<ifunc%> which is not supported "
    4345                 :             :                 "on this target");
    4346                 :             :     }
    4347                 :             : 
    4348                 :             :   return dispatch_decl;
    4349                 :             : }
    4350                 :             : 
    4351                 :             : /* Make the resolver function decl to dispatch the versions of
    4352                 :             :    a multi-versioned function,  DEFAULT_DECL.  IFUNC_ALIAS_DECL is
    4353                 :             :    ifunc alias that will point to the created resolver.  Create an
    4354                 :             :    empty basic block in the resolver and store the pointer in
    4355                 :             :    EMPTY_BB.  Return the decl of the resolver function.  */
    4356                 :             : 
    4357                 :             : static tree
    4358                 :         195 : make_resolver_func (const tree default_decl,
    4359                 :             :                     const tree ifunc_alias_decl,
    4360                 :             :                     basic_block *empty_bb)
    4361                 :             : {
    4362                 :         195 :   tree decl, type, t;
    4363                 :             : 
    4364                 :             :   /* Create resolver function name based on default_decl.  */
    4365                 :         195 :   tree decl_name = clone_function_name (default_decl, "resolver");
    4366                 :         195 :   const char *resolver_name = IDENTIFIER_POINTER (decl_name);
    4367                 :             : 
    4368                 :             :   /* The resolver function should return a (void *). */
    4369                 :         195 :   type = build_function_type_list (ptr_type_node, NULL_TREE);
    4370                 :             : 
    4371                 :         195 :   decl = build_fn_decl (resolver_name, type);
    4372                 :         195 :   SET_DECL_ASSEMBLER_NAME (decl, decl_name);
    4373                 :             : 
    4374                 :         195 :   DECL_NAME (decl) = decl_name;
    4375                 :         195 :   TREE_USED (decl) = 1;
    4376                 :         195 :   DECL_ARTIFICIAL (decl) = 1;
    4377                 :         195 :   DECL_IGNORED_P (decl) = 1;
    4378                 :         195 :   TREE_PUBLIC (decl) = 0;
    4379                 :         195 :   DECL_UNINLINABLE (decl) = 1;
    4380                 :             : 
    4381                 :             :   /* Resolver is not external, body is generated.  */
    4382                 :         195 :   DECL_EXTERNAL (decl) = 0;
    4383                 :         195 :   DECL_EXTERNAL (ifunc_alias_decl) = 0;
    4384                 :             : 
    4385                 :         195 :   DECL_CONTEXT (decl) = NULL_TREE;
    4386                 :         195 :   DECL_INITIAL (decl) = make_node (BLOCK);
    4387                 :         195 :   DECL_STATIC_CONSTRUCTOR (decl) = 0;
    4388                 :             : 
    4389                 :         195 :   if (DECL_COMDAT_GROUP (default_decl)
    4390                 :         195 :       || TREE_PUBLIC (default_decl))
    4391                 :             :     {
    4392                 :             :       /* In this case, each translation unit with a call to this
    4393                 :             :          versioned function will put out a resolver.  Ensure it
    4394                 :             :          is comdat to keep just one copy.  */
    4395                 :         171 :       DECL_COMDAT (decl) = 1;
    4396                 :         171 :       make_decl_one_only (decl, DECL_ASSEMBLER_NAME (decl));
    4397                 :             :     }
    4398                 :             :   else
    4399                 :          24 :     TREE_PUBLIC (ifunc_alias_decl) = 0;
    4400                 :             : 
    4401                 :             :   /* Build result decl and add to function_decl. */
    4402                 :         195 :   t = build_decl (UNKNOWN_LOCATION, RESULT_DECL, NULL_TREE, ptr_type_node);
    4403                 :         195 :   DECL_CONTEXT (t) = decl;
    4404                 :         195 :   DECL_ARTIFICIAL (t) = 1;
    4405                 :         195 :   DECL_IGNORED_P (t) = 1;
    4406                 :         195 :   DECL_RESULT (decl) = t;
    4407                 :             : 
    4408                 :         195 :   gimplify_function_tree (decl);
    4409                 :         195 :   push_cfun (DECL_STRUCT_FUNCTION (decl));
    4410                 :         195 :   *empty_bb = init_lowered_empty_function (decl, false,
    4411                 :             :                                            profile_count::uninitialized ());
    4412                 :             : 
    4413                 :         195 :   cgraph_node::add_new_function (decl, true);
    4414                 :         195 :   symtab->call_cgraph_insertion_hooks (cgraph_node::get_create (decl));
    4415                 :             : 
    4416                 :         195 :   pop_cfun ();
    4417                 :             : 
    4418                 :         195 :   gcc_assert (ifunc_alias_decl != NULL);
    4419                 :             :   /* Mark ifunc_alias_decl as "ifunc" with resolver as resolver_name.  */
    4420                 :         195 :   DECL_ATTRIBUTES (ifunc_alias_decl)
    4421                 :         195 :     = make_attribute ("ifunc", resolver_name,
    4422                 :         195 :                       DECL_ATTRIBUTES (ifunc_alias_decl));
    4423                 :             : 
    4424                 :             :   /* Create the alias for dispatch to resolver here.  */
    4425                 :         195 :   cgraph_node::create_same_body_alias (ifunc_alias_decl, decl);
    4426                 :         195 :   return decl;
    4427                 :             : }
    4428                 :             : 
    4429                 :             : /* Generate the dispatching code body to dispatch multi-versioned function
    4430                 :             :    DECL.  The target hook is called to process the "target" attributes and
    4431                 :             :    provide the code to dispatch the right function at run-time.  NODE points
    4432                 :             :    to the dispatcher decl whose body will be created.  */
    4433                 :             : 
    4434                 :             : tree
    4435                 :         195 : ix86_generate_version_dispatcher_body (void *node_p)
    4436                 :             : {
    4437                 :         195 :   tree resolver_decl;
    4438                 :         195 :   basic_block empty_bb;
    4439                 :         195 :   tree default_ver_decl;
    4440                 :         195 :   struct cgraph_node *versn;
    4441                 :         195 :   struct cgraph_node *node;
    4442                 :             : 
    4443                 :         195 :   struct cgraph_function_version_info *node_version_info = NULL;
    4444                 :         195 :   struct cgraph_function_version_info *versn_info = NULL;
    4445                 :             : 
    4446                 :         195 :   node = (cgraph_node *)node_p;
    4447                 :             : 
    4448                 :         195 :   node_version_info = node->function_version ();
    4449                 :         195 :   gcc_assert (node->dispatcher_function
    4450                 :             :               && node_version_info != NULL);
    4451                 :             : 
    4452                 :         195 :   if (node_version_info->dispatcher_resolver)
    4453                 :             :     return node_version_info->dispatcher_resolver;
    4454                 :             : 
    4455                 :             :   /* The first version in the chain corresponds to the default version.  */
    4456                 :         195 :   default_ver_decl = node_version_info->next->this_node->decl;
    4457                 :             : 
    4458                 :             :   /* node is going to be an alias, so remove the finalized bit.  */
    4459                 :         195 :   node->definition = false;
    4460                 :             : 
    4461                 :         195 :   resolver_decl = make_resolver_func (default_ver_decl,
    4462                 :             :                                       node->decl, &empty_bb);
    4463                 :             : 
    4464                 :         195 :   node_version_info->dispatcher_resolver = resolver_decl;
    4465                 :             : 
    4466                 :         195 :   push_cfun (DECL_STRUCT_FUNCTION (resolver_decl));
    4467                 :             : 
    4468                 :         195 :   auto_vec<tree, 2> fn_ver_vec;
    4469                 :             : 
    4470                 :        1161 :   for (versn_info = node_version_info->next; versn_info;
    4471                 :         966 :        versn_info = versn_info->next)
    4472                 :             :     {
    4473                 :         966 :       versn = versn_info->this_node;
    4474                 :             :       /* Check for virtual functions here again, as by this time it should
    4475                 :             :          have been determined if this function needs a vtable index or
    4476                 :             :          not.  This happens for methods in derived classes that override
    4477                 :             :          virtual methods in base classes but are not explicitly marked as
    4478                 :             :          virtual.  */
    4479                 :         966 :       if (DECL_VINDEX (versn->decl))
    4480                 :           0 :         sorry ("virtual function multiversioning not supported");
    4481                 :             : 
    4482                 :         966 :       fn_ver_vec.safe_push (versn->decl);
    4483                 :             :     }
    4484                 :             : 
    4485                 :         195 :   dispatch_function_versions (resolver_decl, &fn_ver_vec, &empty_bb);
    4486                 :         195 :   cgraph_edge::rebuild_edges ();
    4487                 :         195 :   pop_cfun ();
    4488                 :         195 :   return resolver_decl;
    4489                 :         195 : }
    4490                 :             : 
    4491                 :             : 
        

Generated by: LCOV version 2.1-beta

LCOV profile is generated on x86_64 machine using following configure options: configure --disable-bootstrap --enable-coverage=opt --enable-languages=c,c++,fortran,go,jit,lto,rust,m2 --enable-host-shared. GCC test suite is run with the built compiler.