LCOV - code coverage report
Current view: top level - gcc - tree-vect-stmts.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 77.1 % 7435 5734
Test Date: 2025-06-21 16:26:05 Functions: 88.8 % 107 95
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* Statement Analysis and Transformation for Vectorization
       2                 :             :    Copyright (C) 2003-2025 Free Software Foundation, Inc.
       3                 :             :    Contributed by Dorit Naishlos <dorit@il.ibm.com>
       4                 :             :    and Ira Rosen <irar@il.ibm.com>
       5                 :             : 
       6                 :             : This file is part of GCC.
       7                 :             : 
       8                 :             : GCC is free software; you can redistribute it and/or modify it under
       9                 :             : the terms of the GNU General Public License as published by the Free
      10                 :             : Software Foundation; either version 3, or (at your option) any later
      11                 :             : version.
      12                 :             : 
      13                 :             : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      14                 :             : WARRANTY; without even the implied warranty of MERCHANTABILITY or
      15                 :             : FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      16                 :             : for more details.
      17                 :             : 
      18                 :             : You should have received a copy of the GNU General Public License
      19                 :             : along with GCC; see the file COPYING3.  If not see
      20                 :             : <http://www.gnu.org/licenses/>.  */
      21                 :             : 
      22                 :             : #include "config.h"
      23                 :             : #include "system.h"
      24                 :             : #include "coretypes.h"
      25                 :             : #include "backend.h"
      26                 :             : #include "target.h"
      27                 :             : #include "rtl.h"
      28                 :             : #include "tree.h"
      29                 :             : #include "gimple.h"
      30                 :             : #include "ssa.h"
      31                 :             : #include "optabs-tree.h"
      32                 :             : #include "insn-config.h"
      33                 :             : #include "recog.h"            /* FIXME: for insn_data */
      34                 :             : #include "cgraph.h"
      35                 :             : #include "dumpfile.h"
      36                 :             : #include "alias.h"
      37                 :             : #include "fold-const.h"
      38                 :             : #include "stor-layout.h"
      39                 :             : #include "tree-eh.h"
      40                 :             : #include "gimplify.h"
      41                 :             : #include "gimple-iterator.h"
      42                 :             : #include "gimplify-me.h"
      43                 :             : #include "tree-cfg.h"
      44                 :             : #include "tree-ssa-loop-manip.h"
      45                 :             : #include "cfgloop.h"
      46                 :             : #include "explow.h"
      47                 :             : #include "tree-ssa-loop.h"
      48                 :             : #include "tree-scalar-evolution.h"
      49                 :             : #include "tree-vectorizer.h"
      50                 :             : #include "builtins.h"
      51                 :             : #include "internal-fn.h"
      52                 :             : #include "tree-vector-builder.h"
      53                 :             : #include "vec-perm-indices.h"
      54                 :             : #include "gimple-range.h"
      55                 :             : #include "tree-ssa-loop-niter.h"
      56                 :             : #include "gimple-fold.h"
      57                 :             : #include "regs.h"
      58                 :             : #include "attribs.h"
      59                 :             : #include "optabs-libfuncs.h"
      60                 :             : #include "tree-dfa.h"
      61                 :             : 
      62                 :             : /* For lang_hooks.types.type_for_mode.  */
      63                 :             : #include "langhooks.h"
      64                 :             : 
      65                 :             : /* Return the vectorized type for the given statement.  */
      66                 :             : 
      67                 :             : tree
      68                 :           0 : stmt_vectype (class _stmt_vec_info *stmt_info)
      69                 :             : {
      70                 :           0 :   return STMT_VINFO_VECTYPE (stmt_info);
      71                 :             : }
      72                 :             : 
      73                 :             : /* Return TRUE iff the given statement is in an inner loop relative to
      74                 :             :    the loop being vectorized.  */
      75                 :             : bool
      76                 :     4101941 : stmt_in_inner_loop_p (vec_info *vinfo, class _stmt_vec_info *stmt_info)
      77                 :             : {
      78                 :     4101941 :   gimple *stmt = STMT_VINFO_STMT (stmt_info);
      79                 :     4101941 :   basic_block bb = gimple_bb (stmt);
      80                 :     4101941 :   loop_vec_info loop_vinfo = dyn_cast <loop_vec_info> (vinfo);
      81                 :      806793 :   class loop* loop;
      82                 :             : 
      83                 :      806793 :   if (!loop_vinfo)
      84                 :             :     return false;
      85                 :             : 
      86                 :      806793 :   loop = LOOP_VINFO_LOOP (loop_vinfo);
      87                 :             : 
      88                 :      806793 :   return (bb->loop_father == loop->inner);
      89                 :             : }
      90                 :             : 
      91                 :             : /* Record the cost of a statement, either by directly informing the
      92                 :             :    target model or by saving it in a vector for later processing.
      93                 :             :    Return a preliminary estimate of the statement's cost.  */
      94                 :             : 
      95                 :             : unsigned
      96                 :     9995796 : record_stmt_cost (stmt_vector_for_cost *body_cost_vec, int count,
      97                 :             :                   enum vect_cost_for_stmt kind,
      98                 :             :                   stmt_vec_info stmt_info, slp_tree node,
      99                 :             :                   tree vectype, int misalign,
     100                 :             :                   enum vect_cost_model_location where)
     101                 :             : {
     102                 :     9995796 :   if ((kind == vector_load || kind == unaligned_load)
     103                 :     1410643 :       && (stmt_info && STMT_VINFO_GATHER_SCATTER_P (stmt_info)))
     104                 :             :     kind = vector_gather_load;
     105                 :     9995796 :   if ((kind == vector_store || kind == unaligned_store)
     106                 :     1006674 :       && (stmt_info && STMT_VINFO_GATHER_SCATTER_P (stmt_info)))
     107                 :     9995796 :     kind = vector_scatter_store;
     108                 :             : 
     109                 :     9995796 :   stmt_info_for_cost si
     110                 :     9995796 :     = { count, kind, where, stmt_info, node, vectype, misalign };
     111                 :     9995796 :   body_cost_vec->safe_push (si);
     112                 :             : 
     113                 :     9995796 :   return (unsigned)
     114                 :     9995796 :       (builtin_vectorization_cost (kind, vectype, misalign) * count);
     115                 :             : }
     116                 :             : 
     117                 :             : unsigned
     118                 :     5820444 : record_stmt_cost (stmt_vector_for_cost *body_cost_vec, int count,
     119                 :             :                   enum vect_cost_for_stmt kind, stmt_vec_info stmt_info,
     120                 :             :                   tree vectype, int misalign,
     121                 :             :                   enum vect_cost_model_location where)
     122                 :             : {
     123                 :     5820444 :   return record_stmt_cost (body_cost_vec, count, kind, stmt_info, NULL,
     124                 :     5820444 :                            vectype, misalign, where);
     125                 :             : }
     126                 :             : 
     127                 :             : unsigned
     128                 :     1020741 : record_stmt_cost (stmt_vector_for_cost *body_cost_vec, int count,
     129                 :             :                   enum vect_cost_for_stmt kind, slp_tree node,
     130                 :             :                   tree vectype, int misalign,
     131                 :             :                   enum vect_cost_model_location where)
     132                 :             : {
     133                 :     1020741 :   return record_stmt_cost (body_cost_vec, count, kind,
     134                 :             :                            SLP_TREE_REPRESENTATIVE (node), node,
     135                 :     1020741 :                            vectype, misalign, where);
     136                 :             : }
     137                 :             : 
     138                 :             : unsigned
     139                 :      148191 : record_stmt_cost (stmt_vector_for_cost *body_cost_vec, int count,
     140                 :             :                   enum vect_cost_for_stmt kind,
     141                 :             :                   enum vect_cost_model_location where)
     142                 :             : {
     143                 :      148191 :   gcc_assert (kind == cond_branch_taken || kind == cond_branch_not_taken
     144                 :             :               || kind == scalar_stmt);
     145                 :      148191 :   return record_stmt_cost (body_cost_vec, count, kind, NULL, NULL,
     146                 :      148191 :                            NULL_TREE, 0, where);
     147                 :             : }
     148                 :             : 
     149                 :             : /* Return a variable of type ELEM_TYPE[NELEMS].  */
     150                 :             : 
     151                 :             : static tree
     152                 :           0 : create_vector_array (tree elem_type, unsigned HOST_WIDE_INT nelems)
     153                 :             : {
     154                 :           0 :   return create_tmp_var (build_array_type_nelts (elem_type, nelems),
     155                 :           0 :                          "vect_array");
     156                 :             : }
     157                 :             : 
     158                 :             : /* ARRAY is an array of vectors created by create_vector_array.
     159                 :             :    Return an SSA_NAME for the vector in index N.  The reference
     160                 :             :    is part of the vectorization of STMT_INFO and the vector is associated
     161                 :             :    with scalar destination SCALAR_DEST.
     162                 :             :    If we need to ensure that inactive elements are set to zero,
     163                 :             :    NEED_ZEROING is true, MASK contains the loop mask to be used.  */
     164                 :             : 
     165                 :             : static tree
     166                 :           0 : read_vector_array (vec_info *vinfo,
     167                 :             :                    stmt_vec_info stmt_info, gimple_stmt_iterator *gsi,
     168                 :             :                    tree scalar_dest, tree array, unsigned HOST_WIDE_INT n,
     169                 :             :                    bool need_zeroing, tree mask)
     170                 :             : {
     171                 :           0 :   tree vect_type, vect, vect_name, tmp, tmp_name, array_ref;
     172                 :           0 :   gimple *new_stmt;
     173                 :             : 
     174                 :           0 :   gcc_assert (TREE_CODE (TREE_TYPE (array)) == ARRAY_TYPE);
     175                 :           0 :   vect_type = TREE_TYPE (TREE_TYPE (array));
     176                 :           0 :   tmp = vect_create_destination_var (scalar_dest, vect_type);
     177                 :           0 :   vect = vect_create_destination_var (scalar_dest, vect_type);
     178                 :           0 :   array_ref = build4 (ARRAY_REF, vect_type, array,
     179                 :           0 :                       build_int_cst (size_type_node, n),
     180                 :             :                       NULL_TREE, NULL_TREE);
     181                 :             : 
     182                 :           0 :   new_stmt = gimple_build_assign (tmp, array_ref);
     183                 :           0 :   tmp_name = make_ssa_name (vect, new_stmt);
     184                 :           0 :   gimple_assign_set_lhs (new_stmt, tmp_name);
     185                 :           0 :   vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
     186                 :             : 
     187                 :           0 :   if (need_zeroing)
     188                 :             :     {
     189                 :           0 :       tree vec_els = vect_get_mask_load_else (MASK_LOAD_ELSE_ZERO,
     190                 :             :                                               vect_type);
     191                 :           0 :       vect_name = make_ssa_name (vect, new_stmt);
     192                 :           0 :       new_stmt
     193                 :           0 :         = gimple_build_assign (vect_name, VEC_COND_EXPR,
     194                 :             :                                mask, tmp_name, vec_els);
     195                 :           0 :       vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
     196                 :             :     }
     197                 :             :   else
     198                 :             :     vect_name = tmp_name;
     199                 :             : 
     200                 :           0 :   return vect_name;
     201                 :             : }
     202                 :             : 
     203                 :             : /* ARRAY is an array of vectors created by create_vector_array.
     204                 :             :    Emit code to store SSA_NAME VECT in index N of the array.
     205                 :             :    The store is part of the vectorization of STMT_INFO.  */
     206                 :             : 
     207                 :             : static void
     208                 :           0 : write_vector_array (vec_info *vinfo,
     209                 :             :                     stmt_vec_info stmt_info, gimple_stmt_iterator *gsi,
     210                 :             :                     tree vect, tree array, unsigned HOST_WIDE_INT n)
     211                 :             : {
     212                 :           0 :   tree array_ref;
     213                 :           0 :   gimple *new_stmt;
     214                 :             : 
     215                 :           0 :   array_ref = build4 (ARRAY_REF, TREE_TYPE (vect), array,
     216                 :           0 :                       build_int_cst (size_type_node, n),
     217                 :             :                       NULL_TREE, NULL_TREE);
     218                 :             : 
     219                 :           0 :   new_stmt = gimple_build_assign (array_ref, vect);
     220                 :           0 :   vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
     221                 :           0 : }
     222                 :             : 
     223                 :             : /* PTR is a pointer to an array of type TYPE.  Return a representation
     224                 :             :    of *PTR.  The memory reference replaces those in FIRST_DR
     225                 :             :    (and its group).  */
     226                 :             : 
     227                 :             : static tree
     228                 :           0 : create_array_ref (tree type, tree ptr, tree alias_ptr_type)
     229                 :             : {
     230                 :           0 :   tree mem_ref;
     231                 :             : 
     232                 :           0 :   mem_ref = build2 (MEM_REF, type, ptr, build_int_cst (alias_ptr_type, 0));
     233                 :             :   /* Arrays have the same alignment as their type.  */
     234                 :           0 :   set_ptr_info_alignment (get_ptr_info (ptr), TYPE_ALIGN_UNIT (type), 0);
     235                 :           0 :   return mem_ref;
     236                 :             : }
     237                 :             : 
     238                 :             : /* Add a clobber of variable VAR to the vectorization of STMT_INFO.
     239                 :             :    Emit the clobber before *GSI.  */
     240                 :             : 
     241                 :             : static void
     242                 :          15 : vect_clobber_variable (vec_info *vinfo, stmt_vec_info stmt_info,
     243                 :             :                        gimple_stmt_iterator *gsi, tree var)
     244                 :             : {
     245                 :          15 :   tree clobber = build_clobber (TREE_TYPE (var));
     246                 :          15 :   gimple *new_stmt = gimple_build_assign (var, clobber);
     247                 :          15 :   vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
     248                 :          15 : }
     249                 :             : 
     250                 :             : /* Utility functions used by vect_mark_stmts_to_be_vectorized.  */
     251                 :             : 
     252                 :             : /* Function vect_mark_relevant.
     253                 :             : 
     254                 :             :    Mark STMT_INFO as "relevant for vectorization" and add it to WORKLIST.  */
     255                 :             : 
     256                 :             : static void
     257                 :     2979151 : vect_mark_relevant (vec<stmt_vec_info> *worklist, stmt_vec_info stmt_info,
     258                 :             :                     enum vect_relevant relevant, bool live_p)
     259                 :             : {
     260                 :     2979151 :   enum vect_relevant save_relevant = STMT_VINFO_RELEVANT (stmt_info);
     261                 :     2979151 :   bool save_live_p = STMT_VINFO_LIVE_P (stmt_info);
     262                 :             : 
     263                 :     2979151 :   if (dump_enabled_p ())
     264                 :      172521 :     dump_printf_loc (MSG_NOTE, vect_location,
     265                 :             :                      "mark relevant %d, live %d: %G", relevant, live_p,
     266                 :             :                      stmt_info->stmt);
     267                 :             : 
     268                 :             :   /* If this stmt is an original stmt in a pattern, we might need to mark its
     269                 :             :      related pattern stmt instead of the original stmt.  However, such stmts
     270                 :             :      may have their own uses that are not in any pattern, in such cases the
     271                 :             :      stmt itself should be marked.  */
     272                 :     2979151 :   if (STMT_VINFO_IN_PATTERN_P (stmt_info))
     273                 :             :     {
     274                 :             :       /* This is the last stmt in a sequence that was detected as a
     275                 :             :          pattern that can potentially be vectorized.  Don't mark the stmt
     276                 :             :          as relevant/live because it's not going to be vectorized.
     277                 :             :          Instead mark the pattern-stmt that replaces it.  */
     278                 :             : 
     279                 :      163757 :       if (dump_enabled_p ())
     280                 :        2410 :         dump_printf_loc (MSG_NOTE, vect_location,
     281                 :             :                          "last stmt in pattern. don't mark"
     282                 :             :                          " relevant/live.\n");
     283                 :             : 
     284                 :      163757 :       stmt_vec_info old_stmt_info = stmt_info;
     285                 :      163757 :       stmt_info = STMT_VINFO_RELATED_STMT (stmt_info);
     286                 :      163757 :       gcc_assert (STMT_VINFO_RELATED_STMT (stmt_info) == old_stmt_info);
     287                 :      163757 :       save_relevant = STMT_VINFO_RELEVANT (stmt_info);
     288                 :      163757 :       save_live_p = STMT_VINFO_LIVE_P (stmt_info);
     289                 :             : 
     290                 :      163757 :       if (live_p && relevant == vect_unused_in_scope)
     291                 :             :         {
     292                 :         108 :           if (dump_enabled_p ())
     293                 :           6 :             dump_printf_loc (MSG_NOTE, vect_location,
     294                 :             :                              "vec_stmt_relevant_p: forcing live pattern stmt "
     295                 :             :                              "relevant.\n");
     296                 :             :           relevant = vect_used_only_live;
     297                 :             :         }
     298                 :             : 
     299                 :      163757 :       if (dump_enabled_p ())
     300                 :        2410 :         dump_printf_loc (MSG_NOTE, vect_location,
     301                 :             :                          "mark relevant %d, live %d: %G", relevant, live_p,
     302                 :             :                          stmt_info->stmt);
     303                 :             :     }
     304                 :             : 
     305                 :     2979151 :   STMT_VINFO_LIVE_P (stmt_info) |= live_p;
     306                 :     2979151 :   if (relevant > STMT_VINFO_RELEVANT (stmt_info))
     307                 :     2469212 :     STMT_VINFO_RELEVANT (stmt_info) = relevant;
     308                 :             : 
     309                 :     2979151 :   if (STMT_VINFO_RELEVANT (stmt_info) == save_relevant
     310                 :      509939 :       && STMT_VINFO_LIVE_P (stmt_info) == save_live_p)
     311                 :             :     {
     312                 :      509227 :       if (dump_enabled_p ())
     313                 :       22307 :         dump_printf_loc (MSG_NOTE, vect_location,
     314                 :             :                          "already marked relevant/live.\n");
     315                 :      509227 :       return;
     316                 :             :     }
     317                 :             : 
     318                 :     2469924 :   worklist->safe_push (stmt_info);
     319                 :             : }
     320                 :             : 
     321                 :             : 
     322                 :             : /* Function is_simple_and_all_uses_invariant
     323                 :             : 
     324                 :             :    Return true if STMT_INFO is simple and all uses of it are invariant.  */
     325                 :             : 
     326                 :             : bool
     327                 :      361691 : is_simple_and_all_uses_invariant (stmt_vec_info stmt_info,
     328                 :             :                                   loop_vec_info loop_vinfo)
     329                 :             : {
     330                 :      361691 :   tree op;
     331                 :      361691 :   ssa_op_iter iter;
     332                 :             : 
     333                 :      483299 :   gassign *stmt = dyn_cast <gassign *> (stmt_info->stmt);
     334                 :      122428 :   if (!stmt)
     335                 :             :     return false;
     336                 :             : 
     337                 :      127645 :   FOR_EACH_SSA_TREE_OPERAND (op, stmt, iter, SSA_OP_USE)
     338                 :             :     {
     339                 :      126825 :       enum vect_def_type dt = vect_uninitialized_def;
     340                 :             : 
     341                 :      126825 :       if (!vect_is_simple_use (op, loop_vinfo, &dt))
     342                 :             :         {
     343                 :        1210 :           if (dump_enabled_p ())
     344                 :          23 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
     345                 :             :                              "use not simple.\n");
     346                 :      121608 :           return false;
     347                 :             :         }
     348                 :             : 
     349                 :      125615 :       if (dt != vect_external_def && dt != vect_constant_def)
     350                 :             :         return false;
     351                 :             :     }
     352                 :             :   return true;
     353                 :             : }
     354                 :             : 
     355                 :             : /* Function vect_stmt_relevant_p.
     356                 :             : 
     357                 :             :    Return true if STMT_INFO, in the loop that is represented by LOOP_VINFO,
     358                 :             :    is "relevant for vectorization".
     359                 :             : 
     360                 :             :    A stmt is considered "relevant for vectorization" if:
     361                 :             :    - it has uses outside the loop.
     362                 :             :    - it has vdefs (it alters memory).
     363                 :             :    - control stmts in the loop (except for the exit condition).
     364                 :             :    - it is an induction and we have multiple exits.
     365                 :             : 
     366                 :             :    CHECKME: what other side effects would the vectorizer allow?  */
     367                 :             : 
     368                 :             : static bool
     369                 :     3863735 : vect_stmt_relevant_p (stmt_vec_info stmt_info, loop_vec_info loop_vinfo,
     370                 :             :                       enum vect_relevant *relevant, bool *live_p)
     371                 :             : {
     372                 :     3863735 :   class loop *loop = LOOP_VINFO_LOOP (loop_vinfo);
     373                 :     3863735 :   ssa_op_iter op_iter;
     374                 :     3863735 :   imm_use_iterator imm_iter;
     375                 :     3863735 :   use_operand_p use_p;
     376                 :     3863735 :   def_operand_p def_p;
     377                 :             : 
     378                 :     3863735 :   *relevant = vect_unused_in_scope;
     379                 :     3863735 :   *live_p = false;
     380                 :             : 
     381                 :             :   /* cond stmt other than loop exit cond.  */
     382                 :     3863735 :   gimple *stmt = STMT_VINFO_STMT (stmt_info);
     383                 :     3863735 :   if (is_ctrl_stmt (stmt)
     384                 :      473495 :       && LOOP_VINFO_LOOP_IV_COND (loop_vinfo) != stmt
     385                 :     4023596 :       && (!loop->inner || gimple_bb (stmt)->loop_father == loop))
     386                 :      158212 :     *relevant = vect_used_in_scope;
     387                 :             : 
     388                 :             :   /* changing memory.  */
     389                 :     3863735 :   if (gimple_code (stmt_info->stmt) != GIMPLE_PHI)
     390                 :     3217024 :     if (gimple_vdef (stmt_info->stmt)
     391                 :     2740952 :         && !gimple_clobber_p (stmt_info->stmt))
     392                 :             :       {
     393                 :      268817 :         if (dump_enabled_p ())
     394                 :       28650 :           dump_printf_loc (MSG_NOTE, vect_location,
     395                 :             :                            "vec_stmt_relevant_p: stmt has vdefs.\n");
     396                 :      268817 :         *relevant = vect_used_in_scope;
     397                 :             :       }
     398                 :             : 
     399                 :             :   /* uses outside the loop.  */
     400                 :    10838066 :   FOR_EACH_PHI_OR_STMT_DEF (def_p, stmt_info->stmt, op_iter, SSA_OP_DEF)
     401                 :             :     {
     402                 :     8231161 :       FOR_EACH_IMM_USE_FAST (use_p, imm_iter, DEF_FROM_PTR (def_p))
     403                 :             :         {
     404                 :     5120565 :           basic_block bb = gimple_bb (USE_STMT (use_p));
     405                 :     5120565 :           if (!flow_bb_inside_loop_p (loop, bb))
     406                 :             :             {
     407                 :      170841 :               if (is_gimple_debug (USE_STMT (use_p)))
     408                 :         627 :                 continue;
     409                 :             : 
     410                 :      170214 :               if (dump_enabled_p ())
     411                 :        5859 :                 dump_printf_loc (MSG_NOTE, vect_location,
     412                 :             :                                  "vec_stmt_relevant_p: used out of loop.\n");
     413                 :             : 
     414                 :             :               /* We expect all such uses to be in the loop exit phis
     415                 :             :                  (because of loop closed form)   */
     416                 :      170214 :               gcc_assert (gimple_code (USE_STMT (use_p)) == GIMPLE_PHI);
     417                 :             : 
     418                 :      170214 :               *live_p = true;
     419                 :             :             }
     420                 :             :         }
     421                 :             :     }
     422                 :             : 
     423                 :             :   /* Check if it's a not live PHI and multiple exits.  In this case
     424                 :             :      there will be a usage later on after peeling which is needed for the
     425                 :             :      alternate exit.  */
     426                 :     3863735 :   if (LOOP_VINFO_EARLY_BREAKS (loop_vinfo)
     427                 :     1299111 :       && is_a <gphi *> (stmt)
     428                 :      235616 :       && gimple_bb (stmt) == LOOP_VINFO_LOOP (loop_vinfo)->header
     429                 :     4099328 :       && ((! VECTORIZABLE_CYCLE_DEF (STMT_VINFO_DEF_TYPE (stmt_info))
     430                 :      231682 :           && ! *live_p)
     431                 :       33131 :           || STMT_VINFO_DEF_TYPE (stmt_info) == vect_induction_def))
     432                 :             :     {
     433                 :      227958 :       if (dump_enabled_p ())
     434                 :        2856 :         dump_printf_loc (MSG_NOTE, vect_location,
     435                 :             :                          "vec_stmt_relevant_p: PHI forced live for "
     436                 :             :                          "early break.\n");
     437                 :      227958 :       LOOP_VINFO_EARLY_BREAKS_LIVE_IVS (loop_vinfo).safe_push (stmt_info);
     438                 :      227958 :       *live_p = true;
     439                 :             :     }
     440                 :             : 
     441                 :      361699 :   if (*live_p && *relevant == vect_unused_in_scope
     442                 :     4225426 :       && !is_simple_and_all_uses_invariant (stmt_info, loop_vinfo))
     443                 :             :     {
     444                 :      360871 :       if (dump_enabled_p ())
     445                 :        8364 :         dump_printf_loc (MSG_NOTE, vect_location,
     446                 :             :                          "vec_stmt_relevant_p: stmt live but not relevant.\n");
     447                 :      360871 :       *relevant = vect_used_only_live;
     448                 :             :     }
     449                 :             : 
     450                 :     3863735 :   return (*live_p || *relevant);
     451                 :             : }
     452                 :             : 
     453                 :             : 
     454                 :             : /* Function exist_non_indexing_operands_for_use_p
     455                 :             : 
     456                 :             :    USE is one of the uses attached to STMT_INFO.  Check if USE is
     457                 :             :    used in STMT_INFO for anything other than indexing an array.  */
     458                 :             : 
     459                 :             : static bool
     460                 :     3757235 : exist_non_indexing_operands_for_use_p (tree use, stmt_vec_info stmt_info)
     461                 :             : {
     462                 :     3757235 :   tree operand;
     463                 :             : 
     464                 :             :   /* USE corresponds to some operand in STMT.  If there is no data
     465                 :             :      reference in STMT, then any operand that corresponds to USE
     466                 :             :      is not indexing an array.  */
     467                 :     3757235 :   if (!STMT_VINFO_DATA_REF (stmt_info))
     468                 :             :     return true;
     469                 :             : 
     470                 :             :   /* STMT has a data_ref. FORNOW this means that its of one of
     471                 :             :      the following forms:
     472                 :             :      -1- ARRAY_REF = var
     473                 :             :      -2- var = ARRAY_REF
     474                 :             :      (This should have been verified in analyze_data_refs).
     475                 :             : 
     476                 :             :      'var' in the second case corresponds to a def, not a use,
     477                 :             :      so USE cannot correspond to any operands that are not used
     478                 :             :      for array indexing.
     479                 :             : 
     480                 :             :      Therefore, all we need to check is if STMT falls into the
     481                 :             :      first case, and whether var corresponds to USE.  */
     482                 :             : 
     483                 :     1128775 :   gassign *assign = dyn_cast <gassign *> (stmt_info->stmt);
     484                 :     1116095 :   if (!assign || !gimple_assign_copy_p (assign))
     485                 :             :     {
     486                 :      608417 :       gcall *call = dyn_cast <gcall *> (stmt_info->stmt);
     487                 :       12680 :       if (call && gimple_call_internal_p (call))
     488                 :             :         {
     489                 :       12680 :           internal_fn ifn = gimple_call_internal_fn (call);
     490                 :       12680 :           int mask_index = internal_fn_mask_index (ifn);
     491                 :       12680 :           if (mask_index >= 0
     492                 :       12680 :               && use == gimple_call_arg (call, mask_index))
     493                 :             :             return true;
     494                 :        8290 :           int els_index = internal_fn_else_index (ifn);
     495                 :        8290 :           if (els_index >= 0
     496                 :        8290 :               && use == gimple_call_arg (call, els_index))
     497                 :             :             return true;
     498                 :        7130 :           int stored_value_index = internal_fn_stored_value_index (ifn);
     499                 :        7130 :           if (stored_value_index >= 0
     500                 :        7130 :               && use == gimple_call_arg (call, stored_value_index))
     501                 :             :             return true;
     502                 :        5728 :           if (internal_gather_scatter_fn_p (ifn)
     503                 :        5728 :               && use == gimple_call_arg (call, 1))
     504                 :             :             return true;
     505                 :             :         }
     506                 :      601465 :       return false;
     507                 :             :     }
     508                 :             : 
     509                 :      520358 :   if (TREE_CODE (gimple_assign_lhs (assign)) == SSA_NAME)
     510                 :             :     return false;
     511                 :      520358 :   operand = gimple_assign_rhs1 (assign);
     512                 :      520358 :   if (TREE_CODE (operand) != SSA_NAME)
     513                 :             :     return false;
     514                 :             : 
     515                 :      463367 :   if (operand == use)
     516                 :             :     return true;
     517                 :             : 
     518                 :             :   return false;
     519                 :             : }
     520                 :             : 
     521                 :             : 
     522                 :             : /*
     523                 :             :    Function process_use.
     524                 :             : 
     525                 :             :    Inputs:
     526                 :             :    - a USE in STMT_VINFO in a loop represented by LOOP_VINFO
     527                 :             :    - RELEVANT - enum value to be set in the STMT_VINFO of the stmt
     528                 :             :      that defined USE.  This is done by calling mark_relevant and passing it
     529                 :             :      the WORKLIST (to add DEF_STMT to the WORKLIST in case it is relevant).
     530                 :             :    - FORCE is true if exist_non_indexing_operands_for_use_p check shouldn't
     531                 :             :      be performed.
     532                 :             : 
     533                 :             :    Outputs:
     534                 :             :    Generally, LIVE_P and RELEVANT are used to define the liveness and
     535                 :             :    relevance info of the DEF_STMT of this USE:
     536                 :             :        STMT_VINFO_LIVE_P (DEF_stmt_vinfo) <-- live_p
     537                 :             :        STMT_VINFO_RELEVANT (DEF_stmt_vinfo) <-- relevant
     538                 :             :    Exceptions:
     539                 :             :    - case 1: If USE is used only for address computations (e.g. array indexing),
     540                 :             :    which does not need to be directly vectorized, then the liveness/relevance
     541                 :             :    of the respective DEF_STMT is left unchanged.
     542                 :             :    - case 2: If STMT_VINFO is a reduction phi and DEF_STMT is a reduction stmt,
     543                 :             :    we skip DEF_STMT cause it had already been processed.
     544                 :             :    - case 3: If DEF_STMT and STMT_VINFO are in different nests, then
     545                 :             :    "relevant" will be modified accordingly.
     546                 :             : 
     547                 :             :    Return true if everything is as expected. Return false otherwise.  */
     548                 :             : 
     549                 :             : static opt_result
     550                 :     3787027 : process_use (stmt_vec_info stmt_vinfo, tree use, loop_vec_info loop_vinfo,
     551                 :             :              enum vect_relevant relevant, vec<stmt_vec_info> *worklist,
     552                 :             :              bool force)
     553                 :             : {
     554                 :     3787027 :   stmt_vec_info dstmt_vinfo;
     555                 :     3787027 :   enum vect_def_type dt;
     556                 :             : 
     557                 :             :   /* case 1: we are only interested in uses that need to be vectorized.  Uses
     558                 :             :      that are used for address computation are not considered relevant.  */
     559                 :     3787027 :   if (!force && !exist_non_indexing_operands_for_use_p (use, stmt_vinfo))
     560                 :      903673 :     return opt_result::success ();
     561                 :             : 
     562                 :     2883354 :   if (!vect_is_simple_use (use, loop_vinfo, &dt, &dstmt_vinfo))
     563                 :       12739 :     return opt_result::failure_at (stmt_vinfo->stmt,
     564                 :             :                                    "not vectorized:"
     565                 :             :                                    " unsupported use in stmt.\n");
     566                 :             : 
     567                 :     2870615 :   if (!dstmt_vinfo)
     568                 :      623754 :     return opt_result::success ();
     569                 :             : 
     570                 :     2246861 :   basic_block def_bb = gimple_bb (dstmt_vinfo->stmt);
     571                 :     2246861 :   basic_block bb = gimple_bb (stmt_vinfo->stmt);
     572                 :             : 
     573                 :             :   /* case 2: A reduction phi (STMT) defined by a reduction stmt (DSTMT_VINFO).
     574                 :             :      We have to force the stmt live since the epilogue loop needs it to
     575                 :             :      continue computing the reduction.  */
     576                 :     2246861 :   if (gimple_code (stmt_vinfo->stmt) == GIMPLE_PHI
     577                 :      382682 :       && STMT_VINFO_DEF_TYPE (stmt_vinfo) == vect_reduction_def
     578                 :       63658 :       && gimple_code (dstmt_vinfo->stmt) != GIMPLE_PHI
     579                 :       63658 :       && STMT_VINFO_DEF_TYPE (dstmt_vinfo) == vect_reduction_def
     580                 :     2310519 :       && bb->loop_father == def_bb->loop_father)
     581                 :             :     {
     582                 :       63658 :       if (dump_enabled_p ())
     583                 :        3850 :         dump_printf_loc (MSG_NOTE, vect_location,
     584                 :             :                          "reduc-stmt defining reduc-phi in the same nest.\n");
     585                 :       63658 :       vect_mark_relevant (worklist, dstmt_vinfo, relevant, true);
     586                 :       63658 :       return opt_result::success ();
     587                 :             :     }
     588                 :             : 
     589                 :             :   /* case 3a: outer-loop stmt defining an inner-loop stmt:
     590                 :             :         outer-loop-header-bb:
     591                 :             :                 d = dstmt_vinfo
     592                 :             :         inner-loop:
     593                 :             :                 stmt # use (d)
     594                 :             :         outer-loop-tail-bb:
     595                 :             :                 ...               */
     596                 :     2183203 :   if (flow_loop_nested_p (def_bb->loop_father, bb->loop_father))
     597                 :             :     {
     598                 :        1907 :       if (dump_enabled_p ())
     599                 :         256 :         dump_printf_loc (MSG_NOTE, vect_location,
     600                 :             :                          "outer-loop def-stmt defining inner-loop stmt.\n");
     601                 :             : 
     602                 :        1907 :       switch (relevant)
     603                 :             :         {
     604                 :           0 :         case vect_unused_in_scope:
     605                 :           0 :           relevant = (STMT_VINFO_DEF_TYPE (stmt_vinfo) == vect_nested_cycle) ?
     606                 :             :                       vect_used_in_scope : vect_unused_in_scope;
     607                 :             :           break;
     608                 :             : 
     609                 :         673 :         case vect_used_in_outer_by_reduction:
     610                 :         673 :           gcc_assert (STMT_VINFO_DEF_TYPE (stmt_vinfo) != vect_reduction_def);
     611                 :             :           relevant = vect_used_by_reduction;
     612                 :             :           break;
     613                 :             : 
     614                 :        1022 :         case vect_used_in_outer:
     615                 :        1022 :           gcc_assert (STMT_VINFO_DEF_TYPE (stmt_vinfo) != vect_reduction_def);
     616                 :             :           relevant = vect_used_in_scope;
     617                 :             :           break;
     618                 :             : 
     619                 :             :         case vect_used_in_scope:
     620                 :             :           break;
     621                 :             : 
     622                 :           0 :         default:
     623                 :           0 :           gcc_unreachable ();
     624                 :             :         }
     625                 :             :     }
     626                 :             : 
     627                 :             :   /* case 3b: inner-loop stmt defining an outer-loop stmt:
     628                 :             :         outer-loop-header-bb:
     629                 :             :                 ...
     630                 :             :         inner-loop:
     631                 :             :                 d = dstmt_vinfo
     632                 :             :         outer-loop-tail-bb (or outer-loop-exit-bb in double reduction):
     633                 :             :                 stmt # use (d)          */
     634                 :     2181296 :   else if (flow_loop_nested_p (bb->loop_father, def_bb->loop_father))
     635                 :             :     {
     636                 :        1762 :       if (dump_enabled_p ())
     637                 :         508 :         dump_printf_loc (MSG_NOTE, vect_location,
     638                 :             :                          "inner-loop def-stmt defining outer-loop stmt.\n");
     639                 :             : 
     640                 :        1762 :       switch (relevant)
     641                 :             :         {
     642                 :           0 :         case vect_unused_in_scope:
     643                 :           0 :           relevant = (STMT_VINFO_DEF_TYPE (stmt_vinfo) == vect_reduction_def
     644                 :           0 :             || STMT_VINFO_DEF_TYPE (stmt_vinfo) == vect_double_reduction_def) ?
     645                 :             :                       vect_used_in_outer_by_reduction : vect_unused_in_scope;
     646                 :             :           break;
     647                 :             : 
     648                 :             :         case vect_used_by_reduction:
     649                 :             :         case vect_used_only_live:
     650                 :             :           relevant = vect_used_in_outer_by_reduction;
     651                 :             :           break;
     652                 :             : 
     653                 :             :         case vect_used_in_scope:
     654                 :     2126773 :           relevant = vect_used_in_outer;
     655                 :             :           break;
     656                 :             : 
     657                 :           0 :         default:
     658                 :           0 :           gcc_unreachable ();
     659                 :             :         }
     660                 :             :     }
     661                 :             :   /* We are also not interested in uses on loop PHI backedges that are
     662                 :             :      inductions.  Otherwise we'll needlessly vectorize the IV increment
     663                 :             :      and cause hybrid SLP for SLP inductions.  Unless the PHI is live
     664                 :             :      of course.  */
     665                 :     2179534 :   else if (gimple_code (stmt_vinfo->stmt) == GIMPLE_PHI
     666                 :      316196 :            && STMT_VINFO_DEF_TYPE (stmt_vinfo) == vect_induction_def
     667                 :      312673 :            && ! STMT_VINFO_LIVE_P (stmt_vinfo)
     668                 :     2235964 :            && (PHI_ARG_DEF_FROM_EDGE (stmt_vinfo->stmt,
     669                 :             :                                       loop_latch_edge (bb->loop_father))
     670                 :             :                == use))
     671                 :             :     {
     672                 :       56430 :       if (dump_enabled_p ())
     673                 :        3787 :         dump_printf_loc (MSG_NOTE, vect_location,
     674                 :             :                          "induction value on backedge.\n");
     675                 :       56430 :       return opt_result::success ();
     676                 :             :     }
     677                 :             : 
     678                 :             : 
     679                 :     2126773 :   vect_mark_relevant (worklist, dstmt_vinfo, relevant, false);
     680                 :     2126773 :   return opt_result::success ();
     681                 :             : }
     682                 :             : 
     683                 :             : 
     684                 :             : /* Function vect_mark_stmts_to_be_vectorized.
     685                 :             : 
     686                 :             :    Not all stmts in the loop need to be vectorized. For example:
     687                 :             : 
     688                 :             :      for i...
     689                 :             :        for j...
     690                 :             :    1.    T0 = i + j
     691                 :             :    2.    T1 = a[T0]
     692                 :             : 
     693                 :             :    3.    j = j + 1
     694                 :             : 
     695                 :             :    Stmt 1 and 3 do not need to be vectorized, because loop control and
     696                 :             :    addressing of vectorized data-refs are handled differently.
     697                 :             : 
     698                 :             :    This pass detects such stmts.  */
     699                 :             : 
     700                 :             : opt_result
     701                 :      313634 : vect_mark_stmts_to_be_vectorized (loop_vec_info loop_vinfo, bool *fatal)
     702                 :             : {
     703                 :      313634 :   class loop *loop = LOOP_VINFO_LOOP (loop_vinfo);
     704                 :      313634 :   basic_block *bbs = LOOP_VINFO_BBS (loop_vinfo);
     705                 :      313634 :   unsigned int nbbs = loop->num_nodes;
     706                 :      313634 :   gimple_stmt_iterator si;
     707                 :      313634 :   unsigned int i;
     708                 :      313634 :   basic_block bb;
     709                 :      313634 :   bool live_p;
     710                 :      313634 :   enum vect_relevant relevant;
     711                 :             : 
     712                 :      313634 :   DUMP_VECT_SCOPE ("vect_mark_stmts_to_be_vectorized");
     713                 :             : 
     714                 :      313634 :   auto_vec<stmt_vec_info, 64> worklist;
     715                 :             : 
     716                 :             :   /* 1. Init worklist.  */
     717                 :     1104077 :   for (i = 0; i < nbbs; i++)
     718                 :             :     {
     719                 :      790443 :       bb = bbs[i];
     720                 :     1610549 :       for (si = gsi_start_phis (bb); !gsi_end_p (si); gsi_next (&si))
     721                 :             :         {
     722                 :     1640212 :           if (virtual_operand_p (gimple_phi_result (gsi_stmt (si))))
     723                 :      173395 :             continue;
     724                 :      646711 :           stmt_vec_info phi_info = loop_vinfo->lookup_stmt (gsi_stmt (si));
     725                 :      646711 :           if (dump_enabled_p ())
     726                 :       41090 :             dump_printf_loc (MSG_NOTE, vect_location, "init: phi relevant? %G",
     727                 :             :                              phi_info->stmt);
     728                 :             : 
     729                 :      646711 :           if (vect_stmt_relevant_p (phi_info, loop_vinfo, &relevant, &live_p))
     730                 :      233351 :             vect_mark_relevant (&worklist, phi_info, relevant, live_p);
     731                 :             :         }
     732                 :     6478672 :       for (si = gsi_start_bb (bb); !gsi_end_p (si); gsi_next (&si))
     733                 :             :         {
     734                 :     4897786 :           if (is_gimple_debug (gsi_stmt (si)))
     735                 :     1680762 :             continue;
     736                 :     3217024 :           stmt_vec_info stmt_info = loop_vinfo->lookup_stmt (gsi_stmt (si));
     737                 :     3217024 :           if (dump_enabled_p ())
     738                 :      226367 :               dump_printf_loc (MSG_NOTE, vect_location,
     739                 :             :                                "init: stmt relevant? %G", stmt_info->stmt);
     740                 :             : 
     741                 :     3217024 :           if (vect_stmt_relevant_p (stmt_info, loop_vinfo, &relevant, &live_p))
     742                 :      555369 :             vect_mark_relevant (&worklist, stmt_info, relevant, live_p);
     743                 :             :         }
     744                 :             :     }
     745                 :             : 
     746                 :             :   /* 2. Process_worklist */
     747                 :     2732088 :   while (worklist.length () > 0)
     748                 :             :     {
     749                 :     2431195 :       use_operand_p use_p;
     750                 :     2431195 :       ssa_op_iter iter;
     751                 :             : 
     752                 :     2431195 :       stmt_vec_info stmt_vinfo = worklist.pop ();
     753                 :     2431195 :       if (dump_enabled_p ())
     754                 :      149484 :         dump_printf_loc (MSG_NOTE, vect_location,
     755                 :             :                          "worklist: examine stmt: %G", stmt_vinfo->stmt);
     756                 :             : 
     757                 :             :       /* Examine the USEs of STMT. For each USE, mark the stmt that defines it
     758                 :             :          (DEF_STMT) as relevant/irrelevant according to the relevance property
     759                 :             :          of STMT.  */
     760                 :     2431195 :       relevant = STMT_VINFO_RELEVANT (stmt_vinfo);
     761                 :             : 
     762                 :             :       /* Generally, the relevance property of STMT (in STMT_VINFO_RELEVANT) is
     763                 :             :          propagated as is to the DEF_STMTs of its USEs.
     764                 :             : 
     765                 :             :          One exception is when STMT has been identified as defining a reduction
     766                 :             :          variable; in this case we set the relevance to vect_used_by_reduction.
     767                 :             :          This is because we distinguish between two kinds of relevant stmts -
     768                 :             :          those that are used by a reduction computation, and those that are
     769                 :             :          (also) used by a regular computation.  This allows us later on to
     770                 :             :          identify stmts that are used solely by a reduction, and therefore the
     771                 :             :          order of the results that they produce does not have to be kept.  */
     772                 :             : 
     773                 :     2431195 :       switch (STMT_VINFO_DEF_TYPE (stmt_vinfo))
     774                 :             :         {
     775                 :      127892 :           case vect_reduction_def:
     776                 :      127892 :             gcc_assert (relevant != vect_unused_in_scope);
     777                 :      127892 :             if (relevant != vect_unused_in_scope
     778                 :      127892 :                 && relevant != vect_used_in_scope
     779                 :      127892 :                 && relevant != vect_used_by_reduction
     780                 :      127892 :                 && relevant != vect_used_only_live)
     781                 :           0 :               return opt_result::failure_at
     782                 :           0 :                 (stmt_vinfo->stmt, "unsupported use of reduction.\n");
     783                 :             :             break;
     784                 :             : 
     785                 :        1917 :           case vect_nested_cycle:
     786                 :        1917 :             if (relevant != vect_unused_in_scope
     787                 :        1917 :                 && relevant != vect_used_in_outer_by_reduction
     788                 :        1459 :                 && relevant != vect_used_in_outer)
     789                 :           2 :               return opt_result::failure_at
     790                 :           2 :                 (stmt_vinfo->stmt, "unsupported use of nested cycle.\n");
     791                 :             :             break;
     792                 :             : 
     793                 :        1000 :           case vect_double_reduction_def:
     794                 :        1000 :             if (relevant != vect_unused_in_scope
     795                 :        1000 :                 && relevant != vect_used_by_reduction
     796                 :         352 :                 && relevant != vect_used_only_live)
     797                 :           0 :               return opt_result::failure_at
     798                 :           0 :                 (stmt_vinfo->stmt, "unsupported use of double reduction.\n");
     799                 :             :             break;
     800                 :             : 
     801                 :             :           default:
     802                 :             :             break;
     803                 :             :         }
     804                 :             : 
     805                 :     2431193 :       if (is_pattern_stmt_p (stmt_vinfo))
     806                 :             :         {
     807                 :             :           /* Pattern statements are not inserted into the code, so
     808                 :             :              FOR_EACH_PHI_OR_STMT_USE optimizes their operands out, and we
     809                 :             :              have to scan the RHS or function arguments instead.  */
     810                 :      428280 :           if (gassign *assign = dyn_cast <gassign *> (stmt_vinfo->stmt))
     811                 :             :             {
     812                 :      272270 :               enum tree_code rhs_code = gimple_assign_rhs_code (assign);
     813                 :      272270 :               tree op = gimple_assign_rhs1 (assign);
     814                 :             : 
     815                 :      272270 :               i = 1;
     816                 :      272270 :               if (rhs_code == COND_EXPR && COMPARISON_CLASS_P (op))
     817                 :             :                 {
     818                 :           0 :                   opt_result res
     819                 :           0 :                     = process_use (stmt_vinfo, TREE_OPERAND (op, 0),
     820                 :             :                                    loop_vinfo, relevant, &worklist, false);
     821                 :           0 :                   if (!res)
     822                 :           0 :                     return res;
     823                 :           0 :                   res = process_use (stmt_vinfo, TREE_OPERAND (op, 1),
     824                 :             :                                      loop_vinfo, relevant, &worklist, false);
     825                 :           0 :                   if (!res)
     826                 :           0 :                     return res;
     827                 :             :                   i = 2;
     828                 :             :                 }
     829                 :      792852 :               for (; i < gimple_num_ops (assign); i++)
     830                 :             :                 {
     831                 :      522109 :                   op = gimple_op (assign, i);
     832                 :      522109 :                   if (TREE_CODE (op) == SSA_NAME)
     833                 :             :                     {
     834                 :      395832 :                       opt_result res
     835                 :      395832 :                         = process_use (stmt_vinfo, op, loop_vinfo, relevant,
     836                 :             :                                        &worklist, false);
     837                 :      395832 :                       if (!res)
     838                 :        1527 :                         return res;
     839                 :             :                     }
     840                 :             :                  }
     841                 :             :             }
     842                 :      156010 :           else if (gcond *cond = dyn_cast <gcond *> (stmt_vinfo->stmt))
     843                 :             :             {
     844                 :      151964 :               tree_code rhs_code = gimple_cond_code (cond);
     845                 :      151964 :               gcc_assert (TREE_CODE_CLASS (rhs_code) == tcc_comparison);
     846                 :      151964 :               opt_result res
     847                 :      151964 :                 = process_use (stmt_vinfo, gimple_cond_lhs (cond),
     848                 :             :                                loop_vinfo, relevant, &worklist, false);
     849                 :      151964 :               if (!res)
     850                 :       12741 :                 return res;
     851                 :      151964 :               res = process_use (stmt_vinfo, gimple_cond_rhs (cond),
     852                 :             :                                 loop_vinfo, relevant, &worklist, false);
     853                 :      151964 :               if (!res)
     854                 :           0 :                 return res;
     855                 :             :             }
     856                 :        4046 :           else if (gcall *call = dyn_cast <gcall *> (stmt_vinfo->stmt))
     857                 :             :             {
     858                 :       19437 :               for (i = 0; i < gimple_call_num_args (call); i++)
     859                 :             :                 {
     860                 :       15391 :                   tree arg = gimple_call_arg (call, i);
     861                 :       15391 :                   opt_result res
     862                 :       15391 :                     = process_use (stmt_vinfo, arg, loop_vinfo, relevant,
     863                 :             :                                    &worklist, false);
     864                 :       15391 :                   if (!res)
     865                 :           0 :                     return res;
     866                 :             :                 }
     867                 :             :             }
     868                 :             :           else
     869                 :           0 :             gcc_unreachable ();
     870                 :             :         }
     871                 :             :       else
     872                 :     7038077 :         FOR_EACH_PHI_OR_STMT_USE (use_p, stmt_vinfo->stmt, iter, SSA_OP_USE)
     873                 :             :           {
     874                 :     3042084 :             tree op = USE_FROM_PTR (use_p);
     875                 :     3042084 :             opt_result res
     876                 :     3042084 :               = process_use (stmt_vinfo, op, loop_vinfo, relevant,
     877                 :             :                              &worklist, false);
     878                 :     3042084 :             if (!res)
     879                 :        9833 :               return res;
     880                 :             :           }
     881                 :             : 
     882                 :     2419833 :       if (STMT_VINFO_GATHER_SCATTER_P (stmt_vinfo))
     883                 :             :         {
     884                 :       29792 :           gather_scatter_info gs_info;
     885                 :       29792 :           if (!vect_check_gather_scatter (stmt_vinfo, loop_vinfo, &gs_info))
     886                 :           0 :             gcc_unreachable ();
     887                 :       29792 :           opt_result res
     888                 :       29792 :             = process_use (stmt_vinfo, gs_info.offset, loop_vinfo, relevant,
     889                 :             :                            &worklist, true);
     890                 :       29792 :           if (!res)
     891                 :             :             {
     892                 :        1379 :               if (fatal)
     893                 :        1379 :                 *fatal = false;
     894                 :        1379 :               return res;
     895                 :             :             }
     896                 :             :         }
     897                 :             :     } /* while worklist */
     898                 :             : 
     899                 :      300893 :   return opt_result::success ();
     900                 :      313634 : }
     901                 :             : 
     902                 :             : /* Function vect_model_simple_cost.
     903                 :             : 
     904                 :             :    Models cost for simple operations, i.e. those that only emit ncopies of a
     905                 :             :    single op.  Right now, this does not account for multiple insns that could
     906                 :             :    be generated for the single vector op.  We will handle that shortly.  */
     907                 :             : 
     908                 :             : static void
     909                 :      641758 : vect_model_simple_cost (vec_info *, int ncopies, enum vect_def_type *dt,
     910                 :             :                         int ndts, slp_tree node,
     911                 :             :                         stmt_vector_for_cost *cost_vec,
     912                 :             :                         vect_cost_for_stmt kind = vector_stmt)
     913                 :             : {
     914                 :      641758 :   int inside_cost = 0, prologue_cost = 0;
     915                 :             : 
     916                 :      641758 :   gcc_assert (cost_vec != NULL);
     917                 :             : 
     918                 :             :   /* ???  Somehow we need to fix this at the callers.  */
     919                 :      641758 :   if (node)
     920                 :      641758 :     ncopies = SLP_TREE_NUMBER_OF_VEC_STMTS (node);
     921                 :             : 
     922                 :      641758 :   if (!node)
     923                 :             :     /* Cost the "broadcast" of a scalar operand in to a vector operand.
     924                 :             :        Use scalar_to_vec to cost the broadcast, as elsewhere in the vector
     925                 :             :        cost model.  */
     926                 :           0 :     for (int i = 0; i < ndts; i++)
     927                 :           0 :       if (dt[i] == vect_constant_def || dt[i] == vect_external_def)
     928                 :           0 :         prologue_cost += record_stmt_cost (cost_vec, 1, scalar_to_vec,
     929                 :             :                                            node, 0, vect_prologue);
     930                 :             : 
     931                 :             :   /* Pass the inside-of-loop statements to the target-specific cost model.  */
     932                 :      641758 :   inside_cost += record_stmt_cost (cost_vec, ncopies, kind,
     933                 :             :                                    node, 0, vect_body);
     934                 :             : 
     935                 :      641758 :   if (dump_enabled_p ())
     936                 :       36164 :     dump_printf_loc (MSG_NOTE, vect_location,
     937                 :             :                      "vect_model_simple_cost: inside_cost = %d, "
     938                 :             :                      "prologue_cost = %d .\n", inside_cost, prologue_cost);
     939                 :      641758 : }
     940                 :             : 
     941                 :             : 
     942                 :             : /* Model cost for type demotion and promotion operations.  PWR is
     943                 :             :    normally zero for single-step promotions and demotions.  It will be
     944                 :             :    one if two-step promotion/demotion is required, and so on.  NCOPIES
     945                 :             :    is the number of vector results (and thus number of instructions)
     946                 :             :    for the narrowest end of the operation chain.  Each additional
     947                 :             :    step doubles the number of instructions required.  If WIDEN_ARITH
     948                 :             :    is true the stmt is doing widening arithmetic.  */
     949                 :             : 
     950                 :             : static void
     951                 :       52427 : vect_model_promotion_demotion_cost (stmt_vec_info stmt_info,
     952                 :             :                                     enum vect_def_type *dt,
     953                 :             :                                     unsigned int ncopies, int pwr,
     954                 :             :                                     stmt_vector_for_cost *cost_vec,
     955                 :             :                                     bool widen_arith)
     956                 :             : {
     957                 :       52427 :   int i;
     958                 :       52427 :   int inside_cost = 0, prologue_cost = 0;
     959                 :             : 
     960                 :      125570 :   for (i = 0; i < pwr + 1; i++)
     961                 :             :     {
     962                 :      144268 :       inside_cost += record_stmt_cost (cost_vec, ncopies,
     963                 :             :                                        widen_arith
     964                 :             :                                        ? vector_stmt : vec_promote_demote,
     965                 :             :                                        stmt_info, 0, vect_body);
     966                 :       73143 :       ncopies *= 2;
     967                 :             :     }
     968                 :             : 
     969                 :             :   /* FORNOW: Assuming maximum 2 args per stmts.  */
     970                 :      157281 :   for (i = 0; i < 2; i++)
     971                 :      104854 :     if (dt[i] == vect_constant_def || dt[i] == vect_external_def)
     972                 :        2601 :       prologue_cost += record_stmt_cost (cost_vec, 1, vector_stmt,
     973                 :             :                                          stmt_info, 0, vect_prologue);
     974                 :             : 
     975                 :       52427 :   if (dump_enabled_p ())
     976                 :        7465 :     dump_printf_loc (MSG_NOTE, vect_location,
     977                 :             :                      "vect_model_promotion_demotion_cost: inside_cost = %d, "
     978                 :             :                      "prologue_cost = %d .\n", inside_cost, prologue_cost);
     979                 :       52427 : }
     980                 :             : 
     981                 :             : /* Returns true if the current function returns DECL.  */
     982                 :             : 
     983                 :             : static bool
     984                 :      602513 : cfun_returns (tree decl)
     985                 :             : {
     986                 :      602513 :   edge_iterator ei;
     987                 :      602513 :   edge e;
     988                 :     1181230 :   FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR_FOR_FN (cfun)->preds)
     989                 :             :     {
     990                 :     1193490 :       greturn *ret = safe_dyn_cast <greturn *> (*gsi_last_bb (e->src));
     991                 :      596745 :       if (!ret)
     992                 :           0 :         continue;
     993                 :      596745 :       if (gimple_return_retval (ret) == decl)
     994                 :             :         return true;
     995                 :             :       /* We often end up with an aggregate copy to the result decl,
     996                 :             :          handle that case as well.  First skip intermediate clobbers
     997                 :             :          though.  */
     998                 :             :       gimple *def = ret;
     999                 :     1648821 :       do
    1000                 :             :         {
    1001                 :     3297642 :           def = SSA_NAME_DEF_STMT (gimple_vuse (def));
    1002                 :             :         }
    1003                 :     1648821 :       while (gimple_clobber_p (def));
    1004                 :      579521 :       if (is_a <gassign *> (def)
    1005                 :       70672 :           && gimple_assign_lhs (def) == gimple_return_retval (ret)
    1006                 :      586528 :           && gimple_assign_rhs1 (def) == decl)
    1007                 :             :         return true;
    1008                 :             :     }
    1009                 :             :   return false;
    1010                 :             : }
    1011                 :             : 
    1012                 :             : /* Calculate cost of DR's memory access.  */
    1013                 :             : void
    1014                 :      990472 : vect_get_store_cost (vec_info *, stmt_vec_info stmt_info, slp_tree slp_node,
    1015                 :             :                      int ncopies, dr_alignment_support alignment_support_scheme,
    1016                 :             :                      int misalignment,
    1017                 :             :                      unsigned int *inside_cost,
    1018                 :             :                      stmt_vector_for_cost *body_cost_vec)
    1019                 :             : {
    1020                 :      990472 :   tree vectype
    1021                 :      990472 :     = slp_node ? SLP_TREE_VECTYPE (slp_node) : STMT_VINFO_VECTYPE (stmt_info);
    1022                 :      990472 :   switch (alignment_support_scheme)
    1023                 :             :     {
    1024                 :      563168 :     case dr_aligned:
    1025                 :      563168 :       {
    1026                 :      563168 :         *inside_cost += record_stmt_cost (body_cost_vec, ncopies,
    1027                 :             :                                           vector_store, stmt_info, slp_node,
    1028                 :             :                                           vectype, 0, vect_body);
    1029                 :             : 
    1030                 :      563168 :         if (dump_enabled_p ())
    1031                 :       13951 :           dump_printf_loc (MSG_NOTE, vect_location,
    1032                 :             :                            "vect_model_store_cost: aligned.\n");
    1033                 :             :         break;
    1034                 :             :       }
    1035                 :             : 
    1036                 :      427304 :     case dr_unaligned_supported:
    1037                 :      427304 :       {
    1038                 :             :         /* Here, we assign an additional cost for the unaligned store.  */
    1039                 :      427304 :         *inside_cost += record_stmt_cost (body_cost_vec, ncopies,
    1040                 :             :                                           unaligned_store, stmt_info, slp_node,
    1041                 :             :                                           vectype, misalignment, vect_body);
    1042                 :      427304 :         if (dump_enabled_p ())
    1043                 :       13176 :           dump_printf_loc (MSG_NOTE, vect_location,
    1044                 :             :                            "vect_model_store_cost: unaligned supported by "
    1045                 :             :                            "hardware.\n");
    1046                 :             :         break;
    1047                 :             :       }
    1048                 :             : 
    1049                 :           0 :     case dr_unaligned_unsupported:
    1050                 :           0 :       {
    1051                 :           0 :         *inside_cost = VECT_MAX_COST;
    1052                 :             : 
    1053                 :           0 :         if (dump_enabled_p ())
    1054                 :           0 :           dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    1055                 :             :                            "vect_model_store_cost: unsupported access.\n");
    1056                 :             :         break;
    1057                 :             :       }
    1058                 :             : 
    1059                 :           0 :     default:
    1060                 :           0 :       gcc_unreachable ();
    1061                 :             :     }
    1062                 :      990472 : }
    1063                 :             : 
    1064                 :             : /* Calculate cost of DR's memory access.  */
    1065                 :             : void
    1066                 :      792274 : vect_get_load_cost (vec_info *, stmt_vec_info stmt_info, slp_tree slp_node,
    1067                 :             :                     int ncopies, dr_alignment_support alignment_support_scheme,
    1068                 :             :                     int misalignment,
    1069                 :             :                     bool add_realign_cost, unsigned int *inside_cost,
    1070                 :             :                     unsigned int *prologue_cost,
    1071                 :             :                     stmt_vector_for_cost *prologue_cost_vec,
    1072                 :             :                     stmt_vector_for_cost *body_cost_vec,
    1073                 :             :                     bool record_prologue_costs)
    1074                 :             : {
    1075                 :      792274 :   tree vectype
    1076                 :      792274 :     = slp_node ? SLP_TREE_VECTYPE (slp_node) : STMT_VINFO_VECTYPE (stmt_info);
    1077                 :      792274 :   switch (alignment_support_scheme)
    1078                 :             :     {
    1079                 :      476286 :     case dr_aligned:
    1080                 :      476286 :       {
    1081                 :      476286 :         *inside_cost += record_stmt_cost (body_cost_vec, ncopies, vector_load,
    1082                 :             :                                           stmt_info, slp_node, vectype,
    1083                 :             :                                           0, vect_body);
    1084                 :             : 
    1085                 :      476286 :         if (dump_enabled_p ())
    1086                 :       17903 :           dump_printf_loc (MSG_NOTE, vect_location,
    1087                 :             :                            "vect_model_load_cost: aligned.\n");
    1088                 :             : 
    1089                 :             :         break;
    1090                 :             :       }
    1091                 :      266250 :     case dr_unaligned_supported:
    1092                 :      266250 :       {
    1093                 :             :         /* Here, we assign an additional cost for the unaligned load.  */
    1094                 :      266250 :         *inside_cost += record_stmt_cost (body_cost_vec, ncopies,
    1095                 :             :                                           unaligned_load, stmt_info, slp_node,
    1096                 :             :                                           vectype, misalignment, vect_body);
    1097                 :             : 
    1098                 :      266250 :         if (dump_enabled_p ())
    1099                 :       22766 :           dump_printf_loc (MSG_NOTE, vect_location,
    1100                 :             :                            "vect_model_load_cost: unaligned supported by "
    1101                 :             :                            "hardware.\n");
    1102                 :             : 
    1103                 :             :         break;
    1104                 :             :       }
    1105                 :           0 :     case dr_explicit_realign:
    1106                 :           0 :       {
    1107                 :           0 :         *inside_cost += record_stmt_cost (body_cost_vec, ncopies * 2,
    1108                 :             :                                           vector_load, stmt_info, slp_node,
    1109                 :             :                                           vectype, 0, vect_body);
    1110                 :           0 :         *inside_cost += record_stmt_cost (body_cost_vec, ncopies,
    1111                 :             :                                           vec_perm, stmt_info, slp_node,
    1112                 :             :                                           vectype, 0, vect_body);
    1113                 :             : 
    1114                 :             :         /* FIXME: If the misalignment remains fixed across the iterations of
    1115                 :             :            the containing loop, the following cost should be added to the
    1116                 :             :            prologue costs.  */
    1117                 :           0 :         if (targetm.vectorize.builtin_mask_for_load)
    1118                 :           0 :           *inside_cost += record_stmt_cost (body_cost_vec, 1, vector_stmt,
    1119                 :             :                                             stmt_info, slp_node, vectype,
    1120                 :             :                                             0, vect_body);
    1121                 :             : 
    1122                 :           0 :         if (dump_enabled_p ())
    1123                 :           0 :           dump_printf_loc (MSG_NOTE, vect_location,
    1124                 :             :                            "vect_model_load_cost: explicit realign\n");
    1125                 :             : 
    1126                 :             :         break;
    1127                 :             :       }
    1128                 :           0 :     case dr_explicit_realign_optimized:
    1129                 :           0 :       {
    1130                 :           0 :         if (dump_enabled_p ())
    1131                 :           0 :           dump_printf_loc (MSG_NOTE, vect_location,
    1132                 :             :                            "vect_model_load_cost: unaligned software "
    1133                 :             :                            "pipelined.\n");
    1134                 :             : 
    1135                 :             :         /* Unaligned software pipeline has a load of an address, an initial
    1136                 :             :            load, and possibly a mask operation to "prime" the loop.  However,
    1137                 :             :            if this is an access in a group of loads, which provide grouped
    1138                 :             :            access, then the above cost should only be considered for one
    1139                 :             :            access in the group.  Inside the loop, there is a load op
    1140                 :             :            and a realignment op.  */
    1141                 :             : 
    1142                 :           0 :         if (add_realign_cost && record_prologue_costs)
    1143                 :             :           {
    1144                 :           0 :             *prologue_cost += record_stmt_cost (prologue_cost_vec, 2,
    1145                 :             :                                                 vector_stmt, stmt_info,
    1146                 :             :                                                 slp_node, vectype,
    1147                 :             :                                                 0, vect_prologue);
    1148                 :           0 :             if (targetm.vectorize.builtin_mask_for_load)
    1149                 :           0 :               *prologue_cost += record_stmt_cost (prologue_cost_vec, 1,
    1150                 :             :                                                   vector_stmt, stmt_info,
    1151                 :             :                                                   slp_node, vectype,
    1152                 :             :                                                   0, vect_prologue);
    1153                 :             :           }
    1154                 :             : 
    1155                 :           0 :         *inside_cost += record_stmt_cost (body_cost_vec, ncopies, vector_load,
    1156                 :             :                                           stmt_info, slp_node, vectype,
    1157                 :             :                                           0, vect_body);
    1158                 :           0 :         *inside_cost += record_stmt_cost (body_cost_vec, ncopies, vec_perm,
    1159                 :             :                                           stmt_info, slp_node, vectype,
    1160                 :             :                                           0, vect_body);
    1161                 :             : 
    1162                 :           0 :         if (dump_enabled_p ())
    1163                 :           0 :           dump_printf_loc (MSG_NOTE, vect_location,
    1164                 :             :                            "vect_model_load_cost: explicit realign optimized"
    1165                 :             :                            "\n");
    1166                 :             : 
    1167                 :             :         break;
    1168                 :             :       }
    1169                 :             : 
    1170                 :       49738 :     case dr_unaligned_unsupported:
    1171                 :       49738 :       {
    1172                 :       49738 :         *inside_cost = VECT_MAX_COST;
    1173                 :             : 
    1174                 :       49738 :         if (dump_enabled_p ())
    1175                 :          93 :           dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    1176                 :             :                            "vect_model_load_cost: unsupported access.\n");
    1177                 :             :         break;
    1178                 :             :       }
    1179                 :             : 
    1180                 :           0 :     default:
    1181                 :           0 :       gcc_unreachable ();
    1182                 :             :     }
    1183                 :      792274 : }
    1184                 :             : 
    1185                 :             : /* Insert the new stmt NEW_STMT at *GSI or at the appropriate place in
    1186                 :             :    the loop preheader for the vectorized stmt STMT_VINFO.  */
    1187                 :             : 
    1188                 :             : static void
    1189                 :        6139 : vect_init_vector_1 (vec_info *vinfo, stmt_vec_info stmt_vinfo, gimple *new_stmt,
    1190                 :             :                     gimple_stmt_iterator *gsi)
    1191                 :             : {
    1192                 :        6139 :   if (gsi)
    1193                 :        2890 :     vect_finish_stmt_generation (vinfo, stmt_vinfo, new_stmt, gsi);
    1194                 :             :   else
    1195                 :        3249 :     vinfo->insert_on_entry (stmt_vinfo, new_stmt);
    1196                 :             : 
    1197                 :        6139 :   if (dump_enabled_p ())
    1198                 :        1682 :     dump_printf_loc (MSG_NOTE, vect_location,
    1199                 :             :                      "created new init_stmt: %G", new_stmt);
    1200                 :        6139 : }
    1201                 :             : 
    1202                 :             : /* Function vect_init_vector.
    1203                 :             : 
    1204                 :             :    Insert a new stmt (INIT_STMT) that initializes a new variable of type
    1205                 :             :    TYPE with the value VAL.  If TYPE is a vector type and VAL does not have
    1206                 :             :    vector type a vector with all elements equal to VAL is created first.
    1207                 :             :    Place the initialization at GSI if it is not NULL.  Otherwise, place the
    1208                 :             :    initialization at the loop preheader.
    1209                 :             :    Return the DEF of INIT_STMT.
    1210                 :             :    It will be used in the vectorization of STMT_INFO.  */
    1211                 :             : 
    1212                 :             : tree
    1213                 :        4426 : vect_init_vector (vec_info *vinfo, stmt_vec_info stmt_info, tree val, tree type,
    1214                 :             :                   gimple_stmt_iterator *gsi)
    1215                 :             : {
    1216                 :        4426 :   gimple *init_stmt;
    1217                 :        4426 :   tree new_temp;
    1218                 :             : 
    1219                 :             :   /* We abuse this function to push sth to a SSA name with initial 'val'.  */
    1220                 :        4426 :   if (! useless_type_conversion_p (type, TREE_TYPE (val)))
    1221                 :             :     {
    1222                 :        1326 :       gcc_assert (VECTOR_TYPE_P (type));
    1223                 :        1326 :       if (! types_compatible_p (TREE_TYPE (type), TREE_TYPE (val)))
    1224                 :             :         {
    1225                 :             :           /* Scalar boolean value should be transformed into
    1226                 :             :              all zeros or all ones value before building a vector.  */
    1227                 :          14 :           if (VECTOR_BOOLEAN_TYPE_P (type))
    1228                 :             :             {
    1229                 :           0 :               tree true_val = build_all_ones_cst (TREE_TYPE (type));
    1230                 :           0 :               tree false_val = build_zero_cst (TREE_TYPE (type));
    1231                 :             : 
    1232                 :           0 :               if (CONSTANT_CLASS_P (val))
    1233                 :           0 :                 val = integer_zerop (val) ? false_val : true_val;
    1234                 :             :               else
    1235                 :             :                 {
    1236                 :           0 :                   new_temp = make_ssa_name (TREE_TYPE (type));
    1237                 :           0 :                   init_stmt = gimple_build_assign (new_temp, COND_EXPR,
    1238                 :             :                                                    val, true_val, false_val);
    1239                 :           0 :                   vect_init_vector_1 (vinfo, stmt_info, init_stmt, gsi);
    1240                 :           0 :                   val = new_temp;
    1241                 :             :                 }
    1242                 :             :             }
    1243                 :             :           else
    1244                 :             :             {
    1245                 :          14 :               gimple_seq stmts = NULL;
    1246                 :          14 :               if (! INTEGRAL_TYPE_P (TREE_TYPE (val)))
    1247                 :          12 :                 val = gimple_build (&stmts, VIEW_CONVERT_EXPR,
    1248                 :          12 :                                     TREE_TYPE (type), val);
    1249                 :             :               else
    1250                 :             :                 /* ???  Condition vectorization expects us to do
    1251                 :             :                    promotion of invariant/external defs.  */
    1252                 :           2 :                 val = gimple_convert (&stmts, TREE_TYPE (type), val);
    1253                 :          28 :               for (gimple_stmt_iterator gsi2 = gsi_start (stmts);
    1254                 :          28 :                    !gsi_end_p (gsi2); )
    1255                 :             :                 {
    1256                 :          14 :                   init_stmt = gsi_stmt (gsi2);
    1257                 :          14 :                   gsi_remove (&gsi2, false);
    1258                 :          14 :                   vect_init_vector_1 (vinfo, stmt_info, init_stmt, gsi);
    1259                 :             :                 }
    1260                 :             :             }
    1261                 :             :         }
    1262                 :        1326 :       val = build_vector_from_val (type, val);
    1263                 :             :     }
    1264                 :             : 
    1265                 :        4426 :   new_temp = vect_get_new_ssa_name (type, vect_simple_var, "cst_");
    1266                 :        4426 :   init_stmt = gimple_build_assign (new_temp, val);
    1267                 :        4426 :   vect_init_vector_1 (vinfo, stmt_info, init_stmt, gsi);
    1268                 :        4426 :   return new_temp;
    1269                 :             : }
    1270                 :             : 
    1271                 :             : 
    1272                 :             : /* Function vect_get_vec_defs_for_operand.
    1273                 :             : 
    1274                 :             :    OP is an operand in STMT_VINFO.  This function returns a vector of
    1275                 :             :    NCOPIES defs that will be used in the vectorized stmts for STMT_VINFO.
    1276                 :             : 
    1277                 :             :    In the case that OP is an SSA_NAME which is defined in the loop, then
    1278                 :             :    STMT_VINFO_VEC_STMTS of the defining stmt holds the relevant defs.
    1279                 :             : 
    1280                 :             :    In case OP is an invariant or constant, a new stmt that creates a vector def
    1281                 :             :    needs to be introduced.  VECTYPE may be used to specify a required type for
    1282                 :             :    vector invariant.  */
    1283                 :             : 
    1284                 :             : void
    1285                 :           0 : vect_get_vec_defs_for_operand (vec_info *vinfo, stmt_vec_info stmt_vinfo,
    1286                 :             :                                unsigned ncopies,
    1287                 :             :                                tree op, vec<tree> *vec_oprnds, tree vectype)
    1288                 :             : {
    1289                 :           0 :   gimple *def_stmt;
    1290                 :           0 :   enum vect_def_type dt;
    1291                 :           0 :   bool is_simple_use;
    1292                 :           0 :   loop_vec_info loop_vinfo = dyn_cast <loop_vec_info> (vinfo);
    1293                 :             : 
    1294                 :           0 :   if (dump_enabled_p ())
    1295                 :           0 :     dump_printf_loc (MSG_NOTE, vect_location,
    1296                 :             :                      "vect_get_vec_defs_for_operand: %T\n", op);
    1297                 :             : 
    1298                 :           0 :   stmt_vec_info def_stmt_info;
    1299                 :           0 :   is_simple_use = vect_is_simple_use (op, loop_vinfo, &dt,
    1300                 :             :                                       &def_stmt_info, &def_stmt);
    1301                 :           0 :   gcc_assert (is_simple_use);
    1302                 :           0 :   if (def_stmt && dump_enabled_p ())
    1303                 :           0 :     dump_printf_loc (MSG_NOTE, vect_location, "  def_stmt =  %G", def_stmt);
    1304                 :             : 
    1305                 :           0 :   vec_oprnds->create (ncopies);
    1306                 :           0 :   if (dt == vect_constant_def || dt == vect_external_def)
    1307                 :             :     {
    1308                 :           0 :       tree stmt_vectype = STMT_VINFO_VECTYPE (stmt_vinfo);
    1309                 :           0 :       tree vector_type;
    1310                 :             : 
    1311                 :           0 :       if (vectype)
    1312                 :             :         vector_type = vectype;
    1313                 :           0 :       else if (VECT_SCALAR_BOOLEAN_TYPE_P (TREE_TYPE (op))
    1314                 :           0 :                && VECTOR_BOOLEAN_TYPE_P (stmt_vectype))
    1315                 :           0 :         vector_type = truth_type_for (stmt_vectype);
    1316                 :             :       else
    1317                 :           0 :         vector_type = get_vectype_for_scalar_type (loop_vinfo, TREE_TYPE (op));
    1318                 :             : 
    1319                 :           0 :       gcc_assert (vector_type);
    1320                 :             :       /* A masked load can have a default SSA definition as else operand.
    1321                 :             :          We should "vectorize" this instead of creating a duplicate from the
    1322                 :             :          scalar default.  */
    1323                 :           0 :       tree vop;
    1324                 :           0 :       if (TREE_CODE (op) == SSA_NAME
    1325                 :           0 :           && SSA_NAME_IS_DEFAULT_DEF (op)
    1326                 :           0 :           && VAR_P (SSA_NAME_VAR (op)))
    1327                 :           0 :         vop = get_or_create_ssa_default_def (cfun,
    1328                 :             :                                              create_tmp_var (vector_type));
    1329                 :             :       else
    1330                 :           0 :         vop = vect_init_vector (vinfo, stmt_vinfo, op, vector_type, NULL);
    1331                 :           0 :       while (ncopies--)
    1332                 :           0 :         vec_oprnds->quick_push (vop);
    1333                 :             :     }
    1334                 :             :   else
    1335                 :             :     {
    1336                 :           0 :       def_stmt_info = vect_stmt_to_vectorize (def_stmt_info);
    1337                 :           0 :       gcc_assert (STMT_VINFO_VEC_STMTS (def_stmt_info).length () == ncopies);
    1338                 :           0 :       for (unsigned i = 0; i < ncopies; ++i)
    1339                 :           0 :         vec_oprnds->quick_push (gimple_get_lhs
    1340                 :           0 :                                   (STMT_VINFO_VEC_STMTS (def_stmt_info)[i]));
    1341                 :             :     }
    1342                 :           0 : }
    1343                 :             : 
    1344                 :             : 
    1345                 :             : /* Get vectorized definitions for OP0 and OP1.  */
    1346                 :             : 
    1347                 :             : void
    1348                 :      704320 : vect_get_vec_defs (vec_info *vinfo, stmt_vec_info stmt_info, slp_tree slp_node,
    1349                 :             :                    unsigned ncopies,
    1350                 :             :                    tree op0, tree vectype0, vec<tree> *vec_oprnds0,
    1351                 :             :                    tree op1, tree vectype1, vec<tree> *vec_oprnds1,
    1352                 :             :                    tree op2, tree vectype2, vec<tree> *vec_oprnds2,
    1353                 :             :                    tree op3, tree vectype3, vec<tree> *vec_oprnds3)
    1354                 :             : {
    1355                 :      704320 :   if (slp_node)
    1356                 :             :     {
    1357                 :      704320 :       if (op0)
    1358                 :      702905 :         vect_get_slp_defs (SLP_TREE_CHILDREN (slp_node)[0], vec_oprnds0);
    1359                 :      704320 :       if (op1)
    1360                 :      125642 :         vect_get_slp_defs (SLP_TREE_CHILDREN (slp_node)[1], vec_oprnds1);
    1361                 :      704320 :       if (op2)
    1362                 :        6890 :         vect_get_slp_defs (SLP_TREE_CHILDREN (slp_node)[2], vec_oprnds2);
    1363                 :      704320 :       if (op3)
    1364                 :           0 :         vect_get_slp_defs (SLP_TREE_CHILDREN (slp_node)[3], vec_oprnds3);
    1365                 :             :     }
    1366                 :             :   else
    1367                 :             :     {
    1368                 :           0 :       if (op0)
    1369                 :           0 :         vect_get_vec_defs_for_operand (vinfo, stmt_info, ncopies,
    1370                 :             :                                        op0, vec_oprnds0, vectype0);
    1371                 :           0 :       if (op1)
    1372                 :           0 :         vect_get_vec_defs_for_operand (vinfo, stmt_info, ncopies,
    1373                 :             :                                        op1, vec_oprnds1, vectype1);
    1374                 :           0 :       if (op2)
    1375                 :           0 :         vect_get_vec_defs_for_operand (vinfo, stmt_info, ncopies,
    1376                 :             :                                        op2, vec_oprnds2, vectype2);
    1377                 :           0 :       if (op3)
    1378                 :           0 :         vect_get_vec_defs_for_operand (vinfo, stmt_info, ncopies,
    1379                 :             :                                        op3, vec_oprnds3, vectype3);
    1380                 :             :     }
    1381                 :      704320 : }
    1382                 :             : 
    1383                 :             : void
    1384                 :      668816 : vect_get_vec_defs (vec_info *vinfo, stmt_vec_info stmt_info, slp_tree slp_node,
    1385                 :             :                    unsigned ncopies,
    1386                 :             :                    tree op0, vec<tree> *vec_oprnds0,
    1387                 :             :                    tree op1, vec<tree> *vec_oprnds1,
    1388                 :             :                    tree op2, vec<tree> *vec_oprnds2,
    1389                 :             :                    tree op3, vec<tree> *vec_oprnds3)
    1390                 :             : {
    1391                 :      668816 :   vect_get_vec_defs (vinfo, stmt_info, slp_node, ncopies,
    1392                 :             :                      op0, NULL_TREE, vec_oprnds0,
    1393                 :             :                      op1, NULL_TREE, vec_oprnds1,
    1394                 :             :                      op2, NULL_TREE, vec_oprnds2,
    1395                 :             :                      op3, NULL_TREE, vec_oprnds3);
    1396                 :      668816 : }
    1397                 :             : 
    1398                 :             : /* Helper function called by vect_finish_replace_stmt and
    1399                 :             :    vect_finish_stmt_generation.  Set the location of the new
    1400                 :             :    statement and create and return a stmt_vec_info for it.  */
    1401                 :             : 
    1402                 :             : static void
    1403                 :     1281051 : vect_finish_stmt_generation_1 (vec_info *,
    1404                 :             :                                stmt_vec_info stmt_info, gimple *vec_stmt)
    1405                 :             : {
    1406                 :     1281051 :   if (dump_enabled_p ())
    1407                 :      129855 :     dump_printf_loc (MSG_NOTE, vect_location, "add new stmt: %G", vec_stmt);
    1408                 :             : 
    1409                 :     1281051 :   if (stmt_info)
    1410                 :             :     {
    1411                 :     1251497 :       gimple_set_location (vec_stmt, gimple_location (stmt_info->stmt));
    1412                 :             : 
    1413                 :             :       /* While EH edges will generally prevent vectorization, stmt might
    1414                 :             :          e.g. be in a must-not-throw region.  Ensure newly created stmts
    1415                 :             :          that could throw are part of the same region.  */
    1416                 :     1251497 :       int lp_nr = lookup_stmt_eh_lp (stmt_info->stmt);
    1417                 :     1251497 :       if (lp_nr != 0 && stmt_could_throw_p (cfun, vec_stmt))
    1418                 :          66 :         add_stmt_to_eh_lp (vec_stmt, lp_nr);
    1419                 :             :     }
    1420                 :             :   else
    1421                 :       29554 :     gcc_assert (!stmt_could_throw_p (cfun, vec_stmt));
    1422                 :     1281051 : }
    1423                 :             : 
    1424                 :             : /* Replace the scalar statement STMT_INFO with a new vector statement VEC_STMT,
    1425                 :             :    which sets the same scalar result as STMT_INFO did.  Create and return a
    1426                 :             :    stmt_vec_info for VEC_STMT.  */
    1427                 :             : 
    1428                 :             : void
    1429                 :         834 : vect_finish_replace_stmt (vec_info *vinfo,
    1430                 :             :                           stmt_vec_info stmt_info, gimple *vec_stmt)
    1431                 :             : {
    1432                 :         834 :   gimple *scalar_stmt = vect_orig_stmt (stmt_info)->stmt;
    1433                 :         834 :   gcc_assert (gimple_get_lhs (scalar_stmt) == gimple_get_lhs (vec_stmt));
    1434                 :             : 
    1435                 :         834 :   gimple_stmt_iterator gsi = gsi_for_stmt (scalar_stmt);
    1436                 :         834 :   gsi_replace (&gsi, vec_stmt, true);
    1437                 :             : 
    1438                 :         834 :   vect_finish_stmt_generation_1 (vinfo, stmt_info, vec_stmt);
    1439                 :         834 : }
    1440                 :             : 
    1441                 :             : /* Add VEC_STMT to the vectorized implementation of STMT_INFO and insert it
    1442                 :             :    before *GSI.  Create and return a stmt_vec_info for VEC_STMT.  */
    1443                 :             : 
    1444                 :             : void
    1445                 :     1280217 : vect_finish_stmt_generation (vec_info *vinfo,
    1446                 :             :                              stmt_vec_info stmt_info, gimple *vec_stmt,
    1447                 :             :                              gimple_stmt_iterator *gsi)
    1448                 :             : {
    1449                 :     1280217 :   gcc_assert (!stmt_info || gimple_code (stmt_info->stmt) != GIMPLE_LABEL);
    1450                 :             : 
    1451                 :     1280217 :   if (!gsi_end_p (*gsi)
    1452                 :     2559457 :       && gimple_has_mem_ops (vec_stmt))
    1453                 :             :     {
    1454                 :     1279240 :       gimple *at_stmt = gsi_stmt (*gsi);
    1455                 :     1279240 :       tree vuse = gimple_vuse (at_stmt);
    1456                 :     1272917 :       if (vuse && TREE_CODE (vuse) == SSA_NAME)
    1457                 :             :         {
    1458                 :     1163097 :           tree vdef = gimple_vdef (at_stmt);
    1459                 :     1163097 :           gimple_set_vuse (vec_stmt, gimple_vuse (at_stmt));
    1460                 :     1163097 :           gimple_set_modified (vec_stmt, true);
    1461                 :             :           /* If we have an SSA vuse and insert a store, update virtual
    1462                 :             :              SSA form to avoid triggering the renamer.  Do so only
    1463                 :             :              if we can easily see all uses - which is what almost always
    1464                 :             :              happens with the way vectorized stmts are inserted.  */
    1465                 :      743029 :           if ((vdef && TREE_CODE (vdef) == SSA_NAME)
    1466                 :     1906090 :               && ((is_gimple_assign (vec_stmt)
    1467                 :      742348 :                    && !is_gimple_reg (gimple_assign_lhs (vec_stmt)))
    1468                 :       61761 :                   || (is_gimple_call (vec_stmt)
    1469                 :         645 :                       && (!(gimple_call_flags (vec_stmt)
    1470                 :         645 :                             & (ECF_CONST|ECF_PURE|ECF_NOVOPS))
    1471                 :           1 :                           || (gimple_call_lhs (vec_stmt)
    1472                 :           1 :                               && !is_gimple_reg (gimple_call_lhs (vec_stmt)))))))
    1473                 :             :             {
    1474                 :      681876 :               tree new_vdef = copy_ssa_name (vuse, vec_stmt);
    1475                 :      681876 :               gimple_set_vdef (vec_stmt, new_vdef);
    1476                 :      681876 :               SET_USE (gimple_vuse_op (at_stmt), new_vdef);
    1477                 :             :             }
    1478                 :             :         }
    1479                 :             :     }
    1480                 :     1280217 :   gsi_insert_before (gsi, vec_stmt, GSI_SAME_STMT);
    1481                 :     1280217 :   vect_finish_stmt_generation_1 (vinfo, stmt_info, vec_stmt);
    1482                 :     1280217 : }
    1483                 :             : 
    1484                 :             : /* We want to vectorize a call to combined function CFN with function
    1485                 :             :    decl FNDECL, using VECTYPE_OUT as the type of the output and VECTYPE_IN
    1486                 :             :    as the types of all inputs.  Check whether this is possible using
    1487                 :             :    an internal function, returning its code if so or IFN_LAST if not.  */
    1488                 :             : 
    1489                 :             : static internal_fn
    1490                 :       11622 : vectorizable_internal_function (combined_fn cfn, tree fndecl,
    1491                 :             :                                 tree vectype_out, tree vectype_in)
    1492                 :             : {
    1493                 :       11622 :   internal_fn ifn;
    1494                 :       11622 :   if (internal_fn_p (cfn))
    1495                 :        9203 :     ifn = as_internal_fn (cfn);
    1496                 :             :   else
    1497                 :        2419 :     ifn = associated_internal_fn (fndecl);
    1498                 :       11622 :   if (ifn != IFN_LAST && direct_internal_fn_p (ifn))
    1499                 :             :     {
    1500                 :        7764 :       const direct_internal_fn_info &info = direct_internal_fn (ifn);
    1501                 :        7764 :       if (info.vectorizable)
    1502                 :             :         {
    1503                 :        7764 :           bool same_size_p = TYPE_SIZE (vectype_in) == TYPE_SIZE (vectype_out);
    1504                 :        7764 :           tree type0 = (info.type0 < 0 ? vectype_out : vectype_in);
    1505                 :        7764 :           tree type1 = (info.type1 < 0 ? vectype_out : vectype_in);
    1506                 :             : 
    1507                 :             :           /* The type size of both the vectype_in and vectype_out should be
    1508                 :             :              exactly the same when vectype_out isn't participating the optab.
    1509                 :             :              While there is no restriction for type size when vectype_out
    1510                 :             :              is part of the optab query.  */
    1511                 :        7764 :           if (type0 != vectype_out && type1 != vectype_out && !same_size_p)
    1512                 :             :             return IFN_LAST;
    1513                 :             : 
    1514                 :        7743 :           if (direct_internal_fn_supported_p (ifn, tree_pair (type0, type1),
    1515                 :             :                                               OPTIMIZE_FOR_SPEED))
    1516                 :             :             return ifn;
    1517                 :             :         }
    1518                 :             :     }
    1519                 :             :   return IFN_LAST;
    1520                 :             : }
    1521                 :             : 
    1522                 :             : 
    1523                 :             : static tree permute_vec_elements (vec_info *, tree, tree, tree, stmt_vec_info,
    1524                 :             :                                   gimple_stmt_iterator *);
    1525                 :             : 
    1526                 :             : /* Check whether a load or store statement in the loop described by
    1527                 :             :    LOOP_VINFO is possible in a loop using partial vectors.  This is
    1528                 :             :    testing whether the vectorizer pass has the appropriate support,
    1529                 :             :    as well as whether the target does.
    1530                 :             : 
    1531                 :             :    VLS_TYPE says whether the statement is a load or store and VECTYPE
    1532                 :             :    is the type of the vector being loaded or stored.  SLP_NODE is the SLP
    1533                 :             :    node that contains the statement, or null if none.  MEMORY_ACCESS_TYPE
    1534                 :             :    says how the load or store is going to be implemented and GROUP_SIZE
    1535                 :             :    is the number of load or store statements in the containing group.
    1536                 :             :    If the access is a gather load or scatter store, GS_INFO describes
    1537                 :             :    its arguments.  If the load or store is conditional, SCALAR_MASK is the
    1538                 :             :    condition under which it occurs.
    1539                 :             : 
    1540                 :             :    Clear LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P if a loop using partial
    1541                 :             :    vectors is not supported, otherwise record the required rgroup control
    1542                 :             :    types.
    1543                 :             : 
    1544                 :             :    If partial vectors can be used and ELSVALS is nonzero the supported
    1545                 :             :    else values will be added to the vector ELSVALS points to.  */
    1546                 :             : 
    1547                 :             : static void
    1548                 :         115 : check_load_store_for_partial_vectors (loop_vec_info loop_vinfo, tree vectype,
    1549                 :             :                                       slp_tree slp_node,
    1550                 :             :                                       vec_load_store_type vls_type,
    1551                 :             :                                       int group_size,
    1552                 :             :                                       vect_memory_access_type
    1553                 :             :                                       memory_access_type,
    1554                 :             :                                       gather_scatter_info *gs_info,
    1555                 :             :                                       tree scalar_mask,
    1556                 :             :                                       vec<int> *elsvals = nullptr)
    1557                 :             : {
    1558                 :             :   /* Invariant loads need no special support.  */
    1559                 :         115 :   if (memory_access_type == VMAT_INVARIANT)
    1560                 :           0 :     return;
    1561                 :             : 
    1562                 :         115 :   unsigned int nvectors = vect_get_num_copies (loop_vinfo, slp_node, vectype);
    1563                 :         115 :   vec_loop_masks *masks = &LOOP_VINFO_MASKS (loop_vinfo);
    1564                 :         115 :   vec_loop_lens *lens = &LOOP_VINFO_LENS (loop_vinfo);
    1565                 :         115 :   machine_mode vecmode = TYPE_MODE (vectype);
    1566                 :         115 :   bool is_load = (vls_type == VLS_LOAD);
    1567                 :         115 :   if (memory_access_type == VMAT_LOAD_STORE_LANES)
    1568                 :             :     {
    1569                 :           0 :       if (slp_node)
    1570                 :           0 :         nvectors /= group_size;
    1571                 :           0 :       internal_fn ifn
    1572                 :           0 :         = (is_load ? vect_load_lanes_supported (vectype, group_size, true,
    1573                 :             :                                                 elsvals)
    1574                 :           0 :                    : vect_store_lanes_supported (vectype, group_size, true));
    1575                 :           0 :       if (ifn == IFN_MASK_LEN_LOAD_LANES || ifn == IFN_MASK_LEN_STORE_LANES)
    1576                 :           0 :         vect_record_loop_len (loop_vinfo, lens, nvectors, vectype, 1);
    1577                 :           0 :       else if (ifn == IFN_MASK_LOAD_LANES || ifn == IFN_MASK_STORE_LANES)
    1578                 :           0 :         vect_record_loop_mask (loop_vinfo, masks, nvectors, vectype,
    1579                 :             :                                scalar_mask);
    1580                 :             :       else
    1581                 :             :         {
    1582                 :           0 :           if (dump_enabled_p ())
    1583                 :           0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    1584                 :             :                              "can't operate on partial vectors because"
    1585                 :             :                              " the target doesn't have an appropriate"
    1586                 :             :                              " load/store-lanes instruction.\n");
    1587                 :           0 :           LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo) = false;
    1588                 :             :         }
    1589                 :           0 :       return;
    1590                 :             :     }
    1591                 :             : 
    1592                 :         115 :   if (memory_access_type == VMAT_GATHER_SCATTER)
    1593                 :             :     {
    1594                 :           0 :       internal_fn ifn = (is_load
    1595                 :           0 :                          ? IFN_MASK_GATHER_LOAD
    1596                 :             :                          : IFN_MASK_SCATTER_STORE);
    1597                 :           0 :       internal_fn len_ifn = (is_load
    1598                 :             :                              ? IFN_MASK_LEN_GATHER_LOAD
    1599                 :             :                              : IFN_MASK_LEN_SCATTER_STORE);
    1600                 :           0 :       if (internal_gather_scatter_fn_supported_p (len_ifn, vectype,
    1601                 :             :                                                   gs_info->memory_type,
    1602                 :             :                                                   gs_info->offset_vectype,
    1603                 :             :                                                   gs_info->scale,
    1604                 :             :                                                   elsvals))
    1605                 :           0 :         vect_record_loop_len (loop_vinfo, lens, nvectors, vectype, 1);
    1606                 :           0 :       else if (internal_gather_scatter_fn_supported_p (ifn, vectype,
    1607                 :             :                                                        gs_info->memory_type,
    1608                 :             :                                                        gs_info->offset_vectype,
    1609                 :             :                                                        gs_info->scale,
    1610                 :             :                                                        elsvals))
    1611                 :           0 :         vect_record_loop_mask (loop_vinfo, masks, nvectors, vectype,
    1612                 :             :                                scalar_mask);
    1613                 :             :       else
    1614                 :             :         {
    1615                 :           0 :           if (dump_enabled_p ())
    1616                 :           0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    1617                 :             :                              "can't operate on partial vectors because"
    1618                 :             :                              " the target doesn't have an appropriate"
    1619                 :             :                              " gather load or scatter store instruction.\n");
    1620                 :           0 :           LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo) = false;
    1621                 :             :         }
    1622                 :           0 :       return;
    1623                 :             :     }
    1624                 :             : 
    1625                 :         115 :   if (memory_access_type != VMAT_CONTIGUOUS
    1626                 :         115 :       && memory_access_type != VMAT_CONTIGUOUS_PERMUTE)
    1627                 :             :     {
    1628                 :             :       /* Element X of the data must come from iteration i * VF + X of the
    1629                 :             :          scalar loop.  We need more work to support other mappings.  */
    1630                 :           0 :       if (dump_enabled_p ())
    1631                 :           0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    1632                 :             :                          "can't operate on partial vectors because an"
    1633                 :             :                          " access isn't contiguous.\n");
    1634                 :           0 :       LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo) = false;
    1635                 :           0 :       return;
    1636                 :             :     }
    1637                 :             : 
    1638                 :         115 :   if (!VECTOR_MODE_P (vecmode))
    1639                 :             :     {
    1640                 :           0 :       if (dump_enabled_p ())
    1641                 :           0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    1642                 :             :                          "can't operate on partial vectors when emulating"
    1643                 :             :                          " vector operations.\n");
    1644                 :           0 :       LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo) = false;
    1645                 :           0 :       return;
    1646                 :             :     }
    1647                 :             : 
    1648                 :             :   /* We might load more scalars than we need for permuting SLP loads.
    1649                 :             :      We checked in get_group_load_store_type that the extra elements
    1650                 :             :      don't leak into a new vector.  */
    1651                 :         202 :   auto group_memory_nvectors = [](poly_uint64 size, poly_uint64 nunits)
    1652                 :             :   {
    1653                 :          87 :     unsigned int nvectors;
    1654                 :         174 :     if (can_div_away_from_zero_p (size, nunits, &nvectors))
    1655                 :          87 :       return nvectors;
    1656                 :             :     gcc_unreachable ();
    1657                 :             :   };
    1658                 :             : 
    1659                 :         115 :   poly_uint64 nunits = TYPE_VECTOR_SUBPARTS (vectype);
    1660                 :         115 :   poly_uint64 vf = LOOP_VINFO_VECT_FACTOR (loop_vinfo);
    1661                 :         115 :   machine_mode mask_mode;
    1662                 :         115 :   machine_mode vmode;
    1663                 :         115 :   bool using_partial_vectors_p = false;
    1664                 :         115 :   if (get_len_load_store_mode
    1665                 :         115 :       (vecmode, is_load, nullptr, elsvals).exists (&vmode))
    1666                 :             :     {
    1667                 :           0 :       nvectors = group_memory_nvectors (group_size * vf, nunits);
    1668                 :           0 :       unsigned factor = (vecmode == vmode) ? 1 : GET_MODE_UNIT_SIZE (vecmode);
    1669                 :           0 :       vect_record_loop_len (loop_vinfo, lens, nvectors, vectype, factor);
    1670                 :           0 :       using_partial_vectors_p = true;
    1671                 :             :     }
    1672                 :         202 :   else if (targetm.vectorize.get_mask_mode (vecmode).exists (&mask_mode)
    1673                 :         115 :            && can_vec_mask_load_store_p (vecmode, mask_mode, is_load, NULL,
    1674                 :             :                                          elsvals))
    1675                 :             :     {
    1676                 :          87 :       nvectors = group_memory_nvectors (group_size * vf, nunits);
    1677                 :          87 :       vect_record_loop_mask (loop_vinfo, masks, nvectors, vectype, scalar_mask);
    1678                 :          87 :       using_partial_vectors_p = true;
    1679                 :             :     }
    1680                 :             : 
    1681                 :          87 :   if (!using_partial_vectors_p)
    1682                 :             :     {
    1683                 :          28 :       if (dump_enabled_p ())
    1684                 :           3 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    1685                 :             :                          "can't operate on partial vectors because the"
    1686                 :             :                          " target doesn't have the appropriate partial"
    1687                 :             :                          " vectorization load or store.\n");
    1688                 :          28 :       LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo) = false;
    1689                 :             :     }
    1690                 :             : }
    1691                 :             : 
    1692                 :             : /* Return the mask input to a masked load or store.  VEC_MASK is the vectorized
    1693                 :             :    form of the scalar mask condition and LOOP_MASK, if nonnull, is the mask
    1694                 :             :    that needs to be applied to all loads and stores in a vectorized loop.
    1695                 :             :    Return VEC_MASK if LOOP_MASK is null or if VEC_MASK is already masked,
    1696                 :             :    otherwise return VEC_MASK & LOOP_MASK.
    1697                 :             : 
    1698                 :             :    MASK_TYPE is the type of both masks.  If new statements are needed,
    1699                 :             :    insert them before GSI.  */
    1700                 :             : 
    1701                 :             : tree
    1702                 :        1267 : prepare_vec_mask (loop_vec_info loop_vinfo, tree mask_type, tree loop_mask,
    1703                 :             :                   tree vec_mask, gimple_stmt_iterator *gsi)
    1704                 :             : {
    1705                 :        1267 :   gcc_assert (useless_type_conversion_p (mask_type, TREE_TYPE (vec_mask)));
    1706                 :        1267 :   if (!loop_mask)
    1707                 :             :     return vec_mask;
    1708                 :             : 
    1709                 :          36 :   gcc_assert (TREE_TYPE (loop_mask) == mask_type);
    1710                 :             : 
    1711                 :          36 :   if (loop_vinfo->vec_cond_masked_set.contains ({ vec_mask, loop_mask }))
    1712                 :             :     return vec_mask;
    1713                 :             : 
    1714                 :          36 :   tree and_res = make_temp_ssa_name (mask_type, NULL, "vec_mask_and");
    1715                 :          36 :   gimple *and_stmt = gimple_build_assign (and_res, BIT_AND_EXPR,
    1716                 :             :                                           vec_mask, loop_mask);
    1717                 :             : 
    1718                 :          36 :   gsi_insert_before (gsi, and_stmt, GSI_SAME_STMT);
    1719                 :          36 :   return and_res;
    1720                 :             : }
    1721                 :             : 
    1722                 :             : /* Determine whether we can use a gather load or scatter store to vectorize
    1723                 :             :    strided load or store STMT_INFO by truncating the current offset to a
    1724                 :             :    smaller width.  We need to be able to construct an offset vector:
    1725                 :             : 
    1726                 :             :      { 0, X, X*2, X*3, ... }
    1727                 :             : 
    1728                 :             :    without loss of precision, where X is STMT_INFO's DR_STEP.
    1729                 :             : 
    1730                 :             :    Return true if this is possible, describing the gather load or scatter
    1731                 :             :    store in GS_INFO.  MASKED_P is true if the load or store is conditional.
    1732                 :             : 
    1733                 :             :    If we can use gather/scatter and ELSVALS is nonzero the supported
    1734                 :             :    else values will be stored in the vector ELSVALS points to.  */
    1735                 :             : 
    1736                 :             : static bool
    1737                 :       63447 : vect_truncate_gather_scatter_offset (stmt_vec_info stmt_info,
    1738                 :             :                                      loop_vec_info loop_vinfo, bool masked_p,
    1739                 :             :                                      gather_scatter_info *gs_info,
    1740                 :             :                                      vec<int> *elsvals)
    1741                 :             : {
    1742                 :       63447 :   dr_vec_info *dr_info = STMT_VINFO_DR_INFO (stmt_info);
    1743                 :       63447 :   data_reference *dr = dr_info->dr;
    1744                 :       63447 :   tree step = DR_STEP (dr);
    1745                 :       63447 :   if (TREE_CODE (step) != INTEGER_CST)
    1746                 :             :     {
    1747                 :             :       /* ??? Perhaps we could use range information here?  */
    1748                 :       31938 :       if (dump_enabled_p ())
    1749                 :         443 :         dump_printf_loc (MSG_NOTE, vect_location,
    1750                 :             :                          "cannot truncate variable step.\n");
    1751                 :       31938 :       return false;
    1752                 :             :     }
    1753                 :             : 
    1754                 :             :   /* Get the number of bits in an element.  */
    1755                 :       31509 :   tree vectype = STMT_VINFO_VECTYPE (stmt_info);
    1756                 :       31509 :   scalar_mode element_mode = SCALAR_TYPE_MODE (TREE_TYPE (vectype));
    1757                 :       31509 :   unsigned int element_bits = GET_MODE_BITSIZE (element_mode);
    1758                 :             : 
    1759                 :             :   /* Set COUNT to the upper limit on the number of elements - 1.
    1760                 :             :      Start with the maximum vectorization factor.  */
    1761                 :       31509 :   unsigned HOST_WIDE_INT count = vect_max_vf (loop_vinfo) - 1;
    1762                 :             : 
    1763                 :             :   /* Try lowering COUNT to the number of scalar latch iterations.  */
    1764                 :       31509 :   class loop *loop = LOOP_VINFO_LOOP (loop_vinfo);
    1765                 :       31509 :   widest_int max_iters;
    1766                 :       31509 :   if (max_loop_iterations (loop, &max_iters)
    1767                 :       63018 :       && max_iters < count)
    1768                 :        2411 :     count = max_iters.to_shwi ();
    1769                 :             : 
    1770                 :             :   /* Try scales of 1 and the element size.  */
    1771                 :       31509 :   unsigned int scales[] = { 1, vect_get_scalar_dr_size (dr_info) };
    1772                 :       31509 :   wi::overflow_type overflow = wi::OVF_NONE;
    1773                 :       94527 :   for (int i = 0; i < 2; ++i)
    1774                 :             :     {
    1775                 :       63018 :       unsigned int scale = scales[i];
    1776                 :       63018 :       widest_int factor;
    1777                 :       63018 :       if (!wi::multiple_of_p (wi::to_widest (step), scale, SIGNED, &factor))
    1778                 :           0 :         continue;
    1779                 :             : 
    1780                 :             :       /* Determine the minimum precision of (COUNT - 1) * STEP / SCALE.  */
    1781                 :       63018 :       widest_int range = wi::mul (count, factor, SIGNED, &overflow);
    1782                 :       63018 :       if (overflow)
    1783                 :           0 :         continue;
    1784                 :       63018 :       signop sign = range >= 0 ? UNSIGNED : SIGNED;
    1785                 :       63018 :       unsigned int min_offset_bits = wi::min_precision (range, sign);
    1786                 :             : 
    1787                 :             :       /* Find the narrowest viable offset type.  */
    1788                 :       63018 :       unsigned int offset_bits = 1U << ceil_log2 (min_offset_bits);
    1789                 :       63018 :       tree offset_type = build_nonstandard_integer_type (offset_bits,
    1790                 :             :                                                          sign == UNSIGNED);
    1791                 :             : 
    1792                 :             :       /* See whether the target supports the operation with an offset
    1793                 :             :          no narrower than OFFSET_TYPE.  */
    1794                 :       63018 :       tree memory_type = TREE_TYPE (DR_REF (dr));
    1795                 :       63018 :       if (!vect_gather_scatter_fn_p (loop_vinfo, DR_IS_READ (dr), masked_p,
    1796                 :             :                                      vectype, memory_type, offset_type, scale,
    1797                 :             :                                      &gs_info->ifn, &gs_info->offset_vectype,
    1798                 :             :                                      elsvals)
    1799                 :       63018 :           || gs_info->ifn == IFN_LAST)
    1800                 :       63018 :         continue;
    1801                 :             : 
    1802                 :           0 :       gs_info->decl = NULL_TREE;
    1803                 :             :       /* Logically the sum of DR_BASE_ADDRESS, DR_INIT and DR_OFFSET,
    1804                 :             :          but we don't need to store that here.  */
    1805                 :           0 :       gs_info->base = NULL_TREE;
    1806                 :           0 :       gs_info->element_type = TREE_TYPE (vectype);
    1807                 :           0 :       gs_info->offset = fold_convert (offset_type, step);
    1808                 :           0 :       gs_info->offset_dt = vect_constant_def;
    1809                 :           0 :       gs_info->scale = scale;
    1810                 :           0 :       gs_info->memory_type = memory_type;
    1811                 :           0 :       return true;
    1812                 :      126036 :     }
    1813                 :             : 
    1814                 :       31509 :   if (overflow && dump_enabled_p ())
    1815                 :           0 :     dump_printf_loc (MSG_NOTE, vect_location,
    1816                 :             :                      "truncating gather/scatter offset to %d bits"
    1817                 :             :                      " might change its value.\n", element_bits);
    1818                 :             : 
    1819                 :             :   return false;
    1820                 :       31509 : }
    1821                 :             : 
    1822                 :             : /* Return true if we can use gather/scatter internal functions to
    1823                 :             :    vectorize STMT_INFO, which is a grouped or strided load or store.
    1824                 :             :    MASKED_P is true if load or store is conditional.  When returning
    1825                 :             :    true, fill in GS_INFO with the information required to perform the
    1826                 :             :    operation.
    1827                 :             : 
    1828                 :             :    If we can use gather/scatter and ELSVALS is nonzero the supported
    1829                 :             :    else values will be stored in the vector ELSVALS points to.  */
    1830                 :             : 
    1831                 :             : static bool
    1832                 :       63447 : vect_use_strided_gather_scatters_p (stmt_vec_info stmt_info,
    1833                 :             :                                     loop_vec_info loop_vinfo, bool masked_p,
    1834                 :             :                                     gather_scatter_info *gs_info,
    1835                 :             :                                     vec<int> *elsvals)
    1836                 :             : {
    1837                 :       63447 :   if (!vect_check_gather_scatter (stmt_info, loop_vinfo, gs_info, elsvals)
    1838                 :       63447 :       || gs_info->ifn == IFN_LAST)
    1839                 :       63447 :     return vect_truncate_gather_scatter_offset (stmt_info, loop_vinfo,
    1840                 :       63447 :                                                 masked_p, gs_info, elsvals);
    1841                 :             : 
    1842                 :           0 :   tree old_offset_type = TREE_TYPE (gs_info->offset);
    1843                 :           0 :   tree new_offset_type = TREE_TYPE (gs_info->offset_vectype);
    1844                 :             : 
    1845                 :           0 :   gcc_assert (TYPE_PRECISION (new_offset_type)
    1846                 :             :               >= TYPE_PRECISION (old_offset_type));
    1847                 :           0 :   gs_info->offset = fold_convert (new_offset_type, gs_info->offset);
    1848                 :             : 
    1849                 :           0 :   if (dump_enabled_p ())
    1850                 :           0 :     dump_printf_loc (MSG_NOTE, vect_location,
    1851                 :             :                      "using gather/scatter for strided/grouped access,"
    1852                 :             :                      " scale = %d\n", gs_info->scale);
    1853                 :             : 
    1854                 :             :   return true;
    1855                 :             : }
    1856                 :             : 
    1857                 :             : /* STMT_INFO is a non-strided load or store, meaning that it accesses
    1858                 :             :    elements with a known constant step.  Return -1 if that step
    1859                 :             :    is negative, 0 if it is zero, and 1 if it is greater than zero.  */
    1860                 :             : 
    1861                 :             : int
    1862                 :     2101936 : compare_step_with_zero (vec_info *vinfo, stmt_vec_info stmt_info)
    1863                 :             : {
    1864                 :     2101936 :   dr_vec_info *dr_info = STMT_VINFO_DR_INFO (stmt_info);
    1865                 :     2101936 :   return tree_int_cst_compare (vect_dr_behavior (vinfo, dr_info)->step,
    1866                 :     2101936 :                                size_zero_node);
    1867                 :             : }
    1868                 :             : 
    1869                 :             : /* If the target supports a permute mask that reverses the elements in
    1870                 :             :    a vector of type VECTYPE, return that mask, otherwise return null.  */
    1871                 :             : 
    1872                 :             : tree
    1873                 :       12257 : perm_mask_for_reverse (tree vectype)
    1874                 :             : {
    1875                 :       12257 :   poly_uint64 nunits = TYPE_VECTOR_SUBPARTS (vectype);
    1876                 :             : 
    1877                 :             :   /* The encoding has a single stepped pattern.  */
    1878                 :       12257 :   vec_perm_builder sel (nunits, 1, 3);
    1879                 :       49028 :   for (int i = 0; i < 3; ++i)
    1880                 :       36771 :     sel.quick_push (nunits - 1 - i);
    1881                 :             : 
    1882                 :       12257 :   vec_perm_indices indices (sel, 1, nunits);
    1883                 :       12257 :   if (!can_vec_perm_const_p (TYPE_MODE (vectype), TYPE_MODE (vectype),
    1884                 :             :                              indices))
    1885                 :             :     return NULL_TREE;
    1886                 :       11181 :   return vect_gen_perm_mask_checked (vectype, indices);
    1887                 :       12257 : }
    1888                 :             : 
    1889                 :             : /* A subroutine of get_load_store_type, with a subset of the same
    1890                 :             :    arguments.  Handle the case where STMT_INFO is a load or store that
    1891                 :             :    accesses consecutive elements with a negative step.  Sets *POFFSET
    1892                 :             :    to the offset to be applied to the DR for the first access.  */
    1893                 :             : 
    1894                 :             : static vect_memory_access_type
    1895                 :       13608 : get_negative_load_store_type (vec_info *vinfo,
    1896                 :             :                               stmt_vec_info stmt_info, tree vectype,
    1897                 :             :                               vec_load_store_type vls_type,
    1898                 :             :                               unsigned int ncopies, poly_int64 *poffset)
    1899                 :             : {
    1900                 :       13608 :   dr_vec_info *dr_info = STMT_VINFO_DR_INFO (stmt_info);
    1901                 :       13608 :   dr_alignment_support alignment_support_scheme;
    1902                 :             : 
    1903                 :       13608 :   if (ncopies > 1)
    1904                 :             :     {
    1905                 :           0 :       if (dump_enabled_p ())
    1906                 :           0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    1907                 :             :                          "multiple types with negative step.\n");
    1908                 :           0 :       return VMAT_ELEMENTWISE;
    1909                 :             :     }
    1910                 :             : 
    1911                 :             :   /* For backward running DRs the first access in vectype actually is
    1912                 :             :      N-1 elements before the address of the DR.  */
    1913                 :       13608 :   *poffset = ((-TYPE_VECTOR_SUBPARTS (vectype) + 1)
    1914                 :       13608 :               * TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (vectype))));
    1915                 :             : 
    1916                 :       13608 :   int misalignment = dr_misalignment (dr_info, vectype, *poffset);
    1917                 :       13608 :   alignment_support_scheme
    1918                 :       13608 :     = vect_supportable_dr_alignment (vinfo, dr_info, vectype, misalignment);
    1919                 :       13608 :   if (alignment_support_scheme != dr_aligned
    1920                 :       13608 :       && alignment_support_scheme != dr_unaligned_supported)
    1921                 :             :     {
    1922                 :        2802 :       if (dump_enabled_p ())
    1923                 :           4 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    1924                 :             :                          "negative step but alignment required.\n");
    1925                 :        2802 :       *poffset = 0;
    1926                 :        2802 :       return VMAT_ELEMENTWISE;
    1927                 :             :     }
    1928                 :             : 
    1929                 :       10806 :   if (vls_type == VLS_STORE_INVARIANT)
    1930                 :             :     {
    1931                 :        1092 :       if (dump_enabled_p ())
    1932                 :          52 :         dump_printf_loc (MSG_NOTE, vect_location,
    1933                 :             :                          "negative step with invariant source;"
    1934                 :             :                          " no permute needed.\n");
    1935                 :        1092 :       return VMAT_CONTIGUOUS_DOWN;
    1936                 :             :     }
    1937                 :             : 
    1938                 :        9714 :   if (!perm_mask_for_reverse (vectype))
    1939                 :             :     {
    1940                 :        1076 :       if (dump_enabled_p ())
    1941                 :          50 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    1942                 :             :                          "negative step and reversing not supported.\n");
    1943                 :        1076 :       *poffset = 0;
    1944                 :        1076 :       return VMAT_ELEMENTWISE;
    1945                 :             :     }
    1946                 :             : 
    1947                 :             :   return VMAT_CONTIGUOUS_REVERSE;
    1948                 :             : }
    1949                 :             : 
    1950                 :             : /* STMT_INFO is either a masked or unconditional store.  Return the value
    1951                 :             :    being stored.  */
    1952                 :             : 
    1953                 :             : tree
    1954                 :     5499003 : vect_get_store_rhs (stmt_vec_info stmt_info)
    1955                 :             : {
    1956                 :     5499003 :   if (gassign *assign = dyn_cast <gassign *> (stmt_info->stmt))
    1957                 :             :     {
    1958                 :     5497062 :       gcc_assert (gimple_assign_single_p (assign));
    1959                 :     5497062 :       return gimple_assign_rhs1 (assign);
    1960                 :             :     }
    1961                 :        1941 :   if (gcall *call = dyn_cast <gcall *> (stmt_info->stmt))
    1962                 :             :     {
    1963                 :        1941 :       internal_fn ifn = gimple_call_internal_fn (call);
    1964                 :        1941 :       int index = internal_fn_stored_value_index (ifn);
    1965                 :        1941 :       gcc_assert (index >= 0);
    1966                 :        1941 :       return gimple_call_arg (call, index);
    1967                 :             :     }
    1968                 :           0 :   gcc_unreachable ();
    1969                 :             : }
    1970                 :             : 
    1971                 :             : /* Function VECTOR_VECTOR_COMPOSITION_TYPE
    1972                 :             : 
    1973                 :             :    This function returns a vector type which can be composed with NETLS pieces,
    1974                 :             :    whose type is recorded in PTYPE.  VTYPE should be a vector type, and has the
    1975                 :             :    same vector size as the return vector.  It checks target whether supports
    1976                 :             :    pieces-size vector mode for construction firstly, if target fails to, check
    1977                 :             :    pieces-size scalar mode for construction further.  It returns NULL_TREE if
    1978                 :             :    fails to find the available composition.
    1979                 :             : 
    1980                 :             :    For example, for (vtype=V16QI, nelts=4), we can probably get:
    1981                 :             :      - V16QI with PTYPE V4QI.
    1982                 :             :      - V4SI with PTYPE SI.
    1983                 :             :      - NULL_TREE.  */
    1984                 :             : 
    1985                 :             : static tree
    1986                 :       11305 : vector_vector_composition_type (tree vtype, poly_uint64 nelts, tree *ptype)
    1987                 :             : {
    1988                 :       11305 :   gcc_assert (VECTOR_TYPE_P (vtype));
    1989                 :       11305 :   gcc_assert (known_gt (nelts, 0U));
    1990                 :             : 
    1991                 :       11305 :   machine_mode vmode = TYPE_MODE (vtype);
    1992                 :       11305 :   if (!VECTOR_MODE_P (vmode))
    1993                 :             :     return NULL_TREE;
    1994                 :             : 
    1995                 :             :   /* When we are asked to compose the vector from its components let
    1996                 :             :      that happen directly.  */
    1997                 :       11305 :   if (known_eq (TYPE_VECTOR_SUBPARTS (vtype), nelts))
    1998                 :             :     {
    1999                 :        5461 :       *ptype = TREE_TYPE (vtype);
    2000                 :        5461 :       return vtype;
    2001                 :             :     }
    2002                 :             : 
    2003                 :       11688 :   poly_uint64 vbsize = GET_MODE_BITSIZE (vmode);
    2004                 :        5844 :   unsigned int pbsize;
    2005                 :        5844 :   if (constant_multiple_p (vbsize, nelts, &pbsize))
    2006                 :             :     {
    2007                 :             :       /* First check if vec_init optab supports construction from
    2008                 :             :          vector pieces directly.  */
    2009                 :        5844 :       scalar_mode elmode = SCALAR_TYPE_MODE (TREE_TYPE (vtype));
    2010                 :       11688 :       poly_uint64 inelts = pbsize / GET_MODE_BITSIZE (elmode);
    2011                 :        5844 :       machine_mode rmode;
    2012                 :        5844 :       if (related_vector_mode (vmode, elmode, inelts).exists (&rmode)
    2013                 :        5272 :           && (convert_optab_handler (vec_init_optab, vmode, rmode)
    2014                 :             :               != CODE_FOR_nothing))
    2015                 :             :         {
    2016                 :        4301 :           *ptype = build_vector_type (TREE_TYPE (vtype), inelts);
    2017                 :        4301 :           return vtype;
    2018                 :             :         }
    2019                 :             : 
    2020                 :             :       /* Otherwise check if exists an integer type of the same piece size and
    2021                 :             :          if vec_init optab supports construction from it directly.  */
    2022                 :        1543 :       if (int_mode_for_size (pbsize, 0).exists (&elmode)
    2023                 :        1543 :           && related_vector_mode (vmode, elmode, nelts).exists (&rmode)
    2024                 :        1465 :           && (convert_optab_handler (vec_init_optab, rmode, elmode)
    2025                 :             :               != CODE_FOR_nothing))
    2026                 :             :         {
    2027                 :        1465 :           *ptype = build_nonstandard_integer_type (pbsize, 1);
    2028                 :        1465 :           return build_vector_type (*ptype, nelts);
    2029                 :             :         }
    2030                 :             :     }
    2031                 :             : 
    2032                 :             :   return NULL_TREE;
    2033                 :             : }
    2034                 :             : 
    2035                 :             : /* A subroutine of get_load_store_type, with a subset of the same
    2036                 :             :    arguments.  Handle the case where STMT_INFO is part of a grouped load
    2037                 :             :    or store.
    2038                 :             : 
    2039                 :             :    For stores, the statements in the group are all consecutive
    2040                 :             :    and there is no gap at the end.  For loads, the statements in the
    2041                 :             :    group might not be consecutive; there can be gaps between statements
    2042                 :             :    as well as at the end.
    2043                 :             : 
    2044                 :             :    If we can use gather/scatter and ELSVALS is nonzero the supported
    2045                 :             :    else values will be stored in the vector ELSVALS points to.
    2046                 :             : */
    2047                 :             : 
    2048                 :             : static bool
    2049                 :     2043349 : get_group_load_store_type (vec_info *vinfo, stmt_vec_info stmt_info,
    2050                 :             :                            tree vectype, slp_tree slp_node,
    2051                 :             :                            bool masked_p, vec_load_store_type vls_type,
    2052                 :             :                            vect_memory_access_type *memory_access_type,
    2053                 :             :                            poly_int64 *poffset,
    2054                 :             :                            dr_alignment_support *alignment_support_scheme,
    2055                 :             :                            int *misalignment,
    2056                 :             :                            gather_scatter_info *gs_info,
    2057                 :             :                            internal_fn *lanes_ifn,
    2058                 :             :                            vec<int> *elsvals)
    2059                 :             : {
    2060                 :     2043349 :   loop_vec_info loop_vinfo = dyn_cast <loop_vec_info> (vinfo);
    2061                 :      615858 :   class loop *loop = loop_vinfo ? LOOP_VINFO_LOOP (loop_vinfo) : NULL;
    2062                 :     2043349 :   stmt_vec_info first_stmt_info;
    2063                 :     2043349 :   unsigned int group_size;
    2064                 :     2043349 :   unsigned HOST_WIDE_INT gap;
    2065                 :     2043349 :   bool single_element_p;
    2066                 :     2043349 :   poly_int64 neg_ldst_offset = 0;
    2067                 :     2043349 :   if (STMT_VINFO_GROUPED_ACCESS (stmt_info))
    2068                 :             :     {
    2069                 :     1529886 :       first_stmt_info = DR_GROUP_FIRST_ELEMENT (stmt_info);
    2070                 :     1529886 :       group_size = DR_GROUP_SIZE (first_stmt_info);
    2071                 :     1529886 :       gap = DR_GROUP_GAP (first_stmt_info);
    2072                 :     1529886 :       single_element_p = (stmt_info == first_stmt_info
    2073                 :     1529886 :                           && !DR_GROUP_NEXT_ELEMENT (stmt_info));
    2074                 :             :     }
    2075                 :             :   else
    2076                 :             :     {
    2077                 :             :       first_stmt_info = stmt_info;
    2078                 :             :       group_size = 1;
    2079                 :             :       gap = 0;
    2080                 :             :       single_element_p = true;
    2081                 :             :     }
    2082                 :     2043349 :   dr_vec_info *first_dr_info = STMT_VINFO_DR_INFO (first_stmt_info);
    2083                 :     2043349 :   poly_uint64 nunits = TYPE_VECTOR_SUBPARTS (vectype);
    2084                 :             : 
    2085                 :             :   /* True if the vectorized statements would access beyond the last
    2086                 :             :      statement in the group.  */
    2087                 :     2043349 :   bool overrun_p = false;
    2088                 :             : 
    2089                 :             :   /* True if we can cope with such overrun by peeling for gaps, so that
    2090                 :             :      there is at least one final scalar iteration after the vector loop.  */
    2091                 :     4086698 :   bool can_overrun_p = (!masked_p
    2092                 :     2043349 :                         && vls_type == VLS_LOAD
    2093                 :      651070 :                         && loop_vinfo
    2094                 :     2470196 :                         && !loop->inner);
    2095                 :             : 
    2096                 :             :   /* There can only be a gap at the end of the group if the stride is
    2097                 :             :      known at compile time.  */
    2098                 :     2043349 :   gcc_assert (!STMT_VINFO_STRIDED_P (first_stmt_info) || gap == 0);
    2099                 :             : 
    2100                 :             :   /* For SLP vectorization we directly vectorize a subchain
    2101                 :             :      without permutation.  */
    2102                 :     2043349 :   if (! SLP_TREE_LOAD_PERMUTATION (slp_node).exists ())
    2103                 :     1962418 :     first_dr_info = STMT_VINFO_DR_INFO (SLP_TREE_SCALAR_STMTS (slp_node)[0]);
    2104                 :     2043349 :   if (STMT_VINFO_STRIDED_P (first_stmt_info))
    2105                 :             :     /* Try to use consecutive accesses of as many elements as possible,
    2106                 :             :        separated by the stride, until we have a complete vector.
    2107                 :             :        Fall back to scalar accesses if that isn't possible.  */
    2108                 :       52519 :     *memory_access_type = VMAT_STRIDED_SLP;
    2109                 :             :   else
    2110                 :             :     {
    2111                 :     1990830 :       int cmp = compare_step_with_zero (vinfo, stmt_info);
    2112                 :     1990830 :       if (cmp < 0)
    2113                 :             :         {
    2114                 :       13860 :           if (single_element_p)
    2115                 :             :             /* ???  The VMAT_CONTIGUOUS_REVERSE code generation is
    2116                 :             :                only correct for single element "interleaving" SLP.  */
    2117                 :       13608 :             *memory_access_type = get_negative_load_store_type
    2118                 :       13608 :                 (vinfo, stmt_info, vectype, vls_type, 1,
    2119                 :             :                  &neg_ldst_offset);
    2120                 :             :           else
    2121                 :             :             {
    2122                 :             :               /* Try to use consecutive accesses of DR_GROUP_SIZE elements,
    2123                 :             :                  separated by the stride, until we have a complete vector.
    2124                 :             :                  Fall back to scalar accesses if that isn't possible.  */
    2125                 :         252 :               if (multiple_p (nunits, group_size))
    2126                 :         222 :                 *memory_access_type = VMAT_STRIDED_SLP;
    2127                 :             :               else
    2128                 :          30 :                 *memory_access_type = VMAT_ELEMENTWISE;
    2129                 :             :             }
    2130                 :             :         }
    2131                 :     1976970 :       else if (cmp == 0 && loop_vinfo)
    2132                 :             :         {
    2133                 :        4796 :           gcc_assert (vls_type == VLS_LOAD);
    2134                 :        4796 :           *memory_access_type = VMAT_INVARIANT;
    2135                 :             :         }
    2136                 :             :       /* Try using LOAD/STORE_LANES.  */
    2137                 :     1972174 :       else if (slp_node->ldst_lanes
    2138                 :     1972174 :                && (*lanes_ifn
    2139                 :           0 :                    = (vls_type == VLS_LOAD
    2140                 :           0 :                       ? vect_load_lanes_supported (vectype, group_size,
    2141                 :             :                                                    masked_p, elsvals)
    2142                 :           0 :                       : vect_store_lanes_supported (vectype, group_size,
    2143                 :             :                                                     masked_p))) != IFN_LAST)
    2144                 :           0 :         *memory_access_type = VMAT_LOAD_STORE_LANES;
    2145                 :     1972174 :       else if (!loop_vinfo && slp_node->avoid_stlf_fail)
    2146                 :             :         {
    2147                 :          74 :           *memory_access_type = VMAT_ELEMENTWISE;
    2148                 :          74 :           if (dump_enabled_p ())
    2149                 :           2 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2150                 :             :                              "using element-wise load to avoid disrupting "
    2151                 :             :                              "cross iteration store-to-load forwarding\n");
    2152                 :             :         }
    2153                 :             :       else
    2154                 :     1972100 :         *memory_access_type = VMAT_CONTIGUOUS;
    2155                 :             : 
    2156                 :             :       /* If this is single-element interleaving with an element
    2157                 :             :          distance that leaves unused vector loads around fall back
    2158                 :             :          to elementwise access if possible - we otherwise least
    2159                 :             :          create very sub-optimal code in that case (and
    2160                 :             :          blow up memory, see PR65518).  */
    2161                 :     1990830 :       if (loop_vinfo
    2162                 :     1990830 :           && single_element_p
    2163                 :      498073 :           && (*memory_access_type == VMAT_CONTIGUOUS
    2164                 :       18404 :               || *memory_access_type == VMAT_CONTIGUOUS_REVERSE)
    2165                 :     2488903 :           && maybe_gt (group_size, TYPE_VECTOR_SUBPARTS (vectype)))
    2166                 :             :         {
    2167                 :       14374 :           if (SLP_TREE_LANES (slp_node) == 1)
    2168                 :             :             {
    2169                 :       14354 :               *memory_access_type = VMAT_ELEMENTWISE;
    2170                 :       14354 :               if (dump_enabled_p ())
    2171                 :         309 :                 dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2172                 :             :                                  "single-element interleaving not supported "
    2173                 :             :                                  "for not adjacent vector loads, using "
    2174                 :             :                                  "elementwise access\n");
    2175                 :             :             }
    2176                 :             :           else
    2177                 :             :             {
    2178                 :          20 :               if (dump_enabled_p ())
    2179                 :          10 :                 dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2180                 :             :                                  "single-element interleaving not supported "
    2181                 :             :                                  "for not adjacent vector loads\n");
    2182                 :          32 :               return false;
    2183                 :             :             }
    2184                 :             :         }
    2185                 :             : 
    2186                 :             :       /* For single-element interleaving also fall back to elementwise
    2187                 :             :          access in case we did not lower a permutation and cannot
    2188                 :             :          code generate it.  */
    2189                 :     1990810 :       auto_vec<tree> temv;
    2190                 :     1990810 :       unsigned n_perms;
    2191                 :     1990810 :       if (loop_vinfo
    2192                 :             :           && single_element_p
    2193                 :      498053 :           && SLP_TREE_LANES (slp_node) == 1
    2194                 :      491771 :           && (*memory_access_type == VMAT_CONTIGUOUS
    2195                 :       31845 :               || *memory_access_type == VMAT_CONTIGUOUS_REVERSE)
    2196                 :      468332 :           && SLP_TREE_LOAD_PERMUTATION (slp_node).exists ()
    2197                 :     1999143 :           && !vect_transform_slp_perm_load
    2198                 :        8333 :           (loop_vinfo, slp_node, temv, NULL,
    2199                 :             :            LOOP_VINFO_VECT_FACTOR (loop_vinfo), true, &n_perms))
    2200                 :             :         {
    2201                 :        1441 :           *memory_access_type = VMAT_ELEMENTWISE;
    2202                 :        1441 :           if (dump_enabled_p ())
    2203                 :         100 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2204                 :             :                              "single-element interleaving permutation not "
    2205                 :             :                              "supported, using elementwise access\n");
    2206                 :             :         }
    2207                 :             : 
    2208                 :      563319 :       overrun_p = (loop_vinfo && gap != 0
    2209                 :     2032942 :                    && *memory_access_type != VMAT_ELEMENTWISE);
    2210                 :     1990810 :       if (overrun_p && vls_type != VLS_LOAD)
    2211                 :             :         {
    2212                 :           0 :           dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2213                 :             :                            "Grouped store with gaps requires"
    2214                 :             :                            " non-consecutive accesses\n");
    2215                 :           0 :           return false;
    2216                 :             :         }
    2217                 :             : 
    2218                 :     1990810 :       unsigned HOST_WIDE_INT dr_size = vect_get_scalar_dr_size (first_dr_info);
    2219                 :     1990810 :       poly_int64 off = 0;
    2220                 :     1990810 :       if (*memory_access_type == VMAT_CONTIGUOUS_REVERSE)
    2221                 :        8438 :         off = (TYPE_VECTOR_SUBPARTS (vectype) - 1) * -dr_size;
    2222                 :             : 
    2223                 :             :       /* An overrun is fine if the trailing elements are smaller
    2224                 :             :          than the alignment boundary B.  Every vector access will
    2225                 :             :          be a multiple of B and so we are guaranteed to access a
    2226                 :             :          non-gap element in the same B-sized block.  */
    2227                 :     1990810 :       if (overrun_p
    2228                 :     1990810 :           && gap < (vect_known_alignment_in_bytes (first_dr_info,
    2229                 :       25936 :                                                    vectype, off) / dr_size))
    2230                 :             :         overrun_p = false;
    2231                 :             : 
    2232                 :             :       /* When we have a contiguous access across loop iterations
    2233                 :             :          but the access in the loop doesn't cover the full vector
    2234                 :             :          we can end up with no gap recorded but still excess
    2235                 :             :          elements accessed, see PR103116.  Make sure we peel for
    2236                 :             :          gaps if necessary and sufficient and give up if not.
    2237                 :             : 
    2238                 :             :          If there is a combination of the access not covering the full
    2239                 :             :          vector and a gap recorded then we may need to peel twice.  */
    2240                 :     1990810 :       bool large_vector_overrun_p = false;
    2241                 :     1990810 :       if (loop_vinfo
    2242                 :      563319 :           && (*memory_access_type == VMAT_CONTIGUOUS
    2243                 :       34251 :               || *memory_access_type == VMAT_CONTIGUOUS_REVERSE)
    2244                 :      537506 :           && SLP_TREE_LOAD_PERMUTATION (slp_node).exists ()
    2245                 :     2019251 :           && !multiple_p (group_size * LOOP_VINFO_VECT_FACTOR (loop_vinfo),
    2246                 :             :                           nunits))
    2247                 :             :         large_vector_overrun_p = overrun_p = true;
    2248                 :             : 
    2249                 :             :       /* If the gap splits the vector in half and the target
    2250                 :             :          can do half-vector operations avoid the epilogue peeling
    2251                 :             :          by simply loading half of the vector only.  Usually
    2252                 :             :          the construction with an upper zero half will be elided.  */
    2253                 :     1990810 :       dr_alignment_support alss;
    2254                 :     1990810 :       int misalign = dr_misalignment (first_dr_info, vectype, off);
    2255                 :     1990810 :       tree half_vtype;
    2256                 :     1990810 :       poly_uint64 remain;
    2257                 :     1990810 :       unsigned HOST_WIDE_INT tem, num;
    2258                 :     1990810 :       if (overrun_p
    2259                 :     1990810 :           && !masked_p
    2260                 :       20214 :           && *memory_access_type != VMAT_LOAD_STORE_LANES
    2261                 :       20214 :           && (((alss = vect_supportable_dr_alignment (vinfo, first_dr_info,
    2262                 :             :                                                       vectype, misalign)))
    2263                 :             :               == dr_aligned
    2264                 :       16310 :               || alss == dr_unaligned_supported)
    2265                 :       12955 :           && can_div_trunc_p (group_size
    2266                 :       12955 :                               * LOOP_VINFO_VECT_FACTOR (loop_vinfo) - gap,
    2267                 :             :                               nunits, &tem, &remain)
    2268                 :     2003765 :           && (known_eq (remain, 0u)
    2269                 :        8957 :               || (known_ne (remain, 0u)
    2270                 :        6596 :                   && constant_multiple_p (nunits, remain, &num)
    2271                 :     1986812 :                   && (vector_vector_composition_type (vectype, num, &half_vtype)
    2272                 :             :                       != NULL_TREE))))
    2273                 :       10594 :         overrun_p = false;
    2274                 :             : 
    2275                 :     1990810 :       if (overrun_p && !can_overrun_p)
    2276                 :             :         {
    2277                 :           6 :           if (dump_enabled_p ())
    2278                 :           6 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2279                 :             :                              "Peeling for outer loop is not supported\n");
    2280                 :           6 :           return false;
    2281                 :             :         }
    2282                 :             : 
    2283                 :             :       /* Peeling for gaps assumes that a single scalar iteration
    2284                 :             :          is enough to make sure the last vector iteration doesn't
    2285                 :             :          access excess elements.  */
    2286                 :     1990804 :       if (overrun_p
    2287                 :     1990804 :           && (!can_div_trunc_p (group_size
    2288                 :        9614 :                                 * LOOP_VINFO_VECT_FACTOR (loop_vinfo) - gap,
    2289                 :             :                                 nunits, &tem, &remain)
    2290                 :        9614 :               || maybe_lt (remain + group_size, nunits)))
    2291                 :             :         {
    2292                 :             :           /* But peeling a single scalar iteration is enough if
    2293                 :             :              we can use the next power-of-two sized partial
    2294                 :             :              access and that is sufficiently small to be covered
    2295                 :             :              by the single scalar iteration.  */
    2296                 :          37 :           unsigned HOST_WIDE_INT cnunits, cvf, cremain, cpart_size;
    2297                 :          37 :           if (masked_p
    2298                 :          37 :               || !nunits.is_constant (&cnunits)
    2299                 :          37 :               || !LOOP_VINFO_VECT_FACTOR (loop_vinfo).is_constant (&cvf)
    2300                 :          37 :               || (((cremain = (group_size * cvf - gap) % cnunits), true)
    2301                 :          37 :                   && ((cpart_size = (1 << ceil_log2 (cremain))), true)
    2302                 :          37 :                   && (cremain + group_size < cpart_size
    2303                 :          31 :                       || (vector_vector_composition_type (vectype,
    2304                 :          31 :                                                          cnunits / cpart_size,
    2305                 :             :                                                          &half_vtype)
    2306                 :             :                           == NULL_TREE))))
    2307                 :             :             {
    2308                 :             :               /* If all fails we can still resort to niter masking unless
    2309                 :             :                  the vectors used are too big, so enforce the use of
    2310                 :             :                  partial vectors.  */
    2311                 :           6 :               if (LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo)
    2312                 :           0 :                   && !large_vector_overrun_p)
    2313                 :             :                 {
    2314                 :           0 :                   if (dump_enabled_p ())
    2315                 :           0 :                     dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2316                 :             :                                      "peeling for gaps insufficient for "
    2317                 :             :                                      "access unless using partial "
    2318                 :             :                                      "vectors\n");
    2319                 :           0 :                   LOOP_VINFO_MUST_USE_PARTIAL_VECTORS_P (loop_vinfo) = true;
    2320                 :             :                 }
    2321                 :             :               else
    2322                 :             :                 {
    2323                 :           6 :                   if (dump_enabled_p ())
    2324                 :           6 :                     dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2325                 :             :                                      "peeling for gaps insufficient for "
    2326                 :             :                                      "access\n");
    2327                 :           6 :                   return false;
    2328                 :             :                 }
    2329                 :             :             }
    2330                 :          31 :           else if (large_vector_overrun_p)
    2331                 :             :             {
    2332                 :          31 :               if (dump_enabled_p ())
    2333                 :          28 :                 dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2334                 :             :                                  "can't operate on partial vectors because "
    2335                 :             :                                  "only unmasked loads handle access "
    2336                 :             :                                  "shortening required because of gaps at "
    2337                 :             :                                  "the end of the access\n");
    2338                 :          31 :               LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo) = false;
    2339                 :             :             }
    2340                 :             :         }
    2341                 :     1990810 :     }
    2342                 :             : 
    2343                 :             :   /* As a last resort, trying using a gather load or scatter store.
    2344                 :             : 
    2345                 :             :      ??? Although the code can handle all group sizes correctly,
    2346                 :             :      it probably isn't a win to use separate strided accesses based
    2347                 :             :      on nearby locations.  Or, even if it's a win over scalar code,
    2348                 :             :      it might not be a win over vectorizing at a lower VF, if that
    2349                 :             :      allows us to use contiguous accesses.  */
    2350                 :     2043317 :   if ((*memory_access_type == VMAT_ELEMENTWISE
    2351                 :     2043317 :        || *memory_access_type == VMAT_STRIDED_SLP)
    2352                 :       72518 :       && single_element_p
    2353                 :       63634 :       && SLP_TREE_LANES (slp_node) == 1
    2354                 :       63447 :       && loop_vinfo
    2355                 :     2106764 :       && vect_use_strided_gather_scatters_p (stmt_info, loop_vinfo,
    2356                 :             :                                              masked_p, gs_info, elsvals))
    2357                 :           0 :     *memory_access_type = VMAT_GATHER_SCATTER;
    2358                 :             : 
    2359                 :     2043317 :   if (*memory_access_type == VMAT_CONTIGUOUS_DOWN
    2360                 :     2042225 :       || *memory_access_type == VMAT_CONTIGUOUS_REVERSE)
    2361                 :        9526 :     *poffset = neg_ldst_offset;
    2362                 :             : 
    2363                 :     2043317 :   if (*memory_access_type == VMAT_GATHER_SCATTER
    2364                 :     2043317 :       || *memory_access_type == VMAT_ELEMENTWISE
    2365                 :     2023540 :       || *memory_access_type == VMAT_STRIDED_SLP
    2366                 :     1970799 :       || *memory_access_type == VMAT_INVARIANT)
    2367                 :             :     {
    2368                 :       77314 :       *alignment_support_scheme = dr_unaligned_supported;
    2369                 :       77314 :       *misalignment = DR_MISALIGNMENT_UNKNOWN;
    2370                 :             :     }
    2371                 :             :   else
    2372                 :             :     {
    2373                 :     1966003 :       *misalignment = dr_misalignment (first_dr_info, vectype, *poffset);
    2374                 :     1966003 :       *alignment_support_scheme
    2375                 :     1966003 :         = vect_supportable_dr_alignment (vinfo, first_dr_info, vectype,
    2376                 :             :                                          *misalignment);
    2377                 :             :     }
    2378                 :             : 
    2379                 :     2043317 :   if (vls_type != VLS_LOAD && first_stmt_info == stmt_info)
    2380                 :             :     {
    2381                 :             :       /* STMT is the leader of the group. Check the operands of all the
    2382                 :             :          stmts of the group.  */
    2383                 :     1390748 :       stmt_vec_info next_stmt_info = DR_GROUP_NEXT_ELEMENT (stmt_info);
    2384                 :     3473037 :       while (next_stmt_info)
    2385                 :             :         {
    2386                 :     2082289 :           tree op = vect_get_store_rhs (next_stmt_info);
    2387                 :     2082289 :           enum vect_def_type dt;
    2388                 :     2082289 :           if (!vect_is_simple_use (op, vinfo, &dt))
    2389                 :             :             {
    2390                 :           0 :               if (dump_enabled_p ())
    2391                 :           0 :                 dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2392                 :             :                                  "use not simple.\n");
    2393                 :           0 :               return false;
    2394                 :             :             }
    2395                 :     2082289 :           next_stmt_info = DR_GROUP_NEXT_ELEMENT (next_stmt_info);
    2396                 :             :         }
    2397                 :             :     }
    2398                 :             : 
    2399                 :     2043317 :   if (overrun_p)
    2400                 :             :     {
    2401                 :        9608 :       gcc_assert (can_overrun_p);
    2402                 :        9608 :       if (dump_enabled_p ())
    2403                 :         913 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2404                 :             :                          "Data access with gaps requires scalar "
    2405                 :             :                          "epilogue loop\n");
    2406                 :        9608 :       LOOP_VINFO_PEELING_FOR_GAPS (loop_vinfo) = true;
    2407                 :             :     }
    2408                 :             : 
    2409                 :             :   return true;
    2410                 :             : }
    2411                 :             : 
    2412                 :             : /* Analyze load or store statement STMT_INFO of type VLS_TYPE.  Return true
    2413                 :             :    if there is a memory access type that the vectorized form can use,
    2414                 :             :    storing it in *MEMORY_ACCESS_TYPE if so.  If we decide to use gathers
    2415                 :             :    or scatters, fill in GS_INFO accordingly.  In addition
    2416                 :             :    *ALIGNMENT_SUPPORT_SCHEME is filled out and false is returned if
    2417                 :             :    the target does not support the alignment scheme.  *MISALIGNMENT
    2418                 :             :    is set according to the alignment of the access (including
    2419                 :             :    DR_MISALIGNMENT_UNKNOWN when it is unknown).
    2420                 :             : 
    2421                 :             :    SLP says whether we're performing SLP rather than loop vectorization.
    2422                 :             :    MASKED_P is true if the statement is conditional on a vectorized mask.
    2423                 :             :    VECTYPE is the vector type that the vectorized statements will use.
    2424                 :             :    NCOPIES is the number of vector statements that will be needed.
    2425                 :             : 
    2426                 :             :    If ELSVALS is nonzero the supported else values will be stored in the
    2427                 :             :    vector ELSVALS points to.  */
    2428                 :             : 
    2429                 :             : static bool
    2430                 :     2052276 : get_load_store_type (vec_info  *vinfo, stmt_vec_info stmt_info,
    2431                 :             :                      tree vectype, slp_tree slp_node,
    2432                 :             :                      bool masked_p, vec_load_store_type vls_type,
    2433                 :             :                      unsigned int,
    2434                 :             :                      vect_memory_access_type *memory_access_type,
    2435                 :             :                      poly_int64 *poffset,
    2436                 :             :                      dr_alignment_support *alignment_support_scheme,
    2437                 :             :                      int *misalignment,
    2438                 :             :                      gather_scatter_info *gs_info,
    2439                 :             :                      internal_fn *lanes_ifn,
    2440                 :             :                      vec<int> *elsvals = nullptr)
    2441                 :             : {
    2442                 :     2052276 :   loop_vec_info loop_vinfo = dyn_cast <loop_vec_info> (vinfo);
    2443                 :     2052276 :   poly_uint64 nunits = TYPE_VECTOR_SUBPARTS (vectype);
    2444                 :     2052276 :   *misalignment = DR_MISALIGNMENT_UNKNOWN;
    2445                 :     2052276 :   *poffset = 0;
    2446                 :     2052276 :   if (STMT_VINFO_GATHER_SCATTER_P (stmt_info))
    2447                 :             :     {
    2448                 :        8927 :       *memory_access_type = VMAT_GATHER_SCATTER;
    2449                 :        8927 :       if (!vect_check_gather_scatter (stmt_info, loop_vinfo, gs_info,
    2450                 :             :                                       elsvals))
    2451                 :           0 :         gcc_unreachable ();
    2452                 :             :       /* When using internal functions, we rely on pattern recognition
    2453                 :             :          to convert the type of the offset to the type that the target
    2454                 :             :          requires, with the result being a call to an internal function.
    2455                 :             :          If that failed for some reason (e.g. because another pattern
    2456                 :             :          took priority), just handle cases in which the offset already
    2457                 :             :          has the right type.  */
    2458                 :        8927 :       else if (gs_info->ifn != IFN_LAST
    2459                 :           0 :                && !is_gimple_call (stmt_info->stmt)
    2460                 :        8927 :                && !tree_nop_conversion_p (TREE_TYPE (gs_info->offset),
    2461                 :           0 :                                           TREE_TYPE (gs_info->offset_vectype)))
    2462                 :             :         {
    2463                 :           0 :           if (dump_enabled_p ())
    2464                 :           0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2465                 :             :                              "%s offset requires a conversion\n",
    2466                 :             :                              vls_type == VLS_LOAD ? "gather" : "scatter");
    2467                 :           0 :           return false;
    2468                 :             :         }
    2469                 :        8927 :       else if (!vect_is_simple_use (gs_info->offset, vinfo,
    2470                 :             :                                     &gs_info->offset_dt,
    2471                 :             :                                     &gs_info->offset_vectype))
    2472                 :             :         {
    2473                 :           0 :           if (dump_enabled_p ())
    2474                 :           0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2475                 :             :                              "%s index use not simple.\n",
    2476                 :             :                              vls_type == VLS_LOAD ? "gather" : "scatter");
    2477                 :           0 :           return false;
    2478                 :             :         }
    2479                 :        8927 :       else if (gs_info->ifn == IFN_LAST && !gs_info->decl)
    2480                 :             :         {
    2481                 :        8135 :           if (!TYPE_VECTOR_SUBPARTS (vectype).is_constant ()
    2482                 :        8135 :               || !TYPE_VECTOR_SUBPARTS (gs_info->offset_vectype).is_constant ()
    2483                 :        8135 :               || VECTOR_BOOLEAN_TYPE_P (gs_info->offset_vectype)
    2484                 :        8135 :               || !constant_multiple_p (TYPE_VECTOR_SUBPARTS
    2485                 :        8135 :                                          (gs_info->offset_vectype),
    2486                 :       13960 :                                        TYPE_VECTOR_SUBPARTS (vectype)))
    2487                 :             :             {
    2488                 :        2310 :               if (dump_enabled_p ())
    2489                 :         440 :                 dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2490                 :             :                                  "unsupported vector types for emulated "
    2491                 :             :                                  "gather.\n");
    2492                 :        2310 :               return false;
    2493                 :             :             }
    2494                 :             :         }
    2495                 :             :       /* Gather-scatter accesses perform only component accesses, alignment
    2496                 :             :          is irrelevant for them.  */
    2497                 :        6617 :       *alignment_support_scheme = dr_unaligned_supported;
    2498                 :             :     }
    2499                 :     2043349 :   else if (!get_group_load_store_type (vinfo, stmt_info, vectype, slp_node,
    2500                 :             :                                        masked_p,
    2501                 :             :                                        vls_type, memory_access_type, poffset,
    2502                 :             :                                        alignment_support_scheme,
    2503                 :             :                                        misalignment, gs_info, lanes_ifn,
    2504                 :             :                                        elsvals))
    2505                 :             :     return false;
    2506                 :             : 
    2507                 :     2049934 :   if ((*memory_access_type == VMAT_ELEMENTWISE
    2508                 :     2049934 :        || *memory_access_type == VMAT_STRIDED_SLP)
    2509                 :             :       && !nunits.is_constant ())
    2510                 :             :     {
    2511                 :             :       if (dump_enabled_p ())
    2512                 :             :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2513                 :             :                          "Not using elementwise accesses due to variable "
    2514                 :             :                          "vectorization factor.\n");
    2515                 :             :       return false;
    2516                 :             :     }
    2517                 :             : 
    2518                 :             : 
    2519                 :             :   /* Checks if all scalar iterations are known to be inbounds.  */
    2520                 :     2049934 :   bool inbounds = DR_SCALAR_KNOWN_BOUNDS (STMT_VINFO_DR_INFO (stmt_info));
    2521                 :             : 
    2522                 :             :   /* Check if we support the operation if early breaks are needed.  Here we
    2523                 :             :      must ensure that we don't access any more than the scalar code would
    2524                 :             :      have.  A masked operation would ensure this, so for these load types
    2525                 :             :      force masking.  */
    2526                 :     2049934 :   if (loop_vinfo
    2527                 :      622443 :       && dr_safe_speculative_read_required (stmt_info)
    2528                 :      172398 :       && LOOP_VINFO_EARLY_BREAKS (loop_vinfo)
    2529                 :     2049934 :       && (*memory_access_type == VMAT_GATHER_SCATTER
    2530                 :      172398 :           || *memory_access_type == VMAT_STRIDED_SLP))
    2531                 :             :     {
    2532                 :        6102 :       if (dump_enabled_p ())
    2533                 :           8 :           dump_printf_loc (MSG_NOTE, vect_location,
    2534                 :             :                            "early break not supported: cannot peel for "
    2535                 :             :                            "alignment. With non-contiguous memory vectorization"
    2536                 :             :                            " could read out of bounds at %G ",
    2537                 :             :                            STMT_VINFO_STMT (stmt_info));
    2538                 :        6102 :         if (inbounds)
    2539                 :           0 :           LOOP_VINFO_MUST_USE_PARTIAL_VECTORS_P (loop_vinfo) = true;
    2540                 :             :         else
    2541                 :             :           return false;
    2542                 :             :     }
    2543                 :             : 
    2544                 :             :   /* If this DR needs alignment for correctness, we must ensure the target
    2545                 :             :      alignment is a constant power-of-two multiple of the amount read per
    2546                 :             :      vector iteration or force masking.  */
    2547                 :     2043832 :   if (dr_safe_speculative_read_required (stmt_info)
    2548                 :     2043832 :       && *alignment_support_scheme == dr_aligned)
    2549                 :             :     {
    2550                 :             :       /* We can only peel for loops, of course.  */
    2551                 :       98439 :       gcc_checking_assert (loop_vinfo);
    2552                 :             : 
    2553                 :       98439 :       auto target_alignment
    2554                 :       98439 :         = DR_TARGET_ALIGNMENT (STMT_VINFO_DR_INFO (stmt_info));
    2555                 :       98439 :       unsigned HOST_WIDE_INT target_align;
    2556                 :             : 
    2557                 :       98439 :       bool group_aligned = false;
    2558                 :       98439 :       if (target_alignment.is_constant (&target_align)
    2559                 :             :           && nunits.is_constant ())
    2560                 :             :         {
    2561                 :       98439 :           poly_uint64 vf = LOOP_VINFO_VECT_FACTOR (loop_vinfo);
    2562                 :       98439 :           auto vectype_size
    2563                 :       98439 :             = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (vectype)));
    2564                 :       98439 :           poly_uint64 required_alignment = vf * vectype_size;
    2565                 :             :           /* If we have a grouped access we require that the alignment be N * elem.  */
    2566                 :       98439 :           if (STMT_VINFO_GROUPED_ACCESS (stmt_info))
    2567                 :        4324 :             required_alignment *=
    2568                 :        4324 :                 DR_GROUP_SIZE (DR_GROUP_FIRST_ELEMENT (stmt_info));
    2569                 :       98439 :           if (!multiple_p (target_alignment, required_alignment))
    2570                 :             :             {
    2571                 :        2616 :               if (dump_enabled_p ())
    2572                 :          14 :                 dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2573                 :             :                              "desired alignment %wu not met. Instead got %wu "
    2574                 :             :                              "for DR alignment at %G",
    2575                 :             :                              required_alignment.to_constant (),
    2576                 :             :                              target_align, STMT_VINFO_STMT (stmt_info));
    2577                 :        2616 :               return false;
    2578                 :             :             }
    2579                 :             : 
    2580                 :       95823 :           if (!pow2p_hwi (target_align))
    2581                 :             :             {
    2582                 :           0 :               if (dump_enabled_p ())
    2583                 :           0 :                 dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2584                 :             :                              "non-power-of-two vector alignment %wd "
    2585                 :             :                              "for DR alignment at %G",
    2586                 :             :                              target_align, STMT_VINFO_STMT (stmt_info));
    2587                 :           0 :               return false;
    2588                 :             :             }
    2589                 :             : 
    2590                 :             :           /* For VLA we have to insert a runtime check that the vector loads
    2591                 :             :              per iterations don't exceed a page size.  For now we can use
    2592                 :             :              POLY_VALUE_MAX as a proxy as we can't peel for VLA.  */
    2593                 :       95823 :           if (known_gt (required_alignment, (unsigned)param_min_pagesize))
    2594                 :             :             {
    2595                 :           0 :               if (dump_enabled_p ())
    2596                 :             :                 {
    2597                 :           0 :                   dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2598                 :             :                                "alignment required for correctness (");
    2599                 :           0 :                   dump_dec (MSG_MISSED_OPTIMIZATION, required_alignment);
    2600                 :           0 :                   dump_printf (MSG_NOTE, ") may exceed page size\n");
    2601                 :             :                 }
    2602                 :           0 :               return false;
    2603                 :             :             }
    2604                 :             : 
    2605                 :       95823 :           group_aligned = true;
    2606                 :             :         }
    2607                 :             : 
    2608                 :             :       /* There are multiple loads that have a misalignment that we couldn't
    2609                 :             :          align.  We would need LOOP_VINFO_MUST_USE_PARTIAL_VECTORS_P to
    2610                 :             :          vectorize. */
    2611                 :       95823 :       if (!group_aligned)
    2612                 :             :         {
    2613                 :             :           if (inbounds)
    2614                 :             :             LOOP_VINFO_MUST_USE_PARTIAL_VECTORS_P (loop_vinfo) = true;
    2615                 :             :           else
    2616                 :             :             return false;
    2617                 :             :         }
    2618                 :             : 
    2619                 :             :       /* When using a group access the first element may be aligned but the
    2620                 :             :          subsequent loads may not be.  For LOAD_LANES since the loads are based
    2621                 :             :          on the first DR then all loads in the group are aligned.  For
    2622                 :             :          non-LOAD_LANES this is not the case. In particular a load + blend when
    2623                 :             :          there are gaps can have the non first loads issued unaligned, even
    2624                 :             :          partially overlapping the memory of the first load in order to simplify
    2625                 :             :          the blend.  This is what the x86_64 backend does for instance.  As
    2626                 :             :          such only the first load in the group is aligned, the rest are not.
    2627                 :             :          Because of this the permutes may break the alignment requirements that
    2628                 :             :          have been set, and as such we should for now, reject them.  */
    2629                 :       95823 :       if (SLP_TREE_LOAD_PERMUTATION (slp_node).exists ())
    2630                 :             :         {
    2631                 :        1304 :           if (dump_enabled_p ())
    2632                 :          72 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2633                 :             :                              "loads with load permutations not supported for "
    2634                 :             :                              "speculative early break loads for %G",
    2635                 :             :                              STMT_VINFO_STMT (stmt_info));
    2636                 :        1304 :           return false;
    2637                 :             :         }
    2638                 :             :     }
    2639                 :             : 
    2640                 :     2039912 :   if (*alignment_support_scheme == dr_unaligned_unsupported)
    2641                 :             :     {
    2642                 :       55334 :       if (dump_enabled_p ())
    2643                 :         278 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2644                 :             :                          "unsupported unaligned access\n");
    2645                 :       55334 :       return false;
    2646                 :             :     }
    2647                 :             : 
    2648                 :             :   /* FIXME: At the moment the cost model seems to underestimate the
    2649                 :             :      cost of using elementwise accesses.  This check preserves the
    2650                 :             :      traditional behavior until that can be fixed.  */
    2651                 :     1984578 :   stmt_vec_info first_stmt_info = DR_GROUP_FIRST_ELEMENT (stmt_info);
    2652                 :     1984578 :   if (!first_stmt_info)
    2653                 :      468310 :     first_stmt_info = stmt_info;
    2654                 :     1984578 :   if (*memory_access_type == VMAT_ELEMENTWISE
    2655                 :       19777 :       && !STMT_VINFO_STRIDED_P (first_stmt_info)
    2656                 :     2004355 :       && !(stmt_info == DR_GROUP_FIRST_ELEMENT (stmt_info)
    2657                 :       16271 :            && !DR_GROUP_NEXT_ELEMENT (stmt_info)
    2658                 :       16185 :            && !pow2p_hwi (DR_GROUP_SIZE (stmt_info))))
    2659                 :             :     {
    2660                 :        8150 :       if (dump_enabled_p ())
    2661                 :         270 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2662                 :             :                          "not falling back to elementwise accesses\n");
    2663                 :        8150 :       return false;
    2664                 :             :     }
    2665                 :             :   return true;
    2666                 :             : }
    2667                 :             : 
    2668                 :             : /* Return true if boolean argument at MASK_INDEX is suitable for vectorizing
    2669                 :             :    conditional operation STMT_INFO.  When returning true, store the mask
    2670                 :             :    in *MASK, the type of its definition in *MASK_DT_OUT, the type of the
    2671                 :             :    vectorized mask in *MASK_VECTYPE_OUT and the SLP node corresponding
    2672                 :             :    to the mask in *MASK_NODE if MASK_NODE is not NULL.  */
    2673                 :             : 
    2674                 :             : static bool
    2675                 :        7731 : vect_check_scalar_mask (vec_info *vinfo, stmt_vec_info stmt_info,
    2676                 :             :                         slp_tree slp_node, unsigned mask_index,
    2677                 :             :                         tree *mask, slp_tree *mask_node,
    2678                 :             :                         vect_def_type *mask_dt_out, tree *mask_vectype_out)
    2679                 :             : {
    2680                 :        7731 :   enum vect_def_type mask_dt;
    2681                 :        7731 :   tree mask_vectype;
    2682                 :        7731 :   slp_tree mask_node_1;
    2683                 :        7731 :   if (!vect_is_simple_use (vinfo, stmt_info, slp_node, mask_index,
    2684                 :             :                            mask, &mask_node_1, &mask_dt, &mask_vectype))
    2685                 :             :     {
    2686                 :           0 :       if (dump_enabled_p ())
    2687                 :           0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2688                 :             :                          "mask use not simple.\n");
    2689                 :           0 :       return false;
    2690                 :             :     }
    2691                 :             : 
    2692                 :        7731 :   if ((mask_dt == vect_constant_def || mask_dt == vect_external_def)
    2693                 :        7731 :       && !VECT_SCALAR_BOOLEAN_TYPE_P (TREE_TYPE (*mask)))
    2694                 :             :     {
    2695                 :           0 :       if (dump_enabled_p ())
    2696                 :           0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2697                 :             :                          "mask argument is not a boolean.\n");
    2698                 :           0 :       return false;
    2699                 :             :     }
    2700                 :             : 
    2701                 :             :   /* If the caller is not prepared for adjusting an external/constant
    2702                 :             :      SLP mask vector type fail.  */
    2703                 :        7731 :   if (slp_node
    2704                 :        7731 :       && !mask_node
    2705                 :           0 :       && SLP_TREE_DEF_TYPE (mask_node_1) != vect_internal_def)
    2706                 :             :     {
    2707                 :           0 :       if (dump_enabled_p ())
    2708                 :           0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2709                 :             :                          "SLP mask argument is not vectorized.\n");
    2710                 :           0 :       return false;
    2711                 :             :     }
    2712                 :             : 
    2713                 :        7731 :   tree vectype = STMT_VINFO_VECTYPE (stmt_info);
    2714                 :        7731 :   if (!mask_vectype)
    2715                 :          21 :     mask_vectype = get_mask_type_for_scalar_type (vinfo, TREE_TYPE (vectype),
    2716                 :             :                                                   mask_node_1);
    2717                 :             : 
    2718                 :        7731 :   if (!mask_vectype || !VECTOR_BOOLEAN_TYPE_P (mask_vectype))
    2719                 :             :     {
    2720                 :           0 :       if (dump_enabled_p ())
    2721                 :           0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2722                 :             :                          "could not find an appropriate vector mask type.\n");
    2723                 :           0 :       return false;
    2724                 :             :     }
    2725                 :             : 
    2726                 :        7731 :   if (maybe_ne (TYPE_VECTOR_SUBPARTS (mask_vectype),
    2727                 :       15462 :                 TYPE_VECTOR_SUBPARTS (vectype)))
    2728                 :             :     {
    2729                 :           0 :       if (dump_enabled_p ())
    2730                 :           0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2731                 :             :                          "vector mask type %T"
    2732                 :             :                          " does not match vector data type %T.\n",
    2733                 :             :                          mask_vectype, vectype);
    2734                 :             : 
    2735                 :           0 :       return false;
    2736                 :             :     }
    2737                 :             : 
    2738                 :        7731 :   *mask_dt_out = mask_dt;
    2739                 :        7731 :   *mask_vectype_out = mask_vectype;
    2740                 :        7731 :   if (mask_node)
    2741                 :        7731 :     *mask_node = mask_node_1;
    2742                 :             :   return true;
    2743                 :             : }
    2744                 :             : 
    2745                 :             : /* Return true if stored value is suitable for vectorizing store
    2746                 :             :    statement STMT_INFO.  When returning true, store the scalar stored
    2747                 :             :    in *RHS and *RHS_NODE, the type of the definition in *RHS_DT_OUT,
    2748                 :             :    the type of the vectorized store value in
    2749                 :             :    *RHS_VECTYPE_OUT and the type of the store in *VLS_TYPE_OUT.  */
    2750                 :             : 
    2751                 :             : static bool
    2752                 :     1393885 : vect_check_store_rhs (vec_info *vinfo, stmt_vec_info stmt_info,
    2753                 :             :                       slp_tree slp_node, tree *rhs, slp_tree *rhs_node,
    2754                 :             :                       vect_def_type *rhs_dt_out, tree *rhs_vectype_out,
    2755                 :             :                       vec_load_store_type *vls_type_out)
    2756                 :             : {
    2757                 :     1393885 :   int op_no = 0;
    2758                 :     1393885 :   if (gcall *call = dyn_cast <gcall *> (stmt_info->stmt))
    2759                 :             :     {
    2760                 :        1465 :       if (gimple_call_internal_p (call)
    2761                 :        1465 :           && internal_store_fn_p (gimple_call_internal_fn (call)))
    2762                 :        1465 :         op_no = internal_fn_stored_value_index (gimple_call_internal_fn (call));
    2763                 :             :     }
    2764                 :     1393885 :   if (slp_node)
    2765                 :     1393885 :     op_no = vect_slp_child_index_for_operand
    2766                 :     1393885 :               (stmt_info->stmt, op_no, STMT_VINFO_GATHER_SCATTER_P (stmt_info));
    2767                 :             : 
    2768                 :     1393885 :   enum vect_def_type rhs_dt;
    2769                 :     1393885 :   tree rhs_vectype;
    2770                 :     1393885 :   if (!vect_is_simple_use (vinfo, stmt_info, slp_node, op_no,
    2771                 :             :                            rhs, rhs_node, &rhs_dt, &rhs_vectype))
    2772                 :             :     {
    2773                 :           0 :       if (dump_enabled_p ())
    2774                 :           0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2775                 :             :                          "use not simple.\n");
    2776                 :           0 :       return false;
    2777                 :             :     }
    2778                 :             : 
    2779                 :             :   /* In the case this is a store from a constant make sure
    2780                 :             :      native_encode_expr can handle it.  */
    2781                 :     1393885 :   if (rhs_dt == vect_constant_def
    2782                 :     1393885 :       && CONSTANT_CLASS_P (*rhs) && native_encode_expr (*rhs, NULL, 64) == 0)
    2783                 :             :     {
    2784                 :           0 :       if (dump_enabled_p ())
    2785                 :           0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2786                 :             :                          "cannot encode constant as a byte sequence.\n");
    2787                 :           0 :       return false;
    2788                 :             :     }
    2789                 :             : 
    2790                 :     1393885 :   tree vectype = STMT_VINFO_VECTYPE (stmt_info);
    2791                 :     1393885 :   if (rhs_vectype && !useless_type_conversion_p (vectype, rhs_vectype))
    2792                 :             :     {
    2793                 :          24 :       if (dump_enabled_p ())
    2794                 :          24 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2795                 :             :                          "incompatible vector types.\n");
    2796                 :          24 :       return false;
    2797                 :             :     }
    2798                 :             : 
    2799                 :     1393861 :   *rhs_dt_out = rhs_dt;
    2800                 :     1393861 :   *rhs_vectype_out = rhs_vectype;
    2801                 :     1393861 :   if (rhs_dt == vect_constant_def || rhs_dt == vect_external_def)
    2802                 :     1059783 :     *vls_type_out = VLS_STORE_INVARIANT;
    2803                 :             :   else
    2804                 :      334078 :     *vls_type_out = VLS_STORE;
    2805                 :             :   return true;
    2806                 :             : }
    2807                 :             : 
    2808                 :             : /* Build an all-ones vector mask of type MASKTYPE while vectorizing STMT_INFO.
    2809                 :             :    Note that we support masks with floating-point type, in which case the
    2810                 :             :    floats are interpreted as a bitmask.  */
    2811                 :             : 
    2812                 :             : static tree
    2813                 :         163 : vect_build_all_ones_mask (vec_info *vinfo,
    2814                 :             :                           stmt_vec_info stmt_info, tree masktype)
    2815                 :             : {
    2816                 :         163 :   if (TREE_CODE (masktype) == INTEGER_TYPE)
    2817                 :          98 :     return build_int_cst (masktype, -1);
    2818                 :          65 :   else if (VECTOR_BOOLEAN_TYPE_P (masktype)
    2819                 :         130 :            || TREE_CODE (TREE_TYPE (masktype)) == INTEGER_TYPE)
    2820                 :             :     {
    2821                 :          14 :       tree mask = build_int_cst (TREE_TYPE (masktype), -1);
    2822                 :          14 :       mask = build_vector_from_val (masktype, mask);
    2823                 :          14 :       return vect_init_vector (vinfo, stmt_info, mask, masktype, NULL);
    2824                 :             :     }
    2825                 :          51 :   else if (SCALAR_FLOAT_TYPE_P (TREE_TYPE (masktype)))
    2826                 :             :     {
    2827                 :             :       REAL_VALUE_TYPE r;
    2828                 :             :       long tmp[6];
    2829                 :         357 :       for (int j = 0; j < 6; ++j)
    2830                 :         306 :         tmp[j] = -1;
    2831                 :          51 :       real_from_target (&r, tmp, TYPE_MODE (TREE_TYPE (masktype)));
    2832                 :          51 :       tree mask = build_real (TREE_TYPE (masktype), r);
    2833                 :          51 :       mask = build_vector_from_val (masktype, mask);
    2834                 :          51 :       return vect_init_vector (vinfo, stmt_info, mask, masktype, NULL);
    2835                 :             :     }
    2836                 :           0 :   gcc_unreachable ();
    2837                 :             : }
    2838                 :             : 
    2839                 :             : /* Build an all-zero merge value of type VECTYPE while vectorizing
    2840                 :             :    STMT_INFO as a gather load.  */
    2841                 :             : 
    2842                 :             : static tree
    2843                 :         156 : vect_build_zero_merge_argument (vec_info *vinfo,
    2844                 :             :                                 stmt_vec_info stmt_info, tree vectype)
    2845                 :             : {
    2846                 :         156 :   tree merge;
    2847                 :         156 :   if (TREE_CODE (TREE_TYPE (vectype)) == INTEGER_TYPE)
    2848                 :          49 :     merge = build_int_cst (TREE_TYPE (vectype), 0);
    2849                 :         107 :   else if (SCALAR_FLOAT_TYPE_P (TREE_TYPE (vectype)))
    2850                 :             :     {
    2851                 :             :       REAL_VALUE_TYPE r;
    2852                 :             :       long tmp[6];
    2853                 :         749 :       for (int j = 0; j < 6; ++j)
    2854                 :         642 :         tmp[j] = 0;
    2855                 :         107 :       real_from_target (&r, tmp, TYPE_MODE (TREE_TYPE (vectype)));
    2856                 :         107 :       merge = build_real (TREE_TYPE (vectype), r);
    2857                 :             :     }
    2858                 :             :   else
    2859                 :           0 :     gcc_unreachable ();
    2860                 :         156 :   merge = build_vector_from_val (vectype, merge);
    2861                 :         156 :   return vect_init_vector (vinfo, stmt_info, merge, vectype, NULL);
    2862                 :             : }
    2863                 :             : 
    2864                 :             : /* Return the corresponding else value for an else value constant
    2865                 :             :    ELSVAL with type TYPE.  */
    2866                 :             : 
    2867                 :             : tree
    2868                 :        1621 : vect_get_mask_load_else (int elsval, tree type)
    2869                 :             : {
    2870                 :        1621 :   tree els;
    2871                 :        1621 :   if (elsval == MASK_LOAD_ELSE_UNDEFINED)
    2872                 :             :     {
    2873                 :           0 :       tree tmp = create_tmp_var (type);
    2874                 :             :       /* No need to warn about anything.  */
    2875                 :           0 :       TREE_NO_WARNING (tmp) = 1;
    2876                 :           0 :       els = get_or_create_ssa_default_def (cfun, tmp);
    2877                 :             :     }
    2878                 :        1621 :   else if (elsval == MASK_LOAD_ELSE_M1)
    2879                 :           0 :     els = build_minus_one_cst (type);
    2880                 :        1621 :   else if (elsval == MASK_LOAD_ELSE_ZERO)
    2881                 :        1621 :     els = build_zero_cst (type);
    2882                 :             :   else
    2883                 :           0 :     gcc_unreachable ();
    2884                 :             : 
    2885                 :        1621 :   return els;
    2886                 :             : }
    2887                 :             : 
    2888                 :             : /* Build a gather load call while vectorizing STMT_INFO.  Insert new
    2889                 :             :    instructions before GSI and add them to VEC_STMT.  GS_INFO describes
    2890                 :             :    the gather load operation.  If the load is conditional, MASK is the
    2891                 :             :    vectorized condition, otherwise MASK is null.  PTR is the base
    2892                 :             :    pointer and OFFSET is the vectorized offset.  */
    2893                 :             : 
    2894                 :             : static gimple *
    2895                 :         344 : vect_build_one_gather_load_call (vec_info *vinfo, stmt_vec_info stmt_info,
    2896                 :             :                                  gimple_stmt_iterator *gsi,
    2897                 :             :                                  gather_scatter_info *gs_info,
    2898                 :             :                                  tree ptr, tree offset, tree mask)
    2899                 :             : {
    2900                 :         344 :   tree vectype = STMT_VINFO_VECTYPE (stmt_info);
    2901                 :         344 :   tree arglist = TYPE_ARG_TYPES (TREE_TYPE (gs_info->decl));
    2902                 :         344 :   tree rettype = TREE_TYPE (TREE_TYPE (gs_info->decl));
    2903                 :         344 :   tree srctype = TREE_VALUE (arglist); arglist = TREE_CHAIN (arglist);
    2904                 :         344 :   /* ptrtype */ arglist = TREE_CHAIN (arglist);
    2905                 :         344 :   tree idxtype = TREE_VALUE (arglist); arglist = TREE_CHAIN (arglist);
    2906                 :         344 :   tree masktype = TREE_VALUE (arglist); arglist = TREE_CHAIN (arglist);
    2907                 :         344 :   tree scaletype = TREE_VALUE (arglist);
    2908                 :         344 :   tree var;
    2909                 :         344 :   gcc_checking_assert (types_compatible_p (srctype, rettype)
    2910                 :             :                        && (!mask
    2911                 :             :                            || TREE_CODE (masktype) == INTEGER_TYPE
    2912                 :             :                            || types_compatible_p (srctype, masktype)));
    2913                 :             : 
    2914                 :         344 :   tree op = offset;
    2915                 :         344 :   if (!useless_type_conversion_p (idxtype, TREE_TYPE (op)))
    2916                 :             :     {
    2917                 :         100 :       gcc_assert (known_eq (TYPE_VECTOR_SUBPARTS (TREE_TYPE (op)),
    2918                 :             :                             TYPE_VECTOR_SUBPARTS (idxtype)));
    2919                 :         100 :       var = vect_get_new_ssa_name (idxtype, vect_simple_var);
    2920                 :         100 :       op = build1 (VIEW_CONVERT_EXPR, idxtype, op);
    2921                 :         100 :       gassign *new_stmt = gimple_build_assign (var, VIEW_CONVERT_EXPR, op);
    2922                 :         100 :       vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    2923                 :         100 :       op = var;
    2924                 :             :     }
    2925                 :             : 
    2926                 :         344 :   tree src_op = NULL_TREE;
    2927                 :         344 :   tree mask_op = NULL_TREE;
    2928                 :         344 :   if (mask)
    2929                 :             :     {
    2930                 :         188 :       if (!useless_type_conversion_p (masktype, TREE_TYPE (mask)))
    2931                 :             :         {
    2932                 :         188 :           tree utype, optype = TREE_TYPE (mask);
    2933                 :         188 :           if (VECTOR_TYPE_P (masktype)
    2934                 :         188 :               || TYPE_MODE (masktype) == TYPE_MODE (optype))
    2935                 :             :             utype = masktype;
    2936                 :             :           else
    2937                 :           7 :             utype = lang_hooks.types.type_for_mode (TYPE_MODE (optype), 1);
    2938                 :         188 :           var = vect_get_new_ssa_name (utype, vect_scalar_var);
    2939                 :         188 :           tree mask_arg = build1 (VIEW_CONVERT_EXPR, utype, mask);
    2940                 :         188 :           gassign *new_stmt
    2941                 :         188 :               = gimple_build_assign (var, VIEW_CONVERT_EXPR, mask_arg);
    2942                 :         188 :           vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    2943                 :         188 :           mask_arg = var;
    2944                 :         188 :           if (!useless_type_conversion_p (masktype, utype))
    2945                 :             :             {
    2946                 :           7 :               gcc_assert (TYPE_PRECISION (utype)
    2947                 :             :                           <= TYPE_PRECISION (masktype));
    2948                 :           7 :               var = vect_get_new_ssa_name (masktype, vect_scalar_var);
    2949                 :           7 :               new_stmt = gimple_build_assign (var, NOP_EXPR, mask_arg);
    2950                 :           7 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    2951                 :           7 :               mask_arg = var;
    2952                 :             :             }
    2953                 :         188 :           src_op = build_zero_cst (srctype);
    2954                 :         188 :           mask_op = mask_arg;
    2955                 :             :         }
    2956                 :             :       else
    2957                 :             :         {
    2958                 :             :           src_op = mask;
    2959                 :             :           mask_op = mask;
    2960                 :             :         }
    2961                 :             :     }
    2962                 :             :   else
    2963                 :             :     {
    2964                 :         156 :       src_op = vect_build_zero_merge_argument (vinfo, stmt_info, rettype);
    2965                 :         156 :       mask_op = vect_build_all_ones_mask (vinfo, stmt_info, masktype);
    2966                 :             :     }
    2967                 :             : 
    2968                 :         344 :   tree scale = build_int_cst (scaletype, gs_info->scale);
    2969                 :         344 :   gimple *new_stmt = gimple_build_call (gs_info->decl, 5, src_op, ptr, op,
    2970                 :             :                                         mask_op, scale);
    2971                 :             : 
    2972                 :         344 :   if (!useless_type_conversion_p (vectype, rettype))
    2973                 :             :     {
    2974                 :          49 :       gcc_assert (known_eq (TYPE_VECTOR_SUBPARTS (vectype),
    2975                 :             :                             TYPE_VECTOR_SUBPARTS (rettype)));
    2976                 :          49 :       op = vect_get_new_ssa_name (rettype, vect_simple_var);
    2977                 :          49 :       gimple_call_set_lhs (new_stmt, op);
    2978                 :          49 :       vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    2979                 :          49 :       op = build1 (VIEW_CONVERT_EXPR, vectype, op);
    2980                 :          49 :       new_stmt = gimple_build_assign (NULL_TREE, VIEW_CONVERT_EXPR, op);
    2981                 :             :     }
    2982                 :             : 
    2983                 :         344 :   return new_stmt;
    2984                 :             : }
    2985                 :             : 
    2986                 :             : /* Build a scatter store call while vectorizing STMT_INFO.  Insert new
    2987                 :             :    instructions before GSI.  GS_INFO describes the scatter store operation.
    2988                 :             :    PTR is the base pointer, OFFSET the vectorized offsets and OPRND the
    2989                 :             :    vectorized data to store.
    2990                 :             :    If the store is conditional, MASK is the vectorized condition, otherwise
    2991                 :             :    MASK is null.  */
    2992                 :             : 
    2993                 :             : static gimple *
    2994                 :         169 : vect_build_one_scatter_store_call (vec_info *vinfo, stmt_vec_info stmt_info,
    2995                 :             :                                    gimple_stmt_iterator *gsi,
    2996                 :             :                                    gather_scatter_info *gs_info,
    2997                 :             :                                    tree ptr, tree offset, tree oprnd, tree mask)
    2998                 :             : {
    2999                 :         169 :   tree rettype = TREE_TYPE (TREE_TYPE (gs_info->decl));
    3000                 :         169 :   tree arglist = TYPE_ARG_TYPES (TREE_TYPE (gs_info->decl));
    3001                 :         169 :   /* tree ptrtype = TREE_VALUE (arglist); */ arglist = TREE_CHAIN (arglist);
    3002                 :         169 :   tree masktype = TREE_VALUE (arglist); arglist = TREE_CHAIN (arglist);
    3003                 :         169 :   tree idxtype = TREE_VALUE (arglist); arglist = TREE_CHAIN (arglist);
    3004                 :         169 :   tree srctype = TREE_VALUE (arglist); arglist = TREE_CHAIN (arglist);
    3005                 :         169 :   tree scaletype = TREE_VALUE (arglist);
    3006                 :         169 :   gcc_checking_assert (TREE_CODE (masktype) == INTEGER_TYPE
    3007                 :             :                        && TREE_CODE (rettype) == VOID_TYPE);
    3008                 :             : 
    3009                 :         169 :   tree mask_arg = NULL_TREE;
    3010                 :         169 :   if (mask)
    3011                 :             :     {
    3012                 :         110 :       mask_arg = mask;
    3013                 :         110 :       tree optype = TREE_TYPE (mask_arg);
    3014                 :         110 :       tree utype;
    3015                 :         110 :       if (TYPE_MODE (masktype) == TYPE_MODE (optype))
    3016                 :             :         utype = masktype;
    3017                 :             :       else
    3018                 :           8 :         utype = lang_hooks.types.type_for_mode (TYPE_MODE (optype), 1);
    3019                 :         110 :       tree var = vect_get_new_ssa_name (utype, vect_scalar_var);
    3020                 :         110 :       mask_arg = build1 (VIEW_CONVERT_EXPR, utype, mask_arg);
    3021                 :         110 :       gassign *new_stmt
    3022                 :         110 :         = gimple_build_assign (var, VIEW_CONVERT_EXPR, mask_arg);
    3023                 :         110 :       vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    3024                 :         110 :       mask_arg = var;
    3025                 :         110 :       if (!useless_type_conversion_p (masktype, utype))
    3026                 :             :         {
    3027                 :           8 :           gcc_assert (TYPE_PRECISION (utype) <= TYPE_PRECISION (masktype));
    3028                 :           8 :           tree var = vect_get_new_ssa_name (masktype, vect_scalar_var);
    3029                 :           8 :           new_stmt = gimple_build_assign (var, NOP_EXPR, mask_arg);
    3030                 :           8 :           vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    3031                 :           8 :           mask_arg = var;
    3032                 :             :         }
    3033                 :             :     }
    3034                 :             :   else
    3035                 :             :     {
    3036                 :          59 :       mask_arg = build_int_cst (masktype, -1);
    3037                 :          59 :       mask_arg = vect_init_vector (vinfo, stmt_info, mask_arg, masktype, NULL);
    3038                 :             :     }
    3039                 :             : 
    3040                 :         169 :   tree src = oprnd;
    3041                 :         169 :   if (!useless_type_conversion_p (srctype, TREE_TYPE (src)))
    3042                 :             :     {
    3043                 :           0 :       gcc_assert (known_eq (TYPE_VECTOR_SUBPARTS (TREE_TYPE (src)),
    3044                 :             :                             TYPE_VECTOR_SUBPARTS (srctype)));
    3045                 :           0 :       tree var = vect_get_new_ssa_name (srctype, vect_simple_var);
    3046                 :           0 :       src = build1 (VIEW_CONVERT_EXPR, srctype, src);
    3047                 :           0 :       gassign *new_stmt = gimple_build_assign (var, VIEW_CONVERT_EXPR, src);
    3048                 :           0 :       vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    3049                 :           0 :       src = var;
    3050                 :             :     }
    3051                 :             : 
    3052                 :         169 :   tree op = offset;
    3053                 :         169 :   if (!useless_type_conversion_p (idxtype, TREE_TYPE (op)))
    3054                 :             :     {
    3055                 :          24 :       gcc_assert (known_eq (TYPE_VECTOR_SUBPARTS (TREE_TYPE (op)),
    3056                 :             :                             TYPE_VECTOR_SUBPARTS (idxtype)));
    3057                 :          24 :       tree var = vect_get_new_ssa_name (idxtype, vect_simple_var);
    3058                 :          24 :       op = build1 (VIEW_CONVERT_EXPR, idxtype, op);
    3059                 :          24 :       gassign *new_stmt = gimple_build_assign (var, VIEW_CONVERT_EXPR, op);
    3060                 :          24 :       vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    3061                 :          24 :       op = var;
    3062                 :             :     }
    3063                 :             : 
    3064                 :         169 :   tree scale = build_int_cst (scaletype, gs_info->scale);
    3065                 :         169 :   gcall *new_stmt
    3066                 :         169 :     = gimple_build_call (gs_info->decl, 5, ptr, mask_arg, op, src, scale);
    3067                 :         169 :   return new_stmt;
    3068                 :             : }
    3069                 :             : 
    3070                 :             : /* Prepare the base and offset in GS_INFO for vectorization.
    3071                 :             :    Set *DATAREF_PTR to the loop-invariant base address and *VEC_OFFSET
    3072                 :             :    to the vectorized offset argument for the first copy of STMT_INFO.
    3073                 :             :    STMT_INFO is the statement described by GS_INFO and LOOP is the
    3074                 :             :    containing loop.  */
    3075                 :             : 
    3076                 :             : static void
    3077                 :        1216 : vect_get_gather_scatter_ops (loop_vec_info loop_vinfo,
    3078                 :             :                              class loop *loop, stmt_vec_info stmt_info,
    3079                 :             :                              slp_tree slp_node, gather_scatter_info *gs_info,
    3080                 :             :                              tree *dataref_ptr, vec<tree> *vec_offset)
    3081                 :             : {
    3082                 :        1216 :   gimple_seq stmts = NULL;
    3083                 :        1216 :   *dataref_ptr = force_gimple_operand (gs_info->base, &stmts, true, NULL_TREE);
    3084                 :        1216 :   if (stmts != NULL)
    3085                 :             :     {
    3086                 :         981 :       basic_block new_bb;
    3087                 :         981 :       edge pe = loop_preheader_edge (loop);
    3088                 :         981 :       new_bb = gsi_insert_seq_on_edge_immediate (pe, stmts);
    3089                 :         981 :       gcc_assert (!new_bb);
    3090                 :             :     }
    3091                 :        1216 :   if (slp_node)
    3092                 :        1216 :     vect_get_slp_defs (SLP_TREE_CHILDREN (slp_node)[0], vec_offset);
    3093                 :             :   else
    3094                 :             :     {
    3095                 :           0 :       unsigned ncopies
    3096                 :           0 :         = vect_get_num_copies (loop_vinfo, gs_info->offset_vectype);
    3097                 :           0 :       vect_get_vec_defs_for_operand (loop_vinfo, stmt_info, ncopies,
    3098                 :             :                                      gs_info->offset, vec_offset,
    3099                 :             :                                      gs_info->offset_vectype);
    3100                 :             :     }
    3101                 :        1216 : }
    3102                 :             : 
    3103                 :             : /* Prepare to implement a grouped or strided load or store using
    3104                 :             :    the gather load or scatter store operation described by GS_INFO.
    3105                 :             :    STMT_INFO is the load or store statement.
    3106                 :             : 
    3107                 :             :    Set *DATAREF_BUMP to the amount that should be added to the base
    3108                 :             :    address after each copy of the vectorized statement.  Set *VEC_OFFSET
    3109                 :             :    to an invariant offset vector in which element I has the value
    3110                 :             :    I * DR_STEP / SCALE.  */
    3111                 :             : 
    3112                 :             : static void
    3113                 :           0 : vect_get_strided_load_store_ops (stmt_vec_info stmt_info,
    3114                 :             :                                  loop_vec_info loop_vinfo,
    3115                 :             :                                  gimple_stmt_iterator *gsi,
    3116                 :             :                                  gather_scatter_info *gs_info,
    3117                 :             :                                  tree *dataref_bump, tree *vec_offset,
    3118                 :             :                                  vec_loop_lens *loop_lens)
    3119                 :             : {
    3120                 :           0 :   struct data_reference *dr = STMT_VINFO_DATA_REF (stmt_info);
    3121                 :           0 :   tree vectype = STMT_VINFO_VECTYPE (stmt_info);
    3122                 :             : 
    3123                 :           0 :   if (LOOP_VINFO_USING_SELECT_VL_P (loop_vinfo))
    3124                 :             :     {
    3125                 :             :       /* _31 = .SELECT_VL (ivtmp_29, POLY_INT_CST [4, 4]);
    3126                 :             :          ivtmp_8 = _31 * 16 (step in bytes);
    3127                 :             :          .MASK_LEN_SCATTER_STORE (vectp_a.9_7, ... );
    3128                 :             :          vectp_a.9_26 = vectp_a.9_7 + ivtmp_8;  */
    3129                 :           0 :       tree loop_len
    3130                 :           0 :         = vect_get_loop_len (loop_vinfo, gsi, loop_lens, 1, vectype, 0, 0);
    3131                 :           0 :       tree tmp
    3132                 :           0 :         = fold_build2 (MULT_EXPR, sizetype,
    3133                 :             :                        fold_convert (sizetype, unshare_expr (DR_STEP (dr))),
    3134                 :             :                        loop_len);
    3135                 :           0 :       *dataref_bump = force_gimple_operand_gsi (gsi, tmp, true, NULL_TREE, true,
    3136                 :             :                                                 GSI_SAME_STMT);
    3137                 :             :     }
    3138                 :             :   else
    3139                 :             :     {
    3140                 :           0 :       tree bump
    3141                 :           0 :         = size_binop (MULT_EXPR,
    3142                 :             :                       fold_convert (sizetype, unshare_expr (DR_STEP (dr))),
    3143                 :             :                       size_int (TYPE_VECTOR_SUBPARTS (vectype)));
    3144                 :           0 :       *dataref_bump = cse_and_gimplify_to_preheader (loop_vinfo, bump);
    3145                 :             :     }
    3146                 :             : 
    3147                 :           0 :   internal_fn ifn
    3148                 :           0 :     = DR_IS_READ (dr) ? IFN_MASK_LEN_STRIDED_LOAD : IFN_MASK_LEN_STRIDED_STORE;
    3149                 :           0 :   if (direct_internal_fn_supported_p (ifn, vectype, OPTIMIZE_FOR_SPEED))
    3150                 :             :     {
    3151                 :           0 :       *vec_offset = cse_and_gimplify_to_preheader (loop_vinfo,
    3152                 :             :                                                    unshare_expr (DR_STEP (dr)));
    3153                 :           0 :       return;
    3154                 :             :     }
    3155                 :             : 
    3156                 :             :   /* The offset given in GS_INFO can have pointer type, so use the element
    3157                 :             :      type of the vector instead.  */
    3158                 :           0 :   tree offset_type = TREE_TYPE (gs_info->offset_vectype);
    3159                 :             : 
    3160                 :             :   /* Calculate X = DR_STEP / SCALE and convert it to the appropriate type.  */
    3161                 :           0 :   tree step = size_binop (EXACT_DIV_EXPR, unshare_expr (DR_STEP (dr)),
    3162                 :             :                           ssize_int (gs_info->scale));
    3163                 :           0 :   step = fold_convert (offset_type, step);
    3164                 :             : 
    3165                 :             :   /* Create {0, X, X*2, X*3, ...}.  */
    3166                 :           0 :   tree offset = fold_build2 (VEC_SERIES_EXPR, gs_info->offset_vectype,
    3167                 :             :                              build_zero_cst (offset_type), step);
    3168                 :           0 :   *vec_offset = cse_and_gimplify_to_preheader (loop_vinfo, offset);
    3169                 :             : }
    3170                 :             : 
    3171                 :             : /* Prepare the pointer IVs which needs to be updated by a variable amount.
    3172                 :             :    Such variable amount is the outcome of .SELECT_VL. In this case, we can
    3173                 :             :    allow each iteration process the flexible number of elements as long as
    3174                 :             :    the number <= vf elments.
    3175                 :             : 
    3176                 :             :    Return data reference according to SELECT_VL.
    3177                 :             :    If new statements are needed, insert them before GSI.  */
    3178                 :             : 
    3179                 :             : static tree
    3180                 :           0 : vect_get_loop_variant_data_ptr_increment (
    3181                 :             :   vec_info *vinfo, tree aggr_type, gimple_stmt_iterator *gsi,
    3182                 :             :   vec_loop_lens *loop_lens, dr_vec_info *dr_info,
    3183                 :             :   vect_memory_access_type memory_access_type)
    3184                 :             : {
    3185                 :           0 :   loop_vec_info loop_vinfo = dyn_cast<loop_vec_info> (vinfo);
    3186                 :           0 :   tree step = vect_dr_behavior (vinfo, dr_info)->step;
    3187                 :             : 
    3188                 :             :   /* gather/scatter never reach here.  */
    3189                 :           0 :   gcc_assert (memory_access_type != VMAT_GATHER_SCATTER);
    3190                 :             : 
    3191                 :             :   /* When we support SELECT_VL pattern, we dynamic adjust
    3192                 :             :      the memory address by .SELECT_VL result.
    3193                 :             : 
    3194                 :             :      The result of .SELECT_VL is the number of elements to
    3195                 :             :      be processed of each iteration. So the memory address
    3196                 :             :      adjustment operation should be:
    3197                 :             : 
    3198                 :             :      addr = addr + .SELECT_VL (ARG..) * step;
    3199                 :             :   */
    3200                 :           0 :   tree loop_len
    3201                 :           0 :     = vect_get_loop_len (loop_vinfo, gsi, loop_lens, 1, aggr_type, 0, 0);
    3202                 :           0 :   tree len_type = TREE_TYPE (loop_len);
    3203                 :             :   /* Since the outcome of .SELECT_VL is element size, we should adjust
    3204                 :             :      it into bytesize so that it can be used in address pointer variable
    3205                 :             :      amount IVs adjustment.  */
    3206                 :           0 :   tree tmp = fold_build2 (MULT_EXPR, len_type, loop_len,
    3207                 :             :                           wide_int_to_tree (len_type, wi::to_widest (step)));
    3208                 :           0 :   tree bump = make_temp_ssa_name (len_type, NULL, "ivtmp");
    3209                 :           0 :   gassign *assign = gimple_build_assign (bump, tmp);
    3210                 :           0 :   gsi_insert_before (gsi, assign, GSI_SAME_STMT);
    3211                 :           0 :   return bump;
    3212                 :             : }
    3213                 :             : 
    3214                 :             : /* Return the amount that should be added to a vector pointer to move
    3215                 :             :    to the next or previous copy of AGGR_TYPE.  DR_INFO is the data reference
    3216                 :             :    being vectorized and MEMORY_ACCESS_TYPE describes the type of
    3217                 :             :    vectorization.  */
    3218                 :             : 
    3219                 :             : static tree
    3220                 :      687300 : vect_get_data_ptr_increment (vec_info *vinfo, gimple_stmt_iterator *gsi,
    3221                 :             :                              dr_vec_info *dr_info, tree aggr_type,
    3222                 :             :                              vect_memory_access_type memory_access_type,
    3223                 :             :                              vec_loop_lens *loop_lens = nullptr)
    3224                 :             : {
    3225                 :      687300 :   if (memory_access_type == VMAT_INVARIANT)
    3226                 :           0 :     return size_zero_node;
    3227                 :             : 
    3228                 :      687300 :   loop_vec_info loop_vinfo = dyn_cast<loop_vec_info> (vinfo);
    3229                 :      125454 :   if (loop_vinfo && LOOP_VINFO_USING_SELECT_VL_P (loop_vinfo))
    3230                 :           0 :     return vect_get_loop_variant_data_ptr_increment (vinfo, aggr_type, gsi,
    3231                 :             :                                                      loop_lens, dr_info,
    3232                 :           0 :                                                      memory_access_type);
    3233                 :             : 
    3234                 :      687300 :   tree iv_step = TYPE_SIZE_UNIT (aggr_type);
    3235                 :      687300 :   tree step = vect_dr_behavior (vinfo, dr_info)->step;
    3236                 :      687300 :   if (tree_int_cst_sgn (step) == -1)
    3237                 :        2808 :     iv_step = fold_build1 (NEGATE_EXPR, TREE_TYPE (iv_step), iv_step);
    3238                 :             :   return iv_step;
    3239                 :             : }
    3240                 :             : 
    3241                 :             : /* Check and perform vectorization of BUILT_IN_BSWAP{16,32,64,128}.  */
    3242                 :             : 
    3243                 :             : static bool
    3244                 :         198 : vectorizable_bswap (vec_info *vinfo,
    3245                 :             :                     stmt_vec_info stmt_info, gimple_stmt_iterator *gsi,
    3246                 :             :                     gimple **vec_stmt, slp_tree slp_node,
    3247                 :             :                     slp_tree *slp_op,
    3248                 :             :                     tree vectype_in, stmt_vector_for_cost *cost_vec)
    3249                 :             : {
    3250                 :         198 :   tree op, vectype;
    3251                 :         198 :   gcall *stmt = as_a <gcall *> (stmt_info->stmt);
    3252                 :         198 :   loop_vec_info loop_vinfo = dyn_cast <loop_vec_info> (vinfo);
    3253                 :         198 :   unsigned ncopies;
    3254                 :             : 
    3255                 :         198 :   op = gimple_call_arg (stmt, 0);
    3256                 :         198 :   vectype = STMT_VINFO_VECTYPE (stmt_info);
    3257                 :         198 :   poly_uint64 nunits = TYPE_VECTOR_SUBPARTS (vectype);
    3258                 :             : 
    3259                 :             :   /* Multiple types in SLP are handled by creating the appropriate number of
    3260                 :             :      vectorized stmts for each SLP node.  Hence, NCOPIES is always 1 in
    3261                 :             :      case of SLP.  */
    3262                 :         198 :   if (slp_node)
    3263                 :             :     ncopies = 1;
    3264                 :             :   else
    3265                 :           0 :     ncopies = vect_get_num_copies (loop_vinfo, vectype);
    3266                 :             : 
    3267                 :           0 :   gcc_assert (ncopies >= 1);
    3268                 :             : 
    3269                 :         198 :   if (TYPE_SIZE (vectype_in) != TYPE_SIZE (vectype))
    3270                 :             :     {
    3271                 :           0 :       if (dump_enabled_p ())
    3272                 :           0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    3273                 :             :                          "mismatched vector sizes %T and %T\n",
    3274                 :             :                          vectype_in, vectype);
    3275                 :           0 :       return false;
    3276                 :             :     }
    3277                 :             : 
    3278                 :         198 :   tree char_vectype = get_same_sized_vectype (char_type_node, vectype_in);
    3279                 :         198 :   if (! char_vectype)
    3280                 :             :     return false;
    3281                 :             : 
    3282                 :         198 :   poly_uint64 num_bytes = TYPE_VECTOR_SUBPARTS (char_vectype);
    3283                 :         198 :   unsigned word_bytes;
    3284                 :         198 :   if (!constant_multiple_p (num_bytes, nunits, &word_bytes))
    3285                 :             :     return false;
    3286                 :             : 
    3287                 :             :   /* The encoding uses one stepped pattern for each byte in the word.  */
    3288                 :         198 :   vec_perm_builder elts (num_bytes, word_bytes, 3);
    3289                 :         792 :   for (unsigned i = 0; i < 3; ++i)
    3290                 :        3282 :     for (unsigned j = 0; j < word_bytes; ++j)
    3291                 :        2688 :       elts.quick_push ((i + 1) * word_bytes - j - 1);
    3292                 :             : 
    3293                 :         198 :   vec_perm_indices indices (elts, 1, num_bytes);
    3294                 :         198 :   machine_mode vmode = TYPE_MODE (char_vectype);
    3295                 :         198 :   if (!can_vec_perm_const_p (vmode, vmode, indices))
    3296                 :             :     return false;
    3297                 :             : 
    3298                 :         152 :   if (! vec_stmt)
    3299                 :             :     {
    3300                 :         140 :       if (slp_node
    3301                 :         140 :           && !vect_maybe_update_slp_op_vectype (slp_op[0], vectype_in))
    3302                 :             :         {
    3303                 :           0 :           if (dump_enabled_p ())
    3304                 :           0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    3305                 :             :                              "incompatible vector types for invariants\n");
    3306                 :           0 :           return false;
    3307                 :             :         }
    3308                 :             : 
    3309                 :         140 :       STMT_VINFO_TYPE (stmt_info) = call_vec_info_type;
    3310                 :         140 :       DUMP_VECT_SCOPE ("vectorizable_bswap");
    3311                 :         140 :       record_stmt_cost (cost_vec,
    3312                 :             :                         1, vector_stmt, stmt_info, 0, vect_prologue);
    3313                 :         140 :       record_stmt_cost (cost_vec,
    3314                 :             :                         slp_node
    3315                 :         140 :                         ? SLP_TREE_NUMBER_OF_VEC_STMTS (slp_node) : ncopies,
    3316                 :             :                         vec_perm, stmt_info, 0, vect_body);
    3317                 :         140 :       return true;
    3318                 :             :     }
    3319                 :             : 
    3320                 :          12 :   tree bswap_vconst = vec_perm_indices_to_tree (char_vectype, indices);
    3321                 :             : 
    3322                 :             :   /* Transform.  */
    3323                 :          12 :   vec<tree> vec_oprnds = vNULL;
    3324                 :          12 :   vect_get_vec_defs (vinfo, stmt_info, slp_node, ncopies,
    3325                 :             :                      op, &vec_oprnds);
    3326                 :             :   /* Arguments are ready. create the new vector stmt.  */
    3327                 :          12 :   unsigned i;
    3328                 :          12 :   tree vop;
    3329                 :          24 :   FOR_EACH_VEC_ELT (vec_oprnds, i, vop)
    3330                 :             :     {
    3331                 :          12 :       gimple *new_stmt;
    3332                 :          12 :       tree tem = make_ssa_name (char_vectype);
    3333                 :          12 :       new_stmt = gimple_build_assign (tem, build1 (VIEW_CONVERT_EXPR,
    3334                 :             :                                                    char_vectype, vop));
    3335                 :          12 :       vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    3336                 :          12 :       tree tem2 = make_ssa_name (char_vectype);
    3337                 :          12 :       new_stmt = gimple_build_assign (tem2, VEC_PERM_EXPR,
    3338                 :             :                                       tem, tem, bswap_vconst);
    3339                 :          12 :       vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    3340                 :          12 :       tem = make_ssa_name (vectype);
    3341                 :          12 :       new_stmt = gimple_build_assign (tem, build1 (VIEW_CONVERT_EXPR,
    3342                 :             :                                                    vectype, tem2));
    3343                 :          12 :       vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    3344                 :          12 :       if (slp_node)
    3345                 :          12 :         slp_node->push_vec_def (new_stmt);
    3346                 :             :       else
    3347                 :           0 :         STMT_VINFO_VEC_STMTS (stmt_info).safe_push (new_stmt);
    3348                 :             :     }
    3349                 :             : 
    3350                 :          12 :   if (!slp_node)
    3351                 :           0 :     *vec_stmt = STMT_VINFO_VEC_STMTS (stmt_info)[0];
    3352                 :             : 
    3353                 :          12 :   vec_oprnds.release ();
    3354                 :          12 :   return true;
    3355                 :         198 : }
    3356                 :             : 
    3357                 :             : /* Return true if vector types VECTYPE_IN and VECTYPE_OUT have
    3358                 :             :    integer elements and if we can narrow VECTYPE_IN to VECTYPE_OUT
    3359                 :             :    in a single step.  On success, store the binary pack code in
    3360                 :             :    *CONVERT_CODE.  */
    3361                 :             : 
    3362                 :             : static bool
    3363                 :         165 : simple_integer_narrowing (tree vectype_out, tree vectype_in,
    3364                 :             :                           code_helper *convert_code)
    3365                 :             : {
    3366                 :         330 :   if (!INTEGRAL_TYPE_P (TREE_TYPE (vectype_out))
    3367                 :         330 :       || !INTEGRAL_TYPE_P (TREE_TYPE (vectype_in)))
    3368                 :             :     return false;
    3369                 :             : 
    3370                 :          75 :   code_helper code;
    3371                 :          75 :   int multi_step_cvt = 0;
    3372                 :          75 :   auto_vec <tree, 8> interm_types;
    3373                 :         116 :   if (!supportable_narrowing_operation (NOP_EXPR, vectype_out, vectype_in,
    3374                 :             :                                         &code, &multi_step_cvt, &interm_types)
    3375                 :          75 :       || multi_step_cvt)
    3376                 :          41 :     return false;
    3377                 :             : 
    3378                 :          34 :   *convert_code = code;
    3379                 :          34 :   return true;
    3380                 :          75 : }
    3381                 :             : 
    3382                 :             : /* Function vectorizable_call.
    3383                 :             : 
    3384                 :             :    Check if STMT_INFO performs a function call that can be vectorized.
    3385                 :             :    If VEC_STMT is also passed, vectorize STMT_INFO: create a vectorized
    3386                 :             :    stmt to replace it, put it in VEC_STMT, and insert it at GSI.
    3387                 :             :    Return true if STMT_INFO is vectorizable in this way.  */
    3388                 :             : 
    3389                 :             : static bool
    3390                 :     2518395 : vectorizable_call (vec_info *vinfo,
    3391                 :             :                    stmt_vec_info stmt_info, gimple_stmt_iterator *gsi,
    3392                 :             :                    gimple **vec_stmt, slp_tree slp_node,
    3393                 :             :                    stmt_vector_for_cost *cost_vec)
    3394                 :             : {
    3395                 :     2518395 :   gcall *stmt;
    3396                 :     2518395 :   tree vec_dest;
    3397                 :     2518395 :   tree scalar_dest;
    3398                 :     2518395 :   tree op;
    3399                 :     2518395 :   tree vec_oprnd0 = NULL_TREE, vec_oprnd1 = NULL_TREE;
    3400                 :     2518395 :   tree vectype_out, vectype_in;
    3401                 :     2518395 :   poly_uint64 nunits_in;
    3402                 :     2518395 :   poly_uint64 nunits_out;
    3403                 :     2518395 :   loop_vec_info loop_vinfo = dyn_cast <loop_vec_info> (vinfo);
    3404                 :     2518395 :   bb_vec_info bb_vinfo = dyn_cast <bb_vec_info> (vinfo);
    3405                 :     2518395 :   tree fndecl, new_temp, rhs_type;
    3406                 :     2518395 :   enum vect_def_type dt[4]
    3407                 :             :     = { vect_unknown_def_type, vect_unknown_def_type, vect_unknown_def_type,
    3408                 :             :         vect_unknown_def_type };
    3409                 :     2518395 :   tree vectypes[ARRAY_SIZE (dt)] = {};
    3410                 :     2518395 :   slp_tree slp_op[ARRAY_SIZE (dt)] = {};
    3411                 :     2518395 :   int ndts = ARRAY_SIZE (dt);
    3412                 :     2518395 :   int ncopies, j;
    3413                 :     2518395 :   auto_vec<tree, 8> vargs;
    3414                 :     2518395 :   enum { NARROW, NONE, WIDEN } modifier;
    3415                 :     2518395 :   size_t i, nargs;
    3416                 :     2518395 :   tree lhs;
    3417                 :     2518395 :   tree clz_ctz_arg1 = NULL_TREE;
    3418                 :             : 
    3419                 :     2518395 :   if (!STMT_VINFO_RELEVANT_P (stmt_info) && !bb_vinfo)
    3420                 :             :     return false;
    3421                 :             : 
    3422                 :     2518395 :   if (STMT_VINFO_DEF_TYPE (stmt_info) != vect_internal_def
    3423                 :      200344 :       && ! vec_stmt)
    3424                 :             :     return false;
    3425                 :             : 
    3426                 :             :   /* Is STMT_INFO a vectorizable call?   */
    3427                 :     2528119 :   stmt = dyn_cast <gcall *> (stmt_info->stmt);
    3428                 :       18994 :   if (!stmt)
    3429                 :             :     return false;
    3430                 :             : 
    3431                 :       18994 :   if (gimple_call_internal_p (stmt)
    3432                 :       18994 :       && (internal_load_fn_p (gimple_call_internal_fn (stmt))
    3433                 :       11313 :           || internal_store_fn_p (gimple_call_internal_fn (stmt))))
    3434                 :             :     /* Handled by vectorizable_load and vectorizable_store.  */
    3435                 :        2842 :     return false;
    3436                 :             : 
    3437                 :       16152 :   if (gimple_call_lhs (stmt) == NULL_TREE
    3438                 :       16152 :       || TREE_CODE (gimple_call_lhs (stmt)) != SSA_NAME)
    3439                 :             :     return false;
    3440                 :             : 
    3441                 :       16152 :   gcc_checking_assert (!stmt_can_throw_internal (cfun, stmt));
    3442                 :             : 
    3443                 :       16152 :   vectype_out = STMT_VINFO_VECTYPE (stmt_info);
    3444                 :             : 
    3445                 :             :   /* Process function arguments.  */
    3446                 :       16152 :   rhs_type = NULL_TREE;
    3447                 :       16152 :   vectype_in = NULL_TREE;
    3448                 :       16152 :   nargs = gimple_call_num_args (stmt);
    3449                 :             : 
    3450                 :             :   /* Bail out if the function has more than four arguments, we do not have
    3451                 :             :      interesting builtin functions to vectorize with more than two arguments
    3452                 :             :      except for fma.  No arguments is also not good.  */
    3453                 :       16152 :   if (nargs == 0 || nargs > 4)
    3454                 :             :     return false;
    3455                 :             : 
    3456                 :             :   /* Ignore the arguments of IFN_GOMP_SIMD_LANE, they are magic.  */
    3457                 :       16136 :   combined_fn cfn = gimple_call_combined_fn (stmt);
    3458                 :       16136 :   if (cfn == CFN_GOMP_SIMD_LANE)
    3459                 :             :     {
    3460                 :        3629 :       nargs = 0;
    3461                 :        3629 :       rhs_type = unsigned_type_node;
    3462                 :             :     }
    3463                 :             :   /* Similarly pretend IFN_CLZ and IFN_CTZ only has one argument, the second
    3464                 :             :      argument just says whether it is well-defined at zero or not and what
    3465                 :             :      value should be returned for it.  */
    3466                 :       16136 :   if ((cfn == CFN_CLZ || cfn == CFN_CTZ) && nargs == 2)
    3467                 :             :     {
    3468                 :         118 :       nargs = 1;
    3469                 :         118 :       clz_ctz_arg1 = gimple_call_arg (stmt, 1);
    3470                 :             :     }
    3471                 :             : 
    3472                 :       16136 :   int mask_opno = -1;
    3473                 :       16136 :   if (internal_fn_p (cfn))
    3474                 :       13134 :     mask_opno = internal_fn_mask_index (as_internal_fn (cfn));
    3475                 :             : 
    3476                 :       43456 :   for (i = 0; i < nargs; i++)
    3477                 :             :     {
    3478                 :       28685 :       if ((int) i == mask_opno)
    3479                 :             :         {
    3480                 :        3834 :           if (!vect_check_scalar_mask (vinfo, stmt_info, slp_node, mask_opno,
    3481                 :             :                                        &op, &slp_op[i], &dt[i], &vectypes[i]))
    3482                 :             :             return false;
    3483                 :        3834 :           continue;
    3484                 :             :         }
    3485                 :             : 
    3486                 :       24851 :       if (!vect_is_simple_use (vinfo, stmt_info, slp_node,
    3487                 :             :                                i, &op, &slp_op[i], &dt[i], &vectypes[i]))
    3488                 :             :         {
    3489                 :           0 :           if (dump_enabled_p ())
    3490                 :           0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    3491                 :             :                              "use not simple.\n");
    3492                 :           0 :           return false;
    3493                 :             :         }
    3494                 :             : 
    3495                 :             :       /* We can only handle calls with arguments of the same type.  */
    3496                 :       24851 :       if (rhs_type
    3497                 :       24851 :           && !types_compatible_p (rhs_type, TREE_TYPE (op)))
    3498                 :             :         {
    3499                 :        1365 :           if (dump_enabled_p ())
    3500                 :         337 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    3501                 :             :                              "argument types differ.\n");
    3502                 :        1365 :           return false;
    3503                 :             :         }
    3504                 :       23486 :       if (!rhs_type)
    3505                 :       12507 :         rhs_type = TREE_TYPE (op);
    3506                 :             : 
    3507                 :       23486 :       if (!vectype_in)
    3508                 :       13157 :         vectype_in = vectypes[i];
    3509                 :       10329 :       else if (vectypes[i]
    3510                 :       10329 :                && !types_compatible_p (vectypes[i], vectype_in))
    3511                 :             :         {
    3512                 :           0 :           if (dump_enabled_p ())
    3513                 :           0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    3514                 :             :                              "argument vector types differ.\n");
    3515                 :           0 :           return false;
    3516                 :             :         }
    3517                 :             :     }
    3518                 :             :   /* If all arguments are external or constant defs, infer the vector type
    3519                 :             :      from the scalar type.  */
    3520                 :       14771 :   if (!vectype_in)
    3521                 :        6068 :     vectype_in = get_vectype_for_scalar_type (vinfo, rhs_type, slp_node);
    3522                 :       14771 :   if (vec_stmt)
    3523                 :        3472 :     gcc_assert (vectype_in);
    3524                 :       11299 :   if (!vectype_in)
    3525                 :             :     {
    3526                 :        1004 :       if (dump_enabled_p ())
    3527                 :           6 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    3528                 :             :                          "no vectype for scalar type %T\n", rhs_type);
    3529                 :             : 
    3530                 :        1004 :       return false;
    3531                 :             :     }
    3532                 :             : 
    3533                 :       27534 :   if (VECTOR_BOOLEAN_TYPE_P (vectype_out)
    3534                 :       13767 :       != VECTOR_BOOLEAN_TYPE_P (vectype_in))
    3535                 :             :     {
    3536                 :          12 :       if (dump_enabled_p ())
    3537                 :          12 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    3538                 :             :                          "mixed mask and nonmask vector types\n");
    3539                 :          12 :       return false;
    3540                 :             :     }
    3541                 :             : 
    3542                 :       13755 :   if (vect_emulated_vector_p (vectype_in) || vect_emulated_vector_p (vectype_out))
    3543                 :             :   {
    3544                 :           0 :       if (dump_enabled_p ())
    3545                 :           0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    3546                 :             :                          "use emulated vector type for call\n");
    3547                 :           0 :       return false;
    3548                 :             :   }
    3549                 :             : 
    3550                 :             :   /* FORNOW */
    3551                 :       13755 :   nunits_in = TYPE_VECTOR_SUBPARTS (vectype_in);
    3552                 :       13755 :   nunits_out = TYPE_VECTOR_SUBPARTS (vectype_out);
    3553                 :       13755 :   if (known_eq (nunits_in * 2, nunits_out))
    3554                 :             :     modifier = NARROW;
    3555                 :       13348 :   else if (known_eq (nunits_out, nunits_in))
    3556                 :             :     modifier = NONE;
    3557                 :          23 :   else if (known_eq (nunits_out * 2, nunits_in))
    3558                 :             :     modifier = WIDEN;
    3559                 :             :   else
    3560                 :             :     return false;
    3561                 :             : 
    3562                 :             :   /* We only handle functions that do not read or clobber memory.  */
    3563                 :       27510 :   if (gimple_vuse (stmt))
    3564                 :             :     {
    3565                 :        1354 :       if (dump_enabled_p ())
    3566                 :          12 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    3567                 :             :                          "function reads from or writes to memory.\n");
    3568                 :        1354 :       return false;
    3569                 :             :     }
    3570                 :             : 
    3571                 :             :   /* For now, we only vectorize functions if a target specific builtin
    3572                 :             :      is available.  TODO -- in some cases, it might be profitable to
    3573                 :             :      insert the calls for pieces of the vector, in order to be able
    3574                 :             :      to vectorize other operations in the loop.  */
    3575                 :       12401 :   fndecl = NULL_TREE;
    3576                 :       12401 :   internal_fn ifn = IFN_LAST;
    3577                 :       12401 :   tree callee = gimple_call_fndecl (stmt);
    3578                 :             : 
    3579                 :             :   /* First try using an internal function.  */
    3580                 :       12401 :   code_helper convert_code = MAX_TREE_CODES;
    3581                 :       12401 :   if (cfn != CFN_LAST
    3582                 :       12401 :       && (modifier == NONE
    3583                 :         185 :           || (modifier == NARROW
    3584                 :         165 :               && simple_integer_narrowing (vectype_out, vectype_in,
    3585                 :             :                                            &convert_code))))
    3586                 :       11622 :     ifn = vectorizable_internal_function (cfn, callee, vectype_out,
    3587                 :             :                                           vectype_in);
    3588                 :             : 
    3589                 :             :   /* If that fails, try asking for a target-specific built-in function.  */
    3590                 :       11622 :   if (ifn == IFN_LAST)
    3591                 :             :     {
    3592                 :        7252 :       if (cfn != CFN_LAST)
    3593                 :        6624 :         fndecl = targetm.vectorize.builtin_vectorized_function
    3594                 :        6624 :           (cfn, vectype_out, vectype_in);
    3595                 :         628 :       else if (callee && fndecl_built_in_p (callee, BUILT_IN_MD))
    3596                 :          36 :         fndecl = targetm.vectorize.builtin_md_vectorized_function
    3597                 :          36 :           (callee, vectype_out, vectype_in);
    3598                 :             :     }
    3599                 :             : 
    3600                 :       12401 :   if (ifn == IFN_LAST && !fndecl)
    3601                 :             :     {
    3602                 :        6958 :       if (cfn == CFN_GOMP_SIMD_LANE
    3603                 :        3629 :           && (!slp_node || SLP_TREE_LANES (slp_node) == 1)
    3604                 :        3629 :           && loop_vinfo
    3605                 :        3629 :           && LOOP_VINFO_LOOP (loop_vinfo)->simduid
    3606                 :        3629 :           && TREE_CODE (gimple_call_arg (stmt, 0)) == SSA_NAME
    3607                 :       14216 :           && LOOP_VINFO_LOOP (loop_vinfo)->simduid
    3608                 :        3629 :              == SSA_NAME_VAR (gimple_call_arg (stmt, 0)))
    3609                 :             :         {
    3610                 :             :           /* We can handle IFN_GOMP_SIMD_LANE by returning a
    3611                 :             :              { 0, 1, 2, ... vf - 1 } vector.  */
    3612                 :        3629 :           gcc_assert (nargs == 0);
    3613                 :             :         }
    3614                 :        3329 :       else if (modifier == NONE
    3615                 :        3329 :                && (gimple_call_builtin_p (stmt, BUILT_IN_BSWAP16)
    3616                 :        3166 :                    || gimple_call_builtin_p (stmt, BUILT_IN_BSWAP32)
    3617                 :        3018 :                    || gimple_call_builtin_p (stmt, BUILT_IN_BSWAP64)
    3618                 :        2984 :                    || gimple_call_builtin_p (stmt, BUILT_IN_BSWAP128)))
    3619                 :         198 :         return vectorizable_bswap (vinfo, stmt_info, gsi, vec_stmt, slp_node,
    3620                 :         198 :                                    slp_op, vectype_in, cost_vec);
    3621                 :             :       else
    3622                 :             :         {
    3623                 :        3131 :           if (dump_enabled_p ())
    3624                 :         234 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    3625                 :             :                              "function is not vectorizable.\n");
    3626                 :        3131 :           return false;
    3627                 :             :         }
    3628                 :             :     }
    3629                 :             : 
    3630                 :        9072 :   if (slp_node)
    3631                 :             :     ncopies = 1;
    3632                 :           0 :   else if (modifier == NARROW && ifn == IFN_LAST)
    3633                 :           0 :     ncopies = vect_get_num_copies (loop_vinfo, vectype_out);
    3634                 :             :   else
    3635                 :           0 :     ncopies = vect_get_num_copies (loop_vinfo, vectype_in);
    3636                 :             : 
    3637                 :             :   /* Sanity check: make sure that at least one copy of the vectorized stmt
    3638                 :             :      needs to be generated.  */
    3639                 :           0 :   gcc_assert (ncopies >= 1);
    3640                 :             : 
    3641                 :        9072 :   int reduc_idx = STMT_VINFO_REDUC_IDX (stmt_info);
    3642                 :        9072 :   internal_fn cond_fn = get_conditional_internal_fn (ifn);
    3643                 :        9072 :   internal_fn cond_len_fn = get_len_internal_fn (ifn);
    3644                 :        9072 :   int len_opno = internal_fn_len_index (cond_len_fn);
    3645                 :        9072 :   vec_loop_masks *masks = (loop_vinfo ? &LOOP_VINFO_MASKS (loop_vinfo) : NULL);
    3646                 :        8002 :   vec_loop_lens *lens = (loop_vinfo ? &LOOP_VINFO_LENS (loop_vinfo) : NULL);
    3647                 :        9072 :   if (!vec_stmt) /* transformation not required.  */
    3648                 :             :     {
    3649                 :        5612 :       if (slp_node)
    3650                 :       15655 :         for (i = 0; i < nargs; ++i)
    3651                 :       10043 :           if (!vect_maybe_update_slp_op_vectype (slp_op[i],
    3652                 :       10043 :                                                  vectypes[i]
    3653                 :             :                                                  ? vectypes[i] : vectype_in))
    3654                 :             :             {
    3655                 :           0 :               if (dump_enabled_p ())
    3656                 :           0 :                 dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    3657                 :             :                                  "incompatible vector types for invariants\n");
    3658                 :           0 :               return false;
    3659                 :             :             }
    3660                 :        5612 :       STMT_VINFO_TYPE (stmt_info) = call_vec_info_type;
    3661                 :        5612 :       DUMP_VECT_SCOPE ("vectorizable_call");
    3662                 :        5612 :       vect_model_simple_cost (vinfo, ncopies, dt, ndts, slp_node, cost_vec);
    3663                 :        5612 :       if (ifn != IFN_LAST && modifier == NARROW && !slp_node)
    3664                 :           0 :         record_stmt_cost (cost_vec, ncopies / 2,
    3665                 :             :                           vec_promote_demote, stmt_info, 0, vect_body);
    3666                 :             : 
    3667                 :        5612 :       if (loop_vinfo
    3668                 :        4834 :           && LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo)
    3669                 :          19 :           && (reduc_idx >= 0 || mask_opno >= 0))
    3670                 :             :         {
    3671                 :          18 :           if (reduc_idx >= 0
    3672                 :           0 :               && (cond_fn == IFN_LAST
    3673                 :           0 :                   || !direct_internal_fn_supported_p (cond_fn, vectype_out,
    3674                 :             :                                                       OPTIMIZE_FOR_SPEED))
    3675                 :          18 :               && (cond_len_fn == IFN_LAST
    3676                 :           0 :                   || !direct_internal_fn_supported_p (cond_len_fn, vectype_out,
    3677                 :             :                                                       OPTIMIZE_FOR_SPEED)))
    3678                 :             :             {
    3679                 :           0 :               if (dump_enabled_p ())
    3680                 :           0 :                 dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    3681                 :             :                                  "can't use a fully-masked loop because no"
    3682                 :             :                                  " conditional operation is available.\n");
    3683                 :           0 :               LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo) = false;
    3684                 :             :             }
    3685                 :             :           else
    3686                 :             :             {
    3687                 :          18 :               unsigned int nvectors
    3688                 :             :                 = (slp_node
    3689                 :          18 :                    ? SLP_TREE_NUMBER_OF_VEC_STMTS (slp_node)
    3690                 :             :                    : ncopies);
    3691                 :          18 :               tree scalar_mask = NULL_TREE;
    3692                 :          18 :               if (mask_opno >= 0)
    3693                 :          18 :                 scalar_mask = gimple_call_arg (stmt_info->stmt, mask_opno);
    3694                 :          18 :               if (cond_len_fn != IFN_LAST
    3695                 :          18 :                   && direct_internal_fn_supported_p (cond_len_fn, vectype_out,
    3696                 :             :                                                      OPTIMIZE_FOR_SPEED))
    3697                 :           0 :                 vect_record_loop_len (loop_vinfo, lens, nvectors, vectype_out,
    3698                 :             :                                       1);
    3699                 :             :               else
    3700                 :          18 :                 vect_record_loop_mask (loop_vinfo, masks, nvectors, vectype_out,
    3701                 :             :                                        scalar_mask);
    3702                 :             :             }
    3703                 :             :         }
    3704                 :        5612 :       return true;
    3705                 :             :     }
    3706                 :             : 
    3707                 :             :   /* Transform.  */
    3708                 :             : 
    3709                 :        3460 :   if (dump_enabled_p ())
    3710                 :         398 :     dump_printf_loc (MSG_NOTE, vect_location, "transform call.\n");
    3711                 :             : 
    3712                 :             :   /* Handle def.  */
    3713                 :        3460 :   scalar_dest = gimple_call_lhs (stmt);
    3714                 :        3460 :   vec_dest = vect_create_destination_var (scalar_dest, vectype_out);
    3715                 :             : 
    3716                 :        3460 :   bool masked_loop_p = loop_vinfo && LOOP_VINFO_FULLY_MASKED_P (loop_vinfo);
    3717                 :        3168 :   bool len_loop_p = loop_vinfo && LOOP_VINFO_FULLY_WITH_LENGTH_P (loop_vinfo);
    3718                 :        3460 :   unsigned int vect_nargs = nargs;
    3719                 :        3460 :   if (len_loop_p)
    3720                 :             :     {
    3721                 :           0 :       if (len_opno >= 0)
    3722                 :             :         {
    3723                 :           0 :           ifn = cond_len_fn;
    3724                 :             :           /* COND_* -> COND_LEN_* takes 2 extra arguments:LEN,BIAS.  */
    3725                 :           0 :           vect_nargs += 2;
    3726                 :             :         }
    3727                 :           0 :       else if (reduc_idx >= 0)
    3728                 :           0 :         gcc_unreachable ();
    3729                 :             :     }
    3730                 :        3460 :   else if (masked_loop_p && reduc_idx >= 0)
    3731                 :             :     {
    3732                 :           0 :       ifn = cond_fn;
    3733                 :           0 :       vect_nargs += 2;
    3734                 :             :     }
    3735                 :        3460 :   if (clz_ctz_arg1)
    3736                 :          59 :     ++vect_nargs;
    3737                 :             : 
    3738                 :        3460 :   if (modifier == NONE || ifn != IFN_LAST)
    3739                 :             :     {
    3740                 :        3428 :       tree prev_res = NULL_TREE;
    3741                 :        3428 :       vargs.safe_grow (vect_nargs, true);
    3742                 :        3428 :       auto_vec<vec<tree> > vec_defs (nargs);
    3743                 :        6856 :       for (j = 0; j < ncopies; ++j)
    3744                 :             :         {
    3745                 :             :           /* Build argument list for the vectorized call.  */
    3746                 :        3428 :           if (slp_node)
    3747                 :             :             {
    3748                 :        3428 :               if (cfn == CFN_GOMP_SIMD_LANE)
    3749                 :             :                 {
    3750                 :        3290 :                   for (i = 0; i < SLP_TREE_NUMBER_OF_VEC_STMTS (slp_node); ++i)
    3751                 :             :                     {
    3752                 :             :                       /* ???  For multi-lane SLP we'd need to build
    3753                 :             :                          { 0, 0, .., 1, 1, ... }.  */
    3754                 :        1699 :                       tree cst = build_index_vector (vectype_out,
    3755                 :             :                                                      i * nunits_out, 1);
    3756                 :        1699 :                       tree new_var
    3757                 :        1699 :                           = vect_get_new_ssa_name (vectype_out, vect_simple_var,
    3758                 :             :                                                    "cst_");
    3759                 :        1699 :                       gimple *init_stmt = gimple_build_assign (new_var, cst);
    3760                 :        1699 :                       vect_init_vector_1 (vinfo, stmt_info, init_stmt, NULL);
    3761                 :        1699 :                       new_temp = make_ssa_name (vec_dest);
    3762                 :        1699 :                       gimple *new_stmt
    3763                 :        1699 :                         = gimple_build_assign (new_temp, new_var);
    3764                 :        1699 :                       vect_finish_stmt_generation (vinfo, stmt_info, new_stmt,
    3765                 :             :                                                    gsi);
    3766                 :        1699 :                       slp_node->push_vec_def (new_stmt);
    3767                 :             :                     }
    3768                 :        1591 :                   continue;
    3769                 :        1591 :                 }
    3770                 :             : 
    3771                 :        1837 :               vec<tree> vec_oprnds0;
    3772                 :        1837 :               vect_get_slp_defs (vinfo, slp_node, &vec_defs);
    3773                 :        1837 :               vec_oprnds0 = vec_defs[0];
    3774                 :             : 
    3775                 :             :               /* Arguments are ready.  Create the new vector stmt.  */
    3776                 :        3799 :               FOR_EACH_VEC_ELT (vec_oprnds0, i, vec_oprnd0)
    3777                 :             :                 {
    3778                 :        1962 :                   int varg = 0;
    3779                 :        1962 :                   if (masked_loop_p && reduc_idx >= 0)
    3780                 :             :                     {
    3781                 :           0 :                       unsigned int vec_num = vec_oprnds0.length ();
    3782                 :             :                       /* Always true for SLP.  */
    3783                 :           0 :                       gcc_assert (ncopies == 1);
    3784                 :           0 :                       vargs[varg++] = vect_get_loop_mask (loop_vinfo,
    3785                 :             :                                                           gsi, masks, vec_num,
    3786                 :             :                                                           vectype_out, i);
    3787                 :             :                     }
    3788                 :             :                   size_t k;
    3789                 :        7270 :                   for (k = 0; k < nargs; k++)
    3790                 :             :                     {
    3791                 :        5308 :                       vec<tree> vec_oprndsk = vec_defs[k];
    3792                 :        5308 :                       vargs[varg++] = vec_oprndsk[i];
    3793                 :             :                     }
    3794                 :        1962 :                   if (masked_loop_p && reduc_idx >= 0)
    3795                 :           0 :                     vargs[varg++] = vargs[reduc_idx + 1];
    3796                 :        1962 :                   if (clz_ctz_arg1)
    3797                 :          59 :                     vargs[varg++] = clz_ctz_arg1;
    3798                 :             : 
    3799                 :        1962 :                   gimple *new_stmt;
    3800                 :        1962 :                   if (modifier == NARROW)
    3801                 :             :                     {
    3802                 :             :                       /* We don't define any narrowing conditional functions
    3803                 :             :                          at present.  */
    3804                 :           0 :                       gcc_assert (mask_opno < 0);
    3805                 :           0 :                       tree half_res = make_ssa_name (vectype_in);
    3806                 :           0 :                       gcall *call
    3807                 :           0 :                         = gimple_build_call_internal_vec (ifn, vargs);
    3808                 :           0 :                       gimple_call_set_lhs (call, half_res);
    3809                 :           0 :                       gimple_call_set_nothrow (call, true);
    3810                 :           0 :                       vect_finish_stmt_generation (vinfo, stmt_info, call, gsi);
    3811                 :           0 :                       if ((i & 1) == 0)
    3812                 :             :                         {
    3813                 :           0 :                           prev_res = half_res;
    3814                 :           0 :                           continue;
    3815                 :             :                         }
    3816                 :           0 :                       new_temp = make_ssa_name (vec_dest);
    3817                 :           0 :                       new_stmt = vect_gimple_build (new_temp, convert_code,
    3818                 :             :                                                     prev_res, half_res);
    3819                 :           0 :                       vect_finish_stmt_generation (vinfo, stmt_info,
    3820                 :             :                                                    new_stmt, gsi);
    3821                 :             :                     }
    3822                 :             :                   else
    3823                 :             :                     {
    3824                 :        1962 :                       if (len_opno >= 0 && len_loop_p)
    3825                 :             :                         {
    3826                 :           0 :                           unsigned int vec_num = vec_oprnds0.length ();
    3827                 :             :                           /* Always true for SLP.  */
    3828                 :           0 :                           gcc_assert (ncopies == 1);
    3829                 :           0 :                           tree len
    3830                 :           0 :                             = vect_get_loop_len (loop_vinfo, gsi, lens, vec_num,
    3831                 :             :                                                  vectype_out, i, 1);
    3832                 :           0 :                           signed char biasval
    3833                 :           0 :                             = LOOP_VINFO_PARTIAL_LOAD_STORE_BIAS (loop_vinfo);
    3834                 :           0 :                           tree bias = build_int_cst (intQI_type_node, biasval);
    3835                 :           0 :                           vargs[len_opno] = len;
    3836                 :           0 :                           vargs[len_opno + 1] = bias;
    3837                 :             :                         }
    3838                 :        1962 :                       else if (mask_opno >= 0 && masked_loop_p)
    3839                 :             :                         {
    3840                 :          36 :                           unsigned int vec_num = vec_oprnds0.length ();
    3841                 :             :                           /* Always true for SLP.  */
    3842                 :          36 :                           gcc_assert (ncopies == 1);
    3843                 :          36 :                           tree mask = vect_get_loop_mask (loop_vinfo,
    3844                 :             :                                                           gsi, masks, vec_num,
    3845                 :             :                                                           vectype_out, i);
    3846                 :          36 :                           vargs[mask_opno] = prepare_vec_mask
    3847                 :          36 :                             (loop_vinfo, TREE_TYPE (mask), mask,
    3848                 :          36 :                              vargs[mask_opno], gsi);
    3849                 :             :                         }
    3850                 :             : 
    3851                 :        1962 :                       gcall *call;
    3852                 :        1962 :                       if (ifn != IFN_LAST)
    3853                 :        1881 :                         call = gimple_build_call_internal_vec (ifn, vargs);
    3854                 :             :                       else
    3855                 :          81 :                         call = gimple_build_call_vec (fndecl, vargs);
    3856                 :        1962 :                       new_temp = make_ssa_name (vec_dest, call);
    3857                 :        1962 :                       gimple_call_set_lhs (call, new_temp);
    3858                 :        1962 :                       gimple_call_set_nothrow (call, true);
    3859                 :        1962 :                       vect_finish_stmt_generation (vinfo, stmt_info, call, gsi);
    3860                 :        1962 :                       new_stmt = call;
    3861                 :             :                     }
    3862                 :        1962 :                   slp_node->push_vec_def (new_stmt);
    3863                 :             :                 }
    3864                 :        1837 :               continue;
    3865                 :        1837 :             }
    3866                 :             : 
    3867                 :           0 :           int varg = 0;
    3868                 :           0 :           if (masked_loop_p && reduc_idx >= 0)
    3869                 :           0 :             vargs[varg++] = vect_get_loop_mask (loop_vinfo, gsi, masks, ncopies,
    3870                 :             :                                                 vectype_out, j);
    3871                 :           0 :           for (i = 0; i < nargs; i++)
    3872                 :             :             {
    3873                 :           0 :               op = gimple_call_arg (stmt, i);
    3874                 :           0 :               if (j == 0)
    3875                 :             :                 {
    3876                 :           0 :                   vec_defs.quick_push (vNULL);
    3877                 :           0 :                   vect_get_vec_defs_for_operand (vinfo, stmt_info, ncopies,
    3878                 :           0 :                                                  op, &vec_defs[i],
    3879                 :             :                                                  vectypes[i]);
    3880                 :             :                 }
    3881                 :           0 :               vargs[varg++] = vec_defs[i][j];
    3882                 :             :             }
    3883                 :           0 :           if (masked_loop_p && reduc_idx >= 0)
    3884                 :           0 :             vargs[varg++] = vargs[reduc_idx + 1];
    3885                 :           0 :           if (clz_ctz_arg1)
    3886                 :           0 :             vargs[varg++] = clz_ctz_arg1;
    3887                 :             : 
    3888                 :           0 :           if (len_opno >= 0 && len_loop_p)
    3889                 :             :             {
    3890                 :           0 :               tree len = vect_get_loop_len (loop_vinfo, gsi, lens, ncopies,
    3891                 :             :                                             vectype_out, j, 1);
    3892                 :           0 :               signed char biasval
    3893                 :           0 :                 = LOOP_VINFO_PARTIAL_LOAD_STORE_BIAS (loop_vinfo);
    3894                 :           0 :               tree bias = build_int_cst (intQI_type_node, biasval);
    3895                 :           0 :               vargs[len_opno] = len;
    3896                 :           0 :               vargs[len_opno + 1] = bias;
    3897                 :             :             }
    3898                 :           0 :           else if (mask_opno >= 0 && masked_loop_p)
    3899                 :             :             {
    3900                 :           0 :               tree mask = vect_get_loop_mask (loop_vinfo, gsi, masks, ncopies,
    3901                 :             :                                               vectype_out, j);
    3902                 :           0 :               vargs[mask_opno]
    3903                 :           0 :                 = prepare_vec_mask (loop_vinfo, TREE_TYPE (mask), mask,
    3904                 :           0 :                                     vargs[mask_opno], gsi);
    3905                 :             :             }
    3906                 :             : 
    3907                 :           0 :           gimple *new_stmt;
    3908                 :           0 :           if (cfn == CFN_GOMP_SIMD_LANE)
    3909                 :             :             {
    3910                 :           0 :               tree cst = build_index_vector (vectype_out, j * nunits_out, 1);
    3911                 :           0 :               tree new_var
    3912                 :           0 :                 = vect_get_new_ssa_name (vectype_out, vect_simple_var, "cst_");
    3913                 :           0 :               gimple *init_stmt = gimple_build_assign (new_var, cst);
    3914                 :           0 :               vect_init_vector_1 (vinfo, stmt_info, init_stmt, NULL);
    3915                 :           0 :               new_temp = make_ssa_name (vec_dest);
    3916                 :           0 :               new_stmt = gimple_build_assign (new_temp, new_var);
    3917                 :           0 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    3918                 :             :             }
    3919                 :           0 :           else if (modifier == NARROW)
    3920                 :             :             {
    3921                 :             :               /* We don't define any narrowing conditional functions at
    3922                 :             :                  present.  */
    3923                 :           0 :               gcc_assert (mask_opno < 0);
    3924                 :           0 :               tree half_res = make_ssa_name (vectype_in);
    3925                 :           0 :               gcall *call = gimple_build_call_internal_vec (ifn, vargs);
    3926                 :           0 :               gimple_call_set_lhs (call, half_res);
    3927                 :           0 :               gimple_call_set_nothrow (call, true);
    3928                 :           0 :               vect_finish_stmt_generation (vinfo, stmt_info, call, gsi);
    3929                 :           0 :               if ((j & 1) == 0)
    3930                 :             :                 {
    3931                 :           0 :                   prev_res = half_res;
    3932                 :           0 :                   continue;
    3933                 :             :                 }
    3934                 :           0 :               new_temp = make_ssa_name (vec_dest);
    3935                 :           0 :               new_stmt = vect_gimple_build (new_temp, convert_code, prev_res,
    3936                 :             :                                             half_res);
    3937                 :           0 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    3938                 :             :             }
    3939                 :             :           else
    3940                 :             :             {
    3941                 :           0 :               gcall *call;
    3942                 :           0 :               if (ifn != IFN_LAST)
    3943                 :           0 :                 call = gimple_build_call_internal_vec (ifn, vargs);
    3944                 :             :               else
    3945                 :           0 :                 call = gimple_build_call_vec (fndecl, vargs);
    3946                 :           0 :               new_temp = make_ssa_name (vec_dest, call);
    3947                 :           0 :               gimple_call_set_lhs (call, new_temp);
    3948                 :           0 :               gimple_call_set_nothrow (call, true);
    3949                 :           0 :               vect_finish_stmt_generation (vinfo, stmt_info, call, gsi);
    3950                 :           0 :               new_stmt = call;
    3951                 :             :             }
    3952                 :             : 
    3953                 :           0 :           if (j == (modifier == NARROW ? 1 : 0))
    3954                 :           0 :             *vec_stmt = new_stmt;
    3955                 :           0 :           STMT_VINFO_VEC_STMTS (stmt_info).safe_push (new_stmt);
    3956                 :             :         }
    3957                 :        8442 :       for (i = 0; i < nargs; i++)
    3958                 :             :         {
    3959                 :        5014 :           vec<tree> vec_oprndsi = vec_defs[i];
    3960                 :        5014 :           vec_oprndsi.release ();
    3961                 :             :         }
    3962                 :        3428 :     }
    3963                 :          32 :   else if (modifier == NARROW)
    3964                 :             :     {
    3965                 :          32 :       auto_vec<vec<tree> > vec_defs (nargs);
    3966                 :             :       /* We don't define any narrowing conditional functions at present.  */
    3967                 :          32 :       gcc_assert (mask_opno < 0);
    3968                 :          64 :       for (j = 0; j < ncopies; ++j)
    3969                 :             :         {
    3970                 :             :           /* Build argument list for the vectorized call.  */
    3971                 :          32 :           if (j == 0)
    3972                 :          32 :             vargs.create (nargs * 2);
    3973                 :             :           else
    3974                 :           0 :             vargs.truncate (0);
    3975                 :             : 
    3976                 :          32 :           if (slp_node)
    3977                 :             :             {
    3978                 :          32 :               vec<tree> vec_oprnds0;
    3979                 :             : 
    3980                 :          32 :               vect_get_slp_defs (vinfo, slp_node, &vec_defs);
    3981                 :          32 :               vec_oprnds0 = vec_defs[0];
    3982                 :             : 
    3983                 :             :               /* Arguments are ready.  Create the new vector stmt.  */
    3984                 :          64 :               for (i = 0; vec_oprnds0.iterate (i, &vec_oprnd0); i += 2)
    3985                 :             :                 {
    3986                 :          32 :                   size_t k;
    3987                 :          32 :                   vargs.truncate (0);
    3988                 :          64 :                   for (k = 0; k < nargs; k++)
    3989                 :             :                     {
    3990                 :          32 :                       vec<tree> vec_oprndsk = vec_defs[k];
    3991                 :          32 :                       vargs.quick_push (vec_oprndsk[i]);
    3992                 :          32 :                       vargs.quick_push (vec_oprndsk[i + 1]);
    3993                 :             :                     }
    3994                 :          32 :                   gcall *call;
    3995                 :          32 :                   if (ifn != IFN_LAST)
    3996                 :             :                     call = gimple_build_call_internal_vec (ifn, vargs);
    3997                 :             :                   else
    3998                 :          32 :                     call = gimple_build_call_vec (fndecl, vargs);
    3999                 :          32 :                   new_temp = make_ssa_name (vec_dest, call);
    4000                 :          32 :                   gimple_call_set_lhs (call, new_temp);
    4001                 :          32 :                   gimple_call_set_nothrow (call, true);
    4002                 :          32 :                   vect_finish_stmt_generation (vinfo, stmt_info, call, gsi);
    4003                 :          32 :                   slp_node->push_vec_def (call);
    4004                 :             :                 }
    4005                 :          32 :               continue;
    4006                 :          32 :             }
    4007                 :             : 
    4008                 :           0 :           for (i = 0; i < nargs; i++)
    4009                 :             :             {
    4010                 :           0 :               op = gimple_call_arg (stmt, i);
    4011                 :           0 :               if (j == 0)
    4012                 :             :                 {
    4013                 :           0 :                   vec_defs.quick_push (vNULL);
    4014                 :           0 :                   vect_get_vec_defs_for_operand (vinfo, stmt_info, 2 * ncopies,
    4015                 :           0 :                                                  op, &vec_defs[i], vectypes[i]);
    4016                 :             :                 }
    4017                 :           0 :               vec_oprnd0 = vec_defs[i][2*j];
    4018                 :           0 :               vec_oprnd1 = vec_defs[i][2*j+1];
    4019                 :             : 
    4020                 :           0 :               vargs.quick_push (vec_oprnd0);
    4021                 :           0 :               vargs.quick_push (vec_oprnd1);
    4022                 :             :             }
    4023                 :             : 
    4024                 :           0 :           gcall *new_stmt = gimple_build_call_vec (fndecl, vargs);
    4025                 :           0 :           new_temp = make_ssa_name (vec_dest, new_stmt);
    4026                 :           0 :           gimple_call_set_lhs (new_stmt, new_temp);
    4027                 :           0 :           vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    4028                 :             : 
    4029                 :           0 :           STMT_VINFO_VEC_STMTS (stmt_info).safe_push (new_stmt);
    4030                 :             :         }
    4031                 :             : 
    4032                 :          32 :       if (!slp_node)
    4033                 :           0 :         *vec_stmt = STMT_VINFO_VEC_STMTS (stmt_info)[0];
    4034                 :             : 
    4035                 :          64 :       for (i = 0; i < nargs; i++)
    4036                 :             :         {
    4037                 :          32 :           vec<tree> vec_oprndsi = vec_defs[i];
    4038                 :          32 :           vec_oprndsi.release ();
    4039                 :             :         }
    4040                 :          32 :     }
    4041                 :             :   else
    4042                 :             :     /* No current target implements this case.  */
    4043                 :             :     return false;
    4044                 :             : 
    4045                 :        3460 :   vargs.release ();
    4046                 :             : 
    4047                 :             :   /* The call in STMT might prevent it from being removed in dce.
    4048                 :             :      We however cannot remove it here, due to the way the ssa name
    4049                 :             :      it defines is mapped to the new definition.  So just replace
    4050                 :             :      rhs of the statement with something harmless.  */
    4051                 :             : 
    4052                 :        3460 :   if (slp_node)
    4053                 :             :     return true;
    4054                 :             : 
    4055                 :           0 :   stmt_info = vect_orig_stmt (stmt_info);
    4056                 :           0 :   lhs = gimple_get_lhs (stmt_info->stmt);
    4057                 :             : 
    4058                 :           0 :   gassign *new_stmt
    4059                 :           0 :     = gimple_build_assign (lhs, build_zero_cst (TREE_TYPE (lhs)));
    4060                 :           0 :   vinfo->replace_stmt (gsi, stmt_info, new_stmt);
    4061                 :             : 
    4062                 :           0 :   return true;
    4063                 :     2518395 : }
    4064                 :             : 
    4065                 :             : 
    4066                 :             : struct simd_call_arg_info
    4067                 :             : {
    4068                 :             :   tree vectype;
    4069                 :             :   tree op;
    4070                 :             :   HOST_WIDE_INT linear_step;
    4071                 :             :   enum vect_def_type dt;
    4072                 :             :   unsigned int align;
    4073                 :             :   bool simd_lane_linear;
    4074                 :             : };
    4075                 :             : 
    4076                 :             : /* Helper function of vectorizable_simd_clone_call.  If OP, an SSA_NAME,
    4077                 :             :    is linear within simd lane (but not within whole loop), note it in
    4078                 :             :    *ARGINFO.  */
    4079                 :             : 
    4080                 :             : static void
    4081                 :           3 : vect_simd_lane_linear (tree op, class loop *loop,
    4082                 :             :                        struct simd_call_arg_info *arginfo)
    4083                 :             : {
    4084                 :           3 :   gimple *def_stmt = SSA_NAME_DEF_STMT (op);
    4085                 :             : 
    4086                 :           3 :   if (!is_gimple_assign (def_stmt)
    4087                 :           3 :       || gimple_assign_rhs_code (def_stmt) != POINTER_PLUS_EXPR
    4088                 :           3 :       || !is_gimple_min_invariant (gimple_assign_rhs1 (def_stmt)))
    4089                 :           3 :     return;
    4090                 :             : 
    4091                 :           0 :   tree base = gimple_assign_rhs1 (def_stmt);
    4092                 :           0 :   HOST_WIDE_INT linear_step = 0;
    4093                 :           0 :   tree v = gimple_assign_rhs2 (def_stmt);
    4094                 :           0 :   while (TREE_CODE (v) == SSA_NAME)
    4095                 :             :     {
    4096                 :           0 :       tree t;
    4097                 :           0 :       def_stmt = SSA_NAME_DEF_STMT (v);
    4098                 :           0 :       if (is_gimple_assign (def_stmt))
    4099                 :           0 :         switch (gimple_assign_rhs_code (def_stmt))
    4100                 :             :           {
    4101                 :           0 :           case PLUS_EXPR:
    4102                 :           0 :             t = gimple_assign_rhs2 (def_stmt);
    4103                 :           0 :             if (linear_step || TREE_CODE (t) != INTEGER_CST)
    4104                 :             :               return;
    4105                 :           0 :             base = fold_build2 (POINTER_PLUS_EXPR, TREE_TYPE (base), base, t);
    4106                 :           0 :             v = gimple_assign_rhs1 (def_stmt);
    4107                 :           0 :             continue;
    4108                 :           0 :           case MULT_EXPR:
    4109                 :           0 :             t = gimple_assign_rhs2 (def_stmt);
    4110                 :           0 :             if (linear_step || !tree_fits_shwi_p (t) || integer_zerop (t))
    4111                 :           0 :               return;
    4112                 :           0 :             linear_step = tree_to_shwi (t);
    4113                 :           0 :             v = gimple_assign_rhs1 (def_stmt);
    4114                 :           0 :             continue;
    4115                 :           0 :           CASE_CONVERT:
    4116                 :           0 :             t = gimple_assign_rhs1 (def_stmt);
    4117                 :           0 :             if (TREE_CODE (TREE_TYPE (t)) != INTEGER_TYPE
    4118                 :           0 :                 || (TYPE_PRECISION (TREE_TYPE (v))
    4119                 :           0 :                     < TYPE_PRECISION (TREE_TYPE (t))))
    4120                 :             :               return;
    4121                 :           0 :             if (!linear_step)
    4122                 :           0 :               linear_step = 1;
    4123                 :           0 :             v = t;
    4124                 :           0 :             continue;
    4125                 :             :           default:
    4126                 :             :             return;
    4127                 :             :           }
    4128                 :           0 :       else if (gimple_call_internal_p (def_stmt, IFN_GOMP_SIMD_LANE)
    4129                 :           0 :                && loop->simduid
    4130                 :           0 :                && TREE_CODE (gimple_call_arg (def_stmt, 0)) == SSA_NAME
    4131                 :           0 :                && (SSA_NAME_VAR (gimple_call_arg (def_stmt, 0))
    4132                 :             :                    == loop->simduid))
    4133                 :             :         {
    4134                 :           0 :           if (!linear_step)
    4135                 :           0 :             linear_step = 1;
    4136                 :           0 :           arginfo->linear_step = linear_step;
    4137                 :           0 :           arginfo->op = base;
    4138                 :           0 :           arginfo->simd_lane_linear = true;
    4139                 :           0 :           return;
    4140                 :             :         }
    4141                 :             :     }
    4142                 :             : }
    4143                 :             : 
    4144                 :             : /* Function vectorizable_simd_clone_call.
    4145                 :             : 
    4146                 :             :    Check if STMT_INFO performs a function call that can be vectorized
    4147                 :             :    by calling a simd clone of the function.
    4148                 :             :    If VEC_STMT is also passed, vectorize STMT_INFO: create a vectorized
    4149                 :             :    stmt to replace it, put it in VEC_STMT, and insert it at GSI.
    4150                 :             :    Return true if STMT_INFO is vectorizable in this way.  */
    4151                 :             : 
    4152                 :             : static bool
    4153                 :     2509503 : vectorizable_simd_clone_call (vec_info *vinfo, stmt_vec_info stmt_info,
    4154                 :             :                               gimple_stmt_iterator *gsi,
    4155                 :             :                               gimple **vec_stmt, slp_tree slp_node,
    4156                 :             :                               stmt_vector_for_cost *)
    4157                 :             : {
    4158                 :     2509503 :   tree vec_dest;
    4159                 :     2509503 :   tree scalar_dest;
    4160                 :     2509503 :   tree op, type;
    4161                 :     2509503 :   tree vec_oprnd0 = NULL_TREE;
    4162                 :     2509503 :   tree vectype;
    4163                 :     2509503 :   poly_uint64 nunits;
    4164                 :     2509503 :   loop_vec_info loop_vinfo = dyn_cast <loop_vec_info> (vinfo);
    4165                 :     2509503 :   bb_vec_info bb_vinfo = dyn_cast <bb_vec_info> (vinfo);
    4166                 :     2509503 :   class loop *loop = loop_vinfo ? LOOP_VINFO_LOOP (loop_vinfo) : NULL;
    4167                 :     2509503 :   tree fndecl, new_temp;
    4168                 :     2509503 :   int ncopies, j;
    4169                 :     2509503 :   auto_vec<simd_call_arg_info> arginfo;
    4170                 :     2509503 :   vec<tree> vargs = vNULL;
    4171                 :     2509503 :   size_t i, nargs;
    4172                 :     2509503 :   tree lhs, rtype, ratype;
    4173                 :     2509503 :   vec<constructor_elt, va_gc> *ret_ctor_elts = NULL;
    4174                 :     2509503 :   int masked_call_offset = 0;
    4175                 :             : 
    4176                 :             :   /* Is STMT a vectorizable call?   */
    4177                 :     2509503 :   gcall *stmt = dyn_cast <gcall *> (stmt_info->stmt);
    4178                 :       10709 :   if (!stmt)
    4179                 :             :     return false;
    4180                 :             : 
    4181                 :       10709 :   fndecl = gimple_call_fndecl (stmt);
    4182                 :       10709 :   if (fndecl == NULL_TREE
    4183                 :       10709 :       && gimple_call_internal_p (stmt, IFN_MASK_CALL))
    4184                 :             :     {
    4185                 :         173 :       fndecl = gimple_call_arg (stmt, 0);
    4186                 :         173 :       gcc_checking_assert (TREE_CODE (fndecl) == ADDR_EXPR);
    4187                 :         173 :       fndecl = TREE_OPERAND (fndecl, 0);
    4188                 :         173 :       gcc_checking_assert (TREE_CODE (fndecl) == FUNCTION_DECL);
    4189                 :             :       masked_call_offset = 1;
    4190                 :             :     }
    4191                 :       10536 :   if (fndecl == NULL_TREE)
    4192                 :             :     return false;
    4193                 :             : 
    4194                 :        4738 :   struct cgraph_node *node = cgraph_node::get (fndecl);
    4195                 :        4738 :   if (node == NULL || node->simd_clones == NULL)
    4196                 :             :     return false;
    4197                 :             : 
    4198                 :        1406 :   if (!STMT_VINFO_RELEVANT_P (stmt_info) && !bb_vinfo)
    4199                 :             :     return false;
    4200                 :             : 
    4201                 :        1406 :   if (STMT_VINFO_DEF_TYPE (stmt_info) != vect_internal_def
    4202                 :           0 :       && ! vec_stmt)
    4203                 :             :     return false;
    4204                 :             : 
    4205                 :        1406 :   if (gimple_call_lhs (stmt)
    4206                 :        1406 :       && TREE_CODE (gimple_call_lhs (stmt)) != SSA_NAME)
    4207                 :             :     return false;
    4208                 :             : 
    4209                 :        1406 :   gcc_checking_assert (!stmt_can_throw_internal (cfun, stmt));
    4210                 :             : 
    4211                 :        1406 :   vectype = STMT_VINFO_VECTYPE (stmt_info);
    4212                 :             : 
    4213                 :     2509503 :   if (loop_vinfo && nested_in_vect_loop_p (loop, stmt_info))
    4214                 :             :     return false;
    4215                 :             : 
    4216                 :             :   /* Process function arguments.  */
    4217                 :        1406 :   nargs = gimple_call_num_args (stmt) - masked_call_offset;
    4218                 :             : 
    4219                 :             :   /* Bail out if the function has zero arguments.  */
    4220                 :        1406 :   if (nargs == 0)
    4221                 :             :     return false;
    4222                 :             : 
    4223                 :        1406 :   vec<tree>& simd_clone_info = (slp_node ? SLP_TREE_SIMD_CLONE_INFO (slp_node)
    4224                 :             :                                 : STMT_VINFO_SIMD_CLONE_INFO (stmt_info));
    4225                 :        1406 :   if (!vec_stmt)
    4226                 :        1074 :     simd_clone_info.truncate (0);
    4227                 :        1406 :   arginfo.reserve (nargs, true);
    4228                 :        1406 :   auto_vec<slp_tree> slp_op;
    4229                 :        1406 :   slp_op.safe_grow_cleared (nargs);
    4230                 :             : 
    4231                 :        4041 :   for (i = 0; i < nargs; i++)
    4232                 :             :     {
    4233                 :        2635 :       simd_call_arg_info thisarginfo;
    4234                 :        2635 :       affine_iv iv;
    4235                 :             : 
    4236                 :        2635 :       thisarginfo.linear_step = 0;
    4237                 :        2635 :       thisarginfo.align = 0;
    4238                 :        2635 :       thisarginfo.op = NULL_TREE;
    4239                 :        2635 :       thisarginfo.simd_lane_linear = false;
    4240                 :             : 
    4241                 :        2635 :       int op_no = i + masked_call_offset;
    4242                 :        2635 :       if (slp_node)
    4243                 :        2635 :         op_no = vect_slp_child_index_for_operand (stmt, op_no, false);
    4244                 :        5270 :       if (!vect_is_simple_use (vinfo, stmt_info, slp_node,
    4245                 :        2635 :                                op_no, &op, &slp_op[i],
    4246                 :             :                                &thisarginfo.dt, &thisarginfo.vectype)
    4247                 :        2635 :           || thisarginfo.dt == vect_uninitialized_def)
    4248                 :             :         {
    4249                 :           0 :           if (dump_enabled_p ())
    4250                 :           0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    4251                 :             :                              "use not simple.\n");
    4252                 :           0 :           return false;
    4253                 :             :         }
    4254                 :             : 
    4255                 :        2635 :       if (thisarginfo.dt == vect_constant_def
    4256                 :        2635 :           || thisarginfo.dt == vect_external_def)
    4257                 :             :         {
    4258                 :             :           /* With SLP we determine the vector type of constants/externals
    4259                 :             :              at analysis time, handling conflicts via
    4260                 :             :              vect_maybe_update_slp_op_vectype.  At transform time
    4261                 :             :              we have a vector type recorded for SLP.  */
    4262                 :         733 :           gcc_assert (!vec_stmt
    4263                 :             :                       || !slp_node
    4264                 :             :                       || thisarginfo.vectype != NULL_TREE);
    4265                 :         733 :           if (!vec_stmt)
    4266                 :         603 :             thisarginfo.vectype = get_vectype_for_scalar_type (vinfo,
    4267                 :         603 :                                                                TREE_TYPE (op),
    4268                 :             :                                                                slp_node);
    4269                 :             :         }
    4270                 :             :       else
    4271                 :        1902 :         gcc_assert (thisarginfo.vectype != NULL_TREE);
    4272                 :             : 
    4273                 :             :       /* For linear arguments, the analyze phase should have saved
    4274                 :             :          the base and step in {STMT_VINFO,SLP_TREE}_SIMD_CLONE_INFO.  */
    4275                 :        2505 :       if (vec_stmt
    4276                 :        1498 :           && i * 3 + 4 <= simd_clone_info.length ()
    4277                 :        2706 :           && simd_clone_info[i * 3 + 2])
    4278                 :             :         {
    4279                 :         112 :           thisarginfo.linear_step = tree_to_shwi (simd_clone_info[i * 3 + 2]);
    4280                 :         112 :           thisarginfo.op = simd_clone_info[i * 3 + 1];
    4281                 :         112 :           thisarginfo.simd_lane_linear
    4282                 :         112 :             = (simd_clone_info[i * 3 + 3] == boolean_true_node);
    4283                 :             :           /* If loop has been peeled for alignment, we need to adjust it.  */
    4284                 :         112 :           tree n1 = LOOP_VINFO_NITERS_UNCHANGED (loop_vinfo);
    4285                 :         112 :           tree n2 = LOOP_VINFO_NITERS (loop_vinfo);
    4286                 :         112 :           if (n1 != n2 && !thisarginfo.simd_lane_linear)
    4287                 :             :             {
    4288                 :           0 :               tree bias = fold_build2 (MINUS_EXPR, TREE_TYPE (n1), n1, n2);
    4289                 :           0 :               tree step = simd_clone_info[i * 3 + 2];
    4290                 :           0 :               tree opt = TREE_TYPE (thisarginfo.op);
    4291                 :           0 :               bias = fold_convert (TREE_TYPE (step), bias);
    4292                 :           0 :               bias = fold_build2 (MULT_EXPR, TREE_TYPE (step), bias, step);
    4293                 :           0 :               thisarginfo.op
    4294                 :           0 :                 = fold_build2 (POINTER_TYPE_P (opt)
    4295                 :             :                                ? POINTER_PLUS_EXPR : PLUS_EXPR, opt,
    4296                 :             :                                thisarginfo.op, bias);
    4297                 :             :             }
    4298                 :             :         }
    4299                 :        2523 :       else if (!vec_stmt
    4300                 :        1886 :                && thisarginfo.dt != vect_constant_def
    4301                 :        1758 :                && thisarginfo.dt != vect_external_def
    4302                 :        1283 :                && loop_vinfo
    4303                 :        1280 :                && TREE_CODE (op) == SSA_NAME
    4304                 :        2560 :                && simple_iv (loop, loop_containing_stmt (stmt), op,
    4305                 :             :                              &iv, false)
    4306                 :        2727 :                && tree_fits_shwi_p (iv.step))
    4307                 :             :         {
    4308                 :         204 :           thisarginfo.linear_step = tree_to_shwi (iv.step);
    4309                 :         204 :           thisarginfo.op = iv.base;
    4310                 :             :         }
    4311                 :        2319 :       else if ((thisarginfo.dt == vect_constant_def
    4312                 :        2319 :                 || thisarginfo.dt == vect_external_def)
    4313                 :        2319 :                && POINTER_TYPE_P (TREE_TYPE (op)))
    4314                 :         509 :         thisarginfo.align = get_pointer_alignment (op) / BITS_PER_UNIT;
    4315                 :             :       /* Addresses of array elements indexed by GOMP_SIMD_LANE are
    4316                 :             :          linear too.  */
    4317                 :        4675 :       if (POINTER_TYPE_P (TREE_TYPE (op))
    4318                 :         595 :           && !thisarginfo.linear_step
    4319                 :         517 :           && !vec_stmt
    4320                 :         469 :           && thisarginfo.dt != vect_constant_def
    4321                 :         469 :           && thisarginfo.dt != vect_external_def
    4322                 :           3 :           && loop_vinfo
    4323                 :        2638 :           && TREE_CODE (op) == SSA_NAME)
    4324                 :           3 :         vect_simd_lane_linear (op, loop, &thisarginfo);
    4325                 :             : 
    4326                 :        2635 :       arginfo.quick_push (thisarginfo);
    4327                 :             :     }
    4328                 :             : 
    4329                 :        1406 :   poly_uint64 vf = loop_vinfo ? LOOP_VINFO_VECT_FACTOR (loop_vinfo) : 1;
    4330                 :        1406 :   unsigned group_size = slp_node ? SLP_TREE_LANES (slp_node) : 1;
    4331                 :        1406 :   unsigned int badness = 0;
    4332                 :        1406 :   struct cgraph_node *bestn = NULL;
    4333                 :        1406 :   if (vec_stmt)
    4334                 :         332 :     bestn = cgraph_node::get (simd_clone_info[0]);
    4335                 :             :   else
    4336                 :        6048 :     for (struct cgraph_node *n = node->simd_clones; n != NULL;
    4337                 :        4974 :          n = n->simdclone->next_clone)
    4338                 :             :       {
    4339                 :        4974 :         unsigned int this_badness = 0;
    4340                 :        4974 :         unsigned int num_calls;
    4341                 :             :         /* The number of arguments in the call and the number of parameters in
    4342                 :             :            the simdclone should match.  However, when the simdclone is
    4343                 :             :            'inbranch', it could have one more paramater than nargs when using
    4344                 :             :            an inbranch simdclone to call a non-inbranch call, either in a
    4345                 :             :            non-masked loop using a all true constant mask, or inside a masked
    4346                 :             :            loop using it's mask.  */
    4347                 :        4974 :         size_t simd_nargs = n->simdclone->nargs;
    4348                 :        4974 :         if (!masked_call_offset && n->simdclone->inbranch)
    4349                 :        2447 :           simd_nargs--;
    4350                 :        4974 :         if (!constant_multiple_p (vf * group_size, n->simdclone->simdlen,
    4351                 :             :                                   &num_calls)
    4352                 :        1908 :             || (!n->simdclone->inbranch && (masked_call_offset > 0))
    4353                 :        1790 :             || (nargs != simd_nargs))
    4354                 :        3184 :           continue;
    4355                 :        1790 :         if (num_calls != 1)
    4356                 :        1258 :           this_badness += floor_log2 (num_calls) * 4096;
    4357                 :        1790 :         if (n->simdclone->inbranch)
    4358                 :         701 :           this_badness += 8192;
    4359                 :             : 
    4360                 :             :         /* If STMT_VINFO_VECTYPE has not been set yet pass the general vector
    4361                 :             :            mode,  which for targets that use it will determine what ISA we can
    4362                 :             :            vectorize this code with.  */
    4363                 :        1790 :         machine_mode vector_mode = vinfo->vector_mode;
    4364                 :        1790 :         if (vectype)
    4365                 :        1790 :           vector_mode = TYPE_MODE (vectype);
    4366                 :        1790 :         int target_badness = targetm.simd_clone.usable (n, vector_mode);
    4367                 :        1790 :         if (target_badness < 0)
    4368                 :         403 :           continue;
    4369                 :        1387 :         this_badness += target_badness * 512;
    4370                 :        4347 :         for (i = 0; i < nargs; i++)
    4371                 :             :           {
    4372                 :        3017 :             switch (n->simdclone->args[i].arg_type)
    4373                 :             :               {
    4374                 :        2156 :               case SIMD_CLONE_ARG_TYPE_VECTOR:
    4375                 :        2156 :                 if (!useless_type_conversion_p
    4376                 :        2156 :                         (n->simdclone->args[i].orig_type,
    4377                 :        2156 :                          TREE_TYPE (gimple_call_arg (stmt,
    4378                 :             :                                                      i + masked_call_offset))))
    4379                 :             :                   i = -1;
    4380                 :        2156 :                 else if (arginfo[i].dt == vect_constant_def
    4381                 :        2050 :                          || arginfo[i].dt == vect_external_def
    4382                 :        4142 :                          || arginfo[i].linear_step)
    4383                 :         377 :                   this_badness += 64;
    4384                 :             :                 break;
    4385                 :         322 :               case SIMD_CLONE_ARG_TYPE_UNIFORM:
    4386                 :         322 :                 if (arginfo[i].dt != vect_constant_def
    4387                 :         322 :                     && arginfo[i].dt != vect_external_def)
    4388                 :             :                   i = -1;
    4389                 :             :                 break;
    4390                 :         312 :               case SIMD_CLONE_ARG_TYPE_LINEAR_CONSTANT_STEP:
    4391                 :         312 :               case SIMD_CLONE_ARG_TYPE_LINEAR_REF_CONSTANT_STEP:
    4392                 :         312 :                 if (arginfo[i].dt == vect_constant_def
    4393                 :         312 :                     || arginfo[i].dt == vect_external_def
    4394                 :         312 :                     || (arginfo[i].linear_step
    4395                 :         312 :                         != n->simdclone->args[i].linear_step))
    4396                 :             :                   i = -1;
    4397                 :             :                 break;
    4398                 :             :               case SIMD_CLONE_ARG_TYPE_LINEAR_VARIABLE_STEP:
    4399                 :             :               case SIMD_CLONE_ARG_TYPE_LINEAR_VAL_CONSTANT_STEP:
    4400                 :             :               case SIMD_CLONE_ARG_TYPE_LINEAR_UVAL_CONSTANT_STEP:
    4401                 :             :               case SIMD_CLONE_ARG_TYPE_LINEAR_REF_VARIABLE_STEP:
    4402                 :             :               case SIMD_CLONE_ARG_TYPE_LINEAR_VAL_VARIABLE_STEP:
    4403                 :             :               case SIMD_CLONE_ARG_TYPE_LINEAR_UVAL_VARIABLE_STEP:
    4404                 :             :                 /* FORNOW */
    4405                 :             :                 i = -1;
    4406                 :             :                 break;
    4407                 :         227 :               case SIMD_CLONE_ARG_TYPE_MASK:
    4408                 :             :                 /* While we can create a traditional data vector from
    4409                 :             :                    an incoming integer mode mask we have no good way to
    4410                 :             :                    force generate an integer mode mask from a traditional
    4411                 :             :                    boolean vector input.  */
    4412                 :         227 :                 if (SCALAR_INT_MODE_P (n->simdclone->mask_mode)
    4413                 :         227 :                     && !SCALAR_INT_MODE_P (TYPE_MODE (arginfo[i].vectype)))
    4414                 :             :                   i = -1;
    4415                 :         221 :                 else if (!SCALAR_INT_MODE_P (n->simdclone->mask_mode)
    4416                 :         221 :                          && SCALAR_INT_MODE_P (TYPE_MODE (arginfo[i].vectype)))
    4417                 :          45 :                   this_badness += 2048;
    4418                 :             :                 break;
    4419                 :             :               }
    4420                 :        2960 :             if (i == (size_t) -1)
    4421                 :             :               break;
    4422                 :        2960 :             if (n->simdclone->args[i].alignment > arginfo[i].align)
    4423                 :             :               {
    4424                 :             :                 i = -1;
    4425                 :             :                 break;
    4426                 :             :               }
    4427                 :        2960 :             if (arginfo[i].align)
    4428                 :         110 :               this_badness += (exact_log2 (arginfo[i].align)
    4429                 :         160 :                                - exact_log2 (n->simdclone->args[i].alignment));
    4430                 :             :           }
    4431                 :        1387 :         if (i == (size_t) -1)
    4432                 :          57 :           continue;
    4433                 :        1330 :         if (masked_call_offset == 0
    4434                 :        1109 :             && n->simdclone->inbranch
    4435                 :         343 :             && n->simdclone->nargs > nargs)
    4436                 :             :           {
    4437                 :         343 :             gcc_assert (n->simdclone->args[n->simdclone->nargs - 1].arg_type ==
    4438                 :             :                         SIMD_CLONE_ARG_TYPE_MASK);
    4439                 :             :             /* Penalize using a masked SIMD clone in a non-masked loop, that is
    4440                 :             :                not in a branch, as we'd have to construct an all-true mask.  */
    4441                 :         343 :             if (!loop_vinfo || !LOOP_VINFO_FULLY_MASKED_P (loop_vinfo))
    4442                 :         343 :               this_badness += 64;
    4443                 :             :           }
    4444                 :        1330 :         if (bestn == NULL || this_badness < badness)
    4445                 :             :           {
    4446                 :        4974 :             bestn = n;
    4447                 :        4974 :             badness = this_badness;
    4448                 :             :           }
    4449                 :             :       }
    4450                 :             : 
    4451                 :        1406 :   if (bestn == NULL)
    4452                 :             :     return false;
    4453                 :             : 
    4454                 :         851 :   unsigned int num_mask_args = 0;
    4455                 :         851 :   if (SCALAR_INT_MODE_P (bestn->simdclone->mask_mode))
    4456                 :         111 :     for (i = 0; i < nargs; i++)
    4457                 :          72 :       if (bestn->simdclone->args[i].arg_type == SIMD_CLONE_ARG_TYPE_MASK)
    4458                 :          18 :         num_mask_args++;
    4459                 :             : 
    4460                 :        2755 :   for (i = 0; i < nargs; i++)
    4461                 :             :     {
    4462                 :        1938 :       if ((arginfo[i].dt == vect_constant_def
    4463                 :        1764 :            || arginfo[i].dt == vect_external_def)
    4464                 :        2040 :           && bestn->simdclone->args[i].arg_type == SIMD_CLONE_ARG_TYPE_VECTOR)
    4465                 :             :         {
    4466                 :          67 :           tree arg_type = TREE_TYPE (gimple_call_arg (stmt,
    4467                 :             :                                                       i + masked_call_offset));
    4468                 :          67 :           arginfo[i].vectype = get_vectype_for_scalar_type (vinfo, arg_type,
    4469                 :             :                                                             slp_node);
    4470                 :          67 :           if (arginfo[i].vectype == NULL
    4471                 :         134 :               || !constant_multiple_p (bestn->simdclone->simdlen,
    4472                 :         134 :                                        TYPE_VECTOR_SUBPARTS (arginfo[i].vectype)))
    4473                 :           0 :             return false;
    4474                 :             :         }
    4475                 :             : 
    4476                 :        1938 :       if (bestn->simdclone->args[i].arg_type == SIMD_CLONE_ARG_TYPE_VECTOR
    4477                 :        1938 :           && VECTOR_BOOLEAN_TYPE_P (bestn->simdclone->args[i].vector_type))
    4478                 :             :         {
    4479                 :           4 :           if (dump_enabled_p ())
    4480                 :           4 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    4481                 :             :                              "vector mask arguments are not supported.\n");
    4482                 :           4 :           return false;
    4483                 :             :         }
    4484                 :             : 
    4485                 :        1934 :       if (bestn->simdclone->args[i].arg_type == SIMD_CLONE_ARG_TYPE_MASK)
    4486                 :             :         {
    4487                 :         147 :           tree clone_arg_vectype = bestn->simdclone->args[i].vector_type;
    4488                 :         147 :           if (bestn->simdclone->mask_mode == VOIDmode)
    4489                 :             :             {
    4490                 :         129 :               if (maybe_ne (TYPE_VECTOR_SUBPARTS (clone_arg_vectype),
    4491                 :         258 :                             TYPE_VECTOR_SUBPARTS (arginfo[i].vectype)))
    4492                 :             :                 {
    4493                 :             :                   /* FORNOW we only have partial support for vector-type masks
    4494                 :             :                      that can't hold all of simdlen. */
    4495                 :          12 :                   if (dump_enabled_p ())
    4496                 :          12 :                     dump_printf_loc (MSG_MISSED_OPTIMIZATION,
    4497                 :             :                                      vect_location,
    4498                 :             :                                      "in-branch vector clones are not yet"
    4499                 :             :                                      " supported for mismatched vector sizes.\n");
    4500                 :          12 :                   return false;
    4501                 :             :                 }
    4502                 :         117 :               if (!expand_vec_cond_expr_p (clone_arg_vectype,
    4503                 :         117 :                                            arginfo[i].vectype))
    4504                 :             :                 {
    4505                 :           6 :                   if (dump_enabled_p ())
    4506                 :           6 :                     dump_printf_loc (MSG_MISSED_OPTIMIZATION,
    4507                 :             :                                      vect_location,
    4508                 :             :                                      "cannot compute mask argument for"
    4509                 :             :                                      " in-branch vector clones.\n");
    4510                 :           6 :                   return false;
    4511                 :             :                 }
    4512                 :             :             }
    4513                 :          18 :           else if (SCALAR_INT_MODE_P (bestn->simdclone->mask_mode))
    4514                 :             :             {
    4515                 :          18 :               if (!SCALAR_INT_MODE_P (TYPE_MODE (arginfo[i].vectype))
    4516                 :          36 :                   || maybe_ne (exact_div (bestn->simdclone->simdlen,
    4517                 :             :                                           num_mask_args),
    4518                 :          24 :                                TYPE_VECTOR_SUBPARTS (arginfo[i].vectype)))
    4519                 :             :                 {
    4520                 :             :                   /* FORNOW we only have partial support for integer-type masks
    4521                 :             :                      that represent the same number of lanes as the
    4522                 :             :                      vectorized mask inputs. */
    4523                 :          12 :                   if (dump_enabled_p ())
    4524                 :           6 :                     dump_printf_loc (MSG_MISSED_OPTIMIZATION,
    4525                 :             :                                      vect_location,
    4526                 :             :                                      "in-branch vector clones are not yet "
    4527                 :             :                                      "supported for mismatched vector sizes.\n");
    4528                 :          12 :                   return false;
    4529                 :             :                 }
    4530                 :             :             }
    4531                 :             :           else
    4532                 :             :             {
    4533                 :           0 :               if (dump_enabled_p ())
    4534                 :           0 :                 dump_printf_loc (MSG_MISSED_OPTIMIZATION,
    4535                 :             :                                  vect_location,
    4536                 :             :                                  "in-branch vector clones not supported"
    4537                 :             :                                  " on this target.\n");
    4538                 :           0 :               return false;
    4539                 :             :             }
    4540                 :             :         }
    4541                 :             :     }
    4542                 :             : 
    4543                 :         817 :   fndecl = bestn->decl;
    4544                 :         817 :   nunits = bestn->simdclone->simdlen;
    4545                 :         817 :   if (slp_node)
    4546                 :         817 :     ncopies = vector_unroll_factor (vf * group_size, nunits);
    4547                 :             :   else
    4548                 :           0 :     ncopies = vector_unroll_factor (vf, nunits);
    4549                 :             : 
    4550                 :             :   /* If the function isn't const, only allow it in simd loops where user
    4551                 :             :      has asserted that at least nunits consecutive iterations can be
    4552                 :             :      performed using SIMD instructions.  */
    4553                 :         815 :   if ((loop == NULL || maybe_lt ((unsigned) loop->safelen, nunits))
    4554                 :         989 :       && gimple_vuse (stmt))
    4555                 :             :     return false;
    4556                 :             : 
    4557                 :             :   /* Sanity check: make sure that at least one copy of the vectorized stmt
    4558                 :             :      needs to be generated.  */
    4559                 :         817 :   gcc_assert (ncopies >= 1);
    4560                 :             : 
    4561                 :         817 :   if (!vec_stmt) /* transformation not required.  */
    4562                 :             :     {
    4563                 :         485 :       if (slp_node)
    4564                 :        1598 :         for (unsigned i = 0; i < nargs; ++i)
    4565                 :        1113 :           if (!vect_maybe_update_slp_op_vectype (slp_op[i], arginfo[i].vectype))
    4566                 :             :             {
    4567                 :           0 :               if (dump_enabled_p ())
    4568                 :           0 :                 dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    4569                 :             :                                  "incompatible vector types for invariants\n");
    4570                 :           0 :               return false;
    4571                 :             :             }
    4572                 :             :       /* When the original call is pure or const but the SIMD ABI dictates
    4573                 :             :          an aggregate return we will have to use a virtual definition and
    4574                 :             :          in a loop eventually even need to add a virtual PHI.  That's
    4575                 :             :          not straight-forward so allow to fix this up via renaming.  */
    4576                 :         485 :       if (gimple_call_lhs (stmt)
    4577                 :         485 :           && !gimple_vdef (stmt)
    4578                 :         868 :           && TREE_CODE (TREE_TYPE (TREE_TYPE (bestn->decl))) == ARRAY_TYPE)
    4579                 :          33 :         vinfo->any_known_not_updated_vssa = true;
    4580                 :             :       /* ???  For SLP code-gen we end up inserting after the last
    4581                 :             :          vector argument def rather than at the original call position
    4582                 :             :          so automagic virtual operand updating doesn't work.  */
    4583                 :         970 :       if (gimple_vuse (stmt) && slp_node)
    4584                 :         139 :         vinfo->any_known_not_updated_vssa = true;
    4585                 :         485 :       simd_clone_info.safe_push (bestn->decl);
    4586                 :        1609 :       for (i = 0; i < bestn->simdclone->nargs; i++)
    4587                 :             :         {
    4588                 :        1124 :           switch (bestn->simdclone->args[i].arg_type)
    4589                 :             :             {
    4590                 :         939 :             default:
    4591                 :         939 :               continue;
    4592                 :         112 :             case SIMD_CLONE_ARG_TYPE_LINEAR_CONSTANT_STEP:
    4593                 :         112 :             case SIMD_CLONE_ARG_TYPE_LINEAR_REF_CONSTANT_STEP:
    4594                 :         112 :               {
    4595                 :         112 :                 simd_clone_info.safe_grow_cleared (i * 3 + 1, true);
    4596                 :         112 :                 simd_clone_info.safe_push (arginfo[i].op);
    4597                 :         196 :                 tree lst = POINTER_TYPE_P (TREE_TYPE (arginfo[i].op))
    4598                 :         196 :                            ? size_type_node : TREE_TYPE (arginfo[i].op);
    4599                 :         112 :                 tree ls = build_int_cst (lst, arginfo[i].linear_step);
    4600                 :         112 :                 simd_clone_info.safe_push (ls);
    4601                 :         112 :                 tree sll = arginfo[i].simd_lane_linear
    4602                 :         112 :                            ? boolean_true_node : boolean_false_node;
    4603                 :         112 :                 simd_clone_info.safe_push (sll);
    4604                 :             :               }
    4605                 :         112 :               break;
    4606                 :          73 :             case SIMD_CLONE_ARG_TYPE_MASK:
    4607                 :          73 :               if (loop_vinfo
    4608                 :          73 :                   && LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo))
    4609                 :           0 :                 vect_record_loop_mask (loop_vinfo,
    4610                 :             :                                        &LOOP_VINFO_MASKS (loop_vinfo),
    4611                 :             :                                        ncopies, vectype, op);
    4612                 :             : 
    4613                 :             :               break;
    4614                 :         939 :             }
    4615                 :             :         }
    4616                 :             : 
    4617                 :         485 :       if (!bestn->simdclone->inbranch && loop_vinfo)
    4618                 :             :         {
    4619                 :         411 :           if (dump_enabled_p ()
    4620                 :         411 :               && LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo))
    4621                 :           3 :             dump_printf_loc (MSG_NOTE, vect_location,
    4622                 :             :                              "can't use a fully-masked loop because a"
    4623                 :             :                              " non-masked simd clone was selected.\n");
    4624                 :         411 :           LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo) = false;
    4625                 :             :         }
    4626                 :             : 
    4627                 :         485 :       STMT_VINFO_TYPE (stmt_info) = call_simd_clone_vec_info_type;
    4628                 :         485 :       DUMP_VECT_SCOPE ("vectorizable_simd_clone_call");
    4629                 :             : /*      vect_model_simple_cost (vinfo, ncopies, dt, slp_node, cost_vec); */
    4630                 :         485 :       return true;
    4631                 :             :     }
    4632                 :             : 
    4633                 :             :   /* Transform.  */
    4634                 :             : 
    4635                 :         332 :   if (dump_enabled_p ())
    4636                 :         228 :     dump_printf_loc (MSG_NOTE, vect_location, "transform call.\n");
    4637                 :             : 
    4638                 :             :   /* Handle def.  */
    4639                 :         332 :   scalar_dest = gimple_call_lhs (stmt);
    4640                 :         332 :   vec_dest = NULL_TREE;
    4641                 :         332 :   rtype = NULL_TREE;
    4642                 :         332 :   ratype = NULL_TREE;
    4643                 :         332 :   if (scalar_dest)
    4644                 :             :     {
    4645                 :         332 :       vec_dest = vect_create_destination_var (scalar_dest, vectype);
    4646                 :         332 :       rtype = TREE_TYPE (TREE_TYPE (fndecl));
    4647                 :         332 :       if (TREE_CODE (rtype) == ARRAY_TYPE)
    4648                 :             :         {
    4649                 :           9 :           ratype = rtype;
    4650                 :           9 :           rtype = TREE_TYPE (ratype);
    4651                 :             :         }
    4652                 :             :     }
    4653                 :             : 
    4654                 :         664 :   auto_vec<vec<tree> > vec_oprnds;
    4655                 :         332 :   auto_vec<unsigned> vec_oprnds_i;
    4656                 :         332 :   vec_oprnds_i.safe_grow_cleared (nargs, true);
    4657                 :         332 :   if (slp_node)
    4658                 :             :     {
    4659                 :         332 :       vec_oprnds.reserve_exact (nargs);
    4660                 :         332 :       vect_get_slp_defs (vinfo, slp_node, &vec_oprnds);
    4661                 :             :     }
    4662                 :             :   else
    4663                 :           0 :     vec_oprnds.safe_grow_cleared (nargs, true);
    4664                 :         774 :   for (j = 0; j < ncopies; ++j)
    4665                 :             :     {
    4666                 :         442 :       poly_uint64 callee_nelements;
    4667                 :         442 :       poly_uint64 caller_nelements;
    4668                 :             :       /* Build argument list for the vectorized call.  */
    4669                 :         442 :       if (j == 0)
    4670                 :         332 :         vargs.create (nargs);
    4671                 :             :       else
    4672                 :         110 :         vargs.truncate (0);
    4673                 :             : 
    4674                 :        1504 :       for (i = 0; i < nargs; i++)
    4675                 :             :         {
    4676                 :        1062 :           unsigned int k, l, m, o;
    4677                 :        1062 :           tree atype;
    4678                 :        1062 :           op = gimple_call_arg (stmt, i + masked_call_offset);
    4679                 :        1062 :           switch (bestn->simdclone->args[i].arg_type)
    4680                 :             :             {
    4681                 :         790 :             case SIMD_CLONE_ARG_TYPE_VECTOR:
    4682                 :         790 :               atype = bestn->simdclone->args[i].vector_type;
    4683                 :         790 :               caller_nelements = TYPE_VECTOR_SUBPARTS (arginfo[i].vectype);
    4684                 :         790 :               callee_nelements = TYPE_VECTOR_SUBPARTS (atype);
    4685                 :         790 :               o = vector_unroll_factor (nunits, callee_nelements);
    4686                 :        1804 :               for (m = j * o; m < (j + 1) * o; m++)
    4687                 :             :                 {
    4688                 :        1014 :                   if (known_lt (callee_nelements, caller_nelements))
    4689                 :             :                     {
    4690                 :         516 :                       poly_uint64 prec = GET_MODE_BITSIZE (TYPE_MODE (atype));
    4691                 :         258 :                       if (!constant_multiple_p (caller_nelements,
    4692                 :             :                                                 callee_nelements, &k))
    4693                 :           0 :                         gcc_unreachable ();
    4694                 :             : 
    4695                 :         258 :                       gcc_assert ((k & (k - 1)) == 0);
    4696                 :         258 :                       if (m == 0)
    4697                 :             :                         {
    4698                 :          57 :                           if (!slp_node)
    4699                 :           0 :                             vect_get_vec_defs_for_operand (vinfo, stmt_info,
    4700                 :           0 :                                                            ncopies * o / k, op,
    4701                 :           0 :                                                            &vec_oprnds[i]);
    4702                 :          57 :                           vec_oprnds_i[i] = 0;
    4703                 :          57 :                           vec_oprnd0 = vec_oprnds[i][vec_oprnds_i[i]++];
    4704                 :             :                         }
    4705                 :             :                       else
    4706                 :             :                         {
    4707                 :         201 :                           vec_oprnd0 = arginfo[i].op;
    4708                 :         201 :                           if ((m & (k - 1)) == 0)
    4709                 :          72 :                             vec_oprnd0 = vec_oprnds[i][vec_oprnds_i[i]++];
    4710                 :             :                         }
    4711                 :         258 :                       arginfo[i].op = vec_oprnd0;
    4712                 :         258 :                       vec_oprnd0
    4713                 :         258 :                         = build3 (BIT_FIELD_REF, atype, vec_oprnd0,
    4714                 :         258 :                                   bitsize_int (prec),
    4715                 :         258 :                                   bitsize_int ((m & (k - 1)) * prec));
    4716                 :         258 :                       gassign *new_stmt
    4717                 :         258 :                         = gimple_build_assign (make_ssa_name (atype),
    4718                 :             :                                                vec_oprnd0);
    4719                 :         258 :                       vect_finish_stmt_generation (vinfo, stmt_info,
    4720                 :             :                                                    new_stmt, gsi);
    4721                 :         258 :                       vargs.safe_push (gimple_assign_lhs (new_stmt));
    4722                 :             :                     }
    4723                 :             :                   else
    4724                 :             :                     {
    4725                 :         756 :                       if (!constant_multiple_p (callee_nelements,
    4726                 :             :                                                 caller_nelements, &k))
    4727                 :           0 :                         gcc_unreachable ();
    4728                 :         756 :                       gcc_assert ((k & (k - 1)) == 0);
    4729                 :         756 :                       vec<constructor_elt, va_gc> *ctor_elts;
    4730                 :         756 :                       if (k != 1)
    4731                 :          14 :                         vec_alloc (ctor_elts, k);
    4732                 :             :                       else
    4733                 :         742 :                         ctor_elts = NULL;
    4734                 :         784 :                       for (l = 0; l < k; l++)
    4735                 :             :                         {
    4736                 :         770 :                           if (m == 0 && l == 0)
    4737                 :             :                             {
    4738                 :         423 :                               if (!slp_node)
    4739                 :           0 :                                 vect_get_vec_defs_for_operand (vinfo, stmt_info,
    4740                 :           0 :                                                                k * o * ncopies,
    4741                 :             :                                                                op,
    4742                 :           0 :                                                                &vec_oprnds[i]);
    4743                 :         423 :                               vec_oprnds_i[i] = 0;
    4744                 :         423 :                               vec_oprnd0 = vec_oprnds[i][vec_oprnds_i[i]++];
    4745                 :             :                             }
    4746                 :             :                           else
    4747                 :         347 :                             vec_oprnd0 = vec_oprnds[i][vec_oprnds_i[i]++];
    4748                 :         770 :                           arginfo[i].op = vec_oprnd0;
    4749                 :         770 :                           if (k == 1)
    4750                 :             :                             break;
    4751                 :          28 :                           CONSTRUCTOR_APPEND_ELT (ctor_elts, NULL_TREE,
    4752                 :             :                                                   vec_oprnd0);
    4753                 :             :                         }
    4754                 :         756 :                       if (k == 1)
    4755                 :         742 :                         if (!useless_type_conversion_p (TREE_TYPE (vec_oprnd0),
    4756                 :             :                                                        atype))
    4757                 :             :                           {
    4758                 :           0 :                             vec_oprnd0 = build1 (VIEW_CONVERT_EXPR, atype,
    4759                 :             :                                                  vec_oprnd0);
    4760                 :           0 :                             gassign *new_stmt
    4761                 :           0 :                               = gimple_build_assign (make_ssa_name (atype),
    4762                 :             :                                                      vec_oprnd0);
    4763                 :           0 :                             vect_finish_stmt_generation (vinfo, stmt_info,
    4764                 :             :                                                          new_stmt, gsi);
    4765                 :           0 :                             vargs.safe_push (gimple_get_lhs (new_stmt));
    4766                 :             :                           }
    4767                 :             :                         else
    4768                 :         742 :                           vargs.safe_push (vec_oprnd0);
    4769                 :             :                       else
    4770                 :             :                         {
    4771                 :          14 :                           vec_oprnd0 = build_constructor (atype, ctor_elts);
    4772                 :          14 :                           gassign *new_stmt
    4773                 :          14 :                             = gimple_build_assign (make_ssa_name (atype),
    4774                 :             :                                                    vec_oprnd0);
    4775                 :          14 :                           vect_finish_stmt_generation (vinfo, stmt_info,
    4776                 :             :                                                        new_stmt, gsi);
    4777                 :          14 :                           vargs.safe_push (gimple_assign_lhs (new_stmt));
    4778                 :             :                         }
    4779                 :             :                     }
    4780                 :             :                 }
    4781                 :             :               break;
    4782                 :          55 :             case SIMD_CLONE_ARG_TYPE_MASK:
    4783                 :          55 :               if (bestn->simdclone->mask_mode == VOIDmode)
    4784                 :             :                 {
    4785                 :          52 :                   atype = bestn->simdclone->args[i].vector_type;
    4786                 :          52 :                   tree elt_type = TREE_TYPE (atype);
    4787                 :          52 :                   tree one = fold_convert (elt_type, integer_one_node);
    4788                 :          52 :                   tree zero = fold_convert (elt_type, integer_zero_node);
    4789                 :          52 :                   callee_nelements = TYPE_VECTOR_SUBPARTS (atype);
    4790                 :          52 :                   caller_nelements = TYPE_VECTOR_SUBPARTS (arginfo[i].vectype);
    4791                 :          52 :                   o = vector_unroll_factor (nunits, callee_nelements);
    4792                 :         104 :                   for (m = j * o; m < (j + 1) * o; m++)
    4793                 :             :                     {
    4794                 :          52 :                       if (maybe_lt (callee_nelements, caller_nelements))
    4795                 :             :                         {
    4796                 :             :                           /* The mask type has fewer elements than simdlen.  */
    4797                 :             : 
    4798                 :             :                           /* FORNOW */
    4799                 :           0 :                           gcc_unreachable ();
    4800                 :             :                         }
    4801                 :          52 :                       else if (known_eq (callee_nelements, caller_nelements))
    4802                 :             :                         {
    4803                 :             :                           /* The SIMD clone function has the same number of
    4804                 :             :                              elements as the current function.  */
    4805                 :          52 :                           if (m == 0)
    4806                 :             :                             {
    4807                 :          52 :                               if (!slp_node)
    4808                 :           0 :                                 vect_get_vec_defs_for_operand (vinfo, stmt_info,
    4809                 :           0 :                                                                o * ncopies,
    4810                 :             :                                                                op,
    4811                 :           0 :                                                                &vec_oprnds[i]);
    4812                 :          52 :                               vec_oprnds_i[i] = 0;
    4813                 :             :                             }
    4814                 :          52 :                           vec_oprnd0 = vec_oprnds[i][vec_oprnds_i[i]++];
    4815                 :          52 :                           if (loop_vinfo
    4816                 :          52 :                               && LOOP_VINFO_FULLY_MASKED_P (loop_vinfo))
    4817                 :             :                             {
    4818                 :           0 :                               vec_loop_masks *loop_masks
    4819                 :             :                                 = &LOOP_VINFO_MASKS (loop_vinfo);
    4820                 :           0 :                               tree loop_mask
    4821                 :           0 :                                 = vect_get_loop_mask (loop_vinfo, gsi,
    4822                 :             :                                                       loop_masks, ncopies,
    4823                 :           0 :                                                       vectype, j);
    4824                 :           0 :                               vec_oprnd0
    4825                 :           0 :                                 = prepare_vec_mask (loop_vinfo,
    4826                 :           0 :                                                     TREE_TYPE (loop_mask),
    4827                 :             :                                                     loop_mask, vec_oprnd0,
    4828                 :             :                                                     gsi);
    4829                 :           0 :                               loop_vinfo->vec_cond_masked_set.add ({ vec_oprnd0,
    4830                 :             :                                                                      loop_mask });
    4831                 :             : 
    4832                 :             :                             }
    4833                 :          52 :                           vec_oprnd0
    4834                 :          52 :                             = build3 (VEC_COND_EXPR, atype, vec_oprnd0,
    4835                 :             :                                       build_vector_from_val (atype, one),
    4836                 :             :                                       build_vector_from_val (atype, zero));
    4837                 :          52 :                           gassign *new_stmt
    4838                 :          52 :                             = gimple_build_assign (make_ssa_name (atype),
    4839                 :             :                                                    vec_oprnd0);
    4840                 :          52 :                           vect_finish_stmt_generation (vinfo, stmt_info,
    4841                 :             :                                                        new_stmt, gsi);
    4842                 :          52 :                           vargs.safe_push (gimple_assign_lhs (new_stmt));
    4843                 :             :                         }
    4844                 :             :                       else
    4845                 :             :                         {
    4846                 :             :                           /* The mask type has more elements than simdlen.  */
    4847                 :             : 
    4848                 :             :                           /* FORNOW */
    4849                 :           0 :                           gcc_unreachable ();
    4850                 :             :                         }
    4851                 :             :                     }
    4852                 :             :                 }
    4853                 :           3 :               else if (SCALAR_INT_MODE_P (bestn->simdclone->mask_mode))
    4854                 :             :                 {
    4855                 :           3 :                   atype = bestn->simdclone->args[i].vector_type;
    4856                 :             :                   /* Guess the number of lanes represented by atype.  */
    4857                 :           3 :                   poly_uint64 atype_subparts
    4858                 :           3 :                     = exact_div (bestn->simdclone->simdlen,
    4859                 :             :                                  num_mask_args);
    4860                 :           3 :                   o = vector_unroll_factor (nunits, atype_subparts);
    4861                 :           6 :                   for (m = j * o; m < (j + 1) * o; m++)
    4862                 :             :                     {
    4863                 :           3 :                       if (m == 0)
    4864                 :             :                         {
    4865                 :           3 :                           if (!slp_node)
    4866                 :           0 :                             vect_get_vec_defs_for_operand (vinfo, stmt_info,
    4867                 :           0 :                                                            o * ncopies,
    4868                 :             :                                                            op,
    4869                 :           0 :                                                            &vec_oprnds[i]);
    4870                 :           3 :                           vec_oprnds_i[i] = 0;
    4871                 :             :                         }
    4872                 :           3 :                       if (maybe_lt (atype_subparts,
    4873                 :           3 :                                     TYPE_VECTOR_SUBPARTS (arginfo[i].vectype)))
    4874                 :             :                         {
    4875                 :             :                           /* The mask argument has fewer elements than the
    4876                 :             :                              input vector.  */
    4877                 :             :                           /* FORNOW */
    4878                 :           0 :                           gcc_unreachable ();
    4879                 :             :                         }
    4880                 :           3 :                       else if (known_eq (atype_subparts,
    4881                 :             :                                          TYPE_VECTOR_SUBPARTS (arginfo[i].vectype)))
    4882                 :             :                         {
    4883                 :             :                           /* The vector mask argument matches the input
    4884                 :             :                              in the number of lanes, but not necessarily
    4885                 :             :                              in the mode.  */
    4886                 :           3 :                           vec_oprnd0 = vec_oprnds[i][vec_oprnds_i[i]++];
    4887                 :           3 :                           tree st = lang_hooks.types.type_for_mode
    4888                 :           3 :                                       (TYPE_MODE (TREE_TYPE (vec_oprnd0)), 1);
    4889                 :           3 :                           vec_oprnd0 = build1 (VIEW_CONVERT_EXPR, st,
    4890                 :             :                                                vec_oprnd0);
    4891                 :           3 :                           gassign *new_stmt
    4892                 :           3 :                             = gimple_build_assign (make_ssa_name (st),
    4893                 :             :                                                    vec_oprnd0);
    4894                 :           3 :                           vect_finish_stmt_generation (vinfo, stmt_info,
    4895                 :             :                                                        new_stmt, gsi);
    4896                 :           3 :                           if (!types_compatible_p (atype, st))
    4897                 :             :                             {
    4898                 :           3 :                               new_stmt
    4899                 :           3 :                                 = gimple_build_assign (make_ssa_name (atype),
    4900                 :             :                                                        NOP_EXPR,
    4901                 :             :                                                        gimple_assign_lhs
    4902                 :             :                                                          (new_stmt));
    4903                 :           3 :                               vect_finish_stmt_generation (vinfo, stmt_info,
    4904                 :             :                                                            new_stmt, gsi);
    4905                 :             :                             }
    4906                 :           3 :                           vargs.safe_push (gimple_assign_lhs (new_stmt));
    4907                 :             :                         }
    4908                 :             :                       else
    4909                 :             :                         {
    4910                 :             :                           /* The mask argument has more elements than the
    4911                 :             :                              input vector.  */
    4912                 :             :                           /* FORNOW */
    4913                 :           0 :                           gcc_unreachable ();
    4914                 :             :                         }
    4915                 :             :                     }
    4916                 :             :                 }
    4917                 :             :               else
    4918                 :           0 :                 gcc_unreachable ();
    4919                 :             :               break;
    4920                 :         102 :             case SIMD_CLONE_ARG_TYPE_UNIFORM:
    4921                 :         102 :               vargs.safe_push (op);
    4922                 :         102 :               break;
    4923                 :         115 :             case SIMD_CLONE_ARG_TYPE_LINEAR_CONSTANT_STEP:
    4924                 :         115 :             case SIMD_CLONE_ARG_TYPE_LINEAR_REF_CONSTANT_STEP:
    4925                 :         115 :               if (j == 0)
    4926                 :             :                 {
    4927                 :         112 :                   gimple_seq stmts;
    4928                 :         112 :                   arginfo[i].op
    4929                 :         112 :                     = force_gimple_operand (unshare_expr (arginfo[i].op),
    4930                 :             :                                             &stmts, true, NULL_TREE);
    4931                 :         112 :                   if (stmts != NULL)
    4932                 :             :                     {
    4933                 :           0 :                       basic_block new_bb;
    4934                 :           0 :                       edge pe = loop_preheader_edge (loop);
    4935                 :           0 :                       new_bb = gsi_insert_seq_on_edge_immediate (pe, stmts);
    4936                 :           0 :                       gcc_assert (!new_bb);
    4937                 :             :                     }
    4938                 :         112 :                   if (arginfo[i].simd_lane_linear)
    4939                 :             :                     {
    4940                 :           0 :                       vargs.safe_push (arginfo[i].op);
    4941                 :           0 :                       break;
    4942                 :             :                     }
    4943                 :         112 :                   tree phi_res = copy_ssa_name (op);
    4944                 :         112 :                   gphi *new_phi = create_phi_node (phi_res, loop->header);
    4945                 :         112 :                   add_phi_arg (new_phi, arginfo[i].op,
    4946                 :             :                                loop_preheader_edge (loop), UNKNOWN_LOCATION);
    4947                 :         112 :                   enum tree_code code
    4948                 :         196 :                     = POINTER_TYPE_P (TREE_TYPE (op))
    4949                 :         112 :                       ? POINTER_PLUS_EXPR : PLUS_EXPR;
    4950                 :         196 :                   tree type = POINTER_TYPE_P (TREE_TYPE (op))
    4951                 :         196 :                               ? sizetype : TREE_TYPE (op);
    4952                 :         112 :                   poly_widest_int cst
    4953                 :         112 :                     = wi::mul (bestn->simdclone->args[i].linear_step,
    4954                 :         112 :                                ncopies * nunits);
    4955                 :         112 :                   tree tcst = wide_int_to_tree (type, cst);
    4956                 :         112 :                   tree phi_arg = copy_ssa_name (op);
    4957                 :         112 :                   gassign *new_stmt
    4958                 :         112 :                     = gimple_build_assign (phi_arg, code, phi_res, tcst);
    4959                 :         112 :                   gimple_stmt_iterator si = gsi_after_labels (loop->header);
    4960                 :         112 :                   gsi_insert_after (&si, new_stmt, GSI_NEW_STMT);
    4961                 :         112 :                   add_phi_arg (new_phi, phi_arg, loop_latch_edge (loop),
    4962                 :             :                                UNKNOWN_LOCATION);
    4963                 :         112 :                   arginfo[i].op = phi_res;
    4964                 :         112 :                   vargs.safe_push (phi_res);
    4965                 :         112 :                 }
    4966                 :             :               else
    4967                 :             :                 {
    4968                 :           3 :                   enum tree_code code
    4969                 :           6 :                     = POINTER_TYPE_P (TREE_TYPE (op))
    4970                 :           3 :                       ? POINTER_PLUS_EXPR : PLUS_EXPR;
    4971                 :           6 :                   tree type = POINTER_TYPE_P (TREE_TYPE (op))
    4972                 :           6 :                               ? sizetype : TREE_TYPE (op);
    4973                 :           3 :                   poly_widest_int cst
    4974                 :           3 :                     = wi::mul (bestn->simdclone->args[i].linear_step,
    4975                 :           3 :                                j * nunits);
    4976                 :           3 :                   tree tcst = wide_int_to_tree (type, cst);
    4977                 :           3 :                   new_temp = make_ssa_name (TREE_TYPE (op));
    4978                 :           3 :                   gassign *new_stmt
    4979                 :           6 :                     = gimple_build_assign (new_temp, code,
    4980                 :           3 :                                            arginfo[i].op, tcst);
    4981                 :           3 :                   vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    4982                 :           3 :                   vargs.safe_push (new_temp);
    4983                 :           3 :                 }
    4984                 :             :               break;
    4985                 :           0 :             case SIMD_CLONE_ARG_TYPE_LINEAR_VAL_CONSTANT_STEP:
    4986                 :           0 :             case SIMD_CLONE_ARG_TYPE_LINEAR_UVAL_CONSTANT_STEP:
    4987                 :           0 :             case SIMD_CLONE_ARG_TYPE_LINEAR_VARIABLE_STEP:
    4988                 :           0 :             case SIMD_CLONE_ARG_TYPE_LINEAR_REF_VARIABLE_STEP:
    4989                 :           0 :             case SIMD_CLONE_ARG_TYPE_LINEAR_VAL_VARIABLE_STEP:
    4990                 :           0 :             case SIMD_CLONE_ARG_TYPE_LINEAR_UVAL_VARIABLE_STEP:
    4991                 :           0 :             default:
    4992                 :           0 :               gcc_unreachable ();
    4993                 :             :             }
    4994                 :             :         }
    4995                 :             : 
    4996                 :         442 :       if (masked_call_offset == 0
    4997                 :         387 :           && bestn->simdclone->inbranch
    4998                 :           7 :           && bestn->simdclone->nargs > nargs)
    4999                 :             :         {
    5000                 :           7 :           unsigned long m, o;
    5001                 :           7 :           size_t mask_i = bestn->simdclone->nargs - 1;
    5002                 :           7 :           tree mask;
    5003                 :           7 :           gcc_assert (bestn->simdclone->args[mask_i].arg_type ==
    5004                 :             :                       SIMD_CLONE_ARG_TYPE_MASK);
    5005                 :             : 
    5006                 :           7 :           tree masktype = bestn->simdclone->args[mask_i].vector_type;
    5007                 :           7 :           if (SCALAR_INT_MODE_P (bestn->simdclone->mask_mode))
    5008                 :             :             /* Guess the number of lanes represented by masktype.  */
    5009                 :           1 :             callee_nelements = exact_div (bestn->simdclone->simdlen,
    5010                 :           1 :                                           bestn->simdclone->nargs - nargs);
    5011                 :             :           else
    5012                 :           6 :             callee_nelements = TYPE_VECTOR_SUBPARTS (masktype);
    5013                 :           7 :           o = vector_unroll_factor (nunits, callee_nelements);
    5014                 :          14 :           for (m = j * o; m < (j + 1) * o; m++)
    5015                 :             :             {
    5016                 :           7 :               if (loop_vinfo && LOOP_VINFO_FULLY_MASKED_P (loop_vinfo))
    5017                 :             :                 {
    5018                 :           0 :                   vec_loop_masks *loop_masks = &LOOP_VINFO_MASKS (loop_vinfo);
    5019                 :           0 :                   mask = vect_get_loop_mask (loop_vinfo, gsi, loop_masks,
    5020                 :             :                                              ncopies, masktype, j);
    5021                 :             :                 }
    5022                 :             :               else
    5023                 :           7 :                 mask = vect_build_all_ones_mask (vinfo, stmt_info, masktype);
    5024                 :             : 
    5025                 :           7 :               gassign *new_stmt;
    5026                 :           7 :               if (SCALAR_INT_MODE_P (bestn->simdclone->mask_mode))
    5027                 :             :                 {
    5028                 :             :                   /* This means we are dealing with integer mask modes.
    5029                 :             :                      First convert to an integer type with the same size as
    5030                 :             :                      the current vector type.  */
    5031                 :           1 :                   unsigned HOST_WIDE_INT intermediate_size
    5032                 :           1 :                       = tree_to_uhwi (TYPE_SIZE (TREE_TYPE (mask)));
    5033                 :           1 :                   tree mid_int_type =
    5034                 :           1 :                       build_nonstandard_integer_type (intermediate_size, 1);
    5035                 :           1 :                   mask = build1 (VIEW_CONVERT_EXPR, mid_int_type, mask);
    5036                 :           1 :                   new_stmt
    5037                 :           1 :                       = gimple_build_assign (make_ssa_name (mid_int_type),
    5038                 :             :                                              mask);
    5039                 :           1 :                   gsi_insert_before (gsi, new_stmt, GSI_SAME_STMT);
    5040                 :             :                   /* Then zero-extend to the mask mode.  */
    5041                 :           1 :                   mask = fold_build1 (NOP_EXPR, masktype,
    5042                 :             :                                       gimple_get_lhs (new_stmt));
    5043                 :             :                 }
    5044                 :           6 :               else if (bestn->simdclone->mask_mode == VOIDmode)
    5045                 :             :                 {
    5046                 :           6 :                   tree one = fold_convert (TREE_TYPE (masktype),
    5047                 :             :                                            integer_one_node);
    5048                 :           6 :                   tree zero = fold_convert (TREE_TYPE (masktype),
    5049                 :             :                                             integer_zero_node);
    5050                 :           6 :                   mask = build3 (VEC_COND_EXPR, masktype, mask,
    5051                 :             :                                  build_vector_from_val (masktype, one),
    5052                 :             :                                  build_vector_from_val (masktype, zero));
    5053                 :             :                 }
    5054                 :             :               else
    5055                 :           0 :                 gcc_unreachable ();
    5056                 :             : 
    5057                 :           7 :               new_stmt = gimple_build_assign (make_ssa_name (masktype), mask);
    5058                 :           7 :               vect_finish_stmt_generation (vinfo, stmt_info,
    5059                 :             :                                            new_stmt, gsi);
    5060                 :           7 :               mask = gimple_assign_lhs (new_stmt);
    5061                 :           7 :               vargs.safe_push (mask);
    5062                 :             :             }
    5063                 :             :         }
    5064                 :             : 
    5065                 :         442 :       gcall *new_call = gimple_build_call_vec (fndecl, vargs);
    5066                 :         442 :       if (vec_dest)
    5067                 :             :         {
    5068                 :         442 :           gcc_assert (ratype
    5069                 :             :                       || known_eq (TYPE_VECTOR_SUBPARTS (rtype), nunits));
    5070                 :         442 :           if (ratype)
    5071                 :          15 :             new_temp = create_tmp_var (ratype);
    5072                 :         427 :           else if (useless_type_conversion_p (vectype, rtype))
    5073                 :         405 :             new_temp = make_ssa_name (vec_dest, new_call);
    5074                 :             :           else
    5075                 :          22 :             new_temp = make_ssa_name (rtype, new_call);
    5076                 :         442 :           gimple_call_set_lhs (new_call, new_temp);
    5077                 :             :         }
    5078                 :         442 :       vect_finish_stmt_generation (vinfo, stmt_info, new_call, gsi);
    5079                 :         442 :       gimple *new_stmt = new_call;
    5080                 :             : 
    5081                 :         442 :       if (vec_dest)
    5082                 :             :         {
    5083                 :         442 :           if (!multiple_p (TYPE_VECTOR_SUBPARTS (vectype), nunits))
    5084                 :             :             {
    5085                 :          21 :               unsigned int k, l;
    5086                 :          42 :               poly_uint64 prec = GET_MODE_BITSIZE (TYPE_MODE (vectype));
    5087                 :          42 :               poly_uint64 bytes = GET_MODE_SIZE (TYPE_MODE (vectype));
    5088                 :          21 :               k = vector_unroll_factor (nunits,
    5089                 :             :                                         TYPE_VECTOR_SUBPARTS (vectype));
    5090                 :          21 :               gcc_assert ((k & (k - 1)) == 0);
    5091                 :          75 :               for (l = 0; l < k; l++)
    5092                 :             :                 {
    5093                 :          54 :                   tree t;
    5094                 :          54 :                   if (ratype)
    5095                 :             :                     {
    5096                 :          42 :                       t = build_fold_addr_expr (new_temp);
    5097                 :          42 :                       t = build2 (MEM_REF, vectype, t,
    5098                 :          42 :                                   build_int_cst (TREE_TYPE (t), l * bytes));
    5099                 :             :                     }
    5100                 :             :                   else
    5101                 :          12 :                     t = build3 (BIT_FIELD_REF, vectype, new_temp,
    5102                 :          12 :                                 bitsize_int (prec), bitsize_int (l * prec));
    5103                 :          54 :                   new_stmt = gimple_build_assign (make_ssa_name (vectype), t);
    5104                 :          54 :                   vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    5105                 :             : 
    5106                 :          54 :                   if (j == 0 && l == 0)
    5107                 :          15 :                     *vec_stmt = new_stmt;
    5108                 :          54 :                   if (slp_node)
    5109                 :          54 :                     SLP_TREE_VEC_DEFS (slp_node)
    5110                 :          54 :                       .quick_push (gimple_assign_lhs (new_stmt));
    5111                 :             :                   else
    5112                 :           0 :                     STMT_VINFO_VEC_STMTS (stmt_info).safe_push (new_stmt);
    5113                 :             :                 }
    5114                 :             : 
    5115                 :          21 :               if (ratype)
    5116                 :          15 :                 vect_clobber_variable (vinfo, stmt_info, gsi, new_temp);
    5117                 :          21 :               continue;
    5118                 :          21 :             }
    5119                 :         421 :           else if (!multiple_p (nunits, TYPE_VECTOR_SUBPARTS (vectype)))
    5120                 :             :             {
    5121                 :          16 :               unsigned int k;
    5122                 :          16 :               if (!constant_multiple_p (TYPE_VECTOR_SUBPARTS (vectype),
    5123                 :          16 :                                         TYPE_VECTOR_SUBPARTS (rtype), &k))
    5124                 :           0 :                 gcc_unreachable ();
    5125                 :          16 :               gcc_assert ((k & (k - 1)) == 0);
    5126                 :          16 :               if ((j & (k - 1)) == 0)
    5127                 :           8 :                 vec_alloc (ret_ctor_elts, k);
    5128                 :          16 :               if (ratype)
    5129                 :             :                 {
    5130                 :           0 :                   unsigned int m, o;
    5131                 :           0 :                   o = vector_unroll_factor (nunits,
    5132                 :             :                                             TYPE_VECTOR_SUBPARTS (rtype));
    5133                 :           0 :                   for (m = 0; m < o; m++)
    5134                 :             :                     {
    5135                 :           0 :                       tree tem = build4 (ARRAY_REF, rtype, new_temp,
    5136                 :           0 :                                          size_int (m), NULL_TREE, NULL_TREE);
    5137                 :           0 :                       new_stmt = gimple_build_assign (make_ssa_name (rtype),
    5138                 :             :                                                       tem);
    5139                 :           0 :                       vect_finish_stmt_generation (vinfo, stmt_info,
    5140                 :             :                                                    new_stmt, gsi);
    5141                 :           0 :                       CONSTRUCTOR_APPEND_ELT (ret_ctor_elts, NULL_TREE,
    5142                 :             :                                               gimple_assign_lhs (new_stmt));
    5143                 :             :                     }
    5144                 :           0 :                   vect_clobber_variable (vinfo, stmt_info, gsi, new_temp);
    5145                 :             :                 }
    5146                 :             :               else
    5147                 :          16 :                 CONSTRUCTOR_APPEND_ELT (ret_ctor_elts, NULL_TREE, new_temp);
    5148                 :          16 :               if ((j & (k - 1)) != k - 1)
    5149                 :           8 :                 continue;
    5150                 :           8 :               vec_oprnd0 = build_constructor (vectype, ret_ctor_elts);
    5151                 :           8 :               new_stmt
    5152                 :           8 :                 = gimple_build_assign (make_ssa_name (vec_dest), vec_oprnd0);
    5153                 :           8 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    5154                 :             : 
    5155                 :           8 :               if ((unsigned) j == k - 1)
    5156                 :           8 :                 *vec_stmt = new_stmt;
    5157                 :           8 :               if (slp_node)
    5158                 :           8 :                 SLP_TREE_VEC_DEFS (slp_node)
    5159                 :           8 :                   .quick_push (gimple_assign_lhs (new_stmt));
    5160                 :             :               else
    5161                 :           0 :                 STMT_VINFO_VEC_STMTS (stmt_info).safe_push (new_stmt);
    5162                 :           8 :               continue;
    5163                 :           8 :             }
    5164                 :         405 :           else if (ratype)
    5165                 :             :             {
    5166                 :           0 :               tree t = build_fold_addr_expr (new_temp);
    5167                 :           0 :               t = build2 (MEM_REF, vectype, t,
    5168                 :           0 :                           build_int_cst (TREE_TYPE (t), 0));
    5169                 :           0 :               new_stmt = gimple_build_assign (make_ssa_name (vec_dest), t);
    5170                 :           0 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    5171                 :           0 :               vect_clobber_variable (vinfo, stmt_info, gsi, new_temp);
    5172                 :             :             }
    5173                 :         405 :           else if (!useless_type_conversion_p (vectype, rtype))
    5174                 :             :             {
    5175                 :           0 :               vec_oprnd0 = build1 (VIEW_CONVERT_EXPR, vectype, new_temp);
    5176                 :           0 :               new_stmt
    5177                 :           0 :                 = gimple_build_assign (make_ssa_name (vec_dest), vec_oprnd0);
    5178                 :           0 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    5179                 :             :             }
    5180                 :             :         }
    5181                 :             : 
    5182                 :         405 :       if (j == 0)
    5183                 :         309 :         *vec_stmt = new_stmt;
    5184                 :         405 :       if (slp_node)
    5185                 :         405 :         SLP_TREE_VEC_DEFS (slp_node).quick_push (gimple_get_lhs (new_stmt));
    5186                 :             :       else
    5187                 :           0 :         STMT_VINFO_VEC_STMTS (stmt_info).safe_push (new_stmt);
    5188                 :             :     }
    5189                 :             : 
    5190                 :        1081 :   for (i = 0; i < nargs; ++i)
    5191                 :             :     {
    5192                 :         749 :       vec<tree> oprndsi = vec_oprnds[i];
    5193                 :         749 :       oprndsi.release ();
    5194                 :             :     }
    5195                 :         332 :   vargs.release ();
    5196                 :             : 
    5197                 :             :   /* Mark the clone as no longer being a candidate for GC.  */
    5198                 :         332 :   bestn->gc_candidate = false;
    5199                 :             : 
    5200                 :             :   /* The call in STMT might prevent it from being removed in dce.
    5201                 :             :      We however cannot remove it here, due to the way the ssa name
    5202                 :             :      it defines is mapped to the new definition.  So just replace
    5203                 :             :      rhs of the statement with something harmless.  */
    5204                 :             : 
    5205                 :         332 :   if (slp_node)
    5206                 :             :     return true;
    5207                 :             : 
    5208                 :           0 :   gimple *new_stmt;
    5209                 :           0 :   if (scalar_dest)
    5210                 :             :     {
    5211                 :           0 :       type = TREE_TYPE (scalar_dest);
    5212                 :           0 :       lhs = gimple_call_lhs (vect_orig_stmt (stmt_info)->stmt);
    5213                 :           0 :       new_stmt = gimple_build_assign (lhs, build_zero_cst (type));
    5214                 :             :     }
    5215                 :             :   else
    5216                 :           0 :     new_stmt = gimple_build_nop ();
    5217                 :           0 :   vinfo->replace_stmt (gsi, vect_orig_stmt (stmt_info), new_stmt);
    5218                 :           0 :   unlink_stmt_vdef (stmt);
    5219                 :             : 
    5220                 :           0 :   return true;
    5221                 :        1406 : }
    5222                 :             : 
    5223                 :             : 
    5224                 :             : /* Function vect_gen_widened_results_half
    5225                 :             : 
    5226                 :             :    Create a vector stmt whose code, type, number of arguments, and result
    5227                 :             :    variable are CODE, OP_TYPE, and VEC_DEST, and its arguments are
    5228                 :             :    VEC_OPRND0 and VEC_OPRND1.  The new vector stmt is to be inserted at GSI.
    5229                 :             :    In the case that CODE is a CALL_EXPR, this means that a call to DECL
    5230                 :             :    needs to be created (DECL is a function-decl of a target-builtin).
    5231                 :             :    STMT_INFO is the original scalar stmt that we are vectorizing.  */
    5232                 :             : 
    5233                 :             : static gimple *
    5234                 :       22946 : vect_gen_widened_results_half (vec_info *vinfo, code_helper ch,
    5235                 :             :                                tree vec_oprnd0, tree vec_oprnd1, int op_type,
    5236                 :             :                                tree vec_dest, gimple_stmt_iterator *gsi,
    5237                 :             :                                stmt_vec_info stmt_info)
    5238                 :             : {
    5239                 :       22946 :   gimple *new_stmt;
    5240                 :       22946 :   tree new_temp;
    5241                 :             : 
    5242                 :             :   /* Generate half of the widened result:  */
    5243                 :       22946 :   if (op_type != binary_op)
    5244                 :       21950 :     vec_oprnd1 = NULL;
    5245                 :       22946 :   new_stmt = vect_gimple_build (vec_dest, ch, vec_oprnd0, vec_oprnd1);
    5246                 :       22946 :   new_temp = make_ssa_name (vec_dest, new_stmt);
    5247                 :       22946 :   gimple_set_lhs (new_stmt, new_temp);
    5248                 :       22946 :   vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    5249                 :             : 
    5250                 :       22946 :   return new_stmt;
    5251                 :             : }
    5252                 :             : 
    5253                 :             : 
    5254                 :             : /* Create vectorized demotion statements for vector operands from VEC_OPRNDS.
    5255                 :             :    For multi-step conversions store the resulting vectors and call the function
    5256                 :             :    recursively. When NARROW_SRC_P is true, there's still a conversion after
    5257                 :             :    narrowing, don't store the vectors in the SLP_NODE or in vector info of
    5258                 :             :    the scalar statement(or in STMT_VINFO_RELATED_STMT chain).  */
    5259                 :             : 
    5260                 :             : static void
    5261                 :        9499 : vect_create_vectorized_demotion_stmts (vec_info *vinfo, vec<tree> *vec_oprnds,
    5262                 :             :                                        int multi_step_cvt,
    5263                 :             :                                        stmt_vec_info stmt_info,
    5264                 :             :                                        vec<tree> &vec_dsts,
    5265                 :             :                                        gimple_stmt_iterator *gsi,
    5266                 :             :                                        slp_tree slp_node, code_helper code,
    5267                 :             :                                        bool narrow_src_p)
    5268                 :             : {
    5269                 :        9499 :   unsigned int i;
    5270                 :        9499 :   tree vop0, vop1, new_tmp, vec_dest;
    5271                 :             : 
    5272                 :        9499 :   vec_dest = vec_dsts.pop ();
    5273                 :             : 
    5274                 :       21937 :   for (i = 0; i < vec_oprnds->length (); i += 2)
    5275                 :             :     {
    5276                 :             :       /* Create demotion operation.  */
    5277                 :       12438 :       vop0 = (*vec_oprnds)[i];
    5278                 :       12438 :       vop1 = (*vec_oprnds)[i + 1];
    5279                 :       12438 :       gimple *new_stmt = vect_gimple_build (vec_dest, code, vop0, vop1);
    5280                 :       12438 :       new_tmp = make_ssa_name (vec_dest, new_stmt);
    5281                 :       12438 :       gimple_set_lhs (new_stmt, new_tmp);
    5282                 :       12438 :       vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    5283                 :       12438 :       if (multi_step_cvt || narrow_src_p)
    5284                 :             :         /* Store the resulting vector for next recursive call,
    5285                 :             :            or return the resulting vector_tmp for NARROW FLOAT_EXPR.  */
    5286                 :        4477 :         (*vec_oprnds)[i/2] = new_tmp;
    5287                 :             :       else
    5288                 :             :         {
    5289                 :             :           /* This is the last step of the conversion sequence. Store the
    5290                 :             :              vectors in SLP_NODE or in vector info of the scalar statement
    5291                 :             :              (or in STMT_VINFO_RELATED_STMT chain).  */
    5292                 :        7961 :           if (slp_node)
    5293                 :        7961 :             slp_node->push_vec_def (new_stmt);
    5294                 :             :           else
    5295                 :           0 :             STMT_VINFO_VEC_STMTS (stmt_info).safe_push (new_stmt);
    5296                 :             :         }
    5297                 :             :     }
    5298                 :             : 
    5299                 :             :   /* For multi-step demotion operations we first generate demotion operations
    5300                 :             :      from the source type to the intermediate types, and then combine the
    5301                 :             :      results (stored in VEC_OPRNDS) in demotion operation to the destination
    5302                 :             :      type.  */
    5303                 :        9499 :   if (multi_step_cvt)
    5304                 :             :     {
    5305                 :             :       /* At each level of recursion we have half of the operands we had at the
    5306                 :             :          previous level.  */
    5307                 :        2074 :       vec_oprnds->truncate ((i+1)/2);
    5308                 :        2074 :       vect_create_vectorized_demotion_stmts (vinfo, vec_oprnds,
    5309                 :             :                                              multi_step_cvt - 1,
    5310                 :             :                                              stmt_info, vec_dsts, gsi,
    5311                 :        2074 :                                              slp_node, VEC_PACK_TRUNC_EXPR,
    5312                 :             :                                              narrow_src_p);
    5313                 :             :     }
    5314                 :             : 
    5315                 :        9499 :   vec_dsts.quick_push (vec_dest);
    5316                 :        9499 : }
    5317                 :             : 
    5318                 :             : 
    5319                 :             : /* Create vectorized promotion statements for vector operands from VEC_OPRNDS0
    5320                 :             :    and VEC_OPRNDS1, for a binary operation associated with scalar statement
    5321                 :             :    STMT_INFO.  For multi-step conversions store the resulting vectors and
    5322                 :             :    call the function recursively.  */
    5323                 :             : 
    5324                 :             : static void
    5325                 :        8966 : vect_create_vectorized_promotion_stmts (vec_info *vinfo,
    5326                 :             :                                         vec<tree> *vec_oprnds0,
    5327                 :             :                                         vec<tree> *vec_oprnds1,
    5328                 :             :                                         stmt_vec_info stmt_info, tree vec_dest,
    5329                 :             :                                         gimple_stmt_iterator *gsi,
    5330                 :             :                                         code_helper ch1,
    5331                 :             :                                         code_helper ch2, int op_type)
    5332                 :             : {
    5333                 :        8966 :   int i;
    5334                 :        8966 :   tree vop0, vop1, new_tmp1, new_tmp2;
    5335                 :        8966 :   gimple *new_stmt1, *new_stmt2;
    5336                 :        8966 :   vec<tree> vec_tmp = vNULL;
    5337                 :             : 
    5338                 :        8966 :   vec_tmp.create (vec_oprnds0->length () * 2);
    5339                 :       29405 :   FOR_EACH_VEC_ELT (*vec_oprnds0, i, vop0)
    5340                 :             :     {
    5341                 :       11473 :       if (op_type == binary_op)
    5342                 :         498 :         vop1 = (*vec_oprnds1)[i];
    5343                 :             :       else
    5344                 :             :         vop1 = NULL_TREE;
    5345                 :             : 
    5346                 :             :       /* Generate the two halves of promotion operation.  */
    5347                 :       11473 :       new_stmt1 = vect_gen_widened_results_half (vinfo, ch1, vop0, vop1,
    5348                 :             :                                                  op_type, vec_dest, gsi,
    5349                 :             :                                                  stmt_info);
    5350                 :       11473 :       new_stmt2 = vect_gen_widened_results_half (vinfo, ch2, vop0, vop1,
    5351                 :             :                                                  op_type, vec_dest, gsi,
    5352                 :             :                                                  stmt_info);
    5353                 :       11473 :       if (is_gimple_call (new_stmt1))
    5354                 :             :         {
    5355                 :           0 :           new_tmp1 = gimple_call_lhs (new_stmt1);
    5356                 :           0 :           new_tmp2 = gimple_call_lhs (new_stmt2);
    5357                 :             :         }
    5358                 :             :       else
    5359                 :             :         {
    5360                 :       11473 :           new_tmp1 = gimple_assign_lhs (new_stmt1);
    5361                 :       11473 :           new_tmp2 = gimple_assign_lhs (new_stmt2);
    5362                 :             :         }
    5363                 :             : 
    5364                 :             :       /* Store the results for the next step.  */
    5365                 :       11473 :       vec_tmp.quick_push (new_tmp1);
    5366                 :       11473 :       vec_tmp.quick_push (new_tmp2);
    5367                 :             :     }
    5368                 :             : 
    5369                 :        8966 :   vec_oprnds0->release ();
    5370                 :        8966 :   *vec_oprnds0 = vec_tmp;
    5371                 :        8966 : }
    5372                 :             : 
    5373                 :             : /* Create vectorized promotion stmts for widening stmts using only half the
    5374                 :             :    potential vector size for input.  */
    5375                 :             : static void
    5376                 :          14 : vect_create_half_widening_stmts (vec_info *vinfo,
    5377                 :             :                                         vec<tree> *vec_oprnds0,
    5378                 :             :                                         vec<tree> *vec_oprnds1,
    5379                 :             :                                         stmt_vec_info stmt_info, tree vec_dest,
    5380                 :             :                                         gimple_stmt_iterator *gsi,
    5381                 :             :                                         code_helper code1,
    5382                 :             :                                         int op_type)
    5383                 :             : {
    5384                 :          14 :   int i;
    5385                 :          14 :   tree vop0, vop1;
    5386                 :          14 :   gimple *new_stmt1;
    5387                 :          14 :   gimple *new_stmt2;
    5388                 :          14 :   gimple *new_stmt3;
    5389                 :          14 :   vec<tree> vec_tmp = vNULL;
    5390                 :             : 
    5391                 :          14 :   vec_tmp.create (vec_oprnds0->length ());
    5392                 :          28 :   FOR_EACH_VEC_ELT (*vec_oprnds0, i, vop0)
    5393                 :             :     {
    5394                 :          14 :       tree new_tmp1, new_tmp2, new_tmp3, out_type;
    5395                 :             : 
    5396                 :          14 :       gcc_assert (op_type == binary_op);
    5397                 :          14 :       vop1 = (*vec_oprnds1)[i];
    5398                 :             : 
    5399                 :             :       /* Widen the first vector input.  */
    5400                 :          14 :       out_type = TREE_TYPE (vec_dest);
    5401                 :          14 :       new_tmp1 = make_ssa_name (out_type);
    5402                 :          14 :       new_stmt1 = gimple_build_assign (new_tmp1, NOP_EXPR, vop0);
    5403                 :          14 :       vect_finish_stmt_generation (vinfo, stmt_info, new_stmt1, gsi);
    5404                 :          14 :       if (VECTOR_TYPE_P (TREE_TYPE (vop1)))
    5405                 :             :         {
    5406                 :             :           /* Widen the second vector input.  */
    5407                 :          14 :           new_tmp2 = make_ssa_name (out_type);
    5408                 :          14 :           new_stmt2 = gimple_build_assign (new_tmp2, NOP_EXPR, vop1);
    5409                 :          14 :           vect_finish_stmt_generation (vinfo, stmt_info, new_stmt2, gsi);
    5410                 :             :           /* Perform the operation.  With both vector inputs widened.  */
    5411                 :          14 :           new_stmt3 = vect_gimple_build (vec_dest, code1, new_tmp1, new_tmp2);
    5412                 :             :         }
    5413                 :             :       else
    5414                 :             :         {
    5415                 :             :           /* Perform the operation.  With the single vector input widened.  */
    5416                 :           0 :           new_stmt3 = vect_gimple_build (vec_dest, code1, new_tmp1, vop1);
    5417                 :             :         }
    5418                 :             : 
    5419                 :          14 :       new_tmp3 = make_ssa_name (vec_dest, new_stmt3);
    5420                 :          14 :       gimple_assign_set_lhs (new_stmt3, new_tmp3);
    5421                 :          14 :       vect_finish_stmt_generation (vinfo, stmt_info, new_stmt3, gsi);
    5422                 :             : 
    5423                 :             :       /* Store the results for the next step.  */
    5424                 :          14 :       vec_tmp.quick_push (new_tmp3);
    5425                 :             :     }
    5426                 :             : 
    5427                 :          14 :   vec_oprnds0->release ();
    5428                 :          14 :   *vec_oprnds0 = vec_tmp;
    5429                 :          14 : }
    5430                 :             : 
    5431                 :             : 
    5432                 :             : /* Check if STMT_INFO performs a conversion operation that can be vectorized.
    5433                 :             :    If VEC_STMT is also passed, vectorize STMT_INFO: create a vectorized
    5434                 :             :    stmt to replace it, put it in VEC_STMT, and insert it at GSI.
    5435                 :             :    Return true if STMT_INFO is vectorizable in this way.  */
    5436                 :             : 
    5437                 :             : static bool
    5438                 :     2527996 : vectorizable_conversion (vec_info *vinfo,
    5439                 :             :                          stmt_vec_info stmt_info, gimple_stmt_iterator *gsi,
    5440                 :             :                          gimple **vec_stmt, slp_tree slp_node,
    5441                 :             :                          stmt_vector_for_cost *cost_vec)
    5442                 :             : {
    5443                 :     2527996 :   tree vec_dest, cvt_op = NULL_TREE;
    5444                 :     2527996 :   tree scalar_dest;
    5445                 :     2527996 :   tree op0, op1 = NULL_TREE;
    5446                 :     2527996 :   tree_code tc1;
    5447                 :     2527996 :   code_helper code, code1, code2;
    5448                 :     2527996 :   code_helper codecvt1 = ERROR_MARK, codecvt2 = ERROR_MARK;
    5449                 :     2527996 :   tree new_temp;
    5450                 :     2527996 :   enum vect_def_type dt[2] = {vect_unknown_def_type, vect_unknown_def_type};
    5451                 :     2527996 :   int ndts = 2;
    5452                 :     2527996 :   poly_uint64 nunits_in;
    5453                 :     2527996 :   poly_uint64 nunits_out;
    5454                 :     2527996 :   tree vectype_out, vectype_in;
    5455                 :     2527996 :   int i;
    5456                 :     2527996 :   tree lhs_type, rhs_type;
    5457                 :             :   /* For conversions between floating point and integer, there're 2 NARROW
    5458                 :             :      cases. NARROW_SRC is for FLOAT_EXPR, means
    5459                 :             :      integer --DEMOTION--> integer --FLOAT_EXPR--> floating point.
    5460                 :             :      This is safe when the range of the source integer can fit into the lower
    5461                 :             :      precision. NARROW_DST is for FIX_TRUNC_EXPR, means
    5462                 :             :      floating point --FIX_TRUNC_EXPR--> integer --DEMOTION--> INTEGER.
    5463                 :             :      For other conversions, when there's narrowing, NARROW_DST is used as
    5464                 :             :      default.  */
    5465                 :     2527996 :   enum { NARROW_SRC, NARROW_DST, NONE, WIDEN } modifier;
    5466                 :     2527996 :   vec<tree> vec_oprnds0 = vNULL;
    5467                 :     2527996 :   vec<tree> vec_oprnds1 = vNULL;
    5468                 :     2527996 :   tree vop0;
    5469                 :     2527996 :   bb_vec_info bb_vinfo = dyn_cast <bb_vec_info> (vinfo);
    5470                 :     2527996 :   int multi_step_cvt = 0;
    5471                 :     2527996 :   vec<tree> interm_types = vNULL;
    5472                 :     2527996 :   tree intermediate_type, cvt_type = NULL_TREE;
    5473                 :     2527996 :   int op_type;
    5474                 :     2527996 :   unsigned short fltsz;
    5475                 :             : 
    5476                 :             :   /* Is STMT a vectorizable conversion?   */
    5477                 :             : 
    5478                 :     2527996 :   if (!STMT_VINFO_RELEVANT_P (stmt_info) && !bb_vinfo)
    5479                 :             :     return false;
    5480                 :             : 
    5481                 :     2527996 :   if (STMT_VINFO_DEF_TYPE (stmt_info) != vect_internal_def
    5482                 :      200344 :       && ! vec_stmt)
    5483                 :             :     return false;
    5484                 :             : 
    5485                 :     2327652 :   gimple* stmt = stmt_info->stmt;
    5486                 :     2327652 :   if (!(is_gimple_assign (stmt) || is_gimple_call (stmt)))
    5487                 :             :     return false;
    5488                 :             : 
    5489                 :     2259009 :   if (gimple_get_lhs (stmt) == NULL_TREE
    5490                 :     2259009 :       || TREE_CODE (gimple_get_lhs (stmt)) != SSA_NAME)
    5491                 :      856741 :     return false;
    5492                 :             : 
    5493                 :     1402268 :   if (TREE_CODE (gimple_get_lhs (stmt)) != SSA_NAME)
    5494                 :             :     return false;
    5495                 :             : 
    5496                 :     1402268 :   if (is_gimple_assign (stmt))
    5497                 :             :     {
    5498                 :     1393967 :       code = gimple_assign_rhs_code (stmt);
    5499                 :     1393967 :       op_type = TREE_CODE_LENGTH ((tree_code) code);
    5500                 :             :     }
    5501                 :        8301 :   else if (gimple_call_internal_p (stmt))
    5502                 :             :     {
    5503                 :        4318 :       code = gimple_call_internal_fn (stmt);
    5504                 :        4318 :       op_type = gimple_call_num_args (stmt);
    5505                 :             :     }
    5506                 :             :   else
    5507                 :             :     return false;
    5508                 :             : 
    5509                 :     1398285 :   bool widen_arith = (code == WIDEN_MULT_EXPR
    5510                 :     1395738 :                  || code == WIDEN_LSHIFT_EXPR
    5511                 :     2794023 :                  || widening_fn_p (code));
    5512                 :             : 
    5513                 :     1395738 :   if (!widen_arith
    5514                 :     1395738 :       && !CONVERT_EXPR_CODE_P (code)
    5515                 :             :       && code != FIX_TRUNC_EXPR
    5516                 :             :       && code != FLOAT_EXPR)
    5517                 :             :     return false;
    5518                 :             : 
    5519                 :             :   /* Check types of lhs and rhs.  */
    5520                 :      164691 :   scalar_dest = gimple_get_lhs (stmt);
    5521                 :      164691 :   lhs_type = TREE_TYPE (scalar_dest);
    5522                 :      164691 :   vectype_out = SLP_TREE_VECTYPE (slp_node);
    5523                 :             : 
    5524                 :             :   /* Check the operands of the operation.  */
    5525                 :      164691 :   slp_tree slp_op0, slp_op1 = NULL;
    5526                 :      164691 :   if (!vect_is_simple_use (vinfo, stmt_info, slp_node,
    5527                 :             :                            0, &op0, &slp_op0, &dt[0], &vectype_in))
    5528                 :             :     {
    5529                 :           0 :       if (dump_enabled_p ())
    5530                 :           0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    5531                 :             :                          "use not simple.\n");
    5532                 :           0 :       return false;
    5533                 :             :     }
    5534                 :             : 
    5535                 :      164691 :   rhs_type = TREE_TYPE (op0);
    5536                 :      164691 :   if ((code != FIX_TRUNC_EXPR && code != FLOAT_EXPR)
    5537                 :      316724 :       && !((INTEGRAL_TYPE_P (lhs_type)
    5538                 :      139317 :             && INTEGRAL_TYPE_P (rhs_type))
    5539                 :             :            || (SCALAR_FLOAT_TYPE_P (lhs_type)
    5540                 :        6870 :                && SCALAR_FLOAT_TYPE_P (rhs_type))))
    5541                 :             :     return false;
    5542                 :             : 
    5543                 :      158845 :   if (!VECTOR_BOOLEAN_TYPE_P (vectype_out)
    5544                 :      306494 :       && ((INTEGRAL_TYPE_P (lhs_type)
    5545                 :      125636 :            && !type_has_mode_precision_p (lhs_type))
    5546                 :      147117 :           || (INTEGRAL_TYPE_P (rhs_type)
    5547                 :      138039 :               && !type_has_mode_precision_p (rhs_type))))
    5548                 :             :     {
    5549                 :        1135 :       if (dump_enabled_p ())
    5550                 :          10 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    5551                 :             :                          "type conversion to/from bit-precision unsupported."
    5552                 :             :                          "\n");
    5553                 :        1135 :       return false;
    5554                 :             :     }
    5555                 :             : 
    5556                 :      157710 :   if (op_type == binary_op)
    5557                 :             :     {
    5558                 :        2547 :       gcc_assert (code == WIDEN_MULT_EXPR
    5559                 :             :                   || code == WIDEN_LSHIFT_EXPR
    5560                 :             :                   || widening_fn_p (code));
    5561                 :             : 
    5562                 :        2547 :       op1 = is_gimple_assign (stmt) ? gimple_assign_rhs2 (stmt) :
    5563                 :           0 :                                      gimple_call_arg (stmt, 0);
    5564                 :        2547 :       tree vectype1_in;
    5565                 :        2547 :       if (!vect_is_simple_use (vinfo, stmt_info, slp_node, 1,
    5566                 :             :                                &op1, &slp_op1, &dt[1], &vectype1_in))
    5567                 :             :         {
    5568                 :           0 :           if (dump_enabled_p ())
    5569                 :           0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    5570                 :             :                              "use not simple.\n");
    5571                 :           0 :           return false;
    5572                 :             :         }
    5573                 :             :       /* For WIDEN_MULT_EXPR, if OP0 is a constant, use the type of
    5574                 :             :          OP1.  */
    5575                 :        2547 :       if (!vectype_in)
    5576                 :         121 :         vectype_in = vectype1_in;
    5577                 :             :     }
    5578                 :             : 
    5579                 :             :   /* If op0 is an external or constant def, infer the vector type
    5580                 :             :      from the scalar type.  */
    5581                 :      157710 :   if (!vectype_in)
    5582                 :       21990 :     vectype_in = get_vectype_for_scalar_type (vinfo, rhs_type, slp_node);
    5583                 :      157710 :   if (vec_stmt)
    5584                 :       19310 :     gcc_assert (vectype_in);
    5585                 :      157710 :   if (!vectype_in)
    5586                 :             :     {
    5587                 :        1822 :       if (dump_enabled_p ())
    5588                 :           0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    5589                 :             :                          "no vectype for scalar type %T\n", rhs_type);
    5590                 :             : 
    5591                 :        1822 :       return false;
    5592                 :             :     }
    5593                 :             : 
    5594                 :      155888 :   if (VECTOR_BOOLEAN_TYPE_P (vectype_out)
    5595                 :      167084 :       && !VECTOR_BOOLEAN_TYPE_P (vectype_in))
    5596                 :             :     {
    5597                 :         195 :       if (dump_enabled_p ())
    5598                 :          30 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    5599                 :             :                          "can't convert between boolean and non "
    5600                 :             :                          "boolean vectors %T\n", rhs_type);
    5601                 :             : 
    5602                 :         195 :       return false;
    5603                 :             :     }
    5604                 :             : 
    5605                 :      155693 :   nunits_in = TYPE_VECTOR_SUBPARTS (vectype_in);
    5606                 :      155693 :   nunits_out = TYPE_VECTOR_SUBPARTS (vectype_out);
    5607                 :      155693 :   if (known_eq (nunits_out, nunits_in))
    5608                 :       75000 :     if (widen_arith)
    5609                 :             :       modifier = WIDEN;
    5610                 :             :     else
    5611                 :      155693 :       modifier = NONE;
    5612                 :       80693 :   else if (multiple_p (nunits_out, nunits_in))
    5613                 :             :     modifier = NARROW_DST;
    5614                 :             :   else
    5615                 :             :     {
    5616                 :       47936 :       gcc_checking_assert (multiple_p (nunits_in, nunits_out));
    5617                 :             :       modifier = WIDEN;
    5618                 :             :     }
    5619                 :             : 
    5620                 :      155693 :   bool found_mode = false;
    5621                 :      155693 :   scalar_mode lhs_mode = SCALAR_TYPE_MODE (lhs_type);
    5622                 :      155693 :   scalar_mode rhs_mode = SCALAR_TYPE_MODE (rhs_type);
    5623                 :      155693 :   opt_scalar_mode rhs_mode_iter;
    5624                 :      155693 :   auto_vec<std::pair<tree, tree_code>, 2> converts;
    5625                 :             : 
    5626                 :             :   /* Supportable by target?  */
    5627                 :      155693 :   switch (modifier)
    5628                 :             :     {
    5629                 :       74761 :     case NONE:
    5630                 :       74761 :       if (code != FIX_TRUNC_EXPR
    5631                 :             :           && code != FLOAT_EXPR
    5632                 :             :           && !CONVERT_EXPR_CODE_P (code))
    5633                 :             :         return false;
    5634                 :       74761 :       gcc_assert (code.is_tree_code ());
    5635                 :       74761 :       if (supportable_indirect_convert_operation (code,
    5636                 :             :                                                   vectype_out, vectype_in,
    5637                 :             :                                                   converts, op0, slp_op0))
    5638                 :             :         {
    5639                 :       17957 :           gcc_assert (converts.length () <= 2);
    5640                 :       17957 :           if (converts.length () == 1)
    5641                 :       17883 :             code1 = converts[0].second;
    5642                 :             :           else
    5643                 :             :             {
    5644                 :          74 :               cvt_type = NULL_TREE;
    5645                 :          74 :               multi_step_cvt = converts.length () - 1;
    5646                 :          74 :               codecvt1 = converts[0].second;
    5647                 :          74 :               code1 = converts[1].second;
    5648                 :          74 :               interm_types.safe_push (converts[0].first);
    5649                 :             :             }
    5650                 :             :           break;
    5651                 :             :         }
    5652                 :             : 
    5653                 :             :       /* FALLTHRU */
    5654                 :       56804 :     unsupported:
    5655                 :       70187 :       if (dump_enabled_p ())
    5656                 :        7036 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    5657                 :             :                          "conversion not supported by target.\n");
    5658                 :             :       return false;
    5659                 :             : 
    5660                 :       48175 :     case WIDEN:
    5661                 :       48175 :       if (known_eq (nunits_in, nunits_out))
    5662                 :             :         {
    5663                 :         478 :           if (!(code.is_tree_code ()
    5664                 :         239 :                 && supportable_half_widening_operation ((tree_code) code,
    5665                 :             :                                                         vectype_out, vectype_in,
    5666                 :             :                                                         &tc1)))
    5667                 :          71 :             goto unsupported;
    5668                 :         168 :           code1 = tc1;
    5669                 :         168 :           gcc_assert (!(multi_step_cvt && op_type == binary_op));
    5670                 :             :           break;
    5671                 :             :         }
    5672                 :       47936 :       if (supportable_widening_operation (vinfo, code, stmt_info,
    5673                 :             :                                                vectype_out, vectype_in, &code1,
    5674                 :             :                                                &code2, &multi_step_cvt,
    5675                 :             :                                                &interm_types))
    5676                 :             :         {
    5677                 :             :           /* Binary widening operation can only be supported directly by the
    5678                 :             :              architecture.  */
    5679                 :       38899 :           gcc_assert (!(multi_step_cvt && op_type == binary_op));
    5680                 :             :           break;
    5681                 :             :         }
    5682                 :             : 
    5683                 :        9037 :       if (code != FLOAT_EXPR
    5684                 :        9381 :           || GET_MODE_SIZE (lhs_mode) <= GET_MODE_SIZE (rhs_mode))
    5685                 :        8865 :         goto unsupported;
    5686                 :             : 
    5687                 :         172 :       fltsz = GET_MODE_SIZE (lhs_mode);
    5688                 :         247 :       FOR_EACH_2XWIDER_MODE (rhs_mode_iter, rhs_mode)
    5689                 :             :         {
    5690                 :         247 :           rhs_mode = rhs_mode_iter.require ();
    5691                 :         494 :           if (GET_MODE_SIZE (rhs_mode) > fltsz)
    5692                 :             :             break;
    5693                 :             : 
    5694                 :         247 :           cvt_type
    5695                 :         247 :             = build_nonstandard_integer_type (GET_MODE_BITSIZE (rhs_mode), 0);
    5696                 :         247 :           cvt_type = get_same_sized_vectype (cvt_type, vectype_in);
    5697                 :         247 :           if (cvt_type == NULL_TREE)
    5698                 :           0 :             goto unsupported;
    5699                 :             : 
    5700                 :         494 :           if (GET_MODE_SIZE (rhs_mode) == fltsz)
    5701                 :             :             {
    5702                 :          57 :               tc1 = ERROR_MARK;
    5703                 :          57 :               gcc_assert (code.is_tree_code ());
    5704                 :          57 :               if (!supportable_convert_operation ((tree_code) code, vectype_out,
    5705                 :             :                                                   cvt_type, &tc1))
    5706                 :          22 :                 goto unsupported;
    5707                 :          35 :               codecvt1 = tc1;
    5708                 :             :             }
    5709                 :         190 :           else if (!supportable_widening_operation (vinfo, code,
    5710                 :             :                                                     stmt_info, vectype_out,
    5711                 :             :                                                     cvt_type, &codecvt1,
    5712                 :             :                                                     &codecvt2, &multi_step_cvt,
    5713                 :             :                                                     &interm_types))
    5714                 :          75 :             continue;
    5715                 :             :           else
    5716                 :         115 :             gcc_assert (multi_step_cvt == 0);
    5717                 :             : 
    5718                 :         150 :           if (supportable_widening_operation (vinfo, NOP_EXPR, stmt_info,
    5719                 :             :                                               cvt_type,
    5720                 :             :                                               vectype_in, &code1,
    5721                 :             :                                               &code2, &multi_step_cvt,
    5722                 :             :                                               &interm_types))
    5723                 :             :             {
    5724                 :             :               found_mode = true;
    5725                 :             :               break;
    5726                 :             :             }
    5727                 :             :         }
    5728                 :             : 
    5729                 :         150 :       if (!found_mode)
    5730                 :           0 :         goto unsupported;
    5731                 :             : 
    5732                 :         300 :       if (GET_MODE_SIZE (rhs_mode) == fltsz)
    5733                 :          35 :         codecvt2 = ERROR_MARK;
    5734                 :             :       else
    5735                 :             :         {
    5736                 :         115 :           multi_step_cvt++;
    5737                 :         115 :           interm_types.safe_push (cvt_type);
    5738                 :         115 :           cvt_type = NULL_TREE;
    5739                 :             :         }
    5740                 :             :       break;
    5741                 :             : 
    5742                 :       32757 :     case NARROW_DST:
    5743                 :       32757 :       gcc_assert (op_type == unary_op);
    5744                 :       32757 :       if (supportable_narrowing_operation (code, vectype_out, vectype_in,
    5745                 :             :                                            &code1, &multi_step_cvt,
    5746                 :             :                                            &interm_types))
    5747                 :             :         break;
    5748                 :             : 
    5749                 :       14091 :       if (GET_MODE_SIZE (lhs_mode) >= GET_MODE_SIZE (rhs_mode))
    5750                 :         580 :         goto unsupported;
    5751                 :             : 
    5752                 :        4117 :       if (code == FIX_TRUNC_EXPR)
    5753                 :             :         {
    5754                 :         276 :           cvt_type
    5755                 :         276 :             = build_nonstandard_integer_type (GET_MODE_BITSIZE (rhs_mode), 0);
    5756                 :         276 :           cvt_type = get_same_sized_vectype (cvt_type, vectype_in);
    5757                 :         276 :           if (cvt_type == NULL_TREE)
    5758                 :           0 :             goto unsupported;
    5759                 :         276 :           if (supportable_convert_operation ((tree_code) code, cvt_type, vectype_in,
    5760                 :             :                                               &tc1))
    5761                 :         274 :             codecvt1 = tc1;
    5762                 :             :           else
    5763                 :           2 :             goto unsupported;
    5764                 :         274 :           if (supportable_narrowing_operation (NOP_EXPR, vectype_out, cvt_type,
    5765                 :             :                                                &code1, &multi_step_cvt,
    5766                 :             :                                                &interm_types))
    5767                 :             :             break;
    5768                 :             :         }
    5769                 :             :       /* If op0 can be represented with low precision integer,
    5770                 :             :          truncate it to cvt_type and the do FLOAT_EXPR.  */
    5771                 :        3841 :       else if (code == FLOAT_EXPR)
    5772                 :             :         {
    5773                 :          98 :           wide_int op_min_value, op_max_value;
    5774                 :          98 :           tree def;
    5775                 :             :           /* ???  Merge ranges in case of more than one lane.  */
    5776                 :          98 :           if (SLP_TREE_LANES (slp_op0) != 1
    5777                 :          94 :               || !(def = vect_get_slp_scalar_def (slp_op0, 0))
    5778                 :         192 :               || !vect_get_range_info (def, &op_min_value, &op_max_value))
    5779                 :          96 :             goto unsupported;
    5780                 :             : 
    5781                 :           2 :           cvt_type
    5782                 :           2 :             = build_nonstandard_integer_type (GET_MODE_BITSIZE (lhs_mode), 0);
    5783                 :           2 :           if (cvt_type == NULL_TREE
    5784                 :           2 :               || (wi::min_precision (op_max_value, SIGNED)
    5785                 :           2 :                   > TYPE_PRECISION (cvt_type))
    5786                 :           4 :               || (wi::min_precision (op_min_value, SIGNED)
    5787                 :           2 :                   > TYPE_PRECISION (cvt_type)))
    5788                 :           0 :             goto unsupported;
    5789                 :             : 
    5790                 :           2 :           cvt_type = get_same_sized_vectype (cvt_type, vectype_out);
    5791                 :           2 :           if (cvt_type == NULL_TREE)
    5792                 :           0 :             goto unsupported;
    5793                 :           2 :           if (!supportable_narrowing_operation (NOP_EXPR, cvt_type, vectype_in,
    5794                 :             :                                                 &code1, &multi_step_cvt,
    5795                 :             :                                                 &interm_types))
    5796                 :           0 :             goto unsupported;
    5797                 :           2 :           if (supportable_convert_operation ((tree_code) code, vectype_out,
    5798                 :             :                                              cvt_type, &tc1))
    5799                 :             :             {
    5800                 :           2 :               codecvt1 = tc1;
    5801                 :           2 :               modifier = NARROW_SRC;
    5802                 :           2 :               break;
    5803                 :             :             }
    5804                 :          98 :         }
    5805                 :             : 
    5806                 :        3747 :       goto unsupported;
    5807                 :             : 
    5808                 :             :     default:
    5809                 :             :       gcc_unreachable ();
    5810                 :             :     }
    5811                 :             : 
    5812                 :       85506 :   if (!vec_stmt)                /* transformation not required.  */
    5813                 :             :     {
    5814                 :       66196 :       if (!vect_maybe_update_slp_op_vectype (slp_op0, vectype_in)
    5815                 :       66196 :           || !vect_maybe_update_slp_op_vectype (slp_op1, vectype_in))
    5816                 :             :         {
    5817                 :           0 :           if (dump_enabled_p ())
    5818                 :           0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    5819                 :             :                              "incompatible vector types for invariants\n");
    5820                 :           0 :           return false;
    5821                 :             :         }
    5822                 :       66196 :       DUMP_VECT_SCOPE ("vectorizable_conversion");
    5823                 :       66196 :       if (modifier == NONE)
    5824                 :             :         {
    5825                 :       13769 :           STMT_VINFO_TYPE (stmt_info) = type_conversion_vec_info_type;
    5826                 :       13769 :           vect_model_simple_cost (vinfo, (1 + multi_step_cvt),
    5827                 :             :                                   dt, ndts, slp_node, cost_vec);
    5828                 :             :         }
    5829                 :       52427 :       else if (modifier == NARROW_SRC || modifier == NARROW_DST)
    5830                 :             :         {
    5831                 :       20907 :           STMT_VINFO_TYPE (stmt_info) = type_demotion_vec_info_type;
    5832                 :             :           /* The final packing step produces one vector result per copy.  */
    5833                 :       20907 :           unsigned int nvectors = SLP_TREE_NUMBER_OF_VEC_STMTS (slp_node);
    5834                 :       20907 :           vect_model_promotion_demotion_cost (stmt_info, dt, nvectors,
    5835                 :             :                                               multi_step_cvt, cost_vec,
    5836                 :             :                                               widen_arith);
    5837                 :             :         }
    5838                 :             :       else
    5839                 :             :         {
    5840                 :       31520 :           STMT_VINFO_TYPE (stmt_info) = type_promotion_vec_info_type;
    5841                 :             :           /* The initial unpacking step produces two vector results
    5842                 :             :              per copy.  MULTI_STEP_CVT is 0 for a single conversion,
    5843                 :             :              so >> MULTI_STEP_CVT divides by 2^(number of steps - 1).  */
    5844                 :       31520 :           unsigned int nvectors
    5845                 :       31520 :             = SLP_TREE_NUMBER_OF_VEC_STMTS (slp_node) >> multi_step_cvt;
    5846                 :       31520 :           vect_model_promotion_demotion_cost (stmt_info, dt, nvectors,
    5847                 :             :                                               multi_step_cvt, cost_vec,
    5848                 :             :                                               widen_arith);
    5849                 :             :         }
    5850                 :       66196 :       interm_types.release ();
    5851                 :       66196 :       return true;
    5852                 :             :     }
    5853                 :             : 
    5854                 :             :   /* Transform.  */
    5855                 :       19310 :   if (dump_enabled_p ())
    5856                 :        4054 :     dump_printf_loc (MSG_NOTE, vect_location, "transform conversion.\n");
    5857                 :             : 
    5858                 :       19310 :   if (op_type == binary_op)
    5859                 :             :     {
    5860                 :         458 :       if (CONSTANT_CLASS_P (op0))
    5861                 :           0 :         op0 = fold_convert (TREE_TYPE (op1), op0);
    5862                 :         458 :       else if (CONSTANT_CLASS_P (op1))
    5863                 :         204 :         op1 = fold_convert (TREE_TYPE (op0), op1);
    5864                 :             :     }
    5865                 :             : 
    5866                 :             :   /* In case of multi-step conversion, we first generate conversion operations
    5867                 :             :      to the intermediate types, and then from that types to the final one.
    5868                 :             :      We create vector destinations for the intermediate type (TYPES) received
    5869                 :             :      from supportable_*_operation, and store them in the correct order
    5870                 :             :      for future use in vect_create_vectorized_*_stmts ().  */
    5871                 :       38620 :   auto_vec<tree> vec_dsts (multi_step_cvt + 1);
    5872                 :       19310 :   bool widen_or_narrow_float_p
    5873                 :       19310 :     = cvt_type && (modifier == WIDEN || modifier == NARROW_SRC);
    5874                 :       19310 :   vec_dest = vect_create_destination_var (scalar_dest,
    5875                 :             :                                           widen_or_narrow_float_p
    5876                 :             :                                           ? cvt_type : vectype_out);
    5877                 :       19310 :   vec_dsts.quick_push (vec_dest);
    5878                 :             : 
    5879                 :       19310 :   if (multi_step_cvt)
    5880                 :             :     {
    5881                 :        6262 :       for (i = interm_types.length () - 1;
    5882                 :        6509 :            interm_types.iterate (i, &intermediate_type); i--)
    5883                 :             :         {
    5884                 :        3378 :           vec_dest = vect_create_destination_var (scalar_dest,
    5885                 :             :                                                   intermediate_type);
    5886                 :        3378 :           vec_dsts.quick_push (vec_dest);
    5887                 :             :         }
    5888                 :             :     }
    5889                 :             : 
    5890                 :       19310 :   if (cvt_type)
    5891                 :          69 :     vec_dest = vect_create_destination_var (scalar_dest,
    5892                 :             :                                             widen_or_narrow_float_p
    5893                 :             :                                             ? vectype_out : cvt_type);
    5894                 :             : 
    5895                 :       19310 :   switch (modifier)
    5896                 :             :     {
    5897                 :        4188 :     case NONE:
    5898                 :        4188 :       vect_get_vec_defs (vinfo, stmt_info, slp_node, 1,
    5899                 :             :                          op0, vectype_in, &vec_oprnds0);
    5900                 :             :       /* vec_dest is intermediate type operand when multi_step_cvt.  */
    5901                 :        4188 :       if (multi_step_cvt)
    5902                 :             :         {
    5903                 :          21 :           cvt_op = vec_dest;
    5904                 :          21 :           vec_dest = vec_dsts[0];
    5905                 :             :         }
    5906                 :             : 
    5907                 :        8701 :       FOR_EACH_VEC_ELT (vec_oprnds0, i, vop0)
    5908                 :             :         {
    5909                 :             :           /* Arguments are ready, create the new vector stmt.  */
    5910                 :        4513 :           gimple* new_stmt;
    5911                 :        4513 :           if (multi_step_cvt)
    5912                 :             :             {
    5913                 :          21 :               gcc_assert (multi_step_cvt == 1);
    5914                 :          21 :               new_stmt = vect_gimple_build (cvt_op, codecvt1, vop0);
    5915                 :          21 :               new_temp = make_ssa_name (cvt_op, new_stmt);
    5916                 :          21 :               gimple_assign_set_lhs (new_stmt, new_temp);
    5917                 :          21 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    5918                 :          21 :               vop0 = new_temp;
    5919                 :             :             }
    5920                 :        4513 :           new_stmt = vect_gimple_build (vec_dest, code1, vop0);
    5921                 :        4513 :           new_temp = make_ssa_name (vec_dest, new_stmt);
    5922                 :        4513 :           gimple_set_lhs (new_stmt, new_temp);
    5923                 :        4513 :           vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    5924                 :             : 
    5925                 :        4513 :           slp_node->push_vec_def (new_stmt);
    5926                 :             :         }
    5927                 :             :       break;
    5928                 :             : 
    5929                 :        7697 :     case WIDEN:
    5930                 :             :       /* In case the vectorization factor (VF) is bigger than the number
    5931                 :             :          of elements that we can fit in a vectype (nunits), we have to
    5932                 :             :          generate more than one vector stmt - i.e - we need to "unroll"
    5933                 :             :          the vector stmt by a factor VF/nunits.  */
    5934                 :        7697 :       vect_get_vec_defs (vinfo, stmt_info, slp_node, 1,
    5935                 :             :                          op0, vectype_in, &vec_oprnds0,
    5936                 :        7697 :                          code == WIDEN_LSHIFT_EXPR ? NULL_TREE : op1,
    5937                 :             :                          vectype_in, &vec_oprnds1);
    5938                 :        7697 :       if (code == WIDEN_LSHIFT_EXPR)
    5939                 :             :         {
    5940                 :           0 :           int oprnds_size = vec_oprnds0.length ();
    5941                 :           0 :           vec_oprnds1.create (oprnds_size);
    5942                 :           0 :           for (i = 0; i < oprnds_size; ++i)
    5943                 :           0 :             vec_oprnds1.quick_push (op1);
    5944                 :             :         }
    5945                 :             :       /* Arguments are ready.  Create the new vector stmts.  */
    5946                 :       16677 :       for (i = multi_step_cvt; i >= 0; i--)
    5947                 :             :         {
    5948                 :        8980 :           tree this_dest = vec_dsts[i];
    5949                 :        8980 :           code_helper c1 = code1, c2 = code2;
    5950                 :        8980 :           if (i == 0 && codecvt2 != ERROR_MARK)
    5951                 :             :             {
    5952                 :          48 :               c1 = codecvt1;
    5953                 :          48 :               c2 = codecvt2;
    5954                 :             :             }
    5955                 :        8980 :           if (known_eq (nunits_out, nunits_in))
    5956                 :          14 :             vect_create_half_widening_stmts (vinfo, &vec_oprnds0, &vec_oprnds1,
    5957                 :             :                                              stmt_info, this_dest, gsi, c1,
    5958                 :             :                                              op_type);
    5959                 :             :           else
    5960                 :        8966 :             vect_create_vectorized_promotion_stmts (vinfo, &vec_oprnds0,
    5961                 :             :                                                     &vec_oprnds1, stmt_info,
    5962                 :             :                                                     this_dest, gsi,
    5963                 :             :                                                     c1, c2, op_type);
    5964                 :             :         }
    5965                 :             : 
    5966                 :       27737 :       FOR_EACH_VEC_ELT (vec_oprnds0, i, vop0)
    5967                 :             :         {
    5968                 :       20040 :           gimple *new_stmt;
    5969                 :       20040 :           if (cvt_type)
    5970                 :             :             {
    5971                 :         120 :               new_temp = make_ssa_name (vec_dest);
    5972                 :         120 :               new_stmt = vect_gimple_build (new_temp, codecvt1, vop0);
    5973                 :         120 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    5974                 :             :             }
    5975                 :             :           else
    5976                 :       19920 :             new_stmt = SSA_NAME_DEF_STMT (vop0);
    5977                 :             : 
    5978                 :       20040 :           slp_node->push_vec_def (new_stmt);
    5979                 :             :         }
    5980                 :             :       break;
    5981                 :             : 
    5982                 :        7425 :     case NARROW_SRC:
    5983                 :        7425 :     case NARROW_DST:
    5984                 :             :       /* In case the vectorization factor (VF) is bigger than the number
    5985                 :             :          of elements that we can fit in a vectype (nunits), we have to
    5986                 :             :          generate more than one vector stmt - i.e - we need to "unroll"
    5987                 :             :          the vector stmt by a factor VF/nunits.  */
    5988                 :        7425 :       vect_get_vec_defs (vinfo, stmt_info, slp_node, 1,
    5989                 :             :                          op0, vectype_in, &vec_oprnds0);
    5990                 :             :       /* Arguments are ready.  Create the new vector stmts.  */
    5991                 :        7425 :       if (cvt_type && modifier == NARROW_DST)
    5992                 :         153 :         FOR_EACH_VEC_ELT (vec_oprnds0, i, vop0)
    5993                 :             :           {
    5994                 :         124 :             new_temp = make_ssa_name (vec_dest);
    5995                 :         124 :             gimple *new_stmt = vect_gimple_build (new_temp, codecvt1, vop0);
    5996                 :         124 :             vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    5997                 :         124 :             vec_oprnds0[i] = new_temp;
    5998                 :             :           }
    5999                 :             : 
    6000                 :        7425 :       vect_create_vectorized_demotion_stmts (vinfo, &vec_oprnds0,
    6001                 :             :                                              multi_step_cvt,
    6002                 :             :                                              stmt_info, vec_dsts, gsi,
    6003                 :             :                                              slp_node, code1,
    6004                 :             :                                              modifier == NARROW_SRC);
    6005                 :             :       /* After demoting op0 to cvt_type, convert it to dest.  */
    6006                 :        7425 :       if (cvt_type && code == FLOAT_EXPR)
    6007                 :             :         {
    6008                 :           4 :           for (unsigned int i = 0; i != vec_oprnds0.length() / 2;  i++)
    6009                 :             :             {
    6010                 :             :               /* Arguments are ready, create the new vector stmt.  */
    6011                 :           1 :               gcc_assert (TREE_CODE_LENGTH ((tree_code) codecvt1) == unary_op);
    6012                 :           1 :               gimple *new_stmt
    6013                 :           1 :                 = vect_gimple_build (vec_dest, codecvt1, vec_oprnds0[i]);
    6014                 :           1 :               new_temp = make_ssa_name (vec_dest, new_stmt);
    6015                 :           1 :               gimple_set_lhs (new_stmt, new_temp);
    6016                 :           1 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    6017                 :             : 
    6018                 :             :               /* This is the last step of the conversion sequence. Store the
    6019                 :             :                  vectors in SLP_NODE or in vector info of the scalar statement
    6020                 :             :                  (or in STMT_VINFO_RELATED_STMT chain).  */
    6021                 :           1 :               slp_node->push_vec_def (new_stmt);
    6022                 :             :             }
    6023                 :             :         }
    6024                 :             :       break;
    6025                 :             :     }
    6026                 :             : 
    6027                 :       19310 :   vec_oprnds0.release ();
    6028                 :       19310 :   vec_oprnds1.release ();
    6029                 :       19310 :   interm_types.release ();
    6030                 :             : 
    6031                 :       19310 :   return true;
    6032                 :      155693 : }
    6033                 :             : 
    6034                 :             : /* Return true if we can assume from the scalar form of STMT_INFO that
    6035                 :             :    neither the scalar nor the vector forms will generate code.  STMT_INFO
    6036                 :             :    is known not to involve a data reference.  */
    6037                 :             : 
    6038                 :             : bool
    6039                 :     1021307 : vect_nop_conversion_p (stmt_vec_info stmt_info)
    6040                 :             : {
    6041                 :     1021307 :   gassign *stmt = dyn_cast <gassign *> (stmt_info->stmt);
    6042                 :      807600 :   if (!stmt)
    6043                 :             :     return false;
    6044                 :             : 
    6045                 :      807600 :   tree lhs = gimple_assign_lhs (stmt);
    6046                 :      807600 :   tree_code code = gimple_assign_rhs_code (stmt);
    6047                 :      807600 :   tree rhs = gimple_assign_rhs1 (stmt);
    6048                 :             : 
    6049                 :      807600 :   if (code == SSA_NAME || code == VIEW_CONVERT_EXPR)
    6050                 :             :     return true;
    6051                 :             : 
    6052                 :      805769 :   if (CONVERT_EXPR_CODE_P (code))
    6053                 :      188081 :     return tree_nop_conversion_p (TREE_TYPE (lhs), TREE_TYPE (rhs));
    6054                 :             : 
    6055                 :             :   return false;
    6056                 :             : }
    6057                 :             : 
    6058                 :             : /* Function vectorizable_assignment.
    6059                 :             : 
    6060                 :             :    Check if STMT_INFO performs an assignment (copy) that can be vectorized.
    6061                 :             :    If VEC_STMT is also passed, vectorize the STMT_INFO: create a vectorized
    6062                 :             :    stmt to replace it, put it in VEC_STMT, and insert it at GSI.
    6063                 :             :    Return true if STMT_INFO is vectorizable in this way.  */
    6064                 :             : 
    6065                 :             : static bool
    6066                 :     1993361 : vectorizable_assignment (vec_info *vinfo,
    6067                 :             :                          stmt_vec_info stmt_info, gimple_stmt_iterator *gsi,
    6068                 :             :                          gimple **vec_stmt, slp_tree slp_node,
    6069                 :             :                          stmt_vector_for_cost *cost_vec)
    6070                 :             : {
    6071                 :     1993361 :   tree vec_dest;
    6072                 :     1993361 :   tree scalar_dest;
    6073                 :     1993361 :   tree op;
    6074                 :     1993361 :   loop_vec_info loop_vinfo = dyn_cast <loop_vec_info> (vinfo);
    6075                 :     1993361 :   tree new_temp;
    6076                 :     1993361 :   enum vect_def_type dt[1] = {vect_unknown_def_type};
    6077                 :     1993361 :   int ndts = 1;
    6078                 :     1993361 :   int ncopies;
    6079                 :     1993361 :   int i;
    6080                 :     1993361 :   vec<tree> vec_oprnds = vNULL;
    6081                 :     1993361 :   tree vop;
    6082                 :     1993361 :   bb_vec_info bb_vinfo = dyn_cast <bb_vec_info> (vinfo);
    6083                 :     1993361 :   enum tree_code code;
    6084                 :     1993361 :   tree vectype_in;
    6085                 :             : 
    6086                 :     1993361 :   if (!STMT_VINFO_RELEVANT_P (stmt_info) && !bb_vinfo)
    6087                 :             :     return false;
    6088                 :             : 
    6089                 :     1993361 :   if (STMT_VINFO_DEF_TYPE (stmt_info) != vect_internal_def
    6090                 :      200344 :       && ! vec_stmt)
    6091                 :             :     return false;
    6092                 :             : 
    6093                 :             :   /* Is vectorizable assignment?  */
    6094                 :     3633360 :   gassign *stmt = dyn_cast <gassign *> (stmt_info->stmt);
    6095                 :     1715089 :   if (!stmt)
    6096                 :             :     return false;
    6097                 :             : 
    6098                 :     1715089 :   scalar_dest = gimple_assign_lhs (stmt);
    6099                 :     1715089 :   if (TREE_CODE (scalar_dest) != SSA_NAME)
    6100                 :             :     return false;
    6101                 :             : 
    6102                 :      859332 :   if (STMT_VINFO_DATA_REF (stmt_info))
    6103                 :             :     return false;
    6104                 :             : 
    6105                 :      359803 :   code = gimple_assign_rhs_code (stmt);
    6106                 :      359803 :   if (!(gimple_assign_single_p (stmt)
    6107                 :      358450 :         || code == PAREN_EXPR
    6108                 :      356633 :         || CONVERT_EXPR_CODE_P (code)))
    6109                 :             :     return false;
    6110                 :             : 
    6111                 :       94669 :   tree vectype = STMT_VINFO_VECTYPE (stmt_info);
    6112                 :       94669 :   poly_uint64 nunits = TYPE_VECTOR_SUBPARTS (vectype);
    6113                 :             : 
    6114                 :             :   /* Multiple types in SLP are handled by creating the appropriate number of
    6115                 :             :      vectorized stmts for each SLP node.  Hence, NCOPIES is always 1 in
    6116                 :             :      case of SLP.  */
    6117                 :       94669 :   if (slp_node)
    6118                 :             :     ncopies = 1;
    6119                 :             :   else
    6120                 :           0 :     ncopies = vect_get_num_copies (loop_vinfo, vectype);
    6121                 :             : 
    6122                 :           0 :   gcc_assert (ncopies >= 1);
    6123                 :             : 
    6124                 :       94669 :   slp_tree slp_op;
    6125                 :       94669 :   if (!vect_is_simple_use (vinfo, stmt_info, slp_node, 0, &op, &slp_op,
    6126                 :             :                            &dt[0], &vectype_in))
    6127                 :             :     {
    6128                 :           0 :       if (dump_enabled_p ())
    6129                 :           0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6130                 :             :                          "use not simple.\n");
    6131                 :           0 :       return false;
    6132                 :             :     }
    6133                 :       94669 :   if (!vectype_in)
    6134                 :       20750 :     vectype_in = get_vectype_for_scalar_type (vinfo, TREE_TYPE (op), slp_node);
    6135                 :             : 
    6136                 :             :   /* We can handle VIEW_CONVERT conversions that do not change the number
    6137                 :             :      of elements or the vector size or other conversions when the component
    6138                 :             :      types are nop-convertible.  */
    6139                 :       94669 :   if (!vectype_in
    6140                 :       92740 :       || maybe_ne (TYPE_VECTOR_SUBPARTS (vectype_in), nunits)
    6141                 :       78952 :       || (code == VIEW_CONVERT_EXPR
    6142                 :        2176 :           && maybe_ne (GET_MODE_SIZE (TYPE_MODE (vectype)),
    6143                 :        2176 :                        GET_MODE_SIZE (TYPE_MODE (vectype_in))))
    6144                 :      173621 :       || (CONVERT_EXPR_CODE_P (code)
    6145                 :       75953 :           && !tree_nop_conversion_p (TREE_TYPE (vectype),
    6146                 :       75953 :                                      TREE_TYPE (vectype_in))))
    6147                 :       19309 :     return false;
    6148                 :             : 
    6149                 :      225968 :   if (VECTOR_BOOLEAN_TYPE_P (vectype) != VECTOR_BOOLEAN_TYPE_P (vectype_in))
    6150                 :             :     {
    6151                 :           0 :       if (dump_enabled_p ())
    6152                 :           0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6153                 :             :                          "can't convert between boolean and non "
    6154                 :           0 :                          "boolean vectors %T\n", TREE_TYPE (op));
    6155                 :             : 
    6156                 :           0 :       return false;
    6157                 :             :     }
    6158                 :             : 
    6159                 :             :   /* We do not handle bit-precision changes.  */
    6160                 :       75360 :   if ((CONVERT_EXPR_CODE_P (code)
    6161                 :        2999 :        || code == VIEW_CONVERT_EXPR)
    6162                 :       73449 :       && ((INTEGRAL_TYPE_P (TREE_TYPE (scalar_dest))
    6163                 :       72123 :            && !type_has_mode_precision_p (TREE_TYPE (scalar_dest)))
    6164                 :       73141 :           || (INTEGRAL_TYPE_P (TREE_TYPE (op))
    6165                 :       67456 :               && !type_has_mode_precision_p (TREE_TYPE (op))))
    6166                 :             :       /* But a conversion that does not change the bit-pattern is ok.  */
    6167                 :       76134 :       && !(INTEGRAL_TYPE_P (TREE_TYPE (scalar_dest))
    6168                 :         774 :            && INTEGRAL_TYPE_P (TREE_TYPE (op))
    6169                 :         774 :            && (((TYPE_PRECISION (TREE_TYPE (scalar_dest))
    6170                 :         774 :                > TYPE_PRECISION (TREE_TYPE (op)))
    6171                 :         466 :              && TYPE_UNSIGNED (TREE_TYPE (op)))
    6172                 :         332 :                || (TYPE_PRECISION (TREE_TYPE (scalar_dest))
    6173                 :         332 :                    == TYPE_PRECISION (TREE_TYPE (op))))))
    6174                 :             :     {
    6175                 :         270 :       if (dump_enabled_p ())
    6176                 :           0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6177                 :             :                          "type conversion to/from bit-precision "
    6178                 :             :                          "unsupported.\n");
    6179                 :         270 :       return false;
    6180                 :             :     }
    6181                 :             : 
    6182                 :       75090 :   if (!vec_stmt) /* transformation not required.  */
    6183                 :             :     {
    6184                 :       61295 :       if (slp_node
    6185                 :       61295 :           && !vect_maybe_update_slp_op_vectype (slp_op, vectype_in))
    6186                 :             :         {
    6187                 :           0 :           if (dump_enabled_p ())
    6188                 :           0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6189                 :             :                              "incompatible vector types for invariants\n");
    6190                 :           0 :           return false;
    6191                 :             :         }
    6192                 :       61295 :       STMT_VINFO_TYPE (stmt_info) = assignment_vec_info_type;
    6193                 :       61295 :       DUMP_VECT_SCOPE ("vectorizable_assignment");
    6194                 :       61295 :       if (!vect_nop_conversion_p (stmt_info))
    6195                 :        1651 :         vect_model_simple_cost (vinfo, ncopies, dt, ndts, slp_node, cost_vec);
    6196                 :       61295 :       return true;
    6197                 :             :     }
    6198                 :             : 
    6199                 :             :   /* Transform.  */
    6200                 :       13795 :   if (dump_enabled_p ())
    6201                 :        3329 :     dump_printf_loc (MSG_NOTE, vect_location, "transform assignment.\n");
    6202                 :             : 
    6203                 :             :   /* Handle def.  */
    6204                 :       13795 :   vec_dest = vect_create_destination_var (scalar_dest, vectype);
    6205                 :             : 
    6206                 :             :   /* Handle use.  */
    6207                 :       13795 :   vect_get_vec_defs (vinfo, stmt_info, slp_node, ncopies, op, &vec_oprnds);
    6208                 :             : 
    6209                 :             :   /* Arguments are ready. create the new vector stmt.  */
    6210                 :       30221 :   FOR_EACH_VEC_ELT (vec_oprnds, i, vop)
    6211                 :             :     {
    6212                 :       16426 :       if (CONVERT_EXPR_CODE_P (code)
    6213                 :         639 :           || code == VIEW_CONVERT_EXPR)
    6214                 :       15879 :         vop = build1 (VIEW_CONVERT_EXPR, vectype, vop);
    6215                 :       16426 :       gassign *new_stmt = gimple_build_assign (vec_dest, vop);
    6216                 :       16426 :       new_temp = make_ssa_name (vec_dest, new_stmt);
    6217                 :       16426 :       gimple_assign_set_lhs (new_stmt, new_temp);
    6218                 :       16426 :       vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    6219                 :       16426 :       if (slp_node)
    6220                 :       16426 :         slp_node->push_vec_def (new_stmt);
    6221                 :             :       else
    6222                 :           0 :         STMT_VINFO_VEC_STMTS (stmt_info).safe_push (new_stmt);
    6223                 :             :     }
    6224                 :       13795 :   if (!slp_node)
    6225                 :           0 :     *vec_stmt = STMT_VINFO_VEC_STMTS (stmt_info)[0];
    6226                 :             : 
    6227                 :       13795 :   vec_oprnds.release ();
    6228                 :       13795 :   return true;
    6229                 :             : }
    6230                 :             : 
    6231                 :             : 
    6232                 :             : /* Return TRUE if CODE (a shift operation) is supported for SCALAR_TYPE
    6233                 :             :    either as shift by a scalar or by a vector.  */
    6234                 :             : 
    6235                 :             : bool
    6236                 :      258399 : vect_supportable_shift (vec_info *vinfo, enum tree_code code, tree scalar_type)
    6237                 :             : {
    6238                 :      258399 :   optab optab;
    6239                 :      258399 :   tree vectype;
    6240                 :             : 
    6241                 :      258399 :   vectype = get_vectype_for_scalar_type (vinfo, scalar_type);
    6242                 :      258399 :   if (!vectype)
    6243                 :             :     return false;
    6244                 :             : 
    6245                 :      258399 :   optab = optab_for_tree_code (code, vectype, optab_scalar);
    6246                 :      258399 :   if (optab && can_implement_p (optab, TYPE_MODE (vectype)))
    6247                 :             :     return true;
    6248                 :             : 
    6249                 :      226602 :   optab = optab_for_tree_code (code, vectype, optab_vector);
    6250                 :      226602 :   if (optab && can_implement_p (optab, TYPE_MODE (vectype)))
    6251                 :             :     return true;
    6252                 :             : 
    6253                 :             :   return false;
    6254                 :             : }
    6255                 :             : 
    6256                 :             : 
    6257                 :             : /* Function vectorizable_shift.
    6258                 :             : 
    6259                 :             :    Check if STMT_INFO performs a shift operation that can be vectorized.
    6260                 :             :    If VEC_STMT is also passed, vectorize the STMT_INFO: create a vectorized
    6261                 :             :    stmt to replace it, put it in VEC_STMT, and insert it at GSI.
    6262                 :             :    Return true if STMT_INFO is vectorizable in this way.  */
    6263                 :             : 
    6264                 :             : static bool
    6265                 :     1558686 : vectorizable_shift (vec_info *vinfo,
    6266                 :             :                     stmt_vec_info stmt_info, gimple_stmt_iterator *gsi,
    6267                 :             :                     gimple **vec_stmt, slp_tree slp_node,
    6268                 :             :                     stmt_vector_for_cost *cost_vec)
    6269                 :             : {
    6270                 :     1558686 :   tree vec_dest;
    6271                 :     1558686 :   tree scalar_dest;
    6272                 :     1558686 :   tree op0, op1 = NULL;
    6273                 :     1558686 :   tree vec_oprnd1 = NULL_TREE;
    6274                 :     1558686 :   tree vectype;
    6275                 :     1558686 :   loop_vec_info loop_vinfo = dyn_cast <loop_vec_info> (vinfo);
    6276                 :     1558686 :   enum tree_code code;
    6277                 :     1558686 :   machine_mode vec_mode;
    6278                 :     1558686 :   tree new_temp;
    6279                 :     1558686 :   optab optab;
    6280                 :     1558686 :   int icode;
    6281                 :     1558686 :   machine_mode optab_op2_mode;
    6282                 :     1558686 :   enum vect_def_type dt[2] = {vect_unknown_def_type, vect_unknown_def_type};
    6283                 :     1558686 :   int ndts = 2;
    6284                 :     1558686 :   poly_uint64 nunits_in;
    6285                 :     1558686 :   poly_uint64 nunits_out;
    6286                 :     1558686 :   tree vectype_out;
    6287                 :     1558686 :   tree op1_vectype;
    6288                 :     1558686 :   int ncopies;
    6289                 :     1558686 :   int i;
    6290                 :     1558686 :   vec<tree> vec_oprnds0 = vNULL;
    6291                 :     1558686 :   vec<tree> vec_oprnds1 = vNULL;
    6292                 :     1558686 :   tree vop0, vop1;
    6293                 :     1558686 :   unsigned int k;
    6294                 :     1558686 :   bool scalar_shift_arg = true;
    6295                 :     1558686 :   bb_vec_info bb_vinfo = dyn_cast <bb_vec_info> (vinfo);
    6296                 :     1558686 :   bool incompatible_op1_vectype_p = false;
    6297                 :             : 
    6298                 :     1558686 :   if (!STMT_VINFO_RELEVANT_P (stmt_info) && !bb_vinfo)
    6299                 :             :     return false;
    6300                 :             : 
    6301                 :     1558686 :   if (STMT_VINFO_DEF_TYPE (stmt_info) != vect_internal_def
    6302                 :       33288 :       && STMT_VINFO_DEF_TYPE (stmt_info) != vect_nested_cycle
    6303                 :       33288 :       && ! vec_stmt)
    6304                 :             :     return false;
    6305                 :             : 
    6306                 :             :   /* Is STMT a vectorizable binary/unary operation?   */
    6307                 :     2963334 :   gassign *stmt = dyn_cast <gassign *> (stmt_info->stmt);
    6308                 :     1449387 :   if (!stmt)
    6309                 :             :     return false;
    6310                 :             : 
    6311                 :     1449387 :   if (TREE_CODE (gimple_assign_lhs (stmt)) != SSA_NAME)
    6312                 :             :     return false;
    6313                 :             : 
    6314                 :      724365 :   code = gimple_assign_rhs_code (stmt);
    6315                 :             : 
    6316                 :      724365 :   if (!(code == LSHIFT_EXPR || code == RSHIFT_EXPR || code == LROTATE_EXPR
    6317                 :             :       || code == RROTATE_EXPR))
    6318                 :             :     return false;
    6319                 :             : 
    6320                 :       58773 :   scalar_dest = gimple_assign_lhs (stmt);
    6321                 :       58773 :   vectype_out = STMT_VINFO_VECTYPE (stmt_info);
    6322                 :       58773 :   if (!type_has_mode_precision_p (TREE_TYPE (scalar_dest)))
    6323                 :             :     {
    6324                 :           0 :       if (dump_enabled_p ())
    6325                 :           0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6326                 :             :                          "bit-precision shifts not supported.\n");
    6327                 :           0 :       return false;
    6328                 :             :     }
    6329                 :             : 
    6330                 :       58773 :   slp_tree slp_op0;
    6331                 :       58773 :   if (!vect_is_simple_use (vinfo, stmt_info, slp_node,
    6332                 :             :                            0, &op0, &slp_op0, &dt[0], &vectype))
    6333                 :             :     {
    6334                 :           0 :       if (dump_enabled_p ())
    6335                 :           0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6336                 :             :                          "use not simple.\n");
    6337                 :           0 :       return false;
    6338                 :             :     }
    6339                 :             :   /* If op0 is an external or constant def, infer the vector type
    6340                 :             :      from the scalar type.  */
    6341                 :       58773 :   if (!vectype)
    6342                 :       16988 :     vectype = get_vectype_for_scalar_type (vinfo, TREE_TYPE (op0), slp_node);
    6343                 :       58773 :   if (vec_stmt)
    6344                 :        5761 :     gcc_assert (vectype);
    6345                 :       58773 :   if (!vectype)
    6346                 :             :     {
    6347                 :           0 :       if (dump_enabled_p ())
    6348                 :           0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6349                 :             :                          "no vectype for scalar type\n");
    6350                 :           0 :       return false;
    6351                 :             :     }
    6352                 :             : 
    6353                 :       58773 :   nunits_out = TYPE_VECTOR_SUBPARTS (vectype_out);
    6354                 :       58773 :   nunits_in = TYPE_VECTOR_SUBPARTS (vectype);
    6355                 :       58773 :   if (maybe_ne (nunits_out, nunits_in))
    6356                 :             :     return false;
    6357                 :             : 
    6358                 :       58773 :   stmt_vec_info op1_def_stmt_info;
    6359                 :       58773 :   slp_tree slp_op1;
    6360                 :       58773 :   if (!vect_is_simple_use (vinfo, stmt_info, slp_node, 1, &op1, &slp_op1,
    6361                 :             :                            &dt[1], &op1_vectype, &op1_def_stmt_info))
    6362                 :             :     {
    6363                 :           0 :       if (dump_enabled_p ())
    6364                 :           0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6365                 :             :                          "use not simple.\n");
    6366                 :           0 :       return false;
    6367                 :             :     }
    6368                 :             : 
    6369                 :             :   /* Multiple types in SLP are handled by creating the appropriate number of
    6370                 :             :      vectorized stmts for each SLP node.  Hence, NCOPIES is always 1 in
    6371                 :             :      case of SLP.  */
    6372                 :       58773 :   if (slp_node)
    6373                 :             :     ncopies = 1;
    6374                 :             :   else
    6375                 :           0 :     ncopies = vect_get_num_copies (loop_vinfo, vectype);
    6376                 :             : 
    6377                 :           0 :   gcc_assert (ncopies >= 1);
    6378                 :             : 
    6379                 :             :   /* Determine whether the shift amount is a vector, or scalar.  If the
    6380                 :             :      shift/rotate amount is a vector, use the vector/vector shift optabs.  */
    6381                 :             : 
    6382                 :       58773 :   if ((dt[1] == vect_internal_def
    6383                 :       58773 :        || dt[1] == vect_induction_def
    6384                 :       42221 :        || dt[1] == vect_nested_cycle)
    6385                 :       16570 :       && (!slp_node || SLP_TREE_LANES (slp_node) == 1))
    6386                 :             :     scalar_shift_arg = false;
    6387                 :       42251 :   else if (dt[1] == vect_constant_def
    6388                 :             :            || dt[1] == vect_external_def
    6389                 :       42251 :            || dt[1] == vect_internal_def)
    6390                 :             :     {
    6391                 :             :       /* In SLP, need to check whether the shift count is the same,
    6392                 :             :          in loops if it is a constant or invariant, it is always
    6393                 :             :          a scalar shift.  */
    6394                 :       42243 :       if (slp_node)
    6395                 :             :         {
    6396                 :       42243 :           vec<stmt_vec_info> stmts = SLP_TREE_SCALAR_STMTS (slp_node);
    6397                 :       42243 :           stmt_vec_info slpstmt_info;
    6398                 :             : 
    6399                 :      115805 :           FOR_EACH_VEC_ELT (stmts, k, slpstmt_info)
    6400                 :       73562 :             if (slpstmt_info)
    6401                 :             :               {
    6402                 :       73562 :                 gassign *slpstmt = as_a <gassign *> (slpstmt_info->stmt);
    6403                 :      147124 :                 if (!operand_equal_p (gimple_assign_rhs2 (slpstmt), op1, 0))
    6404                 :       73562 :                   scalar_shift_arg = false;
    6405                 :             :               }
    6406                 :             : 
    6407                 :             :           /* For internal SLP defs we have to make sure we see scalar stmts
    6408                 :             :              for all vector elements.
    6409                 :             :              ???  For different vectors we could resort to a different
    6410                 :             :              scalar shift operand but code-generation below simply always
    6411                 :             :              takes the first.  */
    6412                 :       42243 :           if (dt[1] == vect_internal_def
    6413                 :       42243 :               && maybe_ne (nunits_out * SLP_TREE_NUMBER_OF_VEC_STMTS (slp_node),
    6414                 :          40 :                            stmts.length ()))
    6415                 :             :             scalar_shift_arg = false;
    6416                 :             :         }
    6417                 :             : 
    6418                 :             :       /* If the shift amount is computed by a pattern stmt we cannot
    6419                 :             :          use the scalar amount directly thus give up and use a vector
    6420                 :             :          shift.  */
    6421                 :       42243 :       if (op1_def_stmt_info && is_pattern_stmt_p (op1_def_stmt_info))
    6422                 :             :         scalar_shift_arg = false;
    6423                 :             :     }
    6424                 :             :   else
    6425                 :             :     {
    6426                 :           8 :       if (dump_enabled_p ())
    6427                 :           8 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6428                 :             :                          "operand mode requires invariant argument.\n");
    6429                 :           8 :       return false;
    6430                 :             :     }
    6431                 :             : 
    6432                 :             :   /* Vector shifted by vector.  */
    6433                 :       58793 :   bool was_scalar_shift_arg = scalar_shift_arg;
    6434                 :       42243 :   if (!scalar_shift_arg)
    6435                 :             :     {
    6436                 :       16550 :       optab = optab_for_tree_code (code, vectype, optab_vector);
    6437                 :       16550 :       if (dump_enabled_p ())
    6438                 :        1121 :         dump_printf_loc (MSG_NOTE, vect_location,
    6439                 :             :                          "vector/vector shift/rotate found.\n");
    6440                 :             : 
    6441                 :       16550 :       if (!op1_vectype)
    6442                 :           7 :         op1_vectype = get_vectype_for_scalar_type (vinfo, TREE_TYPE (op1),
    6443                 :             :                                                    slp_op1);
    6444                 :       16550 :       incompatible_op1_vectype_p
    6445                 :       33100 :         = (op1_vectype == NULL_TREE
    6446                 :       16550 :            || maybe_ne (TYPE_VECTOR_SUBPARTS (op1_vectype),
    6447                 :       16550 :                         TYPE_VECTOR_SUBPARTS (vectype))
    6448                 :       22960 :            || TYPE_MODE (op1_vectype) != TYPE_MODE (vectype));
    6449                 :        6405 :       if (incompatible_op1_vectype_p
    6450                 :       10145 :           && (!slp_node
    6451                 :       10145 :               || SLP_TREE_DEF_TYPE (slp_op1) != vect_constant_def
    6452                 :           1 :               || slp_op1->refcnt != 1))
    6453                 :             :         {
    6454                 :       10144 :           if (dump_enabled_p ())
    6455                 :          72 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6456                 :             :                              "unusable type for last operand in"
    6457                 :             :                              " vector/vector shift/rotate.\n");
    6458                 :       10144 :           return false;
    6459                 :             :         }
    6460                 :             :     }
    6461                 :             :   /* See if the machine has a vector shifted by scalar insn and if not
    6462                 :             :      then see if it has a vector shifted by vector insn.  */
    6463                 :             :   else
    6464                 :             :     {
    6465                 :       42215 :       optab = optab_for_tree_code (code, vectype, optab_scalar);
    6466                 :       42215 :       if (optab
    6467                 :       42215 :           && can_implement_p (optab, TYPE_MODE (vectype)))
    6468                 :             :         {
    6469                 :       42215 :           if (dump_enabled_p ())
    6470                 :        5280 :             dump_printf_loc (MSG_NOTE, vect_location,
    6471                 :             :                              "vector/scalar shift/rotate found.\n");
    6472                 :             :         }
    6473                 :             :       else
    6474                 :             :         {
    6475                 :           0 :           optab = optab_for_tree_code (code, vectype, optab_vector);
    6476                 :           0 :           if (optab
    6477                 :           0 :               && can_implement_p (optab, TYPE_MODE (vectype)))
    6478                 :             :             {
    6479                 :           0 :               scalar_shift_arg = false;
    6480                 :             : 
    6481                 :           0 :               if (dump_enabled_p ())
    6482                 :           0 :                 dump_printf_loc (MSG_NOTE, vect_location,
    6483                 :             :                                  "vector/vector shift/rotate found.\n");
    6484                 :             : 
    6485                 :           0 :               if (!op1_vectype)
    6486                 :           0 :                 op1_vectype = get_vectype_for_scalar_type (vinfo,
    6487                 :           0 :                                                            TREE_TYPE (op1),
    6488                 :             :                                                            slp_op1);
    6489                 :             : 
    6490                 :             :               /* Unlike the other binary operators, shifts/rotates have
    6491                 :             :                  the rhs being int, instead of the same type as the lhs,
    6492                 :             :                  so make sure the scalar is the right type if we are
    6493                 :             :                  dealing with vectors of long long/long/short/char.  */
    6494                 :           0 :               incompatible_op1_vectype_p
    6495                 :           0 :                 = (!op1_vectype
    6496                 :           0 :                    || !tree_nop_conversion_p (TREE_TYPE (vectype),
    6497                 :           0 :                                               TREE_TYPE (op1)));
    6498                 :           0 :               if (incompatible_op1_vectype_p
    6499                 :           0 :                   && dt[1] == vect_internal_def)
    6500                 :             :                 {
    6501                 :           0 :                   if (dump_enabled_p ())
    6502                 :           0 :                     dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6503                 :             :                                      "unusable type for last operand in"
    6504                 :             :                                      " vector/vector shift/rotate.\n");
    6505                 :           0 :                   return false;
    6506                 :             :                 }
    6507                 :             :             }
    6508                 :             :         }
    6509                 :             :     }
    6510                 :             : 
    6511                 :             :   /* Supportable by target?  */
    6512                 :       48621 :   if (!optab)
    6513                 :             :     {
    6514                 :           0 :       if (dump_enabled_p ())
    6515                 :           0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6516                 :             :                          "no optab.\n");
    6517                 :           0 :       return false;
    6518                 :             :     }
    6519                 :       48621 :   vec_mode = TYPE_MODE (vectype);
    6520                 :       48621 :   icode = (int) optab_handler (optab, vec_mode);
    6521                 :       48621 :   if (icode == CODE_FOR_nothing)
    6522                 :             :     {
    6523                 :        3882 :       if (dump_enabled_p ())
    6524                 :         776 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6525                 :             :                          "op not supported by target.\n");
    6526                 :        3882 :       return false;
    6527                 :             :     }
    6528                 :             :   /* vector lowering cannot optimize vector shifts using word arithmetic.  */
    6529                 :       44739 :   if (vect_emulated_vector_p (vectype))
    6530                 :             :     return false;
    6531                 :             : 
    6532                 :       44739 :   if (!vec_stmt) /* transformation not required.  */
    6533                 :             :     {
    6534                 :       38978 :       if (slp_node
    6535                 :       38978 :           && (!vect_maybe_update_slp_op_vectype (slp_op0, vectype)
    6536                 :       38978 :               || ((!scalar_shift_arg || dt[1] == vect_internal_def)
    6537                 :        1788 :                   && (!incompatible_op1_vectype_p
    6538                 :           1 :                       || dt[1] == vect_constant_def)
    6539                 :        1788 :                   && !vect_maybe_update_slp_op_vectype
    6540                 :        1788 :                         (slp_op1,
    6541                 :             :                          incompatible_op1_vectype_p ? vectype : op1_vectype))))
    6542                 :             :         {
    6543                 :           0 :           if (dump_enabled_p ())
    6544                 :           0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6545                 :             :                              "incompatible vector types for invariants\n");
    6546                 :           0 :           return false;
    6547                 :             :         }
    6548                 :             :       /* Now adjust the constant shift amount in place.  */
    6549                 :       38978 :       if (slp_node
    6550                 :       38978 :           && incompatible_op1_vectype_p
    6551                 :           1 :           && dt[1] == vect_constant_def)
    6552                 :             :         {
    6553                 :           4 :           for (unsigned i = 0;
    6554                 :           5 :                i < SLP_TREE_SCALAR_OPS (slp_op1).length (); ++i)
    6555                 :             :             {
    6556                 :           4 :               SLP_TREE_SCALAR_OPS (slp_op1)[i]
    6557                 :           4 :                 = fold_convert (TREE_TYPE (vectype),
    6558                 :             :                                 SLP_TREE_SCALAR_OPS (slp_op1)[i]);
    6559                 :           4 :               gcc_assert ((TREE_CODE (SLP_TREE_SCALAR_OPS (slp_op1)[i])
    6560                 :             :                            == INTEGER_CST));
    6561                 :             :             }
    6562                 :             :         }
    6563                 :       38978 :       STMT_VINFO_TYPE (stmt_info) = shift_vec_info_type;
    6564                 :       38978 :       DUMP_VECT_SCOPE ("vectorizable_shift");
    6565                 :       40756 :       vect_model_simple_cost (vinfo, ncopies, dt,
    6566                 :             :                               scalar_shift_arg ? 1 : ndts, slp_node, cost_vec);
    6567                 :       38978 :       return true;
    6568                 :             :     }
    6569                 :             : 
    6570                 :             :   /* Transform.  */
    6571                 :             : 
    6572                 :        5761 :   if (dump_enabled_p ())
    6573                 :        1833 :     dump_printf_loc (MSG_NOTE, vect_location,
    6574                 :             :                      "transform binary/unary operation.\n");
    6575                 :             : 
    6576                 :        5761 :   if (incompatible_op1_vectype_p && !slp_node)
    6577                 :             :     {
    6578                 :           0 :       gcc_assert (!scalar_shift_arg && was_scalar_shift_arg);
    6579                 :           0 :       op1 = fold_convert (TREE_TYPE (vectype), op1);
    6580                 :           0 :       if (dt[1] != vect_constant_def)
    6581                 :           0 :         op1 = vect_init_vector (vinfo, stmt_info, op1,
    6582                 :           0 :                                 TREE_TYPE (vectype), NULL);
    6583                 :             :     }
    6584                 :             : 
    6585                 :             :   /* Handle def.  */
    6586                 :        5761 :   vec_dest = vect_create_destination_var (scalar_dest, vectype);
    6587                 :             : 
    6588                 :        5761 :   if (scalar_shift_arg && dt[1] != vect_internal_def)
    6589                 :             :     {
    6590                 :             :       /* Vector shl and shr insn patterns can be defined with scalar
    6591                 :             :          operand 2 (shift operand).  In this case, use constant or loop
    6592                 :             :          invariant op1 directly, without extending it to vector mode
    6593                 :             :          first.  */
    6594                 :        5005 :       optab_op2_mode = insn_data[icode].operand[2].mode;
    6595                 :        5005 :       if (!VECTOR_MODE_P (optab_op2_mode))
    6596                 :             :         {
    6597                 :        5005 :           if (dump_enabled_p ())
    6598                 :        1727 :             dump_printf_loc (MSG_NOTE, vect_location,
    6599                 :             :                              "operand 1 using scalar mode.\n");
    6600                 :        5005 :           vec_oprnd1 = op1;
    6601                 :        5005 :           vec_oprnds1.create (slp_node ? slp_node->vec_stmts_size : ncopies);
    6602                 :        5005 :           vec_oprnds1.quick_push (vec_oprnd1);
    6603                 :             :               /* Store vec_oprnd1 for every vector stmt to be created.
    6604                 :             :                  We check during the analysis that all the shift arguments
    6605                 :             :                  are the same.
    6606                 :             :                  TODO: Allow different constants for different vector
    6607                 :             :                  stmts generated for an SLP instance.  */
    6608                 :        5005 :           for (k = 0;
    6609                 :        7071 :                k < (slp_node ? slp_node->vec_stmts_size - 1 : ncopies - 1); k++)
    6610                 :        2066 :             vec_oprnds1.quick_push (vec_oprnd1);
    6611                 :             :         }
    6612                 :             :     }
    6613                 :         756 :   else if (!scalar_shift_arg && slp_node && incompatible_op1_vectype_p)
    6614                 :             :     {
    6615                 :           0 :       if (was_scalar_shift_arg)
    6616                 :             :         {
    6617                 :             :           /* If the argument was the same in all lanes create the
    6618                 :             :              correctly typed vector shift amount directly.  Note
    6619                 :             :              we made SLP scheduling think we use the original scalars,
    6620                 :             :              so place the compensation code next to the shift which
    6621                 :             :              is conservative.  See PR119640 where it otherwise breaks.  */
    6622                 :           0 :           op1 = fold_convert (TREE_TYPE (vectype), op1);
    6623                 :           0 :           op1 = vect_init_vector (vinfo, stmt_info, op1, TREE_TYPE (vectype),
    6624                 :             :                                   gsi);
    6625                 :           0 :           vec_oprnd1 = vect_init_vector (vinfo, stmt_info, op1, vectype,
    6626                 :             :                                          gsi);
    6627                 :           0 :           vec_oprnds1.create (slp_node->vec_stmts_size);
    6628                 :           0 :           for (k = 0; k < slp_node->vec_stmts_size; k++)
    6629                 :           0 :             vec_oprnds1.quick_push (vec_oprnd1);
    6630                 :             :         }
    6631                 :           0 :       else if (dt[1] == vect_constant_def)
    6632                 :             :         /* The constant shift amount has been adjusted in place.  */
    6633                 :             :         ;
    6634                 :             :       else
    6635                 :           0 :         gcc_assert (TYPE_MODE (op1_vectype) == TYPE_MODE (vectype));
    6636                 :             :     }
    6637                 :             : 
    6638                 :             :   /* vec_oprnd1 is available if operand 1 should be of a scalar-type
    6639                 :             :      (a special case for certain kind of vector shifts); otherwise,
    6640                 :             :      operand 1 should be of a vector type (the usual case).  */
    6641                 :         756 :   vect_get_vec_defs (vinfo, stmt_info, slp_node, ncopies,
    6642                 :             :                      op0, &vec_oprnds0,
    6643                 :        5761 :                      vec_oprnd1 ? NULL_TREE : op1, &vec_oprnds1);
    6644                 :             : 
    6645                 :             :   /* Arguments are ready.  Create the new vector stmt.  */
    6646                 :       13996 :   FOR_EACH_VEC_ELT (vec_oprnds0, i, vop0)
    6647                 :             :     {
    6648                 :             :       /* For internal defs where we need to use a scalar shift arg
    6649                 :             :          extract the first lane.  */
    6650                 :        8235 :       if (scalar_shift_arg && dt[1] == vect_internal_def)
    6651                 :             :         {
    6652                 :          10 :           vop1 = vec_oprnds1[0];
    6653                 :          10 :           new_temp = make_ssa_name (TREE_TYPE (TREE_TYPE (vop1)));
    6654                 :          10 :           gassign *new_stmt
    6655                 :          10 :             = gimple_build_assign (new_temp,
    6656                 :          10 :                                    build3 (BIT_FIELD_REF, TREE_TYPE (new_temp),
    6657                 :             :                                            vop1,
    6658                 :          10 :                                            TYPE_SIZE (TREE_TYPE (new_temp)),
    6659                 :             :                                            bitsize_zero_node));
    6660                 :          10 :           vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    6661                 :          10 :           vop1 = new_temp;
    6662                 :          10 :         }
    6663                 :             :       else
    6664                 :        8225 :         vop1 = vec_oprnds1[i];
    6665                 :        8235 :       gassign *new_stmt = gimple_build_assign (vec_dest, code, vop0, vop1);
    6666                 :        8235 :       new_temp = make_ssa_name (vec_dest, new_stmt);
    6667                 :        8235 :       gimple_assign_set_lhs (new_stmt, new_temp);
    6668                 :        8235 :       vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    6669                 :        8235 :       if (slp_node)
    6670                 :        8235 :         slp_node->push_vec_def (new_stmt);
    6671                 :             :       else
    6672                 :           0 :         STMT_VINFO_VEC_STMTS (stmt_info).safe_push (new_stmt);
    6673                 :             :     }
    6674                 :             : 
    6675                 :        5761 :   if (!slp_node)
    6676                 :           0 :     *vec_stmt = STMT_VINFO_VEC_STMTS (stmt_info)[0];
    6677                 :             : 
    6678                 :        5761 :   vec_oprnds0.release ();
    6679                 :        5761 :   vec_oprnds1.release ();
    6680                 :             : 
    6681                 :        5761 :   return true;
    6682                 :             : }
    6683                 :             : 
    6684                 :             : /* Function vectorizable_operation.
    6685                 :             : 
    6686                 :             :    Check if STMT_INFO performs a binary, unary or ternary operation that can
    6687                 :             :    be vectorized.
    6688                 :             :    If VEC_STMT is also passed, vectorize STMT_INFO: create a vectorized
    6689                 :             :    stmt to replace it, put it in VEC_STMT, and insert it at GSI.
    6690                 :             :    Return true if STMT_INFO is vectorizable in this way.  */
    6691                 :             : 
    6692                 :             : static bool
    6693                 :     2526858 : vectorizable_operation (vec_info *vinfo,
    6694                 :             :                         stmt_vec_info stmt_info, gimple_stmt_iterator *gsi,
    6695                 :             :                         gimple **vec_stmt, slp_tree slp_node,
    6696                 :             :                         stmt_vector_for_cost *cost_vec)
    6697                 :             : {
    6698                 :     2526858 :   tree vec_dest;
    6699                 :     2526858 :   tree scalar_dest;
    6700                 :     2526858 :   tree op0, op1 = NULL_TREE, op2 = NULL_TREE;
    6701                 :     2526858 :   tree vectype;
    6702                 :     2526858 :   loop_vec_info loop_vinfo = dyn_cast <loop_vec_info> (vinfo);
    6703                 :     2526858 :   enum tree_code code, orig_code;
    6704                 :     2526858 :   machine_mode vec_mode;
    6705                 :     2526858 :   tree new_temp;
    6706                 :     2526858 :   int op_type;
    6707                 :     2526858 :   optab optab;
    6708                 :     2526858 :   bool target_support_p;
    6709                 :     2526858 :   enum vect_def_type dt[3]
    6710                 :             :     = {vect_unknown_def_type, vect_unknown_def_type, vect_unknown_def_type};
    6711                 :     2526858 :   int ndts = 3;
    6712                 :     2526858 :   poly_uint64 nunits_in;
    6713                 :     2526858 :   poly_uint64 nunits_out;
    6714                 :     2526858 :   tree vectype_out;
    6715                 :     2526858 :   int vec_num;
    6716                 :     2526858 :   int i;
    6717                 :     2526858 :   vec<tree> vec_oprnds0 = vNULL;
    6718                 :     2526858 :   vec<tree> vec_oprnds1 = vNULL;
    6719                 :     2526858 :   vec<tree> vec_oprnds2 = vNULL;
    6720                 :     2526858 :   tree vop0, vop1, vop2;
    6721                 :     2526858 :   bb_vec_info bb_vinfo = dyn_cast <bb_vec_info> (vinfo);
    6722                 :             : 
    6723                 :     2526858 :   if (!STMT_VINFO_RELEVANT_P (stmt_info) && !bb_vinfo)
    6724                 :             :     return false;
    6725                 :             : 
    6726                 :     2526858 :   if (STMT_VINFO_DEF_TYPE (stmt_info) != vect_internal_def
    6727                 :      200344 :       && ! vec_stmt)
    6728                 :             :     return false;
    6729                 :             : 
    6730                 :             :   /* Is STMT a vectorizable binary/unary operation?   */
    6731                 :     4228152 :   gassign *stmt = dyn_cast <gassign *> (stmt_info->stmt);
    6732                 :     2248586 :   if (!stmt)
    6733                 :             :     return false;
    6734                 :             : 
    6735                 :             :   /* Loads and stores are handled in vectorizable_{load,store}.  */
    6736                 :     2248586 :   if (STMT_VINFO_DATA_REF (stmt_info))
    6737                 :             :     return false;
    6738                 :             : 
    6739                 :      893300 :   orig_code = code = gimple_assign_rhs_code (stmt);
    6740                 :             : 
    6741                 :             :   /* Shifts are handled in vectorizable_shift.  */
    6742                 :      893300 :   if (code == LSHIFT_EXPR
    6743                 :             :       || code == RSHIFT_EXPR
    6744                 :             :       || code == LROTATE_EXPR
    6745                 :      893300 :       || code == RROTATE_EXPR)
    6746                 :             :    return false;
    6747                 :             : 
    6748                 :             :   /* Comparisons are handled in vectorizable_comparison.  */
    6749                 :      864295 :   if (TREE_CODE_CLASS (code) == tcc_comparison)
    6750                 :             :     return false;
    6751                 :             : 
    6752                 :             :   /* Conditions are handled in vectorizable_condition.  */
    6753                 :      685183 :   if (code == COND_EXPR)
    6754                 :             :     return false;
    6755                 :             : 
    6756                 :             :   /* For pointer addition and subtraction, we should use the normal
    6757                 :             :      plus and minus for the vector operation.  */
    6758                 :      665634 :   if (code == POINTER_PLUS_EXPR)
    6759                 :             :     code = PLUS_EXPR;
    6760                 :      651538 :   if (code == POINTER_DIFF_EXPR)
    6761                 :        1050 :     code = MINUS_EXPR;
    6762                 :             : 
    6763                 :             :   /* Support only unary or binary operations.  */
    6764                 :      665634 :   op_type = TREE_CODE_LENGTH (code);
    6765                 :      665634 :   if (op_type != unary_op && op_type != binary_op && op_type != ternary_op)
    6766                 :             :     {
    6767                 :           4 :       if (dump_enabled_p ())
    6768                 :           0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6769                 :             :                          "num. args = %d (not unary/binary/ternary op).\n",
    6770                 :             :                          op_type);
    6771                 :           4 :       return false;
    6772                 :             :     }
    6773                 :             : 
    6774                 :      665630 :   scalar_dest = gimple_assign_lhs (stmt);
    6775                 :      665630 :   vectype_out = SLP_TREE_VECTYPE (slp_node);
    6776                 :             : 
    6777                 :             :   /* Most operations cannot handle bit-precision types without extra
    6778                 :             :      truncations.  */
    6779                 :      665630 :   bool mask_op_p = VECTOR_BOOLEAN_TYPE_P (vectype_out);
    6780                 :      657292 :   if (!mask_op_p
    6781                 :      657292 :       && !type_has_mode_precision_p (TREE_TYPE (scalar_dest))
    6782                 :             :       /* Exception are bitwise binary operations.  */
    6783                 :             :       && code != BIT_IOR_EXPR
    6784                 :        1458 :       && code != BIT_XOR_EXPR
    6785                 :        1319 :       && code != BIT_AND_EXPR)
    6786                 :             :     {
    6787                 :        1071 :       if (dump_enabled_p ())
    6788                 :           0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6789                 :             :                          "bit-precision arithmetic not supported.\n");
    6790                 :        1071 :       return false;
    6791                 :             :     }
    6792                 :             : 
    6793                 :      664559 :   slp_tree slp_op0;
    6794                 :      664559 :   if (!vect_is_simple_use (vinfo, stmt_info, slp_node,
    6795                 :             :                            0, &op0, &slp_op0, &dt[0], &vectype))
    6796                 :             :     {
    6797                 :           0 :       if (dump_enabled_p ())
    6798                 :           0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6799                 :             :                          "use not simple.\n");
    6800                 :           0 :       return false;
    6801                 :             :     }
    6802                 :      664559 :   bool is_invariant = (dt[0] == vect_external_def
    6803                 :      664559 :                        || dt[0] == vect_constant_def);
    6804                 :             :   /* If op0 is an external or constant def, infer the vector type
    6805                 :             :      from the scalar type.  */
    6806                 :      664559 :   if (!vectype)
    6807                 :             :     {
    6808                 :             :       /* For boolean type we cannot determine vectype by
    6809                 :             :          invariant value (don't know whether it is a vector
    6810                 :             :          of booleans or vector of integers).  We use output
    6811                 :             :          vectype because operations on boolean don't change
    6812                 :             :          type.  */
    6813                 :       82178 :       if (VECT_SCALAR_BOOLEAN_TYPE_P (TREE_TYPE (op0)))
    6814                 :             :         {
    6815                 :        1092 :           if (!VECT_SCALAR_BOOLEAN_TYPE_P (TREE_TYPE (scalar_dest)))
    6816                 :             :             {
    6817                 :         291 :               if (dump_enabled_p ())
    6818                 :           0 :                 dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6819                 :             :                                  "not supported operation on bool value.\n");
    6820                 :         291 :               return false;
    6821                 :             :             }
    6822                 :         801 :           vectype = vectype_out;
    6823                 :             :         }
    6824                 :             :       else
    6825                 :       81086 :         vectype = get_vectype_for_scalar_type (vinfo, TREE_TYPE (op0),
    6826                 :             :                                                slp_node);
    6827                 :             :     }
    6828                 :      664268 :   if (vec_stmt)
    6829                 :      108375 :     gcc_assert (vectype);
    6830                 :      664268 :   if (!vectype)
    6831                 :             :     {
    6832                 :        1993 :       if (dump_enabled_p ())
    6833                 :           0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6834                 :             :                          "no vectype for scalar type %T\n",
    6835                 :           0 :                          TREE_TYPE (op0));
    6836                 :             : 
    6837                 :        1993 :       return false;
    6838                 :             :     }
    6839                 :             : 
    6840                 :      662275 :   nunits_out = TYPE_VECTOR_SUBPARTS (vectype_out);
    6841                 :      662275 :   nunits_in = TYPE_VECTOR_SUBPARTS (vectype);
    6842                 :      662275 :   if (maybe_ne (nunits_out, nunits_in)
    6843                 :      662275 :       || !tree_nop_conversion_p (TREE_TYPE (vectype_out), TREE_TYPE (vectype)))
    6844                 :       18387 :     return false;
    6845                 :             : 
    6846                 :      643888 :   tree vectype2 = NULL_TREE, vectype3 = NULL_TREE;
    6847                 :      643888 :   slp_tree slp_op1 = NULL, slp_op2 = NULL;
    6848                 :      643888 :   if (op_type == binary_op || op_type == ternary_op)
    6849                 :             :     {
    6850                 :      570705 :       if (!vect_is_simple_use (vinfo, stmt_info, slp_node,
    6851                 :             :                                1, &op1, &slp_op1, &dt[1], &vectype2))
    6852                 :             :         {
    6853                 :           0 :           if (dump_enabled_p ())
    6854                 :           0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6855                 :             :                              "use not simple.\n");
    6856                 :           0 :           return false;
    6857                 :             :         }
    6858                 :      570705 :       is_invariant &= (dt[1] == vect_external_def
    6859                 :      570705 :                        || dt[1] == vect_constant_def);
    6860                 :      570705 :       if (vectype2
    6861                 :      947851 :           && (maybe_ne (nunits_out, TYPE_VECTOR_SUBPARTS (vectype2))
    6862                 :      377146 :               || !tree_nop_conversion_p (TREE_TYPE (vectype_out),
    6863                 :      377146 :                                          TREE_TYPE (vectype2))))
    6864                 :         328 :         return false;
    6865                 :             :     }
    6866                 :      643560 :   if (op_type == ternary_op)
    6867                 :             :     {
    6868                 :           0 :       if (!vect_is_simple_use (vinfo, stmt_info, slp_node,
    6869                 :             :                                2, &op2, &slp_op2, &dt[2], &vectype3))
    6870                 :             :         {
    6871                 :           0 :           if (dump_enabled_p ())
    6872                 :           0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6873                 :             :                              "use not simple.\n");
    6874                 :           0 :           return false;
    6875                 :             :         }
    6876                 :           0 :       is_invariant &= (dt[2] == vect_external_def
    6877                 :           0 :                        || dt[2] == vect_constant_def);
    6878                 :           0 :       if (vectype3
    6879                 :           0 :           && (maybe_ne (nunits_out, TYPE_VECTOR_SUBPARTS (vectype3))
    6880                 :           0 :               || !tree_nop_conversion_p (TREE_TYPE (vectype_out),
    6881                 :           0 :                                          TREE_TYPE (vectype3))))
    6882                 :           0 :         return false;
    6883                 :             :     }
    6884                 :             : 
    6885                 :             :   /* Multiple types in SLP are handled by creating the appropriate number of
    6886                 :             :      vectorized stmts for each SLP node.  */
    6887                 :      643560 :   vec_num = SLP_TREE_NUMBER_OF_VEC_STMTS (slp_node);
    6888                 :             : 
    6889                 :             :   /* Reject attempts to combine mask types with nonmask types, e.g. if
    6890                 :             :      we have an AND between a (nonmask) boolean loaded from memory and
    6891                 :             :      a (mask) boolean result of a comparison.
    6892                 :             : 
    6893                 :             :      TODO: We could easily fix these cases up using pattern statements.  */
    6894                 :      643560 :   if (VECTOR_BOOLEAN_TYPE_P (vectype) != mask_op_p
    6895                 :     1016434 :       || (vectype2 && VECTOR_BOOLEAN_TYPE_P (vectype2) != mask_op_p)
    6896                 :     1287108 :       || (vectype3 && VECTOR_BOOLEAN_TYPE_P (vectype3) != mask_op_p))
    6897                 :             :     {
    6898                 :          12 :       if (dump_enabled_p ())
    6899                 :          12 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6900                 :             :                          "mixed mask and nonmask vector types\n");
    6901                 :          12 :       return false;
    6902                 :             :     }
    6903                 :             : 
    6904                 :             :   /* Supportable by target?  */
    6905                 :             : 
    6906                 :      643548 :   vec_mode = TYPE_MODE (vectype);
    6907                 :      643548 :   optab = optab_for_tree_code (code, vectype, optab_default);
    6908                 :      643548 :   if (!optab)
    6909                 :             :     {
    6910                 :       60850 :       if (dump_enabled_p ())
    6911                 :        6805 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6912                 :             :                          "no optab.\n");
    6913                 :       60850 :       return false;
    6914                 :             :     }
    6915                 :      582698 :   target_support_p = can_implement_p (optab, vec_mode);
    6916                 :             : 
    6917                 :      582698 :   bool using_emulated_vectors_p = vect_emulated_vector_p (vectype);
    6918                 :      582698 :   if (!target_support_p || using_emulated_vectors_p)
    6919                 :             :     {
    6920                 :       42581 :       if (dump_enabled_p ())
    6921                 :        1415 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6922                 :             :                          "op not supported by target.\n");
    6923                 :             :       /* When vec_mode is not a vector mode and we verified ops we
    6924                 :             :          do not have to lower like AND are natively supported let
    6925                 :             :          those through even when the mode isn't word_mode.  For
    6926                 :             :          ops we have to lower the lowering code assumes we are
    6927                 :             :          dealing with word_mode.  */
    6928                 :       85162 :       if (!INTEGRAL_TYPE_P (TREE_TYPE (vectype))
    6929                 :       42487 :           || !GET_MODE_SIZE (vec_mode).is_constant ()
    6930                 :       42487 :           || (((code == PLUS_EXPR || code == MINUS_EXPR || code == NEGATE_EXPR)
    6931                 :       29426 :                || !target_support_p)
    6932                 :       90165 :               && maybe_ne (GET_MODE_SIZE (vec_mode), UNITS_PER_WORD))
    6933                 :             :           /* Check only during analysis.  */
    6934                 :       62801 :           || (!vec_stmt && !vect_can_vectorize_without_simd_p (code)))
    6935                 :             :         {
    6936                 :       35220 :           if (dump_enabled_p ())
    6937                 :        1383 :             dump_printf (MSG_NOTE, "using word mode not possible.\n");
    6938                 :       35220 :           return false;
    6939                 :             :         }
    6940                 :        7361 :       if (dump_enabled_p ())
    6941                 :          32 :         dump_printf_loc (MSG_NOTE, vect_location,
    6942                 :             :                          "proceeding using word mode.\n");
    6943                 :             :       using_emulated_vectors_p = true;
    6944                 :             :     }
    6945                 :             : 
    6946                 :      547478 :   int reduc_idx = STMT_VINFO_REDUC_IDX (stmt_info);
    6947                 :      547478 :   vec_loop_masks *masks = (loop_vinfo ? &LOOP_VINFO_MASKS (loop_vinfo) : NULL);
    6948                 :      369692 :   vec_loop_lens *lens = (loop_vinfo ? &LOOP_VINFO_LENS (loop_vinfo) : NULL);
    6949                 :      547478 :   internal_fn cond_fn = get_conditional_internal_fn (code);
    6950                 :      547478 :   internal_fn cond_len_fn = get_conditional_len_internal_fn (code);
    6951                 :             : 
    6952                 :             :   /* If operating on inactive elements could generate spurious traps,
    6953                 :             :      we need to restrict the operation to active lanes.  Note that this
    6954                 :             :      specifically doesn't apply to unhoisted invariants, since they
    6955                 :             :      operate on the same value for every lane.
    6956                 :             : 
    6957                 :             :      Similarly, if this operation is part of a reduction, a fully-masked
    6958                 :             :      loop should only change the active lanes of the reduction chain,
    6959                 :             :      keeping the inactive lanes as-is.  */
    6960                 :      517868 :   bool mask_out_inactive = ((!is_invariant && gimple_could_trap_p (stmt))
    6961                 :     1006476 :                             || reduc_idx >= 0);
    6962                 :             : 
    6963                 :      547478 :   if (!vec_stmt) /* transformation not required.  */
    6964                 :             :     {
    6965                 :      439103 :       if (loop_vinfo
    6966                 :      269057 :           && LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo)
    6967                 :          31 :           && mask_out_inactive)
    6968                 :             :         {
    6969                 :          10 :           if (cond_len_fn != IFN_LAST
    6970                 :          10 :               && direct_internal_fn_supported_p (cond_len_fn, vectype,
    6971                 :             :                                                  OPTIMIZE_FOR_SPEED))
    6972                 :           0 :             vect_record_loop_len (loop_vinfo, lens, vec_num, vectype,
    6973                 :             :                                   1);
    6974                 :          10 :           else if (cond_fn != IFN_LAST
    6975                 :          10 :                    && direct_internal_fn_supported_p (cond_fn, vectype,
    6976                 :             :                                                       OPTIMIZE_FOR_SPEED))
    6977                 :          10 :             vect_record_loop_mask (loop_vinfo, masks, vec_num,
    6978                 :             :                                    vectype, NULL);
    6979                 :             :           else
    6980                 :             :             {
    6981                 :           0 :               if (dump_enabled_p ())
    6982                 :           0 :                 dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6983                 :             :                                  "can't use a fully-masked loop because no"
    6984                 :             :                                  " conditional operation is available.\n");
    6985                 :           0 :               LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo) = false;
    6986                 :             :             }
    6987                 :             :         }
    6988                 :             : 
    6989                 :             :       /* Put types on constant and invariant SLP children.  */
    6990                 :      439103 :       if (!vect_maybe_update_slp_op_vectype (slp_op0, vectype)
    6991                 :      438936 :           || !vect_maybe_update_slp_op_vectype (slp_op1, vectype)
    6992                 :      878020 :           || !vect_maybe_update_slp_op_vectype (slp_op2, vectype))
    6993                 :             :         {
    6994                 :         186 :           if (dump_enabled_p ())
    6995                 :           4 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6996                 :             :                              "incompatible vector types for invariants\n");
    6997                 :         186 :           return false;
    6998                 :             :         }
    6999                 :             : 
    7000                 :      438917 :       STMT_VINFO_TYPE (stmt_info) = op_vec_info_type;
    7001                 :      438917 :       DUMP_VECT_SCOPE ("vectorizable_operation");
    7002                 :      438917 :       vect_model_simple_cost (vinfo, 1, dt, ndts, slp_node, cost_vec);
    7003                 :      438917 :       if (using_emulated_vectors_p)
    7004                 :             :         {
    7005                 :             :           /* The above vect_model_simple_cost call handles constants
    7006                 :             :              in the prologue and (mis-)costs one of the stmts as
    7007                 :             :              vector stmt.  See below for the actual lowering that will
    7008                 :             :              be applied.  */
    7009                 :        7359 :           unsigned n = SLP_TREE_NUMBER_OF_VEC_STMTS (slp_node);
    7010                 :        7359 :           switch (code)
    7011                 :             :             {
    7012                 :        3255 :             case PLUS_EXPR:
    7013                 :        3255 :               n *= 5;
    7014                 :        3255 :               break;
    7015                 :        3356 :             case MINUS_EXPR:
    7016                 :        3356 :               n *= 6;
    7017                 :        3356 :               break;
    7018                 :           8 :             case NEGATE_EXPR:
    7019                 :           8 :               n *= 4;
    7020                 :           8 :               break;
    7021                 :             :             default:
    7022                 :             :               /* Bit operations do not have extra cost and are accounted
    7023                 :             :                  as vector stmt by vect_model_simple_cost.  */
    7024                 :             :               n = 0;
    7025                 :             :               break;
    7026                 :             :             }
    7027                 :        6619 :           if (n != 0)
    7028                 :             :             {
    7029                 :             :               /* We also need to materialize two large constants.  */
    7030                 :        6619 :               record_stmt_cost (cost_vec, 2, scalar_stmt, stmt_info,
    7031                 :             :                                 0, vect_prologue);
    7032                 :        6619 :               record_stmt_cost (cost_vec, n, scalar_stmt, stmt_info,
    7033                 :             :                                 0, vect_body);
    7034                 :             :             }
    7035                 :             :         }
    7036                 :      438917 :       return true;
    7037                 :             :     }
    7038                 :             : 
    7039                 :             :   /* Transform.  */
    7040                 :             : 
    7041                 :      108375 :   if (dump_enabled_p ())
    7042                 :       15563 :     dump_printf_loc (MSG_NOTE, vect_location,
    7043                 :             :                      "transform binary/unary operation.\n");
    7044                 :             : 
    7045                 :      108375 :   bool masked_loop_p = loop_vinfo && LOOP_VINFO_FULLY_MASKED_P (loop_vinfo);
    7046                 :      100635 :   bool len_loop_p = loop_vinfo && LOOP_VINFO_FULLY_WITH_LENGTH_P (loop_vinfo);
    7047                 :             : 
    7048                 :             :   /* POINTER_DIFF_EXPR has pointer arguments which are vectorized as
    7049                 :             :      vectors with unsigned elements, but the result is signed.  So, we
    7050                 :             :      need to compute the MINUS_EXPR into vectype temporary and
    7051                 :             :      VIEW_CONVERT_EXPR it into the final vectype_out result.  */
    7052                 :      108375 :   tree vec_cvt_dest = NULL_TREE;
    7053                 :      108375 :   if (orig_code == POINTER_DIFF_EXPR)
    7054                 :             :     {
    7055                 :         128 :       vec_dest = vect_create_destination_var (scalar_dest, vectype);
    7056                 :         128 :       vec_cvt_dest = vect_create_destination_var (scalar_dest, vectype_out);
    7057                 :             :     }
    7058                 :             :   /* Handle def.  */
    7059                 :             :   else
    7060                 :      108247 :     vec_dest = vect_create_destination_var (scalar_dest, vectype_out);
    7061                 :             : 
    7062                 :      108375 :   vect_get_vec_defs (vinfo, stmt_info, slp_node, 1,
    7063                 :             :                      op0, &vec_oprnds0, op1, &vec_oprnds1, op2, &vec_oprnds2);
    7064                 :             :   /* Arguments are ready.  Create the new vector stmt.  */
    7065                 :      235120 :   FOR_EACH_VEC_ELT (vec_oprnds0, i, vop0)
    7066                 :             :     {
    7067                 :      126745 :       gimple *new_stmt = NULL;
    7068                 :      253490 :       vop1 = ((op_type == binary_op || op_type == ternary_op)
    7069                 :      126745 :               ? vec_oprnds1[i] : NULL_TREE);
    7070                 :      126745 :       vop2 = ((op_type == ternary_op) ? vec_oprnds2[i] : NULL_TREE);
    7071                 :      126745 :       if (using_emulated_vectors_p)
    7072                 :             :         {
    7073                 :             :           /* Lower the operation.  This follows vector lowering.  */
    7074                 :           2 :           tree word_type = build_nonstandard_integer_type
    7075                 :           2 :                              (GET_MODE_BITSIZE (vec_mode).to_constant (), 1);
    7076                 :           2 :           tree wvop0 = make_ssa_name (word_type);
    7077                 :           2 :           new_stmt = gimple_build_assign (wvop0, VIEW_CONVERT_EXPR,
    7078                 :             :                                           build1 (VIEW_CONVERT_EXPR,
    7079                 :             :                                                   word_type, vop0));
    7080                 :           2 :           vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    7081                 :           2 :           tree wvop1 = NULL_TREE;
    7082                 :           2 :           if (vop1)
    7083                 :             :             {
    7084                 :           2 :               wvop1 = make_ssa_name (word_type);
    7085                 :           2 :               new_stmt = gimple_build_assign (wvop1, VIEW_CONVERT_EXPR,
    7086                 :             :                                               build1 (VIEW_CONVERT_EXPR,
    7087                 :             :                                                       word_type, vop1));
    7088                 :           2 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    7089                 :             :             }
    7090                 :             : 
    7091                 :           2 :           tree result_low;
    7092                 :           2 :           if (code == PLUS_EXPR || code == MINUS_EXPR || code == NEGATE_EXPR)
    7093                 :             :             {
    7094                 :           1 :               unsigned int width = vector_element_bits (vectype);
    7095                 :           1 :               tree inner_type = TREE_TYPE (vectype);
    7096                 :           1 :               HOST_WIDE_INT max = GET_MODE_MASK (TYPE_MODE (inner_type));
    7097                 :           1 :               tree low_bits
    7098                 :           1 :                 = build_replicated_int_cst (word_type, width, max >> 1);
    7099                 :           1 :               tree high_bits
    7100                 :           2 :                 = build_replicated_int_cst (word_type,
    7101                 :           1 :                                             width, max & ~(max >> 1));
    7102                 :           1 :               tree signs;
    7103                 :           1 :               if (code == PLUS_EXPR || code == MINUS_EXPR)
    7104                 :             :                 {
    7105                 :           1 :                   signs = make_ssa_name (word_type);
    7106                 :           1 :                   new_stmt = gimple_build_assign (signs,
    7107                 :             :                                                   BIT_XOR_EXPR, wvop0, wvop1);
    7108                 :           1 :                   vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    7109                 :           1 :                   tree b_low = make_ssa_name (word_type);
    7110                 :           1 :                   new_stmt = gimple_build_assign (b_low, BIT_AND_EXPR,
    7111                 :             :                                                   wvop1, low_bits);
    7112                 :           1 :                   vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    7113                 :           1 :                   tree a_low = make_ssa_name (word_type);
    7114                 :           1 :                   if (code == PLUS_EXPR)
    7115                 :           1 :                     new_stmt = gimple_build_assign (a_low, BIT_AND_EXPR,
    7116                 :             :                                                     wvop0, low_bits);
    7117                 :             :                   else
    7118                 :           0 :                     new_stmt = gimple_build_assign (a_low, BIT_IOR_EXPR,
    7119                 :             :                                                     wvop0, high_bits);
    7120                 :           1 :                   vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    7121                 :           1 :                   if (code == MINUS_EXPR)
    7122                 :             :                     {
    7123                 :           0 :                       new_stmt = gimple_build_assign (NULL_TREE,
    7124                 :             :                                                       BIT_NOT_EXPR, signs);
    7125                 :           0 :                       signs = make_ssa_name (word_type);
    7126                 :           0 :                       gimple_assign_set_lhs (new_stmt, signs);
    7127                 :           0 :                       vect_finish_stmt_generation (vinfo, stmt_info,
    7128                 :             :                                                    new_stmt, gsi);
    7129                 :             :                     }
    7130                 :           1 :                   new_stmt = gimple_build_assign (NULL_TREE, BIT_AND_EXPR,
    7131                 :             :                                                   signs, high_bits);
    7132                 :           1 :                   signs = make_ssa_name (word_type);
    7133                 :           1 :                   gimple_assign_set_lhs (new_stmt, signs);
    7134                 :           1 :                   vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    7135                 :           1 :                   result_low = make_ssa_name (word_type);
    7136                 :           1 :                   new_stmt = gimple_build_assign (result_low, code,
    7137                 :             :                                                   a_low, b_low);
    7138                 :           1 :                   vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    7139                 :             :                 }
    7140                 :             :               else /* if (code == NEGATE_EXPR) */
    7141                 :             :                 {
    7142                 :           0 :                   tree a_low = make_ssa_name (word_type);
    7143                 :           0 :                   new_stmt = gimple_build_assign (a_low, BIT_AND_EXPR,
    7144                 :             :                                                   wvop0, low_bits);
    7145                 :           0 :                   vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    7146                 :           0 :                   signs = make_ssa_name (word_type);
    7147                 :           0 :                   new_stmt = gimple_build_assign (signs, BIT_NOT_EXPR, wvop0);
    7148                 :           0 :                   vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    7149                 :           0 :                   new_stmt = gimple_build_assign (NULL_TREE, BIT_AND_EXPR,
    7150                 :             :                                                   signs, high_bits);
    7151                 :           0 :                   signs = make_ssa_name (word_type);
    7152                 :           0 :                   gimple_assign_set_lhs (new_stmt, signs);
    7153                 :           0 :                   vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    7154                 :           0 :                   result_low = make_ssa_name (word_type);
    7155                 :           0 :                   new_stmt = gimple_build_assign (result_low,
    7156                 :             :                                                   MINUS_EXPR, high_bits, a_low);
    7157                 :           0 :                   vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    7158                 :             :                 }
    7159                 :           1 :               new_stmt = gimple_build_assign (NULL_TREE, BIT_XOR_EXPR,
    7160                 :             :                                               result_low, signs);
    7161                 :           1 :               result_low = make_ssa_name (word_type);
    7162                 :           1 :               gimple_assign_set_lhs (new_stmt, result_low);
    7163                 :           1 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    7164                 :             :             }
    7165                 :             :           else
    7166                 :             :             {
    7167                 :           1 :               new_stmt = gimple_build_assign (NULL_TREE, code, wvop0, wvop1);
    7168                 :           1 :               result_low = make_ssa_name (word_type);
    7169                 :           1 :               gimple_assign_set_lhs (new_stmt, result_low);
    7170                 :           1 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    7171                 :             : 
    7172                 :             :             }
    7173                 :           2 :           new_stmt = gimple_build_assign (NULL_TREE, VIEW_CONVERT_EXPR,
    7174                 :             :                                           build1 (VIEW_CONVERT_EXPR,
    7175                 :             :                                                   vectype, result_low));
    7176                 :           2 :           new_temp = make_ssa_name (vectype);
    7177                 :           2 :           gimple_assign_set_lhs (new_stmt, new_temp);
    7178                 :           2 :           vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    7179                 :             :         }
    7180                 :      126743 :       else if ((masked_loop_p || len_loop_p) && mask_out_inactive)
    7181                 :             :         {
    7182                 :          15 :           tree mask;
    7183                 :          15 :           if (masked_loop_p)
    7184                 :          15 :             mask = vect_get_loop_mask (loop_vinfo, gsi, masks,
    7185                 :             :                                        vec_num, vectype, i);
    7186                 :             :           else
    7187                 :             :             /* Dummy mask.  */
    7188                 :           0 :             mask = build_minus_one_cst (truth_type_for (vectype));
    7189                 :          15 :           auto_vec<tree> vops (6);
    7190                 :          15 :           vops.quick_push (mask);
    7191                 :          15 :           vops.quick_push (vop0);
    7192                 :          15 :           if (vop1)
    7193                 :          15 :             vops.quick_push (vop1);
    7194                 :          15 :           if (vop2)
    7195                 :           0 :             vops.quick_push (vop2);
    7196                 :          15 :           if (reduc_idx >= 0)
    7197                 :             :             {
    7198                 :             :               /* Perform the operation on active elements only and take
    7199                 :             :                  inactive elements from the reduction chain input.  */
    7200                 :           8 :               gcc_assert (!vop2);
    7201                 :           8 :               vops.quick_push (reduc_idx == 1 ? vop1 : vop0);
    7202                 :             :             }
    7203                 :             :           else
    7204                 :             :             {
    7205                 :           7 :               auto else_value = targetm.preferred_else_value
    7206                 :           7 :                 (cond_fn, vectype, vops.length () - 1, &vops[1]);
    7207                 :           7 :               vops.quick_push (else_value);
    7208                 :             :             }
    7209                 :          15 :           if (len_loop_p)
    7210                 :             :             {
    7211                 :           0 :               tree len = vect_get_loop_len (loop_vinfo, gsi, lens,
    7212                 :           0 :                                             vec_num, vectype, i, 1);
    7213                 :           0 :               signed char biasval
    7214                 :           0 :                 = LOOP_VINFO_PARTIAL_LOAD_STORE_BIAS (loop_vinfo);
    7215                 :           0 :               tree bias = build_int_cst (intQI_type_node, biasval);
    7216                 :           0 :               vops.quick_push (len);
    7217                 :           0 :               vops.quick_push (bias);
    7218                 :             :             }
    7219                 :          15 :           gcall *call
    7220                 :          15 :             = gimple_build_call_internal_vec (masked_loop_p ? cond_fn
    7221                 :             :                                                             : cond_len_fn,
    7222                 :             :                                               vops);
    7223                 :          15 :           new_temp = make_ssa_name (vec_dest, call);
    7224                 :          15 :           gimple_call_set_lhs (call, new_temp);
    7225                 :          15 :           gimple_call_set_nothrow (call, true);
    7226                 :          15 :           vect_finish_stmt_generation (vinfo, stmt_info, call, gsi);
    7227                 :          15 :           new_stmt = call;
    7228                 :          15 :         }
    7229                 :             :       else
    7230                 :             :         {
    7231                 :      126728 :           tree mask = NULL_TREE;
    7232                 :             :           /* When combining two masks check if either of them is elsewhere
    7233                 :             :              combined with a loop mask, if that's the case we can mark that the
    7234                 :             :              new combined mask doesn't need to be combined with a loop mask.  */
    7235                 :      126728 :           if (masked_loop_p
    7236                 :      126728 :               && code == BIT_AND_EXPR
    7237                 :      126728 :               && VECTOR_BOOLEAN_TYPE_P (vectype))
    7238                 :             :             {
    7239                 :           0 :               if (loop_vinfo->scalar_cond_masked_set.contains ({ op0, 1 }))
    7240                 :             :                 {
    7241                 :           0 :                   mask = vect_get_loop_mask (loop_vinfo, gsi, masks,
    7242                 :             :                                              vec_num, vectype, i);
    7243                 :             : 
    7244                 :           0 :                   vop0 = prepare_vec_mask (loop_vinfo, TREE_TYPE (mask), mask,
    7245                 :             :                                            vop0, gsi);
    7246                 :             :                 }
    7247                 :             : 
    7248                 :           0 :               if (loop_vinfo->scalar_cond_masked_set.contains ({ op1, 1 }))
    7249                 :             :                 {
    7250                 :           0 :                   mask = vect_get_loop_mask (loop_vinfo, gsi, masks,
    7251                 :             :                                              vec_num, vectype, i);
    7252                 :             : 
    7253                 :           0 :                   vop1 = prepare_vec_mask (loop_vinfo, TREE_TYPE (mask), mask,
    7254                 :             :                                            vop1, gsi);
    7255                 :             :                 }
    7256                 :             :             }
    7257                 :             : 
    7258                 :      126728 :           new_stmt = gimple_build_assign (vec_dest, code, vop0, vop1, vop2);
    7259                 :      126728 :           new_temp = make_ssa_name (vec_dest, new_stmt);
    7260                 :      126728 :           gimple_assign_set_lhs (new_stmt, new_temp);
    7261                 :      126728 :           vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    7262                 :      126728 :           if (using_emulated_vectors_p)
    7263                 :             :             suppress_warning (new_stmt, OPT_Wvector_operation_performance);
    7264                 :             : 
    7265                 :             :           /* Enter the combined value into the vector cond hash so we don't
    7266                 :             :              AND it with a loop mask again.  */
    7267                 :      126728 :           if (mask)
    7268                 :           0 :             loop_vinfo->vec_cond_masked_set.add ({ new_temp, mask });
    7269                 :             :         }
    7270                 :             : 
    7271                 :      126745 :       if (vec_cvt_dest)
    7272                 :             :         {
    7273                 :         143 :           new_temp = build1 (VIEW_CONVERT_EXPR, vectype_out, new_temp);
    7274                 :         143 :           new_stmt = gimple_build_assign (vec_cvt_dest, VIEW_CONVERT_EXPR,
    7275                 :             :                                           new_temp);
    7276                 :         143 :           new_temp = make_ssa_name (vec_cvt_dest, new_stmt);
    7277                 :         143 :           gimple_assign_set_lhs (new_stmt, new_temp);
    7278                 :         143 :           vect_finish_stmt_generation (vinfo, stmt_info,
    7279                 :             :                                        new_stmt, gsi);
    7280                 :             :         }
    7281                 :             : 
    7282                 :      126745 :       slp_node->push_vec_def (new_stmt);
    7283                 :             :     }
    7284                 :             : 
    7285                 :      108375 :   vec_oprnds0.release ();
    7286                 :      108375 :   vec_oprnds1.release ();
    7287                 :      108375 :   vec_oprnds2.release ();
    7288                 :             : 
    7289                 :      108375 :   return true;
    7290                 :             : }
    7291                 :             : 
    7292                 :             : /* A helper function to ensure data reference DR_INFO's base alignment.  */
    7293                 :             : 
    7294                 :             : static void
    7295                 :     1968226 : ensure_base_align (dr_vec_info *dr_info)
    7296                 :             : {
    7297                 :             :   /* Alignment is only analyzed for the first element of a DR group,
    7298                 :             :      use that to look at base alignment we need to enforce.  */
    7299                 :     1968226 :   if (STMT_VINFO_GROUPED_ACCESS (dr_info->stmt))
    7300                 :     1504115 :     dr_info = STMT_VINFO_DR_INFO (DR_GROUP_FIRST_ELEMENT (dr_info->stmt));
    7301                 :             : 
    7302                 :     1968226 :   gcc_assert (dr_info->misalignment != DR_MISALIGNMENT_UNINITIALIZED);
    7303                 :             : 
    7304                 :     1968226 :   if (dr_info->base_misaligned)
    7305                 :             :     {
    7306                 :      171046 :       tree base_decl = dr_info->base_decl;
    7307                 :             : 
    7308                 :             :       // We should only be able to increase the alignment of a base object if
    7309                 :             :       // we know what its new alignment should be at compile time.
    7310                 :      171046 :       unsigned HOST_WIDE_INT align_base_to =
    7311                 :      171046 :         DR_TARGET_ALIGNMENT (dr_info).to_constant () * BITS_PER_UNIT;
    7312                 :             : 
    7313                 :      171046 :       if (decl_in_symtab_p (base_decl))
    7314                 :        5387 :         symtab_node::get (base_decl)->increase_alignment (align_base_to);
    7315                 :      165659 :       else if (DECL_ALIGN (base_decl) < align_base_to)
    7316                 :             :         {
    7317                 :      132123 :           SET_DECL_ALIGN (base_decl, align_base_to);
    7318                 :      132123 :           DECL_USER_ALIGN (base_decl) = 1;
    7319                 :             :         }
    7320                 :      171046 :       dr_info->base_misaligned = false;
    7321                 :             :     }
    7322                 :     1968226 : }
    7323                 :             : 
    7324                 :             : 
    7325                 :             : /* Function get_group_alias_ptr_type.
    7326                 :             : 
    7327                 :             :    Return the alias type for the group starting at FIRST_STMT_INFO.  */
    7328                 :             : 
    7329                 :             : static tree
    7330                 :     1663464 : get_group_alias_ptr_type (stmt_vec_info first_stmt_info)
    7331                 :             : {
    7332                 :     1663464 :   struct data_reference *first_dr, *next_dr;
    7333                 :             : 
    7334                 :     1663464 :   first_dr = STMT_VINFO_DATA_REF (first_stmt_info);
    7335                 :     1663464 :   stmt_vec_info next_stmt_info = DR_GROUP_NEXT_ELEMENT (first_stmt_info);
    7336                 :     4011120 :   while (next_stmt_info)
    7337                 :             :     {
    7338                 :     2506940 :       next_dr = STMT_VINFO_DATA_REF (next_stmt_info);
    7339                 :     5013880 :       if (get_alias_set (DR_REF (first_dr))
    7340                 :     2506940 :           != get_alias_set (DR_REF (next_dr)))
    7341                 :             :         {
    7342                 :      159284 :           if (dump_enabled_p ())
    7343                 :          37 :             dump_printf_loc (MSG_NOTE, vect_location,
    7344                 :             :                              "conflicting alias set types.\n");
    7345                 :      159284 :           return ptr_type_node;
    7346                 :             :         }
    7347                 :     2347656 :       next_stmt_info = DR_GROUP_NEXT_ELEMENT (next_stmt_info);
    7348                 :             :     }
    7349                 :     1504180 :   return reference_alias_ptr_type (DR_REF (first_dr));
    7350                 :             : }
    7351                 :             : 
    7352                 :             : 
    7353                 :             : /* Function scan_operand_equal_p.
    7354                 :             : 
    7355                 :             :    Helper function for check_scan_store.  Compare two references
    7356                 :             :    with .GOMP_SIMD_LANE bases.  */
    7357                 :             : 
    7358                 :             : static bool
    7359                 :        1284 : scan_operand_equal_p (tree ref1, tree ref2)
    7360                 :             : {
    7361                 :        1284 :   tree ref[2] = { ref1, ref2 };
    7362                 :        1284 :   poly_int64 bitsize[2], bitpos[2];
    7363                 :             :   tree offset[2], base[2];
    7364                 :        3852 :   for (int i = 0; i < 2; ++i)
    7365                 :             :     {
    7366                 :        2568 :       machine_mode mode;
    7367                 :        2568 :       int unsignedp, reversep, volatilep = 0;
    7368                 :        2568 :       base[i] = get_inner_reference (ref[i], &bitsize[i], &bitpos[i],
    7369                 :             :                                      &offset[i], &mode, &unsignedp,
    7370                 :             :                                      &reversep, &volatilep);
    7371                 :        2568 :       if (reversep || volatilep || maybe_ne (bitpos[i], 0))
    7372                 :           0 :         return false;
    7373                 :        2568 :       if (TREE_CODE (base[i]) == MEM_REF
    7374                 :          42 :           && offset[i] == NULL_TREE
    7375                 :        2610 :           && TREE_CODE (TREE_OPERAND (base[i], 0)) == SSA_NAME)
    7376                 :             :         {
    7377                 :          42 :           gimple *def_stmt = SSA_NAME_DEF_STMT (TREE_OPERAND (base[i], 0));
    7378                 :          42 :           if (is_gimple_assign (def_stmt)
    7379                 :          42 :               && gimple_assign_rhs_code (def_stmt) == POINTER_PLUS_EXPR
    7380                 :          42 :               && TREE_CODE (gimple_assign_rhs1 (def_stmt)) == ADDR_EXPR
    7381                 :          84 :               && TREE_CODE (gimple_assign_rhs2 (def_stmt)) == SSA_NAME)
    7382                 :             :             {
    7383                 :          42 :               if (maybe_ne (mem_ref_offset (base[i]), 0))
    7384                 :             :                 return false;
    7385                 :          42 :               base[i] = TREE_OPERAND (gimple_assign_rhs1 (def_stmt), 0);
    7386                 :          42 :               offset[i] = gimple_assign_rhs2 (def_stmt);
    7387                 :             :             }
    7388                 :             :         }
    7389                 :             :     }
    7390                 :             : 
    7391                 :        1284 :   if (!operand_equal_p (base[0], base[1], 0))
    7392                 :             :     return false;
    7393                 :         934 :   if (maybe_ne (bitsize[0], bitsize[1]))
    7394                 :             :     return false;
    7395                 :         934 :   if (offset[0] != offset[1])
    7396                 :             :     {
    7397                 :         916 :       if (!offset[0] || !offset[1])
    7398                 :             :         return false;
    7399                 :         916 :       if (!operand_equal_p (offset[0], offset[1], 0))
    7400                 :             :         {
    7401                 :             :           tree step[2];
    7402                 :           0 :           for (int i = 0; i < 2; ++i)
    7403                 :             :             {
    7404                 :           0 :               step[i] = integer_one_node;
    7405                 :           0 :               if (TREE_CODE (offset[i]) == SSA_NAME)
    7406                 :             :                 {
    7407                 :           0 :                   gimple *def_stmt = SSA_NAME_DEF_STMT (offset[i]);
    7408                 :           0 :                   if (is_gimple_assign (def_stmt)
    7409                 :           0 :                       && gimple_assign_rhs_code (def_stmt) == MULT_EXPR
    7410                 :           0 :                       && (TREE_CODE (gimple_assign_rhs2 (def_stmt))
    7411                 :             :                           == INTEGER_CST))
    7412                 :             :                     {
    7413                 :           0 :                       step[i] = gimple_assign_rhs2 (def_stmt);
    7414                 :           0 :                       offset[i] = gimple_assign_rhs1 (def_stmt);
    7415                 :             :                     }
    7416                 :             :                 }
    7417                 :           0 :               else if (TREE_CODE (offset[i]) == MULT_EXPR)
    7418                 :             :                 {
    7419                 :           0 :                   step[i] = TREE_OPERAND (offset[i], 1);
    7420                 :           0 :                   offset[i] = TREE_OPERAND (offset[i], 0);
    7421                 :             :                 }
    7422                 :           0 :               tree rhs1 = NULL_TREE;
    7423                 :           0 :               if (TREE_CODE (offset[i]) == SSA_NAME)
    7424                 :             :                 {
    7425                 :           0 :                   gimple *def_stmt = SSA_NAME_DEF_STMT (offset[i]);
    7426                 :           0 :                   if (gimple_assign_cast_p (def_stmt))
    7427                 :           0 :                     rhs1 = gimple_assign_rhs1 (def_stmt);
    7428                 :             :                 }
    7429                 :           0 :               else if (CONVERT_EXPR_P (offset[i]))
    7430                 :           0 :                 rhs1 = TREE_OPERAND (offset[i], 0);
    7431                 :           0 :               if (rhs1
    7432                 :           0 :                   && INTEGRAL_TYPE_P (TREE_TYPE (rhs1))
    7433                 :           0 :                   && INTEGRAL_TYPE_P (TREE_TYPE (offset[i]))
    7434                 :           0 :                   && (TYPE_PRECISION (TREE_TYPE (offset[i]))
    7435                 :           0 :                       >= TYPE_PRECISION (TREE_TYPE (rhs1))))
    7436                 :           0 :                 offset[i] = rhs1;
    7437                 :             :             }
    7438                 :           0 :           if (!operand_equal_p (offset[0], offset[1], 0)
    7439                 :           0 :               || !operand_equal_p (step[0], step[1], 0))
    7440                 :           0 :             return false;
    7441                 :             :         }
    7442                 :             :     }
    7443                 :             :   return true;
    7444                 :             : }
    7445                 :             : 
    7446                 :             : 
    7447                 :             : enum scan_store_kind {
    7448                 :             :   /* Normal permutation.  */
    7449                 :             :   scan_store_kind_perm,
    7450                 :             : 
    7451                 :             :   /* Whole vector left shift permutation with zero init.  */
    7452                 :             :   scan_store_kind_lshift_zero,
    7453                 :             : 
    7454                 :             :   /* Whole vector left shift permutation and VEC_COND_EXPR.  */
    7455                 :             :   scan_store_kind_lshift_cond
    7456                 :             : };
    7457                 :             : 
    7458                 :             : /* Function check_scan_store.
    7459                 :             : 
    7460                 :             :    Verify if we can perform the needed permutations or whole vector shifts.
    7461                 :             :    Return -1 on failure, otherwise exact log2 of vectype's nunits.
    7462                 :             :    USE_WHOLE_VECTOR is a vector of enum scan_store_kind which operation
    7463                 :             :    to do at each step.  */
    7464                 :             : 
    7465                 :             : static int
    7466                 :        1024 : scan_store_can_perm_p (tree vectype, tree init,
    7467                 :             :                        vec<enum scan_store_kind> *use_whole_vector = NULL)
    7468                 :             : {
    7469                 :        1024 :   enum machine_mode vec_mode = TYPE_MODE (vectype);
    7470                 :        1024 :   unsigned HOST_WIDE_INT nunits;
    7471                 :        1024 :   if (!TYPE_VECTOR_SUBPARTS (vectype).is_constant (&nunits))
    7472                 :             :     return -1;
    7473                 :        1024 :   int units_log2 = exact_log2 (nunits);
    7474                 :        1024 :   if (units_log2 <= 0)
    7475                 :             :     return -1;
    7476                 :             : 
    7477                 :             :   int i;
    7478                 :             :   enum scan_store_kind whole_vector_shift_kind = scan_store_kind_perm;
    7479                 :        4784 :   for (i = 0; i <= units_log2; ++i)
    7480                 :             :     {
    7481                 :        3760 :       unsigned HOST_WIDE_INT j, k;
    7482                 :        3760 :       enum scan_store_kind kind = scan_store_kind_perm;
    7483                 :        3760 :       vec_perm_builder sel (nunits, nunits, 1);
    7484                 :        3760 :       sel.quick_grow (nunits);
    7485                 :        3760 :       if (i == units_log2)
    7486                 :             :         {
    7487                 :        9728 :           for (j = 0; j < nunits; ++j)
    7488                 :        8704 :             sel[j] = nunits - 1;
    7489                 :             :         }
    7490                 :             :       else
    7491                 :             :         {
    7492                 :       10416 :           for (j = 0; j < (HOST_WIDE_INT_1U << i); ++j)
    7493                 :        7680 :             sel[j] = j;
    7494                 :       26416 :           for (k = 0; j < nunits; ++j, ++k)
    7495                 :       23680 :             sel[j] = nunits + k;
    7496                 :             :         }
    7497                 :        6496 :       vec_perm_indices indices (sel, i == units_log2 ? 1 : 2, nunits);
    7498                 :        3760 :       if (!can_vec_perm_const_p (vec_mode, vec_mode, indices))
    7499                 :             :         {
    7500                 :           0 :           if (i == units_log2)
    7501                 :             :             return -1;
    7502                 :             : 
    7503                 :           0 :           if (whole_vector_shift_kind == scan_store_kind_perm)
    7504                 :             :             {
    7505                 :           0 :               if (!can_implement_p (vec_shl_optab, vec_mode))
    7506                 :             :                 return -1;
    7507                 :           0 :               whole_vector_shift_kind = scan_store_kind_lshift_zero;
    7508                 :             :               /* Whole vector shifts shift in zeros, so if init is all zero
    7509                 :             :                  constant, there is no need to do anything further.  */
    7510                 :           0 :               if ((TREE_CODE (init) != INTEGER_CST
    7511                 :           0 :                    && TREE_CODE (init) != REAL_CST)
    7512                 :           0 :                   || !initializer_zerop (init))
    7513                 :             :                 {
    7514                 :           0 :                   tree masktype = truth_type_for (vectype);
    7515                 :           0 :                   if (!expand_vec_cond_expr_p (vectype, masktype))
    7516                 :             :                     return -1;
    7517                 :             :                   whole_vector_shift_kind = scan_store_kind_lshift_cond;
    7518                 :             :                 }
    7519                 :             :             }
    7520                 :           0 :           kind = whole_vector_shift_kind;
    7521                 :             :         }
    7522                 :        3760 :       if (use_whole_vector)
    7523                 :             :         {
    7524                 :        1880 :           if (kind != scan_store_kind_perm && use_whole_vector->is_empty ())
    7525                 :           0 :             use_whole_vector->safe_grow_cleared (i, true);
    7526                 :        5640 :           if (kind != scan_store_kind_perm || !use_whole_vector->is_empty ())
    7527                 :           0 :             use_whole_vector->safe_push (kind);
    7528                 :             :         }
    7529                 :        3760 :     }
    7530                 :             : 
    7531                 :             :   return units_log2;
    7532                 :             : }
    7533                 :             : 
    7534                 :             : 
    7535                 :             : /* Function check_scan_store.
    7536                 :             : 
    7537                 :             :    Check magic stores for #pragma omp scan {in,ex}clusive reductions.  */
    7538                 :             : 
    7539                 :             : static bool
    7540                 :        1076 : check_scan_store (vec_info *vinfo, stmt_vec_info stmt_info, tree vectype,
    7541                 :             :                   enum vect_def_type rhs_dt, slp_tree slp_node, tree mask,
    7542                 :             :                   vect_memory_access_type memory_access_type)
    7543                 :             : {
    7544                 :        1076 :   loop_vec_info loop_vinfo = dyn_cast <loop_vec_info> (vinfo);
    7545                 :        1076 :   dr_vec_info *dr_info = STMT_VINFO_DR_INFO (stmt_info);
    7546                 :        1076 :   tree ref_type;
    7547                 :             : 
    7548                 :        1076 :   gcc_assert (STMT_VINFO_SIMD_LANE_ACCESS_P (stmt_info) > 1);
    7549                 :        1076 :   if ((slp_node && SLP_TREE_LANES (slp_node) > 1)
    7550                 :        1076 :       || mask
    7551                 :        1076 :       || memory_access_type != VMAT_CONTIGUOUS
    7552                 :        1076 :       || TREE_CODE (DR_BASE_ADDRESS (dr_info->dr)) != ADDR_EXPR
    7553                 :        1076 :       || !VAR_P (TREE_OPERAND (DR_BASE_ADDRESS (dr_info->dr), 0))
    7554                 :        1076 :       || loop_vinfo == NULL
    7555                 :        1076 :       || LOOP_VINFO_FULLY_MASKED_P (loop_vinfo)
    7556                 :        1076 :       || STMT_VINFO_GROUPED_ACCESS (stmt_info)
    7557                 :        1076 :       || !integer_zerop (get_dr_vinfo_offset (vinfo, dr_info))
    7558                 :        1076 :       || !integer_zerop (DR_INIT (dr_info->dr))
    7559                 :        1076 :       || !(ref_type = reference_alias_ptr_type (DR_REF (dr_info->dr)))
    7560                 :        2152 :       || !alias_sets_conflict_p (get_alias_set (vectype),
    7561                 :        1076 :                                  get_alias_set (TREE_TYPE (ref_type))))
    7562                 :             :     {
    7563                 :           0 :       if (dump_enabled_p ())
    7564                 :           0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    7565                 :             :                          "unsupported OpenMP scan store.\n");
    7566                 :           0 :       return false;
    7567                 :             :     }
    7568                 :             : 
    7569                 :             :   /* We need to pattern match code built by OpenMP lowering and simplified
    7570                 :             :      by following optimizations into something we can handle.
    7571                 :             :      #pragma omp simd reduction(inscan,+:r)
    7572                 :             :      for (...)
    7573                 :             :        {
    7574                 :             :          r += something ();
    7575                 :             :          #pragma omp scan inclusive (r)
    7576                 :             :          use (r);
    7577                 :             :        }
    7578                 :             :      shall have body with:
    7579                 :             :        // Initialization for input phase, store the reduction initializer:
    7580                 :             :        _20 = .GOMP_SIMD_LANE (simduid.3_14(D), 0);
    7581                 :             :        _21 = .GOMP_SIMD_LANE (simduid.3_14(D), 1);
    7582                 :             :        D.2042[_21] = 0;
    7583                 :             :        // Actual input phase:
    7584                 :             :        ...
    7585                 :             :        r.0_5 = D.2042[_20];
    7586                 :             :        _6 = _4 + r.0_5;
    7587                 :             :        D.2042[_20] = _6;
    7588                 :             :        // Initialization for scan phase:
    7589                 :             :        _25 = .GOMP_SIMD_LANE (simduid.3_14(D), 2);
    7590                 :             :        _26 = D.2043[_25];
    7591                 :             :        _27 = D.2042[_25];
    7592                 :             :        _28 = _26 + _27;
    7593                 :             :        D.2043[_25] = _28;
    7594                 :             :        D.2042[_25] = _28;
    7595                 :             :        // Actual scan phase:
    7596                 :             :        ...
    7597                 :             :        r.1_8 = D.2042[_20];
    7598                 :             :        ...
    7599                 :             :      The "omp simd array" variable D.2042 holds the privatized copy used
    7600                 :             :      inside of the loop and D.2043 is another one that holds copies of
    7601                 :             :      the current original list item.  The separate GOMP_SIMD_LANE ifn
    7602                 :             :      kinds are there in order to allow optimizing the initializer store
    7603                 :             :      and combiner sequence, e.g. if it is originally some C++ish user
    7604                 :             :      defined reduction, but allow the vectorizer to pattern recognize it
    7605                 :             :      and turn into the appropriate vectorized scan.
    7606                 :             : 
    7607                 :             :      For exclusive scan, this is slightly different:
    7608                 :             :      #pragma omp simd reduction(inscan,+:r)
    7609                 :             :      for (...)
    7610                 :             :        {
    7611                 :             :          use (r);
    7612                 :             :          #pragma omp scan exclusive (r)
    7613                 :             :          r += something ();
    7614                 :             :        }
    7615                 :             :      shall have body with:
    7616                 :             :        // Initialization for input phase, store the reduction initializer:
    7617                 :             :        _20 = .GOMP_SIMD_LANE (simduid.3_14(D), 0);
    7618                 :             :        _21 = .GOMP_SIMD_LANE (simduid.3_14(D), 1);
    7619                 :             :        D.2042[_21] = 0;
    7620                 :             :        // Actual input phase:
    7621                 :             :        ...
    7622                 :             :        r.0_5 = D.2042[_20];
    7623                 :             :        _6 = _4 + r.0_5;
    7624                 :             :        D.2042[_20] = _6;
    7625                 :             :        // Initialization for scan phase:
    7626                 :             :        _25 = .GOMP_SIMD_LANE (simduid.3_14(D), 3);
    7627                 :             :        _26 = D.2043[_25];
    7628                 :             :        D.2044[_25] = _26;
    7629                 :             :        _27 = D.2042[_25];
    7630                 :             :        _28 = _26 + _27;
    7631                 :             :        D.2043[_25] = _28;
    7632                 :             :        // Actual scan phase:
    7633                 :             :        ...
    7634                 :             :        r.1_8 = D.2044[_20];
    7635                 :             :        ...  */
    7636                 :             : 
    7637                 :        1076 :   if (STMT_VINFO_SIMD_LANE_ACCESS_P (stmt_info) == 2)
    7638                 :             :     {
    7639                 :             :       /* Match the D.2042[_21] = 0; store above.  Just require that
    7640                 :             :          it is a constant or external definition store.  */
    7641                 :         564 :       if (rhs_dt != vect_constant_def && rhs_dt != vect_external_def)
    7642                 :             :         {
    7643                 :           0 :          fail_init:
    7644                 :           0 :           if (dump_enabled_p ())
    7645                 :           0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    7646                 :             :                              "unsupported OpenMP scan initializer store.\n");
    7647                 :           0 :           return false;
    7648                 :             :         }
    7649                 :             : 
    7650                 :         564 :       if (! loop_vinfo->scan_map)
    7651                 :         322 :         loop_vinfo->scan_map = new hash_map<tree, tree>;
    7652                 :         564 :       tree var = TREE_OPERAND (DR_BASE_ADDRESS (dr_info->dr), 0);
    7653                 :         564 :       tree &cached = loop_vinfo->scan_map->get_or_insert (var);
    7654                 :         564 :       if (cached)
    7655                 :           0 :         goto fail_init;
    7656                 :         564 :       cached = gimple_assign_rhs1 (STMT_VINFO_STMT (stmt_info));
    7657                 :             : 
    7658                 :             :       /* These stores can be vectorized normally.  */
    7659                 :         564 :       return true;
    7660                 :             :     }
    7661                 :             : 
    7662                 :         512 :   if (rhs_dt != vect_internal_def)
    7663                 :             :     {
    7664                 :           0 :      fail:
    7665                 :           0 :       if (dump_enabled_p ())
    7666                 :           0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    7667                 :             :                          "unsupported OpenMP scan combiner pattern.\n");
    7668                 :           0 :       return false;
    7669                 :             :     }
    7670                 :             : 
    7671                 :         512 :   gimple *stmt = STMT_VINFO_STMT (stmt_info);
    7672                 :         512 :   tree rhs = gimple_assign_rhs1 (stmt);
    7673                 :         512 :   if (TREE_CODE (rhs) != SSA_NAME)
    7674                 :           0 :     goto fail;
    7675                 :             : 
    7676                 :         512 :   gimple *other_store_stmt = NULL;
    7677                 :         512 :   tree var = TREE_OPERAND (DR_BASE_ADDRESS (dr_info->dr), 0);
    7678                 :         512 :   bool inscan_var_store
    7679                 :         512 :     = lookup_attribute ("omp simd inscan", DECL_ATTRIBUTES (var)) != NULL;
    7680                 :             : 
    7681                 :         512 :   if (STMT_VINFO_SIMD_LANE_ACCESS_P (stmt_info) == 4)
    7682                 :             :     {
    7683                 :         252 :       if (!inscan_var_store)
    7684                 :             :         {
    7685                 :         126 :           use_operand_p use_p;
    7686                 :         126 :           imm_use_iterator iter;
    7687                 :         378 :           FOR_EACH_IMM_USE_FAST (use_p, iter, rhs)
    7688                 :             :             {
    7689                 :         252 :               gimple *use_stmt = USE_STMT (use_p);
    7690                 :         252 :               if (use_stmt == stmt || is_gimple_debug (use_stmt))
    7691                 :         126 :                 continue;
    7692                 :         126 :               if (gimple_bb (use_stmt) != gimple_bb (stmt)
    7693                 :         126 :                   || !is_gimple_assign (use_stmt)
    7694                 :         126 :                   || gimple_assign_rhs_class (use_stmt) != GIMPLE_BINARY_RHS
    7695                 :         126 :                   || other_store_stmt
    7696                 :         252 :                   || TREE_CODE (gimple_assign_lhs (use_stmt)) != SSA_NAME)
    7697                 :           0 :                 goto fail;
    7698                 :         126 :               other_store_stmt = use_stmt;
    7699                 :             :             }
    7700                 :         126 :           if (other_store_stmt == NULL)
    7701                 :           0 :             goto fail;
    7702                 :         126 :           rhs = gimple_assign_lhs (other_store_stmt);
    7703                 :         126 :           if (!single_imm_use (rhs, &use_p, &other_store_stmt))
    7704                 :           0 :             goto fail;
    7705                 :             :         }
    7706                 :             :     }
    7707                 :         260 :   else if (STMT_VINFO_SIMD_LANE_ACCESS_P (stmt_info) == 3)
    7708                 :             :     {
    7709                 :         260 :       use_operand_p use_p;
    7710                 :         260 :       imm_use_iterator iter;
    7711                 :         780 :       FOR_EACH_IMM_USE_FAST (use_p, iter, rhs)
    7712                 :             :         {
    7713                 :         520 :           gimple *use_stmt = USE_STMT (use_p);
    7714                 :         520 :           if (use_stmt == stmt || is_gimple_debug (use_stmt))
    7715                 :         260 :             continue;
    7716                 :         260 :           if (other_store_stmt)
    7717                 :           0 :             goto fail;
    7718                 :         260 :           other_store_stmt = use_stmt;
    7719                 :             :         }
    7720                 :             :     }
    7721                 :             :   else
    7722                 :           0 :     goto fail;
    7723                 :             : 
    7724                 :         512 :   gimple *def_stmt = SSA_NAME_DEF_STMT (rhs);
    7725                 :         512 :   if (gimple_bb (def_stmt) != gimple_bb (stmt)
    7726                 :         512 :       || !is_gimple_assign (def_stmt)
    7727                 :        1024 :       || gimple_assign_rhs_class (def_stmt) != GIMPLE_BINARY_RHS)
    7728                 :           0 :     goto fail;
    7729                 :             : 
    7730                 :         512 :   enum tree_code code = gimple_assign_rhs_code (def_stmt);
    7731                 :             :   /* For pointer addition, we should use the normal plus for the vector
    7732                 :             :      operation.  */
    7733                 :         512 :   switch (code)
    7734                 :             :     {
    7735                 :           0 :     case POINTER_PLUS_EXPR:
    7736                 :           0 :       code = PLUS_EXPR;
    7737                 :           0 :       break;
    7738                 :           0 :     case MULT_HIGHPART_EXPR:
    7739                 :           0 :       goto fail;
    7740                 :             :     default:
    7741                 :             :       break;
    7742                 :             :     }
    7743                 :         512 :   if (TREE_CODE_LENGTH (code) != binary_op || !commutative_tree_code (code))
    7744                 :           0 :     goto fail;
    7745                 :             : 
    7746                 :         512 :   tree rhs1 = gimple_assign_rhs1 (def_stmt);
    7747                 :         512 :   tree rhs2 = gimple_assign_rhs2 (def_stmt);
    7748                 :         512 :   if (TREE_CODE (rhs1) != SSA_NAME || TREE_CODE (rhs2) != SSA_NAME)
    7749                 :           0 :     goto fail;
    7750                 :             : 
    7751                 :         512 :   gimple *load1_stmt = SSA_NAME_DEF_STMT (rhs1);
    7752                 :         512 :   gimple *load2_stmt = SSA_NAME_DEF_STMT (rhs2);
    7753                 :         512 :   if (gimple_bb (load1_stmt) != gimple_bb (stmt)
    7754                 :         512 :       || !gimple_assign_load_p (load1_stmt)
    7755                 :         512 :       || gimple_bb (load2_stmt) != gimple_bb (stmt)
    7756                 :        1024 :       || !gimple_assign_load_p (load2_stmt))
    7757                 :           0 :     goto fail;
    7758                 :             : 
    7759                 :         512 :   stmt_vec_info load1_stmt_info = loop_vinfo->lookup_stmt (load1_stmt);
    7760                 :         512 :   stmt_vec_info load2_stmt_info = loop_vinfo->lookup_stmt (load2_stmt);
    7761                 :         512 :   if (load1_stmt_info == NULL
    7762                 :         512 :       || load2_stmt_info == NULL
    7763                 :         512 :       || (STMT_VINFO_SIMD_LANE_ACCESS_P (load1_stmt_info)
    7764                 :         512 :           != STMT_VINFO_SIMD_LANE_ACCESS_P (stmt_info))
    7765                 :         512 :       || (STMT_VINFO_SIMD_LANE_ACCESS_P (load2_stmt_info)
    7766                 :         512 :           != STMT_VINFO_SIMD_LANE_ACCESS_P (stmt_info)))
    7767                 :           0 :     goto fail;
    7768                 :             : 
    7769                 :         512 :   if (STMT_VINFO_SIMD_LANE_ACCESS_P (stmt_info) == 4 && inscan_var_store)
    7770                 :             :     {
    7771                 :         126 :       dr_vec_info *load1_dr_info = STMT_VINFO_DR_INFO (load1_stmt_info);
    7772                 :         126 :       if (TREE_CODE (DR_BASE_ADDRESS (load1_dr_info->dr)) != ADDR_EXPR
    7773                 :         126 :           || !VAR_P (TREE_OPERAND (DR_BASE_ADDRESS (load1_dr_info->dr), 0)))
    7774                 :           0 :         goto fail;
    7775                 :         126 :       tree var1 = TREE_OPERAND (DR_BASE_ADDRESS (load1_dr_info->dr), 0);
    7776                 :         126 :       tree lrhs;
    7777                 :         126 :       if (lookup_attribute ("omp simd inscan", DECL_ATTRIBUTES (var1)))
    7778                 :             :         lrhs = rhs1;
    7779                 :             :       else
    7780                 :          16 :         lrhs = rhs2;
    7781                 :         126 :       use_operand_p use_p;
    7782                 :         126 :       imm_use_iterator iter;
    7783                 :         378 :       FOR_EACH_IMM_USE_FAST (use_p, iter, lrhs)
    7784                 :             :         {
    7785                 :         252 :           gimple *use_stmt = USE_STMT (use_p);
    7786                 :         252 :           if (use_stmt == def_stmt || is_gimple_debug (use_stmt))
    7787                 :         126 :             continue;
    7788                 :         126 :           if (other_store_stmt)
    7789                 :           0 :             goto fail;
    7790                 :         126 :           other_store_stmt = use_stmt;
    7791                 :             :         }
    7792                 :             :     }
    7793                 :             : 
    7794                 :         512 :   if (other_store_stmt == NULL)
    7795                 :           0 :     goto fail;
    7796                 :         512 :   if (gimple_bb (other_store_stmt) != gimple_bb (stmt)
    7797                 :         512 :       || !gimple_store_p (other_store_stmt))
    7798                 :           0 :     goto fail;
    7799                 :             : 
    7800                 :         512 :   stmt_vec_info other_store_stmt_info
    7801                 :         512 :     = loop_vinfo->lookup_stmt (other_store_stmt);
    7802                 :         512 :   if (other_store_stmt_info == NULL
    7803                 :         512 :       || (STMT_VINFO_SIMD_LANE_ACCESS_P (other_store_stmt_info)
    7804                 :         512 :           != STMT_VINFO_SIMD_LANE_ACCESS_P (stmt_info)))
    7805                 :           0 :     goto fail;
    7806                 :             : 
    7807                 :         512 :   gimple *stmt1 = stmt;
    7808                 :         512 :   gimple *stmt2 = other_store_stmt;
    7809                 :         512 :   if (STMT_VINFO_SIMD_LANE_ACCESS_P (stmt_info) == 4 && !inscan_var_store)
    7810                 :             :     std::swap (stmt1, stmt2);
    7811                 :         512 :   if (scan_operand_equal_p (gimple_assign_lhs (stmt1),
    7812                 :             :                             gimple_assign_rhs1 (load2_stmt)))
    7813                 :             :     {
    7814                 :         162 :       std::swap (rhs1, rhs2);
    7815                 :         162 :       std::swap (load1_stmt, load2_stmt);
    7816                 :         162 :       std::swap (load1_stmt_info, load2_stmt_info);
    7817                 :             :     }
    7818                 :         512 :   if (!scan_operand_equal_p (gimple_assign_lhs (stmt1),
    7819                 :             :                              gimple_assign_rhs1 (load1_stmt)))
    7820                 :           0 :     goto fail;
    7821                 :             : 
    7822                 :         512 :   tree var3 = NULL_TREE;
    7823                 :         512 :   if (STMT_VINFO_SIMD_LANE_ACCESS_P (stmt_info) == 3
    7824                 :         512 :       && !scan_operand_equal_p (gimple_assign_lhs (stmt2),
    7825                 :             :                                 gimple_assign_rhs1 (load2_stmt)))
    7826                 :           0 :     goto fail;
    7827                 :         512 :   else if (STMT_VINFO_SIMD_LANE_ACCESS_P (stmt_info) == 4)
    7828                 :             :     {
    7829                 :         252 :       dr_vec_info *load2_dr_info = STMT_VINFO_DR_INFO (load2_stmt_info);
    7830                 :         252 :       if (TREE_CODE (DR_BASE_ADDRESS (load2_dr_info->dr)) != ADDR_EXPR
    7831                 :         252 :           || !VAR_P (TREE_OPERAND (DR_BASE_ADDRESS (load2_dr_info->dr), 0)))
    7832                 :           0 :         goto fail;
    7833                 :         252 :       var3 = TREE_OPERAND (DR_BASE_ADDRESS (load2_dr_info->dr), 0);
    7834                 :         252 :       if (!lookup_attribute ("omp simd array", DECL_ATTRIBUTES (var3))
    7835                 :         252 :           || lookup_attribute ("omp simd inscan", DECL_ATTRIBUTES (var3))
    7836                 :         504 :           || lookup_attribute ("omp simd inscan exclusive",
    7837                 :         252 :                                DECL_ATTRIBUTES (var3)))
    7838                 :           0 :         goto fail;
    7839                 :             :     }
    7840                 :             : 
    7841                 :         512 :   dr_vec_info *other_dr_info = STMT_VINFO_DR_INFO (other_store_stmt_info);
    7842                 :         512 :   if (TREE_CODE (DR_BASE_ADDRESS (other_dr_info->dr)) != ADDR_EXPR
    7843                 :         512 :       || !VAR_P (TREE_OPERAND (DR_BASE_ADDRESS (other_dr_info->dr), 0)))
    7844                 :           0 :     goto fail;
    7845                 :             : 
    7846                 :         512 :   tree var1 = TREE_OPERAND (DR_BASE_ADDRESS (dr_info->dr), 0);
    7847                 :         512 :   tree var2 = TREE_OPERAND (DR_BASE_ADDRESS (other_dr_info->dr), 0);
    7848                 :         512 :   if (!lookup_attribute ("omp simd array", DECL_ATTRIBUTES (var1))
    7849                 :         512 :       || !lookup_attribute ("omp simd array", DECL_ATTRIBUTES (var2))
    7850                 :        1024 :       || (!lookup_attribute ("omp simd inscan", DECL_ATTRIBUTES (var1)))
    7851                 :         512 :          == (!lookup_attribute ("omp simd inscan", DECL_ATTRIBUTES (var2))))
    7852                 :           0 :     goto fail;
    7853                 :             : 
    7854                 :         512 :   if (lookup_attribute ("omp simd inscan", DECL_ATTRIBUTES (var1)))
    7855                 :         256 :     std::swap (var1, var2);
    7856                 :             : 
    7857                 :         512 :   if (STMT_VINFO_SIMD_LANE_ACCESS_P (stmt_info) == 4)
    7858                 :             :     {
    7859                 :         252 :       if (!lookup_attribute ("omp simd inscan exclusive",
    7860                 :         252 :                              DECL_ATTRIBUTES (var1)))
    7861                 :           0 :         goto fail;
    7862                 :         252 :       var1 = var3;
    7863                 :             :     }
    7864                 :             : 
    7865                 :         512 :   if (loop_vinfo->scan_map == NULL)
    7866                 :           0 :     goto fail;
    7867                 :         512 :   tree *init = loop_vinfo->scan_map->get (var1);
    7868                 :         512 :   if (init == NULL)
    7869                 :           0 :     goto fail;
    7870                 :             : 
    7871                 :             :   /* The IL is as expected, now check if we can actually vectorize it.
    7872                 :             :      Inclusive scan:
    7873                 :             :        _26 = D.2043[_25];
    7874                 :             :        _27 = D.2042[_25];
    7875                 :             :        _28 = _26 + _27;
    7876                 :             :        D.2043[_25] = _28;
    7877                 :             :        D.2042[_25] = _28;
    7878                 :             :      should be vectorized as (where _40 is the vectorized rhs
    7879                 :             :      from the D.2042[_21] = 0; store):
    7880                 :             :        _30 = MEM <vector(8) int> [(int *)&D.2043];
    7881                 :             :        _31 = MEM <vector(8) int> [(int *)&D.2042];
    7882                 :             :        _32 = VEC_PERM_EXPR <_40, _31, { 0, 8, 9, 10, 11, 12, 13, 14 }>;
    7883                 :             :        _33 = _31 + _32;
    7884                 :             :        // _33 = { _31[0], _31[0]+_31[1], _31[1]+_31[2], ..., _31[6]+_31[7] };
    7885                 :             :        _34 = VEC_PERM_EXPR <_40, _33, { 0, 1, 8, 9, 10, 11, 12, 13 }>;
    7886                 :             :        _35 = _33 + _34;
    7887                 :             :        // _35 = { _31[0], _31[0]+_31[1], _31[0]+.._31[2], _31[0]+.._31[3],
    7888                 :             :        //         _31[1]+.._31[4], ... _31[4]+.._31[7] };
    7889                 :             :        _36 = VEC_PERM_EXPR <_40, _35, { 0, 1, 2, 3, 8, 9, 10, 11 }>;
    7890                 :             :        _37 = _35 + _36;
    7891                 :             :        // _37 = { _31[0], _31[0]+_31[1], _31[0]+.._31[2], _31[0]+.._31[3],
    7892                 :             :        //         _31[0]+.._31[4], ... _31[0]+.._31[7] };
    7893                 :             :        _38 = _30 + _37;
    7894                 :             :        _39 = VEC_PERM_EXPR <_38, _38, { 7, 7, 7, 7, 7, 7, 7, 7 }>;
    7895                 :             :        MEM <vector(8) int> [(int *)&D.2043] = _39;
    7896                 :             :        MEM <vector(8) int> [(int *)&D.2042] = _38;
    7897                 :             :      Exclusive scan:
    7898                 :             :        _26 = D.2043[_25];
    7899                 :             :        D.2044[_25] = _26;
    7900                 :             :        _27 = D.2042[_25];
    7901                 :             :        _28 = _26 + _27;
    7902                 :             :        D.2043[_25] = _28;
    7903                 :             :      should be vectorized as (where _40 is the vectorized rhs
    7904                 :             :      from the D.2042[_21] = 0; store):
    7905                 :             :        _30 = MEM <vector(8) int> [(int *)&D.2043];
    7906                 :             :        _31 = MEM <vector(8) int> [(int *)&D.2042];
    7907                 :             :        _32 = VEC_PERM_EXPR <_40, _31, { 0, 8, 9, 10, 11, 12, 13, 14 }>;
    7908                 :             :        _33 = VEC_PERM_EXPR <_40, _32, { 0, 8, 9, 10, 11, 12, 13, 14 }>;
    7909                 :             :        _34 = _32 + _33;
    7910                 :             :        // _34 = { 0, _31[0], _31[0]+_31[1], _31[1]+_31[2], _31[2]+_31[3],
    7911                 :             :        //         _31[3]+_31[4], ... _31[5]+.._31[6] };
    7912                 :             :        _35 = VEC_PERM_EXPR <_40, _34, { 0, 1, 8, 9, 10, 11, 12, 13 }>;
    7913                 :             :        _36 = _34 + _35;
    7914                 :             :        // _36 = { 0, _31[0], _31[0]+_31[1], _31[0]+.._31[2], _31[0]+.._31[3],
    7915                 :             :        //         _31[1]+.._31[4], ... _31[3]+.._31[6] };
    7916                 :             :        _37 = VEC_PERM_EXPR <_40, _36, { 0, 1, 2, 3, 8, 9, 10, 11 }>;
    7917                 :             :        _38 = _36 + _37;
    7918                 :             :        // _38 = { 0, _31[0], _31[0]+_31[1], _31[0]+.._31[2], _31[0]+.._31[3],
    7919                 :             :        //         _31[0]+.._31[4], ... _31[0]+.._31[6] };
    7920                 :             :        _39 = _30 + _38;
    7921                 :             :        _50 = _31 + _39;
    7922                 :             :        _51 = VEC_PERM_EXPR <_50, _50, { 7, 7, 7, 7, 7, 7, 7, 7 }>;
    7923                 :             :        MEM <vector(8) int> [(int *)&D.2044] = _39;
    7924                 :             :        MEM <vector(8) int> [(int *)&D.2042] = _51;  */
    7925                 :         512 :   enum machine_mode vec_mode = TYPE_MODE (vectype);
    7926                 :         512 :   optab optab = optab_for_tree_code (code, vectype, optab_default);
    7927                 :         512 :   if (!optab || !can_implement_p (optab, vec_mode))
    7928                 :           0 :     goto fail;
    7929                 :             : 
    7930                 :         512 :   int units_log2 = scan_store_can_perm_p (vectype, *init);
    7931                 :         512 :   if (units_log2 == -1)
    7932                 :           0 :     goto fail;
    7933                 :             : 
    7934                 :             :   return true;
    7935                 :             : }
    7936                 :             : 
    7937                 :             : 
    7938                 :             : /* Function vectorizable_scan_store.
    7939                 :             : 
    7940                 :             :    Helper of vectorizable_score, arguments like on vectorizable_store.
    7941                 :             :    Handle only the transformation, checking is done in check_scan_store.  */
    7942                 :             : 
    7943                 :             : static bool
    7944                 :         512 : vectorizable_scan_store (vec_info *vinfo, stmt_vec_info stmt_info,
    7945                 :             :                          slp_tree slp_node, gimple_stmt_iterator *gsi,
    7946                 :             :                          gimple **vec_stmt, int ncopies)
    7947                 :             : {
    7948                 :         512 :   loop_vec_info loop_vinfo = dyn_cast <loop_vec_info> (vinfo);
    7949                 :         512 :   dr_vec_info *dr_info = STMT_VINFO_DR_INFO (stmt_info);
    7950                 :         512 :   tree ref_type = reference_alias_ptr_type (DR_REF (dr_info->dr));
    7951                 :         512 :   tree vectype = STMT_VINFO_VECTYPE (stmt_info);
    7952                 :             : 
    7953                 :         512 :   if (dump_enabled_p ())
    7954                 :         492 :     dump_printf_loc (MSG_NOTE, vect_location,
    7955                 :             :                      "transform scan store. ncopies = %d\n", ncopies);
    7956                 :             : 
    7957                 :         512 :   gimple *stmt = STMT_VINFO_STMT (stmt_info);
    7958                 :         512 :   tree rhs = gimple_assign_rhs1 (stmt);
    7959                 :         512 :   gcc_assert (TREE_CODE (rhs) == SSA_NAME);
    7960                 :             : 
    7961                 :         512 :   tree var = TREE_OPERAND (DR_BASE_ADDRESS (dr_info->dr), 0);
    7962                 :         512 :   bool inscan_var_store
    7963                 :         512 :     = lookup_attribute ("omp simd inscan", DECL_ATTRIBUTES (var)) != NULL;
    7964                 :             : 
    7965                 :         512 :   if (STMT_VINFO_SIMD_LANE_ACCESS_P (stmt_info) == 4 && !inscan_var_store)
    7966                 :             :     {
    7967                 :         126 :       use_operand_p use_p;
    7968                 :         126 :       imm_use_iterator iter;
    7969                 :         126 :       FOR_EACH_IMM_USE_FAST (use_p, iter, rhs)
    7970                 :             :         {
    7971                 :         126 :           gimple *use_stmt = USE_STMT (use_p);
    7972                 :         126 :           if (use_stmt == stmt || is_gimple_debug (use_stmt))
    7973                 :           0 :             continue;
    7974                 :         126 :           rhs = gimple_assign_lhs (use_stmt);
    7975                 :         126 :           break;
    7976                 :             :         }
    7977                 :             :     }
    7978                 :             : 
    7979                 :         512 :   gimple *def_stmt = SSA_NAME_DEF_STMT (rhs);
    7980                 :         512 :   enum tree_code code = gimple_assign_rhs_code (def_stmt);
    7981                 :         512 :   if (code == POINTER_PLUS_EXPR)
    7982                 :           0 :     code = PLUS_EXPR;
    7983                 :         512 :   gcc_assert (TREE_CODE_LENGTH (code) == binary_op
    7984                 :             :               && commutative_tree_code (code));
    7985                 :         512 :   tree rhs1 = gimple_assign_rhs1 (def_stmt);
    7986                 :         512 :   tree rhs2 = gimple_assign_rhs2 (def_stmt);
    7987                 :         512 :   gcc_assert (TREE_CODE (rhs1) == SSA_NAME && TREE_CODE (rhs2) == SSA_NAME);
    7988                 :         512 :   gimple *load1_stmt = SSA_NAME_DEF_STMT (rhs1);
    7989                 :         512 :   gimple *load2_stmt = SSA_NAME_DEF_STMT (rhs2);
    7990                 :         512 :   stmt_vec_info load1_stmt_info = loop_vinfo->lookup_stmt (load1_stmt);
    7991                 :         512 :   stmt_vec_info load2_stmt_info = loop_vinfo->lookup_stmt (load2_stmt);
    7992                 :         512 :   dr_vec_info *load1_dr_info = STMT_VINFO_DR_INFO (load1_stmt_info);
    7993                 :         512 :   dr_vec_info *load2_dr_info = STMT_VINFO_DR_INFO (load2_stmt_info);
    7994                 :         512 :   tree var1 = TREE_OPERAND (DR_BASE_ADDRESS (load1_dr_info->dr), 0);
    7995                 :         512 :   tree var2 = TREE_OPERAND (DR_BASE_ADDRESS (load2_dr_info->dr), 0);
    7996                 :             : 
    7997                 :         512 :   if (lookup_attribute ("omp simd inscan", DECL_ATTRIBUTES (var1)))
    7998                 :             :     {
    7999                 :         436 :       std::swap (rhs1, rhs2);
    8000                 :         436 :       std::swap (var1, var2);
    8001                 :         436 :       std::swap (load1_dr_info, load2_dr_info);
    8002                 :             :     }
    8003                 :             : 
    8004                 :         512 :   tree *init = loop_vinfo->scan_map->get (var1);
    8005                 :         512 :   gcc_assert (init);
    8006                 :             : 
    8007                 :         512 :   unsigned HOST_WIDE_INT nunits;
    8008                 :         512 :   if (!TYPE_VECTOR_SUBPARTS (vectype).is_constant (&nunits))
    8009                 :             :     gcc_unreachable ();
    8010                 :         512 :   auto_vec<enum scan_store_kind, 16> use_whole_vector;
    8011                 :         512 :   int units_log2 = scan_store_can_perm_p (vectype, *init, &use_whole_vector);
    8012                 :         512 :   gcc_assert (units_log2 > 0);
    8013                 :         512 :   auto_vec<tree, 16> perms;
    8014                 :         512 :   perms.quick_grow (units_log2 + 1);
    8015                 :         512 :   tree zero_vec = NULL_TREE, masktype = NULL_TREE;
    8016                 :        2392 :   for (int i = 0; i <= units_log2; ++i)
    8017                 :             :     {
    8018                 :        1880 :       unsigned HOST_WIDE_INT j, k;
    8019                 :        1880 :       vec_perm_builder sel (nunits, nunits, 1);
    8020                 :        1880 :       sel.quick_grow (nunits);
    8021                 :        1880 :       if (i == units_log2)
    8022                 :        4864 :         for (j = 0; j < nunits; ++j)
    8023                 :        4352 :           sel[j] = nunits - 1;
    8024                 :             :       else
    8025                 :             :         {
    8026                 :        5208 :           for (j = 0; j < (HOST_WIDE_INT_1U << i); ++j)
    8027                 :        3840 :             sel[j] = j;
    8028                 :       13208 :           for (k = 0; j < nunits; ++j, ++k)
    8029                 :       11840 :             sel[j] = nunits + k;
    8030                 :             :         }
    8031                 :        3248 :       vec_perm_indices indices (sel, i == units_log2 ? 1 : 2, nunits);
    8032                 :        1880 :       if (!use_whole_vector.is_empty ()
    8033                 :           0 :           && use_whole_vector[i] != scan_store_kind_perm)
    8034                 :             :         {
    8035                 :           0 :           if (zero_vec == NULL_TREE)
    8036                 :           0 :             zero_vec = build_zero_cst (vectype);
    8037                 :           0 :           if (masktype == NULL_TREE
    8038                 :           0 :               && use_whole_vector[i] == scan_store_kind_lshift_cond)
    8039                 :           0 :             masktype = truth_type_for (vectype);
    8040                 :           0 :           perms[i] = vect_gen_perm_mask_any (vectype, indices);
    8041                 :             :         }
    8042                 :             :       else
    8043                 :        1880 :         perms[i] = vect_gen_perm_mask_checked (vectype, indices);
    8044                 :        1880 :     }
    8045                 :             : 
    8046                 :         512 :   tree vec_oprnd1 = NULL_TREE;
    8047                 :         512 :   tree vec_oprnd2 = NULL_TREE;
    8048                 :         512 :   tree vec_oprnd3 = NULL_TREE;
    8049                 :         512 :   tree dataref_ptr = DR_BASE_ADDRESS (dr_info->dr);
    8050                 :         512 :   tree dataref_offset = build_int_cst (ref_type, 0);
    8051                 :         512 :   tree bump = vect_get_data_ptr_increment (vinfo, gsi, dr_info,
    8052                 :             :                                            vectype, VMAT_CONTIGUOUS);
    8053                 :         512 :   tree ldataref_ptr = NULL_TREE;
    8054                 :         512 :   tree orig = NULL_TREE;
    8055                 :         512 :   if (STMT_VINFO_SIMD_LANE_ACCESS_P (stmt_info) == 4 && !inscan_var_store)
    8056                 :         126 :     ldataref_ptr = DR_BASE_ADDRESS (load1_dr_info->dr);
    8057                 :             :   /* The initialization is invariant.  */
    8058                 :         512 :   vec_oprnd1 = vect_init_vector (vinfo, stmt_info, *init, vectype, NULL);
    8059                 :         512 :   auto_vec<tree> vec_oprnds2;
    8060                 :         512 :   auto_vec<tree> vec_oprnds3;
    8061                 :         512 :   if (ldataref_ptr == NULL)
    8062                 :             :     {
    8063                 :             :       /* We want to lookup the vector operands of the reduction, not those
    8064                 :             :          of the store - for SLP we have to use the proper SLP node for the
    8065                 :             :          lookup, which should be the single child of the scan store.  */
    8066                 :         386 :       vect_get_vec_defs (vinfo, stmt_info, SLP_TREE_CHILDREN (slp_node)[0],
    8067                 :             :                          ncopies, rhs1, &vec_oprnds2, rhs2, &vec_oprnds3);
    8068                 :             :       /* ???  For SLP we do not key the def on 'rhs1' or 'rhs2' but get
    8069                 :             :          them in SLP child order.  So we have to swap here with logic
    8070                 :             :          similar to above.  */
    8071                 :         386 :       stmt_vec_info load
    8072                 :         386 :         = SLP_TREE_SCALAR_STMTS (SLP_TREE_CHILDREN
    8073                 :         386 :                                    (SLP_TREE_CHILDREN (slp_node)[0])[0])[0];
    8074                 :         386 :       dr_vec_info *dr_info = STMT_VINFO_DR_INFO (load);
    8075                 :         386 :       tree var = TREE_OPERAND (DR_BASE_ADDRESS (dr_info->dr), 0);
    8076                 :         386 :       if (lookup_attribute ("omp simd inscan", DECL_ATTRIBUTES (var)))
    8077                 :         820 :         for (unsigned i = 0; i < vec_oprnds2.length (); ++i)
    8078                 :         494 :           std::swap (vec_oprnds2[i], vec_oprnds3[i]);;
    8079                 :             :     }
    8080                 :             :   else
    8081                 :         126 :     vect_get_vec_defs (vinfo, stmt_info, slp_node, ncopies,
    8082                 :             :                        rhs2, &vec_oprnds3);
    8083                 :        1248 :   for (unsigned j = 0; j < vec_oprnds3.length (); j++)
    8084                 :             :     {
    8085                 :         736 :       if (ldataref_ptr == NULL)
    8086                 :         554 :         vec_oprnd2 = vec_oprnds2[j];
    8087                 :         736 :       vec_oprnd3 = vec_oprnds3[j];
    8088                 :         736 :       if (j == 0)
    8089                 :             :         orig = vec_oprnd3;
    8090                 :         224 :       else if (!inscan_var_store)
    8091                 :         112 :         dataref_offset = int_const_binop (PLUS_EXPR, dataref_offset, bump);
    8092                 :             : 
    8093                 :         736 :       if (ldataref_ptr)
    8094                 :             :         {
    8095                 :         182 :           vec_oprnd2 = make_ssa_name (vectype);
    8096                 :         182 :           tree data_ref = fold_build2 (MEM_REF, vectype,
    8097                 :             :                                        unshare_expr (ldataref_ptr),
    8098                 :             :                                        dataref_offset);
    8099                 :         182 :           vect_copy_ref_info (data_ref, DR_REF (load1_dr_info->dr));
    8100                 :         182 :           gimple *g = gimple_build_assign (vec_oprnd2, data_ref);
    8101                 :         182 :           vect_finish_stmt_generation (vinfo, stmt_info, g, gsi);
    8102                 :         182 :           if (! slp_node)
    8103                 :             :             {
    8104                 :           0 :               STMT_VINFO_VEC_STMTS (stmt_info).safe_push (g);
    8105                 :           0 :               *vec_stmt = STMT_VINFO_VEC_STMTS (stmt_info)[0];
    8106                 :             :             }
    8107                 :             :         }
    8108                 :             : 
    8109                 :         736 :       tree v = vec_oprnd2;
    8110                 :        3068 :       for (int i = 0; i < units_log2; ++i)
    8111                 :             :         {
    8112                 :        2332 :           tree new_temp = make_ssa_name (vectype);
    8113                 :        2332 :           gimple *g = gimple_build_assign (new_temp, VEC_PERM_EXPR,
    8114                 :             :                                            (zero_vec
    8115                 :           0 :                                             && (use_whole_vector[i]
    8116                 :           0 :                                                 != scan_store_kind_perm))
    8117                 :             :                                            ? zero_vec : vec_oprnd1, v,
    8118                 :        2332 :                                            perms[i]);
    8119                 :        2332 :           vect_finish_stmt_generation (vinfo, stmt_info, g, gsi);
    8120                 :        2332 :           if (! slp_node)
    8121                 :             :             {
    8122                 :           0 :               STMT_VINFO_VEC_STMTS (stmt_info).safe_push (g);
    8123                 :           0 :               *vec_stmt = STMT_VINFO_VEC_STMTS (stmt_info)[0];
    8124                 :             :             }
    8125                 :             : 
    8126                 :        2332 :           if (zero_vec && use_whole_vector[i] == scan_store_kind_lshift_cond)
    8127                 :             :             {
    8128                 :             :               /* Whole vector shift shifted in zero bits, but if *init
    8129                 :             :                  is not initializer_zerop, we need to replace those elements
    8130                 :             :                  with elements from vec_oprnd1.  */
    8131                 :           0 :               tree_vector_builder vb (masktype, nunits, 1);
    8132                 :           0 :               for (unsigned HOST_WIDE_INT k = 0; k < nunits; ++k)
    8133                 :           0 :                 vb.quick_push (k < (HOST_WIDE_INT_1U << i)
    8134                 :             :                                ? boolean_false_node : boolean_true_node);
    8135                 :             : 
    8136                 :           0 :               tree new_temp2 = make_ssa_name (vectype);
    8137                 :           0 :               g = gimple_build_assign (new_temp2, VEC_COND_EXPR, vb.build (),
    8138                 :             :                                        new_temp, vec_oprnd1);
    8139                 :           0 :               vect_finish_stmt_generation (vinfo, stmt_info,
    8140                 :             :                                                            g, gsi);
    8141                 :           0 :               if (! slp_node)
    8142                 :           0 :                 STMT_VINFO_VEC_STMTS (stmt_info).safe_push (g);
    8143                 :           0 :               new_temp = new_temp2;
    8144                 :           0 :             }
    8145                 :             : 
    8146                 :             :           /* For exclusive scan, perform the perms[i] permutation once
    8147                 :             :              more.  */
    8148                 :        2332 :           if (i == 0
    8149                 :        1100 :               && STMT_VINFO_SIMD_LANE_ACCESS_P (stmt_info) == 4
    8150                 :         728 :               && v == vec_oprnd2)
    8151                 :             :             {
    8152                 :         364 :               v = new_temp;
    8153                 :         364 :               --i;
    8154                 :         364 :               continue;
    8155                 :             :             }
    8156                 :             : 
    8157                 :        1968 :           tree new_temp2 = make_ssa_name (vectype);
    8158                 :        1968 :           g = gimple_build_assign (new_temp2, code, v, new_temp);
    8159                 :        1968 :           vect_finish_stmt_generation (vinfo, stmt_info, g, gsi);
    8160                 :        1968 :           if (! slp_node)
    8161                 :           0 :             STMT_VINFO_VEC_STMTS (stmt_info).safe_push (g);
    8162                 :             : 
    8163                 :        1968 :           v = new_temp2;
    8164                 :             :         }
    8165                 :             : 
    8166                 :         736 :       tree new_temp = make_ssa_name (vectype);
    8167                 :         736 :       gimple *g = gimple_build_assign (new_temp, code, orig, v);
    8168                 :         736 :       vect_finish_stmt_generation (vinfo, stmt_info, g, gsi);
    8169                 :         736 :       if (! slp_node)
    8170                 :           0 :         STMT_VINFO_VEC_STMTS (stmt_info).safe_push (g);
    8171                 :             : 
    8172                 :         736 :       tree last_perm_arg = new_temp;
    8173                 :             :       /* For exclusive scan, new_temp computed above is the exclusive scan
    8174                 :             :          prefix sum.  Turn it into inclusive prefix sum for the broadcast
    8175                 :             :          of the last element into orig.  */
    8176                 :         736 :       if (STMT_VINFO_SIMD_LANE_ACCESS_P (stmt_info) == 4)
    8177                 :             :         {
    8178                 :         364 :           last_perm_arg = make_ssa_name (vectype);
    8179                 :         364 :           g = gimple_build_assign (last_perm_arg, code, new_temp, vec_oprnd2);
    8180                 :         364 :           vect_finish_stmt_generation (vinfo, stmt_info, g, gsi);
    8181                 :         364 :           if (! slp_node)
    8182                 :           0 :             STMT_VINFO_VEC_STMTS (stmt_info).safe_push (g);
    8183                 :             :         }
    8184                 :             : 
    8185                 :         736 :       orig = make_ssa_name (vectype);
    8186                 :        2208 :       g = gimple_build_assign (orig, VEC_PERM_EXPR, last_perm_arg,
    8187                 :         736 :                                last_perm_arg, perms[units_log2]);
    8188                 :         736 :       vect_finish_stmt_generation (vinfo, stmt_info, g, gsi);
    8189                 :         736 :       if (! slp_node)
    8190                 :           0 :         STMT_VINFO_VEC_STMTS (stmt_info).safe_push (g);
    8191                 :             : 
    8192                 :         736 :       if (!inscan_var_store)
    8193                 :             :         {
    8194                 :         368 :           tree data_ref = fold_build2 (MEM_REF, vectype,
    8195                 :             :                                        unshare_expr (dataref_ptr),
    8196                 :             :                                        dataref_offset);
    8197                 :         368 :           vect_copy_ref_info (data_ref, DR_REF (dr_info->dr));
    8198                 :         368 :           g = gimple_build_assign (data_ref, new_temp);
    8199                 :         368 :           vect_finish_stmt_generation (vinfo, stmt_info, g, gsi);
    8200                 :         368 :           if (! slp_node)
    8201                 :           0 :             STMT_VINFO_VEC_STMTS (stmt_info).safe_push (g);
    8202                 :             :         }
    8203                 :             :     }
    8204                 :             : 
    8205                 :         512 :   if (inscan_var_store)
    8206                 :         624 :     for (unsigned j = 0; j < vec_oprnds3.length (); j++)
    8207                 :             :       {
    8208                 :         368 :         if (j != 0)
    8209                 :         112 :           dataref_offset = int_const_binop (PLUS_EXPR, dataref_offset, bump);
    8210                 :             : 
    8211                 :         368 :         tree data_ref = fold_build2 (MEM_REF, vectype,
    8212                 :             :                                      unshare_expr (dataref_ptr),
    8213                 :             :                                      dataref_offset);
    8214                 :         368 :         vect_copy_ref_info (data_ref, DR_REF (dr_info->dr));
    8215                 :         368 :         gimple *g = gimple_build_assign (data_ref, orig);
    8216                 :         368 :         vect_finish_stmt_generation (vinfo, stmt_info, g, gsi);
    8217                 :         368 :         if (! slp_node)
    8218                 :           0 :           STMT_VINFO_VEC_STMTS (stmt_info).safe_push (g);
    8219                 :             :       }
    8220                 :         512 :   return true;
    8221                 :         512 : }
    8222                 :             : 
    8223                 :             : 
    8224                 :             : /* Function vectorizable_store.
    8225                 :             : 
    8226                 :             :    Check if STMT_INFO defines a non scalar data-ref (array/pointer/structure)
    8227                 :             :    that can be vectorized.
    8228                 :             :    If VEC_STMT is also passed, vectorize STMT_INFO: create a vectorized
    8229                 :             :    stmt to replace it, put it in VEC_STMT, and insert it at GSI.
    8230                 :             :    Return true if STMT_INFO is vectorizable in this way.  */
    8231                 :             : 
    8232                 :             : static bool
    8233                 :     2039014 : vectorizable_store (vec_info *vinfo,
    8234                 :             :                     stmt_vec_info stmt_info, gimple_stmt_iterator *gsi,
    8235                 :             :                     gimple **vec_stmt, slp_tree slp_node,
    8236                 :             :                     stmt_vector_for_cost *cost_vec)
    8237                 :             : {
    8238                 :     2039014 :   tree data_ref;
    8239                 :     2039014 :   tree vec_oprnd = NULL_TREE;
    8240                 :     2039014 :   tree elem_type;
    8241                 :     2039014 :   loop_vec_info loop_vinfo = dyn_cast <loop_vec_info> (vinfo);
    8242                 :     2039014 :   class loop *loop = NULL;
    8243                 :     2039014 :   machine_mode vec_mode;
    8244                 :     2039014 :   tree dummy;
    8245                 :     2039014 :   enum vect_def_type rhs_dt = vect_unknown_def_type;
    8246                 :     2039014 :   enum vect_def_type mask_dt = vect_unknown_def_type;
    8247                 :     2039014 :   tree dataref_ptr = NULL_TREE;
    8248                 :     2039014 :   tree dataref_offset = NULL_TREE;
    8249                 :     2039014 :   gimple *ptr_incr = NULL;
    8250                 :     2039014 :   int j;
    8251                 :     2039014 :   stmt_vec_info first_stmt_info;
    8252                 :     2039014 :   bool grouped_store;
    8253                 :     2039014 :   unsigned int group_size, i;
    8254                 :     2039014 :   unsigned int vec_num;
    8255                 :     2039014 :   bb_vec_info bb_vinfo = dyn_cast <bb_vec_info> (vinfo);
    8256                 :     2039014 :   tree aggr_type;
    8257                 :     2039014 :   gather_scatter_info gs_info;
    8258                 :     2039014 :   poly_uint64 vf;
    8259                 :     2039014 :   vec_load_store_type vls_type;
    8260                 :     2039014 :   tree ref_type;
    8261                 :             : 
    8262                 :     2039014 :   if (!STMT_VINFO_RELEVANT_P (stmt_info) && !bb_vinfo)
    8263                 :             :     return false;
    8264                 :             : 
    8265                 :     2039014 :   if (STMT_VINFO_DEF_TYPE (stmt_info) != vect_internal_def
    8266                 :      200344 :       && ! vec_stmt)
    8267                 :             :     return false;
    8268                 :             : 
    8269                 :             :   /* Is vectorizable store? */
    8270                 :             : 
    8271                 :     1838670 :   tree mask = NULL_TREE, mask_vectype = NULL_TREE;
    8272                 :     1838670 :   slp_tree mask_node = NULL;
    8273                 :     1838670 :   if (gassign *assign = dyn_cast <gassign *> (stmt_info->stmt))
    8274                 :             :     {
    8275                 :     1761396 :       tree scalar_dest = gimple_assign_lhs (assign);
    8276                 :     1761396 :       if (TREE_CODE (scalar_dest) == VIEW_CONVERT_EXPR
    8277                 :     1761396 :           && is_pattern_stmt_p (stmt_info))
    8278                 :        1077 :         scalar_dest = TREE_OPERAND (scalar_dest, 0);
    8279                 :     1761396 :       if (TREE_CODE (scalar_dest) != ARRAY_REF
    8280                 :     1761396 :           && TREE_CODE (scalar_dest) != BIT_FIELD_REF
    8281                 :             :           && TREE_CODE (scalar_dest) != INDIRECT_REF
    8282                 :             :           && TREE_CODE (scalar_dest) != COMPONENT_REF
    8283                 :             :           && TREE_CODE (scalar_dest) != IMAGPART_EXPR
    8284                 :             :           && TREE_CODE (scalar_dest) != REALPART_EXPR
    8285                 :             :           && TREE_CODE (scalar_dest) != MEM_REF)
    8286                 :             :         return false;
    8287                 :             :     }
    8288                 :             :   else
    8289                 :             :     {
    8290                 :      654409 :       gcall *call = dyn_cast <gcall *> (stmt_info->stmt);
    8291                 :        8631 :       if (!call || !gimple_call_internal_p (call))
    8292                 :             :         return false;
    8293                 :             : 
    8294                 :        4648 :       internal_fn ifn = gimple_call_internal_fn (call);
    8295                 :        4648 :       if (!internal_store_fn_p (ifn))
    8296                 :             :         return false;
    8297                 :             : 
    8298                 :        1465 :       int mask_index = internal_fn_mask_index (ifn);
    8299                 :        1465 :       if (mask_index >= 0)
    8300                 :        1465 :         mask_index = vect_slp_child_index_for_operand
    8301                 :        1465 :                     (call, mask_index, STMT_VINFO_GATHER_SCATTER_P (stmt_info));
    8302                 :        1465 :       if (mask_index >= 0
    8303                 :        1465 :           && !vect_check_scalar_mask (vinfo, stmt_info, slp_node, mask_index,
    8304                 :             :                                       &mask, &mask_node, &mask_dt,
    8305                 :             :                                       &mask_vectype))
    8306                 :             :         return false;
    8307                 :             :     }
    8308                 :             : 
    8309                 :             :   /* Cannot have hybrid store SLP -- that would mean storing to the
    8310                 :             :      same location twice.  */
    8311                 :     1393893 :   gcc_assert (PURE_SLP_STMT (stmt_info));
    8312                 :             : 
    8313                 :     1393893 :   tree vectype = SLP_TREE_VECTYPE (stmt_info), rhs_vectype = NULL_TREE;
    8314                 :     1393893 :   poly_uint64 nunits = TYPE_VECTOR_SUBPARTS (vectype);
    8315                 :             : 
    8316                 :     1393893 :   if (loop_vinfo)
    8317                 :             :     {
    8318                 :      190628 :       loop = LOOP_VINFO_LOOP (loop_vinfo);
    8319                 :      190628 :       vf = LOOP_VINFO_VECT_FACTOR (loop_vinfo);
    8320                 :             :     }
    8321                 :             :   else
    8322                 :             :     vf = 1;
    8323                 :             : 
    8324                 :             :   /* FORNOW.  This restriction should be relaxed.  */
    8325                 :      190628 :   if (loop
    8326                 :     1394130 :       && nested_in_vect_loop_p (loop, stmt_info)
    8327                 :      190873 :       && SLP_TREE_NUMBER_OF_VEC_STMTS (slp_node) > 1)
    8328                 :             :     {
    8329                 :           8 :       if (dump_enabled_p ())
    8330                 :           0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    8331                 :             :                          "multiple types in nested loop.\n");
    8332                 :           8 :       return false;
    8333                 :             :     }
    8334                 :             : 
    8335                 :     1393885 :   tree op;
    8336                 :     1393885 :   slp_tree op_node;
    8337                 :     1393885 :   if (!vect_check_store_rhs (vinfo, stmt_info, slp_node,
    8338                 :             :                              &op, &op_node, &rhs_dt, &rhs_vectype, &vls_type))
    8339                 :             :     return false;
    8340                 :             : 
    8341                 :     1393861 :   elem_type = TREE_TYPE (vectype);
    8342                 :     1393861 :   vec_mode = TYPE_MODE (vectype);
    8343                 :             : 
    8344                 :     1393861 :   if (!STMT_VINFO_DATA_REF (stmt_info))
    8345                 :             :     return false;
    8346                 :             : 
    8347                 :     1393861 :   vect_memory_access_type memory_access_type;
    8348                 :     1393861 :   enum dr_alignment_support alignment_support_scheme;
    8349                 :     1393861 :   int misalignment;
    8350                 :     1393861 :   poly_int64 poffset;
    8351                 :     1393861 :   internal_fn lanes_ifn;
    8352                 :     1393861 :   if (!get_load_store_type (vinfo, stmt_info, vectype, slp_node, mask, vls_type,
    8353                 :             :                             1, &memory_access_type, &poffset,
    8354                 :             :                             &alignment_support_scheme, &misalignment, &gs_info,
    8355                 :             :                             &lanes_ifn))
    8356                 :             :     return false;
    8357                 :             : 
    8358                 :     1393348 :   if (slp_node->ldst_lanes
    8359                 :           0 :       && memory_access_type != VMAT_LOAD_STORE_LANES)
    8360                 :             :     {
    8361                 :           0 :       if (dump_enabled_p ())
    8362                 :           0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    8363                 :             :                          "discovered store-lane but cannot use it.\n");
    8364                 :           0 :       return false;
    8365                 :             :     }
    8366                 :             : 
    8367                 :     1393348 :   if (mask)
    8368                 :             :     {
    8369                 :        1375 :       if (memory_access_type == VMAT_CONTIGUOUS)
    8370                 :             :         {
    8371                 :         491 :           if (!VECTOR_MODE_P (vec_mode)
    8372                 :        2150 :               || !can_vec_mask_load_store_p (vec_mode,
    8373                 :        1075 :                                              TYPE_MODE (mask_vectype), false))
    8374                 :          16 :             return false;
    8375                 :             :         }
    8376                 :         300 :       else if (memory_access_type != VMAT_LOAD_STORE_LANES
    8377                 :         300 :                && (memory_access_type != VMAT_GATHER_SCATTER
    8378                 :         272 :                    || (gs_info.decl && !VECTOR_BOOLEAN_TYPE_P (mask_vectype))))
    8379                 :             :         {
    8380                 :          28 :           if (dump_enabled_p ())
    8381                 :          28 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    8382                 :             :                              "unsupported access type for masked store.\n");
    8383                 :          28 :           return false;
    8384                 :             :         }
    8385                 :         272 :       else if (memory_access_type == VMAT_GATHER_SCATTER
    8386                 :         272 :                && gs_info.ifn == IFN_LAST
    8387                 :         272 :                && !gs_info.decl)
    8388                 :             :         {
    8389                 :          68 :           if (dump_enabled_p ())
    8390                 :          24 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    8391                 :             :                              "unsupported masked emulated scatter.\n");
    8392                 :          68 :           return false;
    8393                 :             :         }
    8394                 :             :     }
    8395                 :             :   else
    8396                 :             :     {
    8397                 :             :       /* FORNOW. In some cases can vectorize even if data-type not supported
    8398                 :             :          (e.g. - array initialization with 0).  */
    8399                 :     1391973 :       if (!can_implement_p (mov_optab, vec_mode))
    8400                 :             :         return false;
    8401                 :             :     }
    8402                 :             : 
    8403                 :     1393236 :   dr_vec_info *dr_info = STMT_VINFO_DR_INFO (stmt_info), *first_dr_info = NULL;
    8404                 :     1393236 :   grouped_store = (STMT_VINFO_GROUPED_ACCESS (stmt_info)
    8405                 :     2614728 :                    && memory_access_type != VMAT_GATHER_SCATTER);
    8406                 :     1221492 :   if (grouped_store)
    8407                 :             :     {
    8408                 :     1221492 :       first_stmt_info = DR_GROUP_FIRST_ELEMENT (stmt_info);
    8409                 :     1221492 :       first_dr_info = STMT_VINFO_DR_INFO (first_stmt_info);
    8410                 :     1221492 :       group_size = DR_GROUP_SIZE (first_stmt_info);
    8411                 :             :     }
    8412                 :             :   else
    8413                 :             :     {
    8414                 :     1393236 :       first_stmt_info = stmt_info;
    8415                 :     1393236 :       first_dr_info = dr_info;
    8416                 :     1393236 :       group_size = vec_num = 1;
    8417                 :             :     }
    8418                 :             : 
    8419                 :     1393236 :   if (STMT_VINFO_SIMD_LANE_ACCESS_P (stmt_info) > 1 && !vec_stmt)
    8420                 :             :     {
    8421                 :        1076 :       if (!check_scan_store (vinfo, stmt_info, vectype, rhs_dt, slp_node, mask,
    8422                 :             :                              memory_access_type))
    8423                 :             :         return false;
    8424                 :             :     }
    8425                 :             : 
    8426                 :     2785704 :   bool costing_p = !vec_stmt;
    8427                 :     1392468 :   if (costing_p) /* transformation not required.  */
    8428                 :             :     {
    8429                 :      854847 :       STMT_VINFO_MEMORY_ACCESS_TYPE (stmt_info) = memory_access_type;
    8430                 :      854847 :       SLP_TREE_MEMORY_ACCESS_TYPE (slp_node) = memory_access_type;
    8431                 :             : 
    8432                 :      854847 :       if (loop_vinfo
    8433                 :      131517 :           && LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo))
    8434                 :          25 :         check_load_store_for_partial_vectors (loop_vinfo, vectype, slp_node,
    8435                 :             :                                               vls_type, group_size,
    8436                 :             :                                               memory_access_type, &gs_info,
    8437                 :             :                                               mask);
    8438                 :             : 
    8439                 :      854847 :       if (!vect_maybe_update_slp_op_vectype (op_node, vectype)
    8440                 :      854847 :           || (mask
    8441                 :         782 :               && !vect_maybe_update_slp_op_vectype (mask_node,
    8442                 :             :                                                     mask_vectype)))
    8443                 :             :         {
    8444                 :           0 :           if (dump_enabled_p ())
    8445                 :           0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    8446                 :             :                              "incompatible vector types for invariants\n");
    8447                 :           0 :           return false;
    8448                 :             :         }
    8449                 :             : 
    8450                 :      854847 :       if (dump_enabled_p ()
    8451                 :             :           && memory_access_type != VMAT_ELEMENTWISE
    8452                 :             :           && memory_access_type != VMAT_GATHER_SCATTER
    8453                 :             :           && memory_access_type != VMAT_STRIDED_SLP
    8454                 :       15240 :           && memory_access_type != VMAT_INVARIANT
    8455                 :      870087 :           && alignment_support_scheme != dr_aligned)
    8456                 :        5502 :         dump_printf_loc (MSG_NOTE, vect_location,
    8457                 :             :                          "Vectorizing an unaligned access.\n");
    8458                 :             : 
    8459                 :      854847 :       STMT_VINFO_TYPE (stmt_info) = store_vec_info_type;
    8460                 :             :     }
    8461                 :     1393236 :   gcc_assert (memory_access_type == SLP_TREE_MEMORY_ACCESS_TYPE (stmt_info));
    8462                 :             : 
    8463                 :             :   /* Transform.  */
    8464                 :             : 
    8465                 :     1393236 :   ensure_base_align (dr_info);
    8466                 :             : 
    8467                 :     1393236 :   if (STMT_VINFO_SIMD_LANE_ACCESS_P (stmt_info) >= 3)
    8468                 :             :     {
    8469                 :        1024 :       gcc_assert (memory_access_type == VMAT_CONTIGUOUS);
    8470                 :        1024 :       gcc_assert (SLP_TREE_LANES (slp_node) == 1);
    8471                 :        1024 :       if (costing_p)
    8472                 :             :         {
    8473                 :         512 :           unsigned int inside_cost = 0, prologue_cost = 0;
    8474                 :         512 :           if (vls_type == VLS_STORE_INVARIANT)
    8475                 :           0 :             prologue_cost += record_stmt_cost (cost_vec, 1, scalar_to_vec,
    8476                 :             :                                                stmt_info, 0, vect_prologue);
    8477                 :         512 :           vect_get_store_cost (vinfo, stmt_info, slp_node, 1,
    8478                 :             :                                alignment_support_scheme, misalignment,
    8479                 :             :                                &inside_cost, cost_vec);
    8480                 :             : 
    8481                 :         512 :           if (dump_enabled_p ())
    8482                 :         492 :             dump_printf_loc (MSG_NOTE, vect_location,
    8483                 :             :                              "vect_model_store_cost: inside_cost = %d, "
    8484                 :             :                              "prologue_cost = %d .\n",
    8485                 :             :                              inside_cost, prologue_cost);
    8486                 :             : 
    8487                 :         512 :           return true;
    8488                 :             :         }
    8489                 :         512 :       return vectorizable_scan_store (vinfo, stmt_info, slp_node,
    8490                 :         512 :                                       gsi, vec_stmt, 1);
    8491                 :             :     }
    8492                 :             : 
    8493                 :             :   /* FORNOW */
    8494                 :     1392212 :   gcc_assert (!grouped_store
    8495                 :             :               || !loop
    8496                 :             :               || !nested_in_vect_loop_p (loop, stmt_info));
    8497                 :             : 
    8498                 :     1392212 :   grouped_store = false;
    8499                 :             :   /* VEC_NUM is the number of vect stmts to be created for this
    8500                 :             :      group.  */
    8501                 :     1392212 :   vec_num = SLP_TREE_NUMBER_OF_VEC_STMTS (slp_node);
    8502                 :     1392212 :   first_stmt_info = SLP_TREE_SCALAR_STMTS (slp_node)[0];
    8503                 :     1392212 :   gcc_assert (!STMT_VINFO_GROUPED_ACCESS (first_stmt_info)
    8504                 :             :               || (DR_GROUP_FIRST_ELEMENT (first_stmt_info) == first_stmt_info));
    8505                 :     1392212 :   first_dr_info = STMT_VINFO_DR_INFO (first_stmt_info);
    8506                 :     1392212 :   op = vect_get_store_rhs (first_stmt_info);
    8507                 :             : 
    8508                 :     1392212 :   ref_type = get_group_alias_ptr_type (first_stmt_info);
    8509                 :             : 
    8510                 :     1392212 :   if (!costing_p && dump_enabled_p ())
    8511                 :       11630 :     dump_printf_loc (MSG_NOTE, vect_location, "transform store.\n");
    8512                 :             : 
    8513                 :     1392212 :   if (memory_access_type == VMAT_ELEMENTWISE
    8514                 :     1392212 :       || memory_access_type == VMAT_STRIDED_SLP)
    8515                 :             :     {
    8516                 :       29425 :       unsigned inside_cost = 0, prologue_cost = 0;
    8517                 :       29425 :       gimple_stmt_iterator incr_gsi;
    8518                 :       29425 :       bool insert_after;
    8519                 :       29425 :       tree offvar = NULL_TREE;
    8520                 :       29425 :       tree ivstep;
    8521                 :       29425 :       tree running_off;
    8522                 :       29425 :       tree stride_base, stride_step, alias_off;
    8523                 :       29425 :       tree vec_oprnd = NULL_TREE;
    8524                 :       29425 :       tree dr_offset;
    8525                 :             :       /* Checked by get_load_store_type.  */
    8526                 :       29425 :       unsigned int const_nunits = nunits.to_constant ();
    8527                 :             : 
    8528                 :       29425 :       gcc_assert (!LOOP_VINFO_FULLY_MASKED_P (loop_vinfo));
    8529                 :       29425 :       gcc_assert (!nested_in_vect_loop_p (loop, stmt_info));
    8530                 :             : 
    8531                 :       29425 :       dr_offset = get_dr_vinfo_offset (vinfo, first_dr_info);
    8532                 :       29425 :       stride_base
    8533                 :       29425 :         = fold_build_pointer_plus
    8534                 :             :             (DR_BASE_ADDRESS (first_dr_info->dr),
    8535                 :             :              size_binop (PLUS_EXPR,
    8536                 :             :                          convert_to_ptrofftype (dr_offset),
    8537                 :             :                          convert_to_ptrofftype (DR_INIT (first_dr_info->dr))));
    8538                 :       29425 :       stride_step = fold_convert (sizetype, DR_STEP (first_dr_info->dr));
    8539                 :             : 
    8540                 :             :       /* For a store with loop-invariant (but other than power-of-2)
    8541                 :             :          stride (i.e. not a grouped access) like so:
    8542                 :             : 
    8543                 :             :            for (i = 0; i < n; i += stride)
    8544                 :             :              array[i] = ...;
    8545                 :             : 
    8546                 :             :          we generate a new induction variable and new stores from
    8547                 :             :          the components of the (vectorized) rhs:
    8548                 :             : 
    8549                 :             :            for (j = 0; ; j += VF*stride)
    8550                 :             :              vectemp = ...;
    8551                 :             :              tmp1 = vectemp[0];
    8552                 :             :              array[j] = tmp1;
    8553                 :             :              tmp2 = vectemp[1];
    8554                 :             :              array[j + stride] = tmp2;
    8555                 :             :              ...
    8556                 :             :          */
    8557                 :             : 
    8558                 :       29425 :       unsigned nstores = const_nunits;
    8559                 :       29425 :       unsigned lnel = 1;
    8560                 :       29425 :       tree ltype = elem_type;
    8561                 :       29425 :       tree lvectype = vectype;
    8562                 :       29425 :       HOST_WIDE_INT n = gcd (group_size, const_nunits);
    8563                 :       29425 :       if (n == const_nunits)
    8564                 :             :         {
    8565                 :        2594 :           int mis_align = dr_misalignment (first_dr_info, vectype);
    8566                 :             :           /* With VF > 1 we advance the DR by step, if that is constant
    8567                 :             :              and only aligned when performed VF times, DR alignment
    8568                 :             :              analysis can analyze this as aligned since it assumes
    8569                 :             :              contiguous accesses.  But that is not how we code generate
    8570                 :             :              here, so adjust for this.  */
    8571                 :        2594 :           if (maybe_gt (vf, 1u)
    8572                 :        4194 :               && !multiple_p (DR_STEP_ALIGNMENT (first_dr_info->dr),
    8573                 :        3940 :                               DR_TARGET_ALIGNMENT (first_dr_info)))
    8574                 :         254 :             mis_align = -1;
    8575                 :        2594 :           dr_alignment_support dr_align
    8576                 :        2594 :               = vect_supportable_dr_alignment (vinfo, dr_info, vectype,
    8577                 :             :                                                mis_align);
    8578                 :        2594 :           if (dr_align == dr_aligned
    8579                 :        2594 :               || dr_align == dr_unaligned_supported)
    8580                 :             :             {
    8581                 :        2594 :               nstores = 1;
    8582                 :        2594 :               lnel = const_nunits;
    8583                 :        2594 :               ltype = vectype;
    8584                 :        2594 :               lvectype = vectype;
    8585                 :        2594 :               alignment_support_scheme = dr_align;
    8586                 :        2594 :               misalignment = mis_align;
    8587                 :             :             }
    8588                 :             :         }
    8589                 :       26831 :       else if (n > 1)
    8590                 :             :         {
    8591                 :        2219 :           nstores = const_nunits / n;
    8592                 :        2219 :           lnel = n;
    8593                 :        2219 :           ltype = build_vector_type (elem_type, n);
    8594                 :        2219 :           lvectype = vectype;
    8595                 :        2219 :           int mis_align = dr_misalignment (first_dr_info, ltype);
    8596                 :        2219 :           if (maybe_gt (vf, 1u)
    8597                 :        4438 :               && !multiple_p (DR_STEP_ALIGNMENT (first_dr_info->dr),
    8598                 :        3579 :                               DR_TARGET_ALIGNMENT (first_dr_info)))
    8599                 :         859 :             mis_align = -1;
    8600                 :        2219 :           dr_alignment_support dr_align
    8601                 :        2219 :             = vect_supportable_dr_alignment (vinfo, dr_info, ltype,
    8602                 :             :                                              mis_align);
    8603                 :        2219 :           alignment_support_scheme = dr_align;
    8604                 :        2219 :           misalignment = mis_align;
    8605                 :             : 
    8606                 :             :           /* First check if vec_extract optab doesn't support extraction
    8607                 :             :              of vector elts directly.  */
    8608                 :        2219 :           scalar_mode elmode = SCALAR_TYPE_MODE (elem_type);
    8609                 :        2219 :           machine_mode vmode;
    8610                 :        4438 :           if (!VECTOR_MODE_P (TYPE_MODE (vectype))
    8611                 :        2512 :               || !related_vector_mode (TYPE_MODE (vectype), elmode,
    8612                 :        2219 :                                        n).exists (&vmode)
    8613                 :        1983 :               || (convert_optab_handler (vec_extract_optab,
    8614                 :        1983 :                                          TYPE_MODE (vectype), vmode)
    8615                 :             :                   == CODE_FOR_nothing)
    8616                 :        2219 :               || !(dr_align == dr_aligned
    8617                 :         293 :                    || dr_align == dr_unaligned_supported))
    8618                 :             :             {
    8619                 :             :               /* Try to avoid emitting an extract of vector elements
    8620                 :             :                  by performing the extracts using an integer type of the
    8621                 :             :                  same size, extracting from a vector of those and then
    8622                 :             :                  re-interpreting it as the original vector type if
    8623                 :             :                  supported.  */
    8624                 :        1926 :               unsigned lsize = n * GET_MODE_BITSIZE (elmode);
    8625                 :        1926 :               unsigned int lnunits = const_nunits / n;
    8626                 :             :               /* If we can't construct such a vector fall back to
    8627                 :             :                  element extracts from the original vector type and
    8628                 :             :                  element size stores.  */
    8629                 :        1926 :               if (int_mode_for_size (lsize, 0).exists (&elmode)
    8630                 :        1926 :                   && VECTOR_MODE_P (TYPE_MODE (vectype))
    8631                 :        1926 :                   && related_vector_mode (TYPE_MODE (vectype), elmode,
    8632                 :        1926 :                                           lnunits).exists (&vmode)
    8633                 :        1876 :                   && (convert_optab_handler (vec_extract_optab,
    8634                 :             :                                              vmode, elmode)
    8635                 :             :                       != CODE_FOR_nothing))
    8636                 :             :                 {
    8637                 :        1876 :                   nstores = lnunits;
    8638                 :        1876 :                   lnel = n;
    8639                 :        1876 :                   ltype = build_nonstandard_integer_type (lsize, 1);
    8640                 :        1876 :                   lvectype = build_vector_type (ltype, nstores);
    8641                 :             :                 }
    8642                 :             :               /* Else fall back to vector extraction anyway.
    8643                 :             :                  Fewer stores are more important than avoiding spilling
    8644                 :             :                  of the vector we extract from.  Compared to the
    8645                 :             :                  construction case in vectorizable_load no store-forwarding
    8646                 :             :                  issue exists here for reasonable archs.  But only
    8647                 :             :                  if the store is supported.  */
    8648                 :          50 :                  else if (!(dr_align == dr_aligned
    8649                 :          50 :                             || dr_align == dr_unaligned_supported))
    8650                 :             :                    {
    8651                 :       24612 :                      nstores = const_nunits;
    8652                 :       24612 :                      lnel = 1;
    8653                 :       24612 :                      ltype = elem_type;
    8654                 :       24612 :                      lvectype = vectype;
    8655                 :             :                    }
    8656                 :             :             }
    8657                 :             :         }
    8658                 :       29425 :       unsigned align;
    8659                 :       29425 :       if (alignment_support_scheme == dr_aligned)
    8660                 :        1076 :         align = known_alignment (DR_TARGET_ALIGNMENT (first_dr_info));
    8661                 :             :       else
    8662                 :       28349 :         align = dr_alignment (vect_dr_behavior (vinfo, first_dr_info));
    8663                 :             :       /* Alignment is at most the access size if we do multiple stores.  */
    8664                 :       29425 :       if (nstores > 1)
    8665                 :       26831 :         align = MIN (tree_to_uhwi (TYPE_SIZE_UNIT (ltype)), align);
    8666                 :       29425 :       ltype = build_aligned_type (ltype, align * BITS_PER_UNIT);
    8667                 :       29425 :       int ncopies = SLP_TREE_NUMBER_OF_VEC_STMTS (slp_node);
    8668                 :             : 
    8669                 :       29425 :       if (!costing_p)
    8670                 :             :         {
    8671                 :        3223 :           ivstep = stride_step;
    8672                 :        3223 :           ivstep = fold_build2 (MULT_EXPR, TREE_TYPE (ivstep), ivstep,
    8673                 :             :                                 build_int_cst (TREE_TYPE (ivstep), vf));
    8674                 :             : 
    8675                 :        3223 :           standard_iv_increment_position (loop, &incr_gsi, &insert_after);
    8676                 :             : 
    8677                 :        3223 :           stride_base = cse_and_gimplify_to_preheader (loop_vinfo, stride_base);
    8678                 :        3223 :           ivstep = cse_and_gimplify_to_preheader (loop_vinfo, ivstep);
    8679                 :        3223 :           create_iv (stride_base, PLUS_EXPR, ivstep, NULL, loop, &incr_gsi,
    8680                 :             :                      insert_after, &offvar, NULL);
    8681                 :             : 
    8682                 :        3223 :           stride_step = cse_and_gimplify_to_preheader (loop_vinfo, stride_step);
    8683                 :             :         }
    8684                 :             : 
    8685                 :       29425 :       alias_off = build_int_cst (ref_type, 0);
    8686                 :       29425 :       stmt_vec_info next_stmt_info = first_stmt_info;
    8687                 :       29425 :       auto_vec<tree> vec_oprnds;
    8688                 :             :       /* For costing some adjacent vector stores, we'd like to cost with
    8689                 :             :          the total number of them once instead of cost each one by one. */
    8690                 :       29425 :       unsigned int n_adjacent_stores = 0;
    8691                 :       29425 :       running_off = offvar;
    8692                 :       29425 :       if (!costing_p)
    8693                 :        3223 :         vect_get_vec_defs (vinfo, next_stmt_info, slp_node, ncopies, op,
    8694                 :             :                            &vec_oprnds);
    8695                 :       29425 :       unsigned int group_el = 0;
    8696                 :       29425 :       unsigned HOST_WIDE_INT elsz
    8697                 :       29425 :         = tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (vectype)));
    8698                 :       69815 :       for (j = 0; j < ncopies; j++)
    8699                 :             :         {
    8700                 :       40390 :           if (!costing_p)
    8701                 :             :             {
    8702                 :        4924 :               vec_oprnd = vec_oprnds[j];
    8703                 :             :               /* Pun the vector to extract from if necessary.  */
    8704                 :        4924 :               if (lvectype != vectype)
    8705                 :             :                 {
    8706                 :        1190 :                   tree tem = make_ssa_name (lvectype);
    8707                 :        1190 :                   tree cvt = build1 (VIEW_CONVERT_EXPR, lvectype, vec_oprnd);
    8708                 :        1190 :                   gimple *pun = gimple_build_assign (tem, cvt);
    8709                 :        1190 :                   vect_finish_stmt_generation (vinfo, stmt_info, pun, gsi);
    8710                 :        1190 :                   vec_oprnd = tem;
    8711                 :             :                 }
    8712                 :             :             }
    8713                 :      181277 :           for (i = 0; i < nstores; i++)
    8714                 :             :             {
    8715                 :      140887 :               if (costing_p)
    8716                 :             :                 {
    8717                 :      125277 :                   n_adjacent_stores++;
    8718                 :      125277 :                   continue;
    8719                 :             :                 }
    8720                 :       15610 :               tree newref, newoff;
    8721                 :       15610 :               gimple *incr, *assign;
    8722                 :       15610 :               tree size = TYPE_SIZE (ltype);
    8723                 :             :               /* Extract the i'th component.  */
    8724                 :       15610 :               tree pos = fold_build2 (MULT_EXPR, bitsizetype,
    8725                 :             :                                       bitsize_int (i), size);
    8726                 :       15610 :               tree elem = fold_build3 (BIT_FIELD_REF, ltype, vec_oprnd,
    8727                 :             :                                        size, pos);
    8728                 :             : 
    8729                 :       15610 :               elem = force_gimple_operand_gsi (gsi, elem, true, NULL_TREE, true,
    8730                 :             :                                                GSI_SAME_STMT);
    8731                 :             : 
    8732                 :       15610 :               tree this_off = build_int_cst (TREE_TYPE (alias_off),
    8733                 :       15610 :                                              group_el * elsz);
    8734                 :       15610 :               newref = build2 (MEM_REF, ltype, running_off, this_off);
    8735                 :       15610 :               vect_copy_ref_info (newref, DR_REF (first_dr_info->dr));
    8736                 :             : 
    8737                 :             :               /* And store it to *running_off.  */
    8738                 :       15610 :               assign = gimple_build_assign (newref, elem);
    8739                 :       15610 :               vect_finish_stmt_generation (vinfo, stmt_info, assign, gsi);
    8740                 :             : 
    8741                 :       15610 :               group_el += lnel;
    8742                 :       15610 :               if (group_el == group_size)
    8743                 :             :                 {
    8744                 :       14531 :                   newoff = copy_ssa_name (running_off, NULL);
    8745                 :       14531 :                   incr = gimple_build_assign (newoff, POINTER_PLUS_EXPR,
    8746                 :             :                                               running_off, stride_step);
    8747                 :       14531 :                   vect_finish_stmt_generation (vinfo, stmt_info, incr, gsi);
    8748                 :             : 
    8749                 :       14531 :                   running_off = newoff;
    8750                 :       14531 :                   group_el = 0;
    8751                 :             :                 }
    8752                 :             :             }
    8753                 :             :         }
    8754                 :             : 
    8755                 :       29425 :       if (costing_p)
    8756                 :             :         {
    8757                 :       26202 :           if (n_adjacent_stores > 0)
    8758                 :             :             {
    8759                 :             :               /* Take a single lane vector type store as scalar
    8760                 :             :                  store to avoid ICE like 110776.  */
    8761                 :       26202 :               if (VECTOR_TYPE_P (ltype)
    8762                 :       26202 :                   && maybe_ne (TYPE_VECTOR_SUBPARTS (ltype), 1U))
    8763                 :        1397 :                 vect_get_store_cost (vinfo, stmt_info, slp_node,
    8764                 :             :                                      n_adjacent_stores, alignment_support_scheme,
    8765                 :             :                                      misalignment, &inside_cost, cost_vec);
    8766                 :             :               else
    8767                 :       24805 :                 inside_cost
    8768                 :       24805 :                   += record_stmt_cost (cost_vec, n_adjacent_stores,
    8769                 :             :                                        scalar_store, stmt_info, 0, vect_body);
    8770                 :             :               /* Only need vector extracting when there are more
    8771                 :             :                  than one stores.  */
    8772                 :       26202 :               if (nstores > 1)
    8773                 :       24336 :                 inside_cost
    8774                 :       24336 :                   += record_stmt_cost (cost_vec, n_adjacent_stores,
    8775                 :             :                                        vec_to_scalar, slp_node, 0, vect_body);
    8776                 :             :             }
    8777                 :       26202 :           if (dump_enabled_p ())
    8778                 :         795 :             dump_printf_loc (MSG_NOTE, vect_location,
    8779                 :             :                              "vect_model_store_cost: inside_cost = %d, "
    8780                 :             :                              "prologue_cost = %d .\n",
    8781                 :             :                              inside_cost, prologue_cost);
    8782                 :             :         }
    8783                 :             : 
    8784                 :       29425 :       return true;
    8785                 :       29425 :     }
    8786                 :             : 
    8787                 :     1362787 :   gcc_assert (alignment_support_scheme);
    8788                 :     1362787 :   vec_loop_masks *loop_masks
    8789                 :      159522 :     = (loop_vinfo && LOOP_VINFO_FULLY_MASKED_P (loop_vinfo)
    8790                 :     1362787 :        ? &LOOP_VINFO_MASKS (loop_vinfo)
    8791                 :           6 :        : NULL);
    8792                 :           6 :   vec_loop_lens *loop_lens
    8793                 :      159522 :     = (loop_vinfo && LOOP_VINFO_FULLY_WITH_LENGTH_P (loop_vinfo)
    8794                 :             :        ? &LOOP_VINFO_LENS (loop_vinfo)
    8795                 :           0 :        : NULL);
    8796                 :             : 
    8797                 :             :   /* The vect_transform_stmt and vect_analyze_stmt will go here but there
    8798                 :             :      are some difference here.  We cannot enable both the lens and masks
    8799                 :             :      during transform but it is allowed during analysis.
    8800                 :             :      Shouldn't go with length-based approach if fully masked.  */
    8801                 :     1362787 :   if (cost_vec == NULL)
    8802                 :             :     /* The cost_vec is NULL during transfrom.  */
    8803                 :      534654 :     gcc_assert ((!loop_lens || !loop_masks));
    8804                 :             : 
    8805                 :             :   /* Targets with store-lane instructions must not require explicit
    8806                 :             :      realignment.  vect_supportable_dr_alignment always returns either
    8807                 :             :      dr_aligned or dr_unaligned_supported for masked operations.  */
    8808                 :     1362787 :   gcc_assert ((memory_access_type != VMAT_LOAD_STORE_LANES
    8809                 :             :                && !mask
    8810                 :             :                && !loop_masks)
    8811                 :             :               || alignment_support_scheme == dr_aligned
    8812                 :             :               || alignment_support_scheme == dr_unaligned_supported);
    8813                 :             : 
    8814                 :     1362787 :   tree offset = NULL_TREE;
    8815                 :     1362787 :   if (!known_eq (poffset, 0))
    8816                 :        4577 :     offset = size_int (poffset);
    8817                 :             : 
    8818                 :     1362787 :   tree bump;
    8819                 :     1362787 :   tree vec_offset = NULL_TREE;
    8820                 :     1362787 :   if (STMT_VINFO_GATHER_SCATTER_P (stmt_info))
    8821                 :             :     {
    8822                 :        2629 :       aggr_type = NULL_TREE;
    8823                 :        2629 :       bump = NULL_TREE;
    8824                 :             :     }
    8825                 :     1360158 :   else if (memory_access_type == VMAT_GATHER_SCATTER)
    8826                 :             :     {
    8827                 :           0 :       aggr_type = elem_type;
    8828                 :           0 :       if (!costing_p)
    8829                 :           0 :         vect_get_strided_load_store_ops (stmt_info, loop_vinfo, gsi, &gs_info,
    8830                 :             :                                          &bump, &vec_offset, loop_lens);
    8831                 :             :     }
    8832                 :             :   else
    8833                 :             :     {
    8834                 :     1360158 :       if (memory_access_type == VMAT_LOAD_STORE_LANES)
    8835                 :           0 :         aggr_type = build_array_type_nelts (elem_type, group_size * nunits);
    8836                 :             :       else
    8837                 :             :         aggr_type = vectype;
    8838                 :     1360158 :       if (!costing_p)
    8839                 :      534180 :         bump = vect_get_data_ptr_increment (vinfo, gsi, dr_info, aggr_type,
    8840                 :             :                                             memory_access_type, loop_lens);
    8841                 :             :     }
    8842                 :             : 
    8843                 :     1362787 :   if (mask && !costing_p)
    8844                 :         481 :     LOOP_VINFO_HAS_MASK_STORE (loop_vinfo) = true;
    8845                 :             : 
    8846                 :             :   /* In case the vectorization factor (VF) is bigger than the number
    8847                 :             :      of elements that we can fit in a vectype (nunits), we have to generate
    8848                 :             :      more than one vector stmt - i.e - we need to "unroll" the
    8849                 :             :      vector stmt by a factor VF/nunits.  */
    8850                 :             : 
    8851                 :             :   /* In case of interleaving (non-unit grouped access):
    8852                 :             : 
    8853                 :             :         S1:  &base + 2 = x2
    8854                 :             :         S2:  &base = x0
    8855                 :             :         S3:  &base + 1 = x1
    8856                 :             :         S4:  &base + 3 = x3
    8857                 :             : 
    8858                 :             :      We create vectorized stores starting from base address (the access of the
    8859                 :             :      first stmt in the chain (S2 in the above example), when the last store stmt
    8860                 :             :      of the chain (S4) is reached:
    8861                 :             : 
    8862                 :             :         VS1: &base = vx2
    8863                 :             :         VS2: &base + vec_size*1 = vx0
    8864                 :             :         VS3: &base + vec_size*2 = vx1
    8865                 :             :         VS4: &base + vec_size*3 = vx3
    8866                 :             : 
    8867                 :             :      Then permutation statements are generated:
    8868                 :             : 
    8869                 :             :         VS5: vx5 = VEC_PERM_EXPR < vx0, vx3, {0, 8, 1, 9, 2, 10, 3, 11} >
    8870                 :             :         VS6: vx6 = VEC_PERM_EXPR < vx0, vx3, {4, 12, 5, 13, 6, 14, 7, 15} >
    8871                 :             :         ...
    8872                 :             : 
    8873                 :             :      And they are put in STMT_VINFO_VEC_STMT of the corresponding scalar stmts
    8874                 :             :      (the order of the data-refs in the output of vect_permute_store_chain
    8875                 :             :      corresponds to the order of scalar stmts in the interleaving chain - see
    8876                 :             :      the documentation of vect_permute_store_chain()).
    8877                 :             : 
    8878                 :             :      In case of both multiple types and interleaving, above vector stores and
    8879                 :             :      permutation stmts are created for every copy.  The result vector stmts are
    8880                 :             :      put in STMT_VINFO_VEC_STMT for the first copy and in the corresponding
    8881                 :             :      STMT_VINFO_RELATED_STMT for the next copies.
    8882                 :             :   */
    8883                 :             : 
    8884                 :     1362787 :   auto_vec<tree> dr_chain (group_size);
    8885                 :     1362787 :   auto_vec<tree> vec_masks;
    8886                 :     1362787 :   tree vec_mask = NULL;
    8887                 :     1362787 :   auto_delete_vec<auto_vec<tree>> gvec_oprnds (group_size);
    8888                 :     6161568 :   for (i = 0; i < group_size; i++)
    8889                 :     3435994 :     gvec_oprnds.quick_push (new auto_vec<tree> ());
    8890                 :             : 
    8891                 :     1362787 :   if (memory_access_type == VMAT_LOAD_STORE_LANES)
    8892                 :             :     {
    8893                 :           0 :       if (costing_p)
    8894                 :             :         /* Update all incoming store operand nodes, the general handling
    8895                 :             :            above only handles the mask and the first store operand node.  */
    8896                 :           0 :         for (slp_tree child : SLP_TREE_CHILDREN (slp_node))
    8897                 :           0 :           if (child != mask_node
    8898                 :           0 :               && !vect_maybe_update_slp_op_vectype (child, vectype))
    8899                 :             :             {
    8900                 :           0 :               if (dump_enabled_p ())
    8901                 :           0 :                 dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    8902                 :             :                                  "incompatible vector types for invariants\n");
    8903                 :           0 :               return false;
    8904                 :             :             }
    8905                 :           0 :       unsigned inside_cost = 0, prologue_cost = 0;
    8906                 :             :       /* For costing some adjacent vector stores, we'd like to cost with
    8907                 :             :          the total number of them once instead of cost each one by one. */
    8908                 :           0 :       unsigned int n_adjacent_stores = 0;
    8909                 :           0 :       int ncopies = SLP_TREE_NUMBER_OF_VEC_STMTS (slp_node) / group_size;
    8910                 :           0 :       for (j = 0; j < ncopies; j++)
    8911                 :             :         {
    8912                 :           0 :           if (j == 0)
    8913                 :             :             {
    8914                 :           0 :               if (!costing_p)
    8915                 :             :                 {
    8916                 :           0 :                   if (mask)
    8917                 :             :                     {
    8918                 :           0 :                       vect_get_slp_defs (mask_node, &vec_masks);
    8919                 :           0 :                       vec_mask = vec_masks[0];
    8920                 :             :                     }
    8921                 :           0 :                   dataref_ptr
    8922                 :           0 :                     = vect_create_data_ref_ptr (vinfo, first_stmt_info,
    8923                 :             :                                                 aggr_type, NULL, offset, &dummy,
    8924                 :             :                                                 gsi, &ptr_incr, false, bump);
    8925                 :             :                 }
    8926                 :             :             }
    8927                 :           0 :           else if (!costing_p)
    8928                 :             :             {
    8929                 :           0 :               gcc_assert (!LOOP_VINFO_USING_SELECT_VL_P (loop_vinfo));
    8930                 :           0 :               if (mask)
    8931                 :           0 :                 vec_mask = vec_masks[j];
    8932                 :           0 :               dataref_ptr = bump_vector_ptr (vinfo, dataref_ptr, ptr_incr, gsi,
    8933                 :             :                                              stmt_info, bump);
    8934                 :             :             }
    8935                 :             : 
    8936                 :           0 :           if (costing_p)
    8937                 :             :             {
    8938                 :           0 :               n_adjacent_stores += group_size;
    8939                 :           0 :               continue;
    8940                 :             :             }
    8941                 :             : 
    8942                 :             :           /* Get an array into which we can store the individual vectors.  */
    8943                 :           0 :           tree vec_array = create_vector_array (vectype, group_size);
    8944                 :             : 
    8945                 :             :           /* Invalidate the current contents of VEC_ARRAY.  This should
    8946                 :             :              become an RTL clobber too, which prevents the vector registers
    8947                 :             :              from being upward-exposed.  */
    8948                 :           0 :           vect_clobber_variable (vinfo, stmt_info, gsi, vec_array);
    8949                 :             : 
    8950                 :             :           /* Store the individual vectors into the array.  */
    8951                 :           0 :           for (i = 0; i < group_size; i++)
    8952                 :             :             {
    8953                 :           0 :               slp_tree child;
    8954                 :           0 :               if (i == 0 || !mask_node)
    8955                 :           0 :                 child = SLP_TREE_CHILDREN (slp_node)[i];
    8956                 :             :               else
    8957                 :           0 :                 child = SLP_TREE_CHILDREN (slp_node)[i + 1];
    8958                 :           0 :               vec_oprnd = SLP_TREE_VEC_DEFS (child)[j];
    8959                 :           0 :               write_vector_array (vinfo, stmt_info, gsi, vec_oprnd, vec_array,
    8960                 :             :                                   i);
    8961                 :             :             }
    8962                 :             : 
    8963                 :           0 :           tree final_mask = NULL;
    8964                 :           0 :           tree final_len = NULL;
    8965                 :           0 :           tree bias = NULL;
    8966                 :           0 :           if (loop_masks)
    8967                 :           0 :             final_mask = vect_get_loop_mask (loop_vinfo, gsi, loop_masks,
    8968                 :             :                                              ncopies, vectype, j);
    8969                 :           0 :           if (vec_mask)
    8970                 :           0 :             final_mask = prepare_vec_mask (loop_vinfo, mask_vectype, final_mask,
    8971                 :             :                                            vec_mask, gsi);
    8972                 :             : 
    8973                 :           0 :           if (lanes_ifn == IFN_MASK_LEN_STORE_LANES)
    8974                 :             :             {
    8975                 :           0 :               if (loop_lens)
    8976                 :           0 :                 final_len = vect_get_loop_len (loop_vinfo, gsi, loop_lens,
    8977                 :             :                                                ncopies, vectype, j, 1);
    8978                 :             :               else
    8979                 :           0 :                 final_len = size_int (TYPE_VECTOR_SUBPARTS (vectype));
    8980                 :           0 :               signed char biasval
    8981                 :           0 :                 = LOOP_VINFO_PARTIAL_LOAD_STORE_BIAS (loop_vinfo);
    8982                 :           0 :               bias = build_int_cst (intQI_type_node, biasval);
    8983                 :           0 :               if (!final_mask)
    8984                 :             :                 {
    8985                 :           0 :                   mask_vectype = truth_type_for (vectype);
    8986                 :           0 :                   final_mask = build_minus_one_cst (mask_vectype);
    8987                 :             :                 }
    8988                 :             :             }
    8989                 :             : 
    8990                 :           0 :           gcall *call;
    8991                 :           0 :           if (final_len && final_mask)
    8992                 :             :             {
    8993                 :             :               /* Emit:
    8994                 :             :                    MASK_LEN_STORE_LANES (DATAREF_PTR, ALIAS_PTR, VEC_MASK,
    8995                 :             :                                          LEN, BIAS, VEC_ARRAY).  */
    8996                 :           0 :               unsigned int align = TYPE_ALIGN (TREE_TYPE (vectype));
    8997                 :           0 :               tree alias_ptr = build_int_cst (ref_type, align);
    8998                 :           0 :               call = gimple_build_call_internal (IFN_MASK_LEN_STORE_LANES, 6,
    8999                 :             :                                                  dataref_ptr, alias_ptr,
    9000                 :             :                                                  final_mask, final_len, bias,
    9001                 :             :                                                  vec_array);
    9002                 :             :             }
    9003                 :           0 :           else if (final_mask)
    9004                 :             :             {
    9005                 :             :               /* Emit:
    9006                 :             :                    MASK_STORE_LANES (DATAREF_PTR, ALIAS_PTR, VEC_MASK,
    9007                 :             :                                      VEC_ARRAY).  */
    9008                 :           0 :               unsigned int align = TYPE_ALIGN (TREE_TYPE (vectype));
    9009                 :           0 :               tree alias_ptr = build_int_cst (ref_type, align);
    9010                 :           0 :               call = gimple_build_call_internal (IFN_MASK_STORE_LANES, 4,
    9011                 :             :                                                  dataref_ptr, alias_ptr,
    9012                 :             :                                                  final_mask, vec_array);
    9013                 :             :             }
    9014                 :             :           else
    9015                 :             :             {
    9016                 :             :               /* Emit:
    9017                 :             :                    MEM_REF[...all elements...] = STORE_LANES (VEC_ARRAY).  */
    9018                 :           0 :               data_ref = create_array_ref (aggr_type, dataref_ptr, ref_type);
    9019                 :           0 :               call = gimple_build_call_internal (IFN_STORE_LANES, 1, vec_array);
    9020                 :           0 :               gimple_call_set_lhs (call, data_ref);
    9021                 :             :             }
    9022                 :           0 :           gimple_call_set_nothrow (call, true);
    9023                 :           0 :           vect_finish_stmt_generation (vinfo, stmt_info, call, gsi);
    9024                 :             : 
    9025                 :             :           /* Record that VEC_ARRAY is now dead.  */
    9026                 :           0 :           vect_clobber_variable (vinfo, stmt_info, gsi, vec_array);
    9027                 :             :         }
    9028                 :             : 
    9029                 :           0 :       if (costing_p)
    9030                 :             :         {
    9031                 :           0 :           if (n_adjacent_stores > 0)
    9032                 :           0 :             vect_get_store_cost (vinfo, stmt_info, slp_node, n_adjacent_stores,
    9033                 :             :                                  alignment_support_scheme, misalignment,
    9034                 :             :                                  &inside_cost, cost_vec);
    9035                 :           0 :           if (dump_enabled_p ())
    9036                 :           0 :             dump_printf_loc (MSG_NOTE, vect_location,
    9037                 :             :                              "vect_model_store_cost: inside_cost = %d, "
    9038                 :             :                              "prologue_cost = %d .\n",
    9039                 :             :                              inside_cost, prologue_cost);
    9040                 :             :         }
    9041                 :             : 
    9042                 :           0 :       return true;
    9043                 :             :     }
    9044                 :             : 
    9045                 :     1362787 :   if (memory_access_type == VMAT_GATHER_SCATTER)
    9046                 :             :     {
    9047                 :        2629 :       gcc_assert (!grouped_store);
    9048                 :        2629 :       auto_vec<tree> vec_offsets;
    9049                 :        2629 :       unsigned int inside_cost = 0, prologue_cost = 0;
    9050                 :        2629 :       int num_stmts = vec_num;
    9051                 :        5731 :       for (j = 0; j < num_stmts; j++)
    9052                 :             :         {
    9053                 :        3102 :           gimple *new_stmt;
    9054                 :        3102 :           if (j == 0)
    9055                 :             :             {
    9056                 :        2629 :               if (costing_p && vls_type == VLS_STORE_INVARIANT)
    9057                 :         239 :                 prologue_cost += record_stmt_cost (cost_vec, 1, scalar_to_vec,
    9058                 :             :                                                    slp_node, 0, vect_prologue);
    9059                 :             :               else if (!costing_p)
    9060                 :             :                 {
    9061                 :             :                   /* Since the store is not grouped, DR_GROUP_SIZE is 1, and
    9062                 :             :                      DR_CHAIN is of size 1.  */
    9063                 :         474 :                   gcc_assert (group_size == 1);
    9064                 :         474 :                   vect_get_slp_defs (op_node, gvec_oprnds[0]);
    9065                 :         474 :                   if (mask)
    9066                 :          70 :                     vect_get_slp_defs (mask_node, &vec_masks);
    9067                 :             : 
    9068                 :         474 :                   if (STMT_VINFO_GATHER_SCATTER_P (stmt_info))
    9069                 :         474 :                     vect_get_gather_scatter_ops (loop_vinfo, loop, stmt_info,
    9070                 :             :                                                  slp_node, &gs_info,
    9071                 :             :                                                  &dataref_ptr, &vec_offsets);
    9072                 :             :                   else
    9073                 :           0 :                     dataref_ptr
    9074                 :           0 :                       = vect_create_data_ref_ptr (vinfo, first_stmt_info,
    9075                 :             :                                                   aggr_type, NULL, offset,
    9076                 :             :                                                   &dummy, gsi, &ptr_incr, false,
    9077                 :             :                                                   bump);
    9078                 :             :                 }
    9079                 :             :             }
    9080                 :         473 :           else if (!costing_p)
    9081                 :             :             {
    9082                 :          38 :               gcc_assert (!LOOP_VINFO_USING_SELECT_VL_P (loop_vinfo));
    9083                 :          38 :               if (!STMT_VINFO_GATHER_SCATTER_P (stmt_info))
    9084                 :           0 :                 dataref_ptr = bump_vector_ptr (vinfo, dataref_ptr, ptr_incr,
    9085                 :             :                                                gsi, stmt_info, bump);
    9086                 :             :             }
    9087                 :             : 
    9088                 :        3853 :           new_stmt = NULL;
    9089                 :         751 :           if (!costing_p)
    9090                 :             :             {
    9091                 :         512 :               vec_oprnd = (*gvec_oprnds[0])[j];
    9092                 :         512 :               if (mask)
    9093                 :          90 :                 vec_mask = vec_masks[j];
    9094                 :             :               /* We should have catched mismatched types earlier.  */
    9095                 :         512 :               gcc_assert (useless_type_conversion_p (vectype,
    9096                 :             :                                                      TREE_TYPE (vec_oprnd)));
    9097                 :             :             }
    9098                 :         512 :           unsigned HOST_WIDE_INT align;
    9099                 :         512 :           tree final_mask = NULL_TREE;
    9100                 :        3614 :           tree final_len = NULL_TREE;
    9101                 :        3614 :           tree bias = NULL_TREE;
    9102                 :         512 :           if (!costing_p)
    9103                 :             :             {
    9104                 :         512 :               if (loop_masks)
    9105                 :           0 :                 final_mask = vect_get_loop_mask (loop_vinfo, gsi,
    9106                 :             :                                                  loop_masks, num_stmts,
    9107                 :             :                                                  vectype, j);
    9108                 :         512 :               if (vec_mask)
    9109                 :          90 :                 final_mask = prepare_vec_mask (loop_vinfo, mask_vectype,
    9110                 :             :                                                final_mask, vec_mask, gsi);
    9111                 :             :             }
    9112                 :             : 
    9113                 :        3102 :           if (gs_info.ifn != IFN_LAST)
    9114                 :             :             {
    9115                 :           0 :               if (costing_p)
    9116                 :             :                 {
    9117                 :           0 :                   unsigned int cnunits = vect_nunits_for_cost (vectype);
    9118                 :           0 :                   inside_cost
    9119                 :           0 :                     += record_stmt_cost (cost_vec, cnunits, scalar_store,
    9120                 :             :                                          slp_node, 0, vect_body);
    9121                 :           0 :                   continue;
    9122                 :           0 :                 }
    9123                 :             : 
    9124                 :           0 :               if (STMT_VINFO_GATHER_SCATTER_P (stmt_info))
    9125                 :           0 :                 vec_offset = vec_offsets[j];
    9126                 :             : 
    9127                 :           0 :               tree scale = size_int (gs_info.scale);
    9128                 :             : 
    9129                 :           0 :               if (gs_info.ifn == IFN_MASK_LEN_SCATTER_STORE)
    9130                 :             :                 {
    9131                 :           0 :                   if (loop_lens)
    9132                 :           0 :                     final_len = vect_get_loop_len (loop_vinfo, gsi,
    9133                 :             :                                                    loop_lens, num_stmts,
    9134                 :             :                                                    vectype, j, 1);
    9135                 :             :                   else
    9136                 :           0 :                     final_len = size_int (TYPE_VECTOR_SUBPARTS (vectype));
    9137                 :             : 
    9138                 :           0 :                   signed char biasval
    9139                 :           0 :                     = LOOP_VINFO_PARTIAL_LOAD_STORE_BIAS (loop_vinfo);
    9140                 :           0 :                   bias = build_int_cst (intQI_type_node, biasval);
    9141                 :           0 :                   if (!final_mask)
    9142                 :             :                     {
    9143                 :           0 :                       mask_vectype = truth_type_for (vectype);
    9144                 :           0 :                       final_mask = build_minus_one_cst (mask_vectype);
    9145                 :             :                     }
    9146                 :             :                 }
    9147                 :             : 
    9148                 :           0 :               gcall *call;
    9149                 :           0 :               if (final_len && final_mask)
    9150                 :             :                 {
    9151                 :           0 :                   if (VECTOR_TYPE_P (TREE_TYPE (vec_offset)))
    9152                 :           0 :                     call = gimple_build_call_internal (
    9153                 :             :                             IFN_MASK_LEN_SCATTER_STORE, 7, dataref_ptr,
    9154                 :             :                             vec_offset, scale, vec_oprnd, final_mask, final_len,
    9155                 :             :                             bias);
    9156                 :             :                   else
    9157                 :             :                     /* Non-vector offset indicates that prefer to take
    9158                 :             :                        MASK_LEN_STRIDED_STORE instead of the
    9159                 :             :                        IFN_MASK_SCATTER_STORE with direct stride arg.  */
    9160                 :           0 :                     call = gimple_build_call_internal (
    9161                 :             :                             IFN_MASK_LEN_STRIDED_STORE, 6, dataref_ptr,
    9162                 :             :                             vec_offset, vec_oprnd, final_mask, final_len, bias);
    9163                 :             :                 }
    9164                 :           0 :               else if (final_mask)
    9165                 :           0 :                 call = gimple_build_call_internal
    9166                 :           0 :                              (IFN_MASK_SCATTER_STORE, 5, dataref_ptr,
    9167                 :             :                               vec_offset, scale, vec_oprnd, final_mask);
    9168                 :             :               else
    9169                 :           0 :                 call = gimple_build_call_internal (IFN_SCATTER_STORE, 4,
    9170                 :             :                                                    dataref_ptr, vec_offset,
    9171                 :             :                                                    scale, vec_oprnd);
    9172                 :           0 :               gimple_call_set_nothrow (call, true);
    9173                 :           0 :               vect_finish_stmt_generation (vinfo, stmt_info, call, gsi);
    9174                 :           0 :               new_stmt = call;
    9175                 :             :             }
    9176                 :        3102 :            else if (gs_info.decl)
    9177                 :             :             {
    9178                 :             :               /* The builtin decls path for scatter is legacy, x86 only.  */
    9179                 :         394 :               gcc_assert (nunits.is_constant ()
    9180                 :             :                           && (!final_mask
    9181                 :             :                               || SCALAR_INT_MODE_P
    9182                 :             :                                    (TYPE_MODE (TREE_TYPE (final_mask)))));
    9183                 :         394 :               if (costing_p)
    9184                 :             :                 {
    9185                 :         255 :                   unsigned int cnunits = vect_nunits_for_cost (vectype);
    9186                 :         255 :                   inside_cost
    9187                 :         255 :                     += record_stmt_cost (cost_vec, cnunits, scalar_store,
    9188                 :             :                                          slp_node, 0, vect_body);
    9189                 :         255 :                   continue;
    9190                 :         255 :                 }
    9191                 :             : 
    9192                 :         139 :                 poly_uint64 offset_nunits
    9193                 :         139 :                   = TYPE_VECTOR_SUBPARTS (gs_info.offset_vectype);
    9194                 :         139 :                 if (known_eq (nunits, offset_nunits))
    9195                 :             :                   {
    9196                 :          63 :                     new_stmt = vect_build_one_scatter_store_call
    9197                 :         189 :                                    (vinfo, stmt_info, gsi, &gs_info,
    9198                 :          63 :                                     dataref_ptr, vec_offsets[j],
    9199                 :             :                                     vec_oprnd, final_mask);
    9200                 :          63 :                     vect_finish_stmt_generation (vinfo, stmt_info,
    9201                 :             :                                                  new_stmt, gsi);
    9202                 :             :                   }
    9203                 :          76 :                 else if (known_eq (nunits, offset_nunits * 2))
    9204                 :             :                   {
    9205                 :             :                     /* We have a offset vector with half the number of
    9206                 :             :                        lanes but the builtins will store full vectype
    9207                 :             :                        data from the lower lanes.  */
    9208                 :          30 :                     new_stmt = vect_build_one_scatter_store_call
    9209                 :          90 :                                    (vinfo, stmt_info, gsi, &gs_info,
    9210                 :          30 :                                     dataref_ptr, vec_offsets[2 * j],
    9211                 :             :                                     vec_oprnd, final_mask);
    9212                 :          30 :                     vect_finish_stmt_generation (vinfo, stmt_info,
    9213                 :             :                                                    new_stmt, gsi);
    9214                 :          30 :                     int count = nunits.to_constant ();
    9215                 :          30 :                     vec_perm_builder sel (count, count, 1);
    9216                 :          30 :                     sel.quick_grow (count);
    9217                 :         382 :                     for (int i = 0; i < count; ++i)
    9218                 :         352 :                       sel[i] = i | (count / 2);
    9219                 :          30 :                     vec_perm_indices indices (sel, 2, count);
    9220                 :          30 :                     tree perm_mask
    9221                 :          30 :                       = vect_gen_perm_mask_checked (vectype, indices);
    9222                 :          30 :                     new_stmt = gimple_build_assign (NULL_TREE, VEC_PERM_EXPR,
    9223                 :             :                                                     vec_oprnd, vec_oprnd,
    9224                 :             :                                                     perm_mask);
    9225                 :          30 :                     vec_oprnd = make_ssa_name (vectype);
    9226                 :          30 :                     gimple_set_lhs (new_stmt, vec_oprnd);
    9227                 :          30 :                     vect_finish_stmt_generation (vinfo, stmt_info,
    9228                 :             :                                                  new_stmt, gsi);
    9229                 :          30 :                     if (final_mask)
    9230                 :             :                       {
    9231                 :          20 :                         new_stmt = gimple_build_assign (NULL_TREE,
    9232                 :             :                                                         VEC_UNPACK_HI_EXPR,
    9233                 :             :                                                         final_mask);
    9234                 :          20 :                         final_mask = make_ssa_name
    9235                 :          20 :                                       (truth_type_for (gs_info.offset_vectype));
    9236                 :          20 :                         gimple_set_lhs (new_stmt, final_mask);
    9237                 :          20 :                         vect_finish_stmt_generation (vinfo, stmt_info,
    9238                 :             :                                                      new_stmt, gsi);
    9239                 :             :                         }
    9240                 :             : 
    9241                 :          30 :                     new_stmt = vect_build_one_scatter_store_call
    9242                 :          60 :                                   (vinfo, stmt_info, gsi, &gs_info,
    9243                 :          30 :                                    dataref_ptr, vec_offsets[2 * j + 1],
    9244                 :             :                                    vec_oprnd, final_mask);
    9245                 :          30 :                     vect_finish_stmt_generation (vinfo, stmt_info,
    9246                 :             :                                                  new_stmt, gsi);
    9247                 :          30 :                   }
    9248                 :          46 :                 else if (known_eq (nunits * 2, offset_nunits))
    9249                 :             :                   {
    9250                 :             :                     /* We have a offset vector with double the number of
    9251                 :             :                        lanes.  Select the low/high part accordingly.  */
    9252                 :          46 :                     vec_offset = vec_offsets[j / 2];
    9253                 :          46 :                     if (j & 1)
    9254                 :             :                       {
    9255                 :          23 :                         int count = offset_nunits.to_constant ();
    9256                 :          23 :                         vec_perm_builder sel (count, count, 1);
    9257                 :          23 :                         sel.quick_grow (count);
    9258                 :         263 :                         for (int i = 0; i < count; ++i)
    9259                 :         240 :                           sel[i] = i | (count / 2);
    9260                 :          23 :                         vec_perm_indices indices (sel, 2, count);
    9261                 :          23 :                         tree perm_mask = vect_gen_perm_mask_checked
    9262                 :          23 :                                            (TREE_TYPE (vec_offset), indices);
    9263                 :          23 :                         new_stmt = gimple_build_assign (NULL_TREE,
    9264                 :             :                                                         VEC_PERM_EXPR,
    9265                 :             :                                                         vec_offset,
    9266                 :             :                                                         vec_offset,
    9267                 :             :                                                         perm_mask);
    9268                 :          23 :                         vec_offset = make_ssa_name (TREE_TYPE (vec_offset));
    9269                 :          23 :                         gimple_set_lhs (new_stmt, vec_offset);
    9270                 :          23 :                         vect_finish_stmt_generation (vinfo, stmt_info,
    9271                 :             :                                                      new_stmt, gsi);
    9272                 :          23 :                       }
    9273                 :             : 
    9274                 :          46 :                     new_stmt = vect_build_one_scatter_store_call
    9275                 :          46 :                                    (vinfo, stmt_info, gsi, &gs_info,
    9276                 :             :                                     dataref_ptr, vec_offset,
    9277                 :             :                                     vec_oprnd, final_mask);
    9278                 :          46 :                     vect_finish_stmt_generation (vinfo, stmt_info,
    9279                 :             :                                                  new_stmt, gsi);
    9280                 :             :                   }
    9281                 :             :                 else
    9282                 :           0 :                   gcc_unreachable ();
    9283                 :             :             }
    9284                 :             :           else
    9285                 :             :             {
    9286                 :             :               /* Emulated scatter.  */
    9287                 :        2708 :               gcc_assert (!final_mask);
    9288                 :        2708 :               if (costing_p)
    9289                 :             :                 {
    9290                 :        2335 :                   unsigned int cnunits = vect_nunits_for_cost (vectype);
    9291                 :             :                   /* For emulated scatter N offset vector element extracts
    9292                 :             :                      (we assume the scalar scaling and ptr + offset add is
    9293                 :             :                      consumed by the load).  */
    9294                 :        2335 :                   inside_cost
    9295                 :        2335 :                     += record_stmt_cost (cost_vec, cnunits, vec_to_scalar,
    9296                 :             :                                          slp_node, 0, vect_body);
    9297                 :             :                   /* N scalar stores plus extracting the elements.  */
    9298                 :        2335 :                   inside_cost
    9299                 :        2335 :                     += record_stmt_cost (cost_vec, cnunits, vec_to_scalar,
    9300                 :             :                                          slp_node, 0, vect_body);
    9301                 :        2335 :                   inside_cost
    9302                 :        2335 :                     += record_stmt_cost (cost_vec, cnunits, scalar_store,
    9303                 :             :                                          slp_node, 0, vect_body);
    9304                 :        2335 :                   continue;
    9305                 :        2335 :                 }
    9306                 :             : 
    9307                 :         373 :               unsigned HOST_WIDE_INT const_nunits = nunits.to_constant ();
    9308                 :         373 :               unsigned HOST_WIDE_INT const_offset_nunits
    9309                 :         373 :                 = TYPE_VECTOR_SUBPARTS (gs_info.offset_vectype).to_constant ();
    9310                 :         373 :               vec<constructor_elt, va_gc> *ctor_elts;
    9311                 :         373 :               vec_alloc (ctor_elts, const_nunits);
    9312                 :         373 :               gimple_seq stmts = NULL;
    9313                 :         373 :               tree elt_type = TREE_TYPE (vectype);
    9314                 :         373 :               unsigned HOST_WIDE_INT elt_size
    9315                 :         373 :                 = tree_to_uhwi (TYPE_SIZE (elt_type));
    9316                 :             :               /* We support offset vectors with more elements
    9317                 :             :                  than the data vector for now.  */
    9318                 :         373 :               unsigned HOST_WIDE_INT factor
    9319                 :             :                 = const_offset_nunits / const_nunits;
    9320                 :         373 :               vec_offset = vec_offsets[j / factor];
    9321                 :         373 :               unsigned elt_offset
    9322                 :         373 :                 = (j % factor) * const_nunits;
    9323                 :         373 :               tree idx_type = TREE_TYPE (TREE_TYPE (vec_offset));
    9324                 :         373 :               tree scale = size_int (gs_info.scale);
    9325                 :         373 :               align = get_object_alignment (DR_REF (first_dr_info->dr));
    9326                 :         373 :               tree ltype = build_aligned_type (TREE_TYPE (vectype), align);
    9327                 :        1519 :               for (unsigned k = 0; k < const_nunits; ++k)
    9328                 :             :                 {
    9329                 :             :                   /* Compute the offsetted pointer.  */
    9330                 :        1146 :                   tree boff = size_binop (MULT_EXPR, TYPE_SIZE (idx_type),
    9331                 :             :                                           bitsize_int (k + elt_offset));
    9332                 :        1146 :                   tree idx
    9333                 :        2292 :                     = gimple_build (&stmts, BIT_FIELD_REF, idx_type,
    9334                 :        1146 :                                     vec_offset, TYPE_SIZE (idx_type), boff);
    9335                 :        1146 :                   idx = gimple_convert (&stmts, sizetype, idx);
    9336                 :        1146 :                   idx = gimple_build (&stmts, MULT_EXPR, sizetype,
    9337                 :             :                                       idx, scale);
    9338                 :        1146 :                   tree ptr
    9339                 :        1146 :                     = gimple_build (&stmts, PLUS_EXPR,
    9340                 :        1146 :                                     TREE_TYPE (dataref_ptr),
    9341                 :             :                                     dataref_ptr, idx);
    9342                 :        1146 :                   ptr = gimple_convert (&stmts, ptr_type_node, ptr);
    9343                 :             :                   /* Extract the element to be stored.  */
    9344                 :        1146 :                   tree elt
    9345                 :        2292 :                     = gimple_build (&stmts, BIT_FIELD_REF,
    9346                 :        1146 :                                     TREE_TYPE (vectype),
    9347                 :        1146 :                                     vec_oprnd, TYPE_SIZE (elt_type),
    9348                 :        1146 :                                     bitsize_int (k * elt_size));
    9349                 :        1146 :                   gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
    9350                 :        1146 :                   stmts = NULL;
    9351                 :        1146 :                   tree ref
    9352                 :        1146 :                     = build2 (MEM_REF, ltype, ptr,
    9353                 :             :                               build_int_cst (ref_type, 0));
    9354                 :        1146 :                   new_stmt = gimple_build_assign (ref, elt);
    9355                 :        1146 :                   vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    9356                 :             :                 }
    9357                 :             : 
    9358                 :         373 :               slp_node->push_vec_def (new_stmt);
    9359                 :             :             }
    9360                 :             :         }
    9361                 :             : 
    9362                 :        2629 :       if (costing_p && dump_enabled_p ())
    9363                 :          97 :         dump_printf_loc (MSG_NOTE, vect_location,
    9364                 :             :                          "vect_model_store_cost: inside_cost = %d, "
    9365                 :             :                          "prologue_cost = %d .\n",
    9366                 :             :                          inside_cost, prologue_cost);
    9367                 :             : 
    9368                 :        2629 :       return true;
    9369                 :        2629 :     }
    9370                 :             : 
    9371                 :     1360158 :   gcc_assert (memory_access_type == VMAT_CONTIGUOUS
    9372                 :             :               || memory_access_type == VMAT_CONTIGUOUS_DOWN
    9373                 :             :               || memory_access_type == VMAT_CONTIGUOUS_PERMUTE
    9374                 :             :               || memory_access_type == VMAT_CONTIGUOUS_REVERSE);
    9375                 :             : 
    9376                 :     1360158 :   unsigned inside_cost = 0, prologue_cost = 0;
    9377                 :             :   /* For costing some adjacent vector stores, we'd like to cost with
    9378                 :             :      the total number of them once instead of cost each one by one. */
    9379                 :     1360158 :   unsigned int n_adjacent_stores = 0;
    9380                 :     1360158 :   auto_vec<tree> result_chain (group_size);
    9381                 :     1360158 :   auto_vec<tree, 1> vec_oprnds;
    9382                 :     1360158 :   gimple *new_stmt;
    9383                 :     1360158 :   if (!costing_p)
    9384                 :             :     {
    9385                 :             :       /* Get vectorized arguments for SLP_NODE.  */
    9386                 :      534180 :       vect_get_vec_defs (vinfo, stmt_info, slp_node, 1, op,
    9387                 :             :                          &vec_oprnds, mask, &vec_masks);
    9388                 :      534180 :       vec_oprnd = vec_oprnds[0];
    9389                 :      534180 :       if (mask)
    9390                 :         411 :         vec_mask = vec_masks[0];
    9391                 :             :     }
    9392                 :             :   else
    9393                 :             :     {
    9394                 :             :       /* For interleaved stores we collect vectorized defs for all the
    9395                 :             :          stores in the group in DR_CHAIN. DR_CHAIN is then used as an
    9396                 :             :          input to vect_permute_store_chain().
    9397                 :             : 
    9398                 :             :          If the store is not grouped, DR_GROUP_SIZE is 1, and DR_CHAIN
    9399                 :             :          is of size 1.  */
    9400                 :             :       stmt_vec_info next_stmt_info = first_stmt_info;
    9401                 :     2849349 :       for (i = 0; i < group_size; i++)
    9402                 :             :         {
    9403                 :             :           /* Since gaps are not supported for interleaved stores,
    9404                 :             :              DR_GROUP_SIZE is the exact number of stmts in the chain.
    9405                 :             :              Therefore, NEXT_STMT_INFO can't be NULL_TREE.  In case
    9406                 :             :              that there is no interleaving, DR_GROUP_SIZE is 1,
    9407                 :             :              and only one iteration of the loop will be executed.  */
    9408                 :     2023371 :           op = vect_get_store_rhs (next_stmt_info);
    9409                 :     2023371 :           if (!costing_p)
    9410                 :             :             {
    9411                 :             :               vect_get_vec_defs_for_operand (vinfo, next_stmt_info,
    9412                 :             :                                              1, op, gvec_oprnds[i]);
    9413                 :             :               vec_oprnd = (*gvec_oprnds[i])[0];
    9414                 :             :               dr_chain.quick_push (vec_oprnd);
    9415                 :             :             }
    9416                 :     2023371 :           next_stmt_info = DR_GROUP_NEXT_ELEMENT (next_stmt_info);
    9417                 :             :         }
    9418                 :      825978 :       if (mask && !costing_p)
    9419                 :             :         {
    9420                 :             :           vect_get_vec_defs_for_operand (vinfo, stmt_info, 1,
    9421                 :             :                                          mask, &vec_masks, mask_vectype);
    9422                 :             :           vec_mask = vec_masks[0];
    9423                 :             :         }
    9424                 :             :     }
    9425                 :             : 
    9426                 :             :   /* We should have catched mismatched types earlier.  */
    9427                 :     1359510 :   gcc_assert (costing_p
    9428                 :             :               || useless_type_conversion_p (vectype, TREE_TYPE (vec_oprnd)));
    9429                 :     1360158 :   bool simd_lane_access_p
    9430                 :     1360158 :       = STMT_VINFO_SIMD_LANE_ACCESS_P (stmt_info) != 0;
    9431                 :     1360158 :   if (!costing_p
    9432                 :     1360158 :       && simd_lane_access_p
    9433                 :        4351 :       && !loop_masks
    9434                 :        4351 :       && TREE_CODE (DR_BASE_ADDRESS (first_dr_info->dr)) == ADDR_EXPR
    9435                 :        4351 :       && VAR_P (TREE_OPERAND (DR_BASE_ADDRESS (first_dr_info->dr), 0))
    9436                 :        4351 :       && integer_zerop (get_dr_vinfo_offset (vinfo, first_dr_info))
    9437                 :        4351 :       && integer_zerop (DR_INIT (first_dr_info->dr))
    9438                 :     1364509 :       && alias_sets_conflict_p (get_alias_set (aggr_type),
    9439                 :        4351 :                                 get_alias_set (TREE_TYPE (ref_type))))
    9440                 :             :     {
    9441                 :        4343 :       dataref_ptr = unshare_expr (DR_BASE_ADDRESS (first_dr_info->dr));
    9442                 :        4343 :       dataref_offset = build_int_cst (ref_type, 0);
    9443                 :             :     }
    9444                 :     1355815 :   else if (!costing_p)
    9445                 :     1059666 :     dataref_ptr = vect_create_data_ref_ptr (vinfo, first_stmt_info, aggr_type,
    9446                 :             :                                             simd_lane_access_p ? loop : NULL,
    9447                 :             :                                             offset, &dummy, gsi, &ptr_incr,
    9448                 :             :                                             simd_lane_access_p, bump);
    9449                 :             : 
    9450                 :     1360158 :   new_stmt = NULL;
    9451                 :     1360158 :   if (grouped_store)
    9452                 :             :     {
    9453                 :             :       /* Permute.  */
    9454                 :             :       gcc_assert (memory_access_type == VMAT_CONTIGUOUS_PERMUTE);
    9455                 :             :       if (costing_p)
    9456                 :             :         {
    9457                 :             :           int group_size = DR_GROUP_SIZE (first_stmt_info);
    9458                 :             :           int nstmts = ceil_log2 (group_size) * group_size;
    9459                 :             :           inside_cost += record_stmt_cost (cost_vec, nstmts, vec_perm,
    9460                 :             :                                            slp_node, 0, vect_body);
    9461                 :             :           if (dump_enabled_p ())
    9462                 :             :             dump_printf_loc (MSG_NOTE, vect_location, "vect_model_store_cost: "
    9463                 :             :                              "strided group_size = %d .\n", group_size);
    9464                 :             :         }
    9465                 :             :       else
    9466                 :             :         vect_permute_store_chain (vinfo, dr_chain, group_size, stmt_info,
    9467                 :             :                                   gsi, &result_chain);
    9468                 :             :     }
    9469                 :             : 
    9470                 :     3100802 :   for (i = 0; i < vec_num; i++)
    9471                 :             :     {
    9472                 :     1740644 :       if (!costing_p)
    9473                 :      664215 :         vec_oprnd = vec_oprnds[i];
    9474                 :             : 
    9475                 :     1740644 :       if (memory_access_type == VMAT_CONTIGUOUS_REVERSE)
    9476                 :             :         {
    9477                 :        3495 :           if (costing_p)
    9478                 :        2364 :             inside_cost += record_stmt_cost (cost_vec, 1, vec_perm,
    9479                 :             :                                              slp_node, 0, vect_body);
    9480                 :             :           else
    9481                 :             :             {
    9482                 :        1131 :               tree perm_mask = perm_mask_for_reverse (vectype);
    9483                 :        1131 :               tree perm_dest
    9484                 :        1131 :                 = vect_create_destination_var (vect_get_store_rhs (stmt_info),
    9485                 :             :                                                vectype);
    9486                 :        1131 :               tree new_temp = make_ssa_name (perm_dest);
    9487                 :             : 
    9488                 :             :               /* Generate the permute statement.  */
    9489                 :        1131 :               gimple *perm_stmt
    9490                 :        1131 :                 = gimple_build_assign (new_temp, VEC_PERM_EXPR, vec_oprnd,
    9491                 :             :                                        vec_oprnd, perm_mask);
    9492                 :        1131 :               vect_finish_stmt_generation (vinfo, stmt_info, perm_stmt, gsi);
    9493                 :             : 
    9494                 :        1131 :               perm_stmt = SSA_NAME_DEF_STMT (new_temp);
    9495                 :        1131 :               vec_oprnd = new_temp;
    9496                 :             :             }
    9497                 :             :         }
    9498                 :             : 
    9499                 :     1740644 :       if (costing_p)
    9500                 :             :         {
    9501                 :     1076429 :           n_adjacent_stores++;
    9502                 :     1076429 :           continue;
    9503                 :             :         }
    9504                 :             : 
    9505                 :      664215 :       tree final_mask = NULL_TREE;
    9506                 :      664215 :       tree final_len = NULL_TREE;
    9507                 :      664215 :       tree bias = NULL_TREE;
    9508                 :      664215 :       if (loop_masks)
    9509                 :           7 :         final_mask = vect_get_loop_mask (loop_vinfo, gsi, loop_masks,
    9510                 :             :                                          vec_num, vectype, i);
    9511                 :      664215 :       if (vec_mask)
    9512                 :         468 :         vec_mask = vec_masks[i];
    9513                 :         468 :       if (vec_mask)
    9514                 :         468 :         final_mask = prepare_vec_mask (loop_vinfo, mask_vectype, final_mask,
    9515                 :             :                                        vec_mask, gsi);
    9516                 :             : 
    9517                 :      664215 :       if (i > 0)
    9518                 :             :         /* Bump the vector pointer.  */
    9519                 :      130035 :         dataref_ptr = bump_vector_ptr (vinfo, dataref_ptr, ptr_incr, gsi,
    9520                 :             :                                        stmt_info, bump);
    9521                 :             : 
    9522                 :      664215 :       unsigned misalign;
    9523                 :      664215 :       unsigned HOST_WIDE_INT align;
    9524                 :      664215 :       align = known_alignment (DR_TARGET_ALIGNMENT (first_dr_info));
    9525                 :      664215 :       if (alignment_support_scheme == dr_aligned)
    9526                 :             :         misalign = 0;
    9527                 :      302188 :       else if (misalignment == DR_MISALIGNMENT_UNKNOWN)
    9528                 :             :         {
    9529                 :      151797 :           align = dr_alignment (vect_dr_behavior (vinfo, first_dr_info));
    9530                 :      151797 :           misalign = 0;
    9531                 :             :         }
    9532                 :             :       else
    9533                 :      150391 :         misalign = misalignment;
    9534                 :      664215 :       if (dataref_offset == NULL_TREE
    9535                 :      658868 :           && TREE_CODE (dataref_ptr) == SSA_NAME)
    9536                 :      166586 :         set_ptr_info_alignment (get_ptr_info (dataref_ptr), align, misalign);
    9537                 :      664215 :       align = least_bit_hwi (misalign | align);
    9538                 :             : 
    9539                 :             :       /* Compute IFN when LOOP_LENS or final_mask valid.  */
    9540                 :      664215 :       machine_mode vmode = TYPE_MODE (vectype);
    9541                 :      664215 :       machine_mode new_vmode = vmode;
    9542                 :      664215 :       internal_fn partial_ifn = IFN_LAST;
    9543                 :      664215 :       if (loop_lens)
    9544                 :             :         {
    9545                 :           0 :           opt_machine_mode new_ovmode
    9546                 :           0 :             = get_len_load_store_mode (vmode, false, &partial_ifn);
    9547                 :           0 :           new_vmode = new_ovmode.require ();
    9548                 :           0 :           unsigned factor
    9549                 :           0 :             = (new_ovmode == vmode) ? 1 : GET_MODE_UNIT_SIZE (vmode);
    9550                 :           0 :           final_len = vect_get_loop_len (loop_vinfo, gsi, loop_lens,
    9551                 :             :                                          vec_num, vectype, i, factor);
    9552                 :             :         }
    9553                 :      664215 :       else if (final_mask)
    9554                 :             :         {
    9555                 :         475 :           if (!can_vec_mask_load_store_p (vmode,
    9556                 :         475 :                                           TYPE_MODE (TREE_TYPE (final_mask)),
    9557                 :             :                                           false, &partial_ifn))
    9558                 :           0 :             gcc_unreachable ();
    9559                 :             :         }
    9560                 :             : 
    9561                 :      664215 :       if (partial_ifn == IFN_MASK_LEN_STORE)
    9562                 :             :         {
    9563                 :           0 :           if (!final_len)
    9564                 :             :             {
    9565                 :             :               /* Pass VF value to 'len' argument of
    9566                 :             :                  MASK_LEN_STORE if LOOP_LENS is invalid.  */
    9567                 :           0 :               final_len = size_int (TYPE_VECTOR_SUBPARTS (vectype));
    9568                 :             :             }
    9569                 :           0 :           if (!final_mask)
    9570                 :             :             {
    9571                 :             :               /* Pass all ones value to 'mask' argument of
    9572                 :             :                  MASK_LEN_STORE if final_mask is invalid.  */
    9573                 :           0 :               mask_vectype = truth_type_for (vectype);
    9574                 :           0 :               final_mask = build_minus_one_cst (mask_vectype);
    9575                 :             :             }
    9576                 :             :         }
    9577                 :      664215 :       if (final_len)
    9578                 :             :         {
    9579                 :           0 :           signed char biasval = LOOP_VINFO_PARTIAL_LOAD_STORE_BIAS (loop_vinfo);
    9580                 :           0 :           bias = build_int_cst (intQI_type_node, biasval);
    9581                 :             :         }
    9582                 :             : 
    9583                 :             :       /* Arguments are ready.  Create the new vector stmt.  */
    9584                 :      664215 :       if (final_len)
    9585                 :             :         {
    9586                 :           0 :           gcall *call;
    9587                 :           0 :           tree ptr = build_int_cst (ref_type, align * BITS_PER_UNIT);
    9588                 :             :           /* Need conversion if it's wrapped with VnQI.  */
    9589                 :           0 :           if (vmode != new_vmode)
    9590                 :             :             {
    9591                 :           0 :               tree new_vtype
    9592                 :           0 :                 = build_vector_type_for_mode (unsigned_intQI_type_node,
    9593                 :             :                                               new_vmode);
    9594                 :           0 :               tree var = vect_get_new_ssa_name (new_vtype, vect_simple_var);
    9595                 :           0 :               vec_oprnd = build1 (VIEW_CONVERT_EXPR, new_vtype, vec_oprnd);
    9596                 :           0 :               gassign *new_stmt
    9597                 :           0 :                 = gimple_build_assign (var, VIEW_CONVERT_EXPR, vec_oprnd);
    9598                 :           0 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    9599                 :           0 :               vec_oprnd = var;
    9600                 :             :             }
    9601                 :             : 
    9602                 :           0 :           if (partial_ifn == IFN_MASK_LEN_STORE)
    9603                 :           0 :             call = gimple_build_call_internal (IFN_MASK_LEN_STORE, 6,
    9604                 :             :                                                dataref_ptr, ptr, final_mask,
    9605                 :             :                                                final_len, bias, vec_oprnd);
    9606                 :             :           else
    9607                 :           0 :             call = gimple_build_call_internal (IFN_LEN_STORE, 5,
    9608                 :             :                                                dataref_ptr, ptr, final_len,
    9609                 :             :                                                bias, vec_oprnd);
    9610                 :           0 :           gimple_call_set_nothrow (call, true);
    9611                 :           0 :           vect_finish_stmt_generation (vinfo, stmt_info, call, gsi);
    9612                 :           0 :           new_stmt = call;
    9613                 :             :         }
    9614                 :      664215 :       else if (final_mask)
    9615                 :             :         {
    9616                 :         475 :           tree ptr = build_int_cst (ref_type, align * BITS_PER_UNIT);
    9617                 :         475 :           gcall *call
    9618                 :         475 :             = gimple_build_call_internal (IFN_MASK_STORE, 4, dataref_ptr,
    9619                 :             :                                           ptr, final_mask, vec_oprnd);
    9620                 :         475 :           gimple_call_set_nothrow (call, true);
    9621                 :         475 :           vect_finish_stmt_generation (vinfo, stmt_info, call, gsi);
    9622                 :         475 :           new_stmt = call;
    9623                 :             :         }
    9624                 :             :       else
    9625                 :             :         {
    9626                 :      663740 :           data_ref = fold_build2 (MEM_REF, vectype, dataref_ptr,
    9627                 :             :                                   dataref_offset ? dataref_offset
    9628                 :             :                                   : build_int_cst (ref_type, 0));
    9629                 :      663740 :           if (alignment_support_scheme == dr_aligned)
    9630                 :             :             ;
    9631                 :             :           else
    9632                 :      301861 :             TREE_TYPE (data_ref)
    9633                 :      603722 :               = build_aligned_type (TREE_TYPE (data_ref),
    9634                 :             :                                     align * BITS_PER_UNIT);
    9635                 :      663740 :           vect_copy_ref_info (data_ref, DR_REF (first_dr_info->dr));
    9636                 :      663740 :           new_stmt = gimple_build_assign (data_ref, vec_oprnd);
    9637                 :      663740 :           vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    9638                 :             :         }
    9639                 :             :     }
    9640                 :             : 
    9641                 :     1360158 :   if (costing_p)
    9642                 :             :     {
    9643                 :      825978 :       if (n_adjacent_stores > 0)
    9644                 :      825978 :         vect_get_store_cost (vinfo, stmt_info, slp_node, n_adjacent_stores,
    9645                 :             :                              alignment_support_scheme, misalignment,
    9646                 :             :                              &inside_cost, cost_vec);
    9647                 :             : 
    9648                 :             :       /* When vectorizing a store into the function result assign
    9649                 :             :          a penalty if the function returns in a multi-register location.
    9650                 :             :          In this case we assume we'll end up with having to spill the
    9651                 :             :          vector result and do piecewise loads as a conservative estimate.  */
    9652                 :      825978 :       tree base = get_base_address (STMT_VINFO_DATA_REF (stmt_info)->ref);
    9653                 :      825978 :       if (base
    9654                 :      825978 :           && (TREE_CODE (base) == RESULT_DECL
    9655                 :      764433 :               || (DECL_P (base) && cfun_returns (base)))
    9656                 :      905551 :           && !aggregate_value_p (base, cfun->decl))
    9657                 :             :         {
    9658                 :       17340 :           rtx reg = hard_function_value (TREE_TYPE (base), cfun->decl, 0, 1);
    9659                 :             :           /* ???  Handle PARALLEL in some way.  */
    9660                 :       17340 :           if (REG_P (reg))
    9661                 :             :             {
    9662                 :       17144 :               int nregs = hard_regno_nregs (REGNO (reg), GET_MODE (reg));
    9663                 :             :               /* Assume that a single reg-reg move is possible and cheap,
    9664                 :             :                  do not account for vector to gp register move cost.  */
    9665                 :       17144 :               if (nregs > 1)
    9666                 :             :                 {
    9667                 :             :                   /* Spill.  */
    9668                 :       16202 :                   prologue_cost
    9669                 :       16202 :                     += record_stmt_cost (cost_vec, 1, vector_store,
    9670                 :             :                                          slp_node, 0, vect_epilogue);
    9671                 :             :                   /* Loads.  */
    9672                 :       16202 :                   prologue_cost
    9673                 :       16202 :                     += record_stmt_cost (cost_vec, nregs, scalar_load,
    9674                 :             :                                          slp_node, 0, vect_epilogue);
    9675                 :             :                 }
    9676                 :             :             }
    9677                 :             :         }
    9678                 :      825978 :       if (dump_enabled_p ())
    9679                 :       14748 :         dump_printf_loc (MSG_NOTE, vect_location,
    9680                 :             :                          "vect_model_store_cost: inside_cost = %d, "
    9681                 :             :                          "prologue_cost = %d .\n",
    9682                 :             :                          inside_cost, prologue_cost);
    9683                 :             :     }
    9684                 :             : 
    9685                 :     1360158 :   return true;
    9686                 :     2722945 : }
    9687                 :             : 
    9688                 :             : /* Given a vector type VECTYPE, turns permutation SEL into the equivalent
    9689                 :             :    VECTOR_CST mask.  No checks are made that the target platform supports the
    9690                 :             :    mask, so callers may wish to test can_vec_perm_const_p separately, or use
    9691                 :             :    vect_gen_perm_mask_checked.  */
    9692                 :             : 
    9693                 :             : tree
    9694                 :       58277 : vect_gen_perm_mask_any (tree vectype, const vec_perm_indices &sel)
    9695                 :             : {
    9696                 :       58277 :   tree mask_type;
    9697                 :             : 
    9698                 :       58277 :   poly_uint64 nunits = sel.length ();
    9699                 :       58277 :   gcc_assert (known_eq (nunits, TYPE_VECTOR_SUBPARTS (vectype)));
    9700                 :             : 
    9701                 :       58277 :   mask_type = build_vector_type (ssizetype, nunits);
    9702                 :       58277 :   return vec_perm_indices_to_tree (mask_type, sel);
    9703                 :             : }
    9704                 :             : 
    9705                 :             : /* Checked version of vect_gen_perm_mask_any.  Asserts can_vec_perm_const_p,
    9706                 :             :    i.e. that the target supports the pattern _for arbitrary input vectors_.  */
    9707                 :             : 
    9708                 :             : tree
    9709                 :       55745 : vect_gen_perm_mask_checked (tree vectype, const vec_perm_indices &sel)
    9710                 :             : {
    9711                 :       55745 :   machine_mode vmode = TYPE_MODE (vectype);
    9712                 :       55745 :   gcc_assert (can_vec_perm_const_p (vmode, vmode, sel));
    9713                 :       55745 :   return vect_gen_perm_mask_any (vectype, sel);
    9714                 :             : }
    9715                 :             : 
    9716                 :             : /* Given a vector variable X and Y, that was generated for the scalar
    9717                 :             :    STMT_INFO, generate instructions to permute the vector elements of X and Y
    9718                 :             :    using permutation mask MASK_VEC, insert them at *GSI and return the
    9719                 :             :    permuted vector variable.  */
    9720                 :             : 
    9721                 :             : static tree
    9722                 :        1412 : permute_vec_elements (vec_info *vinfo,
    9723                 :             :                       tree x, tree y, tree mask_vec, stmt_vec_info stmt_info,
    9724                 :             :                       gimple_stmt_iterator *gsi)
    9725                 :             : {
    9726                 :        1412 :   tree vectype = TREE_TYPE (x);
    9727                 :        1412 :   tree perm_dest, data_ref;
    9728                 :        1412 :   gimple *perm_stmt;
    9729                 :             : 
    9730                 :        1412 :   tree scalar_dest = gimple_get_lhs (stmt_info->stmt);
    9731                 :        1412 :   if (scalar_dest && TREE_CODE (scalar_dest) == SSA_NAME)
    9732                 :        1412 :     perm_dest = vect_create_destination_var (scalar_dest, vectype);
    9733                 :             :   else
    9734                 :           0 :     perm_dest = vect_get_new_vect_var (vectype, vect_simple_var, NULL);
    9735                 :        1412 :   data_ref = make_ssa_name (perm_dest);
    9736                 :             : 
    9737                 :             :   /* Generate the permute statement.  */
    9738                 :        1412 :   perm_stmt = gimple_build_assign (data_ref, VEC_PERM_EXPR, x, y, mask_vec);
    9739                 :        1412 :   vect_finish_stmt_generation (vinfo, stmt_info, perm_stmt, gsi);
    9740                 :             : 
    9741                 :        1412 :   return data_ref;
    9742                 :             : }
    9743                 :             : 
    9744                 :             : /* Hoist the definitions of all SSA uses on STMT_INFO out of the loop LOOP,
    9745                 :             :    inserting them on the loops preheader edge.  Returns true if we
    9746                 :             :    were successful in doing so (and thus STMT_INFO can be moved then),
    9747                 :             :    otherwise returns false.  HOIST_P indicates if we want to hoist the
    9748                 :             :    definitions of all SSA uses, it would be false when we are costing.  */
    9749                 :             : 
    9750                 :             : static bool
    9751                 :        4736 : hoist_defs_of_uses (gimple *stmt, class loop *loop, bool hoist_p)
    9752                 :             : {
    9753                 :        4736 :   ssa_op_iter i;
    9754                 :        4736 :   use_operand_p use_p;
    9755                 :        4736 :   auto_vec<use_operand_p, 8> to_hoist;
    9756                 :             : 
    9757                 :        9001 :   FOR_EACH_SSA_USE_OPERAND (use_p, stmt, i, SSA_OP_USE)
    9758                 :             :     {
    9759                 :        4289 :       gimple *def_stmt = SSA_NAME_DEF_STMT (USE_FROM_PTR (use_p));
    9760                 :        4289 :       if (!gimple_nop_p (def_stmt)
    9761                 :        4289 :           && flow_bb_inside_loop_p (loop, gimple_bb (def_stmt)))
    9762                 :             :         {
    9763                 :             :           /* Make sure we don't need to recurse.  While we could do
    9764                 :             :              so in simple cases when there are more complex use webs
    9765                 :             :              we don't have an easy way to preserve stmt order to fulfil
    9766                 :             :              dependencies within them.  */
    9767                 :          93 :           tree op2;
    9768                 :          93 :           ssa_op_iter i2;
    9769                 :          93 :           if (gimple_code (def_stmt) == GIMPLE_PHI
    9770                 :          93 :               || (single_ssa_def_operand (def_stmt, SSA_OP_DEF)
    9771                 :             :                   == NULL_DEF_OPERAND_P))
    9772                 :          24 :             return false;
    9773                 :         182 :           FOR_EACH_SSA_TREE_OPERAND (op2, def_stmt, i2, SSA_OP_USE)
    9774                 :             :             {
    9775                 :         113 :               gimple *def_stmt2 = SSA_NAME_DEF_STMT (op2);
    9776                 :         113 :               if (!gimple_nop_p (def_stmt2)
    9777                 :         113 :                   && flow_bb_inside_loop_p (loop, gimple_bb (def_stmt2)))
    9778                 :             :                 return false;
    9779                 :             :             }
    9780                 :          69 :           to_hoist.safe_push (use_p);
    9781                 :             :         }
    9782                 :             :     }
    9783                 :             : 
    9784                 :        9424 :   if (to_hoist.is_empty ())
    9785                 :             :     return true;
    9786                 :             : 
    9787                 :          69 :   if (!hoist_p)
    9788                 :             :     return true;
    9789                 :             : 
    9790                 :             :   /* Instead of moving defs we copy them so we can zero their UID to not
    9791                 :             :      confuse dominance queries in the preheader.  */
    9792                 :          13 :   gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
    9793                 :          52 :   for (use_operand_p use_p : to_hoist)
    9794                 :             :     {
    9795                 :          13 :       gimple *def_stmt = SSA_NAME_DEF_STMT (USE_FROM_PTR (use_p));
    9796                 :          13 :       gimple *copy = gimple_copy (def_stmt);
    9797                 :          13 :       gimple_set_uid (copy, 0);
    9798                 :          13 :       def_operand_p def_p = single_ssa_def_operand (def_stmt, SSA_OP_DEF);
    9799                 :          13 :       tree new_def = duplicate_ssa_name (DEF_FROM_PTR (def_p), copy);
    9800                 :          13 :       update_stmt (copy);
    9801                 :          13 :       def_p = single_ssa_def_operand (copy, SSA_OP_DEF);
    9802                 :          13 :       SET_DEF (def_p, new_def);
    9803                 :          13 :       SET_USE (use_p, new_def);
    9804                 :          13 :       gsi_insert_before (&gsi, copy, GSI_SAME_STMT);
    9805                 :             :     }
    9806                 :             : 
    9807                 :             :   return true;
    9808                 :        4736 : }
    9809                 :             : 
    9810                 :             : /* vectorizable_load.
    9811                 :             : 
    9812                 :             :    Check if STMT_INFO reads a non scalar data-ref (array/pointer/structure)
    9813                 :             :    that can be vectorized.
    9814                 :             :    If VEC_STMT is also passed, vectorize STMT_INFO: create a vectorized
    9815                 :             :    stmt to replace it, put it in VEC_STMT, and insert it at GSI.
    9816                 :             :    Return true if STMT_INFO is vectorizable in this way.  */
    9817                 :             : 
    9818                 :             : static bool
    9819                 :     2075615 : vectorizable_load (vec_info *vinfo,
    9820                 :             :                    stmt_vec_info stmt_info, gimple_stmt_iterator *gsi,
    9821                 :             :                    gimple **vec_stmt, slp_tree slp_node,
    9822                 :             :                    stmt_vector_for_cost *cost_vec)
    9823                 :             : {
    9824                 :     2075615 :   tree scalar_dest;
    9825                 :     2075615 :   tree vec_dest = NULL;
    9826                 :     2075615 :   tree data_ref = NULL;
    9827                 :     2075615 :   loop_vec_info loop_vinfo = dyn_cast <loop_vec_info> (vinfo);
    9828                 :     2075615 :   class loop *loop = NULL;
    9829                 :     2075615 :   class loop *containing_loop = gimple_bb (stmt_info->stmt)->loop_father;
    9830                 :     2075615 :   bool nested_in_vect_loop = false;
    9831                 :     2075615 :   tree elem_type;
    9832                 :             :   /* Avoid false positive uninitialized warning, see PR110652.  */
    9833                 :     2075615 :   tree new_temp = NULL_TREE;
    9834                 :     2075615 :   machine_mode mode;
    9835                 :     2075615 :   tree dummy;
    9836                 :     2075615 :   tree dataref_ptr = NULL_TREE;
    9837                 :     2075615 :   tree dataref_offset = NULL_TREE;
    9838                 :     2075615 :   gimple *ptr_incr = NULL;
    9839                 :     2075615 :   int ncopies;
    9840                 :     2075615 :   int i, j;
    9841                 :     2075615 :   unsigned int group_size;
    9842                 :     2075615 :   poly_uint64 group_gap_adj;
    9843                 :     2075615 :   tree msq = NULL_TREE, lsq;
    9844                 :     2075615 :   tree realignment_token = NULL_TREE;
    9845                 :     2075615 :   gphi *phi = NULL;
    9846                 :     2075615 :   vec<tree> dr_chain = vNULL;
    9847                 :     2075615 :   bool grouped_load = false;
    9848                 :     2075615 :   stmt_vec_info first_stmt_info;
    9849                 :     2075615 :   stmt_vec_info first_stmt_info_for_drptr = NULL;
    9850                 :     2075615 :   bool compute_in_loop = false;
    9851                 :     2075615 :   class loop *at_loop;
    9852                 :     2075615 :   int vec_num;
    9853                 :     2075615 :   bool slp = (slp_node != NULL);
    9854                 :     2075615 :   bool slp_perm = false;
    9855                 :     2075615 :   bb_vec_info bb_vinfo = dyn_cast <bb_vec_info> (vinfo);
    9856                 :     2075615 :   poly_uint64 vf;
    9857                 :     2075615 :   tree aggr_type;
    9858                 :     2075615 :   gather_scatter_info gs_info;
    9859                 :     2075615 :   tree ref_type;
    9860                 :     2075615 :   enum vect_def_type mask_dt = vect_unknown_def_type;
    9861                 :     2075615 :   enum vect_def_type els_dt = vect_unknown_def_type;
    9862                 :             : 
    9863                 :     2075615 :   if (!STMT_VINFO_RELEVANT_P (stmt_info) && !bb_vinfo)
    9864                 :             :     return false;
    9865                 :             : 
    9866                 :     2075615 :   if (STMT_VINFO_DEF_TYPE (stmt_info) != vect_internal_def
    9867                 :      200344 :       && ! vec_stmt)
    9868                 :             :     return false;
    9869                 :             : 
    9870                 :     1875271 :   if (!STMT_VINFO_DATA_REF (stmt_info))
    9871                 :             :     return false;
    9872                 :             : 
    9873                 :     1515472 :   tree mask = NULL_TREE, mask_vectype = NULL_TREE;
    9874                 :     1515472 :   tree els = NULL_TREE; tree els_vectype = NULL_TREE;
    9875                 :             : 
    9876                 :     1515472 :   int mask_index = -1;
    9877                 :     1515472 :   int els_index = -1;
    9878                 :     1515472 :   slp_tree slp_op = NULL;
    9879                 :     1515472 :   slp_tree els_op = NULL;
    9880                 :     1515472 :   if (gassign *assign = dyn_cast <gassign *> (stmt_info->stmt))
    9881                 :             :     {
    9882                 :     1512056 :       scalar_dest = gimple_assign_lhs (assign);
    9883                 :     1512056 :       if (TREE_CODE (scalar_dest) != SSA_NAME)
    9884                 :             :         return false;
    9885                 :             : 
    9886                 :      656299 :       tree_code code = gimple_assign_rhs_code (assign);
    9887                 :      656299 :       if (code != ARRAY_REF
    9888                 :      656299 :           && code != BIT_FIELD_REF
    9889                 :      656299 :           && code != INDIRECT_REF
    9890                 :      442698 :           && code != COMPONENT_REF
    9891                 :      442698 :           && code != IMAGPART_EXPR
    9892                 :      298476 :           && code != REALPART_EXPR
    9893                 :      298476 :           && code != MEM_REF
    9894                 :         214 :           && TREE_CODE_CLASS (code) != tcc_declaration)
    9895                 :             :         return false;
    9896                 :             :     }
    9897                 :             :   else
    9898                 :             :     {
    9899                 :     1420616 :       gcall *call = dyn_cast <gcall *> (stmt_info->stmt);
    9900                 :        3416 :       if (!call || !gimple_call_internal_p (call))
    9901                 :             :         return false;
    9902                 :             : 
    9903                 :        3416 :       internal_fn ifn = gimple_call_internal_fn (call);
    9904                 :        3416 :       if (!internal_load_fn_p (ifn))
    9905                 :             :         return false;
    9906                 :             : 
    9907                 :        2432 :       scalar_dest = gimple_call_lhs (call);
    9908                 :        2432 :       if (!scalar_dest)
    9909                 :             :         return false;
    9910                 :             : 
    9911                 :        2432 :       mask_index = internal_fn_mask_index (ifn);
    9912                 :        2432 :       if (mask_index >= 0 && slp_node)
    9913                 :        2432 :         mask_index = vect_slp_child_index_for_operand
    9914                 :        2432 :                     (call, mask_index, STMT_VINFO_GATHER_SCATTER_P (stmt_info));
    9915                 :        2432 :       if (mask_index >= 0
    9916                 :        2432 :           && !vect_check_scalar_mask (vinfo, stmt_info, slp_node, mask_index,
    9917                 :             :                                       &mask, &slp_op, &mask_dt, &mask_vectype))
    9918                 :             :         return false;
    9919                 :             : 
    9920                 :        2432 :       els_index = internal_fn_else_index (ifn);
    9921                 :        2432 :       if (els_index >= 0 && slp_node)
    9922                 :        2432 :         els_index = vect_slp_child_index_for_operand
    9923                 :        2432 :           (call, els_index, STMT_VINFO_GATHER_SCATTER_P (stmt_info));
    9924                 :        2432 :       if (els_index >= 0
    9925                 :        2432 :           && !vect_is_simple_use (vinfo, stmt_info, slp_node, els_index,
    9926                 :             :                                   &els, &els_op, &els_dt, &els_vectype))
    9927                 :             :         return false;
    9928                 :             :     }
    9929                 :             : 
    9930                 :      658731 :   tree vectype = STMT_VINFO_VECTYPE (stmt_info);
    9931                 :      658731 :   poly_uint64 nunits = TYPE_VECTOR_SUBPARTS (vectype);
    9932                 :             : 
    9933                 :      658731 :   if (loop_vinfo)
    9934                 :             :     {
    9935                 :      434505 :       loop = LOOP_VINFO_LOOP (loop_vinfo);
    9936                 :      434505 :       nested_in_vect_loop = nested_in_vect_loop_p (loop, stmt_info);
    9937                 :      434505 :       vf = LOOP_VINFO_VECT_FACTOR (loop_vinfo);
    9938                 :             :     }
    9939                 :             :   else
    9940                 :             :     vf = 1;
    9941                 :             : 
    9942                 :             :   /* Multiple types in SLP are handled by creating the appropriate number of
    9943                 :             :      vectorized stmts for each SLP node.  Hence, NCOPIES is always 1 in
    9944                 :             :      case of SLP.  */
    9945                 :      658731 :   if (slp)
    9946                 :             :     ncopies = 1;
    9947                 :             :   else
    9948                 :           0 :     ncopies = vect_get_num_copies (loop_vinfo, vectype);
    9949                 :             : 
    9950                 :           0 :   gcc_assert (ncopies >= 1);
    9951                 :             : 
    9952                 :             :   /* FORNOW. This restriction should be relaxed.  */
    9953                 :      658731 :   if (nested_in_vect_loop
    9954                 :        1448 :       && (ncopies > 1 || (slp && SLP_TREE_NUMBER_OF_VEC_STMTS (slp_node) > 1)))
    9955                 :             :     {
    9956                 :         304 :       if (dump_enabled_p ())
    9957                 :          72 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    9958                 :             :                          "multiple types in nested loop.\n");
    9959                 :         304 :       return false;
    9960                 :             :     }
    9961                 :             : 
    9962                 :             :   /* Invalidate assumptions made by dependence analysis when vectorization
    9963                 :             :      on the unrolled body effectively re-orders stmts.  */
    9964                 :      658427 :   if (ncopies > 1
    9965                 :           0 :       && STMT_VINFO_MIN_NEG_DIST (stmt_info) != 0
    9966                 :      658427 :       && maybe_gt (LOOP_VINFO_VECT_FACTOR (loop_vinfo),
    9967                 :             :                    STMT_VINFO_MIN_NEG_DIST (stmt_info)))
    9968                 :             :     {
    9969                 :           0 :       if (dump_enabled_p ())
    9970                 :           0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    9971                 :             :                          "cannot perform implicit CSE when unrolling "
    9972                 :             :                          "with negative dependence distance\n");
    9973                 :           0 :       return false;
    9974                 :             :     }
    9975                 :             : 
    9976                 :      658427 :   elem_type = TREE_TYPE (vectype);
    9977                 :      658427 :   mode = TYPE_MODE (vectype);
    9978                 :             : 
    9979                 :             :   /* FORNOW. In some cases can vectorize even if data-type not supported
    9980                 :             :     (e.g. - data copies).  */
    9981                 :      658427 :   if (!can_implement_p (mov_optab, mode))
    9982                 :             :     {
    9983                 :           0 :       if (dump_enabled_p ())
    9984                 :           0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    9985                 :             :                          "Aligned load, but unsupported type.\n");
    9986                 :           0 :       return false;
    9987                 :             :     }
    9988                 :             : 
    9989                 :             :   /* Check if the load is a part of an interleaving chain.  */
    9990                 :      658427 :   if (STMT_VINFO_GROUPED_ACCESS (stmt_info))
    9991                 :             :     {
    9992                 :      308387 :       grouped_load = true;
    9993                 :             :       /* FORNOW */
    9994                 :      308387 :       gcc_assert (!nested_in_vect_loop);
    9995                 :      308387 :       gcc_assert (!STMT_VINFO_GATHER_SCATTER_P (stmt_info));
    9996                 :             : 
    9997                 :      308387 :       first_stmt_info = DR_GROUP_FIRST_ELEMENT (stmt_info);
    9998                 :      308387 :       group_size = DR_GROUP_SIZE (first_stmt_info);
    9999                 :             : 
   10000                 :             :       /* Refuse non-SLP vectorization of SLP-only groups.  */
   10001                 :      308387 :       if (!slp && STMT_VINFO_SLP_VECT_ONLY (first_stmt_info))
   10002                 :             :         {
   10003                 :           0 :           if (dump_enabled_p ())
   10004                 :           0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
   10005                 :             :                              "cannot vectorize load in non-SLP mode.\n");
   10006                 :           0 :           return false;
   10007                 :             :         }
   10008                 :             : 
   10009                 :             :       /* Invalidate assumptions made by dependence analysis when vectorization
   10010                 :             :          on the unrolled body effectively re-orders stmts.  */
   10011                 :      308387 :       if (STMT_VINFO_MIN_NEG_DIST (stmt_info) != 0
   10012                 :      308387 :           && maybe_gt (LOOP_VINFO_VECT_FACTOR (loop_vinfo),
   10013                 :             :                        STMT_VINFO_MIN_NEG_DIST (stmt_info)))
   10014                 :             :         {
   10015                 :          12 :           if (dump_enabled_p ())
   10016                 :          12 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
   10017                 :             :                              "cannot perform implicit CSE when performing "
   10018                 :             :                              "group loads with negative dependence distance\n");
   10019                 :          12 :           return false;
   10020                 :             :         }
   10021                 :             :     }
   10022                 :             :   else
   10023                 :             :     group_size = 1;
   10024                 :             : 
   10025                 :      658415 :   vect_memory_access_type memory_access_type;
   10026                 :      658415 :   enum dr_alignment_support alignment_support_scheme;
   10027                 :      658415 :   int misalignment;
   10028                 :      658415 :   poly_int64 poffset;
   10029                 :      658415 :   internal_fn lanes_ifn;
   10030                 :      658415 :   auto_vec<int> elsvals;
   10031                 :      658415 :   int maskload_elsval = 0;
   10032                 :      658415 :   bool need_zeroing = false;
   10033                 :      658415 :   if (!get_load_store_type (vinfo, stmt_info, vectype, slp_node, mask, VLS_LOAD,
   10034                 :             :                             ncopies, &memory_access_type, &poffset,
   10035                 :             :                             &alignment_support_scheme, &misalignment, &gs_info,
   10036                 :             :                             &lanes_ifn, &elsvals))
   10037                 :             :     return false;
   10038                 :             : 
   10039                 :             : 
   10040                 :             :   /* We might need to explicitly zero inactive elements if there are
   10041                 :             :      padding bits in the type that might leak otherwise.
   10042                 :             :      Refer to PR115336.  */
   10043                 :      583080 :   tree scalar_type = TREE_TYPE (scalar_dest);
   10044                 :      583080 :   bool type_mode_padding_p
   10045                 :     1166160 :     = TYPE_PRECISION (scalar_type) < GET_MODE_PRECISION (GET_MODE_INNER (mode));
   10046                 :             : 
   10047                 :             :   /* ???  The following checks should really be part of
   10048                 :             :      get_group_load_store_type.  */
   10049                 :      583080 :   if (slp
   10050                 :      583080 :       && SLP_TREE_LOAD_PERMUTATION (slp_node).exists ()
   10051                 :      653768 :       && !((memory_access_type == VMAT_ELEMENTWISE
   10052                 :       59141 :             || memory_access_type == VMAT_GATHER_SCATTER)
   10053                 :       11547 :            && SLP_TREE_LANES (slp_node) == 1))
   10054                 :             :     {
   10055                 :       59141 :       slp_perm = true;
   10056                 :             : 
   10057                 :       59141 :       if (!loop_vinfo)
   10058                 :             :         {
   10059                 :             :           /* In BB vectorization we may not actually use a loaded vector
   10060                 :             :              accessing elements in excess of DR_GROUP_SIZE.  */
   10061                 :       32818 :           stmt_vec_info group_info = SLP_TREE_SCALAR_STMTS (slp_node)[0];
   10062                 :       32818 :           group_info = DR_GROUP_FIRST_ELEMENT (group_info);
   10063                 :       32818 :           unsigned HOST_WIDE_INT nunits;
   10064                 :       32818 :           unsigned j, k, maxk = 0;
   10065                 :      118285 :           FOR_EACH_VEC_ELT (SLP_TREE_LOAD_PERMUTATION (slp_node), j, k)
   10066                 :       85467 :               if (k > maxk)
   10067                 :             :                 maxk = k;
   10068                 :       32818 :           tree vectype = SLP_TREE_VECTYPE (slp_node);
   10069                 :       61166 :           if (!TYPE_VECTOR_SUBPARTS (vectype).is_constant (&nunits)
   10070                 :       32818 :               || maxk >= (DR_GROUP_SIZE (group_info) & ~(nunits - 1)))
   10071                 :             :             {
   10072                 :        4470 :               if (dump_enabled_p ())
   10073                 :          33 :                 dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
   10074                 :             :                                  "BB vectorization with gaps at the end of "
   10075                 :             :                                  "a load is not supported\n");
   10076                 :        4470 :               return false;
   10077                 :             :             }
   10078                 :             :         }
   10079                 :             : 
   10080                 :       54671 :       auto_vec<tree> tem;
   10081                 :       54671 :       unsigned n_perms;
   10082                 :       54671 :       if (!vect_transform_slp_perm_load (vinfo, slp_node, tem, NULL, vf,
   10083                 :             :                                          true, &n_perms))
   10084                 :             :         {
   10085                 :        3017 :           if (dump_enabled_p ())
   10086                 :         144 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION,
   10087                 :             :                              vect_location,
   10088                 :             :                              "unsupported load permutation\n");
   10089                 :        3017 :           return false;
   10090                 :             :         }
   10091                 :       54671 :     }
   10092                 :             : 
   10093                 :      575593 :   if (slp_node
   10094                 :      575593 :       && slp_node->ldst_lanes
   10095                 :           0 :       && memory_access_type != VMAT_LOAD_STORE_LANES)
   10096                 :             :     {
   10097                 :           0 :       if (dump_enabled_p ())
   10098                 :           0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
   10099                 :             :                          "discovered load-lane but cannot use it.\n");
   10100                 :           0 :       return false;
   10101                 :             :     }
   10102                 :             : 
   10103                 :      575593 :   if (mask)
   10104                 :             :     {
   10105                 :        2312 :       if (memory_access_type == VMAT_CONTIGUOUS)
   10106                 :             :         {
   10107                 :        1469 :           machine_mode vec_mode = TYPE_MODE (vectype);
   10108                 :         386 :           if (!VECTOR_MODE_P (vec_mode)
   10109                 :        2938 :               || !can_vec_mask_load_store_p (vec_mode,
   10110                 :        1469 :                                              TYPE_MODE (mask_vectype),
   10111                 :             :                                              true, NULL, &elsvals))
   10112                 :          65 :             return false;
   10113                 :             :         }
   10114                 :         843 :       else if (memory_access_type != VMAT_LOAD_STORE_LANES
   10115                 :         843 :                && memory_access_type != VMAT_GATHER_SCATTER)
   10116                 :             :         {
   10117                 :          62 :           if (dump_enabled_p ())
   10118                 :           0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
   10119                 :             :                              "unsupported access type for masked load.\n");
   10120                 :          62 :           return false;
   10121                 :             :         }
   10122                 :         781 :       else if (memory_access_type == VMAT_GATHER_SCATTER
   10123                 :         781 :                && gs_info.ifn == IFN_LAST
   10124                 :         781 :                && !gs_info.decl)
   10125                 :             :         {
   10126                 :         476 :           if (dump_enabled_p ())
   10127                 :          26 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
   10128                 :             :                              "unsupported masked emulated gather.\n");
   10129                 :         476 :           return false;
   10130                 :             :         }
   10131                 :             :       else if (memory_access_type == VMAT_ELEMENTWISE
   10132                 :             :                || memory_access_type == VMAT_STRIDED_SLP)
   10133                 :             :         {
   10134                 :             :           if (dump_enabled_p ())
   10135                 :             :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
   10136                 :             :                              "unsupported masked strided access.\n");
   10137                 :             :           return false;
   10138                 :             :         }
   10139                 :             :     }
   10140                 :             : 
   10141                 :      574990 :   bool costing_p = !vec_stmt;
   10142                 :             : 
   10143                 :      574990 :   if (costing_p) /* transformation not required.  */
   10144                 :             :     {
   10145                 :      417646 :       if (slp_node
   10146                 :      417646 :           && mask
   10147                 :      418781 :           && !vect_maybe_update_slp_op_vectype (slp_op,
   10148                 :             :                                                 mask_vectype))
   10149                 :             :         {
   10150                 :           0 :           if (dump_enabled_p ())
   10151                 :           0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
   10152                 :             :                              "incompatible vector types for invariants\n");
   10153                 :           0 :           return false;
   10154                 :             :         }
   10155                 :             : 
   10156                 :      417646 :       if (!slp)
   10157                 :           0 :         STMT_VINFO_MEMORY_ACCESS_TYPE (stmt_info) = memory_access_type;
   10158                 :             :       else
   10159                 :      417646 :         SLP_TREE_MEMORY_ACCESS_TYPE (slp_node) = memory_access_type;
   10160                 :             : 
   10161                 :      417646 :       if (loop_vinfo
   10162                 :      282334 :           && LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo))
   10163                 :          60 :         check_load_store_for_partial_vectors (loop_vinfo, vectype, slp_node,
   10164                 :             :                                               VLS_LOAD, group_size,
   10165                 :             :                                               memory_access_type, &gs_info,
   10166                 :             :                                               mask, &elsvals);
   10167                 :             : 
   10168                 :      417646 :       if (dump_enabled_p ()
   10169                 :       27209 :           && memory_access_type != VMAT_ELEMENTWISE
   10170                 :             :           && memory_access_type != VMAT_GATHER_SCATTER
   10171                 :             :           && memory_access_type != VMAT_STRIDED_SLP
   10172                 :       26288 :           && memory_access_type != VMAT_INVARIANT
   10173                 :      443367 :           && alignment_support_scheme != dr_aligned)
   10174                 :       11492 :         dump_printf_loc (MSG_NOTE, vect_location,
   10175                 :             :                          "Vectorizing an unaligned access.\n");
   10176                 :             : 
   10177                 :      417646 :       if (memory_access_type == VMAT_LOAD_STORE_LANES)
   10178                 :           0 :         vinfo->any_known_not_updated_vssa = true;
   10179                 :             : 
   10180                 :      417646 :       STMT_VINFO_TYPE (stmt_info) = load_vec_info_type;
   10181                 :             :     }
   10182                 :             :   else
   10183                 :             :     {
   10184                 :             :       /* Here just get the else values.  */
   10185                 :      157344 :       if (loop_vinfo
   10186                 :       75433 :           && LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo))
   10187                 :          30 :         check_load_store_for_partial_vectors (loop_vinfo, vectype, slp_node,
   10188                 :             :                                               VLS_LOAD, group_size,
   10189                 :             :                                               memory_access_type, &gs_info,
   10190                 :             :                                               mask, &elsvals);
   10191                 :             :     }
   10192                 :             : 
   10193                 :             :   /* If the type needs padding we must zero inactive elements.
   10194                 :             :      Check if we can do that with a VEC_COND_EXPR and store the
   10195                 :             :      elsval we choose in MASKLOAD_ELSVAL.  */
   10196                 :      574990 :   if (elsvals.length ()
   10197                 :        1472 :       && type_mode_padding_p
   10198                 :           0 :       && !elsvals.contains (MASK_LOAD_ELSE_ZERO)
   10199                 :        1472 :       && !expand_vec_cond_expr_p (vectype, truth_type_for (vectype)))
   10200                 :             :     {
   10201                 :           0 :       if (dump_enabled_p ())
   10202                 :           0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
   10203                 :             :                          "cannot zero inactive elements.\n");
   10204                 :           0 :       return false;
   10205                 :             :     }
   10206                 :             : 
   10207                 :             :   /* For now just use the first available else value.
   10208                 :             :      get_supported_else_vals tries MASK_LOAD_ELSE_ZERO first so we will
   10209                 :             :      select it here if it is supported.  */
   10210                 :      574990 :   if (elsvals.length ())
   10211                 :        1472 :     maskload_elsval = *elsvals.begin ();
   10212                 :             : 
   10213                 :      574990 :   if (!slp)
   10214                 :           0 :     gcc_assert (memory_access_type
   10215                 :             :                 == STMT_VINFO_MEMORY_ACCESS_TYPE (stmt_info));
   10216                 :             :   else
   10217                 :      574990 :     gcc_assert (memory_access_type
   10218                 :             :                 == SLP_TREE_MEMORY_ACCESS_TYPE (slp_node));
   10219                 :             : 
   10220                 :      574990 :   if (dump_enabled_p () && !costing_p)
   10221                 :       15648 :     dump_printf_loc (MSG_NOTE, vect_location,
   10222                 :             :                      "transform load. ncopies = %d\n", ncopies);
   10223                 :             : 
   10224                 :             :   /* Transform.  */
   10225                 :             : 
   10226                 :      574990 :   dr_vec_info *dr_info = STMT_VINFO_DR_INFO (stmt_info), *first_dr_info = NULL;
   10227                 :      574990 :   ensure_base_align (dr_info);
   10228                 :             : 
   10229                 :      574990 :   if (memory_access_type == VMAT_INVARIANT)
   10230                 :             :     {
   10231                 :        4734 :       gcc_assert (!grouped_load && !mask && !bb_vinfo);
   10232                 :             :       /* If we have versioned for aliasing or the loop doesn't
   10233                 :             :          have any data dependencies that would preclude this,
   10234                 :             :          then we are sure this is a loop invariant load and
   10235                 :             :          thus we can insert it on the preheader edge.
   10236                 :             :          TODO: hoist_defs_of_uses should ideally be computed
   10237                 :             :          once at analysis time, remembered and used in the
   10238                 :             :          transform time.  */
   10239                 :        4734 :       bool hoist_p = (LOOP_VINFO_NO_DATA_DEPENDENCIES (loop_vinfo)
   10240                 :        4530 :                       && !nested_in_vect_loop
   10241                 :        8848 :                       && hoist_defs_of_uses (stmt_info->stmt, loop, false));
   10242                 :        4734 :       if (costing_p)
   10243                 :             :         {
   10244                 :         452 :           enum vect_cost_model_location cost_loc
   10245                 :        3920 :             = hoist_p ? vect_prologue : vect_body;
   10246                 :        3920 :           unsigned int cost = record_stmt_cost (cost_vec, 1, scalar_load,
   10247                 :             :                                                 slp_node, 0, cost_loc);
   10248                 :        3920 :           cost += record_stmt_cost (cost_vec, 1, scalar_to_vec,
   10249                 :             :                                     slp_node, 0, cost_loc);
   10250                 :        3920 :           unsigned int prologue_cost = hoist_p ? cost : 0;
   10251                 :         452 :           unsigned int inside_cost = hoist_p ? 0 : cost;
   10252                 :        3920 :           if (dump_enabled_p ())
   10253                 :         567 :             dump_printf_loc (MSG_NOTE, vect_location,
   10254                 :             :                              "vect_model_load_cost: inside_cost = %d, "
   10255                 :             :                              "prologue_cost = %d .\n",
   10256                 :             :                              inside_cost, prologue_cost);
   10257                 :        3920 :           return true;
   10258                 :             :         }
   10259                 :         814 :       if (hoist_p)
   10260                 :             :         {
   10261                 :         622 :           gassign *stmt = as_a <gassign *> (stmt_info->stmt);
   10262                 :         622 :           if (dump_enabled_p ())
   10263                 :         210 :             dump_printf_loc (MSG_NOTE, vect_location,
   10264                 :             :                              "hoisting out of the vectorized loop: %G",
   10265                 :             :                              (gimple *) stmt);
   10266                 :         622 :           scalar_dest = copy_ssa_name (scalar_dest);
   10267                 :         622 :           tree rhs = unshare_expr (gimple_assign_rhs1 (stmt));
   10268                 :         622 :           edge pe = loop_preheader_edge (loop);
   10269                 :         622 :           gphi *vphi = get_virtual_phi (loop->header);
   10270                 :         622 :           tree vuse;
   10271                 :         622 :           if (vphi)
   10272                 :         616 :             vuse = PHI_ARG_DEF_FROM_EDGE (vphi, pe);
   10273                 :             :           else
   10274                 :           6 :             vuse = gimple_vuse (gsi_stmt (*gsi));
   10275                 :         622 :           gimple *new_stmt = gimple_build_assign (scalar_dest, rhs);
   10276                 :         622 :           gimple_set_vuse (new_stmt, vuse);
   10277                 :         622 :           gsi_insert_on_edge_immediate (pe, new_stmt);
   10278                 :         622 :           hoist_defs_of_uses (new_stmt, loop, true);
   10279                 :             :         }
   10280                 :             :       /* These copies are all equivalent.  */
   10281                 :         814 :       if (hoist_p)
   10282                 :         622 :         new_temp = vect_init_vector (vinfo, stmt_info, scalar_dest,
   10283                 :             :                                      vectype, NULL);
   10284                 :             :       else
   10285                 :             :         {
   10286                 :         192 :           gimple_stmt_iterator gsi2 = *gsi;
   10287                 :         192 :           gsi_next (&gsi2);
   10288                 :         192 :           new_temp = vect_init_vector (vinfo, stmt_info, scalar_dest,
   10289                 :             :                                        vectype, &gsi2);
   10290                 :             :         }
   10291                 :         814 :       gimple *new_stmt = SSA_NAME_DEF_STMT (new_temp);
   10292                 :         814 :       if (slp)
   10293                 :        1689 :         for (j = 0; j < (int) SLP_TREE_NUMBER_OF_VEC_STMTS (slp_node); ++j)
   10294                 :         875 :           slp_node->push_vec_def (new_stmt);
   10295                 :             :       else
   10296                 :             :         {
   10297                 :           0 :           for (j = 0; j < ncopies; ++j)
   10298                 :           0 :             STMT_VINFO_VEC_STMTS (stmt_info).safe_push (new_stmt);
   10299                 :           0 :           *vec_stmt = new_stmt;
   10300                 :             :         }
   10301                 :         814 :       return true;
   10302                 :             :     }
   10303                 :             : 
   10304                 :      570256 :   if (memory_access_type == VMAT_ELEMENTWISE
   10305                 :      570256 :       || memory_access_type == VMAT_STRIDED_SLP)
   10306                 :             :     {
   10307                 :       29234 :       gimple_stmt_iterator incr_gsi;
   10308                 :       29234 :       bool insert_after;
   10309                 :       29234 :       tree offvar = NULL_TREE;
   10310                 :       29234 :       tree ivstep;
   10311                 :       29234 :       tree running_off;
   10312                 :       29234 :       vec<constructor_elt, va_gc> *v = NULL;
   10313                 :       29234 :       tree stride_base, stride_step, alias_off;
   10314                 :             :       /* Checked by get_load_store_type.  */
   10315                 :       29234 :       unsigned int const_nunits = nunits.to_constant ();
   10316                 :       29234 :       unsigned HOST_WIDE_INT cst_offset = 0;
   10317                 :       29234 :       tree dr_offset;
   10318                 :       29234 :       unsigned int inside_cost = 0;
   10319                 :             : 
   10320                 :       29234 :       gcc_assert (!LOOP_VINFO_USING_PARTIAL_VECTORS_P (loop_vinfo));
   10321                 :       29234 :       gcc_assert (!nested_in_vect_loop);
   10322                 :             : 
   10323                 :       29234 :       if (grouped_load)
   10324                 :             :         {
   10325                 :       16047 :           first_stmt_info = DR_GROUP_FIRST_ELEMENT (stmt_info);
   10326                 :       16047 :           first_dr_info = STMT_VINFO_DR_INFO (first_stmt_info);
   10327                 :             :         }
   10328                 :             :       else
   10329                 :             :         {
   10330                 :             :           first_stmt_info = stmt_info;
   10331                 :             :           first_dr_info = dr_info;
   10332                 :             :         }
   10333                 :             : 
   10334                 :       16047 :       if (grouped_load && memory_access_type == VMAT_STRIDED_SLP)
   10335                 :             :         {
   10336                 :        4420 :           group_size = DR_GROUP_SIZE (first_stmt_info);
   10337                 :        4420 :           ref_type = get_group_alias_ptr_type (first_stmt_info);
   10338                 :             :         }
   10339                 :             :       else
   10340                 :             :         {
   10341                 :       11627 :           if (grouped_load)
   10342                 :       11627 :             cst_offset
   10343                 :       11627 :               = (tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (vectype)))
   10344                 :       11627 :                  * vect_get_place_in_interleaving_chain (stmt_info,
   10345                 :             :                                                          first_stmt_info));
   10346                 :       24814 :           group_size = 1;
   10347                 :       24814 :           ref_type = reference_alias_ptr_type (DR_REF (dr_info->dr));
   10348                 :             :         }
   10349                 :             : 
   10350                 :       29234 :       if (!costing_p)
   10351                 :             :         {
   10352                 :        3180 :           dr_offset = get_dr_vinfo_offset (vinfo, first_dr_info);
   10353                 :        3180 :           stride_base = fold_build_pointer_plus (
   10354                 :             :             DR_BASE_ADDRESS (first_dr_info->dr),
   10355                 :             :             size_binop (PLUS_EXPR, convert_to_ptrofftype (dr_offset),
   10356                 :             :                         convert_to_ptrofftype (DR_INIT (first_dr_info->dr))));
   10357                 :        3180 :           stride_step = fold_convert (sizetype, DR_STEP (first_dr_info->dr));
   10358                 :             : 
   10359                 :             :           /* For a load with loop-invariant (but other than power-of-2)
   10360                 :             :              stride (i.e. not a grouped access) like so:
   10361                 :             : 
   10362                 :             :                for (i = 0; i < n; i += stride)
   10363                 :             :                  ... = array[i];
   10364                 :             : 
   10365                 :             :              we generate a new induction variable and new accesses to
   10366                 :             :              form a new vector (or vectors, depending on ncopies):
   10367                 :             : 
   10368                 :             :                for (j = 0; ; j += VF*stride)
   10369                 :             :                  tmp1 = array[j];
   10370                 :             :                  tmp2 = array[j + stride];
   10371                 :             :                  ...
   10372                 :             :                  vectemp = {tmp1, tmp2, ...}
   10373                 :             :              */
   10374                 :             : 
   10375                 :        3180 :           ivstep = fold_build2 (MULT_EXPR, TREE_TYPE (stride_step), stride_step,
   10376                 :             :                                 build_int_cst (TREE_TYPE (stride_step), vf));
   10377                 :             : 
   10378                 :        3180 :           standard_iv_increment_position (loop, &incr_gsi, &insert_after);
   10379                 :             : 
   10380                 :        3180 :           stride_base = cse_and_gimplify_to_preheader (loop_vinfo, stride_base);
   10381                 :        3180 :           ivstep = cse_and_gimplify_to_preheader (loop_vinfo, ivstep);
   10382                 :        3180 :           create_iv (stride_base, PLUS_EXPR, ivstep, NULL,
   10383                 :             :                      loop, &incr_gsi, insert_after,
   10384                 :             :                      &offvar, NULL);
   10385                 :             : 
   10386                 :        3180 :           stride_step = cse_and_gimplify_to_preheader (loop_vinfo, stride_step);
   10387                 :             :         }
   10388                 :             : 
   10389                 :       29234 :       running_off = offvar;
   10390                 :       29234 :       alias_off = build_int_cst (ref_type, 0);
   10391                 :       29234 :       int nloads = const_nunits;
   10392                 :       29234 :       int lnel = 1;
   10393                 :       29234 :       tree ltype = TREE_TYPE (vectype);
   10394                 :       29234 :       tree lvectype = vectype;
   10395                 :       29234 :       auto_vec<tree> dr_chain;
   10396                 :       29234 :       if (memory_access_type == VMAT_STRIDED_SLP)
   10397                 :             :         {
   10398                 :       17607 :           HOST_WIDE_INT n = gcd (group_size, const_nunits);
   10399                 :             :           /* Use the target vector type if the group size is a multiple
   10400                 :             :              of it.  */
   10401                 :       17607 :           if (n == const_nunits)
   10402                 :             :             {
   10403                 :        1799 :               int mis_align = dr_misalignment (first_dr_info, vectype);
   10404                 :             :               /* With VF > 1 we advance the DR by step, if that is constant
   10405                 :             :                  and only aligned when performed VF times, DR alignment
   10406                 :             :                  analysis can analyze this as aligned since it assumes
   10407                 :             :                  contiguous accesses.  But that is not how we code generate
   10408                 :             :                  here, so adjust for this.  */
   10409                 :        1799 :               if (maybe_gt (vf, 1u)
   10410                 :        3034 :                   && !multiple_p (DR_STEP_ALIGNMENT (first_dr_info->dr),
   10411                 :        2794 :                                   DR_TARGET_ALIGNMENT (first_dr_info)))
   10412                 :         240 :                 mis_align = -1;
   10413                 :        1799 :               dr_alignment_support dr_align
   10414                 :        1799 :                 = vect_supportable_dr_alignment (vinfo, dr_info, vectype,
   10415                 :             :                                                  mis_align);
   10416                 :        1799 :               if (dr_align == dr_aligned
   10417                 :        1799 :                   || dr_align == dr_unaligned_supported)
   10418                 :             :                 {
   10419                 :        1799 :                   nloads = 1;
   10420                 :        1799 :                   lnel = const_nunits;
   10421                 :        1799 :                   ltype = vectype;
   10422                 :        1799 :                   alignment_support_scheme = dr_align;
   10423                 :        1799 :                   misalignment = mis_align;
   10424                 :             :                 }
   10425                 :             :             }
   10426                 :             :           /* Else use the biggest vector we can load the group without
   10427                 :             :              accessing excess elements.  */
   10428                 :       15808 :           else if (n > 1)
   10429                 :             :             {
   10430                 :        2686 :               tree ptype;
   10431                 :        2686 :               tree vtype
   10432                 :        2686 :                 = vector_vector_composition_type (vectype, const_nunits / n,
   10433                 :             :                                                   &ptype);
   10434                 :        2686 :               if (vtype != NULL_TREE)
   10435                 :             :                 {
   10436                 :        2608 :                   dr_alignment_support dr_align;
   10437                 :        2608 :                   int mis_align = 0;
   10438                 :        2608 :                   if (VECTOR_TYPE_P (ptype))
   10439                 :             :                     {
   10440                 :        1313 :                       mis_align = dr_misalignment (first_dr_info, ptype);
   10441                 :        1313 :                       if (maybe_gt (vf, 1u)
   10442                 :        2598 :                           && !multiple_p (DR_STEP_ALIGNMENT (first_dr_info->dr),
   10443                 :        1322 :                                           DR_TARGET_ALIGNMENT (first_dr_info)))
   10444                 :        1276 :                         mis_align = -1;
   10445                 :        1313 :                       dr_align
   10446                 :        1313 :                         = vect_supportable_dr_alignment (vinfo, dr_info, ptype,
   10447                 :             :                                                          mis_align);
   10448                 :             :                     }
   10449                 :             :                   else
   10450                 :             :                     dr_align = dr_unaligned_supported;
   10451                 :        2608 :                   if (dr_align == dr_aligned
   10452                 :        2608 :                       || dr_align == dr_unaligned_supported)
   10453                 :             :                     {
   10454                 :        2608 :                       nloads = const_nunits / n;
   10455                 :        2608 :                       lnel = n;
   10456                 :        2608 :                       lvectype = vtype;
   10457                 :        2608 :                       ltype = ptype;
   10458                 :        2608 :                       alignment_support_scheme = dr_align;
   10459                 :        2608 :                       misalignment = mis_align;
   10460                 :             :                     }
   10461                 :             :                 }
   10462                 :             :             }
   10463                 :       17607 :           unsigned align;
   10464                 :       17607 :           if (alignment_support_scheme == dr_aligned)
   10465                 :          16 :             align = known_alignment (DR_TARGET_ALIGNMENT (first_dr_info));
   10466                 :             :           else
   10467                 :       17591 :             align = dr_alignment (vect_dr_behavior (vinfo, first_dr_info));
   10468                 :             :           /* Alignment is at most the access size if we do multiple loads.  */
   10469                 :       17607 :           if (nloads > 1)
   10470                 :       15808 :             align = MIN (tree_to_uhwi (TYPE_SIZE_UNIT (ltype)), align);
   10471                 :       17607 :           ltype = build_aligned_type (ltype, align * BITS_PER_UNIT);
   10472                 :             :         }
   10473                 :             : 
   10474                 :             :       /* For SLP permutation support we need to load the whole group,
   10475                 :             :          not only the number of vector stmts the permutation result
   10476                 :             :          fits in.  */
   10477                 :       29234 :       if (slp_perm)
   10478                 :             :         {
   10479                 :             :           /* We don't yet generate SLP_TREE_LOAD_PERMUTATIONs for
   10480                 :             :              variable VF.  */
   10481                 :        3011 :           unsigned int const_vf = vf.to_constant ();
   10482                 :        3011 :           ncopies = CEIL (group_size * const_vf, const_nunits);
   10483                 :        3011 :           dr_chain.create (ncopies);
   10484                 :             :         }
   10485                 :             :       else
   10486                 :       26223 :         ncopies = SLP_TREE_NUMBER_OF_VEC_STMTS (slp_node);
   10487                 :             : 
   10488                 :       29234 :       unsigned int group_el = 0;
   10489                 :       29234 :       unsigned HOST_WIDE_INT
   10490                 :       29234 :         elsz = tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (vectype)));
   10491                 :       29234 :       unsigned int n_groups = 0;
   10492                 :             :       /* For costing some adjacent vector loads, we'd like to cost with
   10493                 :             :          the total number of them once instead of cost each one by one. */
   10494                 :       29234 :       unsigned int n_adjacent_loads = 0;
   10495                 :       69356 :       for (j = 0; j < ncopies; j++)
   10496                 :             :         {
   10497                 :       40122 :           if (nloads > 1 && !costing_p)
   10498                 :        2694 :             vec_alloc (v, nloads);
   10499                 :             :           gimple *new_stmt = NULL;
   10500                 :      171942 :           for (i = 0; i < nloads; i++)
   10501                 :             :             {
   10502                 :      131820 :               if (costing_p)
   10503                 :             :                 {
   10504                 :             :                   /* For VMAT_ELEMENTWISE, just cost it as scalar_load to
   10505                 :             :                      avoid ICE, see PR110776.  */
   10506                 :      122602 :                   if (VECTOR_TYPE_P (ltype)
   10507                 :        6034 :                       && memory_access_type != VMAT_ELEMENTWISE)
   10508                 :        6034 :                     n_adjacent_loads++;
   10509                 :             :                   else
   10510                 :      116568 :                     inside_cost += record_stmt_cost (cost_vec, 1, scalar_load,
   10511                 :             :                                                      slp_node, 0, vect_body);
   10512                 :      122602 :                   continue;
   10513                 :             :                 }
   10514                 :        9218 :               tree this_off = build_int_cst (TREE_TYPE (alias_off),
   10515                 :        9218 :                                              group_el * elsz + cst_offset);
   10516                 :        9218 :               tree data_ref = build2 (MEM_REF, ltype, running_off, this_off);
   10517                 :        9218 :               vect_copy_ref_info (data_ref, DR_REF (first_dr_info->dr));
   10518                 :        9218 :               new_temp = make_ssa_name (ltype);
   10519                 :        9218 :               new_stmt = gimple_build_assign (new_temp, data_ref);
   10520                 :        9218 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
   10521                 :        9218 :               if (nloads > 1)
   10522                 :        7862 :                 CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, new_temp);
   10523                 :             : 
   10524                 :        9218 :               group_el += lnel;
   10525                 :        9218 :               if (group_el == group_size)
   10526                 :             :                 {
   10527                 :        8912 :                   n_groups++;
   10528                 :             :                   /* When doing SLP make sure to not load elements from
   10529                 :             :                      the next vector iteration, those will not be accessed
   10530                 :             :                      so just use the last element again.  See PR107451.  */
   10531                 :        8912 :                   if (known_lt (n_groups, vf))
   10532                 :             :                     {
   10533                 :        5710 :                       tree newoff = copy_ssa_name (running_off);
   10534                 :        5710 :                       gimple *incr
   10535                 :        5710 :                         = gimple_build_assign (newoff, POINTER_PLUS_EXPR,
   10536                 :             :                                                running_off, stride_step);
   10537                 :        5710 :                       vect_finish_stmt_generation (vinfo, stmt_info, incr, gsi);
   10538                 :        5710 :                       running_off = newoff;
   10539                 :             :                     }
   10540                 :             :                   group_el = 0;
   10541                 :             :                 }
   10542                 :             :             }
   10543                 :             : 
   10544                 :       40122 :           if (nloads > 1)
   10545                 :             :             {
   10546                 :       34380 :               if (costing_p)
   10547                 :       31686 :                 inside_cost += record_stmt_cost (cost_vec, 1, vec_construct,
   10548                 :             :                                                  slp_node, 0, vect_body);
   10549                 :             :               else
   10550                 :             :                 {
   10551                 :        2694 :                   tree vec_inv = build_constructor (lvectype, v);
   10552                 :        2694 :                   new_temp = vect_init_vector (vinfo, stmt_info, vec_inv,
   10553                 :             :                                                lvectype, gsi);
   10554                 :        2694 :                   new_stmt = SSA_NAME_DEF_STMT (new_temp);
   10555                 :        2694 :                   if (lvectype != vectype)
   10556                 :             :                     {
   10557                 :         221 :                       new_stmt
   10558                 :         221 :                         = gimple_build_assign (make_ssa_name (vectype),
   10559                 :             :                                                VIEW_CONVERT_EXPR,
   10560                 :             :                                                build1 (VIEW_CONVERT_EXPR,
   10561                 :             :                                                        vectype, new_temp));
   10562                 :         221 :                       vect_finish_stmt_generation (vinfo, stmt_info, new_stmt,
   10563                 :             :                                                    gsi);
   10564                 :             :                     }
   10565                 :             :                 }
   10566                 :             :             }
   10567                 :        5742 :           else if (!costing_p && ltype != vectype)
   10568                 :             :             {
   10569                 :        1339 :               new_stmt = gimple_build_assign (make_ssa_name (vectype),
   10570                 :             :                                               VIEW_CONVERT_EXPR,
   10571                 :             :                                               build1 (VIEW_CONVERT_EXPR,
   10572                 :             :                                                       vectype, new_temp));
   10573                 :        1339 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt,
   10574                 :             :                                            gsi);
   10575                 :             :             }
   10576                 :             : 
   10577                 :       40122 :           if (!costing_p)
   10578                 :             :             {
   10579                 :        4050 :               if (slp_perm)
   10580                 :        1102 :                 dr_chain.quick_push (gimple_assign_lhs (new_stmt));
   10581                 :             :               else
   10582                 :        2948 :                 slp_node->push_vec_def (new_stmt);
   10583                 :             :             }
   10584                 :             :         }
   10585                 :       29234 :       if (slp_perm)
   10586                 :             :         {
   10587                 :        3011 :           unsigned n_perms;
   10588                 :        3011 :           if (costing_p)
   10589                 :             :             {
   10590                 :        2374 :               unsigned n_loads;
   10591                 :        2374 :               vect_transform_slp_perm_load (vinfo, slp_node, vNULL, NULL, vf,
   10592                 :             :                                             true, &n_perms, &n_loads);
   10593                 :        2374 :               inside_cost += record_stmt_cost (cost_vec, n_perms, vec_perm,
   10594                 :             :                                                slp_node, 0, vect_body);
   10595                 :             :             }
   10596                 :             :           else
   10597                 :         637 :             vect_transform_slp_perm_load (vinfo, slp_node, dr_chain, gsi, vf,
   10598                 :             :                                           false, &n_perms);
   10599                 :             :         }
   10600                 :             : 
   10601                 :       29234 :       if (costing_p)
   10602                 :             :         {
   10603                 :       26054 :           if (n_adjacent_loads > 0)
   10604                 :        2108 :             vect_get_load_cost (vinfo, stmt_info, slp_node, n_adjacent_loads,
   10605                 :             :                                 alignment_support_scheme, misalignment, false,
   10606                 :             :                                 &inside_cost, nullptr, cost_vec, cost_vec,
   10607                 :             :                                 true);
   10608                 :       26054 :           if (dump_enabled_p ())
   10609                 :         621 :             dump_printf_loc (MSG_NOTE, vect_location,
   10610                 :             :                              "vect_model_load_cost: inside_cost = %u, "
   10611                 :             :                              "prologue_cost = 0 .\n",
   10612                 :             :                              inside_cost);
   10613                 :             :         }
   10614                 :             : 
   10615                 :       29234 :       return true;
   10616                 :       29234 :     }
   10617                 :             : 
   10618                 :      541022 :   if (memory_access_type == VMAT_GATHER_SCATTER
   10619                 :      538014 :       || (!slp && memory_access_type == VMAT_CONTIGUOUS))
   10620                 :             :     grouped_load = false;
   10621                 :             : 
   10622                 :      538014 :   if (grouped_load
   10623                 :      541022 :       || (slp && SLP_TREE_LOAD_PERMUTATION (slp_node).exists ()))
   10624                 :             :     {
   10625                 :      266832 :       if (grouped_load)
   10626                 :             :         {
   10627                 :      266576 :           first_stmt_info = DR_GROUP_FIRST_ELEMENT (stmt_info);
   10628                 :      266576 :           group_size = DR_GROUP_SIZE (first_stmt_info);
   10629                 :             :         }
   10630                 :             :       else
   10631                 :             :         {
   10632                 :             :           first_stmt_info = stmt_info;
   10633                 :             :           group_size = 1;
   10634                 :             :         }
   10635                 :             :       /* For SLP vectorization we directly vectorize a subchain
   10636                 :             :          without permutation.  */
   10637                 :      266832 :       if (slp && ! SLP_TREE_LOAD_PERMUTATION (slp_node).exists ())
   10638                 :      218713 :         first_stmt_info = SLP_TREE_SCALAR_STMTS (slp_node)[0];
   10639                 :             :       /* For BB vectorization always use the first stmt to base
   10640                 :             :          the data ref pointer on.  */
   10641                 :      266832 :       if (bb_vinfo)
   10642                 :      217223 :         first_stmt_info_for_drptr
   10643                 :      217223 :           = vect_find_first_scalar_stmt_in_slp (slp_node);
   10644                 :             : 
   10645                 :             :       /* Check if the chain of loads is already vectorized.  */
   10646                 :      266832 :       if (STMT_VINFO_VEC_STMTS (first_stmt_info).exists ()
   10647                 :             :           /* For SLP we would need to copy over SLP_TREE_VEC_DEFS.
   10648                 :             :              ???  But we can only do so if there is exactly one
   10649                 :             :              as we have no way to get at the rest.  Leave the CSE
   10650                 :             :              opportunity alone.
   10651                 :             :              ???  With the group load eventually participating
   10652                 :             :              in multiple different permutations (having multiple
   10653                 :             :              slp nodes which refer to the same group) the CSE
   10654                 :             :              is even wrong code.  See PR56270.  */
   10655                 :      266832 :           && !slp)
   10656                 :             :         {
   10657                 :           0 :           *vec_stmt = STMT_VINFO_VEC_STMTS (stmt_info)[0];
   10658                 :           0 :           return true;
   10659                 :             :         }
   10660                 :      266832 :       first_dr_info = STMT_VINFO_DR_INFO (first_stmt_info);
   10661                 :      266832 :       group_gap_adj = 0;
   10662                 :             : 
   10663                 :             :       /* VEC_NUM is the number of vect stmts to be created for this group.  */
   10664                 :      266832 :       if (slp)
   10665                 :             :         {
   10666                 :      266832 :           grouped_load = false;
   10667                 :             :           /* If an SLP permutation is from N elements to N elements,
   10668                 :             :              and if one vector holds a whole number of N, we can load
   10669                 :             :              the inputs to the permutation in the same way as an
   10670                 :             :              unpermuted sequence.  In other cases we need to load the
   10671                 :             :              whole group, not only the number of vector stmts the
   10672                 :             :              permutation result fits in.  */
   10673                 :      266832 :           unsigned scalar_lanes = SLP_TREE_LANES (slp_node);
   10674                 :      266832 :           if (nested_in_vect_loop)
   10675                 :             :             /* We do not support grouped accesses in a nested loop,
   10676                 :             :                instead the access is contiguous but it might be
   10677                 :             :                permuted.  No gap adjustment is needed though.  */
   10678                 :           2 :             vec_num = SLP_TREE_NUMBER_OF_VEC_STMTS (slp_node);
   10679                 :      266830 :           else if (slp_perm
   10680                 :      266830 :                    && (group_size != scalar_lanes
   10681                 :        8381 :                        || !multiple_p (nunits, group_size)))
   10682                 :             :             {
   10683                 :             :               /* We don't yet generate such SLP_TREE_LOAD_PERMUTATIONs for
   10684                 :             :                  variable VF; see vect_transform_slp_perm_load.  */
   10685                 :       41836 :               unsigned int const_vf = vf.to_constant ();
   10686                 :       41836 :               unsigned int const_nunits = nunits.to_constant ();
   10687                 :       41836 :               vec_num = CEIL (group_size * const_vf, const_nunits);
   10688                 :       41836 :               group_gap_adj = vf * group_size - nunits * vec_num;
   10689                 :             :             }
   10690                 :             :           else
   10691                 :             :             {
   10692                 :      224994 :               vec_num = SLP_TREE_NUMBER_OF_VEC_STMTS (slp_node);
   10693                 :      224994 :               group_gap_adj
   10694                 :      224994 :                 = group_size - scalar_lanes;
   10695                 :             :             }
   10696                 :             :         }
   10697                 :             :       else
   10698                 :           0 :         vec_num = group_size;
   10699                 :             : 
   10700                 :      266832 :       ref_type = get_group_alias_ptr_type (first_stmt_info);
   10701                 :             :     }
   10702                 :             :   else
   10703                 :             :     {
   10704                 :      274190 :       first_stmt_info = stmt_info;
   10705                 :      274190 :       first_dr_info = dr_info;
   10706                 :      274190 :       group_size = vec_num = 1;
   10707                 :      274190 :       group_gap_adj = 0;
   10708                 :      274190 :       ref_type = reference_alias_ptr_type (DR_REF (first_dr_info->dr));
   10709                 :      274190 :       if (slp)
   10710                 :      274190 :         vec_num = SLP_TREE_NUMBER_OF_VEC_STMTS (slp_node);
   10711                 :             :     }
   10712                 :             : 
   10713                 :      541022 :   gcc_assert (alignment_support_scheme);
   10714                 :      541022 :   vec_loop_masks *loop_masks
   10715                 :      323799 :     = (loop_vinfo && LOOP_VINFO_FULLY_MASKED_P (loop_vinfo)
   10716                 :      541022 :        ? &LOOP_VINFO_MASKS (loop_vinfo)
   10717                 :          16 :        : NULL);
   10718                 :          16 :   vec_loop_lens *loop_lens
   10719                 :      323799 :     = (loop_vinfo && LOOP_VINFO_FULLY_WITH_LENGTH_P (loop_vinfo)
   10720                 :             :        ? &LOOP_VINFO_LENS (loop_vinfo)
   10721                 :           0 :        : NULL);
   10722                 :             : 
   10723                 :             :   /* The vect_transform_stmt and vect_analyze_stmt will go here but there
   10724                 :             :      are some difference here.  We cannot enable both the lens and masks
   10725                 :             :      during transform but it is allowed during analysis.
   10726                 :             :      Shouldn't go with length-based approach if fully masked.  */
   10727                 :      541022 :   if (cost_vec == NULL)
   10728                 :             :     /* The cost_vec is NULL during transfrom.  */
   10729                 :      153350 :     gcc_assert ((!loop_lens || !loop_masks));
   10730                 :             : 
   10731                 :             :   /* Targets with store-lane instructions must not require explicit
   10732                 :             :      realignment.  vect_supportable_dr_alignment always returns either
   10733                 :             :      dr_aligned or dr_unaligned_supported for masked operations.  */
   10734                 :      541022 :   gcc_assert ((memory_access_type != VMAT_LOAD_STORE_LANES
   10735                 :             :                && !mask
   10736                 :             :                && !loop_masks)
   10737                 :             :               || alignment_support_scheme == dr_aligned
   10738                 :             :               || alignment_support_scheme == dr_unaligned_supported);
   10739                 :             : 
   10740                 :             :   /* In case the vectorization factor (VF) is bigger than the number
   10741                 :             :      of elements that we can fit in a vectype (nunits), we have to generate
   10742                 :             :      more than one vector stmt - i.e - we need to "unroll" the
   10743                 :             :      vector stmt by a factor VF/nunits.  In doing so, we record a pointer
   10744                 :             :      from one copy of the vector stmt to the next, in the field
   10745                 :             :      STMT_VINFO_RELATED_STMT.  This is necessary in order to allow following
   10746                 :             :      stages to find the correct vector defs to be used when vectorizing
   10747                 :             :      stmts that use the defs of the current stmt.  The example below
   10748                 :             :      illustrates the vectorization process when VF=16 and nunits=4 (i.e., we
   10749                 :             :      need to create 4 vectorized stmts):
   10750                 :             : 
   10751                 :             :      before vectorization:
   10752                 :             :                                 RELATED_STMT    VEC_STMT
   10753                 :             :         S1:     x = memref      -               -
   10754                 :             :         S2:     z = x + 1       -               -
   10755                 :             : 
   10756                 :             :      step 1: vectorize stmt S1:
   10757                 :             :         We first create the vector stmt VS1_0, and, as usual, record a
   10758                 :             :         pointer to it in the STMT_VINFO_VEC_STMT of the scalar stmt S1.
   10759                 :             :         Next, we create the vector stmt VS1_1, and record a pointer to
   10760                 :             :         it in the STMT_VINFO_RELATED_STMT of the vector stmt VS1_0.
   10761                 :             :         Similarly, for VS1_2 and VS1_3.  This is the resulting chain of
   10762                 :             :         stmts and pointers:
   10763                 :             :                                 RELATED_STMT    VEC_STMT
   10764                 :             :         VS1_0:  vx0 = memref0   VS1_1           -
   10765                 :             :         VS1_1:  vx1 = memref1   VS1_2           -
   10766                 :             :         VS1_2:  vx2 = memref2   VS1_3           -
   10767                 :             :         VS1_3:  vx3 = memref3   -               -
   10768                 :             :         S1:     x = load        -               VS1_0
   10769                 :             :         S2:     z = x + 1       -               -
   10770                 :             :   */
   10771                 :             : 
   10772                 :             :   /* In case of interleaving (non-unit grouped access):
   10773                 :             : 
   10774                 :             :      S1:  x2 = &base + 2
   10775                 :             :      S2:  x0 = &base
   10776                 :             :      S3:  x1 = &base + 1
   10777                 :             :      S4:  x3 = &base + 3
   10778                 :             : 
   10779                 :             :      Vectorized loads are created in the order of memory accesses
   10780                 :             :      starting from the access of the first stmt of the chain:
   10781                 :             : 
   10782                 :             :      VS1: vx0 = &base
   10783                 :             :      VS2: vx1 = &base + vec_size*1
   10784                 :             :      VS3: vx3 = &base + vec_size*2
   10785                 :             :      VS4: vx4 = &base + vec_size*3
   10786                 :             : 
   10787                 :             :      Then permutation statements are generated:
   10788                 :             : 
   10789                 :             :      VS5: vx5 = VEC_PERM_EXPR < vx0, vx1, { 0, 2, ..., i*2 } >
   10790                 :             :      VS6: vx6 = VEC_PERM_EXPR < vx0, vx1, { 1, 3, ..., i*2+1 } >
   10791                 :             :        ...
   10792                 :             : 
   10793                 :             :      And they are put in STMT_VINFO_VEC_STMT of the corresponding scalar stmts
   10794                 :             :      (the order of the data-refs in the output of vect_permute_load_chain
   10795                 :             :      corresponds to the order of scalar stmts in the interleaving chain - see
   10796                 :             :      the documentation of vect_permute_load_chain()).
   10797                 :             :      The generation of permutation stmts and recording them in
   10798                 :             :      STMT_VINFO_VEC_STMT is done in vect_transform_grouped_load().
   10799                 :             : 
   10800                 :             :      In case of both multiple types and interleaving, the vector loads and
   10801                 :             :      permutation stmts above are created for every copy.  The result vector
   10802                 :             :      stmts are put in STMT_VINFO_VEC_STMT for the first copy and in the
   10803                 :             :      corresponding STMT_VINFO_RELATED_STMT for the next copies.  */
   10804                 :             : 
   10805                 :             :   /* If the data reference is aligned (dr_aligned) or potentially unaligned
   10806                 :             :      on a target that supports unaligned accesses (dr_unaligned_supported)
   10807                 :             :      we generate the following code:
   10808                 :             :          p = initial_addr;
   10809                 :             :          indx = 0;
   10810                 :             :          loop {
   10811                 :             :            p = p + indx * vectype_size;
   10812                 :             :            vec_dest = *(p);
   10813                 :             :            indx = indx + 1;
   10814                 :             :          }
   10815                 :             : 
   10816                 :             :      Otherwise, the data reference is potentially unaligned on a target that
   10817                 :             :      does not support unaligned accesses (dr_explicit_realign_optimized) -
   10818                 :             :      then generate the following code, in which the data in each iteration is
   10819                 :             :      obtained by two vector loads, one from the previous iteration, and one
   10820                 :             :      from the current iteration:
   10821                 :             :          p1 = initial_addr;
   10822                 :             :          msq_init = *(floor(p1))
   10823                 :             :          p2 = initial_addr + VS - 1;
   10824                 :             :          realignment_token = call target_builtin;
   10825                 :             :          indx = 0;
   10826                 :             :          loop {
   10827                 :             :            p2 = p2 + indx * vectype_size
   10828                 :             :            lsq = *(floor(p2))
   10829                 :             :            vec_dest = realign_load (msq, lsq, realignment_token)
   10830                 :             :            indx = indx + 1;
   10831                 :             :            msq = lsq;
   10832                 :             :          }   */
   10833                 :             : 
   10834                 :             :   /* If the misalignment remains the same throughout the execution of the
   10835                 :             :      loop, we can create the init_addr and permutation mask at the loop
   10836                 :             :      preheader.  Otherwise, it needs to be created inside the loop.
   10837                 :             :      This can only occur when vectorizing memory accesses in the inner-loop
   10838                 :             :      nested within an outer-loop that is being vectorized.  */
   10839                 :             : 
   10840                 :      541022 :   if (nested_in_vect_loop
   10841                 :      541022 :       && !multiple_p (DR_STEP_ALIGNMENT (dr_info->dr),
   10842                 :        1300 :                       GET_MODE_SIZE (TYPE_MODE (vectype))))
   10843                 :             :     {
   10844                 :         211 :       gcc_assert (alignment_support_scheme != dr_explicit_realign_optimized);
   10845                 :             :       compute_in_loop = true;
   10846                 :             :     }
   10847                 :             : 
   10848                 :      541022 :   bool diff_first_stmt_info
   10849                 :      541022 :     = first_stmt_info_for_drptr && first_stmt_info != first_stmt_info_for_drptr;
   10850                 :             : 
   10851                 :      541022 :   tree offset = NULL_TREE;
   10852                 :      541022 :   if ((alignment_support_scheme == dr_explicit_realign_optimized
   10853                 :      541022 :        || alignment_support_scheme == dr_explicit_realign)
   10854                 :           0 :       && !compute_in_loop)
   10855                 :             :     {
   10856                 :             :       /* If we have different first_stmt_info, we can't set up realignment
   10857                 :             :          here, since we can't guarantee first_stmt_info DR has been
   10858                 :             :          initialized yet, use first_stmt_info_for_drptr DR by bumping the
   10859                 :             :          distance from first_stmt_info DR instead as below.  */
   10860                 :           0 :       if (!costing_p)
   10861                 :             :         {
   10862                 :           0 :           if (!diff_first_stmt_info)
   10863                 :           0 :             msq = vect_setup_realignment (vinfo, first_stmt_info, gsi,
   10864                 :             :                                           &realignment_token,
   10865                 :             :                                           alignment_support_scheme, NULL_TREE,
   10866                 :             :                                           &at_loop);
   10867                 :           0 :           if (alignment_support_scheme == dr_explicit_realign_optimized)
   10868                 :             :             {
   10869                 :           0 :               phi = as_a<gphi *> (SSA_NAME_DEF_STMT (msq));
   10870                 :           0 :               offset = size_binop (MINUS_EXPR, TYPE_SIZE_UNIT (vectype),
   10871                 :             :                                    size_one_node);
   10872                 :           0 :               gcc_assert (!first_stmt_info_for_drptr);
   10873                 :             :             }
   10874                 :             :         }
   10875                 :             :     }
   10876                 :             :   else
   10877                 :      541022 :     at_loop = loop;
   10878                 :             : 
   10879                 :      541022 :   if (!known_eq (poffset, 0))
   10880                 :        4927 :     offset = (offset
   10881                 :        4927 :               ? size_binop (PLUS_EXPR, offset, size_int (poffset))
   10882                 :        4927 :               : size_int (poffset));
   10883                 :             : 
   10884                 :      541022 :   tree bump;
   10885                 :      541022 :   tree vec_offset = NULL_TREE;
   10886                 :      541022 :   if (STMT_VINFO_GATHER_SCATTER_P (stmt_info))
   10887                 :             :     {
   10888                 :        3008 :       aggr_type = NULL_TREE;
   10889                 :        3008 :       bump = NULL_TREE;
   10890                 :             :     }
   10891                 :      538014 :   else if (memory_access_type == VMAT_GATHER_SCATTER)
   10892                 :             :     {
   10893                 :           0 :       aggr_type = elem_type;
   10894                 :           0 :       if (!costing_p)
   10895                 :           0 :         vect_get_strided_load_store_ops (stmt_info, loop_vinfo, gsi, &gs_info,
   10896                 :             :                                          &bump, &vec_offset, loop_lens);
   10897                 :             :     }
   10898                 :             :   else
   10899                 :             :     {
   10900                 :      538014 :       if (memory_access_type == VMAT_LOAD_STORE_LANES)
   10901                 :           0 :         aggr_type = build_array_type_nelts (elem_type, group_size * nunits);
   10902                 :             :       else
   10903                 :             :         aggr_type = vectype;
   10904                 :      538014 :       if (!costing_p)
   10905                 :      152608 :         bump = vect_get_data_ptr_increment (vinfo, gsi, dr_info, aggr_type,
   10906                 :             :                                             memory_access_type, loop_lens);
   10907                 :             :     }
   10908                 :             : 
   10909                 :      541022 :   auto_vec<tree> vec_offsets;
   10910                 :      541022 :   auto_vec<tree> vec_masks;
   10911                 :      541022 :   if (mask && !costing_p)
   10912                 :             :     {
   10913                 :         574 :       if (slp_node)
   10914                 :         574 :         vect_get_slp_defs (SLP_TREE_CHILDREN (slp_node)[mask_index],
   10915                 :             :                            &vec_masks);
   10916                 :             :       else
   10917                 :           0 :         vect_get_vec_defs_for_operand (vinfo, stmt_info, ncopies, mask,
   10918                 :             :                                        &vec_masks, mask_vectype);
   10919                 :             :     }
   10920                 :             : 
   10921                 :      541022 :   tree vec_mask = NULL_TREE;
   10922                 :      541022 :   tree vec_els = NULL_TREE;
   10923                 :      541022 :   if (memory_access_type == VMAT_LOAD_STORE_LANES)
   10924                 :             :     {
   10925                 :           0 :       gcc_assert (alignment_support_scheme == dr_aligned
   10926                 :             :                   || alignment_support_scheme == dr_unaligned_supported);
   10927                 :             : 
   10928                 :           0 :       unsigned int inside_cost = 0, prologue_cost = 0;
   10929                 :             :       /* For costing some adjacent vector loads, we'd like to cost with
   10930                 :             :          the total number of them once instead of cost each one by one. */
   10931                 :           0 :       unsigned int n_adjacent_loads = 0;
   10932                 :           0 :       if (slp_node)
   10933                 :           0 :         ncopies = slp_node->vec_stmts_size / group_size;
   10934                 :           0 :       for (j = 0; j < ncopies; j++)
   10935                 :             :         {
   10936                 :           0 :           if (costing_p)
   10937                 :             :             {
   10938                 :             :               /* An IFN_LOAD_LANES will load all its vector results,
   10939                 :             :                  regardless of which ones we actually need.  Account
   10940                 :             :                  for the cost of unused results.  */
   10941                 :           0 :               if (first_stmt_info == stmt_info)
   10942                 :             :                 {
   10943                 :           0 :                   unsigned int gaps = DR_GROUP_SIZE (first_stmt_info);
   10944                 :           0 :                   stmt_vec_info next_stmt_info = first_stmt_info;
   10945                 :           0 :                   do
   10946                 :             :                     {
   10947                 :           0 :                       gaps -= 1;
   10948                 :           0 :                       next_stmt_info = DR_GROUP_NEXT_ELEMENT (next_stmt_info);
   10949                 :             :                     }
   10950                 :           0 :                   while (next_stmt_info);
   10951                 :           0 :                   if (gaps)
   10952                 :             :                     {
   10953                 :           0 :                       if (dump_enabled_p ())
   10954                 :           0 :                         dump_printf_loc (MSG_NOTE, vect_location,
   10955                 :             :                                          "vect_model_load_cost: %d "
   10956                 :             :                                          "unused vectors.\n",
   10957                 :             :                                          gaps);
   10958                 :           0 :                       vect_get_load_cost (vinfo, stmt_info, slp_node, gaps,
   10959                 :             :                                           alignment_support_scheme,
   10960                 :             :                                           misalignment, false, &inside_cost,
   10961                 :             :                                           &prologue_cost, cost_vec, cost_vec,
   10962                 :             :                                           true);
   10963                 :             :                     }
   10964                 :             :                 }
   10965                 :           0 :               n_adjacent_loads++;
   10966                 :           0 :               continue;
   10967                 :           0 :             }
   10968                 :             : 
   10969                 :             :           /* 1. Create the vector or array pointer update chain.  */
   10970                 :           0 :           if (j == 0)
   10971                 :           0 :             dataref_ptr
   10972                 :           0 :               = vect_create_data_ref_ptr (vinfo, first_stmt_info, aggr_type,
   10973                 :             :                                           at_loop, offset, &dummy, gsi,
   10974                 :             :                                           &ptr_incr, false, bump);
   10975                 :             :           else
   10976                 :             :             {
   10977                 :           0 :               gcc_assert (!LOOP_VINFO_USING_SELECT_VL_P (loop_vinfo));
   10978                 :           0 :               dataref_ptr = bump_vector_ptr (vinfo, dataref_ptr, ptr_incr, gsi,
   10979                 :             :                                              stmt_info, bump);
   10980                 :             :             }
   10981                 :           0 :           if (mask)
   10982                 :           0 :             vec_mask = vec_masks[j];
   10983                 :             : 
   10984                 :           0 :           tree vec_array = create_vector_array (vectype, group_size);
   10985                 :             : 
   10986                 :           0 :           tree final_mask = NULL_TREE;
   10987                 :           0 :           tree final_len = NULL_TREE;
   10988                 :           0 :           tree bias = NULL_TREE;
   10989                 :           0 :           if (loop_masks)
   10990                 :           0 :             final_mask = vect_get_loop_mask (loop_vinfo, gsi, loop_masks,
   10991                 :             :                                              ncopies, vectype, j);
   10992                 :           0 :           if (vec_mask)
   10993                 :           0 :             final_mask = prepare_vec_mask (loop_vinfo, mask_vectype, final_mask,
   10994                 :             :                                            vec_mask, gsi);
   10995                 :             : 
   10996                 :           0 :           if (lanes_ifn == IFN_MASK_LEN_LOAD_LANES)
   10997                 :             :             {
   10998                 :           0 :               if (loop_lens)
   10999                 :           0 :                 final_len = vect_get_loop_len (loop_vinfo, gsi, loop_lens,
   11000                 :             :                                                ncopies, vectype, j, 1);
   11001                 :             :               else
   11002                 :           0 :                 final_len = size_int (TYPE_VECTOR_SUBPARTS (vectype));
   11003                 :           0 :               signed char biasval
   11004                 :           0 :                 = LOOP_VINFO_PARTIAL_LOAD_STORE_BIAS (loop_vinfo);
   11005                 :           0 :               bias = build_int_cst (intQI_type_node, biasval);
   11006                 :           0 :               if (!final_mask)
   11007                 :             :                 {
   11008                 :           0 :                   mask_vectype = truth_type_for (vectype);
   11009                 :           0 :                   final_mask = build_minus_one_cst (mask_vectype);
   11010                 :             :                 }
   11011                 :             :             }
   11012                 :             : 
   11013                 :           0 :           if (final_mask)
   11014                 :             :             {
   11015                 :           0 :               vec_els = vect_get_mask_load_else (maskload_elsval, vectype);
   11016                 :           0 :               if (type_mode_padding_p
   11017                 :           0 :                   && maskload_elsval != MASK_LOAD_ELSE_ZERO)
   11018                 :           0 :                 need_zeroing = true;
   11019                 :             :             }
   11020                 :             : 
   11021                 :           0 :           gcall *call;
   11022                 :           0 :           if (final_len && final_mask)
   11023                 :             :             {
   11024                 :             :               /* Emit:
   11025                 :             :                    VEC_ARRAY = MASK_LEN_LOAD_LANES (DATAREF_PTR, ALIAS_PTR,
   11026                 :             :                                                     VEC_MASK, LEN, BIAS).  */
   11027                 :           0 :               unsigned int align = TYPE_ALIGN (TREE_TYPE (vectype));
   11028                 :           0 :               tree alias_ptr = build_int_cst (ref_type, align);
   11029                 :           0 :               call = gimple_build_call_internal (IFN_MASK_LEN_LOAD_LANES, 6,
   11030                 :             :                                                  dataref_ptr, alias_ptr,
   11031                 :             :                                                  final_mask, vec_els,
   11032                 :             :                                                  final_len, bias);
   11033                 :             :             }
   11034                 :           0 :           else if (final_mask)
   11035                 :             :             {
   11036                 :             :               /* Emit:
   11037                 :             :                    VEC_ARRAY = MASK_LOAD_LANES (DATAREF_PTR, ALIAS_PTR,
   11038                 :             :                                                 VEC_MASK).  */
   11039                 :           0 :               unsigned int align = TYPE_ALIGN (TREE_TYPE (vectype));
   11040                 :           0 :               tree alias_ptr = build_int_cst (ref_type, align);
   11041                 :           0 :               call = gimple_build_call_internal (IFN_MASK_LOAD_LANES, 4,
   11042                 :             :                                                  dataref_ptr, alias_ptr,
   11043                 :             :                                                  final_mask, vec_els);
   11044                 :             :             }
   11045                 :             :           else
   11046                 :             :             {
   11047                 :             :               /* Emit:
   11048                 :             :                    VEC_ARRAY = LOAD_LANES (MEM_REF[...all elements...]).  */
   11049                 :           0 :               data_ref = create_array_ref (aggr_type, dataref_ptr, ref_type);
   11050                 :           0 :               call = gimple_build_call_internal (IFN_LOAD_LANES, 1, data_ref);
   11051                 :             :             }
   11052                 :           0 :           gimple_call_set_lhs (call, vec_array);
   11053                 :           0 :           gimple_call_set_nothrow (call, true);
   11054                 :           0 :           vect_finish_stmt_generation (vinfo, stmt_info, call, gsi);
   11055                 :             : 
   11056                 :           0 :           if (!slp)
   11057                 :           0 :             dr_chain.create (group_size);
   11058                 :             :           /* Extract each vector into an SSA_NAME.  */
   11059                 :           0 :           for (unsigned i = 0; i < group_size; i++)
   11060                 :             :             {
   11061                 :           0 :               new_temp = read_vector_array (vinfo, stmt_info, gsi, scalar_dest,
   11062                 :             :                                             vec_array, i, need_zeroing,
   11063                 :             :                                             final_mask);
   11064                 :           0 :               if (slp)
   11065                 :           0 :                 slp_node->push_vec_def (new_temp);
   11066                 :             :               else
   11067                 :           0 :                 dr_chain.quick_push (new_temp);
   11068                 :             :             }
   11069                 :             : 
   11070                 :           0 :           if (!slp)
   11071                 :             :             /* Record the mapping between SSA_NAMEs and statements.  */
   11072                 :           0 :             vect_record_grouped_load_vectors (vinfo, stmt_info, dr_chain);
   11073                 :             : 
   11074                 :             :           /* Record that VEC_ARRAY is now dead.  */
   11075                 :           0 :           vect_clobber_variable (vinfo, stmt_info, gsi, vec_array);
   11076                 :             : 
   11077                 :           0 :           if (!slp)
   11078                 :           0 :             dr_chain.release ();
   11079                 :             : 
   11080                 :           0 :           if (!slp_node)
   11081                 :           0 :             *vec_stmt = STMT_VINFO_VEC_STMTS (stmt_info)[0];
   11082                 :             :         }
   11083                 :             : 
   11084                 :           0 :       if (costing_p)
   11085                 :             :         {
   11086                 :           0 :           if (n_adjacent_loads > 0)
   11087                 :           0 :             vect_get_load_cost (vinfo, stmt_info, slp_node, n_adjacent_loads,
   11088                 :             :                                 alignment_support_scheme, misalignment, false,
   11089                 :             :                                 &inside_cost, &prologue_cost, cost_vec,
   11090                 :             :                                 cost_vec, true);
   11091                 :           0 :           if (dump_enabled_p ())
   11092                 :           0 :             dump_printf_loc (MSG_NOTE, vect_location,
   11093                 :             :                              "vect_model_load_cost: inside_cost = %u, "
   11094                 :             :                              "prologue_cost = %u .\n",
   11095                 :             :                              inside_cost, prologue_cost);
   11096                 :             :         }
   11097                 :             : 
   11098                 :           0 :       return true;
   11099                 :             :     }
   11100                 :             : 
   11101                 :      541022 :   if (memory_access_type == VMAT_GATHER_SCATTER)
   11102                 :             :     {
   11103                 :        3008 :       gcc_assert (alignment_support_scheme == dr_aligned
   11104                 :             :                   || alignment_support_scheme == dr_unaligned_supported);
   11105                 :        3008 :       gcc_assert (!grouped_load && !slp_perm);
   11106                 :             : 
   11107                 :             :       unsigned int inside_cost = 0, prologue_cost = 0;
   11108                 :        6016 :       for (j = 0; j < ncopies; j++)
   11109                 :             :         {
   11110                 :             :           /* 1. Create the vector or array pointer update chain.  */
   11111                 :        3008 :           if (j == 0 && !costing_p)
   11112                 :             :             {
   11113                 :         742 :               if (STMT_VINFO_GATHER_SCATTER_P (stmt_info))
   11114                 :         742 :                 vect_get_gather_scatter_ops (loop_vinfo, loop, stmt_info,
   11115                 :             :                                              slp_node, &gs_info, &dataref_ptr,
   11116                 :             :                                              &vec_offsets);
   11117                 :             :               else
   11118                 :           0 :                 dataref_ptr
   11119                 :           0 :                   = vect_create_data_ref_ptr (vinfo, first_stmt_info, aggr_type,
   11120                 :             :                                               at_loop, offset, &dummy, gsi,
   11121                 :             :                                               &ptr_incr, false, bump);
   11122                 :             :             }
   11123                 :        2266 :           else if (!costing_p)
   11124                 :             :             {
   11125                 :           0 :               gcc_assert (!LOOP_VINFO_USING_SELECT_VL_P (loop_vinfo));
   11126                 :           0 :               if (!STMT_VINFO_GATHER_SCATTER_P (stmt_info))
   11127                 :           0 :                 dataref_ptr = bump_vector_ptr (vinfo, dataref_ptr, ptr_incr,
   11128                 :             :                                                gsi, stmt_info, bump);
   11129                 :             :             }
   11130                 :             : 
   11131                 :        3008 :           gimple *new_stmt = NULL;
   11132                 :        6904 :           for (i = 0; i < vec_num; i++)
   11133                 :             :             {
   11134                 :        3896 :               tree final_mask = NULL_TREE;
   11135                 :        3896 :               tree final_len = NULL_TREE;
   11136                 :        3896 :               tree bias = NULL_TREE;
   11137                 :        3896 :               if (!costing_p)
   11138                 :             :                 {
   11139                 :         954 :                   if (mask)
   11140                 :         153 :                     vec_mask = vec_masks[vec_num * j + i];
   11141                 :         954 :                   if (loop_masks)
   11142                 :           0 :                     final_mask
   11143                 :           0 :                       = vect_get_loop_mask (loop_vinfo, gsi, loop_masks,
   11144                 :           0 :                                             vec_num * ncopies, vectype,
   11145                 :           0 :                                             vec_num * j + i);
   11146                 :         954 :                   if (vec_mask)
   11147                 :         153 :                     final_mask = prepare_vec_mask (loop_vinfo, mask_vectype,
   11148                 :             :                                                    final_mask, vec_mask, gsi);
   11149                 :             : 
   11150                 :         954 :                   if (i > 0 && !STMT_VINFO_GATHER_SCATTER_P (stmt_info))
   11151                 :           0 :                     dataref_ptr = bump_vector_ptr (vinfo, dataref_ptr, ptr_incr,
   11152                 :             :                                                    gsi, stmt_info, bump);
   11153                 :             :                 }
   11154                 :             : 
   11155                 :             :               /* 2. Create the vector-load in the loop.  */
   11156                 :        3896 :               unsigned HOST_WIDE_INT align;
   11157                 :        3896 :               if (gs_info.ifn != IFN_LAST)
   11158                 :             :                 {
   11159                 :           0 :                   if (costing_p)
   11160                 :             :                     {
   11161                 :           0 :                       unsigned int cnunits = vect_nunits_for_cost (vectype);
   11162                 :           0 :                       inside_cost
   11163                 :           0 :                         = record_stmt_cost (cost_vec, cnunits, scalar_load,
   11164                 :             :                                             slp_node, 0, vect_body);
   11165                 :           0 :                       continue;
   11166                 :           0 :                     }
   11167                 :           0 :                   if (STMT_VINFO_GATHER_SCATTER_P (stmt_info))
   11168                 :           0 :                     vec_offset = vec_offsets[vec_num * j + i];
   11169                 :           0 :                   tree zero = build_zero_cst (vectype);
   11170                 :           0 :                   tree scale = size_int (gs_info.scale);
   11171                 :             : 
   11172                 :           0 :                   if (gs_info.ifn == IFN_MASK_LEN_GATHER_LOAD)
   11173                 :             :                     {
   11174                 :           0 :                       if (loop_lens)
   11175                 :           0 :                         final_len
   11176                 :           0 :                           = vect_get_loop_len (loop_vinfo, gsi, loop_lens,
   11177                 :           0 :                                                vec_num * ncopies, vectype,
   11178                 :           0 :                                                vec_num * j + i, 1);
   11179                 :             :                       else
   11180                 :           0 :                         final_len
   11181                 :           0 :                           = build_int_cst (sizetype,
   11182                 :           0 :                                            TYPE_VECTOR_SUBPARTS (vectype));
   11183                 :           0 :                       signed char biasval
   11184                 :           0 :                         = LOOP_VINFO_PARTIAL_LOAD_STORE_BIAS (loop_vinfo);
   11185                 :           0 :                       bias = build_int_cst (intQI_type_node, biasval);
   11186                 :           0 :                       if (!final_mask)
   11187                 :             :                         {
   11188                 :           0 :                           mask_vectype = truth_type_for (vectype);
   11189                 :           0 :                           final_mask = build_minus_one_cst (mask_vectype);
   11190                 :             :                         }
   11191                 :             :                     }
   11192                 :             : 
   11193                 :           0 :                   if (final_mask)
   11194                 :             :                     {
   11195                 :           0 :                       vec_els = vect_get_mask_load_else
   11196                 :           0 :                         (maskload_elsval, vectype);
   11197                 :           0 :                       if (type_mode_padding_p
   11198                 :           0 :                           && maskload_elsval != MASK_LOAD_ELSE_ZERO)
   11199                 :           0 :                         need_zeroing = true;
   11200                 :             :                     }
   11201                 :             : 
   11202                 :           0 :                   gcall *call;
   11203                 :           0 :                   if (final_len && final_mask)
   11204                 :             :                     {
   11205                 :           0 :                       if (VECTOR_TYPE_P (TREE_TYPE (vec_offset)))
   11206                 :           0 :                         call = gimple_build_call_internal (
   11207                 :             :                           IFN_MASK_LEN_GATHER_LOAD, 8, dataref_ptr, vec_offset,
   11208                 :             :                           scale, zero, final_mask, vec_els, final_len, bias);
   11209                 :             :                       else
   11210                 :             :                         /* Non-vector offset indicates that prefer to take
   11211                 :             :                            MASK_LEN_STRIDED_LOAD instead of the
   11212                 :             :                            MASK_LEN_GATHER_LOAD with direct stride arg.  */
   11213                 :           0 :                         call = gimple_build_call_internal (
   11214                 :             :                           IFN_MASK_LEN_STRIDED_LOAD, 7, dataref_ptr, vec_offset,
   11215                 :             :                           zero, final_mask, vec_els, final_len, bias);
   11216                 :             :                     }
   11217                 :           0 :                   else if (final_mask)
   11218                 :           0 :                     call = gimple_build_call_internal (IFN_MASK_GATHER_LOAD,
   11219                 :             :                                                        6, dataref_ptr,
   11220                 :             :                                                        vec_offset, scale,
   11221                 :             :                                                        zero, final_mask,
   11222                 :             :                                                        vec_els);
   11223                 :             :                   else
   11224                 :           0 :                     call = gimple_build_call_internal (IFN_GATHER_LOAD, 4,
   11225                 :             :                                                        dataref_ptr, vec_offset,
   11226                 :             :                                                        scale, zero);
   11227                 :           0 :                   gimple_call_set_nothrow (call, true);
   11228                 :           0 :                   new_stmt = call;
   11229                 :           0 :                   data_ref = NULL_TREE;
   11230                 :             :                 }
   11231                 :        3896 :               else if (gs_info.decl)
   11232                 :             :                 {
   11233                 :             :                   /* The builtin decls path for gather is legacy, x86 only.  */
   11234                 :         657 :                   gcc_assert (!final_len && nunits.is_constant ());
   11235                 :         657 :                   if (costing_p)
   11236                 :             :                     {
   11237                 :         376 :                       unsigned int cnunits = vect_nunits_for_cost (vectype);
   11238                 :         376 :                       inside_cost
   11239                 :         376 :                         = record_stmt_cost (cost_vec, cnunits, scalar_load,
   11240                 :             :                                             slp_node, 0, vect_body);
   11241                 :         376 :                       continue;
   11242                 :         376 :                     }
   11243                 :         281 :                   poly_uint64 offset_nunits
   11244                 :         281 :                     = TYPE_VECTOR_SUBPARTS (gs_info.offset_vectype);
   11245                 :         281 :                   if (known_eq (nunits, offset_nunits))
   11246                 :             :                     {
   11247                 :         264 :                       new_stmt = vect_build_one_gather_load_call
   11248                 :         132 :                                    (vinfo, stmt_info, gsi, &gs_info,
   11249                 :         132 :                                     dataref_ptr, vec_offsets[vec_num * j + i],
   11250                 :             :                                     final_mask);
   11251                 :         132 :                       data_ref = NULL_TREE;
   11252                 :             :                     }
   11253                 :         149 :                   else if (known_eq (nunits, offset_nunits * 2))
   11254                 :             :                     {
   11255                 :             :                       /* We have a offset vector with half the number of
   11256                 :             :                          lanes but the builtins will produce full vectype
   11257                 :             :                          data with just the lower lanes filled.  */
   11258                 :          63 :                       new_stmt = vect_build_one_gather_load_call
   11259                 :          63 :                           (vinfo, stmt_info, gsi, &gs_info,
   11260                 :          63 :                            dataref_ptr, vec_offsets[2 * vec_num * j + 2 * i],
   11261                 :             :                            final_mask);
   11262                 :          63 :                       tree low = make_ssa_name (vectype);
   11263                 :          63 :                       gimple_set_lhs (new_stmt, low);
   11264                 :          63 :                       vect_finish_stmt_generation (vinfo, stmt_info,
   11265                 :             :                                                    new_stmt, gsi);
   11266                 :             : 
   11267                 :             :                       /* now put upper half of final_mask in final_mask low. */
   11268                 :          63 :                       if (final_mask
   11269                 :          63 :                           && !SCALAR_INT_MODE_P
   11270                 :             :                                 (TYPE_MODE (TREE_TYPE (final_mask))))
   11271                 :             :                         {
   11272                 :          10 :                           int count = nunits.to_constant ();
   11273                 :          10 :                           vec_perm_builder sel (count, count, 1);
   11274                 :          10 :                           sel.quick_grow (count);
   11275                 :          78 :                           for (int i = 0; i < count; ++i)
   11276                 :          68 :                             sel[i] = i | (count / 2);
   11277                 :          10 :                           vec_perm_indices indices (sel, 2, count);
   11278                 :          10 :                           tree perm_mask = vect_gen_perm_mask_checked
   11279                 :          10 :                                              (TREE_TYPE (final_mask), indices);
   11280                 :          10 :                           new_stmt = gimple_build_assign (NULL_TREE,
   11281                 :             :                                                           VEC_PERM_EXPR,
   11282                 :             :                                                           final_mask,
   11283                 :             :                                                           final_mask,
   11284                 :             :                                                           perm_mask);
   11285                 :          10 :                           final_mask = make_ssa_name (TREE_TYPE (final_mask));
   11286                 :          10 :                           gimple_set_lhs (new_stmt, final_mask);
   11287                 :          10 :                           vect_finish_stmt_generation (vinfo, stmt_info,
   11288                 :             :                                                        new_stmt, gsi);
   11289                 :          10 :                         }
   11290                 :          53 :                       else if (final_mask)
   11291                 :             :                         {
   11292                 :          25 :                           new_stmt = gimple_build_assign (NULL_TREE,
   11293                 :             :                                                           VEC_UNPACK_HI_EXPR,
   11294                 :             :                                                           final_mask);
   11295                 :          25 :                           final_mask = make_ssa_name
   11296                 :          25 :                             (truth_type_for (gs_info.offset_vectype));
   11297                 :          25 :                           gimple_set_lhs (new_stmt, final_mask);
   11298                 :          25 :                           vect_finish_stmt_generation (vinfo, stmt_info,
   11299                 :             :                                                        new_stmt, gsi);
   11300                 :             :                         }
   11301                 :             : 
   11302                 :          63 :                       new_stmt = vect_build_one_gather_load_call
   11303                 :          63 :                                    (vinfo, stmt_info, gsi, &gs_info,
   11304                 :             :                                     dataref_ptr,
   11305                 :          63 :                                     vec_offsets[2 * vec_num * j + 2 * i + 1],
   11306                 :             :                                     final_mask);
   11307                 :          63 :                       tree high = make_ssa_name (vectype);
   11308                 :          63 :                       gimple_set_lhs (new_stmt, high);
   11309                 :          63 :                       vect_finish_stmt_generation (vinfo, stmt_info,
   11310                 :             :                                                    new_stmt, gsi);
   11311                 :             : 
   11312                 :             :                       /* compose low + high.  */
   11313                 :          63 :                       int count = nunits.to_constant ();
   11314                 :          63 :                       vec_perm_builder sel (count, count, 1);
   11315                 :          63 :                       sel.quick_grow (count);
   11316                 :         655 :                       for (int i = 0; i < count; ++i)
   11317                 :         592 :                         sel[i] = i < count / 2 ? i : i + count / 2;
   11318                 :          63 :                       vec_perm_indices indices (sel, 2, count);
   11319                 :          63 :                       tree perm_mask
   11320                 :          63 :                         = vect_gen_perm_mask_checked (vectype, indices);
   11321                 :          63 :                       new_stmt = gimple_build_assign (NULL_TREE,
   11322                 :             :                                                       VEC_PERM_EXPR,
   11323                 :             :                                                       low, high, perm_mask);
   11324                 :          63 :                       data_ref = NULL_TREE;
   11325                 :          63 :                     }
   11326                 :          86 :                   else if (known_eq (nunits * 2, offset_nunits))
   11327                 :             :                     {
   11328                 :             :                       /* We have a offset vector with double the number of
   11329                 :             :                          lanes.  Select the low/high part accordingly.  */
   11330                 :          86 :                       vec_offset = vec_offsets[(vec_num * j + i) / 2];
   11331                 :          86 :                       if ((vec_num * j + i) & 1)
   11332                 :             :                         {
   11333                 :          43 :                           int count = offset_nunits.to_constant ();
   11334                 :          43 :                           vec_perm_builder sel (count, count, 1);
   11335                 :          43 :                           sel.quick_grow (count);
   11336                 :         463 :                           for (int i = 0; i < count; ++i)
   11337                 :         420 :                             sel[i] = i | (count / 2);
   11338                 :          43 :                           vec_perm_indices indices (sel, 2, count);
   11339                 :          43 :                           tree perm_mask = vect_gen_perm_mask_checked
   11340                 :          43 :                                              (TREE_TYPE (vec_offset), indices);
   11341                 :          43 :                           new_stmt = gimple_build_assign (NULL_TREE,
   11342                 :             :                                                           VEC_PERM_EXPR,
   11343                 :             :                                                           vec_offset,
   11344                 :             :                                                           vec_offset,
   11345                 :             :                                                           perm_mask);
   11346                 :          43 :                           vec_offset = make_ssa_name (TREE_TYPE (vec_offset));
   11347                 :          43 :                           gimple_set_lhs (new_stmt, vec_offset);
   11348                 :          43 :                           vect_finish_stmt_generation (vinfo, stmt_info,
   11349                 :             :                                                        new_stmt, gsi);
   11350                 :          43 :                         }
   11351                 :         172 :                       new_stmt = vect_build_one_gather_load_call
   11352                 :          86 :                                    (vinfo, stmt_info, gsi, &gs_info,
   11353                 :             :                                     dataref_ptr, vec_offset, final_mask);
   11354                 :          86 :                       data_ref = NULL_TREE;
   11355                 :             :                     }
   11356                 :             :                   else
   11357                 :           0 :                     gcc_unreachable ();
   11358                 :             :                 }
   11359                 :             :               else
   11360                 :             :                 {
   11361                 :             :                   /* Emulated gather-scatter.  */
   11362                 :        3239 :                   gcc_assert (!final_mask);
   11363                 :        3239 :                   unsigned HOST_WIDE_INT const_nunits = nunits.to_constant ();
   11364                 :        3239 :                   if (costing_p)
   11365                 :             :                     {
   11366                 :             :                       /* For emulated gathers N offset vector element
   11367                 :             :                          offset add is consumed by the load).  */
   11368                 :        2566 :                       inside_cost = record_stmt_cost (cost_vec, const_nunits,
   11369                 :             :                                                       vec_to_scalar,
   11370                 :             :                                                       slp_node, 0, vect_body);
   11371                 :             :                       /* N scalar loads plus gathering them into a
   11372                 :             :                          vector.  */
   11373                 :        2566 :                       inside_cost
   11374                 :        2566 :                         = record_stmt_cost (cost_vec, const_nunits, scalar_load,
   11375                 :             :                                             slp_node, 0, vect_body);
   11376                 :        2566 :                       inside_cost
   11377                 :        2566 :                         = record_stmt_cost (cost_vec, 1, vec_construct,
   11378                 :             :                                             slp_node, 0, vect_body);
   11379                 :        2566 :                       continue;
   11380                 :             :                     }
   11381                 :         673 :                   unsigned HOST_WIDE_INT const_offset_nunits
   11382                 :         673 :                     = TYPE_VECTOR_SUBPARTS (gs_info.offset_vectype)
   11383                 :         673 :                         .to_constant ();
   11384                 :         673 :                   vec<constructor_elt, va_gc> *ctor_elts;
   11385                 :         673 :                   vec_alloc (ctor_elts, const_nunits);
   11386                 :         673 :                   gimple_seq stmts = NULL;
   11387                 :             :                   /* We support offset vectors with more elements
   11388                 :             :                      than the data vector for now.  */
   11389                 :         673 :                   unsigned HOST_WIDE_INT factor
   11390                 :             :                     = const_offset_nunits / const_nunits;
   11391                 :         673 :                   vec_offset = vec_offsets[(vec_num * j + i) / factor];
   11392                 :         673 :                   unsigned elt_offset
   11393                 :         673 :                     = ((vec_num * j + i) % factor) * const_nunits;
   11394                 :         673 :                   tree idx_type = TREE_TYPE (TREE_TYPE (vec_offset));
   11395                 :         673 :                   tree scale = size_int (gs_info.scale);
   11396                 :         673 :                   align = get_object_alignment (DR_REF (first_dr_info->dr));
   11397                 :         673 :                   tree ltype = build_aligned_type (TREE_TYPE (vectype), align);
   11398                 :        2807 :                   for (unsigned k = 0; k < const_nunits; ++k)
   11399                 :             :                     {
   11400                 :        2134 :                       tree boff = size_binop (MULT_EXPR, TYPE_SIZE (idx_type),
   11401                 :             :                                               bitsize_int (k + elt_offset));
   11402                 :        2134 :                       tree idx
   11403                 :        4268 :                         = gimple_build (&stmts, BIT_FIELD_REF, idx_type,
   11404                 :        2134 :                                         vec_offset, TYPE_SIZE (idx_type), boff);
   11405                 :        2134 :                       idx = gimple_convert (&stmts, sizetype, idx);
   11406                 :        2134 :                       idx = gimple_build (&stmts, MULT_EXPR, sizetype, idx,
   11407                 :             :                                           scale);
   11408                 :        2134 :                       tree ptr = gimple_build (&stmts, PLUS_EXPR,
   11409                 :        2134 :                                                TREE_TYPE (dataref_ptr),
   11410                 :             :                                                dataref_ptr, idx);
   11411                 :        2134 :                       ptr = gimple_convert (&stmts, ptr_type_node, ptr);
   11412                 :        2134 :                       tree elt = make_ssa_name (TREE_TYPE (vectype));
   11413                 :        2134 :                       tree ref = build2 (MEM_REF, ltype, ptr,
   11414                 :             :                                          build_int_cst (ref_type, 0));
   11415                 :        2134 :                       new_stmt = gimple_build_assign (elt, ref);
   11416                 :        4268 :                       gimple_set_vuse (new_stmt, gimple_vuse (gsi_stmt (*gsi)));
   11417                 :        2134 :                       gimple_seq_add_stmt (&stmts, new_stmt);
   11418                 :        2134 :                       CONSTRUCTOR_APPEND_ELT (ctor_elts, NULL_TREE, elt);
   11419                 :             :                     }
   11420                 :         673 :                   gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
   11421                 :         673 :                   new_stmt = gimple_build_assign (
   11422                 :             :                     NULL_TREE, build_constructor (vectype, ctor_elts));
   11423                 :         673 :                   data_ref = NULL_TREE;
   11424                 :             :                 }
   11425                 :             : 
   11426                 :         954 :               vec_dest = vect_create_destination_var (scalar_dest, vectype);
   11427                 :             :               /* DATA_REF is null if we've already built the statement.  */
   11428                 :         954 :               if (data_ref)
   11429                 :             :                 {
   11430                 :             :                   vect_copy_ref_info (data_ref, DR_REF (first_dr_info->dr));
   11431                 :             :                   new_stmt = gimple_build_assign (vec_dest, data_ref);
   11432                 :             :                 }
   11433                 :        1908 :               new_temp = need_zeroing
   11434                 :         954 :                 ? make_ssa_name (vectype)
   11435                 :         954 :                 : make_ssa_name (vec_dest, new_stmt);
   11436                 :         954 :               gimple_set_lhs (new_stmt, new_temp);
   11437                 :         954 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
   11438                 :             : 
   11439                 :             :               /* If we need to explicitly zero inactive elements emit a
   11440                 :             :                  VEC_COND_EXPR that does so.  */
   11441                 :         954 :               if (need_zeroing)
   11442                 :             :                 {
   11443                 :           0 :                   vec_els = vect_get_mask_load_else (MASK_LOAD_ELSE_ZERO,
   11444                 :             :                                                      vectype);
   11445                 :             : 
   11446                 :           0 :                   tree new_temp2 = make_ssa_name (vec_dest, new_stmt);
   11447                 :           0 :                   new_stmt
   11448                 :           0 :                     = gimple_build_assign (new_temp2, VEC_COND_EXPR,
   11449                 :             :                                            final_mask, new_temp, vec_els);
   11450                 :           0 :                   vect_finish_stmt_generation (vinfo, stmt_info, new_stmt,
   11451                 :             :                                                gsi);
   11452                 :           0 :                   new_temp = new_temp2;
   11453                 :             :                 }
   11454                 :             : 
   11455                 :             :               /* Store vector loads in the corresponding SLP_NODE.  */
   11456                 :         954 :               if (slp)
   11457                 :         954 :                 slp_node->push_vec_def (new_stmt);
   11458                 :             :             }
   11459                 :             : 
   11460                 :        3008 :           if (!slp && !costing_p)
   11461                 :           0 :             STMT_VINFO_VEC_STMTS (stmt_info).safe_push (new_stmt);
   11462                 :             :         }
   11463                 :             : 
   11464                 :        3008 :       if (!slp && !costing_p)
   11465                 :           0 :         *vec_stmt = STMT_VINFO_VEC_STMTS (stmt_info)[0];
   11466                 :             : 
   11467                 :        3008 :       if (costing_p && dump_enabled_p ())
   11468                 :         300 :         dump_printf_loc (MSG_NOTE, vect_location,
   11469                 :             :                          "vect_model_load_cost: inside_cost = %u, "
   11470                 :             :                          "prologue_cost = %u .\n",
   11471                 :             :                          inside_cost, prologue_cost);
   11472                 :        3008 :       return true;
   11473                 :             :     }
   11474                 :             : 
   11475                 :      538014 :   poly_uint64 group_elt = 0;
   11476                 :      538014 :   unsigned int inside_cost = 0, prologue_cost = 0;
   11477                 :             :   /* For costing some adjacent vector loads, we'd like to cost with
   11478                 :             :      the total number of them once instead of cost each one by one. */
   11479                 :      538014 :   unsigned int n_adjacent_loads = 0;
   11480                 :     1076028 :   for (j = 0; j < ncopies; j++)
   11481                 :             :     {
   11482                 :             :       /* 1. Create the vector or array pointer update chain.  */
   11483                 :      538014 :       if (j == 0 && !costing_p)
   11484                 :             :         {
   11485                 :      152608 :           bool simd_lane_access_p
   11486                 :      152608 :             = STMT_VINFO_SIMD_LANE_ACCESS_P (stmt_info) != 0;
   11487                 :      152608 :           if (simd_lane_access_p
   11488                 :        1605 :               && TREE_CODE (DR_BASE_ADDRESS (first_dr_info->dr)) == ADDR_EXPR
   11489                 :        1605 :               && VAR_P (TREE_OPERAND (DR_BASE_ADDRESS (first_dr_info->dr), 0))
   11490                 :        1605 :               && integer_zerop (get_dr_vinfo_offset (vinfo, first_dr_info))
   11491                 :        1605 :               && integer_zerop (DR_INIT (first_dr_info->dr))
   11492                 :        1605 :               && alias_sets_conflict_p (get_alias_set (aggr_type),
   11493                 :        1605 :                                         get_alias_set (TREE_TYPE (ref_type)))
   11494                 :      154213 :               && (alignment_support_scheme == dr_aligned
   11495                 :           0 :                   || alignment_support_scheme == dr_unaligned_supported))
   11496                 :             :             {
   11497                 :        1605 :               dataref_ptr = unshare_expr (DR_BASE_ADDRESS (first_dr_info->dr));
   11498                 :        1605 :               dataref_offset = build_int_cst (ref_type, 0);
   11499                 :             :             }
   11500                 :      151003 :           else if (diff_first_stmt_info)
   11501                 :             :             {
   11502                 :        2484 :               dataref_ptr
   11503                 :        2484 :                 = vect_create_data_ref_ptr (vinfo, first_stmt_info_for_drptr,
   11504                 :             :                                             aggr_type, at_loop, offset, &dummy,
   11505                 :             :                                             gsi, &ptr_incr, simd_lane_access_p,
   11506                 :             :                                             bump);
   11507                 :             :               /* Adjust the pointer by the difference to first_stmt.  */
   11508                 :        2484 :               data_reference_p ptrdr
   11509                 :             :                 = STMT_VINFO_DATA_REF (first_stmt_info_for_drptr);
   11510                 :        2484 :               tree diff
   11511                 :        2484 :                 = fold_convert (sizetype,
   11512                 :             :                                 size_binop (MINUS_EXPR,
   11513                 :             :                                             DR_INIT (first_dr_info->dr),
   11514                 :             :                                             DR_INIT (ptrdr)));
   11515                 :        2484 :               dataref_ptr = bump_vector_ptr (vinfo, dataref_ptr, ptr_incr, gsi,
   11516                 :             :                                              stmt_info, diff);
   11517                 :        2484 :               if (alignment_support_scheme == dr_explicit_realign)
   11518                 :             :                 {
   11519                 :           0 :                   msq = vect_setup_realignment (vinfo,
   11520                 :             :                                                 first_stmt_info_for_drptr, gsi,
   11521                 :             :                                                 &realignment_token,
   11522                 :             :                                                 alignment_support_scheme,
   11523                 :             :                                                 dataref_ptr, &at_loop);
   11524                 :           0 :                   gcc_assert (!compute_in_loop);
   11525                 :             :                 }
   11526                 :             :             }
   11527                 :             :           else
   11528                 :      148519 :             dataref_ptr
   11529                 :      148519 :               = vect_create_data_ref_ptr (vinfo, first_stmt_info, aggr_type,
   11530                 :             :                                           at_loop,
   11531                 :             :                                           offset, &dummy, gsi, &ptr_incr,
   11532                 :             :                                           simd_lane_access_p, bump);
   11533                 :             :         }
   11534                 :      385406 :       else if (!costing_p)
   11535                 :             :         {
   11536                 :           0 :           gcc_assert (!LOOP_VINFO_USING_SELECT_VL_P (loop_vinfo));
   11537                 :           0 :           if (dataref_offset)
   11538                 :           0 :             dataref_offset = int_const_binop (PLUS_EXPR, dataref_offset,
   11539                 :             :                                               bump);
   11540                 :             :           else
   11541                 :           0 :             dataref_ptr = bump_vector_ptr (vinfo, dataref_ptr, ptr_incr, gsi,
   11542                 :             :                                            stmt_info, bump);
   11543                 :             :         }
   11544                 :             : 
   11545                 :      538014 :       if (grouped_load || slp_perm)
   11546                 :       48119 :         dr_chain.create (vec_num);
   11547                 :             : 
   11548                 :      538014 :       gimple *new_stmt = NULL;
   11549                 :     1455584 :       for (i = 0; i < vec_num; i++)
   11550                 :             :         {
   11551                 :      917570 :           tree final_mask = NULL_TREE;
   11552                 :      917570 :           tree final_len = NULL_TREE;
   11553                 :      917570 :           tree bias = NULL_TREE;
   11554                 :             : 
   11555                 :      917570 :           if (!costing_p)
   11556                 :             :             {
   11557                 :      203344 :               if (mask)
   11558                 :         520 :                 vec_mask = vec_masks[vec_num * j + i];
   11559                 :      203344 :               if (loop_masks)
   11560                 :          19 :                 final_mask = vect_get_loop_mask (loop_vinfo, gsi, loop_masks,
   11561                 :          19 :                                                  vec_num * ncopies, vectype,
   11562                 :          19 :                                                  vec_num * j + i);
   11563                 :      203344 :               if (vec_mask)
   11564                 :         520 :                 final_mask = prepare_vec_mask (loop_vinfo, mask_vectype,
   11565                 :             :                                                final_mask, vec_mask, gsi);
   11566                 :             : 
   11567                 :      203344 :               if (i > 0)
   11568                 :       50736 :                 dataref_ptr = bump_vector_ptr (vinfo, dataref_ptr, ptr_incr,
   11569                 :             :                                                gsi, stmt_info, bump);
   11570                 :             :             }
   11571                 :             : 
   11572                 :             :           /* 2. Create the vector-load in the loop.  */
   11573                 :      917570 :           switch (alignment_support_scheme)
   11574                 :             :             {
   11575                 :      917570 :             case dr_aligned:
   11576                 :      917570 :             case dr_unaligned_supported:
   11577                 :      917570 :               {
   11578                 :      917570 :                 if (costing_p)
   11579                 :             :                   break;
   11580                 :             : 
   11581                 :      203344 :                 unsigned int misalign;
   11582                 :      203344 :                 unsigned HOST_WIDE_INT align;
   11583                 :      203344 :                 align = known_alignment (DR_TARGET_ALIGNMENT (first_dr_info));
   11584                 :      203344 :                 if (alignment_support_scheme == dr_aligned)
   11585                 :             :                   misalign = 0;
   11586                 :      122709 :                 else if (misalignment == DR_MISALIGNMENT_UNKNOWN)
   11587                 :             :                   {
   11588                 :       96725 :                     align
   11589                 :       96725 :                       = dr_alignment (vect_dr_behavior (vinfo, first_dr_info));
   11590                 :       96725 :                     misalign = 0;
   11591                 :             :                   }
   11592                 :             :                 else
   11593                 :       25984 :                   misalign = misalignment;
   11594                 :      203344 :                 if (dataref_offset == NULL_TREE
   11595                 :      201251 :                     && TREE_CODE (dataref_ptr) == SSA_NAME)
   11596                 :      131478 :                   set_ptr_info_alignment (get_ptr_info (dataref_ptr), align,
   11597                 :             :                                           misalign);
   11598                 :      203344 :                 align = least_bit_hwi (misalign | align);
   11599                 :             : 
   11600                 :             :                 /* Compute IFN when LOOP_LENS or final_mask valid.  */
   11601                 :      203344 :                 machine_mode vmode = TYPE_MODE (vectype);
   11602                 :      203344 :                 machine_mode new_vmode = vmode;
   11603                 :      203344 :                 internal_fn partial_ifn = IFN_LAST;
   11604                 :      203344 :                 if (loop_lens)
   11605                 :             :                   {
   11606                 :           0 :                     opt_machine_mode new_ovmode
   11607                 :           0 :                       = get_len_load_store_mode (vmode, true, &partial_ifn);
   11608                 :           0 :                     new_vmode = new_ovmode.require ();
   11609                 :           0 :                     unsigned factor
   11610                 :           0 :                       = (new_ovmode == vmode) ? 1 : GET_MODE_UNIT_SIZE (vmode);
   11611                 :           0 :                     final_len = vect_get_loop_len (loop_vinfo, gsi, loop_lens,
   11612                 :           0 :                                                    vec_num * ncopies, vectype,
   11613                 :           0 :                                                    vec_num * j + i, factor);
   11614                 :             :                   }
   11615                 :      203344 :                 else if (final_mask)
   11616                 :             :                   {
   11617                 :         539 :                     if (!can_vec_mask_load_store_p (
   11618                 :         539 :                           vmode, TYPE_MODE (TREE_TYPE (final_mask)), true,
   11619                 :             :                           &partial_ifn))
   11620                 :           0 :                       gcc_unreachable ();
   11621                 :             :                   }
   11622                 :             : 
   11623                 :      203344 :                 if (partial_ifn == IFN_MASK_LEN_LOAD)
   11624                 :             :                   {
   11625                 :           0 :                     if (!final_len)
   11626                 :             :                       {
   11627                 :             :                         /* Pass VF value to 'len' argument of
   11628                 :             :                            MASK_LEN_LOAD if LOOP_LENS is invalid.  */
   11629                 :           0 :                         final_len = size_int (TYPE_VECTOR_SUBPARTS (vectype));
   11630                 :             :                       }
   11631                 :           0 :                     if (!final_mask)
   11632                 :             :                       {
   11633                 :             :                         /* Pass all ones value to 'mask' argument of
   11634                 :             :                            MASK_LEN_LOAD if final_mask is invalid.  */
   11635                 :           0 :                         mask_vectype = truth_type_for (vectype);
   11636                 :           0 :                         final_mask = build_minus_one_cst (mask_vectype);
   11637                 :             :                       }
   11638                 :             :                   }
   11639                 :      203344 :                 if (final_len)
   11640                 :             :                   {
   11641                 :           0 :                     signed char biasval
   11642                 :           0 :                       = LOOP_VINFO_PARTIAL_LOAD_STORE_BIAS (loop_vinfo);
   11643                 :             : 
   11644                 :           0 :                     bias = build_int_cst (intQI_type_node, biasval);
   11645                 :             :                   }
   11646                 :             : 
   11647                 :      203344 :                 tree vec_els;
   11648                 :             : 
   11649                 :      203344 :                 if (final_len)
   11650                 :             :                   {
   11651                 :           0 :                     tree ptr = build_int_cst (ref_type, align * BITS_PER_UNIT);
   11652                 :           0 :                     gcall *call;
   11653                 :           0 :                     if (partial_ifn == IFN_MASK_LEN_LOAD)
   11654                 :             :                       {
   11655                 :           0 :                         vec_els = vect_get_mask_load_else
   11656                 :           0 :                           (maskload_elsval, vectype);
   11657                 :           0 :                         if (type_mode_padding_p
   11658                 :           0 :                             && maskload_elsval != MASK_LOAD_ELSE_ZERO)
   11659                 :           0 :                           need_zeroing = true;
   11660                 :           0 :                         call = gimple_build_call_internal (IFN_MASK_LEN_LOAD,
   11661                 :             :                                                            6, dataref_ptr, ptr,
   11662                 :             :                                                            final_mask, vec_els,
   11663                 :             :                                                            final_len, bias);
   11664                 :             :                       }
   11665                 :             :                     else
   11666                 :           0 :                       call = gimple_build_call_internal (IFN_LEN_LOAD, 4,
   11667                 :             :                                                          dataref_ptr, ptr,
   11668                 :             :                                                          final_len, bias);
   11669                 :           0 :                     gimple_call_set_nothrow (call, true);
   11670                 :           0 :                     new_stmt = call;
   11671                 :           0 :                     data_ref = NULL_TREE;
   11672                 :             : 
   11673                 :             :                     /* Need conversion if it's wrapped with VnQI.  */
   11674                 :           0 :                     if (vmode != new_vmode)
   11675                 :             :                       {
   11676                 :           0 :                         tree new_vtype = build_vector_type_for_mode (
   11677                 :             :                           unsigned_intQI_type_node, new_vmode);
   11678                 :           0 :                         tree var
   11679                 :           0 :                           = vect_get_new_ssa_name (new_vtype, vect_simple_var);
   11680                 :           0 :                         gimple_set_lhs (call, var);
   11681                 :           0 :                         vect_finish_stmt_generation (vinfo, stmt_info, call,
   11682                 :             :                                                      gsi);
   11683                 :           0 :                         tree op = build1 (VIEW_CONVERT_EXPR, vectype, var);
   11684                 :           0 :                         new_stmt = gimple_build_assign (vec_dest,
   11685                 :             :                                                         VIEW_CONVERT_EXPR, op);
   11686                 :             :                       }
   11687                 :             :                   }
   11688                 :      203344 :                 else if (final_mask)
   11689                 :             :                   {
   11690                 :         539 :                     tree ptr = build_int_cst (ref_type, align * BITS_PER_UNIT);
   11691                 :         539 :                     vec_els = vect_get_mask_load_else
   11692                 :         539 :                       (maskload_elsval, vectype);
   11693                 :         539 :                     if (type_mode_padding_p
   11694                 :         539 :                         && maskload_elsval != MASK_LOAD_ELSE_ZERO)
   11695                 :           0 :                       need_zeroing = true;
   11696                 :         539 :                     gcall *call = gimple_build_call_internal (IFN_MASK_LOAD, 4,
   11697                 :             :                                                               dataref_ptr, ptr,
   11698                 :             :                                                               final_mask,
   11699                 :             :                                                               vec_els);
   11700                 :         539 :                     gimple_call_set_nothrow (call, true);
   11701                 :         539 :                     new_stmt = call;
   11702                 :         539 :                     data_ref = NULL_TREE;
   11703                 :             :                   }
   11704                 :             :                 else
   11705                 :             :                   {
   11706                 :      202805 :                     tree ltype = vectype;
   11707                 :      202805 :                     tree new_vtype = NULL_TREE;
   11708                 :      202805 :                     unsigned HOST_WIDE_INT gap = DR_GROUP_GAP (first_stmt_info);
   11709                 :      202805 :                     unsigned HOST_WIDE_INT dr_size
   11710                 :      202805 :                       = vect_get_scalar_dr_size (first_dr_info);
   11711                 :      202805 :                     poly_int64 off = 0;
   11712                 :      202805 :                     if (memory_access_type == VMAT_CONTIGUOUS_REVERSE)
   11713                 :        1412 :                       off = (TYPE_VECTOR_SUBPARTS (vectype) - 1) * -dr_size;
   11714                 :      202805 :                     unsigned int vect_align
   11715                 :      202805 :                       = vect_known_alignment_in_bytes (first_dr_info, vectype,
   11716                 :      202805 :                                                        off);
   11717                 :             :                     /* Try to use a single smaller load when we are about
   11718                 :             :                        to load excess elements compared to the unrolled
   11719                 :             :                        scalar loop.  */
   11720                 :      202805 :                     if (known_gt ((vec_num * j + i + 1) * nunits,
   11721                 :             :                                        (group_size * vf - gap)))
   11722                 :             :                       {
   11723                 :        2124 :                         poly_uint64 remain = ((group_size * vf - gap)
   11724                 :        2124 :                                               - (vec_num * j + i) * nunits);
   11725                 :        2124 :                         if (known_ge ((vec_num * j + i + 1) * nunits
   11726                 :             :                                       - (group_size * vf - gap), nunits))
   11727                 :             :                           /* DR will be unused.  */
   11728                 :             :                           ltype = NULL_TREE;
   11729                 :        1599 :                         else if (known_ge (vect_align,
   11730                 :             :                                            tree_to_poly_uint64
   11731                 :             :                                              (TYPE_SIZE_UNIT (vectype))))
   11732                 :             :                           /* Aligned access to excess elements is OK if
   11733                 :             :                              at least one element is accessed in the
   11734                 :             :                              scalar loop.  */
   11735                 :             :                           ;
   11736                 :        1368 :                         else if (known_gt (vect_align,
   11737                 :             :                                            ((nunits - remain) * dr_size)))
   11738                 :             :                           /* Aligned access to the gap area when there's
   11739                 :             :                              at least one element in it is OK.  */
   11740                 :             :                           ;
   11741                 :             :                         else
   11742                 :             :                           {
   11743                 :             :                             /* remain should now be > 0 and < nunits.  */
   11744                 :        1365 :                             unsigned num;
   11745                 :        1365 :                             if (known_ne (remain, 0u)
   11746                 :        1365 :                                 && constant_multiple_p (nunits, remain, &num))
   11747                 :             :                               {
   11748                 :         990 :                                 tree ptype;
   11749                 :         990 :                                 new_vtype
   11750                 :        1980 :                                   = vector_vector_composition_type (vectype,
   11751                 :         990 :                                                                     num,
   11752                 :             :                                                                     &ptype);
   11753                 :         990 :                                 if (new_vtype)
   11754                 :         990 :                                   ltype = ptype;
   11755                 :             :                               }
   11756                 :             :                             /* Else use multiple loads or a masked load?  */
   11757                 :             :                             /* For loop vectorization we now should have
   11758                 :             :                                an alternate type or LOOP_VINFO_PEELING_FOR_GAPS
   11759                 :             :                                set.  */
   11760                 :        1365 :                             if (loop_vinfo)
   11761                 :        1331 :                               gcc_assert (new_vtype
   11762                 :             :                                           || LOOP_VINFO_PEELING_FOR_GAPS
   11763                 :             :                                                (loop_vinfo));
   11764                 :             :                             /* But still reduce the access size to the next
   11765                 :             :                                required power-of-two so peeling a single
   11766                 :             :                                scalar iteration is sufficient.  */
   11767                 :        1365 :                             unsigned HOST_WIDE_INT cremain;
   11768                 :        1365 :                             if (remain.is_constant (&cremain))
   11769                 :             :                               {
   11770                 :        1365 :                                 unsigned HOST_WIDE_INT cpart_size
   11771                 :        1365 :                                   = 1 << ceil_log2 (cremain);
   11772                 :        1365 :                                 if (known_gt (nunits, cpart_size)
   11773                 :        1365 :                                     && constant_multiple_p (nunits, cpart_size,
   11774                 :             :                                                             &num))
   11775                 :             :                                   {
   11776                 :        1002 :                                     tree ptype;
   11777                 :        1002 :                                     new_vtype
   11778                 :        2004 :                                       = vector_vector_composition_type (vectype,
   11779                 :        1002 :                                                                         num,
   11780                 :             :                                                                         &ptype);
   11781                 :        1002 :                                     if (new_vtype)
   11782                 :        1002 :                                       ltype = ptype;
   11783                 :             :                                   }
   11784                 :             :                               }
   11785                 :             :                           }
   11786                 :             :                       }
   11787                 :      202805 :                     tree offset
   11788                 :      202805 :                       = (dataref_offset ? dataref_offset
   11789                 :      200712 :                                         : build_int_cst (ref_type, 0));
   11790                 :      202805 :                     if (!ltype)
   11791                 :             :                       ;
   11792                 :      202280 :                     else if (ltype != vectype
   11793                 :        1002 :                              && memory_access_type == VMAT_CONTIGUOUS_REVERSE)
   11794                 :             :                       {
   11795                 :          21 :                         poly_uint64 gap_offset
   11796                 :          21 :                           = (tree_to_poly_uint64 (TYPE_SIZE_UNIT (vectype))
   11797                 :          21 :                              - tree_to_poly_uint64 (TYPE_SIZE_UNIT (ltype)));
   11798                 :          21 :                         tree gapcst = build_int_cstu (ref_type, gap_offset);
   11799                 :          21 :                         offset = size_binop (PLUS_EXPR, offset, gapcst);
   11800                 :             :                       }
   11801                 :      202805 :                     if (ltype)
   11802                 :             :                       {
   11803                 :      202280 :                         data_ref
   11804                 :      202280 :                           = fold_build2 (MEM_REF, ltype, dataref_ptr, offset);
   11805                 :      202280 :                         if (alignment_support_scheme == dr_aligned)
   11806                 :             :                           ;
   11807                 :             :                         else
   11808                 :      122066 :                           TREE_TYPE (data_ref)
   11809                 :      244132 :                             = build_aligned_type (TREE_TYPE (data_ref),
   11810                 :             :                                                   align * BITS_PER_UNIT);
   11811                 :             :                       }
   11812                 :      202805 :                     if (!ltype)
   11813                 :         525 :                       data_ref = build_constructor (vectype, NULL);
   11814                 :      202280 :                     else if (ltype != vectype)
   11815                 :             :                       {
   11816                 :        1002 :                         vect_copy_ref_info (data_ref,
   11817                 :        1002 :                                             DR_REF (first_dr_info->dr));
   11818                 :        1002 :                         tree tem = make_ssa_name (ltype);
   11819                 :        1002 :                         new_stmt = gimple_build_assign (tem, data_ref);
   11820                 :        1002 :                         vect_finish_stmt_generation (vinfo, stmt_info, new_stmt,
   11821                 :             :                                                      gsi);
   11822                 :        1002 :                         data_ref = NULL;
   11823                 :        1002 :                         vec<constructor_elt, va_gc> *v;
   11824                 :             :                         /* We've computed 'num' above to statically two
   11825                 :             :                            or via constant_multiple_p.  */
   11826                 :        1002 :                         unsigned num
   11827                 :        1002 :                           = (exact_div (tree_to_poly_uint64
   11828                 :        1002 :                                           (TYPE_SIZE_UNIT (vectype)),
   11829                 :             :                                         tree_to_poly_uint64
   11830                 :        1002 :                                           (TYPE_SIZE_UNIT (ltype)))
   11831                 :        1002 :                              .to_constant ());
   11832                 :        1002 :                         vec_alloc (v, num);
   11833                 :        1002 :                         if (memory_access_type == VMAT_CONTIGUOUS_REVERSE)
   11834                 :             :                           {
   11835                 :          54 :                             while (--num)
   11836                 :          54 :                               CONSTRUCTOR_APPEND_ELT (v, NULL_TREE,
   11837                 :             :                                                       build_zero_cst (ltype));
   11838                 :          21 :                             CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, tem);
   11839                 :             :                           }
   11840                 :             :                         else
   11841                 :             :                           {
   11842                 :         981 :                             CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, tem);
   11843                 :         981 :                             while (--num)
   11844                 :        2284 :                               CONSTRUCTOR_APPEND_ELT (v, NULL_TREE,
   11845                 :             :                                                       build_zero_cst (ltype));
   11846                 :             :                           }
   11847                 :        1002 :                         gcc_assert (new_vtype != NULL_TREE);
   11848                 :        1002 :                         if (new_vtype == vectype)
   11849                 :         972 :                           new_stmt = gimple_build_assign (
   11850                 :             :                             vec_dest, build_constructor (vectype, v));
   11851                 :             :                         else
   11852                 :             :                           {
   11853                 :          30 :                             tree new_vname = make_ssa_name (new_vtype);
   11854                 :          30 :                             new_stmt = gimple_build_assign (
   11855                 :             :                               new_vname, build_constructor (new_vtype, v));
   11856                 :          30 :                             vect_finish_stmt_generation (vinfo, stmt_info,
   11857                 :             :                                                          new_stmt, gsi);
   11858                 :          30 :                             new_stmt = gimple_build_assign (
   11859                 :             :                               vec_dest,
   11860                 :             :                               build1 (VIEW_CONVERT_EXPR, vectype, new_vname));
   11861                 :             :                           }
   11862                 :             :                       }
   11863                 :             :                   }
   11864                 :             :                 break;
   11865                 :             :               }
   11866                 :           0 :             case dr_explicit_realign:
   11867                 :           0 :               {
   11868                 :           0 :                 if (costing_p)
   11869                 :             :                   break;
   11870                 :           0 :                 tree ptr, bump;
   11871                 :             : 
   11872                 :           0 :                 tree vs = size_int (TYPE_VECTOR_SUBPARTS (vectype));
   11873                 :             : 
   11874                 :           0 :                 if (compute_in_loop)
   11875                 :           0 :                   msq = vect_setup_realignment (vinfo, first_stmt_info, gsi,
   11876                 :             :                                                 &realignment_token,
   11877                 :             :                                                 dr_explicit_realign,
   11878                 :             :                                                 dataref_ptr, NULL);
   11879                 :             : 
   11880                 :           0 :                 if (TREE_CODE (dataref_ptr) == SSA_NAME)
   11881                 :           0 :                   ptr = copy_ssa_name (dataref_ptr);
   11882                 :             :                 else
   11883                 :           0 :                   ptr = make_ssa_name (TREE_TYPE (dataref_ptr));
   11884                 :             :                 // For explicit realign the target alignment should be
   11885                 :             :                 // known at compile time.
   11886                 :           0 :                 unsigned HOST_WIDE_INT align
   11887                 :           0 :                   = DR_TARGET_ALIGNMENT (first_dr_info).to_constant ();
   11888                 :           0 :                 new_stmt = gimple_build_assign (
   11889                 :             :                   ptr, BIT_AND_EXPR, dataref_ptr,
   11890                 :           0 :                   build_int_cst (TREE_TYPE (dataref_ptr),
   11891                 :           0 :                                  -(HOST_WIDE_INT) align));
   11892                 :           0 :                 vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
   11893                 :           0 :                 data_ref
   11894                 :           0 :                   = build2 (MEM_REF, vectype, ptr, build_int_cst (ref_type, 0));
   11895                 :           0 :                 vect_copy_ref_info (data_ref, DR_REF (first_dr_info->dr));
   11896                 :           0 :                 vec_dest = vect_create_destination_var (scalar_dest, vectype);
   11897                 :           0 :                 new_stmt = gimple_build_assign (vec_dest, data_ref);
   11898                 :           0 :                 new_temp = make_ssa_name (vec_dest, new_stmt);
   11899                 :           0 :                 gimple_assign_set_lhs (new_stmt, new_temp);
   11900                 :           0 :                 gimple_move_vops (new_stmt, stmt_info->stmt);
   11901                 :           0 :                 vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
   11902                 :           0 :                 msq = new_temp;
   11903                 :             : 
   11904                 :           0 :                 bump = size_binop (MULT_EXPR, vs, TYPE_SIZE_UNIT (elem_type));
   11905                 :           0 :                 bump = size_binop (MINUS_EXPR, bump, size_one_node);
   11906                 :           0 :                 ptr = bump_vector_ptr (vinfo, dataref_ptr, NULL, gsi, stmt_info,
   11907                 :             :                                        bump);
   11908                 :           0 :                 new_stmt = gimple_build_assign (
   11909                 :             :                   NULL_TREE, BIT_AND_EXPR, ptr,
   11910                 :           0 :                   build_int_cst (TREE_TYPE (ptr), -(HOST_WIDE_INT) align));
   11911                 :           0 :                 if (TREE_CODE (ptr) == SSA_NAME)
   11912                 :           0 :                   ptr = copy_ssa_name (ptr, new_stmt);
   11913                 :             :                 else
   11914                 :           0 :                   ptr = make_ssa_name (TREE_TYPE (ptr), new_stmt);
   11915                 :           0 :                 gimple_assign_set_lhs (new_stmt, ptr);
   11916                 :           0 :                 vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
   11917                 :           0 :                 data_ref
   11918                 :           0 :                   = build2 (MEM_REF, vectype, ptr, build_int_cst (ref_type, 0));
   11919                 :           0 :                 break;
   11920                 :             :               }
   11921                 :           0 :             case dr_explicit_realign_optimized:
   11922                 :           0 :               {
   11923                 :           0 :                 if (costing_p)
   11924                 :             :                   break;
   11925                 :           0 :                 if (TREE_CODE (dataref_ptr) == SSA_NAME)
   11926                 :           0 :                   new_temp = copy_ssa_name (dataref_ptr);
   11927                 :             :                 else
   11928                 :           0 :                   new_temp = make_ssa_name (TREE_TYPE (dataref_ptr));
   11929                 :             :                 // We should only be doing this if we know the target
   11930                 :             :                 // alignment at compile time.
   11931                 :           0 :                 unsigned HOST_WIDE_INT align
   11932                 :           0 :                   = DR_TARGET_ALIGNMENT (first_dr_info).to_constant ();
   11933                 :           0 :                 new_stmt = gimple_build_assign (
   11934                 :             :                   new_temp, BIT_AND_EXPR, dataref_ptr,
   11935                 :           0 :                   build_int_cst (TREE_TYPE (dataref_ptr),
   11936                 :           0 :                                  -(HOST_WIDE_INT) align));
   11937                 :           0 :                 vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
   11938                 :           0 :                 data_ref = build2 (MEM_REF, vectype, new_temp,
   11939                 :             :                                    build_int_cst (ref_type, 0));
   11940                 :           0 :                 break;
   11941                 :             :               }
   11942                 :           0 :             default:
   11943                 :           0 :               gcc_unreachable ();
   11944                 :             :             }
   11945                 :             : 
   11946                 :             :           /* One common place to cost the above vect load for different
   11947                 :             :              alignment support schemes.  */
   11948                 :      917570 :           if (costing_p)
   11949                 :             :             {
   11950                 :             :               /* For VMAT_CONTIGUOUS_PERMUTE if it's grouped load, we
   11951                 :             :                  only need to take care of the first stmt, whose
   11952                 :             :                  stmt_info is first_stmt_info, vec_num iterating on it
   11953                 :             :                  will cover the cost for the remaining, it's consistent
   11954                 :             :                  with transforming.  For the prologue cost for realign,
   11955                 :             :                  we only need to count it once for the whole group.  */
   11956                 :      714226 :               bool first_stmt_info_p = first_stmt_info == stmt_info;
   11957                 :      714226 :               bool add_realign_cost = first_stmt_info_p && i == 0;
   11958                 :      714226 :               if (memory_access_type == VMAT_CONTIGUOUS
   11959                 :        5105 :                   || memory_access_type == VMAT_CONTIGUOUS_REVERSE
   11960                 :           0 :                   || (memory_access_type == VMAT_CONTIGUOUS_PERMUTE
   11961                 :           0 :                       && (!grouped_load || first_stmt_info_p)))
   11962                 :             :                 {
   11963                 :             :                   /* Leave realign cases alone to keep them simple.  */
   11964                 :      714226 :                   if (alignment_support_scheme == dr_explicit_realign_optimized
   11965                 :      714226 :                       || alignment_support_scheme == dr_explicit_realign)
   11966                 :           0 :                     vect_get_load_cost (vinfo, stmt_info, slp_node, 1,
   11967                 :             :                                         alignment_support_scheme, misalignment,
   11968                 :             :                                         add_realign_cost, &inside_cost,
   11969                 :             :                                         &prologue_cost, cost_vec, cost_vec,
   11970                 :             :                                         true);
   11971                 :             :                   else
   11972                 :      714226 :                     n_adjacent_loads++;
   11973                 :             :                 }
   11974                 :             :             }
   11975                 :             :           else
   11976                 :             :             {
   11977                 :      203344 :               vec_dest = vect_create_destination_var (scalar_dest, vectype);
   11978                 :             :               /* DATA_REF is null if we've already built the statement.  */
   11979                 :      203344 :               if (data_ref)
   11980                 :             :                 {
   11981                 :      201803 :                   vect_copy_ref_info (data_ref, DR_REF (first_dr_info->dr));
   11982                 :      201803 :                   new_stmt = gimple_build_assign (vec_dest, data_ref);
   11983                 :             :                 }
   11984                 :             : 
   11985                 :      406688 :               new_temp = need_zeroing
   11986                 :      203344 :                 ? make_ssa_name (vectype)
   11987                 :      203344 :                 : make_ssa_name (vec_dest, new_stmt);
   11988                 :      203344 :               gimple_set_lhs (new_stmt, new_temp);
   11989                 :      203344 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
   11990                 :             : 
   11991                 :             :               /* If we need to explicitly zero inactive elements emit a
   11992                 :             :                  VEC_COND_EXPR that does so.  */
   11993                 :      203344 :               if (need_zeroing)
   11994                 :             :                 {
   11995                 :           0 :                   vec_els = vect_get_mask_load_else (MASK_LOAD_ELSE_ZERO,
   11996                 :             :                                                      vectype);
   11997                 :             : 
   11998                 :           0 :                   tree new_temp2 = make_ssa_name (vec_dest, new_stmt);
   11999                 :           0 :                   new_stmt
   12000                 :           0 :                     = gimple_build_assign (new_temp2, VEC_COND_EXPR,
   12001                 :             :                                            final_mask, new_temp, vec_els);
   12002                 :           0 :                   vect_finish_stmt_generation (vinfo, stmt_info, new_stmt,
   12003                 :             :                                                gsi);
   12004                 :           0 :                   new_temp = new_temp2;
   12005                 :             :                 }
   12006                 :             :             }
   12007                 :             : 
   12008                 :             :           /* 3. Handle explicit realignment if necessary/supported.
   12009                 :             :              Create in loop:
   12010                 :             :                vec_dest = realign_load (msq, lsq, realignment_token)  */
   12011                 :      917570 :           if (!costing_p
   12012                 :      203344 :               && (alignment_support_scheme == dr_explicit_realign_optimized
   12013                 :      203344 :                   || alignment_support_scheme == dr_explicit_realign))
   12014                 :             :             {
   12015                 :           0 :               lsq = gimple_assign_lhs (new_stmt);
   12016                 :           0 :               if (!realignment_token)
   12017                 :           0 :                 realignment_token = dataref_ptr;
   12018                 :           0 :               vec_dest = vect_create_destination_var (scalar_dest, vectype);
   12019                 :           0 :               new_stmt = gimple_build_assign (vec_dest, REALIGN_LOAD_EXPR, msq,
   12020                 :             :                                               lsq, realignment_token);
   12021                 :           0 :               new_temp = make_ssa_name (vec_dest, new_stmt);
   12022                 :           0 :               gimple_assign_set_lhs (new_stmt, new_temp);
   12023                 :           0 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
   12024                 :             : 
   12025                 :           0 :               if (alignment_support_scheme == dr_explicit_realign_optimized)
   12026                 :             :                 {
   12027                 :           0 :                   gcc_assert (phi);
   12028                 :           0 :                   if (i == vec_num - 1 && j == ncopies - 1)
   12029                 :           0 :                     add_phi_arg (phi, lsq, loop_latch_edge (containing_loop),
   12030                 :             :                                  UNKNOWN_LOCATION);
   12031                 :             :                   msq = lsq;
   12032                 :             :                 }
   12033                 :             :             }
   12034                 :             : 
   12035                 :      917570 :           if (memory_access_type == VMAT_CONTIGUOUS_REVERSE)
   12036                 :             :             {
   12037                 :        6517 :               if (costing_p)
   12038                 :        5105 :                 inside_cost = record_stmt_cost (cost_vec, 1, vec_perm,
   12039                 :             :                                                 slp_node, 0, vect_body);
   12040                 :             :               else
   12041                 :             :                 {
   12042                 :        1412 :                   tree perm_mask = perm_mask_for_reverse (vectype);
   12043                 :        1412 :                   new_temp = permute_vec_elements (vinfo, new_temp, new_temp,
   12044                 :             :                                                    perm_mask, stmt_info, gsi);
   12045                 :        1412 :                   new_stmt = SSA_NAME_DEF_STMT (new_temp);
   12046                 :             :                 }
   12047                 :             :             }
   12048                 :             : 
   12049                 :             :           /* Collect vector loads and later create their permutation in
   12050                 :             :              vect_transform_grouped_load ().  */
   12051                 :      917570 :           if (!costing_p && (grouped_load || slp_perm))
   12052                 :       29199 :             dr_chain.quick_push (new_temp);
   12053                 :             : 
   12054                 :             :           /* Store vector loads in the corresponding SLP_NODE.  */
   12055                 :      917570 :           if (!costing_p && slp && !slp_perm)
   12056                 :      174145 :             slp_node->push_vec_def (new_stmt);
   12057                 :             : 
   12058                 :             :           /* With SLP permutation we load the gaps as well, without
   12059                 :             :              we need to skip the gaps after we manage to fully load
   12060                 :             :              all elements.  group_gap_adj is DR_GROUP_SIZE here.  */
   12061                 :      917570 :           group_elt += nunits;
   12062                 :      917570 :           if (!costing_p
   12063                 :      203344 :               && maybe_ne (group_gap_adj, 0U)
   12064                 :       24064 :               && !slp_perm
   12065                 :      941306 :               && known_eq (group_elt, group_size - group_gap_adj))
   12066                 :             :             {
   12067                 :       16749 :               poly_wide_int bump_val
   12068                 :       16749 :                 = (wi::to_wide (TYPE_SIZE_UNIT (elem_type)) * group_gap_adj);
   12069                 :       16749 :               if (tree_int_cst_sgn (vect_dr_behavior (vinfo, dr_info)->step)
   12070                 :             :                   == -1)
   12071                 :           0 :                 bump_val = -bump_val;
   12072                 :       16749 :               tree bump = wide_int_to_tree (sizetype, bump_val);
   12073                 :       16749 :               dataref_ptr = bump_vector_ptr (vinfo, dataref_ptr, ptr_incr, gsi,
   12074                 :             :                                              stmt_info, bump);
   12075                 :       16749 :               group_elt = 0;
   12076                 :       16749 :             }
   12077                 :             :         }
   12078                 :             :       /* Bump the vector pointer to account for a gap or for excess
   12079                 :             :          elements loaded for a permuted SLP load.  */
   12080                 :      538014 :       if (!costing_p
   12081                 :      152608 :           && maybe_ne (group_gap_adj, 0U)
   12082                 :      554926 :           && slp_perm)
   12083                 :             :         {
   12084                 :         163 :           poly_wide_int bump_val
   12085                 :         163 :             = (wi::to_wide (TYPE_SIZE_UNIT (elem_type)) * group_gap_adj);
   12086                 :         163 :           if (tree_int_cst_sgn (vect_dr_behavior (vinfo, dr_info)->step) == -1)
   12087                 :           9 :             bump_val = -bump_val;
   12088                 :         163 :           tree bump = wide_int_to_tree (sizetype, bump_val);
   12089                 :         163 :           dataref_ptr = bump_vector_ptr (vinfo, dataref_ptr, ptr_incr, gsi,
   12090                 :             :                                          stmt_info, bump);
   12091                 :         163 :         }
   12092                 :             : 
   12093                 :      538014 :       if (slp && !slp_perm)
   12094                 :      489895 :         continue;
   12095                 :             : 
   12096                 :       48119 :       if (slp_perm)
   12097                 :             :         {
   12098                 :       48119 :           unsigned n_perms;
   12099                 :             :           /* For SLP we know we've seen all possible uses of dr_chain so
   12100                 :             :              direct vect_transform_slp_perm_load to DCE the unused parts.
   12101                 :             :              ???  This is a hack to prevent compile-time issues as seen
   12102                 :             :              in PR101120 and friends.  */
   12103                 :       48119 :           if (costing_p)
   12104                 :             :             {
   12105                 :       34553 :               vect_transform_slp_perm_load (vinfo, slp_node, vNULL, nullptr, vf,
   12106                 :             :                                             true, &n_perms, nullptr);
   12107                 :       34553 :               inside_cost = record_stmt_cost (cost_vec, n_perms, vec_perm,
   12108                 :             :                                               slp_node, 0, vect_body);
   12109                 :             :             }
   12110                 :             :           else
   12111                 :             :             {
   12112                 :       13566 :               bool ok = vect_transform_slp_perm_load (vinfo, slp_node, dr_chain,
   12113                 :             :                                                       gsi, vf, false, &n_perms,
   12114                 :             :                                                       nullptr, true);
   12115                 :       13566 :               gcc_assert (ok);
   12116                 :             :             }
   12117                 :             :         }
   12118                 :             :       else
   12119                 :             :         {
   12120                 :           0 :           if (grouped_load)
   12121                 :             :             {
   12122                 :           0 :               gcc_assert (memory_access_type == VMAT_CONTIGUOUS_PERMUTE);
   12123                 :             :               /* We assume that the cost of a single load-lanes instruction
   12124                 :             :                  is equivalent to the cost of DR_GROUP_SIZE separate loads.
   12125                 :             :                  If a grouped access is instead being provided by a
   12126                 :             :                  load-and-permute operation, include the cost of the
   12127                 :             :                  permutes.  */
   12128                 :           0 :               if (costing_p && first_stmt_info == stmt_info)
   12129                 :             :                 {
   12130                 :             :                   /* Uses an even and odd extract operations or shuffle
   12131                 :             :                      operations for each needed permute.  */
   12132                 :           0 :                   int group_size = DR_GROUP_SIZE (first_stmt_info);
   12133                 :           0 :                   int nstmts = ceil_log2 (group_size) * group_size;
   12134                 :           0 :                   inside_cost += record_stmt_cost (cost_vec, nstmts, vec_perm,
   12135                 :             :                                                    slp_node, 0, vect_body);
   12136                 :             : 
   12137                 :           0 :                   if (dump_enabled_p ())
   12138                 :           0 :                     dump_printf_loc (MSG_NOTE, vect_location,
   12139                 :             :                                      "vect_model_load_cost: "
   12140                 :             :                                      "strided group_size = %d .\n",
   12141                 :             :                                      group_size);
   12142                 :             :                 }
   12143                 :           0 :               else if (!costing_p)
   12144                 :             :                 {
   12145                 :           0 :                   vect_transform_grouped_load (vinfo, stmt_info, dr_chain,
   12146                 :             :                                                group_size, gsi);
   12147                 :           0 :                   *vec_stmt = STMT_VINFO_VEC_STMTS (stmt_info)[0];
   12148                 :             :                 }
   12149                 :             :             }
   12150                 :           0 :           else if (!costing_p)
   12151                 :           0 :             STMT_VINFO_VEC_STMTS (stmt_info).safe_push (new_stmt);
   12152                 :             :         }
   12153                 :       48119 :       dr_chain.release ();
   12154                 :             :     }
   12155                 :      538014 :   if (!slp && !costing_p)
   12156                 :           0 :     *vec_stmt = STMT_VINFO_VEC_STMTS (stmt_info)[0];
   12157                 :             : 
   12158                 :      538014 :   if (costing_p)
   12159                 :             :     {
   12160                 :      385406 :       gcc_assert (memory_access_type == VMAT_CONTIGUOUS
   12161                 :             :                   || memory_access_type == VMAT_CONTIGUOUS_REVERSE
   12162                 :             :                   || memory_access_type == VMAT_CONTIGUOUS_PERMUTE);
   12163                 :      385406 :       if (n_adjacent_loads > 0)
   12164                 :      385406 :         vect_get_load_cost (vinfo, stmt_info, slp_node, n_adjacent_loads,
   12165                 :             :                             alignment_support_scheme, misalignment, false,
   12166                 :             :                             &inside_cost, &prologue_cost, cost_vec, cost_vec,
   12167                 :             :                             true);
   12168                 :      385406 :       if (dump_enabled_p ())
   12169                 :       25721 :         dump_printf_loc (MSG_NOTE, vect_location,
   12170                 :             :                          "vect_model_load_cost: inside_cost = %u, "
   12171                 :             :                          "prologue_cost = %u .\n",
   12172                 :             :                          inside_cost, prologue_cost);
   12173                 :             :     }
   12174                 :             : 
   12175                 :             :   return true;
   12176                 :     1199437 : }
   12177                 :             : 
   12178                 :             : /* Function vect_is_simple_cond.
   12179                 :             : 
   12180                 :             :    Input:
   12181                 :             :    LOOP - the loop that is being vectorized.
   12182                 :             :    COND - Condition that is checked for simple use.
   12183                 :             : 
   12184                 :             :    Output:
   12185                 :             :    *COMP_VECTYPE - the vector type for the comparison.
   12186                 :             :    *DTS - The def types for the arguments of the comparison
   12187                 :             : 
   12188                 :             :    Returns whether a COND can be vectorized.  Checks whether
   12189                 :             :    condition operands are supportable using vec_is_simple_use.  */
   12190                 :             : 
   12191                 :             : static bool
   12192                 :       25934 : vect_is_simple_cond (tree cond, vec_info *vinfo, stmt_vec_info stmt_info,
   12193                 :             :                      slp_tree slp_node, tree *comp_vectype,
   12194                 :             :                      enum vect_def_type *dts, tree vectype)
   12195                 :             : {
   12196                 :       25934 :   tree lhs, rhs;
   12197                 :       25934 :   tree vectype1 = NULL_TREE, vectype2 = NULL_TREE;
   12198                 :       25934 :   slp_tree slp_op;
   12199                 :             : 
   12200                 :             :   /* Mask case.  */
   12201                 :       25934 :   if (TREE_CODE (cond) == SSA_NAME
   12202                 :       25934 :       && VECT_SCALAR_BOOLEAN_TYPE_P (TREE_TYPE (cond)))
   12203                 :             :     {
   12204                 :       25922 :       if (!vect_is_simple_use (vinfo, stmt_info, slp_node, 0, &cond,
   12205                 :             :                                &slp_op, &dts[0], comp_vectype)
   12206                 :       25922 :           || !*comp_vectype
   12207                 :       51810 :           || !VECTOR_BOOLEAN_TYPE_P (*comp_vectype))
   12208                 :             :         return false;
   12209                 :             :       return true;
   12210                 :             :     }
   12211                 :             : 
   12212                 :          12 :   if (!COMPARISON_CLASS_P (cond))
   12213                 :             :     return false;
   12214                 :             : 
   12215                 :           0 :   lhs = TREE_OPERAND (cond, 0);
   12216                 :           0 :   rhs = TREE_OPERAND (cond, 1);
   12217                 :             : 
   12218                 :           0 :   if (TREE_CODE (lhs) == SSA_NAME)
   12219                 :             :     {
   12220                 :           0 :       if (!vect_is_simple_use (vinfo, stmt_info, slp_node, 0,
   12221                 :             :                                &lhs, &slp_op, &dts[0], &vectype1))
   12222                 :             :         return false;
   12223                 :             :     }
   12224                 :           0 :   else if (TREE_CODE (lhs) == INTEGER_CST || TREE_CODE (lhs) == REAL_CST
   12225                 :           0 :            || TREE_CODE (lhs) == FIXED_CST)
   12226                 :           0 :     dts[0] = vect_constant_def;
   12227                 :             :   else
   12228                 :             :     return false;
   12229                 :             : 
   12230                 :           0 :   if (TREE_CODE (rhs) == SSA_NAME)
   12231                 :             :     {
   12232                 :           0 :       if (!vect_is_simple_use (vinfo, stmt_info, slp_node, 1,
   12233                 :             :                                &rhs, &slp_op, &dts[1], &vectype2))
   12234                 :             :         return false;
   12235                 :             :     }
   12236                 :           0 :   else if (TREE_CODE (rhs) == INTEGER_CST || TREE_CODE (rhs) == REAL_CST
   12237                 :           0 :            || TREE_CODE (rhs) == FIXED_CST)
   12238                 :           0 :     dts[1] = vect_constant_def;
   12239                 :             :   else
   12240                 :             :     return false;
   12241                 :             : 
   12242                 :           0 :   if (vectype1 && vectype2
   12243                 :           0 :       && maybe_ne (TYPE_VECTOR_SUBPARTS (vectype1),
   12244                 :           0 :                    TYPE_VECTOR_SUBPARTS (vectype2)))
   12245                 :           0 :     return false;
   12246                 :             : 
   12247                 :           0 :   *comp_vectype = vectype1 ? vectype1 : vectype2;
   12248                 :             :   /* Invariant comparison.  */
   12249                 :           0 :   if (! *comp_vectype)
   12250                 :             :     {
   12251                 :           0 :       tree scalar_type = TREE_TYPE (lhs);
   12252                 :           0 :       if (VECT_SCALAR_BOOLEAN_TYPE_P (scalar_type))
   12253                 :           0 :         *comp_vectype = truth_type_for (vectype);
   12254                 :             :       else
   12255                 :             :         {
   12256                 :             :           /* If we can widen the comparison to match vectype do so.  */
   12257                 :           0 :           if (INTEGRAL_TYPE_P (scalar_type)
   12258                 :           0 :               && !slp_node
   12259                 :           0 :               && tree_int_cst_lt (TYPE_SIZE (scalar_type),
   12260                 :           0 :                                   TYPE_SIZE (TREE_TYPE (vectype))))
   12261                 :           0 :             scalar_type = build_nonstandard_integer_type
   12262                 :           0 :               (vector_element_bits (vectype), TYPE_UNSIGNED (scalar_type));
   12263                 :           0 :           *comp_vectype = get_vectype_for_scalar_type (vinfo, scalar_type,
   12264                 :             :                                                        slp_node);
   12265                 :             :         }
   12266                 :             :     }
   12267                 :             : 
   12268                 :             :   return true;
   12269                 :             : }
   12270                 :             : 
   12271                 :             : /* vectorizable_condition.
   12272                 :             : 
   12273                 :             :    Check if STMT_INFO is conditional modify expression that can be vectorized.
   12274                 :             :    If VEC_STMT is also passed, vectorize STMT_INFO: create a vectorized
   12275                 :             :    stmt using VEC_COND_EXPR  to replace it, put it in VEC_STMT, and insert it
   12276                 :             :    at GSI.
   12277                 :             : 
   12278                 :             :    When STMT_INFO is vectorized as a nested cycle, for_reduction is true.
   12279                 :             : 
   12280                 :             :    Return true if STMT_INFO is vectorizable in this way.  */
   12281                 :             : 
   12282                 :             : static bool
   12283                 :      469724 : vectorizable_condition (vec_info *vinfo,
   12284                 :             :                         stmt_vec_info stmt_info, gimple_stmt_iterator *gsi,
   12285                 :             :                         gimple **vec_stmt,
   12286                 :             :                         slp_tree slp_node, stmt_vector_for_cost *cost_vec)
   12287                 :             : {
   12288                 :      469724 :   tree scalar_dest = NULL_TREE;
   12289                 :      469724 :   tree vec_dest = NULL_TREE;
   12290                 :      469724 :   tree cond_expr, cond_expr0 = NULL_TREE, cond_expr1 = NULL_TREE;
   12291                 :      469724 :   tree then_clause, else_clause;
   12292                 :      469724 :   tree comp_vectype = NULL_TREE;
   12293                 :      469724 :   tree vec_cond_lhs = NULL_TREE, vec_cond_rhs = NULL_TREE;
   12294                 :      469724 :   tree vec_then_clause = NULL_TREE, vec_else_clause = NULL_TREE;
   12295                 :      469724 :   tree vec_compare;
   12296                 :      469724 :   tree new_temp;
   12297                 :      469724 :   loop_vec_info loop_vinfo = dyn_cast <loop_vec_info> (vinfo);
   12298                 :      469724 :   enum vect_def_type dts[4]
   12299                 :             :     = {vect_unknown_def_type, vect_unknown_def_type,
   12300                 :             :        vect_unknown_def_type, vect_unknown_def_type};
   12301                 :      469724 :   int ndts = 4;
   12302                 :      469724 :   int ncopies;
   12303                 :      469724 :   int vec_num;
   12304                 :      469724 :   enum tree_code code, cond_code, bitop1 = NOP_EXPR, bitop2 = NOP_EXPR;
   12305                 :      469724 :   int i;
   12306                 :      469724 :   bb_vec_info bb_vinfo = dyn_cast <bb_vec_info> (vinfo);
   12307                 :      469724 :   vec<tree> vec_oprnds0 = vNULL;
   12308                 :      469724 :   vec<tree> vec_oprnds1 = vNULL;
   12309                 :      469724 :   vec<tree> vec_oprnds2 = vNULL;
   12310                 :      469724 :   vec<tree> vec_oprnds3 = vNULL;
   12311                 :      469724 :   tree vec_cmp_type;
   12312                 :      469724 :   bool masked = false;
   12313                 :             : 
   12314                 :      469724 :   if (!STMT_VINFO_RELEVANT_P (stmt_info) && !bb_vinfo)
   12315                 :             :     return false;
   12316                 :             : 
   12317                 :             :   /* Is vectorizable conditional operation?  */
   12318                 :      805573 :   gassign *stmt = dyn_cast <gassign *> (stmt_info->stmt);
   12319                 :      360425 :   if (!stmt)
   12320                 :             :     return false;
   12321                 :             : 
   12322                 :      360425 :   code = gimple_assign_rhs_code (stmt);
   12323                 :      360425 :   if (code != COND_EXPR)
   12324                 :             :     return false;
   12325                 :             : 
   12326                 :       25934 :   stmt_vec_info reduc_info = NULL;
   12327                 :       25934 :   int reduc_index = -1;
   12328                 :       25934 :   vect_reduction_type reduction_type = TREE_CODE_REDUCTION;
   12329                 :       25934 :   bool for_reduction
   12330                 :       25934 :     = STMT_VINFO_REDUC_DEF (vect_orig_stmt (stmt_info)) != NULL;
   12331                 :       25934 :   if (for_reduction)
   12332                 :             :     {
   12333                 :         850 :       if (slp_node && SLP_TREE_LANES (slp_node) > 1)
   12334                 :             :         return false;
   12335                 :         850 :       reduc_info = info_for_reduction (vinfo, stmt_info);
   12336                 :         850 :       reduction_type = STMT_VINFO_REDUC_TYPE (reduc_info);
   12337                 :         850 :       reduc_index = STMT_VINFO_REDUC_IDX (stmt_info);
   12338                 :         850 :       gcc_assert (reduction_type != EXTRACT_LAST_REDUCTION
   12339                 :             :                   || reduc_index != -1);
   12340                 :             :     }
   12341                 :             :   else
   12342                 :             :     {
   12343                 :       25084 :       if (STMT_VINFO_DEF_TYPE (stmt_info) != vect_internal_def)
   12344                 :             :         return false;
   12345                 :             :     }
   12346                 :             : 
   12347                 :       25934 :   tree vectype = STMT_VINFO_VECTYPE (stmt_info);
   12348                 :       25934 :   tree vectype1 = NULL_TREE, vectype2 = NULL_TREE;
   12349                 :             : 
   12350                 :       25934 :   if (slp_node)
   12351                 :             :     {
   12352                 :       25934 :       ncopies = 1;
   12353                 :       25934 :       vec_num = SLP_TREE_NUMBER_OF_VEC_STMTS (slp_node);
   12354                 :             :     }
   12355                 :             :   else
   12356                 :             :     {
   12357                 :           0 :       ncopies = vect_get_num_copies (loop_vinfo, vectype);
   12358                 :           0 :       vec_num = 1;
   12359                 :             :     }
   12360                 :             : 
   12361                 :       25934 :   gcc_assert (ncopies >= 1);
   12362                 :       25934 :   if (for_reduction && ncopies > 1)
   12363                 :             :     return false; /* FORNOW */
   12364                 :             : 
   12365                 :       25934 :   cond_expr = gimple_assign_rhs1 (stmt);
   12366                 :       25934 :   gcc_assert (! COMPARISON_CLASS_P (cond_expr));
   12367                 :             : 
   12368                 :       25934 :   if (!vect_is_simple_cond (cond_expr, vinfo, stmt_info, slp_node,
   12369                 :             :                             &comp_vectype, &dts[0], vectype)
   12370                 :       25934 :       || !comp_vectype)
   12371                 :             :     return false;
   12372                 :             : 
   12373                 :       25832 :   unsigned op_adjust = COMPARISON_CLASS_P (cond_expr) ? 1 : 0;
   12374                 :       25832 :   slp_tree then_slp_node, else_slp_node;
   12375                 :       25832 :   if (!vect_is_simple_use (vinfo, stmt_info, slp_node, 1 + op_adjust,
   12376                 :             :                            &then_clause, &then_slp_node, &dts[2], &vectype1))
   12377                 :             :     return false;
   12378                 :       25832 :   if (!vect_is_simple_use (vinfo, stmt_info, slp_node, 2 + op_adjust,
   12379                 :             :                            &else_clause, &else_slp_node, &dts[3], &vectype2))
   12380                 :             :     return false;
   12381                 :             : 
   12382                 :       25832 :   if (vectype1 && !useless_type_conversion_p (vectype, vectype1))
   12383                 :             :     return false;
   12384                 :             : 
   12385                 :       25832 :   if (vectype2 && !useless_type_conversion_p (vectype, vectype2))
   12386                 :             :     return false;
   12387                 :             : 
   12388                 :       25832 :   masked = !COMPARISON_CLASS_P (cond_expr);
   12389                 :       25832 :   vec_cmp_type = truth_type_for (comp_vectype);
   12390                 :       25832 :   if (vec_cmp_type == NULL_TREE
   12391                 :       51664 :       || maybe_ne (TYPE_VECTOR_SUBPARTS (vectype),
   12392                 :       25832 :                    TYPE_VECTOR_SUBPARTS (vec_cmp_type)))
   12393                 :        1128 :     return false;
   12394                 :             : 
   12395                 :       24704 :   cond_code = TREE_CODE (cond_expr);
   12396                 :       24704 :   if (!masked)
   12397                 :             :     {
   12398                 :           0 :       cond_expr0 = TREE_OPERAND (cond_expr, 0);
   12399                 :           0 :       cond_expr1 = TREE_OPERAND (cond_expr, 1);
   12400                 :             :     }
   12401                 :             : 
   12402                 :             :   /* For conditional reductions, the "then" value needs to be the candidate
   12403                 :             :      value calculated by this iteration while the "else" value needs to be
   12404                 :             :      the result carried over from previous iterations.  If the COND_EXPR
   12405                 :             :      is the other way around, we need to swap it.  */
   12406                 :       24704 :   bool must_invert_cmp_result = false;
   12407                 :       24704 :   if (reduction_type == EXTRACT_LAST_REDUCTION && reduc_index == 1)
   12408                 :             :     {
   12409                 :           0 :       if (masked)
   12410                 :             :         must_invert_cmp_result = true;
   12411                 :             :       else
   12412                 :             :         {
   12413                 :           0 :           bool honor_nans = HONOR_NANS (TREE_TYPE (cond_expr0));
   12414                 :           0 :           tree_code new_code = invert_tree_comparison (cond_code, honor_nans);
   12415                 :           0 :           if (new_code == ERROR_MARK)
   12416                 :             :             must_invert_cmp_result = true;
   12417                 :             :           else
   12418                 :             :             {
   12419                 :           0 :               cond_code = new_code;
   12420                 :             :               /* Make sure we don't accidentally use the old condition.  */
   12421                 :           0 :               cond_expr = NULL_TREE;
   12422                 :             :             }
   12423                 :             :         }
   12424                 :             :       /* ???  The vectorized operand query below doesn't allow swapping
   12425                 :             :          this way for SLP.  */
   12426                 :           0 :       if (slp_node)
   12427                 :             :         return false;
   12428                 :           0 :       std::swap (then_clause, else_clause);
   12429                 :             :     }
   12430                 :             : 
   12431                 :       24704 :   if (!masked && VECTOR_BOOLEAN_TYPE_P (comp_vectype))
   12432                 :             :     {
   12433                 :             :       /* Boolean values may have another representation in vectors
   12434                 :             :          and therefore we prefer bit operations over comparison for
   12435                 :             :          them (which also works for scalar masks).  We store opcodes
   12436                 :             :          to use in bitop1 and bitop2.  Statement is vectorized as
   12437                 :             :          BITOP2 (rhs1 BITOP1 rhs2) or rhs1 BITOP2 (BITOP1 rhs2)
   12438                 :             :          depending on bitop1 and bitop2 arity.  */
   12439                 :           0 :       switch (cond_code)
   12440                 :             :         {
   12441                 :             :         case GT_EXPR:
   12442                 :             :           bitop1 = BIT_NOT_EXPR;
   12443                 :             :           bitop2 = BIT_AND_EXPR;
   12444                 :             :           break;
   12445                 :           0 :         case GE_EXPR:
   12446                 :           0 :           bitop1 = BIT_NOT_EXPR;
   12447                 :           0 :           bitop2 = BIT_IOR_EXPR;
   12448                 :           0 :           break;
   12449                 :           0 :         case LT_EXPR:
   12450                 :           0 :           bitop1 = BIT_NOT_EXPR;
   12451                 :           0 :           bitop2 = BIT_AND_EXPR;
   12452                 :           0 :           std::swap (cond_expr0, cond_expr1);
   12453                 :           0 :           break;
   12454                 :           0 :         case LE_EXPR:
   12455                 :           0 :           bitop1 = BIT_NOT_EXPR;
   12456                 :           0 :           bitop2 = BIT_IOR_EXPR;
   12457                 :           0 :           std::swap (cond_expr0, cond_expr1);
   12458                 :           0 :           break;
   12459                 :           0 :         case NE_EXPR:
   12460                 :           0 :           bitop1 = BIT_XOR_EXPR;
   12461                 :           0 :           break;
   12462                 :           0 :         case EQ_EXPR:
   12463                 :           0 :           bitop1 = BIT_XOR_EXPR;
   12464                 :           0 :           bitop2 = BIT_NOT_EXPR;
   12465                 :           0 :           break;
   12466                 :             :         default:
   12467                 :             :           return false;
   12468                 :             :         }
   12469                 :             :       cond_code = SSA_NAME;
   12470                 :             :     }
   12471                 :             : 
   12472                 :       24704 :   if (TREE_CODE_CLASS (cond_code) == tcc_comparison
   12473                 :           0 :       && reduction_type == EXTRACT_LAST_REDUCTION
   12474                 :       24704 :       && !expand_vec_cmp_expr_p (comp_vectype, vec_cmp_type, cond_code))
   12475                 :             :     {
   12476                 :           0 :       if (dump_enabled_p ())
   12477                 :           0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
   12478                 :             :                          "reduction comparison operation not supported.\n");
   12479                 :           0 :       return false;
   12480                 :             :     }
   12481                 :             : 
   12482                 :       24704 :   if (!vec_stmt)
   12483                 :             :     {
   12484                 :       18319 :       if (bitop1 != NOP_EXPR)
   12485                 :             :         {
   12486                 :           0 :           machine_mode mode = TYPE_MODE (comp_vectype);
   12487                 :           0 :           optab optab;
   12488                 :             : 
   12489                 :           0 :           optab = optab_for_tree_code (bitop1, comp_vectype, optab_default);
   12490                 :           0 :           if (!optab || !can_implement_p (optab, mode))
   12491                 :           0 :             return false;
   12492                 :             : 
   12493                 :           0 :           if (bitop2 != NOP_EXPR)
   12494                 :             :             {
   12495                 :           0 :               optab = optab_for_tree_code (bitop2, comp_vectype,
   12496                 :             :                                            optab_default);
   12497                 :           0 :               if (!optab || !can_implement_p (optab, mode))
   12498                 :           0 :                 return false;
   12499                 :             :             }
   12500                 :             :         }
   12501                 :             : 
   12502                 :       18319 :       vect_cost_for_stmt kind = vector_stmt;
   12503                 :       18319 :       if (reduction_type == EXTRACT_LAST_REDUCTION)
   12504                 :             :         /* Count one reduction-like operation per vector.  */
   12505                 :             :         kind = vec_to_scalar;
   12506                 :       18319 :       else if ((masked && !expand_vec_cond_expr_p (vectype, comp_vectype))
   12507                 :       18319 :                || (!masked
   12508                 :           0 :                    && (!expand_vec_cmp_expr_p (comp_vectype, vec_cmp_type,
   12509                 :             :                                                cond_code)
   12510                 :           0 :                        || !expand_vec_cond_expr_p (vectype, vec_cmp_type))))
   12511                 :         128 :         return false;
   12512                 :             : 
   12513                 :       18191 :       if (slp_node
   12514                 :       36382 :           && (!vect_maybe_update_slp_op_vectype
   12515                 :       18191 :                  (SLP_TREE_CHILDREN (slp_node)[0], comp_vectype)
   12516                 :       18191 :               || (op_adjust == 1
   12517                 :           0 :                   && !vect_maybe_update_slp_op_vectype
   12518                 :           0 :                         (SLP_TREE_CHILDREN (slp_node)[1], comp_vectype))
   12519                 :       18191 :               || !vect_maybe_update_slp_op_vectype (then_slp_node, vectype)
   12520                 :       18191 :               || !vect_maybe_update_slp_op_vectype (else_slp_node, vectype)))
   12521                 :             :         {
   12522                 :           0 :           if (dump_enabled_p ())
   12523                 :           0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
   12524                 :             :                              "incompatible vector types for invariants\n");
   12525                 :           0 :           return false;
   12526                 :             :         }
   12527                 :             : 
   12528                 :       18191 :       if (loop_vinfo && for_reduction
   12529                 :         671 :           && LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo))
   12530                 :             :         {
   12531                 :           0 :           if (reduction_type == EXTRACT_LAST_REDUCTION)
   12532                 :             :             {
   12533                 :           0 :               if (direct_internal_fn_supported_p (IFN_LEN_FOLD_EXTRACT_LAST,
   12534                 :             :                                                   vectype, OPTIMIZE_FOR_SPEED))
   12535                 :           0 :                 vect_record_loop_len (loop_vinfo,
   12536                 :             :                                       &LOOP_VINFO_LENS (loop_vinfo),
   12537                 :           0 :                                       ncopies * vec_num, vectype, 1);
   12538                 :             :               else
   12539                 :           0 :                 vect_record_loop_mask (loop_vinfo,
   12540                 :             :                                        &LOOP_VINFO_MASKS (loop_vinfo),
   12541                 :           0 :                                        ncopies * vec_num, vectype, NULL);
   12542                 :             :             }
   12543                 :             :           /* Extra inactive lanes should be safe for vect_nested_cycle.  */
   12544                 :           0 :           else if (STMT_VINFO_DEF_TYPE (reduc_info) != vect_nested_cycle)
   12545                 :             :             {
   12546                 :           0 :               if (dump_enabled_p ())
   12547                 :           0 :                 dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
   12548                 :             :                                  "conditional reduction prevents the use"
   12549                 :             :                                  " of partial vectors.\n");
   12550                 :           0 :               LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo) = false;
   12551                 :             :             }
   12552                 :             :         }
   12553                 :             : 
   12554                 :       18191 :       STMT_VINFO_TYPE (stmt_info) = condition_vec_info_type;
   12555                 :       18191 :       vect_model_simple_cost (vinfo, ncopies, dts, ndts, slp_node,
   12556                 :             :                               cost_vec, kind);
   12557                 :       18191 :       return true;
   12558                 :             :     }
   12559                 :             : 
   12560                 :             :   /* Transform.  */
   12561                 :             : 
   12562                 :             :   /* Handle def.  */
   12563                 :        6385 :   scalar_dest = gimple_assign_lhs (stmt);
   12564                 :        6385 :   if (reduction_type != EXTRACT_LAST_REDUCTION)
   12565                 :        6385 :     vec_dest = vect_create_destination_var (scalar_dest, vectype);
   12566                 :             : 
   12567                 :        6385 :   bool swap_cond_operands = false;
   12568                 :             : 
   12569                 :             :   /* See whether another part of the vectorized code applies a loop
   12570                 :             :      mask to the condition, or to its inverse.  */
   12571                 :             : 
   12572                 :        6385 :   vec_loop_masks *masks = NULL;
   12573                 :        6385 :   vec_loop_lens *lens = NULL;
   12574                 :        6385 :   if (loop_vinfo && LOOP_VINFO_FULLY_WITH_LENGTH_P (loop_vinfo))
   12575                 :             :     {
   12576                 :           0 :       if (reduction_type == EXTRACT_LAST_REDUCTION)
   12577                 :           0 :         lens = &LOOP_VINFO_LENS (loop_vinfo);
   12578                 :             :     }
   12579                 :        6385 :   else if (loop_vinfo && LOOP_VINFO_FULLY_MASKED_P (loop_vinfo))
   12580                 :             :     {
   12581                 :           2 :       if (reduction_type == EXTRACT_LAST_REDUCTION)
   12582                 :           0 :         masks = &LOOP_VINFO_MASKS (loop_vinfo);
   12583                 :             :       else
   12584                 :             :         {
   12585                 :           2 :           scalar_cond_masked_key cond (cond_expr, ncopies);
   12586                 :           2 :           if (loop_vinfo->scalar_cond_masked_set.contains (cond))
   12587                 :           0 :             masks = &LOOP_VINFO_MASKS (loop_vinfo);
   12588                 :             :           else
   12589                 :             :             {
   12590                 :           2 :               bool honor_nans = HONOR_NANS (TREE_TYPE (cond.op0));
   12591                 :           2 :               tree_code orig_code = cond.code;
   12592                 :           2 :               cond.code = invert_tree_comparison (cond.code, honor_nans);
   12593                 :           2 :               if (!masked && loop_vinfo->scalar_cond_masked_set.contains (cond))
   12594                 :             :                 {
   12595                 :           0 :                   masks = &LOOP_VINFO_MASKS (loop_vinfo);
   12596                 :           0 :                   cond_code = cond.code;
   12597                 :           0 :                   swap_cond_operands = true;
   12598                 :             :                 }
   12599                 :             :               else
   12600                 :             :                 {
   12601                 :             :                   /* Try the inverse of the current mask.  We check if the
   12602                 :             :                      inverse mask is live and if so we generate a negate of
   12603                 :             :                      the current mask such that we still honor NaNs.  */
   12604                 :           2 :                   cond.inverted_p = true;
   12605                 :           2 :                   cond.code = orig_code;
   12606                 :           2 :                   if (loop_vinfo->scalar_cond_masked_set.contains (cond))
   12607                 :             :                     {
   12608                 :           0 :                       masks = &LOOP_VINFO_MASKS (loop_vinfo);
   12609                 :           0 :                       cond_code = cond.code;
   12610                 :           0 :                       swap_cond_operands = true;
   12611                 :           0 :                       must_invert_cmp_result = true;
   12612                 :             :                     }
   12613                 :             :                 }
   12614                 :             :             }
   12615                 :             :         }
   12616                 :             :     }
   12617                 :             : 
   12618                 :             :   /* Handle cond expr.  */
   12619                 :        6385 :   if (masked)
   12620                 :        6385 :     vect_get_vec_defs (vinfo, stmt_info, slp_node, ncopies,
   12621                 :             :                        cond_expr, comp_vectype, &vec_oprnds0,
   12622                 :             :                        then_clause, vectype, &vec_oprnds2,
   12623                 :             :                        reduction_type != EXTRACT_LAST_REDUCTION
   12624                 :             :                        ? else_clause : NULL, vectype, &vec_oprnds3);
   12625                 :             :   else
   12626                 :           0 :     vect_get_vec_defs (vinfo, stmt_info, slp_node, ncopies,
   12627                 :             :                        cond_expr0, comp_vectype, &vec_oprnds0,
   12628                 :             :                        cond_expr1, comp_vectype, &vec_oprnds1,
   12629                 :             :                        then_clause, vectype, &vec_oprnds2,
   12630                 :             :                        reduction_type != EXTRACT_LAST_REDUCTION
   12631                 :             :                        ? else_clause : NULL, vectype, &vec_oprnds3);
   12632                 :             : 
   12633                 :        6385 :   if (reduction_type == EXTRACT_LAST_REDUCTION)
   12634                 :           0 :     vec_else_clause = else_clause;
   12635                 :             : 
   12636                 :             :   /* Arguments are ready.  Create the new vector stmt.  */
   12637                 :       15322 :   FOR_EACH_VEC_ELT (vec_oprnds0, i, vec_cond_lhs)
   12638                 :             :     {
   12639                 :        8937 :       vec_then_clause = vec_oprnds2[i];
   12640                 :        8937 :       if (reduction_type != EXTRACT_LAST_REDUCTION)
   12641                 :        8937 :         vec_else_clause = vec_oprnds3[i];
   12642                 :             : 
   12643                 :        8937 :       if (swap_cond_operands)
   12644                 :           0 :         std::swap (vec_then_clause, vec_else_clause);
   12645                 :             : 
   12646                 :        8937 :       if (masked)
   12647                 :             :         vec_compare = vec_cond_lhs;
   12648                 :             :       else
   12649                 :             :         {
   12650                 :           0 :           vec_cond_rhs = vec_oprnds1[i];
   12651                 :           0 :           if (bitop1 == NOP_EXPR)
   12652                 :             :             {
   12653                 :           0 :               gimple_seq stmts = NULL;
   12654                 :           0 :               vec_compare = gimple_build (&stmts, cond_code, vec_cmp_type,
   12655                 :             :                                            vec_cond_lhs, vec_cond_rhs);
   12656                 :           0 :               gsi_insert_before (gsi, stmts, GSI_SAME_STMT);
   12657                 :             :             }
   12658                 :             :           else
   12659                 :             :             {
   12660                 :           0 :               new_temp = make_ssa_name (vec_cmp_type);
   12661                 :           0 :               gassign *new_stmt;
   12662                 :           0 :               if (bitop1 == BIT_NOT_EXPR)
   12663                 :           0 :                 new_stmt = gimple_build_assign (new_temp, bitop1,
   12664                 :             :                                                 vec_cond_rhs);
   12665                 :             :               else
   12666                 :           0 :                 new_stmt
   12667                 :           0 :                   = gimple_build_assign (new_temp, bitop1, vec_cond_lhs,
   12668                 :             :                                          vec_cond_rhs);
   12669                 :           0 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
   12670                 :           0 :               if (bitop2 == NOP_EXPR)
   12671                 :             :                 vec_compare = new_temp;
   12672                 :           0 :               else if (bitop2 == BIT_NOT_EXPR
   12673                 :           0 :                        && reduction_type != EXTRACT_LAST_REDUCTION)
   12674                 :             :                 {
   12675                 :             :                   /* Instead of doing ~x ? y : z do x ? z : y.  */
   12676                 :             :                   vec_compare = new_temp;
   12677                 :             :                   std::swap (vec_then_clause, vec_else_clause);
   12678                 :             :                 }
   12679                 :             :               else
   12680                 :             :                 {
   12681                 :           0 :                   vec_compare = make_ssa_name (vec_cmp_type);
   12682                 :           0 :                   if (bitop2 == BIT_NOT_EXPR)
   12683                 :           0 :                     new_stmt
   12684                 :           0 :                       = gimple_build_assign (vec_compare, bitop2, new_temp);
   12685                 :             :                   else
   12686                 :           0 :                     new_stmt
   12687                 :           0 :                       = gimple_build_assign (vec_compare, bitop2,
   12688                 :             :                                              vec_cond_lhs, new_temp);
   12689                 :           0 :                   vect_finish_stmt_generation (vinfo, stmt_info,
   12690                 :             :                                                new_stmt, gsi);
   12691                 :             :                 }
   12692                 :             :             }
   12693                 :             :         }
   12694                 :             : 
   12695                 :             :       /* If we decided to apply a loop mask to the result of the vector
   12696                 :             :          comparison, AND the comparison with the mask now.  Later passes
   12697                 :             :          should then be able to reuse the AND results between mulitple
   12698                 :             :          vector statements.
   12699                 :             : 
   12700                 :             :          For example:
   12701                 :             :          for (int i = 0; i < 100; ++i)
   12702                 :             :          x[i] = y[i] ? z[i] : 10;
   12703                 :             : 
   12704                 :             :          results in following optimized GIMPLE:
   12705                 :             : 
   12706                 :             :          mask__35.8_43 = vect__4.7_41 != { 0, ... };
   12707                 :             :          vec_mask_and_46 = loop_mask_40 & mask__35.8_43;
   12708                 :             :          _19 = &MEM[base: z_12(D), index: ivtmp_56, step: 4, offset: 0B];
   12709                 :             :          vect_iftmp.11_47 = .MASK_LOAD (_19, 4B, vec_mask_and_46);
   12710                 :             :          vect_iftmp.12_52 = VEC_COND_EXPR <vec_mask_and_46,
   12711                 :             :          vect_iftmp.11_47, { 10, ... }>;
   12712                 :             : 
   12713                 :             :          instead of using a masked and unmasked forms of
   12714                 :             :          vec != { 0, ... } (masked in the MASK_LOAD,
   12715                 :             :          unmasked in the VEC_COND_EXPR).  */
   12716                 :             : 
   12717                 :             :       /* Force vec_compare to be an SSA_NAME rather than a comparison,
   12718                 :             :          in cases where that's necessary.  */
   12719                 :             : 
   12720                 :        8937 :       tree len = NULL_TREE, bias = NULL_TREE;
   12721                 :        8937 :       if (masks || lens || reduction_type == EXTRACT_LAST_REDUCTION)
   12722                 :             :         {
   12723                 :           0 :           if (!is_gimple_val (vec_compare))
   12724                 :             :             {
   12725                 :           0 :               tree vec_compare_name = make_ssa_name (vec_cmp_type);
   12726                 :           0 :               gassign *new_stmt = gimple_build_assign (vec_compare_name,
   12727                 :             :                                                        vec_compare);
   12728                 :           0 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
   12729                 :           0 :               vec_compare = vec_compare_name;
   12730                 :             :             }
   12731                 :             : 
   12732                 :           0 :           if (must_invert_cmp_result)
   12733                 :             :             {
   12734                 :           0 :               tree vec_compare_name = make_ssa_name (vec_cmp_type);
   12735                 :           0 :               gassign *new_stmt = gimple_build_assign (vec_compare_name,
   12736                 :             :                                                        BIT_NOT_EXPR,
   12737                 :             :                                                        vec_compare);
   12738                 :           0 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
   12739                 :           0 :               vec_compare = vec_compare_name;
   12740                 :             :             }
   12741                 :             : 
   12742                 :           0 :           if (direct_internal_fn_supported_p (IFN_LEN_FOLD_EXTRACT_LAST,
   12743                 :             :                                               vectype, OPTIMIZE_FOR_SPEED))
   12744                 :             :             {
   12745                 :           0 :               if (lens)
   12746                 :             :                 {
   12747                 :           0 :                   len = vect_get_loop_len (loop_vinfo, gsi, lens,
   12748                 :           0 :                                            vec_num * ncopies, vectype, i, 1);
   12749                 :           0 :                   signed char biasval
   12750                 :           0 :                     = LOOP_VINFO_PARTIAL_LOAD_STORE_BIAS (loop_vinfo);
   12751                 :           0 :                   bias = build_int_cst (intQI_type_node, biasval);
   12752                 :             :                 }
   12753                 :             :               else
   12754                 :             :                 {
   12755                 :           0 :                   len = size_int (TYPE_VECTOR_SUBPARTS (vectype));
   12756                 :           0 :                   bias = build_int_cst (intQI_type_node, 0);
   12757                 :             :                 }
   12758                 :             :             }
   12759                 :           0 :           if (masks)
   12760                 :             :             {
   12761                 :           0 :               tree loop_mask
   12762                 :           0 :                 = vect_get_loop_mask (loop_vinfo, gsi, masks, vec_num * ncopies,
   12763                 :             :                                       vectype, i);
   12764                 :           0 :               tree tmp2 = make_ssa_name (vec_cmp_type);
   12765                 :           0 :               gassign *g
   12766                 :           0 :                 = gimple_build_assign (tmp2, BIT_AND_EXPR, vec_compare,
   12767                 :             :                                        loop_mask);
   12768                 :           0 :               vect_finish_stmt_generation (vinfo, stmt_info, g, gsi);
   12769                 :           0 :               vec_compare = tmp2;
   12770                 :             :             }
   12771                 :             :         }
   12772                 :             : 
   12773                 :           0 :       gimple *new_stmt;
   12774                 :           0 :       if (reduction_type == EXTRACT_LAST_REDUCTION)
   12775                 :             :         {
   12776                 :           0 :           gimple *old_stmt = vect_orig_stmt (stmt_info)->stmt;
   12777                 :           0 :           tree lhs = gimple_get_lhs (old_stmt);
   12778                 :           0 :           if ((unsigned)i != vec_oprnds0.length () - 1)
   12779                 :           0 :             lhs = copy_ssa_name (lhs);
   12780                 :           0 :           if (len)
   12781                 :           0 :             new_stmt = gimple_build_call_internal
   12782                 :           0 :                 (IFN_LEN_FOLD_EXTRACT_LAST, 5, vec_else_clause, vec_compare,
   12783                 :             :                  vec_then_clause, len, bias);
   12784                 :             :           else
   12785                 :           0 :             new_stmt = gimple_build_call_internal
   12786                 :           0 :                 (IFN_FOLD_EXTRACT_LAST, 3, vec_else_clause, vec_compare,
   12787                 :             :                  vec_then_clause);
   12788                 :           0 :           gimple_call_set_lhs (new_stmt, lhs);
   12789                 :           0 :           SSA_NAME_DEF_STMT (lhs) = new_stmt;
   12790                 :           0 :           if ((unsigned)i != vec_oprnds0.length () - 1)
   12791                 :             :             {
   12792                 :           0 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
   12793                 :           0 :               vec_else_clause = lhs;
   12794                 :             :             }
   12795                 :           0 :           else if (old_stmt == gsi_stmt (*gsi))
   12796                 :           0 :             vect_finish_replace_stmt (vinfo, stmt_info, new_stmt);
   12797                 :             :           else
   12798                 :             :             {
   12799                 :             :               /* In this case we're moving the definition to later in the
   12800                 :             :                  block.  That doesn't matter because the only uses of the
   12801                 :             :                  lhs are in phi statements.  */
   12802                 :           0 :               gimple_stmt_iterator old_gsi = gsi_for_stmt (old_stmt);
   12803                 :           0 :               gsi_remove (&old_gsi, true);
   12804                 :           0 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
   12805                 :             :             }
   12806                 :             :         }
   12807                 :             :       else
   12808                 :             :         {
   12809                 :        8937 :           new_temp = make_ssa_name (vec_dest);
   12810                 :        8937 :           new_stmt = gimple_build_assign (new_temp, VEC_COND_EXPR, vec_compare,
   12811                 :             :                                           vec_then_clause, vec_else_clause);
   12812                 :        8937 :           vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
   12813                 :             :         }
   12814                 :        8937 :       if (slp_node)
   12815                 :        8937 :         slp_node->push_vec_def (new_stmt);
   12816                 :             :       else
   12817                 :           0 :         STMT_VINFO_VEC_STMTS (stmt_info).safe_push (new_stmt);
   12818                 :             :     }
   12819                 :             : 
   12820                 :        6385 :   if (!slp_node)
   12821                 :           0 :     *vec_stmt = STMT_VINFO_VEC_STMTS (stmt_info)[0];
   12822                 :             : 
   12823                 :        6385 :   vec_oprnds0.release ();
   12824                 :        6385 :   vec_oprnds1.release ();
   12825                 :        6385 :   vec_oprnds2.release ();
   12826                 :        6385 :   vec_oprnds3.release ();
   12827                 :             : 
   12828                 :        6385 :   return true;
   12829                 :             : }
   12830                 :             : 
   12831                 :             : /* Helper of vectorizable_comparison.
   12832                 :             : 
   12833                 :             :    Check if STMT_INFO is comparison expression CODE that can be vectorized.
   12834                 :             :    If VEC_STMT is also passed, vectorize STMT_INFO: create a vectorized
   12835                 :             :    comparison, put it in VEC_STMT, and insert it at GSI.
   12836                 :             : 
   12837                 :             :    Return true if STMT_INFO is vectorizable in this way.  */
   12838                 :             : 
   12839                 :             : static bool
   12840                 :      347512 : vectorizable_comparison_1 (vec_info *vinfo, tree vectype,
   12841                 :             :                            stmt_vec_info stmt_info, tree_code code,
   12842                 :             :                            gimple_stmt_iterator *gsi, gimple **vec_stmt,
   12843                 :             :                            slp_tree slp_node, stmt_vector_for_cost *cost_vec)
   12844                 :             : {
   12845                 :      347512 :   tree lhs, rhs1, rhs2;
   12846                 :      347512 :   tree vectype1 = NULL_TREE, vectype2 = NULL_TREE;
   12847                 :      347512 :   tree vec_rhs1 = NULL_TREE, vec_rhs2 = NULL_TREE;
   12848                 :      347512 :   tree new_temp;
   12849                 :      347512 :   loop_vec_info loop_vinfo = dyn_cast <loop_vec_info> (vinfo);
   12850                 :      347512 :   enum vect_def_type dts[2] = {vect_unknown_def_type, vect_unknown_def_type};
   12851                 :      347512 :   int ndts = 2;
   12852                 :      347512 :   poly_uint64 nunits;
   12853                 :      347512 :   int ncopies;
   12854                 :      347512 :   enum tree_code bitop1 = NOP_EXPR, bitop2 = NOP_EXPR;
   12855                 :      347512 :   int i;
   12856                 :      347512 :   bb_vec_info bb_vinfo = dyn_cast <bb_vec_info> (vinfo);
   12857                 :      347512 :   vec<tree> vec_oprnds0 = vNULL;
   12858                 :      347512 :   vec<tree> vec_oprnds1 = vNULL;
   12859                 :      347512 :   tree mask_type;
   12860                 :      347512 :   tree mask = NULL_TREE;
   12861                 :             : 
   12862                 :      347512 :   if (!STMT_VINFO_RELEVANT_P (stmt_info) && !bb_vinfo)
   12863                 :             :     return false;
   12864                 :             : 
   12865                 :      347512 :   if (!vectype || !VECTOR_BOOLEAN_TYPE_P (vectype))
   12866                 :             :     return false;
   12867                 :             : 
   12868                 :      146348 :   mask_type = vectype;
   12869                 :      146348 :   nunits = TYPE_VECTOR_SUBPARTS (vectype);
   12870                 :             : 
   12871                 :      146348 :   if (slp_node)
   12872                 :             :     ncopies = 1;
   12873                 :             :   else
   12874                 :           0 :     ncopies = vect_get_num_copies (loop_vinfo, vectype);
   12875                 :             : 
   12876                 :           0 :   gcc_assert (ncopies >= 1);
   12877                 :             : 
   12878                 :      146348 :   if (TREE_CODE_CLASS (code) != tcc_comparison)
   12879                 :             :     return false;
   12880                 :             : 
   12881                 :      143349 :   slp_tree slp_rhs1, slp_rhs2;
   12882                 :      143349 :   if (!vect_is_simple_use (vinfo, stmt_info, slp_node,
   12883                 :             :                            0, &rhs1, &slp_rhs1, &dts[0], &vectype1))
   12884                 :             :     return false;
   12885                 :             : 
   12886                 :      143349 :   if (!vect_is_simple_use (vinfo, stmt_info, slp_node,
   12887                 :             :                            1, &rhs2, &slp_rhs2, &dts[1], &vectype2))
   12888                 :             :     return false;
   12889                 :             : 
   12890                 :       80182 :   if (vectype1 && vectype2
   12891                 :      206798 :       && maybe_ne (TYPE_VECTOR_SUBPARTS (vectype1),
   12892                 :       63449 :                    TYPE_VECTOR_SUBPARTS (vectype2)))
   12893                 :          16 :     return false;
   12894                 :             : 
   12895                 :      143333 :   vectype = vectype1 ? vectype1 : vectype2;
   12896                 :             : 
   12897                 :             :   /* Invariant comparison.  */
   12898                 :      143333 :   if (!vectype)
   12899                 :             :     {
   12900                 :       30901 :       vectype = get_vectype_for_scalar_type (vinfo, TREE_TYPE (rhs1), slp_node);
   12901                 :       30901 :       if (!vectype || maybe_ne (TYPE_VECTOR_SUBPARTS (vectype), nunits))
   12902                 :           7 :         return false;
   12903                 :             :     }
   12904                 :      112432 :   else if (maybe_ne (nunits, TYPE_VECTOR_SUBPARTS (vectype)))
   12905                 :             :     return false;
   12906                 :             : 
   12907                 :             :   /* Can't compare mask and non-mask types.  */
   12908                 :       80166 :   if (vectype1 && vectype2
   12909                 :      333099 :       && (VECTOR_BOOLEAN_TYPE_P (vectype1) ^ VECTOR_BOOLEAN_TYPE_P (vectype2)))
   12910                 :             :     return false;
   12911                 :             : 
   12912                 :             :   /* Boolean values may have another representation in vectors
   12913                 :             :      and therefore we prefer bit operations over comparison for
   12914                 :             :      them (which also works for scalar masks).  We store opcodes
   12915                 :             :      to use in bitop1 and bitop2.  Statement is vectorized as
   12916                 :             :        BITOP2 (rhs1 BITOP1 rhs2) or
   12917                 :             :        rhs1 BITOP2 (BITOP1 rhs2)
   12918                 :             :      depending on bitop1 and bitop2 arity.  */
   12919                 :      143318 :   bool swap_p = false;
   12920                 :      143318 :   if (VECTOR_BOOLEAN_TYPE_P (vectype))
   12921                 :             :     {
   12922                 :         702 :       if (code == GT_EXPR)
   12923                 :             :         {
   12924                 :             :           bitop1 = BIT_NOT_EXPR;
   12925                 :             :           bitop2 = BIT_AND_EXPR;
   12926                 :             :         }
   12927                 :             :       else if (code == GE_EXPR)
   12928                 :             :         {
   12929                 :             :           bitop1 = BIT_NOT_EXPR;
   12930                 :             :           bitop2 = BIT_IOR_EXPR;
   12931                 :             :         }
   12932                 :             :       else if (code == LT_EXPR)
   12933                 :             :         {
   12934                 :             :           bitop1 = BIT_NOT_EXPR;
   12935                 :             :           bitop2 = BIT_AND_EXPR;
   12936                 :             :           swap_p = true;
   12937                 :             :         }
   12938                 :             :       else if (code == LE_EXPR)
   12939                 :             :         {
   12940                 :             :           bitop1 = BIT_NOT_EXPR;
   12941                 :             :           bitop2 = BIT_IOR_EXPR;
   12942                 :             :           swap_p = true;
   12943                 :             :         }
   12944                 :             :       else
   12945                 :             :         {
   12946                 :             :           bitop1 = BIT_XOR_EXPR;
   12947                 :             :           if (code == EQ_EXPR)
   12948                 :             :             bitop2 = BIT_NOT_EXPR;
   12949                 :             :         }
   12950                 :             :     }
   12951                 :             : 
   12952                 :      143318 :   if (!vec_stmt)
   12953                 :             :     {
   12954                 :      133777 :       if (bitop1 == NOP_EXPR)
   12955                 :             :         {
   12956                 :      133193 :           if (!expand_vec_cmp_expr_p (vectype, mask_type, code))
   12957                 :             :             return false;
   12958                 :             :         }
   12959                 :             :       else
   12960                 :             :         {
   12961                 :         584 :           machine_mode mode = TYPE_MODE (vectype);
   12962                 :         584 :           optab optab;
   12963                 :             : 
   12964                 :         584 :           optab = optab_for_tree_code (bitop1, vectype, optab_default);
   12965                 :         584 :           if (!optab || !can_implement_p (optab, mode))
   12966                 :           0 :             return false;
   12967                 :             : 
   12968                 :         584 :           if (bitop2 != NOP_EXPR)
   12969                 :             :             {
   12970                 :          77 :               optab = optab_for_tree_code (bitop2, vectype, optab_default);
   12971                 :          77 :               if (!optab || !can_implement_p (optab, mode))
   12972                 :           0 :                 return false;
   12973                 :             :             }
   12974                 :             :         }
   12975                 :             : 
   12976                 :             :       /* Put types on constant and invariant SLP children.  */
   12977                 :      124640 :       if (slp_node
   12978                 :      124640 :           && (!vect_maybe_update_slp_op_vectype (slp_rhs1, vectype)
   12979                 :      124640 :               || !vect_maybe_update_slp_op_vectype (slp_rhs2, vectype)))
   12980                 :             :         {
   12981                 :           0 :           if (dump_enabled_p ())
   12982                 :           0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
   12983                 :             :                              "incompatible vector types for invariants\n");
   12984                 :           0 :           return false;
   12985                 :             :         }
   12986                 :             : 
   12987                 :      124640 :       vect_model_simple_cost (vinfo, ncopies * (1 + (bitop2 != NOP_EXPR)),
   12988                 :             :                               dts, ndts, slp_node, cost_vec);
   12989                 :      124640 :       return true;
   12990                 :             :     }
   12991                 :             : 
   12992                 :             :   /* Transform.  */
   12993                 :             : 
   12994                 :             :   /* Handle def.  */
   12995                 :        9541 :   lhs = gimple_get_lhs (STMT_VINFO_STMT (stmt_info));
   12996                 :        9541 :   if (lhs)
   12997                 :        9541 :     mask = vect_create_destination_var (lhs, mask_type);
   12998                 :             : 
   12999                 :        9541 :   vect_get_vec_defs (vinfo, stmt_info, slp_node, ncopies,
   13000                 :             :                      rhs1, vectype, &vec_oprnds0,
   13001                 :             :                      rhs2, vectype, &vec_oprnds1);
   13002                 :        9541 :   if (swap_p)
   13003                 :          26 :     std::swap (vec_oprnds0, vec_oprnds1);
   13004                 :             : 
   13005                 :             :   /* Arguments are ready.  Create the new vector stmt.  */
   13006                 :       22200 :   FOR_EACH_VEC_ELT (vec_oprnds0, i, vec_rhs1)
   13007                 :             :     {
   13008                 :       12659 :       gimple *new_stmt;
   13009                 :       12659 :       vec_rhs2 = vec_oprnds1[i];
   13010                 :             : 
   13011                 :       12659 :       if (lhs)
   13012                 :       12659 :         new_temp = make_ssa_name (mask);
   13013                 :             :       else
   13014                 :           0 :         new_temp = make_temp_ssa_name (mask_type, NULL, "cmp");
   13015                 :       12659 :       if (bitop1 == NOP_EXPR)
   13016                 :             :         {
   13017                 :       12536 :           new_stmt = gimple_build_assign (new_temp, code,
   13018                 :             :                                           vec_rhs1, vec_rhs2);
   13019                 :       12536 :           vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
   13020                 :             :         }
   13021                 :             :       else
   13022                 :             :         {
   13023                 :         123 :           if (bitop1 == BIT_NOT_EXPR)
   13024                 :          52 :             new_stmt = gimple_build_assign (new_temp, bitop1, vec_rhs2);
   13025                 :             :           else
   13026                 :          71 :             new_stmt = gimple_build_assign (new_temp, bitop1, vec_rhs1,
   13027                 :             :                                             vec_rhs2);
   13028                 :         123 :           vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
   13029                 :         123 :           if (bitop2 != NOP_EXPR)
   13030                 :             :             {
   13031                 :          52 :               tree res = make_ssa_name (mask);
   13032                 :          52 :               if (bitop2 == BIT_NOT_EXPR)
   13033                 :           0 :                 new_stmt = gimple_build_assign (res, bitop2, new_temp);
   13034                 :             :               else
   13035                 :          52 :                 new_stmt = gimple_build_assign (res, bitop2, vec_rhs1,
   13036                 :             :                                                 new_temp);
   13037                 :          52 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
   13038                 :             :             }
   13039                 :             :         }
   13040                 :       12659 :       if (slp_node)
   13041                 :       12659 :         slp_node->push_vec_def (new_stmt);
   13042                 :             :       else
   13043                 :           0 :         STMT_VINFO_VEC_STMTS (stmt_info).safe_push (new_stmt);
   13044                 :             :     }
   13045                 :             : 
   13046                 :        9541 :   if (!slp_node)
   13047                 :           0 :     *vec_stmt = STMT_VINFO_VEC_STMTS (stmt_info)[0];
   13048                 :             : 
   13049                 :        9541 :   vec_oprnds0.release ();
   13050                 :        9541 :   vec_oprnds1.release ();
   13051                 :             : 
   13052                 :        9541 :   return true;
   13053                 :             : }
   13054                 :             : 
   13055                 :             : /* vectorizable_comparison.
   13056                 :             : 
   13057                 :             :    Check if STMT_INFO is comparison expression that can be vectorized.
   13058                 :             :    If VEC_STMT is also passed, vectorize STMT_INFO: create a vectorized
   13059                 :             :    comparison, put it in VEC_STMT, and insert it at GSI.
   13060                 :             : 
   13061                 :             :    Return true if STMT_INFO is vectorizable in this way.  */
   13062                 :             : 
   13063                 :             : static bool
   13064                 :      454689 : vectorizable_comparison (vec_info *vinfo,
   13065                 :             :                          stmt_vec_info stmt_info, gimple_stmt_iterator *gsi,
   13066                 :             :                          gimple **vec_stmt,
   13067                 :             :                          slp_tree slp_node, stmt_vector_for_cost *cost_vec)
   13068                 :             : {
   13069                 :      454689 :   bb_vec_info bb_vinfo = dyn_cast <bb_vec_info> (vinfo);
   13070                 :             : 
   13071                 :      454689 :   if (!STMT_VINFO_RELEVANT_P (stmt_info) && !bb_vinfo)
   13072                 :             :     return false;
   13073                 :             : 
   13074                 :      454689 :   if (STMT_VINFO_DEF_TYPE (stmt_info) != vect_internal_def)
   13075                 :             :     return false;
   13076                 :             : 
   13077                 :      668020 :   gassign *stmt = dyn_cast <gassign *> (stmt_info->stmt);
   13078                 :      345390 :   if (!stmt)
   13079                 :             :     return false;
   13080                 :             : 
   13081                 :      345390 :   enum tree_code code = gimple_assign_rhs_code (stmt);
   13082                 :      345390 :   tree vectype = STMT_VINFO_VECTYPE (stmt_info);
   13083                 :      345390 :   if (!vectorizable_comparison_1 (vinfo, vectype, stmt_info, code, gsi,
   13084                 :             :                                   vec_stmt, slp_node, cost_vec))
   13085                 :             :     return false;
   13086                 :             : 
   13087                 :      132059 :   if (!vec_stmt)
   13088                 :      122518 :     STMT_VINFO_TYPE (stmt_info) = comparison_vec_info_type;
   13089                 :             : 
   13090                 :             :   return true;
   13091                 :             : }
   13092                 :             : 
   13093                 :             : /* Check to see if the current early break given in STMT_INFO is valid for
   13094                 :             :    vectorization.  */
   13095                 :             : 
   13096                 :             : bool
   13097                 :      311580 : vectorizable_early_exit (vec_info *vinfo, stmt_vec_info stmt_info,
   13098                 :             :                          gimple_stmt_iterator *gsi, gimple **vec_stmt,
   13099                 :             :                          slp_tree slp_node, stmt_vector_for_cost *cost_vec)
   13100                 :             : {
   13101                 :      311580 :   loop_vec_info loop_vinfo = dyn_cast <loop_vec_info> (vinfo);
   13102                 :      225807 :   if (!loop_vinfo
   13103                 :      225807 :       || !is_a <gcond *> (STMT_VINFO_STMT (stmt_info)))
   13104                 :             :     return false;
   13105                 :             : 
   13106                 :       57859 :   if (STMT_VINFO_DEF_TYPE (stmt_info) != vect_condition_def)
   13107                 :             :     return false;
   13108                 :             : 
   13109                 :       57859 :   if (!STMT_VINFO_RELEVANT_P (stmt_info))
   13110                 :             :     return false;
   13111                 :             : 
   13112                 :       57859 :   DUMP_VECT_SCOPE ("vectorizable_early_exit");
   13113                 :             : 
   13114                 :       57859 :   auto code = gimple_cond_code (STMT_VINFO_STMT (stmt_info));
   13115                 :             : 
   13116                 :       57859 :   tree vectype = NULL_TREE;
   13117                 :       57859 :   slp_tree slp_op0;
   13118                 :       57859 :   tree op0;
   13119                 :       57859 :   enum vect_def_type dt0;
   13120                 :             : 
   13121                 :             :   /* Early break gcond kind SLP trees can be root only and have no children,
   13122                 :             :      for instance in the case where the argument is an external.  If that's
   13123                 :             :      the case there is no operand to analyse use of.  */
   13124                 :       57859 :   if ((!slp_node || !SLP_TREE_CHILDREN (slp_node).is_empty ())
   13125                 :      115718 :       && !vect_is_simple_use (vinfo, stmt_info, slp_node, 0, &op0, &slp_op0, &dt0,
   13126                 :             :                               &vectype))
   13127                 :             :     {
   13128                 :           0 :       if (dump_enabled_p ())
   13129                 :           0 :           dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
   13130                 :             :                            "use not simple.\n");
   13131                 :           0 :         return false;
   13132                 :             :     }
   13133                 :             : 
   13134                 :             :   /* For SLP we don't want to use the type of the operands of the SLP node, when
   13135                 :             :      vectorizing using SLP slp_node will be the children of the gcond and we
   13136                 :             :      want to use the type of the direct children which since the gcond is root
   13137                 :             :      will be the current node, rather than a child node as vect_is_simple_use
   13138                 :             :      assumes.  */
   13139                 :       57859 :   if (slp_node)
   13140                 :       57859 :     vectype = SLP_TREE_VECTYPE (slp_node);
   13141                 :             : 
   13142                 :       57859 :   if (!vectype)
   13143                 :             :     return false;
   13144                 :             : 
   13145                 :       57859 :   machine_mode mode = TYPE_MODE (vectype);
   13146                 :       57859 :   int ncopies, vec_num;
   13147                 :             : 
   13148                 :       57859 :   if (slp_node)
   13149                 :             :     {
   13150                 :       57859 :       ncopies = 1;
   13151                 :       57859 :       vec_num = SLP_TREE_NUMBER_OF_VEC_STMTS (slp_node);
   13152                 :             :     }
   13153                 :             :   else
   13154                 :             :     {
   13155                 :           0 :       ncopies = vect_get_num_copies (loop_vinfo, vectype);
   13156                 :           0 :       vec_num = 1;
   13157                 :             :     }
   13158                 :             : 
   13159                 :       57859 :   vec_loop_masks *masks = &LOOP_VINFO_MASKS (loop_vinfo);
   13160                 :       57859 :   vec_loop_lens *lens = &LOOP_VINFO_LENS (loop_vinfo);
   13161                 :       57859 :   bool masked_loop_p = LOOP_VINFO_FULLY_MASKED_P (loop_vinfo);
   13162                 :       57859 :   bool len_loop_p = LOOP_VINFO_FULLY_WITH_LENGTH_P (loop_vinfo);
   13163                 :             : 
   13164                 :             :   /* Now build the new conditional.  Pattern gimple_conds get dropped during
   13165                 :             :      codegen so we must replace the original insn.  */
   13166                 :       57859 :   gimple *orig_stmt = STMT_VINFO_STMT (vect_orig_stmt (stmt_info));
   13167                 :       57859 :   gcond *cond_stmt = as_a <gcond *>(orig_stmt);
   13168                 :             : 
   13169                 :       57859 :   tree cst = build_zero_cst (vectype);
   13170                 :       57859 :   auto bb = gimple_bb (cond_stmt);
   13171                 :       57859 :   edge exit_true_edge = EDGE_SUCC (bb, 0);
   13172                 :       57859 :   if (exit_true_edge->flags & EDGE_FALSE_VALUE)
   13173                 :         708 :     exit_true_edge = EDGE_SUCC (bb, 1);
   13174                 :       57859 :   gcc_assert (exit_true_edge->flags & EDGE_TRUE_VALUE);
   13175                 :             : 
   13176                 :             :   /* When vectorizing we assume that if the branch edge is taken that we're
   13177                 :             :      exiting the loop.  This is not however always the case as the compiler will
   13178                 :             :      rewrite conditions to always be a comparison against 0.  To do this it
   13179                 :             :      sometimes flips the edges.  This is fine for scalar,  but for vector we
   13180                 :             :      then have to negate the result of the test, as we're still assuming that if
   13181                 :             :      you take the branch edge that we found the exit condition.  i.e. we need to
   13182                 :             :      know whether we are generating a `forall` or an `exist` condition.  */
   13183                 :      115718 :   bool flipped = flow_bb_inside_loop_p (LOOP_VINFO_LOOP (loop_vinfo),
   13184                 :       57859 :                                         exit_true_edge->dest);
   13185                 :             : 
   13186                 :             :   /* Analyze only.  */
   13187                 :       57859 :   if (!vec_stmt)
   13188                 :             :     {
   13189                 :       56290 :       if (direct_optab_handler (cbranch_optab, mode) == CODE_FOR_nothing)
   13190                 :             :         {
   13191                 :       54168 :           if (dump_enabled_p ())
   13192                 :         580 :               dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
   13193                 :             :                                "can't vectorize early exit because the "
   13194                 :             :                                "target doesn't support flag setting vector "
   13195                 :             :                                "comparisons.\n");
   13196                 :       54168 :           return false;
   13197                 :             :         }
   13198                 :             : 
   13199                 :        2122 :       if (ncopies > 1
   13200                 :        2122 :           && direct_optab_handler (ior_optab, mode) == CODE_FOR_nothing)
   13201                 :             :         {
   13202                 :           0 :           if (dump_enabled_p ())
   13203                 :           0 :               dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
   13204                 :             :                                "can't vectorize early exit because the "
   13205                 :             :                                "target does not support boolean vector IOR "
   13206                 :             :                                "for type %T.\n",
   13207                 :             :                                vectype);
   13208                 :           0 :           return false;
   13209                 :             :         }
   13210                 :             : 
   13211                 :        2122 :       if (!vectorizable_comparison_1 (vinfo, vectype, stmt_info, code, gsi,
   13212                 :             :                                       vec_stmt, slp_node, cost_vec))
   13213                 :             :         return false;
   13214                 :             : 
   13215                 :        2122 :       if (LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo))
   13216                 :             :         {
   13217                 :           1 :           if (direct_internal_fn_supported_p (IFN_VCOND_MASK_LEN, vectype,
   13218                 :             :                                               OPTIMIZE_FOR_SPEED))
   13219                 :           0 :             vect_record_loop_len (loop_vinfo, lens, ncopies * vec_num,
   13220                 :             :                                   vectype, 1);
   13221                 :             :           else
   13222                 :           1 :             vect_record_loop_mask (loop_vinfo, masks, ncopies * vec_num,
   13223                 :             :                                    vectype, NULL);
   13224                 :             :         }
   13225                 :             : 
   13226                 :        2122 :       return true;
   13227                 :             :     }
   13228                 :             : 
   13229                 :             :   /* Tranform.  */
   13230                 :             : 
   13231                 :        1569 :   tree new_temp = NULL_TREE;
   13232                 :        1569 :   gimple *new_stmt = NULL;
   13233                 :             : 
   13234                 :        1569 :   if (dump_enabled_p ())
   13235                 :         345 :     dump_printf_loc (MSG_NOTE, vect_location, "transform early-exit.\n");
   13236                 :             : 
   13237                 :             :   /* For SLP we don't do codegen of the body starting from the gcond, the gconds are
   13238                 :             :      roots and so by the time we get to them we have already codegened the SLP tree
   13239                 :             :      and so we shouldn't try to do so again.  The arguments have already been
   13240                 :             :      vectorized.  It's not very clean to do this here, But the masking code below is
   13241                 :             :      complex and this keeps it all in one place to ease fixes and backports.  Once we
   13242                 :             :      drop the non-SLP loop vect or split vectorizable_* this can be simplified.  */
   13243                 :        1569 :   if (!slp_node)
   13244                 :             :     {
   13245                 :           0 :       if (!vectorizable_comparison_1 (vinfo, vectype, stmt_info, code, gsi,
   13246                 :             :                                       vec_stmt, slp_node, cost_vec))
   13247                 :           0 :         gcc_unreachable ();
   13248                 :             :     }
   13249                 :             : 
   13250                 :        1569 :   gimple *stmt = STMT_VINFO_STMT (stmt_info);
   13251                 :        1569 :   basic_block cond_bb = gimple_bb (stmt);
   13252                 :        1569 :   gimple_stmt_iterator  cond_gsi = gsi_last_bb (cond_bb);
   13253                 :             : 
   13254                 :        1569 :   auto_vec<tree> stmts;
   13255                 :             : 
   13256                 :        1569 :   if (slp_node)
   13257                 :        1569 :     stmts.safe_splice (SLP_TREE_VEC_DEFS (slp_node));
   13258                 :             :   else
   13259                 :             :     {
   13260                 :           0 :       auto vec_stmts = STMT_VINFO_VEC_STMTS (stmt_info);
   13261                 :           0 :       stmts.reserve_exact (vec_stmts.length ());
   13262                 :           0 :       for (auto stmt : vec_stmts)
   13263                 :           0 :         stmts.quick_push (gimple_assign_lhs (stmt));
   13264                 :             :     }
   13265                 :             : 
   13266                 :             :   /* If we're comparing against a previous forall we need to negate the resullts
   13267                 :             :      before we do the final comparison or reduction.  */
   13268                 :        1569 :   if (flipped)
   13269                 :             :     {
   13270                 :             :       /* Rewrite the if(all(mask)) into if (!all(mask)) which is the same as
   13271                 :             :          if (any(~mask)) by negating the masks and flipping the branches.
   13272                 :             : 
   13273                 :             :         1. For unmasked loops we simply reduce the ~mask.
   13274                 :             :         2. For masked loops we reduce (~mask & loop_mask) which is the same as
   13275                 :             :            doing (mask & loop_mask) ^ loop_mask.  */
   13276                 :         222 :       for (unsigned i = 0; i < stmts.length (); i++)
   13277                 :             :         {
   13278                 :         133 :           tree inv_lhs = make_temp_ssa_name (vectype, NULL, "vexit_inv");
   13279                 :         133 :           auto inv_stmt = gimple_build_assign (inv_lhs, BIT_NOT_EXPR, stmts[i]);
   13280                 :         133 :           vect_finish_stmt_generation (loop_vinfo, stmt_info, inv_stmt,
   13281                 :             :                                        &cond_gsi);
   13282                 :         133 :           stmts[i] = inv_lhs;
   13283                 :             :         }
   13284                 :             : 
   13285                 :          89 :       EDGE_SUCC (bb, 0)->flags ^= (EDGE_TRUE_VALUE|EDGE_FALSE_VALUE);
   13286                 :          89 :       EDGE_SUCC (bb, 1)->flags ^= (EDGE_TRUE_VALUE|EDGE_FALSE_VALUE);
   13287                 :             :     }
   13288                 :             : 
   13289                 :             :   /* Determine if we need to reduce the final value.  */
   13290                 :        1569 :   if (stmts.length () > 1)
   13291                 :             :     {
   13292                 :             :       /* We build the reductions in a way to maintain as much parallelism as
   13293                 :             :          possible.  */
   13294                 :         393 :       auto_vec<tree> workset (stmts.length ());
   13295                 :             : 
   13296                 :             :       /* Mask the statements as we queue them up.  Normally we loop over
   13297                 :             :          vec_num,  but since we inspect the exact results of vectorization
   13298                 :             :          we don't need to and instead can just use the stmts themselves.  */
   13299                 :         393 :       if (masked_loop_p)
   13300                 :           0 :         for (unsigned i = 0; i < stmts.length (); i++)
   13301                 :             :           {
   13302                 :           0 :             tree stmt_mask
   13303                 :           0 :               = vect_get_loop_mask (loop_vinfo, gsi, masks, ncopies * vec_num,
   13304                 :             :                                     vectype, i);
   13305                 :           0 :             stmt_mask
   13306                 :           0 :               = prepare_vec_mask (loop_vinfo, TREE_TYPE (stmt_mask), stmt_mask,
   13307                 :           0 :                                   stmts[i], &cond_gsi);
   13308                 :           0 :             workset.quick_push (stmt_mask);
   13309                 :             :           }
   13310                 :         393 :       else if (len_loop_p)
   13311                 :           0 :         for (unsigned i = 0; i < stmts.length (); i++)
   13312                 :             :           {
   13313                 :           0 :             tree len_mask = vect_gen_loop_len_mask (loop_vinfo, gsi, &cond_gsi,
   13314                 :           0 :                                                     lens, ncopies * vec_num,
   13315                 :           0 :                                                     vectype, stmts[i], i, 1);
   13316                 :             : 
   13317                 :           0 :             workset.quick_push (len_mask);
   13318                 :             :           }
   13319                 :             :       else
   13320                 :         393 :         workset.splice (stmts);
   13321                 :             : 
   13322                 :         926 :       while (workset.length () > 1)
   13323                 :             :         {
   13324                 :         533 :           new_temp = make_temp_ssa_name (vectype, NULL, "vexit_reduc");
   13325                 :         533 :           tree arg0 = workset.pop ();
   13326                 :         533 :           tree arg1 = workset.pop ();
   13327                 :         533 :           new_stmt = gimple_build_assign (new_temp, BIT_IOR_EXPR, arg0, arg1);
   13328                 :         533 :           vect_finish_stmt_generation (loop_vinfo, stmt_info, new_stmt,
   13329                 :             :                                        &cond_gsi);
   13330                 :         533 :           workset.quick_insert (0, new_temp);
   13331                 :             :         }
   13332                 :         393 :     }
   13333                 :             :   else
   13334                 :             :     {
   13335                 :        1176 :       new_temp = stmts[0];
   13336                 :        1176 :       if (masked_loop_p)
   13337                 :             :         {
   13338                 :           0 :           tree mask
   13339                 :           0 :             = vect_get_loop_mask (loop_vinfo, gsi, masks, ncopies, vectype, 0);
   13340                 :           0 :           new_temp = prepare_vec_mask (loop_vinfo, TREE_TYPE (mask), mask,
   13341                 :             :                                        new_temp, &cond_gsi);
   13342                 :             :         }
   13343                 :        1176 :       else if (len_loop_p)
   13344                 :           0 :         new_temp = vect_gen_loop_len_mask (loop_vinfo, gsi, &cond_gsi, lens,
   13345                 :             :                                            ncopies, vectype, new_temp, 0, 1);
   13346                 :             :     }
   13347                 :             : 
   13348                 :        1569 :   gcc_assert (new_temp);
   13349                 :             : 
   13350                 :        1569 :   gimple_cond_set_condition (cond_stmt, NE_EXPR, new_temp, cst);
   13351                 :        1569 :   update_stmt (orig_stmt);
   13352                 :             : 
   13353                 :        1569 :   if (slp_node)
   13354                 :        1569 :     SLP_TREE_VEC_DEFS (slp_node).truncate (0);
   13355                 :             :    else
   13356                 :           0 :     STMT_VINFO_VEC_STMTS (stmt_info).truncate (0);
   13357                 :             : 
   13358                 :        1569 :   if (!slp_node)
   13359                 :           0 :     *vec_stmt = orig_stmt;
   13360                 :             : 
   13361                 :        1569 :   return true;
   13362                 :        1569 : }
   13363                 :             : 
   13364                 :             : /* If SLP_NODE is nonnull, return true if vectorizable_live_operation
   13365                 :             :    can handle all live statements in the node.  Otherwise return true
   13366                 :             :    if STMT_INFO is not live or if vectorizable_live_operation can handle it.
   13367                 :             :    VEC_STMT_P is as for vectorizable_live_operation.  */
   13368                 :             : 
   13369                 :             : static bool
   13370                 :     1441454 : can_vectorize_live_stmts (vec_info *vinfo, stmt_vec_info stmt_info,
   13371                 :             :                           slp_tree slp_node, slp_instance slp_node_instance,
   13372                 :             :                           bool vec_stmt_p,
   13373                 :             :                           stmt_vector_for_cost *cost_vec)
   13374                 :             : {
   13375                 :     1441454 :   loop_vec_info loop_vinfo = dyn_cast <loop_vec_info> (vinfo);
   13376                 :     1441454 :   if (slp_node)
   13377                 :             :     {
   13378                 :             :       stmt_vec_info slp_stmt_info;
   13379                 :             :       unsigned int i;
   13380                 :     3231662 :       FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_STMTS (slp_node), i, slp_stmt_info)
   13381                 :             :         {
   13382                 :     1790208 :           if (slp_stmt_info
   13383                 :     1769429 :               && (STMT_VINFO_LIVE_P (slp_stmt_info)
   13384                 :     1571711 :                   || (loop_vinfo
   13385                 :     1313569 :                       && LOOP_VINFO_EARLY_BREAKS (loop_vinfo)
   13386                 :      251723 :                       && STMT_VINFO_DEF_TYPE (slp_stmt_info)
   13387                 :             :                       == vect_induction_def))
   13388                 :     1987926 :               && !vectorizable_live_operation (vinfo, slp_stmt_info, slp_node,
   13389                 :             :                                                slp_node_instance, i,
   13390                 :             :                                                vec_stmt_p, cost_vec))
   13391                 :           0 :             return false;
   13392                 :             :         }
   13393                 :             :     }
   13394                 :           0 :   else if ((STMT_VINFO_LIVE_P (stmt_info)
   13395                 :           0 :             || (LOOP_VINFO_EARLY_BREAKS (loop_vinfo)
   13396                 :           0 :                 && STMT_VINFO_DEF_TYPE (stmt_info) == vect_induction_def))
   13397                 :           0 :            && !vectorizable_live_operation (vinfo, stmt_info,
   13398                 :             :                                             slp_node, slp_node_instance, -1,
   13399                 :             :                                             vec_stmt_p, cost_vec))
   13400                 :             :     return false;
   13401                 :             : 
   13402                 :             :   return true;
   13403                 :             : }
   13404                 :             : 
   13405                 :             : /* Make sure the statement is vectorizable.  */
   13406                 :             : 
   13407                 :             : opt_result
   13408                 :     3813734 : vect_analyze_stmt (vec_info *vinfo,
   13409                 :             :                    stmt_vec_info stmt_info, bool *need_to_vectorize,
   13410                 :             :                    slp_tree node, slp_instance node_instance,
   13411                 :             :                    stmt_vector_for_cost *cost_vec)
   13412                 :             : {
   13413                 :     3813734 :   bb_vec_info bb_vinfo = dyn_cast <bb_vec_info> (vinfo);
   13414                 :     3813734 :   enum vect_relevant relevance = STMT_VINFO_RELEVANT (stmt_info);
   13415                 :     3813734 :   bool ok;
   13416                 :     3813734 :   gimple_seq pattern_def_seq;
   13417                 :             : 
   13418                 :     3813734 :   if (dump_enabled_p ())
   13419                 :      286744 :     dump_printf_loc (MSG_NOTE, vect_location, "==> examining statement: %G",
   13420                 :             :                      stmt_info->stmt);
   13421                 :             : 
   13422                 :     7245950 :   if (gimple_has_volatile_ops (stmt_info->stmt))
   13423                 :           0 :     return opt_result::failure_at (stmt_info->stmt,
   13424                 :             :                                    "not vectorized:"
   13425                 :             :                                    " stmt has volatile operands: %G\n",
   13426                 :             :                                    stmt_info->stmt);
   13427                 :             : 
   13428                 :     3813734 :   if (STMT_VINFO_IN_PATTERN_P (stmt_info)
   13429                 :       43842 :       && node == NULL
   13430                 :     3857576 :       && (pattern_def_seq = STMT_VINFO_PATTERN_DEF_SEQ (stmt_info)))
   13431                 :             :     {
   13432                 :             :       gimple_stmt_iterator si;
   13433                 :             : 
   13434                 :       88552 :       for (si = gsi_start (pattern_def_seq); !gsi_end_p (si); gsi_next (&si))
   13435                 :             :         {
   13436                 :       51772 :           stmt_vec_info pattern_def_stmt_info
   13437                 :       51772 :             = vinfo->lookup_stmt (gsi_stmt (si));
   13438                 :       51772 :           if (STMT_VINFO_RELEVANT_P (pattern_def_stmt_info)
   13439                 :       22211 :               || STMT_VINFO_LIVE_P (pattern_def_stmt_info))
   13440                 :             :             {
   13441                 :             :               /* Analyze def stmt of STMT if it's a pattern stmt.  */
   13442                 :       29561 :               if (dump_enabled_p ())
   13443                 :       10344 :                 dump_printf_loc (MSG_NOTE, vect_location,
   13444                 :             :                                  "==> examining pattern def statement: %G",
   13445                 :             :                                  pattern_def_stmt_info->stmt);
   13446                 :             : 
   13447                 :       29561 :               opt_result res
   13448                 :       29561 :                 = vect_analyze_stmt (vinfo, pattern_def_stmt_info,
   13449                 :             :                                      need_to_vectorize, node, node_instance,
   13450                 :             :                                      cost_vec);
   13451                 :       29561 :               if (!res)
   13452                 :           4 :                 return res;
   13453                 :             :             }
   13454                 :             :         }
   13455                 :             :     }
   13456                 :             : 
   13457                 :             :   /* Skip stmts that do not need to be vectorized. In loops this is expected
   13458                 :             :      to include:
   13459                 :             :      - the COND_EXPR which is the loop exit condition
   13460                 :             :      - any LABEL_EXPRs in the loop
   13461                 :             :      - computations that are used only for array indexing or loop control.
   13462                 :             :      In basic blocks we only analyze statements that are a part of some SLP
   13463                 :             :      instance, therefore, all the statements are relevant.
   13464                 :             : 
   13465                 :             :      Pattern statement needs to be analyzed instead of the original statement
   13466                 :             :      if the original statement is not relevant.  Otherwise, we analyze both
   13467                 :             :      statements.  In basic blocks we are called from some SLP instance
   13468                 :             :      traversal, don't analyze pattern stmts instead, the pattern stmts
   13469                 :             :      already will be part of SLP instance.  */
   13470                 :             : 
   13471                 :     3813730 :   stmt_vec_info pattern_stmt_info = STMT_VINFO_RELATED_STMT (stmt_info);
   13472                 :     3813730 :   if (!STMT_VINFO_RELEVANT_P (stmt_info)
   13473                 :      711306 :       && !STMT_VINFO_LIVE_P (stmt_info))
   13474                 :             :     {
   13475                 :      711282 :       if (STMT_VINFO_IN_PATTERN_P (stmt_info)
   13476                 :       43838 :           && pattern_stmt_info
   13477                 :       43838 :           && (STMT_VINFO_RELEVANT_P (pattern_stmt_info)
   13478                 :       26861 :               || STMT_VINFO_LIVE_P (pattern_stmt_info)))
   13479                 :             :         {
   13480                 :             :           /* Analyze PATTERN_STMT instead of the original stmt.  */
   13481                 :       16977 :           stmt_info = pattern_stmt_info;
   13482                 :       16977 :           if (dump_enabled_p ())
   13483                 :        4428 :             dump_printf_loc (MSG_NOTE, vect_location,
   13484                 :             :                              "==> examining pattern statement: %G",
   13485                 :             :                              stmt_info->stmt);
   13486                 :             :         }
   13487                 :             :       else
   13488                 :             :         {
   13489                 :      694305 :           if (dump_enabled_p ())
   13490                 :       79679 :             dump_printf_loc (MSG_NOTE, vect_location, "irrelevant.\n");
   13491                 :             : 
   13492                 :      694305 :           if (node)
   13493                 :           0 :             return opt_result::failure_at (stmt_info->stmt,
   13494                 :             :                                            "not vectorized:"
   13495                 :             :                                            " irrelevant stmt as SLP node %p "
   13496                 :             :                                            "representative.\n",
   13497                 :             :                                            (void *)node);
   13498                 :      694305 :           return opt_result::success ();
   13499                 :             :         }
   13500                 :             :     }
   13501                 :     3102448 :   else if (STMT_VINFO_IN_PATTERN_P (stmt_info)
   13502                 :           0 :            && node == NULL
   13503                 :           0 :            && pattern_stmt_info
   13504                 :           0 :            && (STMT_VINFO_RELEVANT_P (pattern_stmt_info)
   13505                 :           0 :                || STMT_VINFO_LIVE_P (pattern_stmt_info)))
   13506                 :             :     {
   13507                 :             :       /* Analyze PATTERN_STMT too.  */
   13508                 :           0 :       if (dump_enabled_p ())
   13509                 :           0 :         dump_printf_loc (MSG_NOTE, vect_location,
   13510                 :             :                          "==> examining pattern statement: %G",
   13511                 :             :                          pattern_stmt_info->stmt);
   13512                 :             : 
   13513                 :           0 :       opt_result res
   13514                 :           0 :         = vect_analyze_stmt (vinfo, pattern_stmt_info, need_to_vectorize, node,
   13515                 :             :                              node_instance, cost_vec);
   13516                 :           0 :       if (!res)
   13517                 :           0 :         return res;
   13518                 :             :     }
   13519                 :             : 
   13520                 :     3119425 :   switch (STMT_VINFO_DEF_TYPE (stmt_info))
   13521                 :             :     {
   13522                 :             :       case vect_internal_def:
   13523                 :             :       case vect_condition_def:
   13524                 :             :         break;
   13525                 :             : 
   13526                 :       70636 :       case vect_reduction_def:
   13527                 :       70636 :       case vect_nested_cycle:
   13528                 :       70636 :          gcc_assert (!bb_vinfo
   13529                 :             :                      && (relevance == vect_used_in_outer
   13530                 :             :                          || relevance == vect_used_in_outer_by_reduction
   13531                 :             :                          || relevance == vect_used_by_reduction
   13532                 :             :                          || relevance == vect_unused_in_scope
   13533                 :             :                          || relevance == vect_used_only_live));
   13534                 :             :          break;
   13535                 :             : 
   13536                 :         382 :       case vect_double_reduction_def:
   13537                 :         382 :         gcc_assert (!bb_vinfo && node);
   13538                 :             :         break;
   13539                 :             : 
   13540                 :      137163 :       case vect_induction_def:
   13541                 :      137163 :       case vect_first_order_recurrence:
   13542                 :      137163 :         gcc_assert (!bb_vinfo);
   13543                 :             :         break;
   13544                 :             : 
   13545                 :           0 :       case vect_constant_def:
   13546                 :           0 :       case vect_external_def:
   13547                 :           0 :       case vect_unknown_def_type:
   13548                 :           0 :       default:
   13549                 :           0 :         gcc_unreachable ();
   13550                 :             :     }
   13551                 :             : 
   13552                 :     3119425 :   tree saved_vectype = STMT_VINFO_VECTYPE (stmt_info);
   13553                 :     3119425 :   if (node)
   13554                 :     2514923 :     STMT_VINFO_VECTYPE (stmt_info) = SLP_TREE_VECTYPE (node);
   13555                 :             : 
   13556                 :     3119425 :   if (STMT_VINFO_RELEVANT_P (stmt_info))
   13557                 :             :     {
   13558                 :     3119401 :       gcall *call = dyn_cast <gcall *> (stmt_info->stmt);
   13559                 :     3119401 :       gcc_assert (STMT_VINFO_VECTYPE (stmt_info)
   13560                 :             :                   || gimple_code (stmt_info->stmt) == GIMPLE_COND
   13561                 :             :                   || (call && gimple_call_lhs (call) == NULL_TREE));
   13562                 :     3119401 :       *need_to_vectorize = true;
   13563                 :             :     }
   13564                 :             : 
   13565                 :     3119425 :   if (PURE_SLP_STMT (stmt_info) && !node)
   13566                 :             :     {
   13567                 :      604416 :       if (dump_enabled_p ())
   13568                 :       97596 :         dump_printf_loc (MSG_NOTE, vect_location,
   13569                 :             :                          "handled only by SLP analysis\n");
   13570                 :      604416 :       return opt_result::success ();
   13571                 :             :     }
   13572                 :             : 
   13573                 :             :   /* When we arrive here with a non-SLP statement and we are supposed
   13574                 :             :      to use SLP for everything fail vectorization.  */
   13575                 :        6896 :   if (!node)
   13576                 :          86 :     return opt_result::failure_at (stmt_info->stmt,
   13577                 :             :                                    "needs non-SLP handling\n");
   13578                 :             : 
   13579                 :     2514923 :   ok = true;
   13580                 :     2514923 :   if (!bb_vinfo
   13581                 :     1239449 :       && (STMT_VINFO_RELEVANT_P (stmt_info)
   13582                 :           0 :           || STMT_VINFO_DEF_TYPE (stmt_info) == vect_reduction_def))
   13583                 :             :     /* Prefer vectorizable_call over vectorizable_simd_clone_call so
   13584                 :             :        -mveclibabi= takes preference over library functions with
   13585                 :             :        the simd attribute.  */
   13586                 :     1239449 :     ok = (vectorizable_call (vinfo, stmt_info, NULL, NULL, node, cost_vec)
   13587                 :     1234601 :           || vectorizable_simd_clone_call (vinfo, stmt_info, NULL, NULL, node,
   13588                 :             :                                            cost_vec)
   13589                 :     1234117 :           || vectorizable_conversion (vinfo, stmt_info,
   13590                 :             :                                       NULL, NULL, node, cost_vec)
   13591                 :     1178426 :           || vectorizable_operation (vinfo, stmt_info,
   13592                 :             :                                      NULL, NULL, node, cost_vec)
   13593                 :      909377 :           || vectorizable_assignment (vinfo, stmt_info,
   13594                 :             :                                       NULL, NULL, node, cost_vec)
   13595                 :      870180 :           || vectorizable_load (vinfo, stmt_info, NULL, NULL, node, cost_vec)
   13596                 :      587846 :           || vectorizable_store (vinfo, stmt_info, NULL, NULL, node, cost_vec)
   13597                 :      456329 :           || vectorizable_lane_reducing (as_a <loop_vec_info> (vinfo),
   13598                 :             :                                          stmt_info, node, cost_vec)
   13599                 :      455917 :           || vectorizable_reduction (as_a <loop_vec_info> (vinfo), stmt_info,
   13600                 :             :                                      node, node_instance, cost_vec)
   13601                 :      395824 :           || vectorizable_induction (as_a <loop_vec_info> (vinfo), stmt_info,
   13602                 :             :                                      NULL, node, cost_vec)
   13603                 :      288861 :           || vectorizable_shift (vinfo, stmt_info, NULL, NULL, node, cost_vec)
   13604                 :      273890 :           || vectorizable_condition (vinfo, stmt_info,
   13605                 :             :                                      NULL, NULL, node, cost_vec)
   13606                 :      256397 :           || vectorizable_comparison (vinfo, stmt_info, NULL, NULL, node,
   13607                 :             :                                       cost_vec)
   13608                 :      168983 :           || vectorizable_lc_phi (as_a <loop_vec_info> (vinfo),
   13609                 :             :                                   stmt_info, node)
   13610                 :      168146 :           || vectorizable_recurr (as_a <loop_vec_info> (vinfo),
   13611                 :             :                                    stmt_info, NULL, node, cost_vec)
   13612                 :     1407397 :           || vectorizable_early_exit (vinfo, stmt_info, NULL, NULL, node,
   13613                 :             :                                       cost_vec));
   13614                 :             :   else
   13615                 :             :     {
   13616                 :             :       if (bb_vinfo)
   13617                 :     1275474 :         ok = (vectorizable_call (vinfo, stmt_info, NULL, NULL, node, cost_vec)
   13618                 :     1274570 :               || vectorizable_simd_clone_call (vinfo, stmt_info,
   13619                 :             :                                                NULL, NULL, node, cost_vec)
   13620                 :     1274569 :               || vectorizable_conversion (vinfo, stmt_info, NULL, NULL, node,
   13621                 :             :                                           cost_vec)
   13622                 :     1264064 :               || vectorizable_shift (vinfo, stmt_info,
   13623                 :             :                                      NULL, NULL, node, cost_vec)
   13624                 :     1240057 :               || vectorizable_operation (vinfo, stmt_info,
   13625                 :             :                                          NULL, NULL, node, cost_vec)
   13626                 :     1070189 :               || vectorizable_assignment (vinfo, stmt_info, NULL, NULL, node,
   13627                 :             :                                           cost_vec)
   13628                 :     1048091 :               || vectorizable_load (vinfo, stmt_info,
   13629                 :             :                                     NULL, NULL, node, cost_vec)
   13630                 :      912779 :               || vectorizable_store (vinfo, stmt_info,
   13631                 :             :                                      NULL, NULL, node, cost_vec)
   13632                 :      189449 :               || vectorizable_condition (vinfo, stmt_info,
   13633                 :             :                                          NULL, NULL, node, cost_vec)
   13634                 :      188751 :               || vectorizable_comparison (vinfo, stmt_info, NULL, NULL, node,
   13635                 :             :                                           cost_vec)
   13636                 :      153647 :               || vectorizable_phi (vinfo, stmt_info, NULL, node, cost_vec)
   13637                 :     1361247 :               || vectorizable_early_exit (vinfo, stmt_info, NULL, NULL, node,
   13638                 :             :                                           cost_vec));
   13639                 :             : 
   13640                 :             :     }
   13641                 :             : 
   13642                 :     2514923 :   if (node)
   13643                 :     2514923 :     STMT_VINFO_VECTYPE (stmt_info) = saved_vectype;
   13644                 :             : 
   13645                 :     2514923 :   if (!ok)
   13646                 :      253721 :     return opt_result::failure_at (stmt_info->stmt,
   13647                 :             :                                    "not vectorized:"
   13648                 :             :                                    " relevant stmt not supported: %G",
   13649                 :             :                                    stmt_info->stmt);
   13650                 :             : 
   13651                 :             :   /* Stmts that are (also) "live" (i.e. - that are used out of the loop)
   13652                 :             :       need extra handling, except for vectorizable reductions.  */
   13653                 :     2261202 :   if (!bb_vinfo
   13654                 :     1071501 :       && STMT_VINFO_TYPE (stmt_info) != reduc_vec_info_type
   13655                 :     1063795 :       && STMT_VINFO_TYPE (stmt_info) != lc_phi_info_type
   13656                 :     1062958 :       && (!node || !node->ldst_lanes || SLP_TREE_CODE (node) == VEC_PERM_EXPR)
   13657                 :     3324160 :       && !can_vectorize_live_stmts (as_a <loop_vec_info> (vinfo),
   13658                 :             :                                     stmt_info, node, node_instance,
   13659                 :             :                                     false, cost_vec))
   13660                 :           0 :     return opt_result::failure_at (stmt_info->stmt,
   13661                 :             :                                    "not vectorized:"
   13662                 :             :                                    " live stmt not supported: %G",
   13663                 :             :                                    stmt_info->stmt);
   13664                 :             : 
   13665                 :     2261202 :   return opt_result::success ();
   13666                 :             : }
   13667                 :             : 
   13668                 :             : 
   13669                 :             : /* Function vect_transform_stmt.
   13670                 :             : 
   13671                 :             :    Create a vectorized stmt to replace STMT_INFO, and insert it at GSI.  */
   13672                 :             : 
   13673                 :             : bool
   13674                 :      916885 : vect_transform_stmt (vec_info *vinfo,
   13675                 :             :                      stmt_vec_info stmt_info, gimple_stmt_iterator *gsi,
   13676                 :             :                      slp_tree slp_node, slp_instance slp_node_instance)
   13677                 :             : {
   13678                 :      916885 :   bool is_store = false;
   13679                 :      916885 :   gimple *vec_stmt = NULL;
   13680                 :      916885 :   bool done;
   13681                 :             : 
   13682                 :      916885 :   gcc_assert (slp_node || !PURE_SLP_STMT (stmt_info));
   13683                 :             : 
   13684                 :      916885 :   if (dump_enabled_p ())
   13685                 :       63489 :     dump_printf_loc (MSG_NOTE, vect_location,
   13686                 :             :                      "------>vectorizing statement: %G", stmt_info->stmt);
   13687                 :             : 
   13688                 :      916885 :   tree saved_vectype = STMT_VINFO_VECTYPE (stmt_info);
   13689                 :      916885 :   if (slp_node)
   13690                 :      916885 :     STMT_VINFO_VECTYPE (stmt_info) = SLP_TREE_VECTYPE (slp_node);
   13691                 :             : 
   13692                 :      916885 :   switch (STMT_VINFO_TYPE (stmt_info))
   13693                 :             :     {
   13694                 :       19310 :     case type_demotion_vec_info_type:
   13695                 :       19310 :     case type_promotion_vec_info_type:
   13696                 :       19310 :     case type_conversion_vec_info_type:
   13697                 :       19310 :       done = vectorizable_conversion (vinfo, stmt_info,
   13698                 :             :                                       gsi, &vec_stmt, slp_node, NULL);
   13699                 :       19310 :       gcc_assert (done);
   13700                 :             :       break;
   13701                 :             : 
   13702                 :       15917 :     case induc_vec_info_type:
   13703                 :       15917 :       done = vectorizable_induction (as_a <loop_vec_info> (vinfo),
   13704                 :             :                                      stmt_info, &vec_stmt, slp_node,
   13705                 :             :                                      NULL);
   13706                 :       15917 :       gcc_assert (done);
   13707                 :             :       break;
   13708                 :             : 
   13709                 :        5761 :     case shift_vec_info_type:
   13710                 :        5761 :       done = vectorizable_shift (vinfo, stmt_info,
   13711                 :             :                                  gsi, &vec_stmt, slp_node, NULL);
   13712                 :        5761 :       gcc_assert (done);
   13713                 :             :       break;
   13714                 :             : 
   13715                 :      108375 :     case op_vec_info_type:
   13716                 :      108375 :       done = vectorizable_operation (vinfo, stmt_info, gsi, &vec_stmt, slp_node,
   13717                 :             :                                      NULL);
   13718                 :      108375 :       gcc_assert (done);
   13719                 :             :       break;
   13720                 :             : 
   13721                 :       13795 :     case assignment_vec_info_type:
   13722                 :       13795 :       done = vectorizable_assignment (vinfo, stmt_info,
   13723                 :             :                                       gsi, &vec_stmt, slp_node, NULL);
   13724                 :       13795 :       gcc_assert (done);
   13725                 :             :       break;
   13726                 :             : 
   13727                 :      157344 :     case load_vec_info_type:
   13728                 :      157344 :       done = vectorizable_load (vinfo, stmt_info, gsi, &vec_stmt, slp_node,
   13729                 :             :                                 NULL);
   13730                 :      157344 :       gcc_assert (done);
   13731                 :             :       break;
   13732                 :             : 
   13733                 :      538389 :     case store_vec_info_type:
   13734                 :      538389 :       if (STMT_VINFO_GROUPED_ACCESS (stmt_info)
   13735                 :      486686 :           && !slp_node
   13736                 :      538389 :           && (++DR_GROUP_STORE_COUNT (DR_GROUP_FIRST_ELEMENT (stmt_info))
   13737                 :           0 :               < DR_GROUP_SIZE (DR_GROUP_FIRST_ELEMENT (stmt_info))))
   13738                 :             :         /* In case of interleaving, the whole chain is vectorized when the
   13739                 :             :            last store in the chain is reached.  Store stmts before the last
   13740                 :             :            one are skipped, and there vec_stmt_info shouldn't be freed
   13741                 :             :            meanwhile.  */
   13742                 :             :         ;
   13743                 :             :       else
   13744                 :             :         {
   13745                 :      538389 :           done = vectorizable_store (vinfo, stmt_info,
   13746                 :             :                                      gsi, &vec_stmt, slp_node, NULL);
   13747                 :      538389 :           gcc_assert (done);
   13748                 :             :           is_store = true;
   13749                 :             :         }
   13750                 :             :       break;
   13751                 :             : 
   13752                 :        6385 :     case condition_vec_info_type:
   13753                 :        6385 :       done = vectorizable_condition (vinfo, stmt_info,
   13754                 :             :                                      gsi, &vec_stmt, slp_node, NULL);
   13755                 :        6385 :       gcc_assert (done);
   13756                 :             :       break;
   13757                 :             : 
   13758                 :        9541 :     case comparison_vec_info_type:
   13759                 :        9541 :       done = vectorizable_comparison (vinfo, stmt_info, gsi, &vec_stmt,
   13760                 :             :                                       slp_node, NULL);
   13761                 :        9541 :       gcc_assert (done);
   13762                 :             :       break;
   13763                 :             : 
   13764                 :        3472 :     case call_vec_info_type:
   13765                 :        3472 :       done = vectorizable_call (vinfo, stmt_info,
   13766                 :             :                                 gsi, &vec_stmt, slp_node, NULL);
   13767                 :        3472 :       break;
   13768                 :             : 
   13769                 :         332 :     case call_simd_clone_vec_info_type:
   13770                 :         332 :       done = vectorizable_simd_clone_call (vinfo, stmt_info, gsi, &vec_stmt,
   13771                 :             :                                            slp_node, NULL);
   13772                 :         332 :       break;
   13773                 :             : 
   13774                 :        2297 :     case reduc_vec_info_type:
   13775                 :        2297 :       done = vect_transform_reduction (as_a <loop_vec_info> (vinfo), stmt_info,
   13776                 :             :                                        gsi, slp_node);
   13777                 :        2297 :       gcc_assert (done);
   13778                 :             :       break;
   13779                 :             : 
   13780                 :       22360 :     case cycle_phi_info_type:
   13781                 :       22360 :       done = vect_transform_cycle_phi (as_a <loop_vec_info> (vinfo), stmt_info,
   13782                 :             :                                        slp_node, slp_node_instance);
   13783                 :       22360 :       gcc_assert (done);
   13784                 :             :       break;
   13785                 :             : 
   13786                 :         348 :     case lc_phi_info_type:
   13787                 :         348 :       done = vect_transform_lc_phi (as_a <loop_vec_info> (vinfo),
   13788                 :             :                                     stmt_info, slp_node);
   13789                 :         348 :       gcc_assert (done);
   13790                 :             :       break;
   13791                 :             : 
   13792                 :          32 :     case recurr_info_type:
   13793                 :          32 :       done = vectorizable_recurr (as_a <loop_vec_info> (vinfo),
   13794                 :             :                                   stmt_info, &vec_stmt, slp_node, NULL);
   13795                 :          32 :       gcc_assert (done);
   13796                 :             :       break;
   13797                 :             : 
   13798                 :       13227 :     case phi_info_type:
   13799                 :       13227 :       done = vectorizable_phi (vinfo, stmt_info, &vec_stmt, slp_node, NULL);
   13800                 :       13227 :       gcc_assert (done);
   13801                 :             :       break;
   13802                 :             : 
   13803                 :           0 :     case loop_exit_ctrl_vec_info_type:
   13804                 :           0 :       done = vectorizable_early_exit (vinfo, stmt_info, gsi, &vec_stmt,
   13805                 :             :                                       slp_node, NULL);
   13806                 :           0 :       gcc_assert (done);
   13807                 :             :       break;
   13808                 :             : 
   13809                 :           0 :     default:
   13810                 :           0 :       if (!STMT_VINFO_LIVE_P (stmt_info))
   13811                 :             :         {
   13812                 :           0 :           if (dump_enabled_p ())
   13813                 :           0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
   13814                 :             :                              "stmt not supported.\n");
   13815                 :           0 :           gcc_unreachable ();
   13816                 :             :         }
   13817                 :      916885 :       done = true;
   13818                 :             :     }
   13819                 :             : 
   13820                 :      916885 :   if (!slp_node && vec_stmt)
   13821                 :           0 :     gcc_assert (STMT_VINFO_VEC_STMTS (stmt_info).exists ());
   13822                 :             : 
   13823                 :      916885 :   if (STMT_VINFO_TYPE (stmt_info) != store_vec_info_type
   13824                 :      378496 :       && (!slp_node
   13825                 :      378496 :           || !slp_node->ldst_lanes
   13826                 :           0 :           || SLP_TREE_CODE (slp_node) == VEC_PERM_EXPR))
   13827                 :             :     {
   13828                 :             :       /* Handle stmts whose DEF is used outside the loop-nest that is
   13829                 :             :          being vectorized.  */
   13830                 :      378496 :       done = can_vectorize_live_stmts (vinfo, stmt_info, slp_node,
   13831                 :             :                                        slp_node_instance, true, NULL);
   13832                 :      378496 :       gcc_assert (done);
   13833                 :             :     }
   13834                 :             : 
   13835                 :      916885 :   if (slp_node)
   13836                 :      916885 :     STMT_VINFO_VECTYPE (stmt_info) = saved_vectype;
   13837                 :             : 
   13838                 :      916885 :   return is_store;
   13839                 :             : }
   13840                 :             : 
   13841                 :             : 
   13842                 :             : /* Remove a group of stores (for SLP or interleaving), free their
   13843                 :             :    stmt_vec_info.  */
   13844                 :             : 
   13845                 :             : void
   13846                 :           0 : vect_remove_stores (vec_info *vinfo, stmt_vec_info first_stmt_info)
   13847                 :             : {
   13848                 :           0 :   stmt_vec_info next_stmt_info = first_stmt_info;
   13849                 :             : 
   13850                 :           0 :   while (next_stmt_info)
   13851                 :             :     {
   13852                 :           0 :       stmt_vec_info tmp = DR_GROUP_NEXT_ELEMENT (next_stmt_info);
   13853                 :           0 :       next_stmt_info = vect_orig_stmt (next_stmt_info);
   13854                 :             :       /* Free the attached stmt_vec_info and remove the stmt.  */
   13855                 :           0 :       vinfo->remove_stmt (next_stmt_info);
   13856                 :           0 :       next_stmt_info = tmp;
   13857                 :             :     }
   13858                 :           0 : }
   13859                 :             : 
   13860                 :             : /* If NUNITS is nonzero, return a vector type that contains NUNITS
   13861                 :             :    elements of type SCALAR_TYPE, or null if the target doesn't support
   13862                 :             :    such a type.
   13863                 :             : 
   13864                 :             :    If NUNITS is zero, return a vector type that contains elements of
   13865                 :             :    type SCALAR_TYPE, choosing whichever vector size the target prefers.
   13866                 :             : 
   13867                 :             :    If PREVAILING_MODE is VOIDmode, we have not yet chosen a vector mode
   13868                 :             :    for this vectorization region and want to "autodetect" the best choice.
   13869                 :             :    Otherwise, PREVAILING_MODE is a previously-chosen vector TYPE_MODE
   13870                 :             :    and we want the new type to be interoperable with it.   PREVAILING_MODE
   13871                 :             :    in this case can be a scalar integer mode or a vector mode; when it
   13872                 :             :    is a vector mode, the function acts like a tree-level version of
   13873                 :             :    related_vector_mode.  */
   13874                 :             : 
   13875                 :             : tree
   13876                 :    30588087 : get_related_vectype_for_scalar_type (machine_mode prevailing_mode,
   13877                 :             :                                      tree scalar_type, poly_uint64 nunits)
   13878                 :             : {
   13879                 :    30588087 :   tree orig_scalar_type = scalar_type;
   13880                 :    30588087 :   scalar_mode inner_mode;
   13881                 :    30588087 :   machine_mode simd_mode;
   13882                 :    30588087 :   tree vectype;
   13883                 :             : 
   13884                 :    30588087 :   if ((!INTEGRAL_TYPE_P (scalar_type)
   13885                 :    10456234 :        && !POINTER_TYPE_P (scalar_type)
   13886                 :     1671592 :        && !SCALAR_FLOAT_TYPE_P (scalar_type))
   13887                 :    40570134 :       || (!is_int_mode (TYPE_MODE (scalar_type), &inner_mode)
   13888                 :     1197486 :           && !is_float_mode (TYPE_MODE (scalar_type), &inner_mode)))
   13889                 :      478755 :     return NULL_TREE;
   13890                 :             : 
   13891                 :    30109332 :   unsigned int nbytes = GET_MODE_SIZE (inner_mode);
   13892                 :             : 
   13893                 :             :   /* Interoperability between modes requires one to be a constant multiple
   13894                 :             :      of the other, so that the number of vectors required for each operation
   13895                 :             :      is a compile-time constant.  */
   13896                 :    30109332 :   if (prevailing_mode != VOIDmode
   13897                 :    29011506 :       && !constant_multiple_p (nunits * nbytes,
   13898                 :    29011506 :                                GET_MODE_SIZE (prevailing_mode))
   13899                 :    31624083 :       && !constant_multiple_p (GET_MODE_SIZE (prevailing_mode),
   13900                 :     1514751 :                                nunits * nbytes))
   13901                 :             :     return NULL_TREE;
   13902                 :             : 
   13903                 :             :   /* For vector types of elements whose mode precision doesn't
   13904                 :             :      match their types precision we use a element type of mode
   13905                 :             :      precision.  The vectorization routines will have to make sure
   13906                 :             :      they support the proper result truncation/extension.
   13907                 :             :      We also make sure to build vector types with INTEGER_TYPE
   13908                 :             :      component type only.  */
   13909                 :    30109332 :   if (INTEGRAL_TYPE_P (scalar_type)
   13910                 :    50241104 :       && (GET_MODE_BITSIZE (inner_mode) != TYPE_PRECISION (scalar_type)
   13911                 :    18197527 :           || TREE_CODE (scalar_type) != INTEGER_TYPE))
   13912                 :     2171721 :     scalar_type = build_nonstandard_integer_type (GET_MODE_BITSIZE (inner_mode),
   13913                 :     2171721 :                                                   TYPE_UNSIGNED (scalar_type));
   13914                 :             : 
   13915                 :             :   /* We shouldn't end up building VECTOR_TYPEs of non-scalar components.
   13916                 :             :      When the component mode passes the above test simply use a type
   13917                 :             :      corresponding to that mode.  The theory is that any use that
   13918                 :             :      would cause problems with this will disable vectorization anyway.  */
   13919                 :    27937611 :   else if (!SCALAR_FLOAT_TYPE_P (scalar_type)
   13920                 :             :            && !INTEGRAL_TYPE_P (scalar_type))
   13921                 :     8784642 :     scalar_type = lang_hooks.types.type_for_mode (inner_mode, 1);
   13922                 :             : 
   13923                 :             :   /* We can't build a vector type of elements with alignment bigger than
   13924                 :             :      their size.  */
   13925                 :    19152969 :   else if (nbytes < TYPE_ALIGN_UNIT (scalar_type))
   13926                 :      315022 :     scalar_type = lang_hooks.types.type_for_mode (inner_mode,
   13927                 :      157511 :                                                   TYPE_UNSIGNED (scalar_type));
   13928                 :             : 
   13929                 :             :   /* If we felt back to using the mode fail if there was
   13930                 :             :      no scalar type for it.  */
   13931                 :    30109332 :   if (scalar_type == NULL_TREE)
   13932                 :             :     return NULL_TREE;
   13933                 :             : 
   13934                 :             :   /* If no prevailing mode was supplied, use the mode the target prefers.
   13935                 :             :      Otherwise lookup a vector mode based on the prevailing mode.  */
   13936                 :    30109332 :   if (prevailing_mode == VOIDmode)
   13937                 :             :     {
   13938                 :     1097826 :       gcc_assert (known_eq (nunits, 0U));
   13939                 :     1097826 :       simd_mode = targetm.vectorize.preferred_simd_mode (inner_mode);
   13940                 :     1097826 :       if (SCALAR_INT_MODE_P (simd_mode))
   13941                 :             :         {
   13942                 :             :           /* Traditional behavior is not to take the integer mode
   13943                 :             :              literally, but simply to use it as a way of determining
   13944                 :             :              the vector size.  It is up to mode_for_vector to decide
   13945                 :             :              what the TYPE_MODE should be.
   13946                 :             : 
   13947                 :             :              Note that nunits == 1 is allowed in order to support single
   13948                 :             :              element vector types.  */
   13949                 :       34000 :           if (!multiple_p (GET_MODE_SIZE (simd_mode), nbytes, &nunits)
   13950                 :         341 :               || !mode_for_vector (inner_mode, nunits).exists (&simd_mode))
   13951                 :       16659 :             return NULL_TREE;
   13952                 :             :         }
   13953                 :             :     }
   13954                 :    29011506 :   else if (SCALAR_INT_MODE_P (prevailing_mode)
   13955                 :    29011506 :            || !related_vector_mode (prevailing_mode,
   13956                 :    27051063 :                                     inner_mode, nunits).exists (&simd_mode))
   13957                 :             :     {
   13958                 :             :       /* Fall back to using mode_for_vector, mostly in the hope of being
   13959                 :             :          able to use an integer mode.  */
   13960                 :     1960443 :       if (known_eq (nunits, 0U)
   13961                 :     4556666 :           && !multiple_p (GET_MODE_SIZE (prevailing_mode), nbytes, &nunits))
   13962                 :             :         return NULL_TREE;
   13963                 :             : 
   13964                 :      147434 :       if (!mode_for_vector (inner_mode, nunits).exists (&simd_mode))
   13965                 :      137585 :         return NULL_TREE;
   13966                 :             :     }
   13967                 :             : 
   13968                 :    28142079 :   vectype = build_vector_type_for_mode (scalar_type, simd_mode);
   13969                 :             : 
   13970                 :             :   /* In cases where the mode was chosen by mode_for_vector, check that
   13971                 :             :      the target actually supports the chosen mode, or that it at least
   13972                 :             :      allows the vector mode to be replaced by a like-sized integer.  */
   13973                 :    56284158 :   if (!VECTOR_MODE_P (TYPE_MODE (vectype))
   13974                 :    28152179 :       && !INTEGRAL_MODE_P (TYPE_MODE (vectype)))
   13975                 :             :     return NULL_TREE;
   13976                 :             : 
   13977                 :             :   /* Re-attach the address-space qualifier if we canonicalized the scalar
   13978                 :             :      type.  */
   13979                 :    28134125 :   if (TYPE_ADDR_SPACE (orig_scalar_type) != TYPE_ADDR_SPACE (vectype))
   13980                 :           9 :     return build_qualified_type
   13981                 :           9 :              (vectype, KEEP_QUAL_ADDR_SPACE (TYPE_QUALS (orig_scalar_type)));
   13982                 :             : 
   13983                 :             :   return vectype;
   13984                 :             : }
   13985                 :             : 
   13986                 :             : /* Function get_vectype_for_scalar_type.
   13987                 :             : 
   13988                 :             :    Returns the vector type corresponding to SCALAR_TYPE as supported
   13989                 :             :    by the target.  If GROUP_SIZE is nonzero and we're performing BB
   13990                 :             :    vectorization, make sure that the number of elements in the vector
   13991                 :             :    is no bigger than GROUP_SIZE.  */
   13992                 :             : 
   13993                 :             : tree
   13994                 :    27386489 : get_vectype_for_scalar_type (vec_info *vinfo, tree scalar_type,
   13995                 :             :                              unsigned int group_size)
   13996                 :             : {
   13997                 :             :   /* For BB vectorization, we should always have a group size once we've
   13998                 :             :      constructed the SLP tree; the only valid uses of zero GROUP_SIZEs
   13999                 :             :      are tentative requests during things like early data reference
   14000                 :             :      analysis and pattern recognition.  */
   14001                 :    27386489 :   if (is_a <bb_vec_info> (vinfo))
   14002                 :    25629670 :     gcc_assert (vinfo->slp_instances.is_empty () || group_size != 0);
   14003                 :             :   else
   14004                 :             :     group_size = 0;
   14005                 :             : 
   14006                 :    27386489 :   tree vectype = get_related_vectype_for_scalar_type (vinfo->vector_mode,
   14007                 :             :                                                       scalar_type);
   14008                 :    27386489 :   if (vectype && vinfo->vector_mode == VOIDmode)
   14009                 :     1081165 :     vinfo->vector_mode = TYPE_MODE (vectype);
   14010                 :             : 
   14011                 :             :   /* Register the natural choice of vector type, before the group size
   14012                 :             :      has been applied.  */
   14013                 :           0 :   if (vectype)
   14014                 :    24936311 :     vinfo->used_vector_modes.add (TYPE_MODE (vectype));
   14015                 :             : 
   14016                 :             :   /* If the natural choice of vector type doesn't satisfy GROUP_SIZE,
   14017                 :             :      try again with an explicit number of elements.  */
   14018                 :    24936311 :   if (vectype
   14019                 :    24936311 :       && group_size
   14020                 :    27386489 :       && maybe_ge (TYPE_VECTOR_SUBPARTS (vectype), group_size))
   14021                 :             :     {
   14022                 :             :       /* Start with the biggest number of units that fits within
   14023                 :             :          GROUP_SIZE and halve it until we find a valid vector type.
   14024                 :             :          Usually either the first attempt will succeed or all will
   14025                 :             :          fail (in the latter case because GROUP_SIZE is too small
   14026                 :             :          for the target), but it's possible that a target could have
   14027                 :             :          a hole between supported vector types.
   14028                 :             : 
   14029                 :             :          If GROUP_SIZE is not a power of 2, this has the effect of
   14030                 :             :          trying the largest power of 2 that fits within the group,
   14031                 :             :          even though the group is not a multiple of that vector size.
   14032                 :             :          The BB vectorizer will then try to carve up the group into
   14033                 :             :          smaller pieces.  */
   14034                 :     3046922 :       unsigned int nunits = 1 << floor_log2 (group_size);
   14035                 :     3046922 :       do
   14036                 :             :         {
   14037                 :     3046922 :           vectype = get_related_vectype_for_scalar_type (vinfo->vector_mode,
   14038                 :     3046922 :                                                          scalar_type, nunits);
   14039                 :     3046922 :           nunits /= 2;
   14040                 :             :         }
   14041                 :     3046922 :       while (nunits > 1 && !vectype);
   14042                 :             :     }
   14043                 :             : 
   14044                 :    27386489 :   return vectype;
   14045                 :             : }
   14046                 :             : 
   14047                 :             : /* Return the vector type corresponding to SCALAR_TYPE as supported
   14048                 :             :    by the target.  NODE, if nonnull, is the SLP tree node that will
   14049                 :             :    use the returned vector type.  */
   14050                 :             : 
   14051                 :             : tree
   14052                 :      182382 : get_vectype_for_scalar_type (vec_info *vinfo, tree scalar_type, slp_tree node)
   14053                 :             : {
   14054                 :      182382 :   unsigned int group_size = 0;
   14055                 :      182382 :   if (node)
   14056                 :      182382 :     group_size = SLP_TREE_LANES (node);
   14057                 :      182382 :   return get_vectype_for_scalar_type (vinfo, scalar_type, group_size);
   14058                 :             : }
   14059                 :             : 
   14060                 :             : /* Function get_mask_type_for_scalar_type.
   14061                 :             : 
   14062                 :             :    Returns the mask type corresponding to a result of comparison
   14063                 :             :    of vectors of specified SCALAR_TYPE as supported by target.
   14064                 :             :    If GROUP_SIZE is nonzero and we're performing BB vectorization,
   14065                 :             :    make sure that the number of elements in the vector is no bigger
   14066                 :             :    than GROUP_SIZE.  */
   14067                 :             : 
   14068                 :             : tree
   14069                 :     1716202 : get_mask_type_for_scalar_type (vec_info *vinfo, tree scalar_type,
   14070                 :             :                                unsigned int group_size)
   14071                 :             : {
   14072                 :     1716202 :   tree vectype = get_vectype_for_scalar_type (vinfo, scalar_type, group_size);
   14073                 :             : 
   14074                 :     1716202 :   if (!vectype)
   14075                 :             :     return NULL;
   14076                 :             : 
   14077                 :     1696581 :   return truth_type_for (vectype);
   14078                 :             : }
   14079                 :             : 
   14080                 :             : /* Function get_mask_type_for_scalar_type.
   14081                 :             : 
   14082                 :             :    Returns the mask type corresponding to a result of comparison
   14083                 :             :    of vectors of specified SCALAR_TYPE as supported by target.
   14084                 :             :    NODE, if nonnull, is the SLP tree node that will use the returned
   14085                 :             :    vector type.  */
   14086                 :             : 
   14087                 :             : tree
   14088                 :          21 : get_mask_type_for_scalar_type (vec_info *vinfo, tree scalar_type,
   14089                 :             :                                slp_tree node)
   14090                 :             : {
   14091                 :          21 :   tree vectype = get_vectype_for_scalar_type (vinfo, scalar_type, node);
   14092                 :             : 
   14093                 :          21 :   if (!vectype)
   14094                 :             :     return NULL;
   14095                 :             : 
   14096                 :          21 :   return truth_type_for (vectype);
   14097                 :             : }
   14098                 :             : 
   14099                 :             : /* Function get_same_sized_vectype
   14100                 :             : 
   14101                 :             :    Returns a vector type corresponding to SCALAR_TYPE of size
   14102                 :             :    VECTOR_TYPE if supported by the target.  */
   14103                 :             : 
   14104                 :             : tree
   14105                 :      143882 : get_same_sized_vectype (tree scalar_type, tree vector_type)
   14106                 :             : {
   14107                 :      143882 :   if (VECT_SCALAR_BOOLEAN_TYPE_P (scalar_type))
   14108                 :           0 :     return truth_type_for (vector_type);
   14109                 :             : 
   14110                 :      143882 :   poly_uint64 nunits;
   14111                 :      287764 :   if (!multiple_p (GET_MODE_SIZE (TYPE_MODE (vector_type)),
   14112                 :      287764 :                    GET_MODE_SIZE (TYPE_MODE (scalar_type)), &nunits))
   14113                 :             :     return NULL_TREE;
   14114                 :             : 
   14115                 :      143882 :   return get_related_vectype_for_scalar_type (TYPE_MODE (vector_type),
   14116                 :      143882 :                                               scalar_type, nunits);
   14117                 :             : }
   14118                 :             : 
   14119                 :             : /* Return true if replacing LOOP_VINFO->vector_mode with VECTOR_MODE
   14120                 :             :    would not change the chosen vector modes.  */
   14121                 :             : 
   14122                 :             : bool
   14123                 :     1434578 : vect_chooses_same_modes_p (vec_info *vinfo, machine_mode vector_mode)
   14124                 :             : {
   14125                 :     1434578 :   for (vec_info::mode_set::iterator i = vinfo->used_vector_modes.begin ();
   14126                 :     3401042 :        i != vinfo->used_vector_modes.end (); ++i)
   14127                 :     1752523 :     if (!VECTOR_MODE_P (*i)
   14128                 :     5257569 :         || related_vector_mode (vector_mode, GET_MODE_INNER (*i), 0) != *i)
   14129                 :      769291 :       return false;
   14130                 :      665287 :   return true;
   14131                 :             : }
   14132                 :             : 
   14133                 :             : /* Function vect_is_simple_use.
   14134                 :             : 
   14135                 :             :    Input:
   14136                 :             :    VINFO - the vect info of the loop or basic block that is being vectorized.
   14137                 :             :    OPERAND - operand in the loop or bb.
   14138                 :             :    Output:
   14139                 :             :    DEF_STMT_INFO_OUT (optional) - information about the defining stmt in
   14140                 :             :      case OPERAND is an SSA_NAME that is defined in the vectorizable region
   14141                 :             :    DEF_STMT_OUT (optional) - the defining stmt in case OPERAND is an SSA_NAME;
   14142                 :             :      the definition could be anywhere in the function
   14143                 :             :    DT - the type of definition
   14144                 :             : 
   14145                 :             :    Returns whether a stmt with OPERAND can be vectorized.
   14146                 :             :    For loops, supportable operands are constants, loop invariants, and operands
   14147                 :             :    that are defined by the current iteration of the loop.  Unsupportable
   14148                 :             :    operands are those that are defined by a previous iteration of the loop (as
   14149                 :             :    is the case in reduction/induction computations).
   14150                 :             :    For basic blocks, supportable operands are constants and bb invariants.
   14151                 :             :    For now, operands defined outside the basic block are not supported.  */
   14152                 :             : 
   14153                 :             : bool
   14154                 :    42574200 : vect_is_simple_use (tree operand, vec_info *vinfo, enum vect_def_type *dt,
   14155                 :             :                     stmt_vec_info *def_stmt_info_out, gimple **def_stmt_out)
   14156                 :             : {
   14157                 :    42574200 :   if (def_stmt_info_out)
   14158                 :    38612819 :     *def_stmt_info_out = NULL;
   14159                 :    42574200 :   if (def_stmt_out)
   14160                 :     8931305 :     *def_stmt_out = NULL;
   14161                 :    42574200 :   *dt = vect_unknown_def_type;
   14162                 :             : 
   14163                 :    42574200 :   if (dump_enabled_p ())
   14164                 :             :     {
   14165                 :      803033 :       dump_printf_loc (MSG_NOTE, vect_location,
   14166                 :             :                        "vect_is_simple_use: operand ");
   14167                 :      803033 :       if (TREE_CODE (operand) == SSA_NAME
   14168                 :      803033 :           && !SSA_NAME_IS_DEFAULT_DEF (operand))
   14169                 :      729554 :         dump_gimple_expr (MSG_NOTE, TDF_SLIM, SSA_NAME_DEF_STMT (operand), 0);
   14170                 :             :       else
   14171                 :       73479 :         dump_generic_expr (MSG_NOTE, TDF_SLIM, operand);
   14172                 :             :     }
   14173                 :             : 
   14174                 :    42574200 :   if (CONSTANT_CLASS_P (operand))
   14175                 :     4435895 :     *dt = vect_constant_def;
   14176                 :    38138305 :   else if (is_gimple_min_invariant (operand))
   14177                 :      604169 :     *dt = vect_external_def;
   14178                 :    37534136 :   else if (TREE_CODE (operand) != SSA_NAME)
   14179                 :        1401 :     *dt = vect_unknown_def_type;
   14180                 :    37532735 :   else if (SSA_NAME_IS_DEFAULT_DEF (operand))
   14181                 :      565020 :     *dt = vect_external_def;
   14182                 :             :   else
   14183                 :             :     {
   14184                 :    36967715 :       gimple *def_stmt = SSA_NAME_DEF_STMT (operand);
   14185                 :    36967715 :       stmt_vec_info stmt_vinfo = vinfo->lookup_def (operand);
   14186                 :    36967715 :       if (!stmt_vinfo)
   14187                 :      899288 :         *dt = vect_external_def;
   14188                 :             :       else
   14189                 :             :         {
   14190                 :    36068427 :           stmt_vinfo = vect_stmt_to_vectorize (stmt_vinfo);
   14191                 :    36068427 :           def_stmt = stmt_vinfo->stmt;
   14192                 :    36068427 :           *dt = STMT_VINFO_DEF_TYPE (stmt_vinfo);
   14193                 :    36068427 :           if (def_stmt_info_out)
   14194                 :    33673506 :             *def_stmt_info_out = stmt_vinfo;
   14195                 :             :         }
   14196                 :    36967715 :       if (def_stmt_out)
   14197                 :     8732142 :         *def_stmt_out = def_stmt;
   14198                 :             :     }
   14199                 :             : 
   14200                 :    42574200 :   if (dump_enabled_p ())
   14201                 :             :     {
   14202                 :      803033 :       dump_printf (MSG_NOTE, ", type of def: ");
   14203                 :      803033 :       switch (*dt)
   14204                 :             :         {
   14205                 :           0 :         case vect_uninitialized_def:
   14206                 :           0 :           dump_printf (MSG_NOTE, "uninitialized\n");
   14207                 :           0 :           break;
   14208                 :       61525 :         case vect_constant_def:
   14209                 :       61525 :           dump_printf (MSG_NOTE, "constant\n");
   14210                 :       61525 :           break;
   14211                 :       28471 :         case vect_external_def:
   14212                 :       28471 :           dump_printf (MSG_NOTE, "external\n");
   14213                 :       28471 :           break;
   14214                 :      585845 :         case vect_internal_def:
   14215                 :      585845 :           dump_printf (MSG_NOTE, "internal\n");
   14216                 :      585845 :           break;
   14217                 :       99025 :         case vect_induction_def:
   14218                 :       99025 :           dump_printf (MSG_NOTE, "induction\n");
   14219                 :       99025 :           break;
   14220                 :       25281 :         case vect_reduction_def:
   14221                 :       25281 :           dump_printf (MSG_NOTE, "reduction\n");
   14222                 :       25281 :           break;
   14223                 :         340 :         case vect_double_reduction_def:
   14224                 :         340 :           dump_printf (MSG_NOTE, "double reduction\n");
   14225                 :         340 :           break;
   14226                 :        1851 :         case vect_nested_cycle:
   14227                 :        1851 :           dump_printf (MSG_NOTE, "nested cycle\n");
   14228                 :        1851 :           break;
   14229                 :         195 :         case vect_first_order_recurrence:
   14230                 :         195 :           dump_printf (MSG_NOTE, "first order recurrence\n");
   14231                 :         195 :           break;
   14232                 :           0 :         case vect_condition_def:
   14233                 :           0 :           dump_printf (MSG_NOTE, "control flow\n");
   14234                 :           0 :           break;
   14235                 :         500 :         case vect_unknown_def_type:
   14236                 :         500 :           dump_printf (MSG_NOTE, "unknown\n");
   14237                 :         500 :           break;
   14238                 :             :         }
   14239                 :             :     }
   14240                 :             : 
   14241                 :    42574200 :   if (*dt == vect_unknown_def_type)
   14242                 :             :     {
   14243                 :       20325 :       if (dump_enabled_p ())
   14244                 :         500 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
   14245                 :             :                          "Unsupported pattern.\n");
   14246                 :       20325 :       return false;
   14247                 :             :     }
   14248                 :             : 
   14249                 :             :   return true;
   14250                 :             : }
   14251                 :             : 
   14252                 :             : /* Function vect_is_simple_use.
   14253                 :             : 
   14254                 :             :    Same as vect_is_simple_use but also determines the vector operand
   14255                 :             :    type of OPERAND and stores it to *VECTYPE.  If the definition of
   14256                 :             :    OPERAND is vect_uninitialized_def, vect_constant_def or
   14257                 :             :    vect_external_def *VECTYPE will be set to NULL_TREE and the caller
   14258                 :             :    is responsible to compute the best suited vector type for the
   14259                 :             :    scalar operand.  */
   14260                 :             : 
   14261                 :             : bool
   14262                 :        9551 : vect_is_simple_use (tree operand, vec_info *vinfo, enum vect_def_type *dt,
   14263                 :             :                     tree *vectype, stmt_vec_info *def_stmt_info_out,
   14264                 :             :                     gimple **def_stmt_out)
   14265                 :             : {
   14266                 :        9551 :   stmt_vec_info def_stmt_info;
   14267                 :        9551 :   gimple *def_stmt;
   14268                 :        9551 :   if (!vect_is_simple_use (operand, vinfo, dt, &def_stmt_info, &def_stmt))
   14269                 :             :     return false;
   14270                 :             : 
   14271                 :        9551 :   if (def_stmt_out)
   14272                 :           0 :     *def_stmt_out = def_stmt;
   14273                 :        9551 :   if (def_stmt_info_out)
   14274                 :           0 :     *def_stmt_info_out = def_stmt_info;
   14275                 :             : 
   14276                 :             :   /* Now get a vector type if the def is internal, otherwise supply
   14277                 :             :      NULL_TREE and leave it up to the caller to figure out a proper
   14278                 :             :      type for the use stmt.  */
   14279                 :        9551 :   if (*dt == vect_internal_def
   14280                 :             :       || *dt == vect_induction_def
   14281                 :             :       || *dt == vect_reduction_def
   14282                 :             :       || *dt == vect_double_reduction_def
   14283                 :             :       || *dt == vect_nested_cycle
   14284                 :        9551 :       || *dt == vect_first_order_recurrence)
   14285                 :             :     {
   14286                 :        9540 :       *vectype = STMT_VINFO_VECTYPE (def_stmt_info);
   14287                 :        9540 :       gcc_assert (*vectype != NULL_TREE);
   14288                 :        9540 :       if (dump_enabled_p ())
   14289                 :        1511 :         dump_printf_loc (MSG_NOTE, vect_location,
   14290                 :             :                          "vect_is_simple_use: vectype %T\n", *vectype);
   14291                 :             :     }
   14292                 :          11 :   else if (*dt == vect_uninitialized_def
   14293                 :             :            || *dt == vect_constant_def
   14294                 :             :            || *dt == vect_external_def)
   14295                 :          11 :     *vectype = NULL_TREE;
   14296                 :             :   else
   14297                 :           0 :     gcc_unreachable ();
   14298                 :             : 
   14299                 :             :   return true;
   14300                 :             : }
   14301                 :             : 
   14302                 :             : /* Function vect_is_simple_use.
   14303                 :             : 
   14304                 :             :    Same as vect_is_simple_use but determines the operand by operand
   14305                 :             :    position OPERAND from either STMT or SLP_NODE, filling in *OP
   14306                 :             :    and *SLP_DEF (when SLP_NODE is not NULL).  */
   14307                 :             : 
   14308                 :             : bool
   14309                 :     3581397 : vect_is_simple_use (vec_info *vinfo, stmt_vec_info stmt, slp_tree slp_node,
   14310                 :             :                     unsigned operand, tree *op, slp_tree *slp_def,
   14311                 :             :                     enum vect_def_type *dt,
   14312                 :             :                     tree *vectype, stmt_vec_info *def_stmt_info_out)
   14313                 :             : {
   14314                 :     3581397 :   if (slp_node)
   14315                 :             :     {
   14316                 :     3581397 :       slp_tree child = SLP_TREE_CHILDREN (slp_node)[operand];
   14317                 :     3581397 :       *slp_def = child;
   14318                 :     3581397 :       *vectype = SLP_TREE_VECTYPE (child);
   14319                 :     3581397 :       if (SLP_TREE_DEF_TYPE (child) == vect_internal_def)
   14320                 :             :         {
   14321                 :             :           /* ???  VEC_PERM nodes might be intermediate and their lane value
   14322                 :             :              have no representative (nor do we build a VEC_PERM stmt for
   14323                 :             :              the actual operation).  Note for two-operator nodes we set
   14324                 :             :              a representative but leave scalar stmts empty as we'd only
   14325                 :             :              have one for a subset of lanes.  Ideally no caller would
   14326                 :             :              require *op for internal defs.  */
   14327                 :     1851451 :           if (SLP_TREE_REPRESENTATIVE (child))
   14328                 :             :             {
   14329                 :     1850649 :               *op = gimple_get_lhs (SLP_TREE_REPRESENTATIVE (child)->stmt);
   14330                 :     1850649 :               return vect_is_simple_use (*op, vinfo, dt, def_stmt_info_out);
   14331                 :             :             }
   14332                 :             :           else
   14333                 :             :             {
   14334                 :         802 :               gcc_assert (SLP_TREE_CODE (child) == VEC_PERM_EXPR);
   14335                 :         802 :               *op = error_mark_node;
   14336                 :         802 :               *dt = vect_internal_def;
   14337                 :         802 :               if (def_stmt_info_out)
   14338                 :           0 :                 *def_stmt_info_out = NULL;
   14339                 :         802 :               return true;
   14340                 :             :             }
   14341                 :             :         }
   14342                 :             :       else
   14343                 :             :         {
   14344                 :     1729946 :           if (def_stmt_info_out)
   14345                 :       46104 :             *def_stmt_info_out = NULL;
   14346                 :     1729946 :           *op = SLP_TREE_SCALAR_OPS (child)[0];
   14347                 :     1729946 :           *dt = SLP_TREE_DEF_TYPE (child);
   14348                 :     1729946 :           return true;
   14349                 :             :         }
   14350                 :             :     }
   14351                 :             :   else
   14352                 :             :     {
   14353                 :           0 :       *slp_def = NULL;
   14354                 :           0 :       if (gassign *ass = dyn_cast <gassign *> (stmt->stmt))
   14355                 :             :         {
   14356                 :           0 :           if (gimple_assign_rhs_code (ass) == COND_EXPR
   14357                 :           0 :               && COMPARISON_CLASS_P (gimple_assign_rhs1 (ass)))
   14358                 :           0 :             gcc_unreachable ();
   14359                 :           0 :           else if (gimple_assign_rhs_code (ass) == VIEW_CONVERT_EXPR)
   14360                 :           0 :             *op = TREE_OPERAND (gimple_assign_rhs1 (ass), 0);
   14361                 :             :           else
   14362                 :           0 :             *op = gimple_op (ass, operand + 1);
   14363                 :             :         }
   14364                 :           0 :       else if (gcond *cond = dyn_cast <gcond *> (stmt->stmt))
   14365                 :           0 :         *op = gimple_op (cond, operand);
   14366                 :           0 :       else if (gcall *call = dyn_cast <gcall *> (stmt->stmt))
   14367                 :           0 :         *op = gimple_call_arg (call, operand);
   14368                 :             :       else
   14369                 :           0 :         gcc_unreachable ();
   14370                 :           0 :       return vect_is_simple_use (*op, vinfo, dt, vectype, def_stmt_info_out);
   14371                 :             :     }
   14372                 :             : }
   14373                 :             : 
   14374                 :             : /* If OP is not NULL and is external or constant update its vector
   14375                 :             :    type with VECTYPE.  Returns true if successful or false if not,
   14376                 :             :    for example when conflicting vector types are present.  */
   14377                 :             : 
   14378                 :             : bool
   14379                 :     3114225 : vect_maybe_update_slp_op_vectype (slp_tree op, tree vectype)
   14380                 :             : {
   14381                 :     3114225 :   if (!op || SLP_TREE_DEF_TYPE (op) == vect_internal_def)
   14382                 :             :     return true;
   14383                 :     1147806 :   if (SLP_TREE_VECTYPE (op))
   14384                 :       67772 :     return types_compatible_p (SLP_TREE_VECTYPE (op), vectype);
   14385                 :             :   /* For external defs refuse to produce VECTOR_BOOLEAN_TYPE_P, those
   14386                 :             :      should be handled by patters.  Allow vect_constant_def for now
   14387                 :             :      as well as the trivial single-lane uniform vect_external_def case
   14388                 :             :      both of which we code-generate reasonably.  */
   14389                 :     1080034 :   if (VECTOR_BOOLEAN_TYPE_P (vectype)
   14390                 :        1040 :       && SLP_TREE_DEF_TYPE (op) == vect_external_def
   14391                 :     1080630 :       && SLP_TREE_LANES (op) > 1)
   14392                 :             :     return false;
   14393                 :     1079831 :   SLP_TREE_VECTYPE (op) = vectype;
   14394                 :     1079831 :   return true;
   14395                 :             : }
   14396                 :             : 
   14397                 :             : /* Function supportable_widening_operation
   14398                 :             : 
   14399                 :             :    Check whether an operation represented by the code CODE is a
   14400                 :             :    widening operation that is supported by the target platform in
   14401                 :             :    vector form (i.e., when operating on arguments of type VECTYPE_IN
   14402                 :             :    producing a result of type VECTYPE_OUT).
   14403                 :             : 
   14404                 :             :    Widening operations we currently support are NOP (CONVERT), FLOAT,
   14405                 :             :    FIX_TRUNC and WIDEN_MULT.  This function checks if these operations
   14406                 :             :    are supported by the target platform either directly (via vector
   14407                 :             :    tree-codes), or via target builtins.
   14408                 :             : 
   14409                 :             :    Output:
   14410                 :             :    - CODE1 and CODE2 are codes of vector operations to be used when
   14411                 :             :    vectorizing the operation, if available.
   14412                 :             :    - MULTI_STEP_CVT determines the number of required intermediate steps in
   14413                 :             :    case of multi-step conversion (like char->short->int - in that case
   14414                 :             :    MULTI_STEP_CVT will be 1).
   14415                 :             :    - INTERM_TYPES contains the intermediate type required to perform the
   14416                 :             :    widening operation (short in the above example).  */
   14417                 :             : 
   14418                 :             : bool
   14419                 :      327431 : supportable_widening_operation (vec_info *vinfo,
   14420                 :             :                                 code_helper code,
   14421                 :             :                                 stmt_vec_info stmt_info,
   14422                 :             :                                 tree vectype_out, tree vectype_in,
   14423                 :             :                                 code_helper *code1,
   14424                 :             :                                 code_helper *code2,
   14425                 :             :                                 int *multi_step_cvt,
   14426                 :             :                                 vec<tree> *interm_types)
   14427                 :             : {
   14428                 :      327431 :   loop_vec_info loop_info = dyn_cast <loop_vec_info> (vinfo);
   14429                 :      327431 :   class loop *vect_loop = NULL;
   14430                 :      327431 :   machine_mode vec_mode;
   14431                 :      327431 :   enum insn_code icode1, icode2;
   14432                 :      327431 :   optab optab1 = unknown_optab, optab2 = unknown_optab;
   14433                 :      327431 :   tree vectype = vectype_in;
   14434                 :      327431 :   tree wide_vectype = vectype_out;
   14435                 :      327431 :   tree_code c1 = MAX_TREE_CODES, c2 = MAX_TREE_CODES;
   14436                 :      327431 :   int i;
   14437                 :      327431 :   tree prev_type, intermediate_type;
   14438                 :      327431 :   machine_mode intermediate_mode, prev_mode;
   14439                 :      327431 :   optab optab3, optab4;
   14440                 :             : 
   14441                 :      327431 :   *multi_step_cvt = 0;
   14442                 :      182984 :   if (loop_info)
   14443                 :      144447 :     vect_loop = LOOP_VINFO_LOOP (loop_info);
   14444                 :             : 
   14445                 :      327431 :   switch (code.safe_as_tree_code ())
   14446                 :             :     {
   14447                 :             :     case MAX_TREE_CODES:
   14448                 :             :       /* Don't set c1 and c2 if code is not a tree_code.  */
   14449                 :             :       break;
   14450                 :             : 
   14451                 :      170486 :     case WIDEN_MULT_EXPR:
   14452                 :             :       /* The result of a vectorized widening operation usually requires
   14453                 :             :          two vectors (because the widened results do not fit into one vector).
   14454                 :             :          The generated vector results would normally be expected to be
   14455                 :             :          generated in the same order as in the original scalar computation,
   14456                 :             :          i.e. if 8 results are generated in each vector iteration, they are
   14457                 :             :          to be organized as follows:
   14458                 :             :                 vect1: [res1,res2,res3,res4],
   14459                 :             :                 vect2: [res5,res6,res7,res8].
   14460                 :             : 
   14461                 :             :          However, in the special case that the result of the widening
   14462                 :             :          operation is used in a reduction computation only, the order doesn't
   14463                 :             :          matter (because when vectorizing a reduction we change the order of
   14464                 :             :          the computation).  Some targets can take advantage of this and
   14465                 :             :          generate more efficient code.  For example, targets like Altivec,
   14466                 :             :          that support widen_mult using a sequence of {mult_even,mult_odd}
   14467                 :             :          generate the following vectors:
   14468                 :             :                 vect1: [res1,res3,res5,res7],
   14469                 :             :                 vect2: [res2,res4,res6,res8].
   14470                 :             : 
   14471                 :             :          When vectorizing outer-loops, we execute the inner-loop sequentially
   14472                 :             :          (each vectorized inner-loop iteration contributes to VF outer-loop
   14473                 :             :          iterations in parallel).  We therefore don't allow to change the
   14474                 :             :          order of the computation in the inner-loop during outer-loop
   14475                 :             :          vectorization.  */
   14476                 :             :       /* TODO: Another case in which order doesn't *really* matter is when we
   14477                 :             :          widen and then contract again, e.g. (short)((int)x * y >> 8).
   14478                 :             :          Normally, pack_trunc performs an even/odd permute, whereas the
   14479                 :             :          repack from an even/odd expansion would be an interleave, which
   14480                 :             :          would be significantly simpler for e.g. AVX2.  */
   14481                 :             :       /* In any case, in order to avoid duplicating the code below, recurse
   14482                 :             :          on VEC_WIDEN_MULT_EVEN_EXPR.  If it succeeds, all the return values
   14483                 :             :          are properly set up for the caller.  If we fail, we'll continue with
   14484                 :             :          a VEC_WIDEN_MULT_LO/HI_EXPR check.  */
   14485                 :      170486 :       if (vect_loop
   14486                 :       46484 :           && !nested_in_vect_loop_p (vect_loop, stmt_info)
   14487                 :      217432 :           && supportable_widening_operation (vinfo, VEC_WIDEN_MULT_EVEN_EXPR,
   14488                 :             :                                              stmt_info, vectype_out,
   14489                 :             :                                              vectype_in, code1,
   14490                 :             :                                              code2, multi_step_cvt,
   14491                 :             :                                              interm_types))
   14492                 :             :         {
   14493                 :             :           /* Elements in a vector with vect_used_by_reduction property cannot
   14494                 :             :              be reordered if the use chain with this property does not have the
   14495                 :             :              same operation.  One such an example is s += a * b, where elements
   14496                 :             :              in a and b cannot be reordered.  Here we check if the vector defined
   14497                 :             :              by STMT is only directly used in the reduction statement.  */
   14498                 :       32488 :           tree lhs = gimple_assign_lhs (vect_orig_stmt (stmt_info)->stmt);
   14499                 :       30895 :           stmt_vec_info use_stmt_info = loop_info->lookup_single_use (lhs);
   14500                 :       30895 :           if (use_stmt_info && STMT_VINFO_REDUC_DEF (use_stmt_info))
   14501                 :             :             return true;
   14502                 :             :         }
   14503                 :             :       c1 = VEC_WIDEN_MULT_LO_EXPR;
   14504                 :             :       c2 = VEC_WIDEN_MULT_HI_EXPR;
   14505                 :             :       break;
   14506                 :             : 
   14507                 :             :     case DOT_PROD_EXPR:
   14508                 :      327274 :       c1 = DOT_PROD_EXPR;
   14509                 :      327274 :       c2 = DOT_PROD_EXPR;
   14510                 :             :       break;
   14511                 :             : 
   14512                 :           0 :     case SAD_EXPR:
   14513                 :           0 :       c1 = SAD_EXPR;
   14514                 :           0 :       c2 = SAD_EXPR;
   14515                 :           0 :       break;
   14516                 :             : 
   14517                 :       46484 :     case VEC_WIDEN_MULT_EVEN_EXPR:
   14518                 :             :       /* Support the recursion induced just above.  */
   14519                 :       46484 :       c1 = VEC_WIDEN_MULT_EVEN_EXPR;
   14520                 :       46484 :       c2 = VEC_WIDEN_MULT_ODD_EXPR;
   14521                 :       46484 :       break;
   14522                 :             : 
   14523                 :        9792 :     case WIDEN_LSHIFT_EXPR:
   14524                 :        9792 :       c1 = VEC_WIDEN_LSHIFT_LO_EXPR;
   14525                 :        9792 :       c2 = VEC_WIDEN_LSHIFT_HI_EXPR;
   14526                 :        9792 :       break;
   14527                 :             : 
   14528                 :       38399 :     CASE_CONVERT:
   14529                 :       38399 :       c1 = VEC_UNPACK_LO_EXPR;
   14530                 :       38399 :       c2 = VEC_UNPACK_HI_EXPR;
   14531                 :       38399 :       break;
   14532                 :             : 
   14533                 :        7309 :     case FLOAT_EXPR:
   14534                 :        7309 :       c1 = VEC_UNPACK_FLOAT_LO_EXPR;
   14535                 :        7309 :       c2 = VEC_UNPACK_FLOAT_HI_EXPR;
   14536                 :        7309 :       break;
   14537                 :             : 
   14538                 :         260 :     case FIX_TRUNC_EXPR:
   14539                 :         260 :       c1 = VEC_UNPACK_FIX_TRUNC_LO_EXPR;
   14540                 :         260 :       c2 = VEC_UNPACK_FIX_TRUNC_HI_EXPR;
   14541                 :         260 :       break;
   14542                 :             : 
   14543                 :           0 :     default:
   14544                 :           0 :       gcc_unreachable ();
   14545                 :             :     }
   14546                 :             : 
   14547                 :      327274 :   if (BYTES_BIG_ENDIAN && c1 != VEC_WIDEN_MULT_EVEN_EXPR)
   14548                 :             :     std::swap (c1, c2);
   14549                 :             : 
   14550                 :      327274 :   if (code == FIX_TRUNC_EXPR)
   14551                 :             :     {
   14552                 :             :       /* The signedness is determined from output operand.  */
   14553                 :         260 :       optab1 = optab_for_tree_code (c1, vectype_out, optab_default);
   14554                 :         260 :       optab2 = optab_for_tree_code (c2, vectype_out, optab_default);
   14555                 :             :     }
   14556                 :      567480 :   else if (CONVERT_EXPR_CODE_P (code.safe_as_tree_code ())
   14557                 :       38399 :            && VECTOR_BOOLEAN_TYPE_P (wide_vectype)
   14558                 :        6214 :            && VECTOR_BOOLEAN_TYPE_P (vectype)
   14559                 :        6214 :            && TYPE_MODE (wide_vectype) == TYPE_MODE (vectype)
   14560                 :      272584 :            && SCALAR_INT_MODE_P (TYPE_MODE (vectype)))
   14561                 :             :     {
   14562                 :             :       /* If the input and result modes are the same, a different optab
   14563                 :             :          is needed where we pass in the number of units in vectype.  */
   14564                 :             :       optab1 = vec_unpacks_sbool_lo_optab;
   14565                 :             :       optab2 = vec_unpacks_sbool_hi_optab;
   14566                 :             :     }
   14567                 :             : 
   14568                 :      327274 :   vec_mode = TYPE_MODE (vectype);
   14569                 :      327274 :   if (widening_fn_p (code))
   14570                 :             :      {
   14571                 :             :        /* If this is an internal fn then we must check whether the target
   14572                 :             :           supports either a low-high split or an even-odd split.  */
   14573                 :       54701 :       internal_fn ifn = as_internal_fn ((combined_fn) code);
   14574                 :             : 
   14575                 :       54701 :       internal_fn lo, hi, even, odd;
   14576                 :       54701 :       lookup_hilo_internal_fn (ifn, &lo, &hi);
   14577                 :       54701 :       *code1 = as_combined_fn (lo);
   14578                 :       54701 :       *code2 = as_combined_fn (hi);
   14579                 :       54701 :       optab1 = direct_internal_fn_optab (lo, {vectype, vectype});
   14580                 :       54701 :       optab2 = direct_internal_fn_optab (hi, {vectype, vectype});
   14581                 :             : 
   14582                 :             :       /* If we don't support low-high, then check for even-odd.  */
   14583                 :       54701 :       if (!optab1
   14584                 :       54701 :           || (icode1 = optab_handler (optab1, vec_mode)) == CODE_FOR_nothing
   14585                 :           0 :           || !optab2
   14586                 :       54701 :           || (icode2 = optab_handler (optab2, vec_mode)) == CODE_FOR_nothing)
   14587                 :             :         {
   14588                 :       54701 :           lookup_evenodd_internal_fn (ifn, &even, &odd);
   14589                 :       54701 :           *code1 = as_combined_fn (even);
   14590                 :       54701 :           *code2 = as_combined_fn (odd);
   14591                 :       54701 :           optab1 = direct_internal_fn_optab (even, {vectype, vectype});
   14592                 :       54701 :           optab2 = direct_internal_fn_optab (odd, {vectype, vectype});
   14593                 :             :         }
   14594                 :             :     }
   14595                 :      272573 :   else if (code.is_tree_code ())
   14596                 :             :     {
   14597                 :      272573 :       if (code == FIX_TRUNC_EXPR)
   14598                 :             :         {
   14599                 :             :           /* The signedness is determined from output operand.  */
   14600                 :         260 :           optab1 = optab_for_tree_code (c1, vectype_out, optab_default);
   14601                 :         260 :           optab2 = optab_for_tree_code (c2, vectype_out, optab_default);
   14602                 :             :         }
   14603                 :      272313 :       else if (CONVERT_EXPR_CODE_P ((tree_code) code.safe_as_tree_code ())
   14604                 :       38399 :                && VECTOR_BOOLEAN_TYPE_P (wide_vectype)
   14605                 :        6214 :                && VECTOR_BOOLEAN_TYPE_P (vectype)
   14606                 :        6214 :                && TYPE_MODE (wide_vectype) == TYPE_MODE (vectype)
   14607                 :      272584 :                && SCALAR_INT_MODE_P (TYPE_MODE (vectype)))
   14608                 :             :         {
   14609                 :             :           /* If the input and result modes are the same, a different optab
   14610                 :             :              is needed where we pass in the number of units in vectype.  */
   14611                 :             :           optab1 = vec_unpacks_sbool_lo_optab;
   14612                 :             :           optab2 = vec_unpacks_sbool_hi_optab;
   14613                 :             :         }
   14614                 :             :       else
   14615                 :             :         {
   14616                 :      272042 :           optab1 = optab_for_tree_code (c1, vectype, optab_default);
   14617                 :      272042 :           optab2 = optab_for_tree_code (c2, vectype, optab_default);
   14618                 :             :         }
   14619                 :      272573 :       *code1 = c1;
   14620                 :      272573 :       *code2 = c2;
   14621                 :             :     }
   14622                 :             : 
   14623                 :      327274 :   if (!optab1 || !optab2)
   14624                 :             :     return false;
   14625                 :             : 
   14626                 :      327274 :   if ((icode1 = optab_handler (optab1, vec_mode)) == CODE_FOR_nothing
   14627                 :      327274 :        || (icode2 = optab_handler (optab2, vec_mode)) == CODE_FOR_nothing)
   14628                 :      160700 :     return false;
   14629                 :             : 
   14630                 :             : 
   14631                 :      166574 :   if (insn_data[icode1].operand[0].mode == TYPE_MODE (wide_vectype)
   14632                 :      166574 :       && insn_data[icode2].operand[0].mode == TYPE_MODE (wide_vectype))
   14633                 :             :     {
   14634                 :      153556 :       if (!VECTOR_BOOLEAN_TYPE_P (vectype))
   14635                 :             :         return true;
   14636                 :             :       /* For scalar masks we may have different boolean
   14637                 :             :          vector types having the same QImode.  Thus we
   14638                 :             :          add additional check for elements number.  */
   14639                 :        2733 :       if (known_eq (TYPE_VECTOR_SUBPARTS (vectype),
   14640                 :             :                     TYPE_VECTOR_SUBPARTS (wide_vectype) * 2))
   14641                 :             :         return true;
   14642                 :             :     }
   14643                 :             : 
   14644                 :             :   /* Check if it's a multi-step conversion that can be done using intermediate
   14645                 :             :      types.  */
   14646                 :             : 
   14647                 :       13118 :   prev_type = vectype;
   14648                 :       13118 :   prev_mode = vec_mode;
   14649                 :             : 
   14650                 :      175396 :   if (!CONVERT_EXPR_CODE_P (code.safe_as_tree_code ()))
   14651                 :             :     return false;
   14652                 :             : 
   14653                 :             :   /* We assume here that there will not be more than MAX_INTERM_CVT_STEPS
   14654                 :             :      intermediate steps in promotion sequence.  We try
   14655                 :             :      MAX_INTERM_CVT_STEPS to get to NARROW_VECTYPE, and fail if we do
   14656                 :             :      not.  */
   14657                 :       13066 :   interm_types->create (MAX_INTERM_CVT_STEPS);
   14658                 :       15036 :   for (i = 0; i < MAX_INTERM_CVT_STEPS; i++)
   14659                 :             :     {
   14660                 :       15036 :       intermediate_mode = insn_data[icode1].operand[0].mode;
   14661                 :       15036 :       if (VECTOR_BOOLEAN_TYPE_P (prev_type))
   14662                 :        4250 :         intermediate_type
   14663                 :        4250 :           = vect_halve_mask_nunits (prev_type, intermediate_mode);
   14664                 :       10786 :       else if (VECTOR_MODE_P (intermediate_mode))
   14665                 :             :         {
   14666                 :       10786 :           tree intermediate_element_type
   14667                 :       10786 :             = lang_hooks.types.type_for_mode (GET_MODE_INNER (intermediate_mode),
   14668                 :       10786 :                                               TYPE_UNSIGNED (prev_type));
   14669                 :       10786 :           intermediate_type
   14670                 :       10786 :             = build_vector_type_for_mode (intermediate_element_type,
   14671                 :             :                                           intermediate_mode);
   14672                 :       10786 :         }
   14673                 :             :       else
   14674                 :           0 :         intermediate_type
   14675                 :           0 :           = lang_hooks.types.type_for_mode (intermediate_mode,
   14676                 :           0 :                                             TYPE_UNSIGNED (prev_type));
   14677                 :             : 
   14678                 :       15036 :       if (VECTOR_BOOLEAN_TYPE_P (intermediate_type)
   14679                 :        4250 :           && VECTOR_BOOLEAN_TYPE_P (prev_type)
   14680                 :        4250 :           && intermediate_mode == prev_mode
   14681                 :       15036 :           && SCALAR_INT_MODE_P (prev_mode))
   14682                 :             :         {
   14683                 :             :           /* If the input and result modes are the same, a different optab
   14684                 :             :              is needed where we pass in the number of units in vectype.  */
   14685                 :             :           optab3 = vec_unpacks_sbool_lo_optab;
   14686                 :             :           optab4 = vec_unpacks_sbool_hi_optab;
   14687                 :             :         }
   14688                 :             :       else
   14689                 :             :         {
   14690                 :       15036 :           optab3 = optab_for_tree_code (c1, intermediate_type, optab_default);
   14691                 :       15036 :           optab4 = optab_for_tree_code (c2, intermediate_type, optab_default);
   14692                 :             :         }
   14693                 :             : 
   14694                 :       15036 :       if (!optab3 || !optab4
   14695                 :       15036 :           || (icode1 = optab_handler (optab1, prev_mode)) == CODE_FOR_nothing
   14696                 :       15036 :           || insn_data[icode1].operand[0].mode != intermediate_mode
   14697                 :       15036 :           || (icode2 = optab_handler (optab2, prev_mode)) == CODE_FOR_nothing
   14698                 :       15036 :           || insn_data[icode2].operand[0].mode != intermediate_mode
   14699                 :       15036 :           || ((icode1 = optab_handler (optab3, intermediate_mode))
   14700                 :             :               == CODE_FOR_nothing)
   14701                 :       28494 :           || ((icode2 = optab_handler (optab4, intermediate_mode))
   14702                 :             :               == CODE_FOR_nothing))
   14703                 :             :         break;
   14704                 :             : 
   14705                 :       13458 :       interm_types->quick_push (intermediate_type);
   14706                 :       13458 :       (*multi_step_cvt)++;
   14707                 :             : 
   14708                 :       13458 :       if (insn_data[icode1].operand[0].mode == TYPE_MODE (wide_vectype)
   14709                 :       13458 :           && insn_data[icode2].operand[0].mode == TYPE_MODE (wide_vectype))
   14710                 :             :         {
   14711                 :       11508 :           if (!VECTOR_BOOLEAN_TYPE_P (vectype))
   14712                 :             :             return true;
   14713                 :        1917 :           if (known_eq (TYPE_VECTOR_SUBPARTS (intermediate_type),
   14714                 :             :                         TYPE_VECTOR_SUBPARTS (wide_vectype) * 2))
   14715                 :             :             return true;
   14716                 :             :         }
   14717                 :             : 
   14718                 :        1970 :       prev_type = intermediate_type;
   14719                 :        1970 :       prev_mode = intermediate_mode;
   14720                 :             :     }
   14721                 :             : 
   14722                 :        1578 :   interm_types->release ();
   14723                 :        1578 :   return false;
   14724                 :             : }
   14725                 :             : 
   14726                 :             : 
   14727                 :             : /* Function supportable_narrowing_operation
   14728                 :             : 
   14729                 :             :    Check whether an operation represented by the code CODE is a
   14730                 :             :    narrowing operation that is supported by the target platform in
   14731                 :             :    vector form (i.e., when operating on arguments of type VECTYPE_IN
   14732                 :             :    and producing a result of type VECTYPE_OUT).
   14733                 :             : 
   14734                 :             :    Narrowing operations we currently support are NOP (CONVERT), FIX_TRUNC
   14735                 :             :    and FLOAT.  This function checks if these operations are supported by
   14736                 :             :    the target platform directly via vector tree-codes.
   14737                 :             : 
   14738                 :             :    Output:
   14739                 :             :    - CODE1 is the code of a vector operation to be used when
   14740                 :             :    vectorizing the operation, if available.
   14741                 :             :    - MULTI_STEP_CVT determines the number of required intermediate steps in
   14742                 :             :    case of multi-step conversion (like int->short->char - in that case
   14743                 :             :    MULTI_STEP_CVT will be 1).
   14744                 :             :    - INTERM_TYPES contains the intermediate type required to perform the
   14745                 :             :    narrowing operation (short in the above example).   */
   14746                 :             : 
   14747                 :             : bool
   14748                 :       33108 : supportable_narrowing_operation (code_helper code,
   14749                 :             :                                  tree vectype_out, tree vectype_in,
   14750                 :             :                                  code_helper *code1, int *multi_step_cvt,
   14751                 :             :                                  vec<tree> *interm_types)
   14752                 :             : {
   14753                 :       33108 :   machine_mode vec_mode;
   14754                 :       33108 :   enum insn_code icode1;
   14755                 :       33108 :   optab optab1, interm_optab;
   14756                 :       33108 :   tree vectype = vectype_in;
   14757                 :       33108 :   tree narrow_vectype = vectype_out;
   14758                 :       33108 :   enum tree_code c1;
   14759                 :       33108 :   tree intermediate_type, prev_type;
   14760                 :       33108 :   machine_mode intermediate_mode, prev_mode;
   14761                 :       33108 :   int i;
   14762                 :       33108 :   unsigned HOST_WIDE_INT n_elts;
   14763                 :       33108 :   bool uns;
   14764                 :             : 
   14765                 :       33108 :   if (!code.is_tree_code ())
   14766                 :             :     return false;
   14767                 :             : 
   14768                 :       33108 :   *multi_step_cvt = 0;
   14769                 :       33108 :   switch ((tree_code) code)
   14770                 :             :     {
   14771                 :       32089 :     CASE_CONVERT:
   14772                 :       32089 :       c1 = VEC_PACK_TRUNC_EXPR;
   14773                 :       32089 :       if (VECTOR_BOOLEAN_TYPE_P (narrow_vectype)
   14774                 :        4723 :           && VECTOR_BOOLEAN_TYPE_P (vectype)
   14775                 :        4723 :           && SCALAR_INT_MODE_P (TYPE_MODE (vectype))
   14776                 :        1737 :           && TYPE_VECTOR_SUBPARTS (vectype).is_constant (&n_elts)
   14777                 :       33826 :           && n_elts < BITS_PER_UNIT)
   14778                 :             :         optab1 = vec_pack_sbool_trunc_optab;
   14779                 :             :       else
   14780                 :       31304 :         optab1 = optab_for_tree_code (c1, vectype, optab_default);
   14781                 :             :       break;
   14782                 :             : 
   14783                 :         823 :     case FIX_TRUNC_EXPR:
   14784                 :         823 :       c1 = VEC_PACK_FIX_TRUNC_EXPR;
   14785                 :             :       /* The signedness is determined from output operand.  */
   14786                 :         823 :       optab1 = optab_for_tree_code (c1, vectype_out, optab_default);
   14787                 :         823 :       break;
   14788                 :             : 
   14789                 :         196 :     case FLOAT_EXPR:
   14790                 :         196 :       c1 = VEC_PACK_FLOAT_EXPR;
   14791                 :         196 :       optab1 = optab_for_tree_code (c1, vectype, optab_default);
   14792                 :         196 :       break;
   14793                 :             : 
   14794                 :           0 :     default:
   14795                 :           0 :       gcc_unreachable ();
   14796                 :             :     }
   14797                 :             : 
   14798                 :       33108 :   if (!optab1)
   14799                 :             :     return false;
   14800                 :             : 
   14801                 :       33108 :   vec_mode = TYPE_MODE (vectype);
   14802                 :       33108 :   if ((icode1 = optab_handler (optab1, vec_mode)) == CODE_FOR_nothing)
   14803                 :             :     return false;
   14804                 :             : 
   14805                 :       28896 :   *code1 = c1;
   14806                 :             : 
   14807                 :       28896 :   if (insn_data[icode1].operand[0].mode == TYPE_MODE (narrow_vectype))
   14808                 :             :     {
   14809                 :       17952 :       if (!VECTOR_BOOLEAN_TYPE_P (vectype))
   14810                 :             :         return true;
   14811                 :             :       /* For scalar masks we may have different boolean
   14812                 :             :          vector types having the same QImode.  Thus we
   14813                 :             :          add additional check for elements number.  */
   14814                 :        3134 :       if (known_eq (TYPE_VECTOR_SUBPARTS (vectype) * 2,
   14815                 :             :                     TYPE_VECTOR_SUBPARTS (narrow_vectype)))
   14816                 :             :         return true;
   14817                 :             :     }
   14818                 :             : 
   14819                 :       10945 :   if (code == FLOAT_EXPR)
   14820                 :             :     return false;
   14821                 :             : 
   14822                 :             :   /* Check if it's a multi-step conversion that can be done using intermediate
   14823                 :             :      types.  */
   14824                 :       10945 :   prev_mode = vec_mode;
   14825                 :       10945 :   prev_type = vectype;
   14826                 :       10945 :   if (code == FIX_TRUNC_EXPR)
   14827                 :         172 :     uns = TYPE_UNSIGNED (vectype_out);
   14828                 :             :   else
   14829                 :       10773 :     uns = TYPE_UNSIGNED (vectype);
   14830                 :             : 
   14831                 :             :   /* For multi-step FIX_TRUNC_EXPR prefer signed floating to integer
   14832                 :             :      conversion over unsigned, as unsigned FIX_TRUNC_EXPR is often more
   14833                 :             :      costly than signed.  */
   14834                 :       10945 :   if (code == FIX_TRUNC_EXPR && uns)
   14835                 :             :     {
   14836                 :          76 :       enum insn_code icode2;
   14837                 :             : 
   14838                 :          76 :       intermediate_type
   14839                 :          76 :         = lang_hooks.types.type_for_mode (TYPE_MODE (vectype_out), 0);
   14840                 :          76 :       interm_optab
   14841                 :          76 :         = optab_for_tree_code (c1, intermediate_type, optab_default);
   14842                 :          76 :       if (interm_optab != unknown_optab
   14843                 :          76 :           && (icode2 = optab_handler (optab1, vec_mode)) != CODE_FOR_nothing
   14844                 :          76 :           && insn_data[icode1].operand[0].mode
   14845                 :          76 :              == insn_data[icode2].operand[0].mode)
   14846                 :             :         {
   14847                 :             :           uns = false;
   14848                 :             :           optab1 = interm_optab;
   14849                 :             :           icode1 = icode2;
   14850                 :             :         }
   14851                 :             :     }
   14852                 :             : 
   14853                 :             :   /* We assume here that there will not be more than MAX_INTERM_CVT_STEPS
   14854                 :             :      intermediate steps in promotion sequence.  We try
   14855                 :             :      MAX_INTERM_CVT_STEPS to get to NARROW_VECTYPE, and fail if we do not.  */
   14856                 :       10945 :   interm_types->create (MAX_INTERM_CVT_STEPS);
   14857                 :       23159 :   for (i = 0; i < MAX_INTERM_CVT_STEPS; i++)
   14858                 :             :     {
   14859                 :       12214 :       intermediate_mode = insn_data[icode1].operand[0].mode;
   14860                 :       12214 :       if (VECTOR_BOOLEAN_TYPE_P (prev_type))
   14861                 :        2029 :         intermediate_type
   14862                 :        2029 :           = vect_double_mask_nunits (prev_type, intermediate_mode);
   14863                 :             :       else
   14864                 :       10185 :         intermediate_type
   14865                 :       10185 :           = lang_hooks.types.type_for_mode (intermediate_mode, uns);
   14866                 :       12214 :       if (VECTOR_BOOLEAN_TYPE_P (intermediate_type)
   14867                 :        2029 :           && VECTOR_BOOLEAN_TYPE_P (prev_type)
   14868                 :        2029 :           && SCALAR_INT_MODE_P (prev_mode)
   14869                 :         769 :           && TYPE_VECTOR_SUBPARTS (intermediate_type).is_constant (&n_elts)
   14870                 :       12983 :           && n_elts < BITS_PER_UNIT)
   14871                 :             :         interm_optab = vec_pack_sbool_trunc_optab;
   14872                 :             :       else
   14873                 :       12173 :         interm_optab
   14874                 :       12173 :           = optab_for_tree_code (VEC_PACK_TRUNC_EXPR, intermediate_type,
   14875                 :             :                                  optab_default);
   14876                 :          41 :       if (!interm_optab
   14877                 :       12214 :           || ((icode1 = optab_handler (optab1, prev_mode)) == CODE_FOR_nothing)
   14878                 :       12214 :           || insn_data[icode1].operand[0].mode != intermediate_mode
   14879                 :       24387 :           || ((icode1 = optab_handler (interm_optab, intermediate_mode))
   14880                 :             :               == CODE_FOR_nothing))
   14881                 :             :         break;
   14882                 :             : 
   14883                 :       11684 :       interm_types->quick_push (intermediate_type);
   14884                 :       11684 :       (*multi_step_cvt)++;
   14885                 :             : 
   14886                 :       11684 :       if (insn_data[icode1].operand[0].mode == TYPE_MODE (narrow_vectype))
   14887                 :             :         {
   14888                 :       10415 :           if (!VECTOR_BOOLEAN_TYPE_P (vectype))
   14889                 :             :             return true;
   14890                 :        1010 :           if (known_eq (TYPE_VECTOR_SUBPARTS (intermediate_type) * 2,
   14891                 :             :                         TYPE_VECTOR_SUBPARTS (narrow_vectype)))
   14892                 :             :             return true;
   14893                 :             :         }
   14894                 :             : 
   14895                 :        1269 :       prev_mode = intermediate_mode;
   14896                 :        1269 :       prev_type = intermediate_type;
   14897                 :        1269 :       optab1 = interm_optab;
   14898                 :             :     }
   14899                 :             : 
   14900                 :         530 :   interm_types->release ();
   14901                 :         530 :   return false;
   14902                 :             : }
   14903                 :             : 
   14904                 :             : /* Function supportable_indirect_convert_operation
   14905                 :             : 
   14906                 :             :    Check whether an operation represented by the code CODE is single or multi
   14907                 :             :    operations that are supported by the target platform in
   14908                 :             :    vector form (i.e., when operating on arguments of type VECTYPE_IN
   14909                 :             :    producing a result of type VECTYPE_OUT).
   14910                 :             : 
   14911                 :             :    Convert operations we currently support directly are FIX_TRUNC and FLOAT.
   14912                 :             :    This function checks if these operations are supported
   14913                 :             :    by the target platform directly (via vector tree-codes).
   14914                 :             : 
   14915                 :             :    Output:
   14916                 :             :    - converts contains some pairs to perform the convert operation,
   14917                 :             :    the pair's first is the intermediate type, and its second is the code of
   14918                 :             :    a vector operation to be used when converting the operation from the
   14919                 :             :    previous type to the intermediate type. */
   14920                 :             : bool
   14921                 :       75209 : supportable_indirect_convert_operation (code_helper code,
   14922                 :             :                                         tree vectype_out,
   14923                 :             :                                         tree vectype_in,
   14924                 :             :                                         vec<std::pair<tree, tree_code> > &converts,
   14925                 :             :                                         tree op0, slp_tree slp_op0)
   14926                 :             : {
   14927                 :       75209 :   bool found_mode = false;
   14928                 :       75209 :   scalar_mode lhs_mode = GET_MODE_INNER (TYPE_MODE (vectype_out));
   14929                 :       75209 :   scalar_mode rhs_mode = GET_MODE_INNER (TYPE_MODE (vectype_in));
   14930                 :       75209 :   opt_scalar_mode mode_iter;
   14931                 :       75209 :   tree_code tc1, tc2, code1, code2;
   14932                 :             : 
   14933                 :       75209 :   tree cvt_type = NULL_TREE;
   14934                 :       75209 :   poly_uint64 nelts = TYPE_VECTOR_SUBPARTS (vectype_in);
   14935                 :             : 
   14936                 :       75209 :   if (supportable_convert_operation ((tree_code) code,
   14937                 :             :                                      vectype_out,
   14938                 :             :                                      vectype_in,
   14939                 :             :                                      &tc1))
   14940                 :             :     {
   14941                 :       18117 :       converts.safe_push (std::make_pair (vectype_out, tc1));
   14942                 :       18117 :       return true;
   14943                 :             :     }
   14944                 :             : 
   14945                 :             :   /* For conversions between float and integer types try whether
   14946                 :             :      we can use intermediate signed integer types to support the
   14947                 :             :      conversion.  */
   14948                 :      114184 :   if (GET_MODE_SIZE (lhs_mode) != GET_MODE_SIZE (rhs_mode)
   14949                 :       57092 :       && (code == FLOAT_EXPR
   14950                 :        3515 :           || (code == FIX_TRUNC_EXPR && !flag_trapping_math)))
   14951                 :             :     {
   14952                 :         380 :       bool demotion = GET_MODE_SIZE (rhs_mode) > GET_MODE_SIZE (lhs_mode);
   14953                 :         190 :       bool float_expr_p = code == FLOAT_EXPR;
   14954                 :         190 :       unsigned short target_size;
   14955                 :         190 :       scalar_mode intermediate_mode;
   14956                 :         190 :       if (demotion)
   14957                 :             :         {
   14958                 :          86 :           intermediate_mode = lhs_mode;
   14959                 :          86 :           target_size = GET_MODE_SIZE (rhs_mode);
   14960                 :             :         }
   14961                 :             :       else
   14962                 :             :         {
   14963                 :         104 :           target_size = GET_MODE_SIZE (lhs_mode);
   14964                 :         104 :           if (!int_mode_for_size
   14965                 :         104 :               (GET_MODE_BITSIZE (rhs_mode), 0).exists (&intermediate_mode))
   14966                 :         122 :             return false;
   14967                 :             :         }
   14968                 :         190 :       code1 = float_expr_p ? (tree_code) code : NOP_EXPR;
   14969                 :             :       code2 = float_expr_p ? NOP_EXPR : (tree_code) code;
   14970                 :         190 :       opt_scalar_mode mode_iter;
   14971                 :         294 :       FOR_EACH_2XWIDER_MODE (mode_iter, intermediate_mode)
   14972                 :             :         {
   14973                 :         294 :           intermediate_mode = mode_iter.require ();
   14974                 :             : 
   14975                 :         588 :           if (GET_MODE_SIZE (intermediate_mode) > target_size)
   14976                 :             :             break;
   14977                 :             : 
   14978                 :         266 :           scalar_mode cvt_mode;
   14979                 :         266 :           if (!int_mode_for_size
   14980                 :         266 :               (GET_MODE_BITSIZE (intermediate_mode), 0).exists (&cvt_mode))
   14981                 :             :             break;
   14982                 :             : 
   14983                 :         236 :           cvt_type = build_nonstandard_integer_type
   14984                 :         236 :             (GET_MODE_BITSIZE (cvt_mode), 0);
   14985                 :             : 
   14986                 :             :           /* Check if the intermediate type can hold OP0's range.
   14987                 :             :              When converting from float to integer this is not necessary
   14988                 :             :              because values that do not fit the (smaller) target type are
   14989                 :             :              unspecified anyway.  */
   14990                 :         236 :           if (demotion && float_expr_p)
   14991                 :             :             {
   14992                 :          10 :               wide_int op_min_value, op_max_value;
   14993                 :             :               /* For vector form, it looks like op0 doesn't have RANGE_INFO.
   14994                 :             :                  In the future, if it is supported, changes may need to be made
   14995                 :             :                  to this part, such as checking the RANGE of each element
   14996                 :             :                  in the vector.  */
   14997                 :          10 :               if (slp_op0)
   14998                 :             :                 {
   14999                 :           6 :                   tree def;
   15000                 :             :                   /* ???  Merge ranges in case of more than one lane.  */
   15001                 :           6 :                   if (SLP_TREE_LANES (slp_op0) != 1
   15002                 :           0 :                       || !(def = vect_get_slp_scalar_def (slp_op0, 0))
   15003                 :           6 :                       || !vect_get_range_info (def,
   15004                 :             :                                                &op_min_value, &op_max_value))
   15005                 :             :                     break;
   15006                 :             :                 }
   15007                 :           4 :               else if (!op0
   15008                 :           0 :                        || TREE_CODE (op0) != SSA_NAME
   15009                 :           0 :                        || !SSA_NAME_RANGE_INFO (op0)
   15010                 :           4 :                        || !vect_get_range_info (op0, &op_min_value,
   15011                 :             :                                                 &op_max_value))
   15012                 :             :                 break;
   15013                 :             : 
   15014                 :           0 :               if (cvt_type == NULL_TREE
   15015                 :           0 :                   || (wi::min_precision (op_max_value, SIGNED)
   15016                 :           0 :                       > TYPE_PRECISION (cvt_type))
   15017                 :           0 :                   || (wi::min_precision (op_min_value, SIGNED)
   15018                 :           0 :                       > TYPE_PRECISION (cvt_type)))
   15019                 :           0 :                 continue;
   15020                 :          10 :             }
   15021                 :             : 
   15022                 :         226 :           cvt_type = get_related_vectype_for_scalar_type (TYPE_MODE (vectype_in),
   15023                 :             :                                                           cvt_type,
   15024                 :             :                                                           nelts);
   15025                 :             :           /* This should only happened for SLP as long as loop vectorizer
   15026                 :             :              only supports same-sized vector.  */
   15027                 :         330 :           if (cvt_type == NULL_TREE
   15028                 :         348 :               || maybe_ne (TYPE_VECTOR_SUBPARTS (cvt_type), nelts)
   15029                 :         226 :               || !supportable_convert_operation ((tree_code) code1,
   15030                 :             :                                                  vectype_out,
   15031                 :             :                                                  cvt_type, &tc1)
   15032                 :         396 :               || !supportable_convert_operation ((tree_code) code2,
   15033                 :             :                                                  cvt_type,
   15034                 :             :                                                  vectype_in, &tc2))
   15035                 :         104 :             continue;
   15036                 :             : 
   15037                 :             :           found_mode = true;
   15038                 :             :           break;
   15039                 :             :         }
   15040                 :             : 
   15041                 :         190 :       if (found_mode)
   15042                 :             :         {
   15043                 :         122 :           converts.safe_push (std::make_pair (cvt_type, tc2));
   15044                 :         122 :           if (TYPE_MODE (cvt_type) != TYPE_MODE (vectype_out))
   15045                 :         122 :             converts.safe_push (std::make_pair (vectype_out, tc1));
   15046                 :         122 :           return true;
   15047                 :             :         }
   15048                 :             :     }
   15049                 :             :   return false;
   15050                 :             : }
   15051                 :             : 
   15052                 :             : /* Generate and return a vector mask of MASK_TYPE such that
   15053                 :             :    mask[I] is true iff J + START_INDEX < END_INDEX for all J <= I.
   15054                 :             :    Add the statements to SEQ.  */
   15055                 :             : 
   15056                 :             : tree
   15057                 :           0 : vect_gen_while (gimple_seq *seq, tree mask_type, tree start_index,
   15058                 :             :                 tree end_index, const char *name)
   15059                 :             : {
   15060                 :           0 :   tree cmp_type = TREE_TYPE (start_index);
   15061                 :           0 :   gcc_checking_assert (direct_internal_fn_supported_p (IFN_WHILE_ULT,
   15062                 :             :                                                        cmp_type, mask_type,
   15063                 :             :                                                        OPTIMIZE_FOR_SPEED));
   15064                 :           0 :   gcall *call = gimple_build_call_internal (IFN_WHILE_ULT, 3,
   15065                 :             :                                             start_index, end_index,
   15066                 :             :                                             build_zero_cst (mask_type));
   15067                 :           0 :   tree tmp;
   15068                 :           0 :   if (name)
   15069                 :           0 :     tmp = make_temp_ssa_name (mask_type, NULL, name);
   15070                 :             :   else
   15071                 :           0 :     tmp = make_ssa_name (mask_type);
   15072                 :           0 :   gimple_call_set_lhs (call, tmp);
   15073                 :           0 :   gimple_seq_add_stmt (seq, call);
   15074                 :           0 :   return tmp;
   15075                 :             : }
   15076                 :             : 
   15077                 :             : /* Generate a vector mask of type MASK_TYPE for which index I is false iff
   15078                 :             :    J + START_INDEX < END_INDEX for all J <= I.  Add the statements to SEQ.  */
   15079                 :             : 
   15080                 :             : tree
   15081                 :           0 : vect_gen_while_not (gimple_seq *seq, tree mask_type, tree start_index,
   15082                 :             :                     tree end_index)
   15083                 :             : {
   15084                 :           0 :   tree tmp = vect_gen_while (seq, mask_type, start_index, end_index);
   15085                 :           0 :   return gimple_build (seq, BIT_NOT_EXPR, mask_type, tmp);
   15086                 :             : }
   15087                 :             : 
   15088                 :             : /* Try to compute the vector types required to vectorize STMT_INFO,
   15089                 :             :    returning true on success and false if vectorization isn't possible.
   15090                 :             :    If GROUP_SIZE is nonzero and we're performing BB vectorization,
   15091                 :             :    take sure that the number of elements in the vectors is no bigger
   15092                 :             :    than GROUP_SIZE.
   15093                 :             : 
   15094                 :             :    On success:
   15095                 :             : 
   15096                 :             :    - Set *STMT_VECTYPE_OUT to:
   15097                 :             :      - NULL_TREE if the statement doesn't need to be vectorized;
   15098                 :             :      - the equivalent of STMT_VINFO_VECTYPE otherwise.
   15099                 :             : 
   15100                 :             :    - Set *NUNITS_VECTYPE_OUT to the vector type that contains the maximum
   15101                 :             :      number of units needed to vectorize STMT_INFO, or NULL_TREE if the
   15102                 :             :      statement does not help to determine the overall number of units.  */
   15103                 :             : 
   15104                 :             : opt_result
   15105                 :     7280941 : vect_get_vector_types_for_stmt (vec_info *vinfo, stmt_vec_info stmt_info,
   15106                 :             :                                 tree *stmt_vectype_out,
   15107                 :             :                                 tree *nunits_vectype_out,
   15108                 :             :                                 unsigned int group_size)
   15109                 :             : {
   15110                 :     7280941 :   gimple *stmt = stmt_info->stmt;
   15111                 :             : 
   15112                 :             :   /* For BB vectorization, we should always have a group size once we've
   15113                 :             :      constructed the SLP tree; the only valid uses of zero GROUP_SIZEs
   15114                 :             :      are tentative requests during things like early data reference
   15115                 :             :      analysis and pattern recognition.  */
   15116                 :     7280941 :   if (is_a <bb_vec_info> (vinfo))
   15117                 :     4622682 :     gcc_assert (vinfo->slp_instances.is_empty () || group_size != 0);
   15118                 :             :   else
   15119                 :             :     group_size = 0;
   15120                 :             : 
   15121                 :     7280941 :   *stmt_vectype_out = NULL_TREE;
   15122                 :     7280941 :   *nunits_vectype_out = NULL_TREE;
   15123                 :             : 
   15124                 :     7280941 :   if (gimple_get_lhs (stmt) == NULL_TREE
   15125                 :             :       /* Allow vector conditionals through here.  */
   15126                 :      127885 :       && !is_a <gcond *> (stmt)
   15127                 :             :       /* MASK_STORE and friends have no lhs, but are ok.  */
   15128                 :     7287038 :       && !(is_gimple_call (stmt)
   15129                 :        2975 :            && gimple_call_internal_p (stmt)
   15130                 :        2949 :            && internal_store_fn_p (gimple_call_internal_fn (stmt))))
   15131                 :             :     {
   15132                 :         199 :       if (is_a <gcall *> (stmt))
   15133                 :             :         {
   15134                 :             :           /* Ignore calls with no lhs.  These must be calls to
   15135                 :             :              #pragma omp simd functions, and what vectorization factor
   15136                 :             :              it really needs can't be determined until
   15137                 :             :              vectorizable_simd_clone_call.  */
   15138                 :          26 :           if (dump_enabled_p ())
   15139                 :          24 :             dump_printf_loc (MSG_NOTE, vect_location,
   15140                 :             :                              "defer to SIMD clone analysis.\n");
   15141                 :          26 :           return opt_result::success ();
   15142                 :             :         }
   15143                 :             : 
   15144                 :         173 :       return opt_result::failure_at (stmt,
   15145                 :             :                                      "not vectorized: irregular stmt: %G", stmt);
   15146                 :             :     }
   15147                 :             : 
   15148                 :     7280742 :   tree vectype;
   15149                 :     7280742 :   tree scalar_type = NULL_TREE;
   15150                 :     7280742 :   if (group_size == 0 && STMT_VINFO_VECTYPE (stmt_info))
   15151                 :             :     {
   15152                 :     3539526 :       vectype = STMT_VINFO_VECTYPE (stmt_info);
   15153                 :     3539526 :       if (dump_enabled_p ())
   15154                 :      231122 :         dump_printf_loc (MSG_NOTE, vect_location,
   15155                 :             :                          "precomputed vectype: %T\n", vectype);
   15156                 :             :     }
   15157                 :     3741216 :   else if (vect_use_mask_type_p (stmt_info))
   15158                 :             :     {
   15159                 :      174742 :       unsigned int precision = stmt_info->mask_precision;
   15160                 :      174742 :       scalar_type = build_nonstandard_integer_type (precision, 1);
   15161                 :      174742 :       vectype = get_mask_type_for_scalar_type (vinfo, scalar_type, group_size);
   15162                 :      174742 :       if (!vectype)
   15163                 :           0 :         return opt_result::failure_at (stmt, "not vectorized: unsupported"
   15164                 :             :                                        " data-type %T\n", scalar_type);
   15165                 :      174742 :       if (dump_enabled_p ())
   15166                 :        3994 :         dump_printf_loc (MSG_NOTE, vect_location, "vectype: %T\n", vectype);
   15167                 :             :     }
   15168                 :             :   else
   15169                 :             :     {
   15170                 :             :       /* If we got here with a gcond it means that the target had no available vector
   15171                 :             :          mode for the scalar type.  We can't vectorize so abort.  */
   15172                 :     3566474 :       if (is_a <gcond *> (stmt))
   15173                 :          36 :         return opt_result::failure_at (stmt,
   15174                 :             :                                        "not vectorized:"
   15175                 :             :                                        " unsupported data-type for gcond %T\n",
   15176                 :             :                                        scalar_type);
   15177                 :             : 
   15178                 :     3566438 :       if (data_reference *dr = STMT_VINFO_DATA_REF (stmt_info))
   15179                 :     1473130 :         scalar_type = TREE_TYPE (DR_REF (dr));
   15180                 :             :       else
   15181                 :     2093308 :         scalar_type = TREE_TYPE (gimple_get_lhs (stmt));
   15182                 :             : 
   15183                 :     3566438 :       if (dump_enabled_p ())
   15184                 :             :         {
   15185                 :       53997 :           if (group_size)
   15186                 :        7515 :             dump_printf_loc (MSG_NOTE, vect_location,
   15187                 :             :                              "get vectype for scalar type (group size %d):"
   15188                 :             :                              " %T\n", group_size, scalar_type);
   15189                 :             :           else
   15190                 :       46482 :             dump_printf_loc (MSG_NOTE, vect_location,
   15191                 :             :                              "get vectype for scalar type: %T\n", scalar_type);
   15192                 :             :         }
   15193                 :     3566438 :       vectype = get_vectype_for_scalar_type (vinfo, scalar_type, group_size);
   15194                 :     3566438 :       if (!vectype)
   15195                 :      188534 :         return opt_result::failure_at (stmt,
   15196                 :             :                                        "not vectorized:"
   15197                 :             :                                        " unsupported data-type %T\n",
   15198                 :             :                                        scalar_type);
   15199                 :             : 
   15200                 :     3377904 :       if (dump_enabled_p ())
   15201                 :       53829 :         dump_printf_loc (MSG_NOTE, vect_location, "vectype: %T\n", vectype);
   15202                 :             :     }
   15203                 :             : 
   15204                 :     3783768 :   if (scalar_type && VECTOR_MODE_P (TYPE_MODE (scalar_type)))
   15205                 :           0 :     return opt_result::failure_at (stmt,
   15206                 :             :                                    "not vectorized: vector stmt in loop:%G",
   15207                 :             :                                    stmt);
   15208                 :             : 
   15209                 :     7092172 :   *stmt_vectype_out = vectype;
   15210                 :             : 
   15211                 :             :   /* Don't try to compute scalar types if the stmt produces a boolean
   15212                 :             :      vector; use the existing vector type instead.  */
   15213                 :     7092172 :   tree nunits_vectype = vectype;
   15214                 :     7092172 :   if (!VECTOR_BOOLEAN_TYPE_P (vectype))
   15215                 :             :     {
   15216                 :             :       /* The number of units is set according to the smallest scalar
   15217                 :             :          type (or the largest vector size, but we only support one
   15218                 :             :          vector size per vectorization).  */
   15219                 :     6352012 :       scalar_type = vect_get_smallest_scalar_type (stmt_info,
   15220                 :     6352012 :                                                    TREE_TYPE (vectype));
   15221                 :     6352012 :       if (!types_compatible_p (scalar_type, TREE_TYPE (vectype)))
   15222                 :             :         {
   15223                 :     1125155 :           if (dump_enabled_p ())
   15224                 :       19482 :             dump_printf_loc (MSG_NOTE, vect_location,
   15225                 :             :                              "get vectype for smallest scalar type: %T\n",
   15226                 :             :                              scalar_type);
   15227                 :     1125155 :           nunits_vectype = get_vectype_for_scalar_type (vinfo, scalar_type,
   15228                 :             :                                                         group_size);
   15229                 :     1125155 :           if (!nunits_vectype)
   15230                 :           7 :             return opt_result::failure_at
   15231                 :           7 :               (stmt, "not vectorized: unsupported data-type %T\n",
   15232                 :             :                scalar_type);
   15233                 :     1125148 :           if (dump_enabled_p ())
   15234                 :       19482 :             dump_printf_loc (MSG_NOTE, vect_location, "nunits vectype: %T\n",
   15235                 :             :                              nunits_vectype);
   15236                 :             :         }
   15237                 :             :     }
   15238                 :             : 
   15239                 :     7092165 :   if (!multiple_p (TYPE_VECTOR_SUBPARTS (nunits_vectype),
   15240                 :     7092165 :                    TYPE_VECTOR_SUBPARTS (*stmt_vectype_out)))
   15241                 :           0 :     return opt_result::failure_at (stmt,
   15242                 :             :                                    "Not vectorized: Incompatible number "
   15243                 :             :                                    "of vector subparts between %T and %T\n",
   15244                 :             :                                    nunits_vectype, *stmt_vectype_out);
   15245                 :             : 
   15246                 :     7092165 :   if (dump_enabled_p ())
   15247                 :             :     {
   15248                 :      288945 :       dump_printf_loc (MSG_NOTE, vect_location, "nunits = ");
   15249                 :      288945 :       dump_dec (MSG_NOTE, TYPE_VECTOR_SUBPARTS (nunits_vectype));
   15250                 :      288945 :       dump_printf (MSG_NOTE, "\n");
   15251                 :             :     }
   15252                 :             : 
   15253                 :     7092165 :   *nunits_vectype_out = nunits_vectype;
   15254                 :     7092165 :   return opt_result::success ();
   15255                 :             : }
   15256                 :             : 
   15257                 :             : /* Generate and return statement sequence that sets vector length LEN that is:
   15258                 :             : 
   15259                 :             :    min_of_start_and_end = min (START_INDEX, END_INDEX);
   15260                 :             :    left_len = END_INDEX - min_of_start_and_end;
   15261                 :             :    rhs = min (left_len, LEN_LIMIT);
   15262                 :             :    LEN = rhs;
   15263                 :             : 
   15264                 :             :    Note: the cost of the code generated by this function is modeled
   15265                 :             :    by vect_estimate_min_profitable_iters, so changes here may need
   15266                 :             :    corresponding changes there.  */
   15267                 :             : 
   15268                 :             : gimple_seq
   15269                 :           0 : vect_gen_len (tree len, tree start_index, tree end_index, tree len_limit)
   15270                 :             : {
   15271                 :           0 :   gimple_seq stmts = NULL;
   15272                 :           0 :   tree len_type = TREE_TYPE (len);
   15273                 :           0 :   gcc_assert (TREE_TYPE (start_index) == len_type);
   15274                 :             : 
   15275                 :           0 :   tree min = gimple_build (&stmts, MIN_EXPR, len_type, start_index, end_index);
   15276                 :           0 :   tree left_len = gimple_build (&stmts, MINUS_EXPR, len_type, end_index, min);
   15277                 :           0 :   tree rhs = gimple_build (&stmts, MIN_EXPR, len_type, left_len, len_limit);
   15278                 :           0 :   gimple* stmt = gimple_build_assign (len, rhs);
   15279                 :           0 :   gimple_seq_add_stmt (&stmts, stmt);
   15280                 :             : 
   15281                 :           0 :   return stmts;
   15282                 :             : }
   15283                 :             : 
        

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.