LCOV - code coverage report
Current view: top level - gcc - tree-vect-stmts.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 79.9 % 7240 5786
Test Date: 2026-03-28 14:25:54 Functions: 89.7 % 107 96
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* Statement Analysis and Transformation for Vectorization
       2              :    Copyright (C) 2003-2026 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              : static tree vector_vector_composition_type (tree, poly_uint64, tree *,
      66              :                                             bool = false);
      67              : 
      68              : /* Return TRUE iff the given statement is in an inner loop relative to
      69              :    the loop being vectorized.  */
      70              : bool
      71      3823896 : stmt_in_inner_loop_p (vec_info *vinfo, class _stmt_vec_info *stmt_info)
      72              : {
      73      3823896 :   gimple *stmt = STMT_VINFO_STMT (stmt_info);
      74      3823896 :   basic_block bb = gimple_bb (stmt);
      75      3823896 :   loop_vec_info loop_vinfo = dyn_cast <loop_vec_info> (vinfo);
      76       785694 :   class loop* loop;
      77              : 
      78       785694 :   if (!loop_vinfo)
      79              :     return false;
      80              : 
      81       785694 :   loop = LOOP_VINFO_LOOP (loop_vinfo);
      82              : 
      83       785694 :   return (bb->loop_father == loop->inner);
      84              : }
      85              : 
      86              : /* Record the cost of a statement, either by directly informing the
      87              :    target model or by saving it in a vector for later processing.
      88              :    Return a preliminary estimate of the statement's cost.  */
      89              : 
      90              : unsigned
      91      9257276 : record_stmt_cost (stmt_vector_for_cost *body_cost_vec, int count,
      92              :                   enum vect_cost_for_stmt kind,
      93              :                   stmt_vec_info stmt_info, slp_tree node,
      94              :                   tree vectype, int misalign,
      95              :                   enum vect_cost_model_location where)
      96              : {
      97      9257276 :   if ((kind == vector_load || kind == unaligned_load)
      98      1354748 :       && (stmt_info && STMT_VINFO_GATHER_SCATTER_P (stmt_info)))
      99              :     kind = vector_gather_load;
     100      9257276 :   if ((kind == vector_store || kind == unaligned_store)
     101       904203 :       && (stmt_info && STMT_VINFO_GATHER_SCATTER_P (stmt_info)))
     102      9257276 :     kind = vector_scatter_store;
     103              : 
     104      9257276 :   stmt_info_for_cost si
     105      9257276 :     = { count, kind, where, stmt_info, node, vectype, misalign };
     106      9257276 :   body_cost_vec->safe_push (si);
     107              : 
     108      9257276 :   return (unsigned)
     109      9257276 :       (builtin_vectorization_cost (kind, vectype, misalign) * count);
     110              : }
     111              : 
     112              : unsigned
     113      4864480 : record_stmt_cost (stmt_vector_for_cost *body_cost_vec, int count,
     114              :                   enum vect_cost_for_stmt kind, stmt_vec_info stmt_info,
     115              :                   tree vectype, int misalign,
     116              :                   enum vect_cost_model_location where)
     117              : {
     118      4864480 :   return record_stmt_cost (body_cost_vec, count, kind, stmt_info, NULL,
     119      4864480 :                            vectype, misalign, where);
     120              : }
     121              : 
     122              : unsigned
     123      1514167 : record_stmt_cost (stmt_vector_for_cost *body_cost_vec, int count,
     124              :                   enum vect_cost_for_stmt kind, slp_tree node,
     125              :                   tree vectype, int misalign,
     126              :                   enum vect_cost_model_location where)
     127              : {
     128      1514167 :   return record_stmt_cost (body_cost_vec, count, kind,
     129              :                            SLP_TREE_REPRESENTATIVE (node), node,
     130      1514167 :                            vectype, misalign, where);
     131              : }
     132              : 
     133              : unsigned
     134       177382 : record_stmt_cost (stmt_vector_for_cost *body_cost_vec, int count,
     135              :                   enum vect_cost_for_stmt kind,
     136              :                   enum vect_cost_model_location where)
     137              : {
     138       177382 :   gcc_assert (kind == cond_branch_taken || kind == cond_branch_not_taken
     139              :               || kind == scalar_stmt);
     140       177382 :   return record_stmt_cost (body_cost_vec, count, kind, NULL, NULL,
     141       177382 :                            NULL_TREE, 0, where);
     142              : }
     143              : 
     144              : /* Return a variable of type ELEM_TYPE[NELEMS].  */
     145              : 
     146              : static tree
     147            0 : create_vector_array (tree elem_type, unsigned HOST_WIDE_INT nelems)
     148              : {
     149            0 :   return create_tmp_var (build_array_type_nelts (elem_type, nelems),
     150            0 :                          "vect_array");
     151              : }
     152              : 
     153              : /* ARRAY is an array of vectors created by create_vector_array.
     154              :    Return an SSA_NAME for the vector in index N.  The reference
     155              :    is part of the vectorization of STMT_INFO and the vector is associated
     156              :    with scalar destination SCALAR_DEST.
     157              :    If we need to ensure that inactive elements are set to zero,
     158              :    NEED_ZEROING is true, MASK contains the loop mask to be used.  */
     159              : 
     160              : static tree
     161            0 : read_vector_array (vec_info *vinfo,
     162              :                    stmt_vec_info stmt_info, gimple_stmt_iterator *gsi,
     163              :                    tree scalar_dest, tree array, unsigned HOST_WIDE_INT n,
     164              :                    bool need_zeroing, tree mask)
     165              : {
     166            0 :   tree vect_type, vect, vect_name, tmp, tmp_name, array_ref;
     167            0 :   gimple *new_stmt;
     168              : 
     169            0 :   gcc_assert (TREE_CODE (TREE_TYPE (array)) == ARRAY_TYPE);
     170            0 :   vect_type = TREE_TYPE (TREE_TYPE (array));
     171            0 :   tmp = vect_create_destination_var (scalar_dest, vect_type);
     172            0 :   vect = vect_create_destination_var (scalar_dest, vect_type);
     173            0 :   array_ref = build4 (ARRAY_REF, vect_type, array,
     174            0 :                       build_int_cst (size_type_node, n),
     175              :                       NULL_TREE, NULL_TREE);
     176              : 
     177            0 :   new_stmt = gimple_build_assign (tmp, array_ref);
     178            0 :   tmp_name = make_ssa_name (vect, new_stmt);
     179            0 :   gimple_assign_set_lhs (new_stmt, tmp_name);
     180            0 :   vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
     181              : 
     182            0 :   if (need_zeroing)
     183              :     {
     184            0 :       tree vec_els = vect_get_mask_load_else (MASK_LOAD_ELSE_ZERO,
     185              :                                               vect_type);
     186            0 :       vect_name = make_ssa_name (vect, new_stmt);
     187            0 :       new_stmt
     188            0 :         = gimple_build_assign (vect_name, VEC_COND_EXPR,
     189              :                                mask, tmp_name, vec_els);
     190            0 :       vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
     191              :     }
     192              :   else
     193              :     vect_name = tmp_name;
     194              : 
     195            0 :   return vect_name;
     196              : }
     197              : 
     198              : /* ARRAY is an array of vectors created by create_vector_array.
     199              :    Emit code to store SSA_NAME VECT in index N of the array.
     200              :    The store is part of the vectorization of STMT_INFO.  */
     201              : 
     202              : static void
     203            0 : write_vector_array (vec_info *vinfo,
     204              :                     stmt_vec_info stmt_info, gimple_stmt_iterator *gsi,
     205              :                     tree vect, tree array, unsigned HOST_WIDE_INT n)
     206              : {
     207            0 :   tree array_ref;
     208            0 :   gimple *new_stmt;
     209              : 
     210            0 :   array_ref = build4 (ARRAY_REF, TREE_TYPE (vect), array,
     211            0 :                       build_int_cst (size_type_node, n),
     212              :                       NULL_TREE, NULL_TREE);
     213              : 
     214            0 :   new_stmt = gimple_build_assign (array_ref, vect);
     215            0 :   vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
     216            0 : }
     217              : 
     218              : /* PTR is a pointer to an array of type TYPE.  Return a representation
     219              :    of *PTR.  The memory reference replaces those in FIRST_DR
     220              :    (and its group).  */
     221              : 
     222              : static tree
     223            0 : create_array_ref (tree type, tree ptr, tree alias_ptr_type)
     224              : {
     225            0 :   tree mem_ref;
     226              : 
     227            0 :   mem_ref = build2 (MEM_REF, type, ptr, build_int_cst (alias_ptr_type, 0));
     228              :   /* Arrays have the same alignment as their type.  */
     229            0 :   set_ptr_info_alignment (get_ptr_info (ptr), TYPE_ALIGN_UNIT (type), 0);
     230            0 :   return mem_ref;
     231              : }
     232              : 
     233              : /* Add a clobber of variable VAR to the vectorization of STMT_INFO.
     234              :    Emit the clobber before *GSI.  */
     235              : 
     236              : static void
     237           15 : vect_clobber_variable (vec_info *vinfo, stmt_vec_info stmt_info,
     238              :                        gimple_stmt_iterator *gsi, tree var)
     239              : {
     240           15 :   tree clobber = build_clobber (TREE_TYPE (var));
     241           15 :   gimple *new_stmt = gimple_build_assign (var, clobber);
     242           15 :   vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
     243           15 : }
     244              : 
     245              : /* Utility functions used by vect_mark_stmts_to_be_vectorized.  */
     246              : 
     247              : /* Function vect_mark_relevant.
     248              : 
     249              :    Mark STMT_INFO as "relevant for vectorization" and add it to WORKLIST.  */
     250              : 
     251              : static void
     252      2762676 : vect_mark_relevant (vec<stmt_vec_info> *worklist, stmt_vec_info stmt_info,
     253              :                     enum vect_relevant relevant, bool live_p)
     254              : {
     255      2762676 :   enum vect_relevant save_relevant = STMT_VINFO_RELEVANT (stmt_info);
     256      2762676 :   bool save_live_p = STMT_VINFO_LIVE_P (stmt_info);
     257              : 
     258      2762676 :   if (dump_enabled_p ())
     259       159761 :     dump_printf_loc (MSG_NOTE, vect_location,
     260              :                      "mark relevant %d, live %d: %G", relevant, live_p,
     261              :                      stmt_info->stmt);
     262              : 
     263              :   /* If this stmt is an original stmt in a pattern, we might need to mark its
     264              :      related pattern stmt instead of the original stmt.  However, such stmts
     265              :      may have their own uses that are not in any pattern, in such cases the
     266              :      stmt itself should be marked.  */
     267      2762676 :   if (STMT_VINFO_IN_PATTERN_P (stmt_info))
     268              :     {
     269              :       /* This is the last stmt in a sequence that was detected as a
     270              :          pattern that can potentially be vectorized.  Don't mark the stmt
     271              :          as relevant/live because it's not going to be vectorized.
     272              :          Instead mark the pattern-stmt that replaces it.  */
     273              : 
     274       241306 :       if (dump_enabled_p ())
     275         2711 :         dump_printf_loc (MSG_NOTE, vect_location,
     276              :                          "last stmt in pattern. don't mark"
     277              :                          " relevant/live.\n");
     278              : 
     279       241306 :       stmt_vec_info old_stmt_info = stmt_info;
     280       241306 :       stmt_info = STMT_VINFO_RELATED_STMT (stmt_info);
     281       241306 :       gcc_assert (STMT_VINFO_RELATED_STMT (stmt_info) == old_stmt_info);
     282       241306 :       save_relevant = STMT_VINFO_RELEVANT (stmt_info);
     283       241306 :       save_live_p = STMT_VINFO_LIVE_P (stmt_info);
     284              : 
     285       241306 :       if (live_p && relevant == vect_unused_in_scope)
     286              :         {
     287          122 :           if (dump_enabled_p ())
     288           10 :             dump_printf_loc (MSG_NOTE, vect_location,
     289              :                              "vec_stmt_relevant_p: forcing live pattern stmt "
     290              :                              "relevant.\n");
     291              :           relevant = vect_used_only_live;
     292              :         }
     293              : 
     294       241306 :       if (dump_enabled_p ())
     295         2711 :         dump_printf_loc (MSG_NOTE, vect_location,
     296              :                          "mark relevant %d, live %d: %G", relevant, live_p,
     297              :                          stmt_info->stmt);
     298              :     }
     299              : 
     300      2762676 :   STMT_VINFO_LIVE_P (stmt_info) |= live_p;
     301      2762676 :   if (relevant > STMT_VINFO_RELEVANT (stmt_info))
     302      2498857 :     STMT_VINFO_RELEVANT (stmt_info) = relevant;
     303              : 
     304      2762676 :   if (STMT_VINFO_RELEVANT (stmt_info) == save_relevant
     305       263819 :       && STMT_VINFO_LIVE_P (stmt_info) == save_live_p)
     306              :     {
     307       263103 :       if (dump_enabled_p ())
     308        19145 :         dump_printf_loc (MSG_NOTE, vect_location,
     309              :                          "already marked relevant/live.\n");
     310       263103 :       return;
     311              :     }
     312              : 
     313      2499573 :   worklist->safe_push (stmt_info);
     314              : }
     315              : 
     316              : 
     317              : /* Function is_simple_and_all_uses_invariant
     318              : 
     319              :    Return true if STMT_INFO is simple and all uses of it are invariant.  */
     320              : 
     321              : bool
     322       226309 : is_simple_and_all_uses_invariant (stmt_vec_info stmt_info,
     323              :                                   loop_vec_info loop_vinfo)
     324              : {
     325       226309 :   tree op;
     326       226309 :   ssa_op_iter iter;
     327              : 
     328       399871 :   gassign *stmt = dyn_cast <gassign *> (stmt_info->stmt);
     329       174400 :   if (!stmt)
     330              :     return false;
     331              : 
     332       181944 :   FOR_EACH_SSA_TREE_OPERAND (op, stmt, iter, SSA_OP_USE)
     333              :     {
     334       181106 :       enum vect_def_type dt = vect_uninitialized_def;
     335              : 
     336       181106 :       if (!vect_is_simple_use (op, loop_vinfo, &dt))
     337              :         {
     338         5626 :           if (dump_enabled_p ())
     339           16 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
     340              :                              "use not simple.\n");
     341       173562 :           return false;
     342              :         }
     343              : 
     344       175480 :       if (dt != vect_external_def && dt != vect_constant_def)
     345              :         return false;
     346              :     }
     347              :   return true;
     348              : }
     349              : 
     350              : /* Function vect_stmt_relevant_p.
     351              : 
     352              :    Return true if STMT_INFO, in the loop that is represented by LOOP_VINFO,
     353              :    is "relevant for vectorization".
     354              : 
     355              :    A stmt is considered "relevant for vectorization" if:
     356              :    - it has uses outside the loop.
     357              :    - it has vdefs (it alters memory).
     358              :    - control stmts in the loop (except for the exit condition).
     359              : 
     360              :    CHECKME: what other side effects would the vectorizer allow?  */
     361              : 
     362              : static bool
     363      4343582 : vect_stmt_relevant_p (stmt_vec_info stmt_info, loop_vec_info loop_vinfo,
     364              :                       enum vect_relevant *relevant, bool *live_p)
     365              : {
     366      4343582 :   class loop *loop = LOOP_VINFO_LOOP (loop_vinfo);
     367      4343582 :   ssa_op_iter op_iter;
     368      4343582 :   imm_use_iterator imm_iter;
     369      4343582 :   use_operand_p use_p;
     370      4343582 :   def_operand_p def_p;
     371              : 
     372      4343582 :   *relevant = vect_unused_in_scope;
     373      4343582 :   *live_p = false;
     374              : 
     375              :   /* cond stmt other than loop exit cond.  */
     376      4343582 :   gimple *stmt = STMT_VINFO_STMT (stmt_info);
     377      4343582 :   if (is_ctrl_stmt (stmt)
     378       542234 :       && LOOP_VINFO_LOOP_IV_COND (loop_vinfo) != stmt
     379      4574671 :       && (!loop->inner || gimple_bb (stmt)->loop_father == loop))
     380       229358 :     *relevant = vect_used_in_scope;
     381              : 
     382              :   /* changing memory.  */
     383      4343582 :   if (gimple_code (stmt_info->stmt) != GIMPLE_PHI)
     384      3604578 :     if (gimple_vdef (stmt_info->stmt)
     385      3062344 :         && !gimple_clobber_p (stmt_info->stmt))
     386              :       {
     387       293792 :         if (dump_enabled_p ())
     388        27202 :           dump_printf_loc (MSG_NOTE, vect_location,
     389              :                            "vec_stmt_relevant_p: stmt has vdefs.\n");
     390       293792 :         *relevant = vect_used_in_scope;
     391       293792 :         if (! STMT_VINFO_DATA_REF (stmt_info)
     392       293792 :             && zero_ssa_operands (stmt_info->stmt, SSA_OP_DEF))
     393           20 :           LOOP_VINFO_ALTERNATE_DEFS (loop_vinfo).safe_push (stmt_info);
     394              :       }
     395              : 
     396              :   /* uses outside the loop.  */
     397     12188340 :   FOR_EACH_PHI_OR_STMT_DEF (def_p, stmt_info->stmt, op_iter, SSA_OP_DEF)
     398              :     {
     399     12973872 :       FOR_EACH_IMM_USE_FAST (use_p, imm_iter, DEF_FROM_PTR (def_p))
     400              :         {
     401      5971520 :           basic_block bb = gimple_bb (USE_STMT (use_p));
     402      5971520 :           if (!flow_bb_inside_loop_p (loop, bb))
     403              :             {
     404       242675 :               if (is_gimple_debug (USE_STMT (use_p)))
     405         1081 :                 continue;
     406              : 
     407       241594 :               if (dump_enabled_p ())
     408         5778 :                 dump_printf_loc (MSG_NOTE, vect_location,
     409              :                                  "vec_stmt_relevant_p: used out of loop.\n");
     410              : 
     411              :               /* We expect all such uses to be in the loop exit phis
     412              :                  (because of loop closed form)   */
     413       241594 :               gcc_assert (gimple_code (USE_STMT (use_p)) == GIMPLE_PHI);
     414              : 
     415       241594 :               *live_p = true;
     416              :             }
     417      3501176 :         }
     418              :     }
     419              : 
     420       226311 :   if (*live_p && *relevant == vect_unused_in_scope
     421      4569891 :       && !is_simple_and_all_uses_invariant (stmt_info, loop_vinfo))
     422              :     {
     423       225471 :       if (dump_enabled_p ())
     424         5638 :         dump_printf_loc (MSG_NOTE, vect_location,
     425              :                          "vec_stmt_relevant_p: stmt live but not relevant.\n");
     426       225471 :       *relevant = vect_used_only_live;
     427              :     }
     428              : 
     429      4343582 :   return (*live_p || *relevant);
     430              : }
     431              : 
     432              : 
     433              : /* Function exist_non_indexing_operands_for_use_p
     434              : 
     435              :    USE is one of the uses attached to STMT_INFO.  Check if USE is
     436              :    used in STMT_INFO for anything other than indexing an array.  */
     437              : 
     438              : static bool
     439      3686978 : exist_non_indexing_operands_for_use_p (tree use, stmt_vec_info stmt_info)
     440              : {
     441      3686978 :   tree operand;
     442              : 
     443              :   /* USE corresponds to some operand in STMT.  If there is no data
     444              :      reference in STMT, then any operand that corresponds to USE
     445              :      is not indexing an array.  */
     446      3686978 :   if (!STMT_VINFO_DATA_REF (stmt_info))
     447              :     return true;
     448              : 
     449              :   /* STMT has a data_ref. FORNOW this means that its of one of
     450              :      the following forms:
     451              :      -1- ARRAY_REF = var
     452              :      -2- var = ARRAY_REF
     453              :      (This should have been verified in analyze_data_refs).
     454              : 
     455              :      'var' in the second case corresponds to a def, not a use,
     456              :      so USE cannot correspond to any operands that are not used
     457              :      for array indexing.
     458              : 
     459              :      Therefore, all we need to check is if STMT falls into the
     460              :      first case, and whether var corresponds to USE.  */
     461              : 
     462      1214074 :   gassign *assign = dyn_cast <gassign *> (stmt_info->stmt);
     463      1200257 :   if (!assign || !gimple_assign_copy_p (assign))
     464              :     {
     465       679039 :       gcall *call = dyn_cast <gcall *> (stmt_info->stmt);
     466        13817 :       if (call && gimple_call_internal_p (call))
     467              :         {
     468        13817 :           internal_fn ifn = gimple_call_internal_fn (call);
     469        13817 :           int mask_index = internal_fn_mask_index (ifn);
     470        13817 :           if (mask_index >= 0
     471        13817 :               && use == gimple_call_arg (call, mask_index))
     472              :             return true;
     473         9057 :           int els_index = internal_fn_else_index (ifn);
     474         9057 :           if (els_index >= 0
     475         9057 :               && use == gimple_call_arg (call, els_index))
     476              :             return true;
     477         7755 :           int stored_value_index = internal_fn_stored_value_index (ifn);
     478         7755 :           if (stored_value_index >= 0
     479         7755 :               && use == gimple_call_arg (call, stored_value_index))
     480              :             return true;
     481         6258 :           if (internal_gather_scatter_fn_p (ifn)
     482         6258 :               && use == gimple_call_arg (call, 1))
     483              :             return true;
     484              :         }
     485       671480 :       return false;
     486              :     }
     487              : 
     488       535035 :   if (TREE_CODE (gimple_assign_lhs (assign)) == SSA_NAME)
     489              :     return false;
     490       535035 :   operand = gimple_assign_rhs1 (assign);
     491       535035 :   if (TREE_CODE (operand) != SSA_NAME)
     492              :     return false;
     493              : 
     494       464573 :   if (operand == use)
     495              :     return true;
     496              : 
     497              :   return false;
     498              : }
     499              : 
     500              : 
     501              : /*
     502              :    Function process_use.
     503              : 
     504              :    Inputs:
     505              :    - a USE in STMT_VINFO in a loop represented by LOOP_VINFO
     506              :    - RELEVANT - enum value to be set in the STMT_VINFO of the stmt
     507              :      that defined USE.  This is done by calling mark_relevant and passing it
     508              :      the WORKLIST (to add DEF_STMT to the WORKLIST in case it is relevant).
     509              :    - FORCE is true if exist_non_indexing_operands_for_use_p check shouldn't
     510              :      be performed.
     511              : 
     512              :    Outputs:
     513              :    Generally, LIVE_P and RELEVANT are used to define the liveness and
     514              :    relevance info of the DEF_STMT of this USE:
     515              :        STMT_VINFO_LIVE_P (DEF_stmt_vinfo) <-- live_p
     516              :        STMT_VINFO_RELEVANT (DEF_stmt_vinfo) <-- relevant
     517              :    Exceptions:
     518              :    - case 1: If USE is used only for address computations (e.g. array indexing),
     519              :    which does not need to be directly vectorized, then the liveness/relevance
     520              :    of the respective DEF_STMT is left unchanged.
     521              :    - case 2: If STMT_VINFO is a reduction phi and DEF_STMT is a reduction stmt,
     522              :    we skip DEF_STMT cause it had already been processed.
     523              :    - case 3: If DEF_STMT and STMT_VINFO are in different nests, then
     524              :    "relevant" will be modified accordingly.
     525              : 
     526              :    Return true if everything is as expected. Return false otherwise.  */
     527              : 
     528              : static opt_result
     529      3748469 : process_use (stmt_vec_info stmt_vinfo, tree use, loop_vec_info loop_vinfo,
     530              :              enum vect_relevant relevant, vec<stmt_vec_info> *worklist,
     531              :              bool force)
     532              : {
     533      3748469 :   stmt_vec_info dstmt_vinfo;
     534      3748469 :   enum vect_def_type dt;
     535              : 
     536              :   /* case 1: we are only interested in uses that need to be vectorized.  Uses
     537              :      that are used for address computation are not considered relevant.  */
     538      3748469 :   if (!force && !exist_non_indexing_operands_for_use_p (use, stmt_vinfo))
     539       987431 :     return opt_result::success ();
     540              : 
     541      2761038 :   if (!vect_is_simple_use (use, loop_vinfo, &dt, &dstmt_vinfo))
     542        35884 :     return opt_result::failure_at (stmt_vinfo->stmt,
     543              :                                    "not vectorized:"
     544              :                                    " unsupported use in stmt.\n");
     545              : 
     546      2725154 :   if (!dstmt_vinfo)
     547       538133 :     return opt_result::success ();
     548              : 
     549      2187021 :   basic_block def_bb = gimple_bb (dstmt_vinfo->stmt);
     550      2187021 :   basic_block bb = gimple_bb (stmt_vinfo->stmt);
     551              : 
     552              :   /* case 2: A reduction phi (STMT) defined by a reduction stmt (DSTMT_VINFO).
     553              :      We have to force the stmt live since the epilogue loop needs it to
     554              :      continue computing the reduction.  */
     555      2187021 :   if (gimple_code (stmt_vinfo->stmt) == GIMPLE_PHI
     556       228686 :       && STMT_VINFO_DEF_TYPE (stmt_vinfo) == vect_reduction_def
     557        59373 :       && gimple_code (dstmt_vinfo->stmt) != GIMPLE_PHI
     558        59373 :       && STMT_VINFO_DEF_TYPE (dstmt_vinfo) == vect_reduction_def
     559      2246394 :       && bb->loop_father == def_bb->loop_father)
     560              :     {
     561        59373 :       if (dump_enabled_p ())
     562         3744 :         dump_printf_loc (MSG_NOTE, vect_location,
     563              :                          "reduc-stmt defining reduc-phi in the same nest.\n");
     564        59373 :       vect_mark_relevant (worklist, dstmt_vinfo, relevant, true);
     565        59373 :       return opt_result::success ();
     566              :     }
     567              : 
     568              :   /* case 3a: outer-loop stmt defining an inner-loop stmt:
     569              :         outer-loop-header-bb:
     570              :                 d = dstmt_vinfo
     571              :         inner-loop:
     572              :                 stmt # use (d)
     573              :         outer-loop-tail-bb:
     574              :                 ...               */
     575      2127648 :   if (flow_loop_nested_p (def_bb->loop_father, bb->loop_father))
     576              :     {
     577         1899 :       if (dump_enabled_p ())
     578          320 :         dump_printf_loc (MSG_NOTE, vect_location,
     579              :                          "outer-loop def-stmt defining inner-loop stmt.\n");
     580              : 
     581         1899 :       switch (relevant)
     582              :         {
     583            0 :         case vect_unused_in_scope:
     584            0 :           relevant = (STMT_VINFO_DEF_TYPE (stmt_vinfo) == vect_nested_cycle) ?
     585              :                       vect_used_in_scope : vect_unused_in_scope;
     586              :           break;
     587              : 
     588          637 :         case vect_used_in_outer_by_reduction:
     589          637 :           gcc_assert (STMT_VINFO_DEF_TYPE (stmt_vinfo) != vect_reduction_def);
     590              :           relevant = vect_used_by_reduction;
     591              :           break;
     592              : 
     593         1032 :         case vect_used_in_outer:
     594         1032 :           gcc_assert (STMT_VINFO_DEF_TYPE (stmt_vinfo) != vect_reduction_def);
     595              :           relevant = vect_used_in_scope;
     596              :           break;
     597              : 
     598              :         case vect_used_in_scope:
     599              :           break;
     600              : 
     601            0 :         default:
     602            0 :           gcc_unreachable ();
     603              :         }
     604              :     }
     605              : 
     606              :   /* case 3b: inner-loop stmt defining an outer-loop stmt:
     607              :         outer-loop-header-bb:
     608              :                 ...
     609              :         inner-loop:
     610              :                 d = dstmt_vinfo
     611              :         outer-loop-tail-bb (or outer-loop-exit-bb in double reduction):
     612              :                 stmt # use (d)          */
     613      2125749 :   else if (flow_loop_nested_p (bb->loop_father, def_bb->loop_father))
     614              :     {
     615         1833 :       if (dump_enabled_p ())
     616          625 :         dump_printf_loc (MSG_NOTE, vect_location,
     617              :                          "inner-loop def-stmt defining outer-loop stmt.\n");
     618              : 
     619         1833 :       switch (relevant)
     620              :         {
     621            0 :         case vect_unused_in_scope:
     622            0 :           relevant = (STMT_VINFO_DEF_TYPE (stmt_vinfo) == vect_reduction_def
     623            0 :             || STMT_VINFO_DEF_TYPE (stmt_vinfo) == vect_double_reduction_def) ?
     624              :                       vect_used_in_outer_by_reduction : vect_unused_in_scope;
     625              :           break;
     626              : 
     627              :         case vect_used_by_reduction:
     628              :         case vect_used_only_live:
     629              :           relevant = vect_used_in_outer_by_reduction;
     630              :           break;
     631              : 
     632              :         case vect_used_in_scope:
     633      1964031 :           relevant = vect_used_in_outer;
     634              :           break;
     635              : 
     636            0 :         default:
     637            0 :           gcc_unreachable ();
     638              :         }
     639              :     }
     640              :   /* We are also not interested in uses on loop PHI backedges that are
     641              :      inductions.  Otherwise we'll needlessly vectorize the IV increment
     642              :      and cause hybrid SLP for SLP inductions.  */
     643      2123916 :   else if (gimple_code (stmt_vinfo->stmt) == GIMPLE_PHI
     644       166367 :            && STMT_VINFO_DEF_TYPE (stmt_vinfo) == vect_induction_def
     645      2287533 :            && (PHI_ARG_DEF_FROM_EDGE (stmt_vinfo->stmt,
     646              :                                       loop_latch_edge (bb->loop_father))
     647              :                == use))
     648              :     {
     649       163617 :       if (dump_enabled_p ())
     650         4789 :         dump_printf_loc (MSG_NOTE, vect_location,
     651              :                          "induction value on backedge.\n");
     652       163617 :       return opt_result::success ();
     653              :     }
     654              : 
     655      1964031 :   vect_mark_relevant (worklist, dstmt_vinfo, relevant, false);
     656      1964031 :   return opt_result::success ();
     657              : }
     658              : 
     659              : 
     660              : /* Function vect_mark_stmts_to_be_vectorized.
     661              : 
     662              :    Not all stmts in the loop need to be vectorized. For example:
     663              : 
     664              :      for i...
     665              :        for j...
     666              :    1.    T0 = i + j
     667              :    2.    T1 = a[T0]
     668              : 
     669              :    3.    j = j + 1
     670              : 
     671              :    Stmt 1 and 3 do not need to be vectorized, because loop control and
     672              :    addressing of vectorized data-refs are handled differently.
     673              : 
     674              :    This pass detects such stmts.  */
     675              : 
     676              : opt_result
     677       369726 : vect_mark_stmts_to_be_vectorized (loop_vec_info loop_vinfo, bool *fatal)
     678              : {
     679       369726 :   class loop *loop = LOOP_VINFO_LOOP (loop_vinfo);
     680       369726 :   basic_block *bbs = LOOP_VINFO_BBS (loop_vinfo);
     681       369726 :   unsigned int nbbs = loop->num_nodes;
     682       369726 :   gimple_stmt_iterator si;
     683       369726 :   unsigned int i;
     684       369726 :   basic_block bb;
     685       369726 :   bool live_p;
     686       369726 :   enum vect_relevant relevant;
     687              : 
     688       369726 :   DUMP_VECT_SCOPE ("vect_mark_stmts_to_be_vectorized");
     689              : 
     690       369726 :   auto_vec<stmt_vec_info, 64> worklist;
     691              : 
     692              :   /* 1. Init worklist.  */
     693      1274841 :   for (i = 0; i < nbbs; i++)
     694              :     {
     695       915446 :       bb = bbs[i];
     696      1828248 :       for (si = gsi_start_phis (bb); !gsi_end_p (si); gsi_next (&si))
     697              :         {
     698      1845978 :           if (virtual_operand_p (gimple_phi_result (gsi_stmt (si))))
     699       183985 :             continue;
     700       739004 :           stmt_vec_info phi_info = loop_vinfo->lookup_stmt (gsi_stmt (si));
     701       739004 :           if (dump_enabled_p ())
     702        40259 :             dump_printf_loc (MSG_NOTE, vect_location, "init: phi relevant? %G",
     703              :                              phi_info->stmt);
     704              : 
     705       739004 :           if (vect_stmt_relevant_p (phi_info, loop_vinfo, &relevant, &live_p))
     706              :             {
     707        45703 :               if (STMT_VINFO_DEF_TYPE (phi_info) == vect_unknown_def_type)
     708        10187 :                 return opt_result::failure_at
     709        10187 :                   (*si, "not vectorized: unhandled relevant PHI: %G", *si);
     710        35516 :               vect_mark_relevant (&worklist, phi_info, relevant, live_p);
     711              :             }
     712              :         }
     713      7113976 :       for (si = gsi_after_labels (bb); !gsi_end_p (si); gsi_next (&si))
     714              :         {
     715      6208861 :           gimple *stmt = gsi_stmt (si);
     716      6208861 :           if (is_gimple_debug (stmt))
     717      2604139 :             continue;
     718      3604722 :           stmt_vec_info stmt_info = loop_vinfo->lookup_stmt (stmt);
     719      3604722 :           if (dump_enabled_p ())
     720       215671 :               dump_printf_loc (MSG_NOTE, vect_location,
     721              :                                "init: stmt relevant? %G", stmt);
     722              : 
     723      3604722 :           if (gimple_get_lhs (stmt) == NULL_TREE
     724       547759 :               && !is_a <gcond *> (stmt)
     725      3610247 :               && !is_a <gcall *> (stmt))
     726          144 :             return opt_result::failure_at
     727          144 :                 (stmt, "not vectorized: irregular stmt: %G", stmt);
     728              : 
     729      3604578 :           if (vect_stmt_relevant_p (stmt_info, loop_vinfo, &relevant, &live_p))
     730       703756 :             vect_mark_relevant (&worklist, stmt_info, relevant, live_p);
     731              :         }
     732              :     }
     733              : 
     734              :   /* 2. Process_worklist */
     735      2730156 :   while (worklist.length () > 0)
     736              :     {
     737      2406647 :       use_operand_p use_p;
     738      2406647 :       ssa_op_iter iter;
     739              : 
     740      2406647 :       stmt_vec_info stmt_vinfo = worklist.pop ();
     741      2406647 :       if (dump_enabled_p ())
     742       140006 :         dump_printf_loc (MSG_NOTE, vect_location,
     743              :                          "worklist: examine stmt: %G", stmt_vinfo->stmt);
     744              : 
     745              :       /* Examine the USEs of STMT. For each USE, mark the stmt that defines it
     746              :          (DEF_STMT) as relevant/irrelevant according to the relevance property
     747              :          of STMT.  */
     748      2406647 :       relevant = STMT_VINFO_RELEVANT (stmt_vinfo);
     749              : 
     750              :       /* Generally, the relevance property of STMT (in STMT_VINFO_RELEVANT) is
     751              :          propagated as is to the DEF_STMTs of its USEs.
     752              : 
     753              :          One exception is when STMT has been identified as defining a reduction
     754              :          variable; in this case we set the relevance to vect_used_by_reduction.
     755              :          This is because we distinguish between two kinds of relevant stmts -
     756              :          those that are used by a reduction computation, and those that are
     757              :          (also) used by a regular computation.  This allows us later on to
     758              :          identify stmts that are used solely by a reduction, and therefore the
     759              :          order of the results that they produce does not have to be kept.  */
     760              : 
     761      2406647 :       switch (STMT_VINFO_DEF_TYPE (stmt_vinfo))
     762              :         {
     763       120835 :           case vect_reduction_def:
     764       120835 :             gcc_assert (relevant != vect_unused_in_scope);
     765       120835 :             if (relevant != vect_unused_in_scope
     766       120835 :                 && relevant != vect_used_in_scope
     767       120835 :                 && relevant != vect_used_by_reduction
     768       120835 :                 && relevant != vect_used_only_live)
     769            0 :               return opt_result::failure_at
     770            0 :                 (stmt_vinfo->stmt, "unsupported use of reduction.\n");
     771              :             break;
     772              : 
     773         1996 :           case vect_nested_cycle:
     774         1996 :             if (relevant != vect_unused_in_scope
     775         1996 :                 && relevant != vect_used_in_outer_by_reduction
     776         1482 :                 && relevant != vect_used_in_outer)
     777            2 :               return opt_result::failure_at
     778            2 :                 (stmt_vinfo->stmt, "unsupported use of nested cycle.\n");
     779              :             break;
     780              : 
     781         1035 :           case vect_double_reduction_def:
     782         1035 :             if (relevant != vect_unused_in_scope
     783         1035 :                 && relevant != vect_used_by_reduction
     784          351 :                 && relevant != vect_used_only_live)
     785            0 :               return opt_result::failure_at
     786            0 :                 (stmt_vinfo->stmt, "unsupported use of double reduction.\n");
     787              :             break;
     788              : 
     789              :           default:
     790              :             break;
     791              :         }
     792              : 
     793      2406645 :       if (is_pattern_stmt_p (stmt_vinfo))
     794              :         {
     795              :           /* Pattern statements are not inserted into the code, so
     796              :              FOR_EACH_PHI_OR_STMT_USE optimizes their operands out, and we
     797              :              have to scan the RHS or function arguments instead.  */
     798       589684 :           if (gassign *assign = dyn_cast <gassign *> (stmt_vinfo->stmt))
     799              :             {
     800       374658 :               enum tree_code rhs_code = gimple_assign_rhs_code (assign);
     801       374658 :               tree op = gimple_assign_rhs1 (assign);
     802              : 
     803       374658 :               i = 1;
     804       374658 :               if (rhs_code == COND_EXPR && COMPARISON_CLASS_P (op))
     805              :                 {
     806            0 :                   opt_result res
     807            0 :                     = process_use (stmt_vinfo, TREE_OPERAND (op, 0),
     808              :                                    loop_vinfo, relevant, &worklist, false);
     809            0 :                   if (!res)
     810            0 :                     return res;
     811            0 :                   res = process_use (stmt_vinfo, TREE_OPERAND (op, 1),
     812              :                                      loop_vinfo, relevant, &worklist, false);
     813            0 :                   if (!res)
     814            0 :                     return res;
     815              :                   i = 2;
     816              :                 }
     817      1079913 :               for (; i < gimple_num_ops (assign); i++)
     818              :                 {
     819       709501 :                   op = gimple_op (assign, i);
     820       709501 :                   if (TREE_CODE (op) == SSA_NAME)
     821              :                     {
     822       541094 :                       opt_result res
     823       541094 :                         = process_use (stmt_vinfo, op, loop_vinfo, relevant,
     824              :                                        &worklist, false);
     825       541094 :                       if (!res)
     826         4246 :                         return res;
     827              :                     }
     828              :                  }
     829              :             }
     830       215026 :           else if (gcond *cond = dyn_cast <gcond *> (stmt_vinfo->stmt))
     831              :             {
     832       210672 :               tree_code rhs_code = gimple_cond_code (cond);
     833       210672 :               gcc_assert (TREE_CODE_CLASS (rhs_code) == tcc_comparison);
     834       210672 :               opt_result res
     835       210672 :                 = process_use (stmt_vinfo, gimple_cond_lhs (cond),
     836              :                                loop_vinfo, relevant, &worklist, false);
     837       210672 :               if (!res)
     838        35886 :                 return res;
     839       210672 :               res = process_use (stmt_vinfo, gimple_cond_rhs (cond),
     840              :                                 loop_vinfo, relevant, &worklist, false);
     841       210672 :               if (!res)
     842            0 :                 return res;
     843              :             }
     844         4354 :           else if (gcall *call = dyn_cast <gcall *> (stmt_vinfo->stmt))
     845              :             {
     846        21018 :               for (i = 0; i < gimple_call_num_args (call); i++)
     847              :                 {
     848        16664 :                   tree arg = gimple_call_arg (call, i);
     849        16664 :                   opt_result res
     850        16664 :                     = process_use (stmt_vinfo, arg, loop_vinfo, relevant,
     851              :                                    &worklist, false);
     852        16664 :                   if (!res)
     853            0 :                     return res;
     854              :                 }
     855              :             }
     856              :           else
     857            0 :             gcc_unreachable ();
     858              :         }
     859              :       else
     860      6323373 :         FOR_EACH_PHI_OR_STMT_USE (use_p, stmt_vinfo->stmt, iter, SSA_OP_USE)
     861              :           {
     862      2707876 :             tree op = USE_FROM_PTR (use_p);
     863      2707876 :             opt_result res
     864      2707876 :               = process_use (stmt_vinfo, op, loop_vinfo, relevant,
     865              :                              &worklist, false);
     866      2707876 :             if (!res)
     867        18425 :               return res;
     868              :           }
     869              : 
     870      2383974 :       if (STMT_VINFO_GATHER_SCATTER_P (stmt_vinfo))
     871              :         {
     872        61491 :           gather_scatter_info gs_info;
     873        61491 :           if (!vect_check_gather_scatter (stmt_vinfo,
     874              :                                           STMT_VINFO_VECTYPE (stmt_vinfo),
     875              :                                           loop_vinfo, &gs_info))
     876            0 :             gcc_unreachable ();
     877        61491 :           opt_result res
     878        61491 :             = process_use (stmt_vinfo, gs_info.offset, loop_vinfo, relevant,
     879              :                            &worklist, true);
     880        61491 :           if (!res)
     881              :             {
     882        13213 :               if (fatal)
     883        13213 :                 *fatal = false;
     884        13213 :               return res;
     885              :             }
     886              :         }
     887              :     } /* while worklist */
     888              : 
     889       323509 :   return opt_result::success ();
     890       369726 : }
     891              : 
     892              : /* Function vect_model_simple_cost.
     893              : 
     894              :    Models cost for simple operations, i.e. those that only emit N operations
     895              :    of the same KIND.  */
     896              : 
     897              : static void
     898       622183 : vect_model_simple_cost (vec_info *vinfo, int n, slp_tree node,
     899              :                         stmt_vector_for_cost *cost_vec,
     900              :                         vect_cost_for_stmt kind = vector_stmt)
     901              : {
     902       622183 :   int inside_cost = 0, prologue_cost = 0;
     903              : 
     904       622183 :   gcc_assert (cost_vec != NULL);
     905              : 
     906       622183 :   n *= vect_get_num_copies (vinfo, node);
     907              : 
     908              :   /* Pass the inside-of-loop statements to the target-specific cost model.  */
     909       622183 :   inside_cost += record_stmt_cost (cost_vec, n, kind, node, 0, vect_body);
     910              : 
     911       622183 :   if (dump_enabled_p ())
     912        32520 :     dump_printf_loc (MSG_NOTE, vect_location,
     913              :                      "vect_model_simple_cost: inside_cost = %d, "
     914              :                      "prologue_cost = %d .\n", inside_cost, prologue_cost);
     915       622183 : }
     916              : 
     917              : 
     918              : /* Model cost for type demotion and promotion operations.  PWR is
     919              :    normally zero for single-step promotions and demotions.  It will be
     920              :    one if two-step promotion/demotion is required, and so on.  NCOPIES
     921              :    is the number of vector results (and thus number of instructions)
     922              :    for the narrowest end of the operation chain.  Each additional
     923              :    step doubles the number of instructions required.  If WIDEN_ARITH
     924              :    is true the stmt is doing widening arithmetic.  */
     925              : 
     926              : static void
     927        53507 : vect_model_promotion_demotion_cost (slp_tree slp_node,
     928              :                                     unsigned int ncopies, int pwr,
     929              :                                     stmt_vector_for_cost *cost_vec,
     930              :                                     bool widen_arith)
     931              : {
     932        53507 :   int i;
     933        53507 :   int inside_cost = 0, prologue_cost = 0;
     934              : 
     935       125836 :   for (i = 0; i < pwr + 1; i++)
     936              :     {
     937       142870 :       inside_cost += record_stmt_cost (cost_vec, ncopies,
     938              :                                        widen_arith
     939              :                                        ? vector_stmt : vec_promote_demote,
     940              :                                        slp_node, 0, vect_body);
     941        72329 :       ncopies *= 2;
     942              :     }
     943              : 
     944        53507 :   if (dump_enabled_p ())
     945         6155 :     dump_printf_loc (MSG_NOTE, vect_location,
     946              :                      "vect_model_promotion_demotion_cost: inside_cost = %d, "
     947              :                      "prologue_cost = %d .\n", inside_cost, prologue_cost);
     948        53507 : }
     949              : 
     950              : /* Returns true if the current function returns DECL.  */
     951              : 
     952              : static bool
     953       534724 : cfun_returns (tree decl)
     954              : {
     955       534724 :   edge_iterator ei;
     956       534724 :   edge e;
     957      1052417 :   FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR_FOR_FN (cfun)->preds)
     958              :     {
     959      1058636 :       greturn *ret = safe_dyn_cast <greturn *> (*gsi_last_bb (e->src));
     960       529318 :       if (!ret)
     961            0 :         continue;
     962       529318 :       if (gimple_return_retval (ret) == decl)
     963              :         return true;
     964              :       /* We often end up with an aggregate copy to the result decl,
     965              :          handle that case as well.  First skip intermediate clobbers
     966              :          though.  */
     967              :       gimple *def = ret;
     968      1562465 :       do
     969              :         {
     970      3124930 :           def = SSA_NAME_DEF_STMT (gimple_vuse (def));
     971              :         }
     972      1562465 :       while (gimple_clobber_p (def));
     973       518377 :       if (is_a <gassign *> (def)
     974        59845 :           && gimple_assign_lhs (def) == gimple_return_retval (ret)
     975       525307 :           && gimple_assign_rhs1 (def) == decl)
     976              :         return true;
     977              :     }
     978              :   return false;
     979              : }
     980              : 
     981              : /* Calculate cost of DR's memory access.  */
     982              : void
     983       894178 : vect_get_store_cost (vec_info *, stmt_vec_info stmt_info, slp_tree slp_node,
     984              :                      int ncopies, dr_alignment_support alignment_support_scheme,
     985              :                      int misalignment,
     986              :                      unsigned int *inside_cost,
     987              :                      stmt_vector_for_cost *body_cost_vec)
     988              : {
     989       894178 :   tree vectype
     990       894178 :     = slp_node ? SLP_TREE_VECTYPE (slp_node) : STMT_VINFO_VECTYPE (stmt_info);
     991       894178 :   switch (alignment_support_scheme)
     992              :     {
     993       472818 :     case dr_aligned:
     994       472818 :       {
     995       472818 :         *inside_cost += record_stmt_cost (body_cost_vec, ncopies,
     996              :                                           vector_store, stmt_info, slp_node,
     997              :                                           vectype, 0, vect_body);
     998              : 
     999       472818 :         if (dump_enabled_p ())
    1000        13674 :           dump_printf_loc (MSG_NOTE, vect_location,
    1001              :                            "vect_model_store_cost: aligned.\n");
    1002              :         break;
    1003              :       }
    1004              : 
    1005       421360 :     case dr_unaligned_supported:
    1006       421360 :       {
    1007              :         /* Here, we assign an additional cost for the unaligned store.  */
    1008       421360 :         *inside_cost += record_stmt_cost (body_cost_vec, ncopies,
    1009              :                                           unaligned_store, stmt_info, slp_node,
    1010              :                                           vectype, misalignment, vect_body);
    1011       421360 :         if (dump_enabled_p ())
    1012        12573 :           dump_printf_loc (MSG_NOTE, vect_location,
    1013              :                            "vect_model_store_cost: unaligned supported by "
    1014              :                            "hardware.\n");
    1015              :         break;
    1016              :       }
    1017              : 
    1018            0 :     case dr_unaligned_unsupported:
    1019            0 :       {
    1020            0 :         *inside_cost = VECT_MAX_COST;
    1021              : 
    1022            0 :         if (dump_enabled_p ())
    1023            0 :           dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    1024              :                            "vect_model_store_cost: unsupported access.\n");
    1025              :         break;
    1026              :       }
    1027              : 
    1028            0 :     default:
    1029            0 :       gcc_unreachable ();
    1030              :     }
    1031       894178 : }
    1032              : 
    1033              : /* Calculate cost of DR's memory access.  */
    1034              : void
    1035       741597 : vect_get_load_cost (vec_info *, stmt_vec_info stmt_info, slp_tree slp_node,
    1036              :                     int ncopies, dr_alignment_support alignment_support_scheme,
    1037              :                     int misalignment,
    1038              :                     bool add_realign_cost, unsigned int *inside_cost,
    1039              :                     unsigned int *prologue_cost,
    1040              :                     stmt_vector_for_cost *prologue_cost_vec,
    1041              :                     stmt_vector_for_cost *body_cost_vec,
    1042              :                     bool record_prologue_costs)
    1043              : {
    1044       741597 :   tree vectype
    1045       741597 :     = slp_node ? SLP_TREE_VECTYPE (slp_node) : STMT_VINFO_VECTYPE (stmt_info);
    1046       741597 :   switch (alignment_support_scheme)
    1047              :     {
    1048       428676 :     case dr_aligned:
    1049       428676 :       {
    1050       428676 :         *inside_cost += record_stmt_cost (body_cost_vec, ncopies, vector_load,
    1051              :                                           stmt_info, slp_node, vectype,
    1052              :                                           0, vect_body);
    1053              : 
    1054       428676 :         if (dump_enabled_p ())
    1055        17697 :           dump_printf_loc (MSG_NOTE, vect_location,
    1056              :                            "vect_model_load_cost: aligned.\n");
    1057              : 
    1058              :         break;
    1059              :       }
    1060       257693 :     case dr_unaligned_supported:
    1061       257693 :       {
    1062              :         /* Here, we assign an additional cost for the unaligned load.  */
    1063       257693 :         *inside_cost += record_stmt_cost (body_cost_vec, ncopies,
    1064              :                                           unaligned_load, stmt_info, slp_node,
    1065              :                                           vectype, misalignment, vect_body);
    1066              : 
    1067       257693 :         if (dump_enabled_p ())
    1068        20881 :           dump_printf_loc (MSG_NOTE, vect_location,
    1069              :                            "vect_model_load_cost: unaligned supported by "
    1070              :                            "hardware.\n");
    1071              : 
    1072              :         break;
    1073              :       }
    1074            0 :     case dr_explicit_realign:
    1075            0 :       {
    1076            0 :         *inside_cost += record_stmt_cost (body_cost_vec, ncopies * 2,
    1077              :                                           vector_load, stmt_info, slp_node,
    1078              :                                           vectype, 0, vect_body);
    1079            0 :         *inside_cost += record_stmt_cost (body_cost_vec, ncopies,
    1080              :                                           vec_perm, stmt_info, slp_node,
    1081              :                                           vectype, 0, vect_body);
    1082              : 
    1083              :         /* FIXME: If the misalignment remains fixed across the iterations of
    1084              :            the containing loop, the following cost should be added to the
    1085              :            prologue costs.  */
    1086            0 :         if (targetm.vectorize.builtin_mask_for_load)
    1087            0 :           *inside_cost += record_stmt_cost (body_cost_vec, 1, vector_stmt,
    1088              :                                             stmt_info, slp_node, vectype,
    1089              :                                             0, vect_body);
    1090              : 
    1091            0 :         if (dump_enabled_p ())
    1092            0 :           dump_printf_loc (MSG_NOTE, vect_location,
    1093              :                            "vect_model_load_cost: explicit realign\n");
    1094              : 
    1095              :         break;
    1096              :       }
    1097            0 :     case dr_explicit_realign_optimized:
    1098            0 :       {
    1099            0 :         if (dump_enabled_p ())
    1100            0 :           dump_printf_loc (MSG_NOTE, vect_location,
    1101              :                            "vect_model_load_cost: unaligned software "
    1102              :                            "pipelined.\n");
    1103              : 
    1104              :         /* Unaligned software pipeline has a load of an address, an initial
    1105              :            load, and possibly a mask operation to "prime" the loop.  However,
    1106              :            if this is an access in a group of loads, which provide grouped
    1107              :            access, then the above cost should only be considered for one
    1108              :            access in the group.  Inside the loop, there is a load op
    1109              :            and a realignment op.  */
    1110              : 
    1111            0 :         if (add_realign_cost && record_prologue_costs)
    1112              :           {
    1113            0 :             *prologue_cost += record_stmt_cost (prologue_cost_vec, 2,
    1114              :                                                 vector_stmt, stmt_info,
    1115              :                                                 slp_node, vectype,
    1116              :                                                 0, vect_prologue);
    1117            0 :             if (targetm.vectorize.builtin_mask_for_load)
    1118            0 :               *prologue_cost += record_stmt_cost (prologue_cost_vec, 1,
    1119              :                                                   vector_stmt, stmt_info,
    1120              :                                                   slp_node, vectype,
    1121              :                                                   0, vect_prologue);
    1122              :           }
    1123              : 
    1124            0 :         *inside_cost += record_stmt_cost (body_cost_vec, ncopies, vector_load,
    1125              :                                           stmt_info, slp_node, vectype,
    1126              :                                           0, vect_body);
    1127            0 :         *inside_cost += record_stmt_cost (body_cost_vec, ncopies, vec_perm,
    1128              :                                           stmt_info, slp_node, vectype,
    1129              :                                           0, vect_body);
    1130              : 
    1131            0 :         if (dump_enabled_p ())
    1132            0 :           dump_printf_loc (MSG_NOTE, vect_location,
    1133              :                            "vect_model_load_cost: explicit realign optimized"
    1134              :                            "\n");
    1135              : 
    1136              :         break;
    1137              :       }
    1138              : 
    1139        55228 :     case dr_unaligned_unsupported:
    1140        55228 :       {
    1141        55228 :         *inside_cost = VECT_MAX_COST;
    1142              : 
    1143        55228 :         if (dump_enabled_p ())
    1144           94 :           dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    1145              :                            "vect_model_load_cost: unsupported access.\n");
    1146              :         break;
    1147              :       }
    1148              : 
    1149            0 :     default:
    1150            0 :       gcc_unreachable ();
    1151              :     }
    1152       741597 : }
    1153              : 
    1154              : /* Insert the new stmt NEW_STMT at *GSI or at the appropriate place in
    1155              :    the loop preheader for the vectorized stmt STMT_VINFO.  */
    1156              : 
    1157              : static void
    1158         6358 : vect_init_vector_1 (vec_info *vinfo, stmt_vec_info stmt_vinfo, gimple *new_stmt,
    1159              :                     gimple_stmt_iterator *gsi)
    1160              : {
    1161         6358 :   if (gsi)
    1162         3035 :     vect_finish_stmt_generation (vinfo, stmt_vinfo, new_stmt, gsi);
    1163              :   else
    1164         3323 :     vinfo->insert_on_entry (stmt_vinfo, new_stmt);
    1165              : 
    1166         6358 :   if (dump_enabled_p ())
    1167         1807 :     dump_printf_loc (MSG_NOTE, vect_location,
    1168              :                      "created new init_stmt: %G", new_stmt);
    1169         6358 : }
    1170              : 
    1171              : /* Function vect_init_vector.
    1172              : 
    1173              :    Insert a new stmt (INIT_STMT) that initializes a new variable of type
    1174              :    TYPE with the value VAL.  If TYPE is a vector type and VAL does not have
    1175              :    vector type a vector with all elements equal to VAL is created first.
    1176              :    Place the initialization at GSI if it is not NULL.  Otherwise, place the
    1177              :    initialization at the loop preheader.
    1178              :    Return the DEF of INIT_STMT.
    1179              :    It will be used in the vectorization of STMT_INFO.  */
    1180              : 
    1181              : tree
    1182         4642 : vect_init_vector (vec_info *vinfo, stmt_vec_info stmt_info, tree val, tree type,
    1183              :                   gimple_stmt_iterator *gsi)
    1184              : {
    1185         4642 :   gimple *init_stmt;
    1186         4642 :   tree new_temp;
    1187              : 
    1188              :   /* We abuse this function to push sth to a SSA name with initial 'val'.  */
    1189         4642 :   if (! useless_type_conversion_p (type, TREE_TYPE (val)))
    1190              :     {
    1191         1361 :       gcc_assert (VECTOR_TYPE_P (type));
    1192         1361 :       if (! types_compatible_p (TREE_TYPE (type), TREE_TYPE (val)))
    1193              :         {
    1194              :           /* Scalar boolean value should be transformed into
    1195              :              all zeros or all ones value before building a vector.  */
    1196            8 :           if (VECTOR_BOOLEAN_TYPE_P (type))
    1197              :             {
    1198            0 :               tree true_val = build_all_ones_cst (TREE_TYPE (type));
    1199            0 :               tree false_val = build_zero_cst (TREE_TYPE (type));
    1200              : 
    1201            0 :               if (CONSTANT_CLASS_P (val))
    1202            0 :                 val = integer_zerop (val) ? false_val : true_val;
    1203              :               else
    1204              :                 {
    1205            0 :                   new_temp = make_ssa_name (TREE_TYPE (type));
    1206            0 :                   init_stmt = gimple_build_assign (new_temp, COND_EXPR,
    1207              :                                                    val, true_val, false_val);
    1208            0 :                   vect_init_vector_1 (vinfo, stmt_info, init_stmt, gsi);
    1209            0 :                   val = new_temp;
    1210              :                 }
    1211              :             }
    1212              :           else
    1213              :             {
    1214            8 :               gimple_seq stmts = NULL;
    1215            8 :               if (! INTEGRAL_TYPE_P (TREE_TYPE (val)))
    1216            8 :                 val = gimple_build (&stmts, VIEW_CONVERT_EXPR,
    1217            8 :                                     TREE_TYPE (type), val);
    1218              :               else
    1219              :                 /* ???  Condition vectorization expects us to do
    1220              :                    promotion of invariant/external defs.  */
    1221            0 :                 val = gimple_convert (&stmts, TREE_TYPE (type), val);
    1222           16 :               for (gimple_stmt_iterator gsi2 = gsi_start (stmts);
    1223           16 :                    !gsi_end_p (gsi2); )
    1224              :                 {
    1225            8 :                   init_stmt = gsi_stmt (gsi2);
    1226            8 :                   gsi_remove (&gsi2, false);
    1227            8 :                   vect_init_vector_1 (vinfo, stmt_info, init_stmt, gsi);
    1228              :                 }
    1229              :             }
    1230              :         }
    1231         1361 :       val = build_vector_from_val (type, val);
    1232              :     }
    1233              : 
    1234         4642 :   new_temp = vect_get_new_ssa_name (type, vect_simple_var, "cst_");
    1235         4642 :   init_stmt = gimple_build_assign (new_temp, val);
    1236         4642 :   vect_init_vector_1 (vinfo, stmt_info, init_stmt, gsi);
    1237         4642 :   return new_temp;
    1238              : }
    1239              : 
    1240              : 
    1241              : /* Get vectorized definitions for OP0 and OP1.  */
    1242              : 
    1243              : void
    1244       186520 : vect_get_vec_defs (vec_info *, slp_tree slp_node,
    1245              :                    tree op0, vec<tree> *vec_oprnds0,
    1246              :                    tree op1, vec<tree> *vec_oprnds1,
    1247              :                    tree op2, vec<tree> *vec_oprnds2,
    1248              :                    tree op3, vec<tree> *vec_oprnds3)
    1249              : {
    1250       186520 :   if (op0)
    1251       184873 :     vect_get_slp_defs (SLP_TREE_CHILDREN (slp_node)[0], vec_oprnds0);
    1252       186520 :   if (op1)
    1253       138778 :     vect_get_slp_defs (SLP_TREE_CHILDREN (slp_node)[1], vec_oprnds1);
    1254       186520 :   if (op2)
    1255         9186 :     vect_get_slp_defs (SLP_TREE_CHILDREN (slp_node)[2], vec_oprnds2);
    1256       186520 :   if (op3)
    1257            0 :     vect_get_slp_defs (SLP_TREE_CHILDREN (slp_node)[3], vec_oprnds3);
    1258       186520 : }
    1259              : 
    1260              : /* Helper function called by vect_finish_replace_stmt and
    1261              :    vect_finish_stmt_generation.  Set the location of the new
    1262              :    statement and create and return a stmt_vec_info for it.  */
    1263              : 
    1264              : static void
    1265      1428291 : vect_finish_stmt_generation_1 (vec_info *,
    1266              :                                stmt_vec_info stmt_info, gimple *vec_stmt)
    1267              : {
    1268      1428291 :   if (dump_enabled_p ())
    1269       148093 :     dump_printf_loc (MSG_NOTE, vect_location, "add new stmt: %G", vec_stmt);
    1270              : 
    1271      1428291 :   if (stmt_info)
    1272              :     {
    1273      1396890 :       gimple_set_location (vec_stmt, gimple_location (stmt_info->stmt));
    1274              : 
    1275              :       /* While EH edges will generally prevent vectorization, stmt might
    1276              :          e.g. be in a must-not-throw region.  Ensure newly created stmts
    1277              :          that could throw are part of the same region.  */
    1278      1396890 :       int lp_nr = lookup_stmt_eh_lp (stmt_info->stmt);
    1279      1396890 :       if (lp_nr != 0 && stmt_could_throw_p (cfun, vec_stmt))
    1280           48 :         add_stmt_to_eh_lp (vec_stmt, lp_nr);
    1281              :     }
    1282              :   else
    1283        31401 :     gcc_assert (!stmt_could_throw_p (cfun, vec_stmt));
    1284      1428291 : }
    1285              : 
    1286              : /* Replace the scalar statement STMT_INFO with a new vector statement VEC_STMT,
    1287              :    which sets the same scalar result as STMT_INFO did.  Create and return a
    1288              :    stmt_vec_info for VEC_STMT.  */
    1289              : 
    1290              : void
    1291          843 : vect_finish_replace_stmt (vec_info *vinfo,
    1292              :                           stmt_vec_info stmt_info, gimple *vec_stmt)
    1293              : {
    1294          843 :   gimple *scalar_stmt = vect_orig_stmt (stmt_info)->stmt;
    1295          843 :   gcc_assert (gimple_get_lhs (scalar_stmt) == gimple_get_lhs (vec_stmt));
    1296              : 
    1297          843 :   gimple_stmt_iterator gsi = gsi_for_stmt (scalar_stmt);
    1298          843 :   gsi_replace (&gsi, vec_stmt, true);
    1299              : 
    1300          843 :   vect_finish_stmt_generation_1 (vinfo, stmt_info, vec_stmt);
    1301          843 : }
    1302              : 
    1303              : /* Add VEC_STMT to the vectorized implementation of STMT_INFO and insert it
    1304              :    before *GSI.  Create and return a stmt_vec_info for VEC_STMT.  */
    1305              : 
    1306              : void
    1307      1427448 : vect_finish_stmt_generation (vec_info *vinfo,
    1308              :                              stmt_vec_info stmt_info, gimple *vec_stmt,
    1309              :                              gimple_stmt_iterator *gsi)
    1310              : {
    1311      1427448 :   gcc_assert (!stmt_info || gimple_code (stmt_info->stmt) != GIMPLE_LABEL);
    1312              : 
    1313      1427448 :   if (!gsi_end_p (*gsi)
    1314      2853788 :       && gimple_has_mem_ops (vec_stmt))
    1315              :     {
    1316      1426340 :       gimple *at_stmt = gsi_stmt (*gsi);
    1317      1426340 :       tree vuse = gimple_vuse (at_stmt);
    1318      1420100 :       if (vuse && TREE_CODE (vuse) == SSA_NAME)
    1319              :         {
    1320      1279180 :           tree vdef = gimple_vdef (at_stmt);
    1321      1279180 :           gimple_set_vuse (vec_stmt, gimple_vuse (at_stmt));
    1322      1279180 :           gimple_set_modified (vec_stmt, true);
    1323              :           /* If we have an SSA vuse and insert a store, update virtual
    1324              :              SSA form to avoid triggering the renamer.  Do so only
    1325              :              if we can easily see all uses - which is what almost always
    1326              :              happens with the way vectorized stmts are inserted.  */
    1327       751601 :           if ((vdef && TREE_CODE (vdef) == SSA_NAME)
    1328      2030745 :               && ((is_gimple_assign (vec_stmt)
    1329       750687 :                    && !is_gimple_reg (gimple_assign_lhs (vec_stmt)))
    1330        66317 :                   || (is_gimple_call (vec_stmt)
    1331          878 :                       && (!(gimple_call_flags (vec_stmt)
    1332          878 :                             & (ECF_CONST|ECF_PURE|ECF_NOVOPS))
    1333            1 :                           || (gimple_call_lhs (vec_stmt)
    1334            1 :                               && !is_gimple_reg (gimple_call_lhs (vec_stmt)))))))
    1335              :             {
    1336       686125 :               tree new_vdef = copy_ssa_name (vuse, vec_stmt);
    1337       686125 :               gimple_set_vdef (vec_stmt, new_vdef);
    1338       686125 :               SET_USE (gimple_vuse_op (at_stmt), new_vdef);
    1339              :             }
    1340              :         }
    1341              :     }
    1342      1427448 :   gsi_insert_before (gsi, vec_stmt, GSI_SAME_STMT);
    1343      1427448 :   vect_finish_stmt_generation_1 (vinfo, stmt_info, vec_stmt);
    1344      1427448 : }
    1345              : 
    1346              : /* We want to vectorize a call to combined function CFN with function
    1347              :    decl FNDECL, using VECTYPE_OUT as the type of the output and VECTYPE_IN
    1348              :    as the types of all inputs.  Check whether this is possible using
    1349              :    an internal function, returning its code if so or IFN_LAST if not.  */
    1350              : 
    1351              : static internal_fn
    1352        11866 : vectorizable_internal_function (combined_fn cfn, tree fndecl,
    1353              :                                 tree vectype_out, tree vectype_in)
    1354              : {
    1355        11866 :   internal_fn ifn;
    1356        11866 :   if (internal_fn_p (cfn))
    1357         9929 :     ifn = as_internal_fn (cfn);
    1358              :   else
    1359         1937 :     ifn = associated_internal_fn (fndecl);
    1360        11866 :   if (ifn != IFN_LAST && direct_internal_fn_p (ifn))
    1361              :     {
    1362         8422 :       const direct_internal_fn_info &info = direct_internal_fn (ifn);
    1363         8422 :       if (info.vectorizable)
    1364              :         {
    1365         8422 :           bool same_size_p = TYPE_SIZE (vectype_in) == TYPE_SIZE (vectype_out);
    1366         8422 :           tree type0 = (info.type0 < 0 ? vectype_out : vectype_in);
    1367         8422 :           tree type1 = (info.type1 < 0 ? vectype_out : vectype_in);
    1368              : 
    1369              :           /* The type size of both the vectype_in and vectype_out should be
    1370              :              exactly the same when vectype_out isn't participating the optab.
    1371              :              While there is no restriction for type size when vectype_out
    1372              :              is part of the optab query.  */
    1373         8422 :           if (type0 != vectype_out && type1 != vectype_out && !same_size_p)
    1374              :             return IFN_LAST;
    1375              : 
    1376         8402 :           if (direct_internal_fn_supported_p (ifn, tree_pair (type0, type1),
    1377              :                                               OPTIMIZE_FOR_SPEED))
    1378              :             return ifn;
    1379              :         }
    1380              :     }
    1381              :   return IFN_LAST;
    1382              : }
    1383              : 
    1384              : 
    1385              : static tree permute_vec_elements (vec_info *, tree, tree, tree, stmt_vec_info,
    1386              :                                   gimple_stmt_iterator *);
    1387              : 
    1388              : /* Check whether a load or store statement in the loop described by
    1389              :    LOOP_VINFO is possible in a loop using partial vectors.  This is
    1390              :    testing whether the vectorizer pass has the appropriate support,
    1391              :    as well as whether the target does.
    1392              : 
    1393              :    VLS_TYPE says whether the statement is a load or store and VECTYPE
    1394              :    is the type of the vector being loaded or stored.  SLP_NODE is the SLP
    1395              :    node that contains the statement, or null if none.  MEMORY_ACCESS_TYPE
    1396              :    says how the load or store is going to be implemented and GROUP_SIZE
    1397              :    is the number of load or store statements in the containing group.
    1398              :    If the access is a gather load or scatter store, GS_INFO describes
    1399              :    its arguments.  If the load or store is conditional, SCALAR_MASK is the
    1400              :    condition under which it occurs.
    1401              : 
    1402              :    Clear LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P if a loop using partial
    1403              :    vectors is not supported, otherwise record the required rgroup control
    1404              :    types.
    1405              : 
    1406              :    If partial vectors can be used and ELSVALS is nonzero the supported
    1407              :    else values will be added to the vector ELSVALS points to.  */
    1408              : 
    1409              : static void
    1410       224395 : check_load_store_for_partial_vectors (loop_vec_info loop_vinfo, tree vectype,
    1411              :                                       slp_tree slp_node,
    1412              :                                       vec_load_store_type vls_type,
    1413              :                                       int group_size,
    1414              :                                       vect_load_store_data *ls,
    1415              :                                       slp_tree mask_node,
    1416              :                                       vec<int> *elsvals = nullptr)
    1417              : {
    1418       224395 :   vect_memory_access_type memory_access_type = ls->memory_access_type;
    1419              : 
    1420              :   /* Invariant loads need no special support.  */
    1421       224395 :   if (memory_access_type == VMAT_INVARIANT)
    1422        27239 :     return;
    1423              : 
    1424              :   /* Figure whether the mask is uniform.  scalar_mask is used to
    1425              :      populate the scalar_cond_masked_set.  */
    1426       223367 :   tree scalar_mask = NULL_TREE;
    1427       223367 :   if (mask_node)
    1428         3538 :     for (unsigned i = 0; i < SLP_TREE_LANES (mask_node); ++i)
    1429              :       {
    1430         1820 :         tree def = vect_get_slp_scalar_def (mask_node, i);
    1431         1820 :         if (!def
    1432         1820 :             || (scalar_mask && def != scalar_mask))
    1433              :           {
    1434              :             scalar_mask = NULL;
    1435              :             break;
    1436              :           }
    1437              :         else
    1438         1789 :           scalar_mask = def;
    1439              :       }
    1440              : 
    1441       223367 :   unsigned int nvectors = vect_get_num_copies (loop_vinfo, slp_node);
    1442       223367 :   vec_loop_masks *masks = &LOOP_VINFO_MASKS (loop_vinfo);
    1443       223367 :   vec_loop_lens *lens = &LOOP_VINFO_LENS (loop_vinfo);
    1444       223367 :   machine_mode vecmode = TYPE_MODE (vectype);
    1445       223367 :   bool is_load = (vls_type == VLS_LOAD);
    1446       223367 :   if (memory_access_type == VMAT_LOAD_STORE_LANES)
    1447              :     {
    1448            0 :       nvectors /= group_size;
    1449            0 :       internal_fn ifn
    1450            0 :         = (is_load ? vect_load_lanes_supported (vectype, group_size, true,
    1451              :                                                 elsvals)
    1452            0 :                    : vect_store_lanes_supported (vectype, group_size, true));
    1453            0 :       if (ifn == IFN_MASK_LEN_LOAD_LANES || ifn == IFN_MASK_LEN_STORE_LANES)
    1454            0 :         vect_record_loop_len (loop_vinfo, lens, nvectors, vectype, 1);
    1455            0 :       else if (ifn == IFN_MASK_LOAD_LANES || ifn == IFN_MASK_STORE_LANES)
    1456            0 :         vect_record_loop_mask (loop_vinfo, masks, nvectors, vectype,
    1457              :                                scalar_mask);
    1458              :       else
    1459              :         {
    1460            0 :           if (dump_enabled_p ())
    1461            0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    1462              :                              "can't operate on partial vectors because"
    1463              :                              " the target doesn't have an appropriate"
    1464              :                              " load/store-lanes instruction.\n");
    1465            0 :           LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo) = false;
    1466              :         }
    1467            0 :       return;
    1468              :     }
    1469              : 
    1470       223367 :   if (mat_gather_scatter_p (memory_access_type))
    1471              :     {
    1472         1441 :       internal_fn ifn = (is_load
    1473         1441 :                          ? IFN_MASK_GATHER_LOAD
    1474              :                          : IFN_MASK_SCATTER_STORE);
    1475          334 :       internal_fn len_ifn = (is_load
    1476              :                              ? IFN_MASK_LEN_GATHER_LOAD
    1477              :                              : IFN_MASK_LEN_SCATTER_STORE);
    1478         1441 :       stmt_vec_info repr = SLP_TREE_REPRESENTATIVE (slp_node);
    1479         1441 :       tree off_vectype = (STMT_VINFO_GATHER_SCATTER_P (repr)
    1480         1441 :                           ? SLP_TREE_VECTYPE (SLP_TREE_CHILDREN (slp_node)[0])
    1481         1441 :                           : ls->strided_offset_vectype);
    1482         1441 :       tree memory_type = TREE_TYPE (DR_REF (STMT_VINFO_DR_INFO (repr)->dr));
    1483         1441 :       int scale = SLP_TREE_GS_SCALE (slp_node);
    1484              : 
    1485              :       /* The following "supported" checks just verify what we established in
    1486              :          get_load_store_type and don't try different offset types.
    1487              :          Therefore, off_vectype must be a supported offset type.  In case
    1488              :          we chose a different one use this instead.  */
    1489         1441 :       if (ls->supported_offset_vectype)
    1490            0 :         off_vectype = ls->supported_offset_vectype;
    1491              :       /* Same for scale.  */
    1492         1441 :       if (ls->supported_scale)
    1493            0 :         scale = ls->supported_scale;
    1494              : 
    1495         1441 :       if (internal_gather_scatter_fn_supported_p (len_ifn, vectype,
    1496              :                                                   memory_type,
    1497              :                                                   off_vectype, scale,
    1498              :                                                   elsvals))
    1499            0 :         vect_record_loop_len (loop_vinfo, lens, nvectors, vectype, 1);
    1500         1441 :       else if (internal_gather_scatter_fn_supported_p (ifn, vectype,
    1501              :                                                        memory_type,
    1502              :                                                        off_vectype, scale,
    1503              :                                                        elsvals)
    1504         1441 :                || memory_access_type == VMAT_GATHER_SCATTER_LEGACY)
    1505          339 :         vect_record_loop_mask (loop_vinfo, masks, nvectors, vectype,
    1506              :                                scalar_mask);
    1507              :       else
    1508              :         {
    1509         1102 :           if (dump_enabled_p ())
    1510           22 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    1511              :                              "can't operate on partial vectors because"
    1512              :                              " the target doesn't have an appropriate"
    1513              :                              " gather load or scatter store instruction.\n");
    1514         1102 :           LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo) = false;
    1515              :         }
    1516         1441 :       return;
    1517              :     }
    1518              : 
    1519       221926 :   if (memory_access_type != VMAT_CONTIGUOUS)
    1520              :     {
    1521              :       /* Element X of the data must come from iteration i * VF + X of the
    1522              :          scalar loop.  We need more work to support other mappings.  */
    1523        24770 :       if (dump_enabled_p ())
    1524          720 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    1525              :                          "can't operate on partial vectors because an"
    1526              :                          " access isn't contiguous.\n");
    1527        24770 :       LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo) = false;
    1528        24770 :       return;
    1529              :     }
    1530              : 
    1531       197156 :   if (!VECTOR_MODE_P (vecmode))
    1532              :     {
    1533            0 :       if (dump_enabled_p ())
    1534            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    1535              :                          "can't operate on partial vectors when emulating"
    1536              :                          " vector operations.\n");
    1537            0 :       LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo) = false;
    1538            0 :       return;
    1539              :     }
    1540              : 
    1541              :   /* We might load more scalars than we need for permuting SLP loads.
    1542              :      We checked in get_load_store_type that the extra elements
    1543              :      don't leak into a new vector.  */
    1544       262763 :   auto group_memory_nvectors = [](poly_uint64 size, poly_uint64 nunits)
    1545              :   {
    1546        65607 :     unsigned int nvectors;
    1547       131214 :     if (can_div_away_from_zero_p (size, nunits, &nvectors))
    1548        65607 :       return nvectors;
    1549              :     gcc_unreachable ();
    1550              :   };
    1551              : 
    1552       197156 :   poly_uint64 nunits = TYPE_VECTOR_SUBPARTS (vectype);
    1553       197156 :   poly_uint64 vf = LOOP_VINFO_VECT_FACTOR (loop_vinfo);
    1554       197156 :   machine_mode mask_mode;
    1555       197156 :   machine_mode vmode;
    1556       197156 :   bool using_partial_vectors_p = false;
    1557       197156 :   if (get_len_load_store_mode
    1558       197156 :       (vecmode, is_load, nullptr, elsvals).exists (&vmode))
    1559              :     {
    1560            0 :       nvectors = group_memory_nvectors (group_size * vf, nunits);
    1561            0 :       unsigned factor = (vecmode == vmode) ? 1 : GET_MODE_UNIT_SIZE (vecmode);
    1562            0 :       vect_record_loop_len (loop_vinfo, lens, nvectors, vectype, factor);
    1563            0 :       using_partial_vectors_p = true;
    1564              :     }
    1565       262763 :   else if (targetm.vectorize.get_mask_mode (vecmode).exists (&mask_mode)
    1566       197156 :            && can_vec_mask_load_store_p (vecmode, mask_mode, is_load, NULL,
    1567              :                                          elsvals))
    1568              :     {
    1569        65607 :       nvectors = group_memory_nvectors (group_size * vf, nunits);
    1570        65607 :       vect_record_loop_mask (loop_vinfo, masks, nvectors, vectype, scalar_mask);
    1571        65607 :       using_partial_vectors_p = true;
    1572              :     }
    1573              : 
    1574        65607 :   if (!using_partial_vectors_p)
    1575              :     {
    1576       131549 :       if (dump_enabled_p ())
    1577        11251 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    1578              :                          "can't operate on partial vectors because the"
    1579              :                          " target doesn't have the appropriate partial"
    1580              :                          " vectorization load or store.\n");
    1581       131549 :       LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo) = false;
    1582              :     }
    1583              : }
    1584              : 
    1585              : /* Return the mask input to a masked load or store.  VEC_MASK is the vectorized
    1586              :    form of the scalar mask condition and LOOP_MASK, if nonnull, is the mask
    1587              :    that needs to be applied to all loads and stores in a vectorized loop.
    1588              :    Return VEC_MASK if LOOP_MASK is null or if VEC_MASK is already masked,
    1589              :    otherwise return VEC_MASK & LOOP_MASK.
    1590              : 
    1591              :    MASK_TYPE is the type of both masks.  If new statements are needed,
    1592              :    insert them before GSI.  */
    1593              : 
    1594              : tree
    1595         1706 : prepare_vec_mask (loop_vec_info loop_vinfo, tree mask_type, tree loop_mask,
    1596              :                   tree vec_mask, gimple_stmt_iterator *gsi)
    1597              : {
    1598         1706 :   gcc_assert (useless_type_conversion_p (mask_type, TREE_TYPE (vec_mask)));
    1599         1706 :   if (!loop_mask)
    1600              :     return vec_mask;
    1601              : 
    1602          139 :   gcc_assert (TREE_TYPE (loop_mask) == mask_type);
    1603              : 
    1604          139 :   if (loop_vinfo->vec_cond_masked_set.contains ({ vec_mask, loop_mask }))
    1605              :     return vec_mask;
    1606              : 
    1607          139 :   tree and_res = make_temp_ssa_name (mask_type, NULL, "vec_mask_and");
    1608          139 :   gimple *and_stmt = gimple_build_assign (and_res, BIT_AND_EXPR,
    1609              :                                           vec_mask, loop_mask);
    1610              : 
    1611          139 :   gsi_insert_before (gsi, and_stmt, GSI_SAME_STMT);
    1612          139 :   return and_res;
    1613              : }
    1614              : 
    1615              : /* Determine whether we can use a gather load or scatter store to vectorize
    1616              :    strided load or store STMT_INFO by truncating the current offset to a
    1617              :    smaller width.  We need to be able to construct an offset vector:
    1618              : 
    1619              :      { 0, X, X*2, X*3, ... }
    1620              : 
    1621              :    without loss of precision, where X is STMT_INFO's DR_STEP.
    1622              : 
    1623              :    Return true if this is possible, describing the gather load or scatter
    1624              :    store in GS_INFO.  MASKED_P is true if the load or store is conditional.
    1625              : 
    1626              :    If we can use gather/scatter and ELSVALS is nonzero the supported
    1627              :    else values will be stored in the vector ELSVALS points to.  */
    1628              : 
    1629              : static bool
    1630        62917 : vect_truncate_gather_scatter_offset (stmt_vec_info stmt_info, tree vectype,
    1631              :                                      loop_vec_info loop_vinfo, bool masked_p,
    1632              :                                      gather_scatter_info *gs_info,
    1633              :                                      vec<int> *elsvals)
    1634              : {
    1635        62917 :   dr_vec_info *dr_info = STMT_VINFO_DR_INFO (stmt_info);
    1636        62917 :   data_reference *dr = dr_info->dr;
    1637        62917 :   tree step = DR_STEP (dr);
    1638        62917 :   if (TREE_CODE (step) != INTEGER_CST)
    1639              :     {
    1640              :       /* ??? Perhaps we could use range information here?  */
    1641        28184 :       if (dump_enabled_p ())
    1642          229 :         dump_printf_loc (MSG_NOTE, vect_location,
    1643              :                          "cannot truncate variable step.\n");
    1644        28184 :       return false;
    1645              :     }
    1646              : 
    1647              :   /* Get the number of bits in an element.  */
    1648        34733 :   scalar_mode element_mode = SCALAR_TYPE_MODE (TREE_TYPE (vectype));
    1649        34733 :   unsigned int element_bits = GET_MODE_BITSIZE (element_mode);
    1650              : 
    1651              :   /* Set COUNT to the upper limit on the number of elements - 1.
    1652              :      Start with the maximum vectorization factor.  */
    1653        34733 :   unsigned HOST_WIDE_INT count = vect_max_vf (loop_vinfo) - 1;
    1654              : 
    1655              :   /* Try lowering COUNT to the number of scalar latch iterations.  */
    1656        34733 :   class loop *loop = LOOP_VINFO_LOOP (loop_vinfo);
    1657        34733 :   widest_int max_iters;
    1658        34733 :   if (max_loop_iterations (loop, &max_iters)
    1659        68753 :       && max_iters < count)
    1660         2115 :     count = max_iters.to_shwi ();
    1661              : 
    1662              :   /* Try scales of 1 and the element size.  */
    1663        34733 :   unsigned int scales[] = { 1, vect_get_scalar_dr_size (dr_info) };
    1664        34733 :   wi::overflow_type overflow = wi::OVF_NONE;
    1665       104199 :   for (int i = 0; i < 2; ++i)
    1666              :     {
    1667        69466 :       unsigned int scale = scales[i];
    1668        69466 :       widest_int factor;
    1669        69466 :       if (!wi::multiple_of_p (wi::to_widest (step), scale, SIGNED, &factor))
    1670            0 :         continue;
    1671              : 
    1672              :       /* Determine the minimum precision of (COUNT - 1) * STEP / SCALE.  */
    1673        69466 :       widest_int range = wi::mul (count, factor, SIGNED, &overflow);
    1674        69466 :       if (overflow)
    1675            0 :         continue;
    1676        69466 :       signop sign = range >= 0 ? UNSIGNED : SIGNED;
    1677        69466 :       unsigned int min_offset_bits = wi::min_precision (range, sign);
    1678              : 
    1679              :       /* Find the narrowest viable offset type.  */
    1680        69466 :       unsigned int offset_bits = 1U << ceil_log2 (min_offset_bits);
    1681        69466 :       tree offset_type = build_nonstandard_integer_type (offset_bits,
    1682              :                                                          sign == UNSIGNED);
    1683              : 
    1684              :       /* See whether the target supports the operation with an offset
    1685              :          no narrower than OFFSET_TYPE.  */
    1686        69466 :       tree memory_type = TREE_TYPE (DR_REF (dr));
    1687        69466 :       tree tmp_offset_vectype;
    1688        69466 :       int tmp_scale;
    1689        69466 :       if (!vect_gather_scatter_fn_p (loop_vinfo, DR_IS_READ (dr), masked_p,
    1690              :                                      vectype, memory_type, offset_type,
    1691              :                                      scale, &tmp_scale,
    1692              :                                      &gs_info->ifn, &gs_info->offset_vectype,
    1693              :                                      &tmp_offset_vectype, elsvals)
    1694        69466 :           || gs_info->ifn == IFN_LAST)
    1695        69466 :         continue;
    1696              : 
    1697            0 :       gs_info->decl = NULL_TREE;
    1698              :       /* Logically the sum of DR_BASE_ADDRESS, DR_INIT and DR_OFFSET,
    1699              :          but we don't need to store that here.  */
    1700            0 :       gs_info->base = NULL_TREE;
    1701            0 :       gs_info->alias_ptr = build_int_cst
    1702            0 :         (reference_alias_ptr_type (DR_REF (dr)),
    1703            0 :          get_object_alignment (DR_REF (dr)));
    1704            0 :       gs_info->element_type = TREE_TYPE (vectype);
    1705            0 :       gs_info->offset = fold_convert (offset_type, step);
    1706            0 :       gs_info->scale = scale;
    1707            0 :       gs_info->memory_type = memory_type;
    1708            0 :       return true;
    1709       138932 :     }
    1710              : 
    1711        34733 :   if (overflow && dump_enabled_p ())
    1712            0 :     dump_printf_loc (MSG_NOTE, vect_location,
    1713              :                      "truncating gather/scatter offset to %d bits"
    1714              :                      " might change its value.\n", element_bits);
    1715              : 
    1716              :   return false;
    1717        34733 : }
    1718              : 
    1719              : /* Return true if we can use gather/scatter or strided internal functions
    1720              :    to vectorize STMT_INFO, which is a grouped or strided load or store
    1721              :    with multiple lanes and will be implemented by a type-punned access
    1722              :    of a vector with element size that matches the number of lanes.
    1723              : 
    1724              :    MASKED_P is true if load or store is conditional.
    1725              :    When returning true, fill in GS_INFO with the information required to
    1726              :    perform the operation.  Also, store the punning type in PUNNED_VECTYPE.
    1727              : 
    1728              :    If successful and ELSVALS is nonzero the supported
    1729              :    else values will be stored in the vector ELSVALS points to.  */
    1730              : 
    1731              : static bool
    1732         3663 : vect_use_grouped_gather (dr_vec_info *dr_info, tree vectype,
    1733              :                          loop_vec_info loop_vinfo, bool masked_p,
    1734              :                          unsigned int nelts,
    1735              :                          gather_scatter_info *info, vec<int> *elsvals,
    1736              :                          tree *pun_vectype)
    1737              : {
    1738         3663 :   data_reference *dr = dr_info->dr;
    1739              : 
    1740              :   /* TODO: We can support nelts > BITS_PER_UNIT or non-power-of-two by
    1741              :      multiple gathers/scatter.  */
    1742         7024 :   if (nelts > BITS_PER_UNIT || !pow2p_hwi (nelts))
    1743              :     return false;
    1744              : 
    1745              :   /* Pun the vectype with one of the same size but an element spanning
    1746              :      NELTS elements of VECTYPE.
    1747              :      The punned type of a V16QI with NELTS = 4 would be V4SI.
    1748              :      */
    1749         3097 :   tree tmp;
    1750         3097 :   unsigned int pieces;
    1751         3097 :   if (!can_div_trunc_p (TYPE_VECTOR_SUBPARTS (vectype), nelts, &pieces)
    1752         3097 :       || !pieces)
    1753          193 :     return false;
    1754              : 
    1755         2904 :   *pun_vectype = vector_vector_composition_type (vectype, pieces, &tmp, true);
    1756              : 
    1757         2904 :   if (!*pun_vectype || !VECTOR_TYPE_P (*pun_vectype))
    1758              :     return false;
    1759              : 
    1760         2540 :   internal_fn ifn;
    1761         2540 :   tree offset_vectype = *pun_vectype;
    1762              : 
    1763         1641 :   internal_fn strided_ifn = DR_IS_READ (dr)
    1764         2540 :     ? IFN_MASK_LEN_STRIDED_LOAD : IFN_MASK_LEN_STRIDED_STORE;
    1765              : 
    1766              :   /* Check if we have a gather/scatter with the new type.  We're just trying
    1767              :      with the type itself as offset for now.  If not, check if we have a
    1768              :      strided load/store.  These have fewer constraints (for example no offset
    1769              :      type must exist) so it is possible that even though a gather/scatter is
    1770              :      not available we still have a strided load/store.  */
    1771         2540 :   bool ok = false;
    1772         2540 :   tree tmp_vectype;
    1773         2540 :   int tmp_scale;
    1774         2540 :   if (vect_gather_scatter_fn_p
    1775         2540 :       (loop_vinfo, DR_IS_READ (dr), masked_p, *pun_vectype,
    1776         2540 :        TREE_TYPE (*pun_vectype), *pun_vectype, 1, &tmp_scale, &ifn,
    1777              :        &offset_vectype, &tmp_vectype, elsvals))
    1778              :     ok = true;
    1779         2540 :   else if (internal_strided_fn_supported_p (strided_ifn, *pun_vectype,
    1780              :                                             elsvals))
    1781              :     {
    1782              :       /* Use gather/scatter IFNs, vect_get_strided_load_store_ops
    1783              :          will switch back to the strided variants.  */
    1784            0 :       ifn = DR_IS_READ (dr) ? IFN_MASK_LEN_GATHER_LOAD :
    1785              :         IFN_MASK_LEN_SCATTER_STORE;
    1786            0 :       ok = true;
    1787              :     }
    1788              : 
    1789            0 :   if (ok)
    1790              :     {
    1791            0 :       info->ifn = ifn;
    1792            0 :       info->decl = NULL_TREE;
    1793            0 :       info->base = dr->ref;
    1794            0 :       info->alias_ptr = build_int_cst
    1795            0 :         (reference_alias_ptr_type (DR_REF (dr)),
    1796            0 :          get_object_alignment (DR_REF (dr)));
    1797            0 :       info->element_type = TREE_TYPE (*pun_vectype);
    1798            0 :       info->offset_vectype = offset_vectype;
    1799              :       /* No need to set the offset, vect_get_strided_load_store_ops
    1800              :          will do that.  */
    1801            0 :       info->scale = 1;
    1802            0 :       info->memory_type = TREE_TYPE (DR_REF (dr));
    1803            0 :       return true;
    1804              :     }
    1805              : 
    1806              :   return false;
    1807              : }
    1808              : 
    1809              : 
    1810              : /* Return true if we can use gather/scatter internal functions to
    1811              :    vectorize STMT_INFO, which is a grouped or strided load or store.
    1812              :    MASKED_P is true if load or store is conditional.  When returning
    1813              :    true, fill in GS_INFO with the information required to perform the
    1814              :    operation.
    1815              : 
    1816              :    If we can use gather/scatter and ELSVALS is nonzero the supported
    1817              :    else values will be stored in the vector ELSVALS points to.  */
    1818              : 
    1819              : static bool
    1820        62917 : vect_use_strided_gather_scatters_p (stmt_vec_info stmt_info, tree vectype,
    1821              :                                     loop_vec_info loop_vinfo, bool masked_p,
    1822              :                                     gather_scatter_info *gs_info,
    1823              :                                     vec<int> *elsvals,
    1824              :                                     unsigned int group_size,
    1825              :                                     bool single_element_p)
    1826              : {
    1827        62917 :   if (!vect_check_gather_scatter (stmt_info, vectype,
    1828              :                                   loop_vinfo, gs_info, elsvals)
    1829        62917 :       || gs_info->ifn == IFN_LAST)
    1830              :     {
    1831        62917 :       if (!vect_truncate_gather_scatter_offset (stmt_info, vectype, loop_vinfo,
    1832              :                                                 masked_p, gs_info, elsvals))
    1833              :         return false;
    1834              :     }
    1835              : 
    1836            0 :   if (!single_element_p
    1837            0 :       && !targetm.vectorize.prefer_gather_scatter (TYPE_MODE (vectype),
    1838              :                                                    gs_info->scale,
    1839              :                                                    group_size))
    1840              :     return false;
    1841              : 
    1842            0 :   if (dump_enabled_p ())
    1843            0 :     dump_printf_loc (MSG_NOTE, vect_location,
    1844              :                      "using gather/scatter for strided/grouped access,"
    1845              :                      " scale = %d\n", gs_info->scale);
    1846              : 
    1847              :   return true;
    1848              : }
    1849              : 
    1850              : /* STMT_INFO is a non-strided load or store, meaning that it accesses
    1851              :    elements with a known constant step.  Return -1 if that step
    1852              :    is negative, 0 if it is zero, and 1 if it is greater than zero.  */
    1853              : 
    1854              : int
    1855      1351389 : compare_step_with_zero (vec_info *vinfo, stmt_vec_info stmt_info)
    1856              : {
    1857      1351389 :   dr_vec_info *dr_info = STMT_VINFO_DR_INFO (stmt_info);
    1858      1351389 :   return tree_int_cst_compare (vect_dr_behavior (vinfo, dr_info)->step,
    1859      1351389 :                                size_zero_node);
    1860              : }
    1861              : 
    1862              : /* If the target supports a permute mask that reverses the elements in
    1863              :    a vector of type VECTYPE, return that mask, otherwise return null.  */
    1864              : 
    1865              : tree
    1866         8799 : perm_mask_for_reverse (tree vectype)
    1867              : {
    1868         8799 :   poly_uint64 nunits = TYPE_VECTOR_SUBPARTS (vectype);
    1869              : 
    1870              :   /* The encoding has a single stepped pattern.  */
    1871         8799 :   vec_perm_builder sel (nunits, 1, 3);
    1872        35196 :   for (int i = 0; i < 3; ++i)
    1873        26397 :     sel.quick_push (nunits - 1 - i);
    1874              : 
    1875         8799 :   vec_perm_indices indices (sel, 1, nunits);
    1876         8799 :   if (!can_vec_perm_const_p (TYPE_MODE (vectype), TYPE_MODE (vectype),
    1877              :                              indices))
    1878              :     return NULL_TREE;
    1879         7653 :   return vect_gen_perm_mask_checked (vectype, indices);
    1880         8799 : }
    1881              : 
    1882              : /* A subroutine of get_load_store_type, with a subset of the same
    1883              :    arguments.  Handle the case where STMT_INFO is a load or store that
    1884              :    accesses consecutive elements with a negative step.  Sets *POFFSET
    1885              :    to the offset to be applied to the DR for the first access.  */
    1886              : 
    1887              : static vect_memory_access_type
    1888        11435 : get_negative_load_store_type (vec_info *vinfo,
    1889              :                               stmt_vec_info stmt_info, tree vectype,
    1890              :                               vec_load_store_type vls_type,
    1891              :                               unsigned int ncopies, poly_int64 *poffset)
    1892              : {
    1893        11435 :   dr_vec_info *dr_info = STMT_VINFO_DR_INFO (stmt_info);
    1894        11435 :   dr_alignment_support alignment_support_scheme;
    1895              : 
    1896        11435 :   if (ncopies > 1)
    1897              :     {
    1898            0 :       if (dump_enabled_p ())
    1899            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    1900              :                          "multiple types with negative step.\n");
    1901            0 :       return VMAT_ELEMENTWISE;
    1902              :     }
    1903              : 
    1904              :   /* For backward running DRs the first access in vectype actually is
    1905              :      N-1 elements before the address of the DR.  */
    1906        11435 :   *poffset = ((-TYPE_VECTOR_SUBPARTS (vectype) + 1)
    1907        11435 :               * TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (vectype))));
    1908              : 
    1909        11435 :   int misalignment = dr_misalignment (dr_info, vectype, *poffset);
    1910        11435 :   alignment_support_scheme
    1911        11435 :     = vect_supportable_dr_alignment (vinfo, dr_info, vectype, misalignment);
    1912        11435 :   if (alignment_support_scheme != dr_aligned
    1913        11435 :       && alignment_support_scheme != dr_unaligned_supported)
    1914              :     {
    1915         4478 :       if (dump_enabled_p ())
    1916            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    1917              :                          "negative step but alignment required.\n");
    1918         4478 :       *poffset = 0;
    1919         4478 :       return VMAT_ELEMENTWISE;
    1920              :     }
    1921              : 
    1922         6957 :   if (vls_type == VLS_STORE_INVARIANT)
    1923              :     {
    1924          725 :       if (dump_enabled_p ())
    1925           21 :         dump_printf_loc (MSG_NOTE, vect_location,
    1926              :                          "negative step with invariant source;"
    1927              :                          " no permute needed.\n");
    1928          725 :       return VMAT_CONTIGUOUS_DOWN;
    1929              :     }
    1930              : 
    1931         6232 :   if (!perm_mask_for_reverse (vectype))
    1932              :     {
    1933         1146 :       if (dump_enabled_p ())
    1934           52 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    1935              :                          "negative step and reversing not supported.\n");
    1936         1146 :       *poffset = 0;
    1937         1146 :       return VMAT_ELEMENTWISE;
    1938              :     }
    1939              : 
    1940              :   return VMAT_CONTIGUOUS_REVERSE;
    1941              : }
    1942              : 
    1943              : /* STMT_INFO is either a masked or unconditional store.  Return the value
    1944              :    being stored.  */
    1945              : 
    1946              : tree
    1947            0 : vect_get_store_rhs (stmt_vec_info stmt_info)
    1948              : {
    1949            0 :   if (gassign *assign = dyn_cast <gassign *> (stmt_info->stmt))
    1950              :     {
    1951            0 :       gcc_assert (gimple_assign_single_p (assign));
    1952            0 :       return gimple_assign_rhs1 (assign);
    1953              :     }
    1954            0 :   if (gcall *call = dyn_cast <gcall *> (stmt_info->stmt))
    1955              :     {
    1956            0 :       internal_fn ifn = gimple_call_internal_fn (call);
    1957            0 :       int index = internal_fn_stored_value_index (ifn);
    1958            0 :       gcc_assert (index >= 0);
    1959            0 :       return gimple_call_arg (call, index);
    1960              :     }
    1961            0 :   gcc_unreachable ();
    1962              : }
    1963              : 
    1964              : /* Function VECTOR_VECTOR_COMPOSITION_TYPE
    1965              : 
    1966              :    This function returns a vector type which can be composed with NELTS pieces,
    1967              :    whose type is recorded in PTYPE.  VTYPE should be a vector type, and has the
    1968              :    same vector size as the return vector.  It checks target whether supports
    1969              :    pieces-size vector mode for construction firstly, if target fails to, check
    1970              :    pieces-size scalar mode for construction further.  It returns NULL_TREE if
    1971              :    fails to find the available composition.  If the caller only wants scalar
    1972              :    pieces where PTYPE e.g. is a possible gather/scatter element type
    1973              :    SCALAR_PTYPE_ONLY must be true.
    1974              : 
    1975              :    For example, for (vtype=V16QI, nelts=4), we can probably get:
    1976              :      - V16QI with PTYPE V4QI.
    1977              :      - V4SI with PTYPE SI.
    1978              :      - NULL_TREE.  */
    1979              : 
    1980              : static tree
    1981        13078 : vector_vector_composition_type (tree vtype, poly_uint64 nelts, tree *ptype,
    1982              :                                 bool scalar_ptype_only)
    1983              : {
    1984        13078 :   gcc_assert (VECTOR_TYPE_P (vtype));
    1985        13078 :   gcc_assert (known_gt (nelts, 0U));
    1986              : 
    1987        13078 :   machine_mode vmode = TYPE_MODE (vtype);
    1988        13078 :   if (!VECTOR_MODE_P (vmode))
    1989              :     return NULL_TREE;
    1990              : 
    1991              :   /* When we are asked to compose the vector from its components let
    1992              :      that happen directly.  */
    1993        13078 :   if (known_eq (TYPE_VECTOR_SUBPARTS (vtype), nelts))
    1994              :     {
    1995         5804 :       *ptype = TREE_TYPE (vtype);
    1996         5804 :       return vtype;
    1997              :     }
    1998              : 
    1999        14548 :   poly_uint64 vbsize = GET_MODE_BITSIZE (vmode);
    2000         7274 :   unsigned int pbsize;
    2001         7274 :   if (constant_multiple_p (vbsize, nelts, &pbsize))
    2002              :     {
    2003              :       /* First check if vec_init optab supports construction from
    2004              :          vector pieces directly.  */
    2005         7274 :       scalar_mode elmode = SCALAR_TYPE_MODE (TREE_TYPE (vtype));
    2006        14548 :       poly_uint64 inelts = pbsize / GET_MODE_BITSIZE (elmode);
    2007         7274 :       machine_mode rmode;
    2008         7274 :       if (!scalar_ptype_only
    2009         4370 :           && related_vector_mode (vmode, elmode, inelts).exists (&rmode)
    2010        11266 :           && (convert_optab_handler (vec_init_optab, vmode, rmode)
    2011              :               != CODE_FOR_nothing))
    2012              :         {
    2013         3375 :           *ptype = build_vector_type (TREE_TYPE (vtype), inelts);
    2014         3375 :           return vtype;
    2015              :         }
    2016              : 
    2017              :       /* Otherwise check if exists an integer type of the same piece size and
    2018              :          if vec_init optab supports construction from it directly.  */
    2019         3899 :       if (int_mode_for_size (pbsize, 0).exists (&elmode)
    2020         3899 :           && related_vector_mode (vmode, elmode, nelts).exists (&rmode))
    2021              :         {
    2022         3499 :           if (scalar_ptype_only
    2023         3499 :               || convert_optab_handler (vec_init_optab, rmode, elmode)
    2024              :               != CODE_FOR_nothing)
    2025              :             {
    2026         3499 :               *ptype = build_nonstandard_integer_type (pbsize, 1);
    2027         3499 :               return build_vector_type (*ptype, nelts);
    2028              :             }
    2029              :         }
    2030              :     }
    2031              : 
    2032              :   return NULL_TREE;
    2033              : }
    2034              : 
    2035              : /* Check if the load permutation of NODE only refers to a consecutive
    2036              :    subset of the group indices where GROUP_SIZE is the size of the
    2037              :    dataref's group.  We also assert that the length of the permutation
    2038              :    divides the group size and is a power of two.
    2039              :    Such load permutations can be elided in strided access schemes as
    2040              :    we can "jump over" the gap they leave.  */
    2041              : 
    2042              : bool
    2043        43043 : has_consecutive_load_permutation (slp_tree node, unsigned group_size)
    2044              : {
    2045        43043 :   load_permutation_t perm = SLP_TREE_LOAD_PERMUTATION (node);
    2046        43043 :   if (!perm.exists ()
    2047         1839 :       || perm.length () <= 1
    2048          411 :       || !pow2p_hwi (perm.length ())
    2049        43440 :       || group_size % perm.length ())
    2050              :     return false;
    2051              : 
    2052          354 :   return vect_load_perm_consecutive_p (node);
    2053              : }
    2054              : 
    2055              : 
    2056              : /* Analyze load or store SLP_NODE of type VLS_TYPE.  Return true
    2057              :    if there is a memory access type that the vectorized form can use,
    2058              :    storing it in *MEMORY_ACCESS_TYPE if so.  If we decide to use gathers
    2059              :    or scatters, fill in GS_INFO accordingly.  In addition
    2060              :    *ALIGNMENT_SUPPORT_SCHEME is filled out and false is returned if
    2061              :    the target does not support the alignment scheme.  *MISALIGNMENT
    2062              :    is set according to the alignment of the access (including
    2063              :    DR_MISALIGNMENT_UNKNOWN when it is unknown).
    2064              : 
    2065              :    MASKED_P is true if the statement is conditional on a vectorized mask.
    2066              :    VECTYPE is the vector type that the vectorized statements will use.
    2067              : 
    2068              :    If ELSVALS is nonzero the supported else values will be stored in the
    2069              :    vector ELSVALS points to.  */
    2070              : 
    2071              : static bool
    2072      1246618 : get_load_store_type (vec_info  *vinfo, stmt_vec_info stmt_info,
    2073              :                      tree vectype, slp_tree slp_node,
    2074              :                      bool masked_p, vec_load_store_type vls_type,
    2075              :                      vect_load_store_data *ls)
    2076              : {
    2077      1246618 :   vect_memory_access_type *memory_access_type = &ls->memory_access_type;
    2078      1246618 :   poly_int64 *poffset = &ls->poffset;
    2079      1246618 :   dr_alignment_support *alignment_support_scheme
    2080              :     = &ls->alignment_support_scheme;
    2081      1246618 :   int *misalignment = &ls->misalignment;
    2082      1246618 :   internal_fn *lanes_ifn = &ls->lanes_ifn;
    2083      1246618 :   vec<int> *elsvals = &ls->elsvals;
    2084      1246618 :   tree *ls_type = &ls->ls_type;
    2085      1246618 :   bool *slp_perm = &ls->slp_perm;
    2086      1246618 :   unsigned *n_perms = &ls->n_perms;
    2087      1246618 :   unsigned *n_loads = &ls->n_loads;
    2088      1246618 :   tree *supported_offset_vectype = &ls->supported_offset_vectype;
    2089      1246618 :   int *supported_scale = &ls->supported_scale;
    2090      1246618 :   loop_vec_info loop_vinfo = dyn_cast <loop_vec_info> (vinfo);
    2091      1246618 :   poly_uint64 nunits = TYPE_VECTOR_SUBPARTS (vectype);
    2092      1246618 :   class loop *loop = loop_vinfo ? LOOP_VINFO_LOOP (loop_vinfo) : NULL;
    2093      1246618 :   stmt_vec_info first_stmt_info;
    2094      1246618 :   unsigned int group_size;
    2095      1246618 :   unsigned HOST_WIDE_INT gap;
    2096      1246618 :   bool single_element_p;
    2097      1246618 :   poly_int64 neg_ldst_offset = 0;
    2098              : 
    2099      1246618 :   *misalignment = DR_MISALIGNMENT_UNKNOWN;
    2100      1246618 :   *poffset = 0;
    2101      1246618 :   *ls_type = NULL_TREE;
    2102      1246618 :   *slp_perm = false;
    2103      1246618 :   *n_perms = -1U;
    2104      1246618 :   *n_loads = -1U;
    2105      1246618 :   ls->subchain_p = false;
    2106              : 
    2107      1246618 :   bool perm_ok = true;
    2108      1246618 :   poly_int64 vf = loop_vinfo ? LOOP_VINFO_VECT_FACTOR (loop_vinfo) : 1;
    2109              : 
    2110      1246618 :   if (SLP_TREE_LOAD_PERMUTATION (slp_node).exists ())
    2111        66547 :     perm_ok = vect_transform_slp_perm_load (vinfo, slp_node, vNULL, NULL,
    2112        66547 :                                             vf, true, n_perms, n_loads);
    2113              : 
    2114      1246618 :   if (STMT_VINFO_GROUPED_ACCESS (stmt_info))
    2115              :     {
    2116       858534 :       first_stmt_info = DR_GROUP_FIRST_ELEMENT (stmt_info);
    2117       858534 :       group_size = DR_GROUP_SIZE (first_stmt_info);
    2118       858534 :       gap = DR_GROUP_GAP (first_stmt_info);
    2119       858534 :       single_element_p = (stmt_info == first_stmt_info
    2120       858534 :                           && !DR_GROUP_NEXT_ELEMENT (stmt_info));
    2121              :     }
    2122              :   else
    2123              :     {
    2124              :       first_stmt_info = stmt_info;
    2125              :       group_size = 1;
    2126              :       gap = 0;
    2127              :       single_element_p = true;
    2128              :     }
    2129      1246618 :   dr_vec_info *first_dr_info = STMT_VINFO_DR_INFO (first_stmt_info);
    2130              : 
    2131              :   /* True if the vectorized statements would access beyond the last
    2132              :      statement in the group.  */
    2133      1246618 :   bool overrun_p = false;
    2134              : 
    2135              :   /* True if we can cope with such overrun by peeling for gaps, so that
    2136              :      there is at least one final scalar iteration after the vector loop.  */
    2137      2493236 :   bool can_overrun_p = (!masked_p
    2138      1246618 :                         && vls_type == VLS_LOAD
    2139       471984 :                         && loop_vinfo
    2140      1588700 :                         && !loop->inner);
    2141              : 
    2142              :   /* There can only be a gap at the end of the group if the stride is
    2143              :      known at compile time.  */
    2144      1246618 :   gcc_assert (!STMT_VINFO_STRIDED_P (first_stmt_info) || gap == 0);
    2145              : 
    2146              :   /* For SLP vectorization we directly vectorize a subchain
    2147              :      without permutation.  */
    2148      1246618 :   if (! SLP_TREE_LOAD_PERMUTATION (slp_node).exists ())
    2149      1180071 :     first_dr_info = STMT_VINFO_DR_INFO (SLP_TREE_SCALAR_STMTS (slp_node)[0]);
    2150              : 
    2151      1246618 :   if (STMT_VINFO_STRIDED_P (first_stmt_info))
    2152              :     {
    2153              :       /* Try to use consecutive accesses of as many elements as possible,
    2154              :          separated by the stride, until we have a complete vector.
    2155              :          Fall back to scalar accesses if that isn't possible.  */
    2156        43043 :       *memory_access_type = VMAT_STRIDED_SLP;
    2157              : 
    2158              :       /* If the load permutation is consecutive we can reduce the group to
    2159              :          the elements the permutation accesses.  Then we release the
    2160              :          permutation.  */
    2161        43043 :       if (has_consecutive_load_permutation (slp_node, group_size))
    2162              :         {
    2163           20 :           ls->subchain_p = true;
    2164           20 :           group_size = SLP_TREE_LANES (slp_node);
    2165           20 :           SLP_TREE_LOAD_PERMUTATION (slp_node).release ();
    2166              :         }
    2167              :     }
    2168      1203575 :   else if (STMT_VINFO_GATHER_SCATTER_P (stmt_info))
    2169              :     {
    2170        10330 :       slp_tree offset_node = SLP_TREE_CHILDREN (slp_node)[0];
    2171        10330 :       tree offset_vectype = SLP_TREE_VECTYPE (offset_node);
    2172        10330 :       int scale = SLP_TREE_GS_SCALE (slp_node);
    2173        10330 :       tree memory_type = TREE_TYPE (DR_REF (first_dr_info->dr));
    2174        10330 :       tree tem;
    2175        10330 :       if (vect_gather_scatter_fn_p (loop_vinfo, vls_type == VLS_LOAD,
    2176              :                                     masked_p, vectype, memory_type,
    2177              :                                     offset_vectype, scale, supported_scale,
    2178              :                                     &ls->gs.ifn, &tem,
    2179              :                                     supported_offset_vectype, elsvals))
    2180              :         {
    2181            0 :           if (dump_enabled_p ())
    2182              :             {
    2183            0 :               dump_printf_loc (MSG_NOTE, vect_location,
    2184              :                                "gather/scatter with required "
    2185              :                                "offset type "
    2186              :                                "%T and offset scale %d.\n",
    2187              :                                offset_vectype, scale);
    2188            0 :               if (*supported_offset_vectype)
    2189            0 :                 dump_printf_loc (MSG_NOTE, vect_location,
    2190              :                                  " target supports offset type %T.\n",
    2191              :                                  *supported_offset_vectype);
    2192            0 :               if (*supported_scale)
    2193            0 :                 dump_printf_loc (MSG_NOTE, vect_location,
    2194              :                                  " target supports offset scale %d.\n",
    2195              :                                  *supported_scale);
    2196              :             }
    2197            0 :           *memory_access_type = VMAT_GATHER_SCATTER_IFN;
    2198              :         }
    2199        10330 :       else if (vls_type == VLS_LOAD
    2200        10330 :                ? (targetm.vectorize.builtin_gather
    2201         8912 :                   && (ls->gs.decl
    2202         8912 :                         = targetm.vectorize.builtin_gather (vectype,
    2203         8912 :                                                             TREE_TYPE
    2204              :                                                               (offset_vectype),
    2205              :                                                             scale)))
    2206         1418 :                : (targetm.vectorize.builtin_scatter
    2207         1418 :                   && (ls->gs.decl
    2208         1418 :                         = targetm.vectorize.builtin_scatter (vectype,
    2209         1418 :                                                              TREE_TYPE
    2210              :                                                                (offset_vectype),
    2211              :                                                              scale))))
    2212          345 :         *memory_access_type = VMAT_GATHER_SCATTER_LEGACY;
    2213              :       else
    2214              :         {
    2215              :           /* GATHER_SCATTER_EMULATED_P.  */
    2216         9985 :           if (!TYPE_VECTOR_SUBPARTS (vectype).is_constant ()
    2217         9985 :               || !TYPE_VECTOR_SUBPARTS (offset_vectype).is_constant ()
    2218         9985 :               || VECTOR_BOOLEAN_TYPE_P (offset_vectype)
    2219         9985 :               || !constant_multiple_p (TYPE_VECTOR_SUBPARTS (offset_vectype),
    2220         9985 :                                        TYPE_VECTOR_SUBPARTS (vectype)))
    2221              :             {
    2222         2600 :               if (dump_enabled_p ())
    2223          450 :                 dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2224              :                                  "unsupported vector types for emulated "
    2225              :                                  "gather.\n");
    2226         2600 :               return false;
    2227              :             }
    2228         7385 :           *memory_access_type = VMAT_GATHER_SCATTER_EMULATED;
    2229              :         }
    2230              :     }
    2231              :   else
    2232              :     {
    2233      1193245 :       int cmp = compare_step_with_zero (vinfo, stmt_info);
    2234      1193245 :       if (cmp < 0)
    2235              :         {
    2236        11574 :           if (single_element_p)
    2237              :             /* ???  The VMAT_CONTIGUOUS_REVERSE code generation is
    2238              :                only correct for single element "interleaving" SLP.  */
    2239        11435 :             *memory_access_type = get_negative_load_store_type
    2240        11435 :                 (vinfo, stmt_info, vectype, vls_type, 1,
    2241              :                  &neg_ldst_offset);
    2242              :           else
    2243              :             /* We can fall back to VMAT_STRIDED_SLP since that does
    2244              :                not care whether the stride between the group instances
    2245              :                is positive or negative.  */
    2246          139 :             *memory_access_type = VMAT_STRIDED_SLP;
    2247              :         }
    2248      1181671 :       else if (cmp == 0 && loop_vinfo)
    2249              :         {
    2250         3046 :           gcc_assert (vls_type == VLS_LOAD);
    2251         3046 :           *memory_access_type = VMAT_INVARIANT;
    2252              :         }
    2253              :       /* Try using LOAD/STORE_LANES.  */
    2254      1178625 :       else if (slp_node->ldst_lanes
    2255      1178625 :                && (*lanes_ifn
    2256            0 :                    = (vls_type == VLS_LOAD
    2257            0 :                       ? vect_load_lanes_supported (vectype, group_size,
    2258              :                                                    masked_p, elsvals)
    2259            0 :                       : vect_store_lanes_supported (vectype, group_size,
    2260              :                                                     masked_p))) != IFN_LAST)
    2261            0 :         *memory_access_type = VMAT_LOAD_STORE_LANES;
    2262      1178625 :       else if (!loop_vinfo && slp_node->avoid_stlf_fail)
    2263              :         {
    2264           74 :           *memory_access_type = VMAT_ELEMENTWISE;
    2265           74 :           if (dump_enabled_p ())
    2266            2 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2267              :                              "using element-wise load to avoid disrupting "
    2268              :                              "cross iteration store-to-load forwarding\n");
    2269              :         }
    2270              :       else
    2271      1178551 :         *memory_access_type = VMAT_CONTIGUOUS;
    2272              : 
    2273              :       /* If this is single-element interleaving with an element
    2274              :          distance that leaves unused vector loads around fall back
    2275              :          to elementwise access if possible - we otherwise least
    2276              :          create very sub-optimal code in that case (and
    2277              :          blow up memory, see PR65518).  */
    2278      1193245 :       if (loop_vinfo
    2279      1193245 :           && single_element_p
    2280       369777 :           && (*memory_access_type == VMAT_CONTIGUOUS
    2281        14481 :               || *memory_access_type == VMAT_CONTIGUOUS_REVERSE)
    2282      1563022 :           && maybe_gt (group_size, TYPE_VECTOR_SUBPARTS (vectype)))
    2283              :         {
    2284        17760 :           *memory_access_type = VMAT_ELEMENTWISE;
    2285        17760 :           if (dump_enabled_p ())
    2286          196 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2287              :                              "single-element interleaving not supported "
    2288              :                              "for not adjacent vector loads, using "
    2289              :                              "elementwise access\n");
    2290              :         }
    2291              : 
    2292              :       /* Also fall back to elementwise access in case we did not lower a
    2293              :          permutation and cannot code generate it.  */
    2294      1193245 :       if (loop_vinfo
    2295       415449 :           && *memory_access_type != VMAT_ELEMENTWISE
    2296       392065 :           && SLP_TREE_LOAD_PERMUTATION (slp_node).exists ()
    2297      1215723 :           && !perm_ok)
    2298              :         {
    2299         1998 :           *memory_access_type = VMAT_ELEMENTWISE;
    2300         1998 :           if (dump_enabled_p ())
    2301          246 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2302              :                              "permutation not supported, using elementwise "
    2303              :                              "access\n");
    2304              :         }
    2305              : 
    2306       415449 :       overrun_p = (loop_vinfo && gap != 0
    2307      1235748 :                    && *memory_access_type != VMAT_ELEMENTWISE);
    2308      1193245 :       if (overrun_p && vls_type != VLS_LOAD)
    2309              :         {
    2310            0 :           dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2311              :                            "Grouped store with gaps requires"
    2312              :                            " non-consecutive accesses\n");
    2313            9 :           return false;
    2314              :         }
    2315              : 
    2316      1193245 :       unsigned HOST_WIDE_INT dr_size = vect_get_scalar_dr_size (first_dr_info);
    2317      1193245 :       poly_int64 off = 0;
    2318      1193245 :       if (*memory_access_type == VMAT_CONTIGUOUS_REVERSE)
    2319         4927 :         off = (TYPE_VECTOR_SUBPARTS (vectype) - 1) * -dr_size;
    2320              : 
    2321              :       /* An overrun is fine if the trailing elements are smaller
    2322              :          than the alignment boundary B.  Every vector access will
    2323              :          be a multiple of B and so we are guaranteed to access a
    2324              :          non-gap element in the same B-sized block.  */
    2325      1193245 :       if (overrun_p
    2326      1193245 :           && gap < (vect_known_alignment_in_bytes (first_dr_info,
    2327        22649 :                                                    vectype, off) / dr_size))
    2328              :         overrun_p = false;
    2329              : 
    2330              :       /* When we have a contiguous access across loop iterations
    2331              :          but the access in the loop doesn't cover the full vector
    2332              :          we can end up with no gap recorded but still excess
    2333              :          elements accessed, see PR103116.  Make sure we peel for
    2334              :          gaps if necessary and sufficient and give up if not.
    2335              : 
    2336              :          If there is a combination of the access not covering the full
    2337              :          vector and a gap recorded then we may need to peel twice.  */
    2338      1193245 :       bool large_vector_overrun_p = false;
    2339      1193245 :       if (loop_vinfo
    2340       415449 :           && (*memory_access_type == VMAT_CONTIGUOUS
    2341        34216 :               || *memory_access_type == VMAT_CONTIGUOUS_REVERSE)
    2342       386160 :           && SLP_TREE_LOAD_PERMUTATION (slp_node).exists ()
    2343      1213423 :           && !multiple_p (group_size * LOOP_VINFO_VECT_FACTOR (loop_vinfo),
    2344              :                           nunits))
    2345              :         large_vector_overrun_p = overrun_p = true;
    2346              : 
    2347              :       /* If the gap splits the vector in half and the target
    2348              :          can do half-vector operations avoid the epilogue peeling
    2349              :          by simply loading half of the vector only.  Usually
    2350              :          the construction with an upper zero half will be elided.  */
    2351      1193245 :       dr_alignment_support alss;
    2352      1193245 :       int misalign = dr_misalignment (first_dr_info, vectype, off);
    2353      1193245 :       tree half_vtype;
    2354      1193245 :       poly_uint64 remain;
    2355      1193245 :       unsigned HOST_WIDE_INT tem, num;
    2356      1193245 :       if (overrun_p
    2357      1193245 :           && !masked_p
    2358        17178 :           && *memory_access_type != VMAT_LOAD_STORE_LANES
    2359        17178 :           && (((alss = vect_supportable_dr_alignment (vinfo, first_dr_info,
    2360              :                                                       vectype, misalign)))
    2361              :               == dr_aligned
    2362        14737 :               || alss == dr_unaligned_supported)
    2363         9636 :           && can_div_trunc_p (group_size
    2364         9636 :                               * LOOP_VINFO_VECT_FACTOR (loop_vinfo) - gap,
    2365              :                               nunits, &tem, &remain)
    2366      1202881 :           && (known_eq (remain, 0u)
    2367         7252 :               || (known_ne (remain, 0u)
    2368         5621 :                   && constant_multiple_p (nunits, remain, &num)
    2369      1190861 :                   && (vector_vector_composition_type (vectype, num, &half_vtype)
    2370              :                       != NULL_TREE))))
    2371         8005 :         overrun_p = false;
    2372              : 
    2373      1193245 :       if (overrun_p && !can_overrun_p)
    2374              :         {
    2375            6 :           if (dump_enabled_p ())
    2376            6 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2377              :                              "Peeling for outer loop is not supported\n");
    2378            6 :           return false;
    2379              :         }
    2380              : 
    2381              :       /* Peeling for gaps assumes that a single scalar iteration
    2382              :          is enough to make sure the last vector iteration doesn't
    2383              :          access excess elements.  */
    2384      1193239 :       if (overrun_p
    2385      1193239 :           && (!can_div_trunc_p (group_size
    2386         9167 :                                 * LOOP_VINFO_VECT_FACTOR (loop_vinfo) - gap,
    2387              :                                 nunits, &tem, &remain)
    2388         9167 :               || maybe_lt (remain + group_size, nunits)))
    2389              :         {
    2390              :           /* But peeling a single scalar iteration is enough if
    2391              :              we can use the next power-of-two sized partial
    2392              :              access and that is sufficiently small to be covered
    2393              :              by the single scalar iteration.  */
    2394           16 :           unsigned HOST_WIDE_INT cnunits, cvf, cremain, cpart_size;
    2395           16 :           if (masked_p
    2396           16 :               || !nunits.is_constant (&cnunits)
    2397           16 :               || !LOOP_VINFO_VECT_FACTOR (loop_vinfo).is_constant (&cvf)
    2398           16 :               || (((cremain = (group_size * cvf - gap) % cnunits), true)
    2399           16 :                   && ((cpart_size = (1 << ceil_log2 (cremain))), true)
    2400           16 :                   && (cremain + group_size < cpart_size
    2401           13 :                       || (vector_vector_composition_type (vectype,
    2402           13 :                                                          cnunits / cpart_size,
    2403              :                                                          &half_vtype)
    2404              :                           == NULL_TREE))))
    2405              :             {
    2406              :               /* If all fails we can still resort to niter masking unless
    2407              :                  the vectors used are too big, so enforce the use of
    2408              :                  partial vectors.  */
    2409            3 :               if (LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo)
    2410            3 :                   && !large_vector_overrun_p)
    2411              :                 {
    2412            0 :                   if (dump_enabled_p ())
    2413            0 :                     dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2414              :                                      "peeling for gaps insufficient for "
    2415              :                                      "access unless using partial "
    2416              :                                      "vectors\n");
    2417            0 :                   LOOP_VINFO_MUST_USE_PARTIAL_VECTORS_P (loop_vinfo) = true;
    2418              :                 }
    2419              :               else
    2420              :                 {
    2421            3 :                   if (dump_enabled_p ())
    2422            3 :                     dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2423              :                                      "peeling for gaps insufficient for "
    2424              :                                      "access\n");
    2425            3 :                   return false;
    2426              :                 }
    2427              :             }
    2428           13 :           else if (large_vector_overrun_p)
    2429              :             {
    2430           13 :               if (dump_enabled_p ())
    2431           12 :                 dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2432              :                                  "can't operate on partial vectors because "
    2433              :                                  "only unmasked loads handle access "
    2434              :                                  "shortening required because of gaps at "
    2435              :                                  "the end of the access\n");
    2436           13 :               LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo) = false;
    2437              :             }
    2438              :         }
    2439              :     }
    2440              : 
    2441              :   /* As a last resort, trying using a gather load or scatter store.
    2442              : 
    2443              :      ??? Although the code can handle all group sizes correctly,
    2444              :      it probably isn't a win to use separate strided accesses based
    2445              :      on nearby locations.  Or, even if it's a win over scalar code,
    2446              :      it might not be a win over vectorizing at a lower VF, if that
    2447              :      allows us to use contiguous accesses.  */
    2448      1244009 :   vect_memory_access_type grouped_gather_fallback = VMAT_UNINITIALIZED;
    2449      1244009 :   if (loop_vinfo
    2450       466213 :       && (*memory_access_type == VMAT_ELEMENTWISE
    2451       466213 :           || *memory_access_type == VMAT_STRIDED_SLP))
    2452              :     {
    2453        68561 :       gather_scatter_info gs_info;
    2454        68561 :       if (SLP_TREE_LANES (slp_node) == 1
    2455        64707 :           && (!SLP_TREE_LOAD_PERMUTATION (slp_node).exists ()
    2456        21262 :               || single_element_p)
    2457       131478 :           && vect_use_strided_gather_scatters_p (stmt_info, vectype, loop_vinfo,
    2458              :                                                  masked_p, &gs_info, elsvals,
    2459              :                                                  group_size, single_element_p))
    2460              :         {
    2461              :           /* vect_use_strided_gather_scatters_p does not save the actually
    2462              :              supported scale and offset type so do that here.
    2463              :              We need it later in check_load_store_for_partial_vectors
    2464              :              where we only check if the given internal function is supported
    2465              :              (to choose whether to use the IFN, LEGACY, or EMULATED flavor
    2466              :              of gather/scatter) and don't re-do the full analysis.  */
    2467            0 :           tree tmp;
    2468            0 :           gcc_assert (vect_gather_scatter_fn_p
    2469              :                       (loop_vinfo, vls_type == VLS_LOAD, masked_p, vectype,
    2470              :                        gs_info.memory_type, TREE_TYPE (gs_info.offset),
    2471              :                        gs_info.scale, supported_scale, &gs_info.ifn,
    2472              :                        &tmp, supported_offset_vectype, elsvals));
    2473              : 
    2474            0 :           SLP_TREE_GS_SCALE (slp_node) = gs_info.scale;
    2475            0 :           SLP_TREE_GS_BASE (slp_node) = error_mark_node;
    2476            0 :           ls->gs.ifn = gs_info.ifn;
    2477            0 :           ls->strided_offset_vectype = gs_info.offset_vectype;
    2478            0 :           *memory_access_type = VMAT_GATHER_SCATTER_IFN;
    2479              :         }
    2480        68561 :       else if (SLP_TREE_LANES (slp_node) > 1
    2481              :                && !masked_p
    2482         3854 :                && !single_element_p
    2483        72224 :                && vect_use_grouped_gather (STMT_VINFO_DR_INFO (stmt_info),
    2484              :                                            vectype, loop_vinfo,
    2485              :                                            masked_p, group_size,
    2486              :                                            &gs_info, elsvals, ls_type))
    2487              :         {
    2488            0 :           SLP_TREE_GS_SCALE (slp_node) = gs_info.scale;
    2489            0 :           SLP_TREE_GS_BASE (slp_node) = error_mark_node;
    2490            0 :           grouped_gather_fallback = *memory_access_type;
    2491            0 :           *memory_access_type = VMAT_GATHER_SCATTER_IFN;
    2492            0 :           ls->gs.ifn = gs_info.ifn;
    2493            0 :           vectype = *ls_type;
    2494            0 :           ls->strided_offset_vectype = gs_info.offset_vectype;
    2495              :         }
    2496              :     }
    2497              : 
    2498      1244009 :   if (*memory_access_type == VMAT_CONTIGUOUS_DOWN
    2499      1244009 :       || *memory_access_type == VMAT_CONTIGUOUS_REVERSE)
    2500         5648 :     *poffset = neg_ldst_offset;
    2501              : 
    2502      1244009 :   if (*memory_access_type == VMAT_ELEMENTWISE
    2503      1218553 :       || *memory_access_type == VMAT_GATHER_SCATTER_LEGACY
    2504      1218208 :       || *memory_access_type == VMAT_STRIDED_SLP
    2505      1175029 :       || *memory_access_type == VMAT_INVARIANT)
    2506              :     {
    2507        72026 :       *alignment_support_scheme = dr_unaligned_supported;
    2508        72026 :       *misalignment = DR_MISALIGNMENT_UNKNOWN;
    2509              :     }
    2510              :   else
    2511              :     {
    2512      1171983 :       if (mat_gather_scatter_p (*memory_access_type)
    2513              :           && !first_dr_info)
    2514              :         *misalignment = DR_MISALIGNMENT_UNKNOWN;
    2515              :       else
    2516      1171983 :         *misalignment = dr_misalignment (first_dr_info, vectype, *poffset);
    2517      1171983 :       *alignment_support_scheme
    2518      1171983 :         = vect_supportable_dr_alignment
    2519      1171983 :            (vinfo, first_dr_info, vectype, *misalignment,
    2520      1171983 :             mat_gather_scatter_p (*memory_access_type));
    2521      1171983 :       if (grouped_gather_fallback != VMAT_UNINITIALIZED
    2522            0 :           && *alignment_support_scheme != dr_aligned
    2523            0 :           && *alignment_support_scheme != dr_unaligned_supported)
    2524              :         {
    2525              :           /* No supportable alignment for a grouped gather, fall back to the
    2526              :              original memory access type.  Even though VMAT_STRIDED_SLP might
    2527              :              also try aligned vector loads it can still choose vector
    2528              :              construction from scalars.  */
    2529            0 :           *memory_access_type = grouped_gather_fallback;
    2530            0 :           *alignment_support_scheme = dr_unaligned_supported;
    2531            0 :           *misalignment = DR_MISALIGNMENT_UNKNOWN;
    2532              :         }
    2533              :     }
    2534              : 
    2535      1244009 :   if (overrun_p)
    2536              :     {
    2537         9164 :       gcc_assert (can_overrun_p);
    2538         9164 :       if (dump_enabled_p ())
    2539          503 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2540              :                          "Data access with gaps requires scalar "
    2541              :                          "epilogue loop\n");
    2542         9164 :       LOOP_VINFO_PEELING_FOR_GAPS (loop_vinfo) = true;
    2543              :     }
    2544              : 
    2545      1244009 :   if ((*memory_access_type == VMAT_ELEMENTWISE
    2546      1244009 :        || *memory_access_type == VMAT_STRIDED_SLP)
    2547              :       && !nunits.is_constant ())
    2548              :     {
    2549              :       if (dump_enabled_p ())
    2550              :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2551              :                          "Not using elementwise accesses due to variable "
    2552              :                          "vectorization factor.\n");
    2553              :       return false;
    2554              :     }
    2555              : 
    2556              :   /* Checks if all scalar iterations are known to be inbounds.  */
    2557      1244009 :   bool inbounds = DR_SCALAR_KNOWN_BOUNDS (STMT_VINFO_DR_INFO (stmt_info));
    2558              : 
    2559              :   /* Check if we support the operation if early breaks are needed.  Here we
    2560              :      must ensure that we don't access any more than the scalar code would
    2561              :      have.  A masked operation would ensure this, so for these load types
    2562              :      force masking.  */
    2563      1244009 :   if (loop_vinfo
    2564       466213 :       && dr_safe_speculative_read_required (stmt_info)
    2565      1416594 :       && LOOP_VINFO_EARLY_BREAKS (loop_vinfo))
    2566              :     {
    2567       172585 :       if (mat_gather_scatter_p (*memory_access_type)
    2568       172585 :           || *memory_access_type == VMAT_STRIDED_SLP)
    2569              :         {
    2570         9006 :           if (dump_enabled_p ())
    2571            8 :             dump_printf_loc (MSG_NOTE, vect_location,
    2572              :                              "early break not supported: cannot peel for "
    2573              :                              "alignment. With non-contiguous memory vectorization"
    2574              :                              " could read out of bounds at %G ",
    2575              :                              STMT_VINFO_STMT (stmt_info));
    2576         9006 :           if (inbounds)
    2577            0 :             LOOP_VINFO_MUST_USE_PARTIAL_VECTORS_P (loop_vinfo) = true;
    2578              :           else
    2579              :             return false;
    2580              :         }
    2581              :       /* Block-level alignment: Even though individual accesses of
    2582              :          VMAT_ELEMENTWISE type do not cause alignment problems, loading the
    2583              :          whole vector's worth of values in a speculative early-break context
    2584              :          might cross a page boundary.  Set the alignment scheme to `dr_aligned'
    2585              :          here in order to force checking of whether such accesses meet
    2586              :          alignment criteria.  */
    2587       163579 :       else if (*memory_access_type == VMAT_ELEMENTWISE && !inbounds)
    2588        14981 :         *alignment_support_scheme = dr_aligned;
    2589              :     }
    2590              : 
    2591              :   /* If this DR needs alignment for correctness, we must ensure the target
    2592              :      alignment is a constant power-of-two multiple of the amount read per
    2593              :      vector iteration or force masking.  */
    2594      1235003 :   if (dr_safe_speculative_read_required (stmt_info)
    2595      1235003 :       && (*alignment_support_scheme == dr_aligned
    2596        96038 :           && !mat_gather_scatter_p (*memory_access_type)))
    2597              :     {
    2598              :       /* We can only peel for loops, of course.  */
    2599        96038 :       gcc_checking_assert (loop_vinfo);
    2600              : 
    2601        96038 :       poly_uint64 vf = LOOP_VINFO_VECT_FACTOR (loop_vinfo);
    2602        96038 :       poly_uint64 read_amount
    2603        96038 :         = vf * TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (vectype)));
    2604        96038 :       if (STMT_VINFO_GROUPED_ACCESS (stmt_info))
    2605        96038 :         read_amount *= group_size;
    2606              : 
    2607        96038 :       auto target_alignment
    2608        96038 :         = DR_TARGET_ALIGNMENT (STMT_VINFO_DR_INFO (stmt_info));
    2609        96038 :       if (!multiple_p (target_alignment, read_amount))
    2610              :         {
    2611        12716 :           if (dump_enabled_p ())
    2612              :             {
    2613           28 :               dump_printf_loc (MSG_NOTE, vect_location,
    2614              :                                "desired alignment not met, target was ");
    2615           28 :               dump_dec (MSG_NOTE, target_alignment);
    2616           28 :               dump_printf (MSG_NOTE, " previously, but read amount is ");
    2617           28 :               dump_dec (MSG_NOTE, read_amount);
    2618           28 :               dump_printf (MSG_NOTE, " at %G.\n", STMT_VINFO_STMT (stmt_info));
    2619              :             }
    2620        14901 :           return false;
    2621              :         }
    2622              : 
    2623              :       /* When using a group access the first element may be aligned but the
    2624              :          subsequent loads may not be.  For LOAD_LANES since the loads are based
    2625              :          on the first DR then all loads in the group are aligned.  For
    2626              :          non-LOAD_LANES this is not the case. In particular a load + blend when
    2627              :          there are gaps can have the non first loads issued unaligned, even
    2628              :          partially overlapping the memory of the first load in order to simplify
    2629              :          the blend.  This is what the x86_64 backend does for instance.  As
    2630              :          such only the first load in the group is aligned, the rest are not.
    2631              :          Because of this the permutes may break the alignment requirements that
    2632              :          have been set, and as such we should for now, reject them.  */
    2633        83322 :       if (SLP_TREE_LOAD_PERMUTATION (slp_node).exists ())
    2634              :         {
    2635         2185 :           if (dump_enabled_p ())
    2636           75 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2637              :                              "loads with load permutations not supported for "
    2638              :                              "speculative early break loads for %G",
    2639              :                              STMT_VINFO_STMT (stmt_info));
    2640         2185 :           return false;
    2641              :         }
    2642              : 
    2643              :       /* Reject vectorization if we know the read mount per vector iteration
    2644              :          exceeds the min page size.  */
    2645        81137 :       if (known_gt (read_amount, (unsigned) param_min_pagesize))
    2646              :         {
    2647            0 :           if (dump_enabled_p ())
    2648              :             {
    2649            0 :               dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2650              :                                "alignment required for correctness (");
    2651            0 :               dump_dec (MSG_MISSED_OPTIMIZATION, read_amount);
    2652            0 :               dump_printf (MSG_NOTE, ") may exceed page size.\n");
    2653              :             }
    2654            0 :           return false;
    2655              :         }
    2656              : 
    2657        81137 :       if (!vf.is_constant ())
    2658              :         {
    2659              :           /* For VLA modes, we need a runtime check to ensure any speculative
    2660              :              read amount does not exceed the page size.  Here we record the max
    2661              :              possible read amount for the check.  */
    2662              :           if (maybe_gt (read_amount,
    2663              :                         LOOP_VINFO_MAX_SPEC_READ_AMOUNT (loop_vinfo)))
    2664              :             LOOP_VINFO_MAX_SPEC_READ_AMOUNT (loop_vinfo) = read_amount;
    2665              : 
    2666              :           /* For VLA modes, we must use partial vectors.  */
    2667              :           LOOP_VINFO_MUST_USE_PARTIAL_VECTORS_P (loop_vinfo) = true;
    2668              :         }
    2669              :     }
    2670              : 
    2671      1220102 :   if (*alignment_support_scheme == dr_unaligned_unsupported)
    2672              :     {
    2673        64217 :       if (dump_enabled_p ())
    2674          248 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2675              :                          "unsupported unaligned access\n");
    2676        64217 :       return false;
    2677              :     }
    2678              : 
    2679              :   /* FIXME: At the moment the cost model seems to underestimate the
    2680              :      cost of using elementwise accesses.  This check preserves the
    2681              :      traditional behavior until that can be fixed.  */
    2682      1155885 :   if (*memory_access_type == VMAT_ELEMENTWISE
    2683        14719 :       && !STMT_VINFO_STRIDED_P (first_stmt_info)
    2684      1170604 :       && !(STMT_VINFO_GROUPED_ACCESS (stmt_info)
    2685         9532 :            && single_element_p
    2686         8906 :            && !pow2p_hwi (group_size)))
    2687              :     {
    2688         9090 :       if (dump_enabled_p ())
    2689          362 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2690              :                          "not falling back to elementwise accesses\n");
    2691         9090 :       return false;
    2692              :     }
    2693              : 
    2694              :   /* For BB vectorization build up the vector from existing scalar defs.  */
    2695      1146795 :   if (!loop_vinfo && *memory_access_type == VMAT_ELEMENTWISE)
    2696              :     return false;
    2697              : 
    2698              :   /* Some loads need to explicitly permute the loaded data if there
    2699              :      is a load permutation.  Among those are:
    2700              :       - VMAT_ELEMENTWISE.
    2701              :       - VMAT_STRIDED_SLP.
    2702              :       - VMAT_GATHER_SCATTER:
    2703              :         - Strided gather (fallback for VMAT_STRIDED_SLP if #lanes == 1).
    2704              :         - Grouped strided gather (ditto but for #lanes > 1).
    2705              : 
    2706              :      For VMAT_ELEMENTWISE we can fold the load permutation into the
    2707              :      individual indices we access directly, eliding the permutation.
    2708              :      Strided gather only allows load permutations for the
    2709              :      single-element case.  */
    2710              : 
    2711      1146795 :   if (SLP_TREE_LOAD_PERMUTATION (slp_node).exists ()
    2712      1146795 :       && !(*memory_access_type == VMAT_ELEMENTWISE
    2713        39806 :            || (mat_gather_scatter_p (*memory_access_type)
    2714            0 :                && SLP_TREE_LANES (slp_node) == 1
    2715            0 :                && single_element_p)))
    2716              :     {
    2717        39806 :       if (!loop_vinfo)
    2718              :         {
    2719              :           /* In BB vectorization we may not actually use a loaded vector
    2720              :              accessing elements in excess of DR_GROUP_SIZE.  */
    2721        24148 :           stmt_vec_info group_info = SLP_TREE_SCALAR_STMTS (slp_node)[0];
    2722        24148 :           group_info = DR_GROUP_FIRST_ELEMENT (group_info);
    2723        24148 :           unsigned HOST_WIDE_INT nunits;
    2724        24148 :           unsigned j, k, maxk = 0;
    2725        85654 :           FOR_EACH_VEC_ELT (SLP_TREE_LOAD_PERMUTATION (slp_node), j, k)
    2726        61506 :             if (k > maxk)
    2727              :               maxk = k;
    2728        24148 :           tree vectype = SLP_TREE_VECTYPE (slp_node);
    2729        44044 :           if (!TYPE_VECTOR_SUBPARTS (vectype).is_constant (&nunits)
    2730        24148 :               || maxk >= (DR_GROUP_SIZE (group_info) & ~(nunits - 1)))
    2731              :             {
    2732         4252 :               if (dump_enabled_p ())
    2733           31 :                 dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2734              :                                  "BB vectorization with gaps at the end of "
    2735              :                                  "a load is not supported\n");
    2736         4252 :               return false;
    2737              :             }
    2738              :         }
    2739              : 
    2740        35554 :       if (!perm_ok)
    2741              :         {
    2742         1985 :           if (dump_enabled_p ())
    2743            8 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION,
    2744              :                              vect_location,
    2745              :                              "unsupported load permutation\n");
    2746         1985 :           return false;
    2747              :         }
    2748              : 
    2749        33569 :       *slp_perm = true;
    2750              :     }
    2751              : 
    2752              :   return true;
    2753              : }
    2754              : 
    2755              : /* Return true if boolean argument at MASK_INDEX is suitable for vectorizing
    2756              :    conditional operation STMT_INFO.  When returning true, store the mask
    2757              :    in *MASK_NODE, the type of its definition in *MASK_DT_OUT and the type of
    2758              :    the vectorized mask in *MASK_VECTYPE_OUT.  */
    2759              : 
    2760              : static bool
    2761         8097 : vect_check_scalar_mask (vec_info *vinfo,
    2762              :                         slp_tree slp_node, unsigned mask_index,
    2763              :                         slp_tree *mask_node,
    2764              :                         vect_def_type *mask_dt_out, tree *mask_vectype_out)
    2765              : {
    2766         8097 :   enum vect_def_type mask_dt;
    2767         8097 :   tree mask_vectype;
    2768         8097 :   slp_tree mask_node_1;
    2769         8097 :   tree mask_;
    2770         8097 :   if (!vect_is_simple_use (vinfo, slp_node, mask_index,
    2771              :                            &mask_, &mask_node_1, &mask_dt, &mask_vectype))
    2772              :     {
    2773            0 :       if (dump_enabled_p ())
    2774            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2775              :                          "mask use not simple.\n");
    2776            0 :       return false;
    2777              :     }
    2778              : 
    2779         8097 :   if ((mask_dt == vect_constant_def || mask_dt == vect_external_def)
    2780         8097 :       && !VECT_SCALAR_BOOLEAN_TYPE_P (TREE_TYPE (mask_)))
    2781              :     {
    2782            0 :       if (dump_enabled_p ())
    2783            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2784              :                          "mask argument is not a boolean.\n");
    2785            0 :       return false;
    2786              :     }
    2787              : 
    2788         8097 :   tree vectype = SLP_TREE_VECTYPE (slp_node);
    2789         8097 :   if (!mask_vectype)
    2790           17 :     mask_vectype = get_mask_type_for_scalar_type (vinfo, TREE_TYPE (vectype),
    2791              :                                                   mask_node_1);
    2792              : 
    2793         8097 :   if (!mask_vectype || !VECTOR_BOOLEAN_TYPE_P (mask_vectype))
    2794              :     {
    2795            0 :       if (dump_enabled_p ())
    2796            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2797              :                          "could not find an appropriate vector mask type.\n");
    2798            0 :       return false;
    2799              :     }
    2800              : 
    2801         8097 :   if (maybe_ne (TYPE_VECTOR_SUBPARTS (mask_vectype),
    2802        16194 :                 TYPE_VECTOR_SUBPARTS (vectype)))
    2803              :     {
    2804            0 :       if (dump_enabled_p ())
    2805            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2806              :                          "vector mask type %T"
    2807              :                          " does not match vector data type %T.\n",
    2808              :                          mask_vectype, vectype);
    2809              : 
    2810            0 :       return false;
    2811              :     }
    2812              : 
    2813         8097 :   *mask_dt_out = mask_dt;
    2814         8097 :   *mask_vectype_out = mask_vectype;
    2815         8097 :   *mask_node = mask_node_1;
    2816         8097 :   return true;
    2817              : }
    2818              : 
    2819              : 
    2820              : /* Return true if stored value is suitable for vectorizing store
    2821              :    statement STMT_INFO.  When returning true, store the scalar stored
    2822              :    in *RHS and *RHS_NODE, the type of the definition in *RHS_DT_OUT,
    2823              :    the type of the vectorized store value in
    2824              :    *RHS_VECTYPE_OUT and the type of the store in *VLS_TYPE_OUT.  */
    2825              : 
    2826              : static bool
    2827      1316572 : vect_check_store_rhs (vec_info *vinfo, stmt_vec_info stmt_info,
    2828              :                       slp_tree slp_node, slp_tree *rhs_node,
    2829              :                       vect_def_type *rhs_dt_out, tree *rhs_vectype_out,
    2830              :                       vec_load_store_type *vls_type_out)
    2831              : {
    2832      1316572 :   int op_no = 0;
    2833      1316572 :   if (gcall *call = dyn_cast <gcall *> (stmt_info->stmt))
    2834              :     {
    2835         1470 :       if (gimple_call_internal_p (call)
    2836         1470 :           && internal_store_fn_p (gimple_call_internal_fn (call)))
    2837         1470 :         op_no = internal_fn_stored_value_index (gimple_call_internal_fn (call));
    2838              :     }
    2839      1316572 :   op_no = vect_slp_child_index_for_operand
    2840      1316572 :             (stmt_info->stmt, op_no, STMT_VINFO_GATHER_SCATTER_P (stmt_info));
    2841              : 
    2842      1316572 :   enum vect_def_type rhs_dt;
    2843      1316572 :   tree rhs_vectype;
    2844      1316572 :   tree rhs;
    2845      1316572 :   if (!vect_is_simple_use (vinfo, slp_node, op_no,
    2846              :                            &rhs, rhs_node, &rhs_dt, &rhs_vectype))
    2847              :     {
    2848            0 :       if (dump_enabled_p ())
    2849            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2850              :                          "use not simple.\n");
    2851            0 :       return false;
    2852              :     }
    2853              : 
    2854              :   /* In the case this is a store from a constant make sure
    2855              :      native_encode_expr can handle it.  */
    2856      1316572 :   if (rhs_dt == vect_constant_def
    2857      1316572 :       && CONSTANT_CLASS_P (rhs) && native_encode_expr (rhs, NULL, 64) == 0)
    2858              :     {
    2859            0 :       if (dump_enabled_p ())
    2860            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2861              :                          "cannot encode constant as a byte sequence.\n");
    2862            0 :       return false;
    2863              :     }
    2864              : 
    2865      1316572 :   tree vectype = SLP_TREE_VECTYPE (slp_node);
    2866      1316572 :   if (rhs_vectype && !useless_type_conversion_p (vectype, rhs_vectype))
    2867              :     {
    2868           24 :       if (dump_enabled_p ())
    2869           24 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2870              :                          "incompatible vector types.\n");
    2871           24 :       return false;
    2872              :     }
    2873              : 
    2874      1316548 :   *rhs_dt_out = rhs_dt;
    2875      1316548 :   *rhs_vectype_out = rhs_vectype;
    2876      1316548 :   if (rhs_dt == vect_constant_def || rhs_dt == vect_external_def)
    2877       990936 :     *vls_type_out = VLS_STORE_INVARIANT;
    2878              :   else
    2879       325612 :     *vls_type_out = VLS_STORE;
    2880              :   return true;
    2881              : }
    2882              : 
    2883              : /* Build an all-ones vector mask of type MASKTYPE while vectorizing STMT_INFO.
    2884              :    Note that we support masks with floating-point type, in which case the
    2885              :    floats are interpreted as a bitmask.  */
    2886              : 
    2887              : static tree
    2888          165 : vect_build_all_ones_mask (vec_info *vinfo,
    2889              :                           stmt_vec_info stmt_info, tree masktype)
    2890              : {
    2891          165 :   if (TREE_CODE (masktype) == INTEGER_TYPE)
    2892           98 :     return build_int_cst (masktype, -1);
    2893           67 :   else if (VECTOR_BOOLEAN_TYPE_P (masktype)
    2894          134 :            || TREE_CODE (TREE_TYPE (masktype)) == INTEGER_TYPE)
    2895              :     {
    2896           14 :       tree mask = build_int_cst (TREE_TYPE (masktype), -1);
    2897           14 :       mask = build_vector_from_val (masktype, mask);
    2898           14 :       return vect_init_vector (vinfo, stmt_info, mask, masktype, NULL);
    2899              :     }
    2900           53 :   else if (SCALAR_FLOAT_TYPE_P (TREE_TYPE (masktype)))
    2901              :     {
    2902              :       REAL_VALUE_TYPE r;
    2903              :       long tmp[6];
    2904          371 :       for (int j = 0; j < 6; ++j)
    2905          318 :         tmp[j] = -1;
    2906           53 :       real_from_target (&r, tmp, TYPE_MODE (TREE_TYPE (masktype)));
    2907           53 :       tree mask = build_real (TREE_TYPE (masktype), r);
    2908           53 :       mask = build_vector_from_val (masktype, mask);
    2909           53 :       return vect_init_vector (vinfo, stmt_info, mask, masktype, NULL);
    2910              :     }
    2911            0 :   gcc_unreachable ();
    2912              : }
    2913              : 
    2914              : /* Build an all-zero merge value of type VECTYPE while vectorizing
    2915              :    STMT_INFO as a gather load.  */
    2916              : 
    2917              : static tree
    2918          158 : vect_build_zero_merge_argument (vec_info *vinfo,
    2919              :                                 stmt_vec_info stmt_info, tree vectype)
    2920              : {
    2921          158 :   tree merge;
    2922          158 :   if (TREE_CODE (TREE_TYPE (vectype)) == INTEGER_TYPE)
    2923           49 :     merge = build_int_cst (TREE_TYPE (vectype), 0);
    2924          109 :   else if (SCALAR_FLOAT_TYPE_P (TREE_TYPE (vectype)))
    2925              :     {
    2926              :       REAL_VALUE_TYPE r;
    2927              :       long tmp[6];
    2928          763 :       for (int j = 0; j < 6; ++j)
    2929          654 :         tmp[j] = 0;
    2930          109 :       real_from_target (&r, tmp, TYPE_MODE (TREE_TYPE (vectype)));
    2931          109 :       merge = build_real (TREE_TYPE (vectype), r);
    2932              :     }
    2933              :   else
    2934            0 :     gcc_unreachable ();
    2935          158 :   merge = build_vector_from_val (vectype, merge);
    2936          158 :   return vect_init_vector (vinfo, stmt_info, merge, vectype, NULL);
    2937              : }
    2938              : 
    2939              : /* Return the corresponding else value for an else value constant
    2940              :    ELSVAL with type TYPE.  */
    2941              : 
    2942              : tree
    2943         1941 : vect_get_mask_load_else (int elsval, tree type)
    2944              : {
    2945         1941 :   tree els;
    2946         1941 :   if (elsval == MASK_LOAD_ELSE_UNDEFINED)
    2947              :     {
    2948            0 :       tree tmp = create_tmp_var (type);
    2949              :       /* No need to warn about anything.  */
    2950            0 :       TREE_NO_WARNING (tmp) = 1;
    2951            0 :       els = get_or_create_ssa_default_def (cfun, tmp);
    2952              :     }
    2953         1941 :   else if (elsval == MASK_LOAD_ELSE_M1)
    2954            0 :     els = build_minus_one_cst (type);
    2955         1941 :   else if (elsval == MASK_LOAD_ELSE_ZERO)
    2956         1941 :     els = build_zero_cst (type);
    2957              :   else
    2958            0 :     gcc_unreachable ();
    2959              : 
    2960         1941 :   return els;
    2961              : }
    2962              : 
    2963              : /* Build a gather load call while vectorizing STMT_INFO.  Insert new
    2964              :    instructions before GSI and add them to VEC_STMT.  GS_INFO describes
    2965              :    the gather load operation.  If the load is conditional, MASK is the
    2966              :    vectorized condition, otherwise MASK is null.  PTR is the base
    2967              :    pointer and OFFSET is the vectorized offset.  */
    2968              : 
    2969              : static gimple *
    2970          346 : vect_build_one_gather_load_call (vec_info *vinfo, stmt_vec_info stmt_info,
    2971              :                                  slp_tree slp_node, tree vectype,
    2972              :                                  gimple_stmt_iterator *gsi, tree decl,
    2973              :                                  tree ptr, tree offset, tree mask)
    2974              : {
    2975          346 :   tree arglist = TYPE_ARG_TYPES (TREE_TYPE (decl));
    2976          346 :   tree rettype = TREE_TYPE (TREE_TYPE (decl));
    2977          346 :   tree srctype = TREE_VALUE (arglist); arglist = TREE_CHAIN (arglist);
    2978          346 :   /* ptrtype */ arglist = TREE_CHAIN (arglist);
    2979          346 :   tree idxtype = TREE_VALUE (arglist); arglist = TREE_CHAIN (arglist);
    2980          346 :   tree masktype = TREE_VALUE (arglist); arglist = TREE_CHAIN (arglist);
    2981          346 :   tree scaletype = TREE_VALUE (arglist);
    2982          346 :   tree var;
    2983          346 :   gcc_checking_assert (types_compatible_p (srctype, rettype)
    2984              :                        && (!mask
    2985              :                            || TREE_CODE (masktype) == INTEGER_TYPE
    2986              :                            || types_compatible_p (srctype, masktype)));
    2987              : 
    2988          346 :   tree op = offset;
    2989          346 :   if (!useless_type_conversion_p (idxtype, TREE_TYPE (op)))
    2990              :     {
    2991          100 :       gcc_assert (known_eq (TYPE_VECTOR_SUBPARTS (TREE_TYPE (op)),
    2992              :                             TYPE_VECTOR_SUBPARTS (idxtype)));
    2993          100 :       var = vect_get_new_ssa_name (idxtype, vect_simple_var);
    2994          100 :       op = build1 (VIEW_CONVERT_EXPR, idxtype, op);
    2995          100 :       gassign *new_stmt = gimple_build_assign (var, VIEW_CONVERT_EXPR, op);
    2996          100 :       vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    2997          100 :       op = var;
    2998              :     }
    2999              : 
    3000          346 :   tree src_op = NULL_TREE;
    3001          346 :   tree mask_op = NULL_TREE;
    3002          346 :   if (mask)
    3003              :     {
    3004          188 :       if (!useless_type_conversion_p (masktype, TREE_TYPE (mask)))
    3005              :         {
    3006          188 :           tree utype, optype = TREE_TYPE (mask);
    3007          188 :           if (VECTOR_TYPE_P (masktype)
    3008          188 :               || TYPE_MODE (masktype) == TYPE_MODE (optype))
    3009              :             utype = masktype;
    3010              :           else
    3011            6 :             utype = lang_hooks.types.type_for_mode (TYPE_MODE (optype), 1);
    3012          188 :           var = vect_get_new_ssa_name (utype, vect_scalar_var);
    3013          188 :           tree mask_arg = build1 (VIEW_CONVERT_EXPR, utype, mask);
    3014          188 :           gassign *new_stmt
    3015          188 :               = gimple_build_assign (var, VIEW_CONVERT_EXPR, mask_arg);
    3016          188 :           vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    3017          188 :           mask_arg = var;
    3018          188 :           if (!useless_type_conversion_p (masktype, utype))
    3019              :             {
    3020            6 :               gcc_assert (TYPE_PRECISION (utype)
    3021              :                           <= TYPE_PRECISION (masktype));
    3022            6 :               var = vect_get_new_ssa_name (masktype, vect_scalar_var);
    3023            6 :               new_stmt = gimple_build_assign (var, NOP_EXPR, mask_arg);
    3024            6 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    3025            6 :               mask_arg = var;
    3026              :             }
    3027          188 :           src_op = build_zero_cst (srctype);
    3028          188 :           mask_op = mask_arg;
    3029              :         }
    3030              :       else
    3031              :         {
    3032              :           src_op = mask;
    3033              :           mask_op = mask;
    3034              :         }
    3035              :     }
    3036              :   else
    3037              :     {
    3038          158 :       src_op = vect_build_zero_merge_argument (vinfo, stmt_info, rettype);
    3039          158 :       mask_op = vect_build_all_ones_mask (vinfo, stmt_info, masktype);
    3040              :     }
    3041              : 
    3042          346 :   tree scale = build_int_cst (scaletype, SLP_TREE_GS_SCALE (slp_node));
    3043          346 :   gimple *new_stmt = gimple_build_call (decl, 5, src_op, ptr, op,
    3044              :                                         mask_op, scale);
    3045              : 
    3046          346 :   if (!useless_type_conversion_p (vectype, rettype))
    3047              :     {
    3048           49 :       gcc_assert (known_eq (TYPE_VECTOR_SUBPARTS (vectype),
    3049              :                             TYPE_VECTOR_SUBPARTS (rettype)));
    3050           49 :       op = vect_get_new_ssa_name (rettype, vect_simple_var);
    3051           49 :       gimple_call_set_lhs (new_stmt, op);
    3052           49 :       vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    3053           49 :       op = build1 (VIEW_CONVERT_EXPR, vectype, op);
    3054           49 :       new_stmt = gimple_build_assign (NULL_TREE, VIEW_CONVERT_EXPR, op);
    3055              :     }
    3056              : 
    3057          346 :   return new_stmt;
    3058              : }
    3059              : 
    3060              : /* Build a scatter store call while vectorizing STMT_INFO.  Insert new
    3061              :    instructions before GSI.  GS_INFO describes the scatter store operation.
    3062              :    PTR is the base pointer, OFFSET the vectorized offsets and OPRND the
    3063              :    vectorized data to store.
    3064              :    If the store is conditional, MASK is the vectorized condition, otherwise
    3065              :    MASK is null.  */
    3066              : 
    3067              : static gimple *
    3068          161 : vect_build_one_scatter_store_call (vec_info *vinfo, stmt_vec_info stmt_info,
    3069              :                                    slp_tree slp_node,
    3070              :                                    gimple_stmt_iterator *gsi,
    3071              :                                    tree decl,
    3072              :                                    tree ptr, tree offset, tree oprnd, tree mask)
    3073              : {
    3074          161 :   tree rettype = TREE_TYPE (TREE_TYPE (decl));
    3075          161 :   tree arglist = TYPE_ARG_TYPES (TREE_TYPE (decl));
    3076          161 :   /* tree ptrtype = TREE_VALUE (arglist); */ arglist = TREE_CHAIN (arglist);
    3077          161 :   tree masktype = TREE_VALUE (arglist); arglist = TREE_CHAIN (arglist);
    3078          161 :   tree idxtype = TREE_VALUE (arglist); arglist = TREE_CHAIN (arglist);
    3079          161 :   tree srctype = TREE_VALUE (arglist); arglist = TREE_CHAIN (arglist);
    3080          161 :   tree scaletype = TREE_VALUE (arglist);
    3081          161 :   gcc_checking_assert (TREE_CODE (masktype) == INTEGER_TYPE
    3082              :                        && TREE_CODE (rettype) == VOID_TYPE);
    3083              : 
    3084          161 :   tree mask_arg = NULL_TREE;
    3085          161 :   if (mask)
    3086              :     {
    3087          110 :       mask_arg = mask;
    3088          110 :       tree optype = TREE_TYPE (mask_arg);
    3089          110 :       tree utype;
    3090          110 :       if (TYPE_MODE (masktype) == TYPE_MODE (optype))
    3091              :         utype = masktype;
    3092              :       else
    3093            8 :         utype = lang_hooks.types.type_for_mode (TYPE_MODE (optype), 1);
    3094          110 :       tree var = vect_get_new_ssa_name (utype, vect_scalar_var);
    3095          110 :       mask_arg = build1 (VIEW_CONVERT_EXPR, utype, mask_arg);
    3096          110 :       gassign *new_stmt
    3097          110 :         = gimple_build_assign (var, VIEW_CONVERT_EXPR, mask_arg);
    3098          110 :       vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    3099          110 :       mask_arg = var;
    3100          110 :       if (!useless_type_conversion_p (masktype, utype))
    3101              :         {
    3102            8 :           gcc_assert (TYPE_PRECISION (utype) <= TYPE_PRECISION (masktype));
    3103            8 :           tree var = vect_get_new_ssa_name (masktype, vect_scalar_var);
    3104            8 :           new_stmt = gimple_build_assign (var, NOP_EXPR, mask_arg);
    3105            8 :           vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    3106            8 :           mask_arg = var;
    3107              :         }
    3108              :     }
    3109              :   else
    3110              :     {
    3111           51 :       mask_arg = build_int_cst (masktype, -1);
    3112           51 :       mask_arg = vect_init_vector (vinfo, stmt_info, mask_arg, masktype, NULL);
    3113              :     }
    3114              : 
    3115          161 :   tree src = oprnd;
    3116          161 :   if (!useless_type_conversion_p (srctype, TREE_TYPE (src)))
    3117              :     {
    3118            0 :       gcc_assert (known_eq (TYPE_VECTOR_SUBPARTS (TREE_TYPE (src)),
    3119              :                             TYPE_VECTOR_SUBPARTS (srctype)));
    3120            0 :       tree var = vect_get_new_ssa_name (srctype, vect_simple_var);
    3121            0 :       src = build1 (VIEW_CONVERT_EXPR, srctype, src);
    3122            0 :       gassign *new_stmt = gimple_build_assign (var, VIEW_CONVERT_EXPR, src);
    3123            0 :       vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    3124            0 :       src = var;
    3125              :     }
    3126              : 
    3127          161 :   tree op = offset;
    3128          161 :   if (!useless_type_conversion_p (idxtype, TREE_TYPE (op)))
    3129              :     {
    3130           16 :       gcc_assert (known_eq (TYPE_VECTOR_SUBPARTS (TREE_TYPE (op)),
    3131              :                             TYPE_VECTOR_SUBPARTS (idxtype)));
    3132           16 :       tree var = vect_get_new_ssa_name (idxtype, vect_simple_var);
    3133           16 :       op = build1 (VIEW_CONVERT_EXPR, idxtype, op);
    3134           16 :       gassign *new_stmt = gimple_build_assign (var, VIEW_CONVERT_EXPR, op);
    3135           16 :       vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    3136           16 :       op = var;
    3137              :     }
    3138              : 
    3139          161 :   tree scale = build_int_cst (scaletype, SLP_TREE_GS_SCALE (slp_node));
    3140          161 :   gcall *new_stmt
    3141          161 :     = gimple_build_call (decl, 5, ptr, mask_arg, op, src, scale);
    3142          161 :   return new_stmt;
    3143              : }
    3144              : 
    3145              : /* Prepare the base and offset in GS_INFO for vectorization.
    3146              :    Set *DATAREF_PTR to the loop-invariant base address and *VEC_OFFSET
    3147              :    to the vectorized offset argument for the first copy of STMT_INFO.
    3148              :    STMT_INFO is the statement described by GS_INFO and LOOP is the
    3149              :    containing loop.  */
    3150              : 
    3151              : static void
    3152         1219 : vect_get_gather_scatter_ops (class loop *loop, slp_tree slp_node,
    3153              :                              tree *dataref_ptr, vec<tree> *vec_offset)
    3154              : {
    3155         1219 :   gimple_seq stmts = NULL;
    3156         1219 :   *dataref_ptr = force_gimple_operand (SLP_TREE_GS_BASE (slp_node),
    3157              :                                        &stmts, true, NULL_TREE);
    3158         1219 :   if (stmts != NULL)
    3159              :     {
    3160          986 :       basic_block new_bb;
    3161          986 :       edge pe = loop_preheader_edge (loop);
    3162          986 :       new_bb = gsi_insert_seq_on_edge_immediate (pe, stmts);
    3163          986 :       gcc_assert (!new_bb);
    3164              :     }
    3165         1219 :   vect_get_slp_defs (SLP_TREE_CHILDREN (slp_node)[0], vec_offset);
    3166         1219 : }
    3167              : 
    3168              : /* Prepare to implement a grouped or strided load or store using
    3169              :    the gather load or scatter store operation described by GS_INFO.
    3170              :    STMT_INFO is the load or store statement.
    3171              : 
    3172              :    Set *DATAREF_BUMP to the amount that should be added to the base
    3173              :    address after each copy of the vectorized statement.  Set *VEC_OFFSET
    3174              :    to an invariant offset vector in which element I has the value
    3175              :    I * DR_STEP / SCALE.  */
    3176              : 
    3177              : static void
    3178            0 : vect_get_strided_load_store_ops (stmt_vec_info stmt_info, slp_tree node,
    3179              :                                  tree vectype, tree offset_vectype,
    3180              :                                  loop_vec_info loop_vinfo,
    3181              :                                  gimple_stmt_iterator *gsi,
    3182              :                                  tree *dataref_bump, tree *vec_offset,
    3183              :                                  vec_loop_lens *loop_lens)
    3184              : {
    3185            0 :   struct data_reference *dr = STMT_VINFO_DATA_REF (stmt_info);
    3186              : 
    3187            0 :   if (LOOP_VINFO_USING_SELECT_VL_P (loop_vinfo))
    3188              :     {
    3189              :       /* _31 = .SELECT_VL (ivtmp_29, POLY_INT_CST [4, 4]);
    3190              :          ivtmp_8 = _31 * 16 (step in bytes);
    3191              :          .MASK_LEN_SCATTER_STORE (vectp_a.9_7, ... );
    3192              :          vectp_a.9_26 = vectp_a.9_7 + ivtmp_8;  */
    3193            0 :       tree loop_len
    3194            0 :         = vect_get_loop_len (loop_vinfo, gsi, loop_lens, 1, vectype, 0, 0, true);
    3195            0 :       tree tmp
    3196            0 :         = fold_build2 (MULT_EXPR, sizetype,
    3197              :                        fold_convert (sizetype, unshare_expr (DR_STEP (dr))),
    3198              :                        loop_len);
    3199            0 :       *dataref_bump = force_gimple_operand_gsi (gsi, tmp, true, NULL_TREE, true,
    3200              :                                                 GSI_SAME_STMT);
    3201              :     }
    3202              :   else
    3203              :     {
    3204            0 :       tree bump
    3205            0 :         = size_binop (MULT_EXPR,
    3206              :                       fold_convert (sizetype, unshare_expr (DR_STEP (dr))),
    3207              :                       size_int (TYPE_VECTOR_SUBPARTS (vectype)));
    3208            0 :       *dataref_bump = cse_and_gimplify_to_preheader (loop_vinfo, bump);
    3209              :     }
    3210              : 
    3211            0 :   internal_fn ifn
    3212            0 :     = DR_IS_READ (dr) ? IFN_MASK_LEN_STRIDED_LOAD : IFN_MASK_LEN_STRIDED_STORE;
    3213            0 :   if (direct_internal_fn_supported_p (ifn, vectype, OPTIMIZE_FOR_SPEED))
    3214              :     {
    3215            0 :       *vec_offset = cse_and_gimplify_to_preheader (loop_vinfo,
    3216              :                                                    unshare_expr (DR_STEP (dr)));
    3217            0 :       return;
    3218              :     }
    3219              : 
    3220              :   /* The offset given in GS_INFO can have pointer type, so use the element
    3221              :      type of the vector instead.  */
    3222            0 :   tree offset_type = TREE_TYPE (offset_vectype);
    3223              : 
    3224              :   /* Calculate X = DR_STEP / SCALE and convert it to the appropriate type.  */
    3225            0 :   tree step = size_binop (EXACT_DIV_EXPR, unshare_expr (DR_STEP (dr)),
    3226              :                           ssize_int (SLP_TREE_GS_SCALE (node)));
    3227            0 :   step = fold_convert (offset_type, step);
    3228              : 
    3229              :   /* Create {0, X, X*2, X*3, ...}.  */
    3230            0 :   tree offset = fold_build2 (VEC_SERIES_EXPR, offset_vectype,
    3231              :                              build_zero_cst (offset_type), step);
    3232            0 :   *vec_offset = cse_and_gimplify_to_preheader (loop_vinfo, offset);
    3233              : }
    3234              : 
    3235              : /* Prepare the pointer IVs which needs to be updated by a variable amount.
    3236              :    Such variable amount is the outcome of .SELECT_VL. In this case, we can
    3237              :    allow each iteration process the flexible number of elements as long as
    3238              :    the number <= vf elments.
    3239              : 
    3240              :    Return data reference according to SELECT_VL.
    3241              :    If new statements are needed, insert them before GSI.  */
    3242              : 
    3243              : static tree
    3244            0 : vect_get_loop_variant_data_ptr_increment (
    3245              :   vec_info *vinfo, tree aggr_type, gimple_stmt_iterator *gsi,
    3246              :   vec_loop_lens *loop_lens, dr_vec_info *dr_info,
    3247              :   vect_memory_access_type memory_access_type)
    3248              : {
    3249            0 :   loop_vec_info loop_vinfo = dyn_cast<loop_vec_info> (vinfo);
    3250            0 :   tree step = vect_dr_behavior (vinfo, dr_info)->step;
    3251              : 
    3252              :   /* gather/scatter never reach here.  */
    3253            0 :   gcc_assert (!mat_gather_scatter_p (memory_access_type));
    3254              : 
    3255              :   /* When we support SELECT_VL pattern, we dynamic adjust
    3256              :      the memory address by .SELECT_VL result.
    3257              : 
    3258              :      The result of .SELECT_VL is the number of elements to
    3259              :      be processed of each iteration. So the memory address
    3260              :      adjustment operation should be:
    3261              : 
    3262              :      addr = addr + .SELECT_VL (ARG..) * step;
    3263              :   */
    3264            0 :   tree loop_len
    3265            0 :     = vect_get_loop_len (loop_vinfo, gsi, loop_lens, 1, aggr_type, 0, 0, true);
    3266            0 :   tree len_type = TREE_TYPE (loop_len);
    3267              :   /* Since the outcome of .SELECT_VL is element size, we should adjust
    3268              :      it into bytesize so that it can be used in address pointer variable
    3269              :      amount IVs adjustment.  */
    3270            0 :   tree tmp = fold_build2 (MULT_EXPR, len_type, loop_len,
    3271              :                           wide_int_to_tree (len_type, wi::to_widest (step)));
    3272            0 :   tree bump = make_temp_ssa_name (len_type, NULL, "ivtmp");
    3273            0 :   gassign *assign = gimple_build_assign (bump, tmp);
    3274            0 :   gsi_insert_before (gsi, assign, GSI_SAME_STMT);
    3275            0 :   return bump;
    3276              : }
    3277              : 
    3278              : /* Return the amount that should be added to a vector pointer to move
    3279              :    to the next or previous copy of AGGR_TYPE.  DR_INFO is the data reference
    3280              :    being vectorized and MEMORY_ACCESS_TYPE describes the type of
    3281              :    vectorization.  */
    3282              : 
    3283              : static tree
    3284       700634 : vect_get_data_ptr_increment (vec_info *vinfo, gimple_stmt_iterator *gsi,
    3285              :                              dr_vec_info *dr_info, tree aggr_type,
    3286              :                              vect_memory_access_type memory_access_type,
    3287              :                              vec_loop_lens *loop_lens)
    3288              : {
    3289       700634 :   if (memory_access_type == VMAT_INVARIANT)
    3290            0 :     return size_zero_node;
    3291              : 
    3292       700634 :   loop_vec_info loop_vinfo = dyn_cast<loop_vec_info> (vinfo);
    3293       134912 :   if (loop_vinfo && LOOP_VINFO_USING_SELECT_VL_P (loop_vinfo))
    3294            0 :     return vect_get_loop_variant_data_ptr_increment (vinfo, aggr_type, gsi,
    3295              :                                                      loop_lens, dr_info,
    3296            0 :                                                      memory_access_type);
    3297              : 
    3298       700634 :   tree iv_step = TYPE_SIZE_UNIT (aggr_type);
    3299       700634 :   tree step = vect_dr_behavior (vinfo, dr_info)->step;
    3300       700634 :   if (tree_int_cst_sgn (step) == -1)
    3301         2828 :     iv_step = fold_build1 (NEGATE_EXPR, TREE_TYPE (iv_step), iv_step);
    3302              :   return iv_step;
    3303              : }
    3304              : 
    3305              : /* Check and perform vectorization of BUILT_IN_BSWAP{16,32,64,128}.  */
    3306              : 
    3307              : static bool
    3308          206 : vectorizable_bswap (vec_info *vinfo,
    3309              :                     stmt_vec_info stmt_info, gimple_stmt_iterator *gsi,
    3310              :                     slp_tree slp_node,
    3311              :                     slp_tree *slp_op,
    3312              :                     tree vectype_in, stmt_vector_for_cost *cost_vec)
    3313              : {
    3314          206 :   tree op, vectype;
    3315          206 :   gcall *stmt = as_a <gcall *> (stmt_info->stmt);
    3316              : 
    3317          206 :   op = gimple_call_arg (stmt, 0);
    3318          206 :   vectype = SLP_TREE_VECTYPE (slp_node);
    3319          206 :   poly_uint64 nunits = TYPE_VECTOR_SUBPARTS (vectype);
    3320              : 
    3321          206 :   if (TYPE_SIZE (vectype_in) != TYPE_SIZE (vectype))
    3322              :     {
    3323            0 :       if (dump_enabled_p ())
    3324            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    3325              :                          "mismatched vector sizes %T and %T\n",
    3326              :                          vectype_in, vectype);
    3327            0 :       return false;
    3328              :     }
    3329              : 
    3330          206 :   tree char_vectype = get_same_sized_vectype (char_type_node, vectype_in);
    3331          206 :   if (! char_vectype)
    3332              :     return false;
    3333              : 
    3334          206 :   poly_uint64 num_bytes = TYPE_VECTOR_SUBPARTS (char_vectype);
    3335          206 :   unsigned word_bytes;
    3336          206 :   if (!constant_multiple_p (num_bytes, nunits, &word_bytes))
    3337              :     return false;
    3338              : 
    3339              :   /* The encoding uses one stepped pattern for each byte in the word.  */
    3340          206 :   vec_perm_builder elts (num_bytes, word_bytes, 3);
    3341          824 :   for (unsigned i = 0; i < 3; ++i)
    3342         3318 :     for (unsigned j = 0; j < word_bytes; ++j)
    3343         2700 :       elts.quick_push ((i + 1) * word_bytes - j - 1);
    3344              : 
    3345          206 :   vec_perm_indices indices (elts, 1, num_bytes);
    3346          206 :   machine_mode vmode = TYPE_MODE (char_vectype);
    3347          206 :   if (!can_vec_perm_const_p (vmode, vmode, indices))
    3348              :     return false;
    3349              : 
    3350          152 :   if (cost_vec)
    3351              :     {
    3352          140 :       if (!vect_maybe_update_slp_op_vectype (slp_op[0], vectype_in))
    3353              :         {
    3354            0 :           if (dump_enabled_p ())
    3355            0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    3356              :                              "incompatible vector types for invariants\n");
    3357            0 :           return false;
    3358              :         }
    3359              : 
    3360          140 :       SLP_TREE_TYPE (slp_node) = call_vec_info_type;
    3361          140 :       DUMP_VECT_SCOPE ("vectorizable_bswap");
    3362          140 :       record_stmt_cost (cost_vec,
    3363              :                         1, vector_stmt, slp_node, 0, vect_prologue);
    3364          140 :       record_stmt_cost (cost_vec,
    3365          140 :                         vect_get_num_copies (vinfo, slp_node),
    3366              :                         vec_perm, slp_node, 0, vect_body);
    3367          140 :       return true;
    3368              :     }
    3369              : 
    3370           12 :   tree bswap_vconst = vec_perm_indices_to_tree (char_vectype, indices);
    3371              : 
    3372              :   /* Transform.  */
    3373           12 :   vec<tree> vec_oprnds = vNULL;
    3374           12 :   vect_get_vec_defs (vinfo, slp_node, op, &vec_oprnds);
    3375              :   /* Arguments are ready. create the new vector stmt.  */
    3376           12 :   unsigned i;
    3377           12 :   tree vop;
    3378           24 :   FOR_EACH_VEC_ELT (vec_oprnds, i, vop)
    3379              :     {
    3380           12 :       gimple *new_stmt;
    3381           12 :       tree tem = make_ssa_name (char_vectype);
    3382           12 :       new_stmt = gimple_build_assign (tem, build1 (VIEW_CONVERT_EXPR,
    3383              :                                                    char_vectype, vop));
    3384           12 :       vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    3385           12 :       tree tem2 = make_ssa_name (char_vectype);
    3386           12 :       new_stmt = gimple_build_assign (tem2, VEC_PERM_EXPR,
    3387              :                                       tem, tem, bswap_vconst);
    3388           12 :       vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    3389           12 :       tem = make_ssa_name (vectype);
    3390           12 :       new_stmt = gimple_build_assign (tem, build1 (VIEW_CONVERT_EXPR,
    3391              :                                                    vectype, tem2));
    3392           12 :       vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    3393           12 :       slp_node->push_vec_def (new_stmt);
    3394              :     }
    3395              : 
    3396           12 :   vec_oprnds.release ();
    3397           12 :   return true;
    3398          206 : }
    3399              : 
    3400              : /* Return true if vector types VECTYPE_IN and VECTYPE_OUT have
    3401              :    integer elements and if we can narrow VECTYPE_IN to VECTYPE_OUT
    3402              :    in a single step.  On success, store the binary pack code in
    3403              :    *CONVERT_CODE.  */
    3404              : 
    3405              : static bool
    3406          156 : simple_integer_narrowing (tree vectype_out, tree vectype_in,
    3407              :                           code_helper *convert_code)
    3408              : {
    3409          312 :   if (!INTEGRAL_TYPE_P (TREE_TYPE (vectype_out))
    3410          312 :       || !INTEGRAL_TYPE_P (TREE_TYPE (vectype_in)))
    3411              :     return false;
    3412              : 
    3413           66 :   code_helper code;
    3414           66 :   int multi_step_cvt = 0;
    3415           66 :   auto_vec <tree, 8> interm_types;
    3416           97 :   if (!supportable_narrowing_operation (NOP_EXPR, vectype_out, vectype_in,
    3417              :                                         &code, &multi_step_cvt, &interm_types)
    3418           66 :       || multi_step_cvt)
    3419           31 :     return false;
    3420              : 
    3421           35 :   *convert_code = code;
    3422           35 :   return true;
    3423           66 : }
    3424              : 
    3425              : /* Function vectorizable_call.
    3426              : 
    3427              :    Check if STMT_INFO performs a function call that can be vectorized.
    3428              :    If COST_VEC is passed, calculate costs but don't change anything,
    3429              :    otherwise, vectorize STMT_INFO: create a vectorized stmt to replace
    3430              :    it, and insert it at GSI.
    3431              :    Return true if STMT_INFO is vectorizable in this way.  */
    3432              : 
    3433              : static bool
    3434      2334134 : vectorizable_call (vec_info *vinfo,
    3435              :                    stmt_vec_info stmt_info, gimple_stmt_iterator *gsi,
    3436              :                    slp_tree slp_node,
    3437              :                    stmt_vector_for_cost *cost_vec)
    3438              : {
    3439      2334134 :   gcall *stmt;
    3440      2334134 :   tree vec_dest;
    3441      2334134 :   tree scalar_dest;
    3442      2334134 :   tree op;
    3443      2334134 :   tree vec_oprnd0 = NULL_TREE;
    3444      2334134 :   tree vectype_out, vectype_in;
    3445      2334134 :   poly_uint64 nunits_in;
    3446      2334134 :   poly_uint64 nunits_out;
    3447      2334134 :   loop_vec_info loop_vinfo = dyn_cast <loop_vec_info> (vinfo);
    3448      2334134 :   bb_vec_info bb_vinfo = dyn_cast <bb_vec_info> (vinfo);
    3449      2334134 :   tree fndecl, new_temp, rhs_type;
    3450      2334134 :   enum vect_def_type dt[5]
    3451              :     = { vect_unknown_def_type, vect_unknown_def_type, vect_unknown_def_type,
    3452              :         vect_unknown_def_type, vect_unknown_def_type };
    3453      2334134 :   tree vectypes[ARRAY_SIZE (dt)] = {};
    3454      2334134 :   slp_tree slp_op[ARRAY_SIZE (dt)] = {};
    3455      2334134 :   auto_vec<tree, 8> vargs;
    3456      2334134 :   enum { NARROW, NONE, WIDEN } modifier;
    3457      2334134 :   size_t i, nargs;
    3458      2334134 :   tree clz_ctz_arg1 = NULL_TREE;
    3459              : 
    3460      2334134 :   if (!STMT_VINFO_RELEVANT_P (stmt_info) && !bb_vinfo)
    3461              :     return false;
    3462              : 
    3463      2334134 :   if (STMT_VINFO_DEF_TYPE (stmt_info) != vect_internal_def
    3464       194522 :       && cost_vec)
    3465              :     return false;
    3466              : 
    3467              :   /* Is STMT_INFO a vectorizable call?   */
    3468      2343683 :   stmt = dyn_cast <gcall *> (stmt_info->stmt);
    3469        19326 :   if (!stmt)
    3470              :     return false;
    3471              : 
    3472        19326 :   if (gimple_call_internal_p (stmt)
    3473        19326 :       && (internal_load_fn_p (gimple_call_internal_fn (stmt))
    3474        12184 :           || internal_store_fn_p (gimple_call_internal_fn (stmt))))
    3475              :     /* Handled by vectorizable_load and vectorizable_store.  */
    3476         2692 :     return false;
    3477              : 
    3478        16634 :   if (gimple_call_lhs (stmt) == NULL_TREE
    3479        16634 :       || TREE_CODE (gimple_call_lhs (stmt)) != SSA_NAME)
    3480              :     return false;
    3481              : 
    3482        16628 :   gcc_checking_assert (!stmt_can_throw_internal (cfun, stmt));
    3483              : 
    3484        16628 :   vectype_out = SLP_TREE_VECTYPE (slp_node);
    3485              : 
    3486              :   /* Process function arguments.  */
    3487        16628 :   rhs_type = NULL_TREE;
    3488        16628 :   vectype_in = NULL_TREE;
    3489        16628 :   nargs = gimple_call_num_args (stmt);
    3490              : 
    3491              :   /* Bail out if the function has more than four arguments, we do not have
    3492              :      interesting builtin functions to vectorize with more than two arguments
    3493              :      except for fma (cond_fma has more).  No arguments is also not good.  */
    3494        16628 :   if (nargs == 0 || nargs > 5)
    3495              :     return false;
    3496              : 
    3497              :   /* Ignore the arguments of IFN_GOMP_SIMD_LANE, they are magic.  */
    3498        16548 :   combined_fn cfn = gimple_call_combined_fn (stmt);
    3499        16548 :   if (cfn == CFN_GOMP_SIMD_LANE)
    3500              :     {
    3501         3207 :       nargs = 0;
    3502         3207 :       rhs_type = unsigned_type_node;
    3503              :     }
    3504              :   /* Similarly pretend IFN_CLZ and IFN_CTZ only has one argument, the second
    3505              :      argument just says whether it is well-defined at zero or not and what
    3506              :      value should be returned for it.  */
    3507        16548 :   if ((cfn == CFN_CLZ || cfn == CFN_CTZ) && nargs == 2)
    3508              :     {
    3509          118 :       nargs = 1;
    3510          118 :       clz_ctz_arg1 = gimple_call_arg (stmt, 1);
    3511              :     }
    3512              : 
    3513        16548 :   int mask_opno = -1;
    3514        16548 :   if (internal_fn_p (cfn))
    3515              :     {
    3516              :       /* We can only handle direct internal masked calls here,
    3517              :          vectorizable_simd_clone_call is for the rest.  */
    3518        14081 :       if (cfn == CFN_MASK_CALL)
    3519              :         return false;
    3520        13927 :       mask_opno = internal_fn_mask_index (as_internal_fn (cfn));
    3521              :     }
    3522              : 
    3523        45912 :   for (i = 0; i < nargs; i++)
    3524              :     {
    3525        30762 :       if ((int) i == mask_opno)
    3526              :         {
    3527         4220 :           if (!vect_check_scalar_mask (vinfo, slp_node, mask_opno,
    3528              :                                        &slp_op[i], &dt[i], &vectypes[i]))
    3529              :             return false;
    3530         4220 :           continue;
    3531              :         }
    3532              : 
    3533        26542 :       if (!vect_is_simple_use (vinfo, slp_node,
    3534              :                                i, &op, &slp_op[i], &dt[i], &vectypes[i]))
    3535              :         {
    3536            0 :           if (dump_enabled_p ())
    3537            0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    3538              :                              "use not simple.\n");
    3539            0 :           return false;
    3540              :         }
    3541              : 
    3542              :       /* We can only handle calls with arguments of the same type.  */
    3543        26542 :       if (rhs_type
    3544        26542 :           && !types_compatible_p (rhs_type, TREE_TYPE (op)))
    3545              :         {
    3546         1244 :           if (dump_enabled_p ())
    3547          200 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    3548              :                              "argument types differ.\n");
    3549         1244 :           return false;
    3550              :         }
    3551        25298 :       if (!rhs_type)
    3552        13187 :         rhs_type = TREE_TYPE (op);
    3553              : 
    3554        25298 :       if (!vectype_in)
    3555        13642 :         vectype_in = vectypes[i];
    3556        11656 :       else if (vectypes[i]
    3557        11656 :                && !types_compatible_p (vectypes[i], vectype_in))
    3558              :         {
    3559            0 :           if (dump_enabled_p ())
    3560            0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    3561              :                              "argument vector types differ.\n");
    3562            0 :           return false;
    3563              :         }
    3564              :     }
    3565              :   /* If all arguments are external or constant defs, infer the vector type
    3566              :      from the scalar type.  */
    3567        15150 :   if (!vectype_in)
    3568         5554 :     vectype_in = get_vectype_for_scalar_type (vinfo, rhs_type, slp_node);
    3569        15150 :   if (!cost_vec)
    3570         4210 :     gcc_assert (vectype_in);
    3571        10940 :   if (!vectype_in)
    3572              :     {
    3573         1065 :       if (dump_enabled_p ())
    3574            4 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    3575              :                          "no vectype for scalar type %T\n", rhs_type);
    3576              : 
    3577         1065 :       return false;
    3578              :     }
    3579              : 
    3580        28170 :   if (VECTOR_BOOLEAN_TYPE_P (vectype_out)
    3581        14085 :       != VECTOR_BOOLEAN_TYPE_P (vectype_in))
    3582              :     {
    3583           12 :       if (dump_enabled_p ())
    3584           12 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    3585              :                          "mixed mask and nonmask vector types\n");
    3586           12 :       return false;
    3587              :     }
    3588              : 
    3589        14073 :   if (vect_emulated_vector_p (vectype_in)
    3590        14073 :       || vect_emulated_vector_p (vectype_out))
    3591              :     {
    3592            0 :       if (dump_enabled_p ())
    3593            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    3594              :                          "use emulated vector type for call\n");
    3595            0 :       return false;
    3596              :     }
    3597              : 
    3598              :   /* FORNOW */
    3599        14073 :   nunits_in = TYPE_VECTOR_SUBPARTS (vectype_in);
    3600        14073 :   nunits_out = TYPE_VECTOR_SUBPARTS (vectype_out);
    3601        14073 :   if (known_eq (nunits_in * 2, nunits_out))
    3602              :     modifier = NARROW;
    3603        13530 :   else if (known_eq (nunits_out, nunits_in))
    3604              :     modifier = NONE;
    3605           45 :   else if (known_eq (nunits_out * 2, nunits_in))
    3606              :     modifier = WIDEN;
    3607              :   else
    3608              :     return false;
    3609              : 
    3610              :   /* We only handle functions that do not read or clobber memory.  */
    3611        28146 :   if (gimple_vuse (stmt))
    3612              :     {
    3613         1241 :       if (dump_enabled_p ())
    3614           14 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    3615              :                          "function reads from or writes to memory.\n");
    3616         1241 :       return false;
    3617              :     }
    3618              : 
    3619              :   /* For now, we only vectorize functions if a target specific builtin
    3620              :      is available.  TODO -- in some cases, it might be profitable to
    3621              :      insert the calls for pieces of the vector, in order to be able
    3622              :      to vectorize other operations in the loop.  */
    3623        12832 :   fndecl = NULL_TREE;
    3624        12832 :   internal_fn ifn = IFN_LAST;
    3625        12832 :   tree callee = gimple_call_fndecl (stmt);
    3626              : 
    3627              :   /* First try using an internal function.  */
    3628        12832 :   code_helper convert_code = MAX_TREE_CODES;
    3629        12832 :   if (cfn != CFN_LAST
    3630        12832 :       && (modifier == NONE
    3631          168 :           || (modifier == NARROW
    3632          156 :               && simple_integer_narrowing (vectype_out, vectype_in,
    3633              :                                            &convert_code))))
    3634        11866 :     ifn = vectorizable_internal_function (cfn, callee, vectype_out,
    3635              :                                           vectype_in);
    3636              : 
    3637              :   /* Check if the operation traps.  */
    3638        12832 :   bool could_trap = gimple_could_trap_p (STMT_VINFO_STMT (stmt_info));
    3639        12832 :   if (could_trap && cost_vec && loop_vinfo)
    3640              :     {
    3641              :       /* If the operation can trap it must be conditional, otherwise fail.  */
    3642          414 :       internal_fn cond_fn = (internal_fn_mask_index (ifn) != -1
    3643          414 :                              ? ifn : get_conditional_internal_fn (ifn));
    3644          414 :       internal_fn cond_len_fn = get_len_internal_fn (cond_fn);
    3645          414 :       if (LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo))
    3646              :         {
    3647              :           /* We assume that BB SLP fills all lanes, so no inactive lanes can
    3648              :              cause issues.  */
    3649           52 :           if ((cond_fn == IFN_LAST
    3650           35 :                || !direct_internal_fn_supported_p (cond_fn, vectype_out,
    3651              :                                                    OPTIMIZE_FOR_SPEED))
    3652           87 :               && (cond_len_fn == IFN_LAST
    3653           35 :                   || !direct_internal_fn_supported_p (cond_len_fn, vectype_out,
    3654              :                                                       OPTIMIZE_FOR_SPEED)))
    3655              :             {
    3656           52 :               if (dump_enabled_p ())
    3657           10 :                 dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    3658              :                                  "can't use a fully-masked loop because no"
    3659              :                                  " conditional operation is available.\n");
    3660           52 :               LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo) = false;
    3661              :             }
    3662              :         }
    3663              :     }
    3664              : 
    3665              :   /* If that fails, try asking for a target-specific built-in function.  */
    3666        12832 :   if (ifn == IFN_LAST)
    3667              :     {
    3668         6762 :       if (cfn != CFN_LAST)
    3669         5929 :         fndecl = targetm.vectorize.builtin_vectorized_function
    3670         5929 :           (cfn, vectype_out, vectype_in);
    3671          833 :       else if (callee && fndecl_built_in_p (callee, BUILT_IN_MD))
    3672           24 :         fndecl = targetm.vectorize.builtin_md_vectorized_function
    3673           24 :           (callee, vectype_out, vectype_in);
    3674              :     }
    3675              : 
    3676        12832 :   if (ifn == IFN_LAST && !fndecl)
    3677              :     {
    3678         6468 :       if (cfn == CFN_GOMP_SIMD_LANE
    3679         3207 :           && SLP_TREE_LANES (slp_node) == 1
    3680         3207 :           && loop_vinfo
    3681         3207 :           && LOOP_VINFO_LOOP (loop_vinfo)->simduid
    3682         3207 :           && TREE_CODE (gimple_call_arg (stmt, 0)) == SSA_NAME
    3683        12882 :           && LOOP_VINFO_LOOP (loop_vinfo)->simduid
    3684         3207 :              == SSA_NAME_VAR (gimple_call_arg (stmt, 0)))
    3685              :         {
    3686              :           /* We can handle IFN_GOMP_SIMD_LANE by returning a
    3687              :              { 0, 1, 2, ... vf - 1 } vector.  */
    3688         3207 :           gcc_assert (nargs == 0);
    3689              :         }
    3690         3261 :       else if (modifier == NONE
    3691         3261 :                && (gimple_call_builtin_p (stmt, BUILT_IN_BSWAP16)
    3692         2931 :                    || gimple_call_builtin_p (stmt, BUILT_IN_BSWAP32)
    3693         2783 :                    || gimple_call_builtin_p (stmt, BUILT_IN_BSWAP64)
    3694         2751 :                    || gimple_call_builtin_p (stmt, BUILT_IN_BSWAP128)))
    3695          206 :         return vectorizable_bswap (vinfo, stmt_info, gsi, slp_node,
    3696          206 :                                    slp_op, vectype_in, cost_vec);
    3697              :       else
    3698              :         {
    3699         3055 :           if (dump_enabled_p ())
    3700          266 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    3701              :                              "function is not vectorizable.\n");
    3702         3055 :           return false;
    3703              :         }
    3704              :     }
    3705              : 
    3706         9571 :   int reduc_idx = SLP_TREE_REDUC_IDX (slp_node);
    3707         9571 :   internal_fn cond_fn = (internal_fn_mask_index (ifn) != -1
    3708         9571 :                          ? ifn : get_conditional_internal_fn (ifn));
    3709         9571 :   internal_fn cond_len_fn = get_len_internal_fn (cond_fn);
    3710         9571 :   vec_loop_masks *masks = (loop_vinfo ? &LOOP_VINFO_MASKS (loop_vinfo) : NULL);
    3711         7691 :   vec_loop_lens *lens = (loop_vinfo ? &LOOP_VINFO_LENS (loop_vinfo) : NULL);
    3712         9571 :   unsigned int nvectors = vect_get_num_copies (vinfo, slp_node);
    3713         9571 :   if (cost_vec) /* transformation not required.  */
    3714              :     {
    3715        16386 :       for (i = 0; i < nargs; ++i)
    3716        11013 :         if (!vect_maybe_update_slp_op_vectype (slp_op[i],
    3717        11013 :                                                vectypes[i]
    3718              :                                                ? vectypes[i] : vectype_in))
    3719              :           {
    3720            0 :             if (dump_enabled_p ())
    3721            0 :               dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    3722              :                                "incompatible vector types for invariants\n");
    3723            0 :             return false;
    3724              :           }
    3725         5373 :       SLP_TREE_TYPE (slp_node) = call_vec_info_type;
    3726         5373 :       DUMP_VECT_SCOPE ("vectorizable_call");
    3727         5373 :       vect_model_simple_cost (vinfo, 1, slp_node, cost_vec);
    3728              : 
    3729         5373 :       if (loop_vinfo
    3730         4428 :           && LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo)
    3731         3070 :           && (reduc_idx >= 0 || could_trap || mask_opno >= 0))
    3732              :         {
    3733         1930 :           if (reduc_idx >= 0
    3734         1438 :               && (cond_fn == IFN_LAST
    3735         1438 :                   || !direct_internal_fn_supported_p (cond_fn, vectype_out,
    3736              :                                                       OPTIMIZE_FOR_SPEED))
    3737         1940 :               && (cond_len_fn == IFN_LAST
    3738           10 :                   || !direct_internal_fn_supported_p (cond_len_fn, vectype_out,
    3739              :                                                       OPTIMIZE_FOR_SPEED)))
    3740              :             {
    3741           10 :               if (dump_enabled_p ())
    3742            6 :                 dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    3743              :                                  "can't use a fully-masked loop because no"
    3744              :                                  " conditional operation is available.\n");
    3745           10 :               LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo) = false;
    3746              :             }
    3747              :           else
    3748              :             {
    3749         1920 :               tree scalar_mask = NULL_TREE;
    3750         1920 :               if (mask_opno >= 0)
    3751         1920 :                 scalar_mask = gimple_call_arg (stmt_info->stmt, mask_opno);
    3752         1920 :               if (cond_len_fn != IFN_LAST
    3753         1920 :                   && direct_internal_fn_supported_p (cond_len_fn, vectype_out,
    3754              :                                                      OPTIMIZE_FOR_SPEED))
    3755            0 :                 vect_record_loop_len (loop_vinfo, lens, nvectors, vectype_out,
    3756              :                                       1);
    3757              :               else
    3758         1920 :                 vect_record_loop_mask (loop_vinfo, masks, nvectors, vectype_out,
    3759              :                                        scalar_mask);
    3760              :             }
    3761              :         }
    3762         5373 :       return true;
    3763              :     }
    3764              : 
    3765              :   /* Transform.  */
    3766              : 
    3767         4198 :   if (dump_enabled_p ())
    3768          415 :     dump_printf_loc (MSG_NOTE, vect_location, "transform call.\n");
    3769              : 
    3770              :   /* Handle def.  */
    3771         4198 :   scalar_dest = gimple_call_lhs (stmt);
    3772         4198 :   vec_dest = vect_create_destination_var (scalar_dest, vectype_out);
    3773              : 
    3774         4198 :   bool masked_loop_p = loop_vinfo && LOOP_VINFO_FULLY_MASKED_P (loop_vinfo);
    3775         3263 :   bool len_loop_p = loop_vinfo && LOOP_VINFO_FULLY_WITH_LENGTH_P (loop_vinfo);
    3776         4198 :   unsigned int vect_nargs = nargs;
    3777         4198 :   if (len_loop_p && (reduc_idx >= 0 || could_trap || mask_opno >= 0))
    3778              :     {
    3779            0 :       ifn = cond_len_fn;
    3780              :       /* COND_* -> COND_LEN_* takes 2 extra arguments:LEN,BIAS.  */
    3781            0 :       vect_nargs += 2;
    3782              :       /* But unless there's a mask argument already we need that
    3783              :          as well, and an else value.  */
    3784            0 :       if (mask_opno == -1)
    3785            0 :         vect_nargs += 2;
    3786              :     }
    3787         4198 :   else if (masked_loop_p && mask_opno == -1 && (reduc_idx >= 0 || could_trap))
    3788              :     {
    3789            0 :       ifn = cond_fn;
    3790            0 :       vect_nargs += 2;
    3791              :     }
    3792         4198 :   int len_opno = internal_fn_len_index (ifn);
    3793         4198 :   if (clz_ctz_arg1)
    3794           59 :     ++vect_nargs;
    3795              : 
    3796         4198 :   if (modifier == NONE || ifn != IFN_LAST)
    3797              :     {
    3798         4166 :       tree prev_res = NULL_TREE;
    3799         4166 :       vargs.safe_grow (vect_nargs, true);
    3800         4166 :       auto_vec<vec<tree> > vec_defs (nargs);
    3801              : 
    3802              :       /* Build argument list for the vectorized call.  */
    3803         4166 :       if (cfn == CFN_GOMP_SIMD_LANE)
    3804              :         {
    3805         3308 :           for (i = 0; i < nvectors; ++i)
    3806              :             {
    3807              :               /* ???  For multi-lane SLP we'd need to build
    3808              :                  { 0, 0, .., 1, 1, ... }.  */
    3809         1708 :               tree cst = build_index_vector (vectype_out,
    3810              :                                              i * nunits_out, 1);
    3811         1708 :               tree new_var
    3812         1708 :                 = vect_get_new_ssa_name (vectype_out, vect_simple_var, "cst_");
    3813         1708 :               gimple *init_stmt = gimple_build_assign (new_var, cst);
    3814         1708 :               vect_init_vector_1 (vinfo, stmt_info, init_stmt, NULL);
    3815         1708 :               new_temp = make_ssa_name (vec_dest);
    3816         1708 :               gimple *new_stmt = gimple_build_assign (new_temp, new_var);
    3817         1708 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    3818         1708 :               slp_node->push_vec_def (new_stmt);
    3819              :             }
    3820              :         }
    3821              :       else
    3822              :         {
    3823         2566 :           vec<tree> vec_oprnds0;
    3824         2566 :           vect_get_slp_defs (vinfo, slp_node, &vec_defs);
    3825         2566 :           vec_oprnds0 = vec_defs[0];
    3826              : 
    3827              :           /* Arguments are ready.  Create the new vector stmt.  */
    3828         5279 :           FOR_EACH_VEC_ELT (vec_oprnds0, i, vec_oprnd0)
    3829              :             {
    3830         2713 :               int varg = 0;
    3831              :               /* Add the mask if necessary.  */
    3832           38 :               if ((masked_loop_p || len_loop_p) && mask_opno == -1
    3833         2715 :                   && internal_fn_mask_index (ifn) != -1)
    3834              :                 {
    3835            0 :                   gcc_assert (internal_fn_mask_index (ifn) == varg);
    3836            0 :                   if (masked_loop_p)
    3837              :                     {
    3838            0 :                       unsigned int vec_num = vec_oprnds0.length ();
    3839            0 :                       vargs[varg++] = vect_get_loop_mask (loop_vinfo, gsi,
    3840              :                                                           masks, vec_num,
    3841              :                                                           vectype_out, i);
    3842              :                     }
    3843              :                   else
    3844              :                     {
    3845            0 :                       tree mask_vectype = truth_type_for (vectype_out);
    3846            0 :                       vargs[varg++] = vect_build_all_ones_mask (loop_vinfo,
    3847              :                                                                 stmt_info,
    3848              :                                                                 mask_vectype);
    3849              :                     }
    3850              :                 }
    3851              :               size_t k;
    3852         9932 :               for (k = 0; k < nargs; k++)
    3853              :                 {
    3854         7219 :                   vec<tree> vec_oprndsk = vec_defs[k];
    3855         7219 :                   vargs[varg++] = vec_oprndsk[i];
    3856              :                 }
    3857              :               /* Add the else value if necessary.  */
    3858           38 :               if ((masked_loop_p || len_loop_p) && mask_opno == -1
    3859         2715 :                   && internal_fn_else_index (ifn) != -1)
    3860              :                 {
    3861            0 :                   gcc_assert (internal_fn_else_index (ifn) == varg);
    3862            0 :                   if (reduc_idx >= 0)
    3863            0 :                     vargs[varg++] = vargs[reduc_idx + 1];
    3864              :                   else
    3865              :                     {
    3866            0 :                       auto else_value = targetm.preferred_else_value
    3867            0 :                         (ifn, vectype_out, varg - 1, &vargs[1]);
    3868            0 :                       vargs[varg++] = else_value;
    3869              :                     }
    3870              :                 }
    3871         2713 :               if (clz_ctz_arg1)
    3872           59 :                 vargs[varg++] = clz_ctz_arg1;
    3873              : 
    3874         2713 :               gimple *new_stmt;
    3875         2713 :               if (modifier == NARROW)
    3876              :                 {
    3877              :                   /* We don't define any narrowing conditional functions
    3878              :                      at present.  */
    3879            0 :                   gcc_assert (mask_opno < 0);
    3880            0 :                   tree half_res = make_ssa_name (vectype_in);
    3881            0 :                   gcall *call = gimple_build_call_internal_vec (ifn, vargs);
    3882            0 :                   gimple_call_set_lhs (call, half_res);
    3883            0 :                   gimple_call_set_nothrow (call, true);
    3884            0 :                   vect_finish_stmt_generation (vinfo, stmt_info, call, gsi);
    3885            0 :                   if ((i & 1) == 0)
    3886              :                     {
    3887            0 :                       prev_res = half_res;
    3888            0 :                       continue;
    3889              :                     }
    3890            0 :                   new_temp = make_ssa_name (vec_dest);
    3891            0 :                   new_stmt = vect_gimple_build (new_temp, convert_code,
    3892              :                                                 prev_res, half_res);
    3893            0 :                   vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    3894              :                 }
    3895              :               else
    3896              :                 {
    3897         2713 :                   if (len_opno >= 0 && len_loop_p)
    3898              :                     {
    3899            0 :                       unsigned int vec_num = vec_oprnds0.length ();
    3900            0 :                       tree len = vect_get_loop_len (loop_vinfo, gsi, lens,
    3901              :                                                     vec_num, vectype_out, i, 1, true);
    3902            0 :                       signed char biasval
    3903            0 :                         = LOOP_VINFO_PARTIAL_LOAD_STORE_BIAS (loop_vinfo);
    3904            0 :                       tree bias = build_int_cst (intQI_type_node, biasval);
    3905            0 :                       vargs[len_opno] = len;
    3906            0 :                       vargs[len_opno + 1] = bias;
    3907              :                     }
    3908         2713 :                   else if (mask_opno >= 0 && masked_loop_p)
    3909              :                     {
    3910           36 :                       unsigned int vec_num = vec_oprnds0.length ();
    3911           36 :                       tree mask = vect_get_loop_mask (loop_vinfo, gsi, masks,
    3912              :                                                       vec_num, vectype_out, i);
    3913           36 :                       vargs[mask_opno]
    3914           72 :                         = prepare_vec_mask (loop_vinfo, TREE_TYPE (mask), mask,
    3915           36 :                                             vargs[mask_opno], gsi);
    3916              :                     }
    3917              : 
    3918         2713 :                   gcall *call;
    3919         2713 :                   if (ifn != IFN_LAST)
    3920         2632 :                     call = gimple_build_call_internal_vec (ifn, vargs);
    3921              :                   else
    3922           81 :                     call = gimple_build_call_vec (fndecl, vargs);
    3923         2713 :                   new_temp = make_ssa_name (vec_dest, call);
    3924         2713 :                   gimple_call_set_lhs (call, new_temp);
    3925         2713 :                   gimple_call_set_nothrow (call, true);
    3926         2713 :                   vect_finish_stmt_generation (vinfo, stmt_info, call, gsi);
    3927         2713 :                   new_stmt = call;
    3928              :                 }
    3929         2713 :               slp_node->push_vec_def (new_stmt);
    3930              :             }
    3931              :         }
    3932              : 
    3933        11035 :       for (i = 0; i < nargs; i++)
    3934              :         {
    3935         6869 :           vec<tree> vec_oprndsi = vec_defs[i];
    3936         6869 :           vec_oprndsi.release ();
    3937              :         }
    3938         4166 :     }
    3939           32 :   else if (modifier == NARROW)
    3940              :     {
    3941           32 :       auto_vec<vec<tree> > vec_defs (nargs);
    3942              :       /* We don't define any narrowing conditional functions at present.  */
    3943           32 :       gcc_assert (mask_opno < 0);
    3944              : 
    3945              :       /* Build argument list for the vectorized call.  */
    3946           32 :       vargs.create (nargs * 2);
    3947              : 
    3948           32 :       vect_get_slp_defs (vinfo, slp_node, &vec_defs);
    3949           32 :       vec<tree> vec_oprnds0 = vec_defs[0];
    3950              : 
    3951              :       /* Arguments are ready.  Create the new vector stmt.  */
    3952           64 :       for (i = 0; vec_oprnds0.iterate (i, &vec_oprnd0); i += 2)
    3953              :         {
    3954           32 :           size_t k;
    3955           32 :           vargs.truncate (0);
    3956           64 :           for (k = 0; k < nargs; k++)
    3957              :             {
    3958           32 :               vec<tree> vec_oprndsk = vec_defs[k];
    3959           32 :               vargs.quick_push (vec_oprndsk[i]);
    3960           32 :               vargs.quick_push (vec_oprndsk[i + 1]);
    3961              :             }
    3962           32 :           gcall *call;
    3963           32 :           if (ifn != IFN_LAST)
    3964              :             call = gimple_build_call_internal_vec (ifn, vargs);
    3965              :           else
    3966           32 :             call = gimple_build_call_vec (fndecl, vargs);
    3967           32 :           new_temp = make_ssa_name (vec_dest, call);
    3968           32 :           gimple_call_set_lhs (call, new_temp);
    3969           32 :           gimple_call_set_nothrow (call, true);
    3970           32 :           vect_finish_stmt_generation (vinfo, stmt_info, call, gsi);
    3971           32 :           slp_node->push_vec_def (call);
    3972              :         }
    3973              : 
    3974           64 :       for (i = 0; i < nargs; i++)
    3975              :         {
    3976           32 :           vec<tree> vec_oprndsi = vec_defs[i];
    3977           32 :           vec_oprndsi.release ();
    3978              :         }
    3979           32 :     }
    3980              :   else
    3981              :     /* No current target implements this case.  */
    3982              :     return false;
    3983              : 
    3984         4198 :   vargs.release ();
    3985              : 
    3986         4198 :   return true;
    3987      2334134 : }
    3988              : 
    3989              : 
    3990              : struct simd_call_arg_info
    3991              : {
    3992              :   tree vectype;
    3993              :   tree op;
    3994              :   HOST_WIDE_INT linear_step;
    3995              :   enum vect_def_type dt;
    3996              :   unsigned int align;
    3997              :   bool simd_lane_linear;
    3998              : };
    3999              : 
    4000              : /* Helper function of vectorizable_simd_clone_call.  If OP, an SSA_NAME,
    4001              :    is linear within simd lane (but not within whole loop), note it in
    4002              :    *ARGINFO.  */
    4003              : 
    4004              : static void
    4005           15 : vect_simd_lane_linear (tree op, class loop *loop,
    4006              :                        struct simd_call_arg_info *arginfo)
    4007              : {
    4008           15 :   gimple *def_stmt = SSA_NAME_DEF_STMT (op);
    4009              : 
    4010           15 :   if (!is_gimple_assign (def_stmt)
    4011           15 :       || gimple_assign_rhs_code (def_stmt) != POINTER_PLUS_EXPR
    4012           27 :       || !is_gimple_min_invariant (gimple_assign_rhs1 (def_stmt)))
    4013            3 :     return;
    4014              : 
    4015           12 :   tree base = gimple_assign_rhs1 (def_stmt);
    4016           12 :   HOST_WIDE_INT linear_step = 0;
    4017           12 :   tree v = gimple_assign_rhs2 (def_stmt);
    4018           48 :   while (TREE_CODE (v) == SSA_NAME)
    4019              :     {
    4020           36 :       tree t;
    4021           36 :       def_stmt = SSA_NAME_DEF_STMT (v);
    4022           36 :       if (is_gimple_assign (def_stmt))
    4023           24 :         switch (gimple_assign_rhs_code (def_stmt))
    4024              :           {
    4025            0 :           case PLUS_EXPR:
    4026            0 :             t = gimple_assign_rhs2 (def_stmt);
    4027            0 :             if (linear_step || TREE_CODE (t) != INTEGER_CST)
    4028              :               return;
    4029            0 :             base = fold_build2 (POINTER_PLUS_EXPR, TREE_TYPE (base), base, t);
    4030            0 :             v = gimple_assign_rhs1 (def_stmt);
    4031            0 :             continue;
    4032           12 :           case MULT_EXPR:
    4033           12 :             t = gimple_assign_rhs2 (def_stmt);
    4034           12 :             if (linear_step || !tree_fits_shwi_p (t) || integer_zerop (t))
    4035            0 :               return;
    4036           12 :             linear_step = tree_to_shwi (t);
    4037           12 :             v = gimple_assign_rhs1 (def_stmt);
    4038           12 :             continue;
    4039           12 :           CASE_CONVERT:
    4040           12 :             t = gimple_assign_rhs1 (def_stmt);
    4041           12 :             if (TREE_CODE (TREE_TYPE (t)) != INTEGER_TYPE
    4042           12 :                 || (TYPE_PRECISION (TREE_TYPE (v))
    4043           12 :                     < TYPE_PRECISION (TREE_TYPE (t))))
    4044              :               return;
    4045           12 :             if (!linear_step)
    4046            0 :               linear_step = 1;
    4047           12 :             v = t;
    4048           12 :             continue;
    4049              :           default:
    4050              :             return;
    4051              :           }
    4052           12 :       else if (gimple_call_internal_p (def_stmt, IFN_GOMP_SIMD_LANE)
    4053           12 :                && loop->simduid
    4054           12 :                && TREE_CODE (gimple_call_arg (def_stmt, 0)) == SSA_NAME
    4055           24 :                && (SSA_NAME_VAR (gimple_call_arg (def_stmt, 0))
    4056              :                    == loop->simduid))
    4057              :         {
    4058           12 :           if (!linear_step)
    4059            0 :             linear_step = 1;
    4060           12 :           arginfo->linear_step = linear_step;
    4061           12 :           arginfo->op = base;
    4062           12 :           arginfo->simd_lane_linear = true;
    4063           12 :           return;
    4064              :         }
    4065              :     }
    4066              : }
    4067              : 
    4068              : /* Function vectorizable_simd_clone_call.
    4069              : 
    4070              :    Check if STMT_INFO performs a function call that can be vectorized
    4071              :    by calling a simd clone of the function.
    4072              :    If COST_VEC is passed, calculate costs but don't change anything,
    4073              :    otherwise, vectorize STMT_INFO: create a vectorized stmt to replace
    4074              :    it, and insert it at GSI.
    4075              :    Return true if STMT_INFO is vectorizable in this way.  */
    4076              : 
    4077              : static bool
    4078      2324768 : vectorizable_simd_clone_call (vec_info *vinfo, stmt_vec_info stmt_info,
    4079              :                               gimple_stmt_iterator *gsi,
    4080              :                               slp_tree slp_node,
    4081              :                               stmt_vector_for_cost *cost_vec)
    4082              : {
    4083      2324768 :   tree vec_dest;
    4084      2324768 :   tree scalar_dest;
    4085      2324768 :   tree vec_oprnd0 = NULL_TREE;
    4086      2324768 :   tree vectype;
    4087      2324768 :   poly_uint64 nunits;
    4088      2324768 :   loop_vec_info loop_vinfo = dyn_cast <loop_vec_info> (vinfo);
    4089      2324768 :   bb_vec_info bb_vinfo = dyn_cast <bb_vec_info> (vinfo);
    4090      2324768 :   class loop *loop = loop_vinfo ? LOOP_VINFO_LOOP (loop_vinfo) : NULL;
    4091      2324768 :   tree fndecl, new_temp;
    4092      2324768 :   int j;
    4093      2324768 :   auto_vec<simd_call_arg_info> arginfo;
    4094      2324768 :   vec<tree> vargs = vNULL;
    4095      2324768 :   size_t i, nargs;
    4096      2324768 :   tree rtype, ratype;
    4097      2324768 :   vec<constructor_elt, va_gc> *ret_ctor_elts = NULL;
    4098      2324768 :   int masked_call_offset = 0;
    4099              : 
    4100              :   /* Is STMT a vectorizable call?   */
    4101      2324768 :   gcall *stmt = dyn_cast <gcall *> (stmt_info->stmt);
    4102        10894 :   if (!stmt)
    4103              :     return false;
    4104              : 
    4105        10894 :   fndecl = gimple_call_fndecl (stmt);
    4106        10894 :   if (fndecl == NULL_TREE
    4107        10894 :       && gimple_call_internal_p (stmt, IFN_MASK_CALL))
    4108              :     {
    4109          220 :       fndecl = gimple_call_arg (stmt, 0);
    4110          220 :       gcc_checking_assert (TREE_CODE (fndecl) == ADDR_EXPR);
    4111          220 :       fndecl = TREE_OPERAND (fndecl, 0);
    4112          220 :       gcc_checking_assert (TREE_CODE (fndecl) == FUNCTION_DECL);
    4113              :       masked_call_offset = 1;
    4114              :     }
    4115        10674 :   if (fndecl == NULL_TREE)
    4116              :     return false;
    4117              : 
    4118         4655 :   struct cgraph_node *node = cgraph_node::get (fndecl);
    4119         4655 :   if (node == NULL || node->simd_clones == NULL)
    4120              :     return false;
    4121              : 
    4122         1454 :   if (!STMT_VINFO_RELEVANT_P (stmt_info) && !bb_vinfo)
    4123              :     return false;
    4124              : 
    4125         1454 :   if (STMT_VINFO_DEF_TYPE (stmt_info) != vect_internal_def
    4126            0 :       && cost_vec)
    4127              :     return false;
    4128              : 
    4129         1454 :   if (gimple_call_lhs (stmt)
    4130         1454 :       && TREE_CODE (gimple_call_lhs (stmt)) != SSA_NAME)
    4131              :     return false;
    4132              : 
    4133         1454 :   gcc_checking_assert (!stmt_can_throw_internal (cfun, stmt));
    4134              : 
    4135         1454 :   vectype = SLP_TREE_VECTYPE (slp_node);
    4136              : 
    4137      2324832 :   if (loop_vinfo && nested_in_vect_loop_p (loop, stmt_info))
    4138              :     return false;
    4139              : 
    4140              :   /* Process function arguments.  */
    4141         1454 :   nargs = gimple_call_num_args (stmt) - masked_call_offset;
    4142              : 
    4143              :   /* Bail out if the function has zero arguments.  */
    4144         1454 :   if (nargs == 0)
    4145              :     return false;
    4146              : 
    4147         1390 :   vect_simd_clone_data _data;
    4148         1390 :   vect_simd_clone_data &data = slp_node->get_data (_data);
    4149         1390 :   vec<tree>& simd_clone_info = data.simd_clone_info;
    4150         1390 :   arginfo.reserve (nargs, true);
    4151         1390 :   auto_vec<slp_tree> slp_op;
    4152         1390 :   slp_op.safe_grow_cleared (nargs);
    4153              : 
    4154         3996 :   for (i = 0; i < nargs; i++)
    4155              :     {
    4156         2606 :       simd_call_arg_info thisarginfo;
    4157         2606 :       affine_iv iv;
    4158         2606 :       tree op;
    4159              : 
    4160         2606 :       thisarginfo.linear_step = 0;
    4161         2606 :       thisarginfo.align = 0;
    4162         2606 :       thisarginfo.op = NULL_TREE;
    4163         2606 :       thisarginfo.simd_lane_linear = false;
    4164              : 
    4165         5212 :       int op_no = vect_slp_child_index_for_operand (stmt,
    4166         2606 :                                                     i + masked_call_offset,
    4167              :                                                     false);
    4168         5212 :       if (!vect_is_simple_use (vinfo, slp_node,
    4169         2606 :                                op_no, &op, &slp_op[i],
    4170              :                                &thisarginfo.dt, &thisarginfo.vectype)
    4171         2606 :           || thisarginfo.dt == vect_uninitialized_def)
    4172              :         {
    4173            0 :           if (dump_enabled_p ())
    4174            0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    4175              :                              "use not simple.\n");
    4176            0 :           return false;
    4177              :         }
    4178              : 
    4179         2606 :       if (thisarginfo.dt == vect_constant_def
    4180         2606 :           || thisarginfo.dt == vect_external_def)
    4181              :         {
    4182              :           /* With SLP we determine the vector type of constants/externals
    4183              :              at analysis time, handling conflicts via
    4184              :              vect_maybe_update_slp_op_vectype.  At transform time
    4185              :              we have a vector type recorded for SLP.  */
    4186          699 :           gcc_assert (cost_vec
    4187              :                       || thisarginfo.vectype != NULL_TREE);
    4188              :           if (cost_vec)
    4189          568 :             thisarginfo.vectype = get_vectype_for_scalar_type (vinfo,
    4190          568 :                                                                TREE_TYPE (op),
    4191              :                                                                slp_node);
    4192              :         }
    4193              :       else
    4194         1907 :         gcc_assert (thisarginfo.vectype != NULL_TREE);
    4195              : 
    4196              :       /* For linear arguments, the analyze phase should have saved
    4197              :          the base and step.  */
    4198         2475 :       if (!cost_vec
    4199         1584 :           && i * 3 + 4 <= simd_clone_info.length ()
    4200         2685 :           && simd_clone_info[i * 3 + 2])
    4201              :         {
    4202          118 :           thisarginfo.linear_step = tree_to_shwi (simd_clone_info[i * 3 + 2]);
    4203          118 :           thisarginfo.op = simd_clone_info[i * 3 + 1];
    4204          118 :           thisarginfo.simd_lane_linear
    4205          118 :             = (simd_clone_info[i * 3 + 3] == boolean_true_node);
    4206              :           /* If loop has been peeled for alignment, we need to adjust it.  */
    4207          118 :           tree n1 = LOOP_VINFO_NITERS_UNCHANGED (loop_vinfo);
    4208          118 :           tree n2 = LOOP_VINFO_NITERS (loop_vinfo);
    4209          118 :           if (n1 != n2 && !thisarginfo.simd_lane_linear)
    4210              :             {
    4211            0 :               tree bias = fold_build2 (MINUS_EXPR, TREE_TYPE (n1), n1, n2);
    4212            0 :               tree step = simd_clone_info[i * 3 + 2];
    4213            0 :               tree opt = TREE_TYPE (thisarginfo.op);
    4214            0 :               bias = fold_convert (TREE_TYPE (step), bias);
    4215            0 :               bias = fold_build2 (MULT_EXPR, TREE_TYPE (step), bias, step);
    4216            0 :               thisarginfo.op
    4217            0 :                 = fold_build2 (POINTER_TYPE_P (opt)
    4218              :                                ? POINTER_PLUS_EXPR : PLUS_EXPR, opt,
    4219              :                                thisarginfo.op, bias);
    4220              :             }
    4221              :         }
    4222         2488 :       else if (cost_vec
    4223         1814 :                && thisarginfo.dt != vect_constant_def
    4224         1692 :                && thisarginfo.dt != vect_external_def
    4225         1246 :                && loop_vinfo
    4226         1241 :                && SLP_TREE_LANES (slp_node) == 1
    4227         1217 :                && TREE_CODE (op) == SSA_NAME
    4228         2434 :                && simple_iv (loop, loop_containing_stmt (stmt), op,
    4229              :                              &iv, false)
    4230         2694 :                && tree_fits_shwi_p (iv.step))
    4231              :         {
    4232          206 :           thisarginfo.linear_step = tree_to_shwi (iv.step);
    4233          206 :           thisarginfo.op = iv.base;
    4234              :         }
    4235         2282 :       else if ((thisarginfo.dt == vect_constant_def
    4236         2282 :                 || thisarginfo.dt == vect_external_def)
    4237          699 :                && SLP_TREE_LANES (slp_node) == 1
    4238         2583 :                && POINTER_TYPE_P (TREE_TYPE (op)))
    4239           86 :         thisarginfo.align = get_pointer_alignment (op) / BITS_PER_UNIT;
    4240              :       /* Addresses of array elements indexed by GOMP_SIMD_LANE are
    4241              :          linear too.  */
    4242         2606 :       if (SLP_TREE_LANES (slp_node) == 1
    4243         2162 :           && POINTER_TYPE_P (TREE_TYPE (op))
    4244          196 :           && !thisarginfo.linear_step
    4245          112 :           && cost_vec
    4246           58 :           && thisarginfo.dt != vect_constant_def
    4247           58 :           && thisarginfo.dt != vect_external_def
    4248           15 :           && loop_vinfo
    4249         2621 :           && TREE_CODE (op) == SSA_NAME)
    4250           15 :         vect_simd_lane_linear (op, loop, &thisarginfo);
    4251              : 
    4252         2606 :       if (!vectype)
    4253           12 :         vectype = thisarginfo.vectype;
    4254         2606 :       arginfo.quick_push (thisarginfo);
    4255              :     }
    4256              : 
    4257         1390 :   poly_uint64 vf = loop_vinfo ? LOOP_VINFO_VECT_FACTOR (loop_vinfo) : 1;
    4258         1390 :   unsigned group_size = SLP_TREE_LANES (slp_node);
    4259         1390 :   unsigned int badness = 0;
    4260         1390 :   unsigned int badness_inbranch = 0;
    4261         1390 :   struct cgraph_node *bestn = NULL;
    4262         1390 :   struct cgraph_node *bestn_inbranch = NULL;
    4263         1390 :   if (!cost_vec)
    4264          357 :     bestn = ((loop_vinfo && LOOP_VINFO_FULLY_MASKED_P (loop_vinfo))
    4265          357 :              ? data.clone_inbranch : data.clone);
    4266              :   else
    4267         5979 :     for (struct cgraph_node *n = node->simd_clones; n != NULL;
    4268         4946 :          n = n->simdclone->next_clone)
    4269              :       {
    4270         4946 :         unsigned int this_badness = 0;
    4271         4946 :         unsigned int num_calls;
    4272              :         /* The number of arguments in the call and the number of parameters in
    4273              :            the simdclone should match.  However, when the simdclone is
    4274              :            'inbranch', it could have one more paramater than nargs when using
    4275              :            an inbranch simdclone to call a non-inbranch call, either in a
    4276              :            non-masked loop using a all true constant mask, or inside a masked
    4277              :            loop using it's mask.  */
    4278         4946 :         size_t simd_nargs = n->simdclone->nargs;
    4279         4946 :         if (!masked_call_offset && n->simdclone->inbranch)
    4280         2333 :           simd_nargs--;
    4281         4946 :         if (!constant_multiple_p (vf * group_size, n->simdclone->simdlen,
    4282              :                                   &num_calls)
    4283         1952 :             || (!n->simdclone->inbranch && (masked_call_offset > 0))
    4284         1768 :             || (nargs != simd_nargs))
    4285         3178 :           continue;
    4286         1768 :         if (num_calls != 1)
    4287         1136 :           this_badness += floor_log2 (num_calls) * 4096;
    4288         1768 :         if (n->simdclone->inbranch)
    4289          764 :           this_badness += 8192;
    4290              : 
    4291              :         /* If SLP_TREE_VECTYPE has not been set yet pass the general vector
    4292              :            mode,  which for targets that use it will determine what ISA we can
    4293              :            vectorize this code with.  */
    4294         1768 :         machine_mode vector_mode = vinfo->vector_mode;
    4295         1768 :         if (vectype)
    4296         1768 :           vector_mode = TYPE_MODE (vectype);
    4297         1768 :         int target_badness = targetm.simd_clone.usable (n, vector_mode);
    4298         1768 :         if (target_badness < 0)
    4299          368 :           continue;
    4300         1400 :         this_badness += target_badness * 512;
    4301         4146 :         for (i = 0; i < nargs; i++)
    4302              :           {
    4303         2994 :             switch (n->simdclone->args[i].arg_type)
    4304              :               {
    4305         2064 :               case SIMD_CLONE_ARG_TYPE_VECTOR:
    4306         2064 :                 if (VECTOR_BOOLEAN_TYPE_P (n->simdclone->args[i].vector_type))
    4307              :                   /* Vector mask arguments are not supported.  */
    4308              :                   i = -1;
    4309         2056 :                 else if (!useless_type_conversion_p
    4310         2056 :                          (n->simdclone->args[i].orig_type,
    4311         2056 :                           TREE_TYPE (gimple_call_arg (stmt,
    4312              :                                                       i + masked_call_offset))))
    4313              :                   i = -1;
    4314         2056 :                 else if (arginfo[i].dt == vect_constant_def
    4315         1951 :                          || arginfo[i].dt == vect_external_def
    4316         3943 :                          || arginfo[i].linear_step)
    4317          392 :                   this_badness += 64;
    4318              :                 break;
    4319          310 :               case SIMD_CLONE_ARG_TYPE_UNIFORM:
    4320          310 :                 if ((arginfo[i].dt != vect_constant_def
    4321          145 :                      && arginfo[i].dt != vect_external_def)
    4322          410 :                     || SLP_TREE_LANES (slp_node) != 1)
    4323              :                   i = -1;
    4324              :                 break;
    4325          324 :               case SIMD_CLONE_ARG_TYPE_LINEAR_CONSTANT_STEP:
    4326          324 :               case SIMD_CLONE_ARG_TYPE_LINEAR_REF_CONSTANT_STEP:
    4327          324 :                 if (arginfo[i].dt == vect_constant_def
    4328          324 :                     || arginfo[i].dt == vect_external_def
    4329          324 :                     || (arginfo[i].linear_step
    4330          324 :                         != n->simdclone->args[i].linear_step))
    4331              :                   i = -1;
    4332              :                 break;
    4333              :               case SIMD_CLONE_ARG_TYPE_LINEAR_VARIABLE_STEP:
    4334              :               case SIMD_CLONE_ARG_TYPE_LINEAR_VAL_CONSTANT_STEP:
    4335              :               case SIMD_CLONE_ARG_TYPE_LINEAR_UVAL_CONSTANT_STEP:
    4336              :               case SIMD_CLONE_ARG_TYPE_LINEAR_REF_VARIABLE_STEP:
    4337              :               case SIMD_CLONE_ARG_TYPE_LINEAR_VAL_VARIABLE_STEP:
    4338              :               case SIMD_CLONE_ARG_TYPE_LINEAR_UVAL_VARIABLE_STEP:
    4339              :                 /* FORNOW */
    4340              :                 i = -1;
    4341              :                 break;
    4342          296 :               case SIMD_CLONE_ARG_TYPE_MASK:
    4343          296 :                 if (!SCALAR_INT_MODE_P (n->simdclone->mask_mode)
    4344          264 :                     && n->simdclone->mask_mode != VOIDmode)
    4345              :                   i = -1;
    4346              :                 /* While we can create a traditional data vector from
    4347              :                    an incoming integer mode mask we have no good way to
    4348              :                    force generate an integer mode mask from a traditional
    4349              :                    boolean vector input.  */
    4350          296 :                 else if (SCALAR_INT_MODE_P (n->simdclone->mask_mode)
    4351          296 :                          && !SCALAR_INT_MODE_P (TYPE_MODE (arginfo[i].vectype)))
    4352              :                   i = -1;
    4353          290 :                 else if (n->simdclone->mask_mode == VOIDmode
    4354              :                          /* FORNOW we only have partial support for vector-type
    4355              :                             masks that can't hold all of simdlen. */
    4356          554 :                          && (maybe_ne (TYPE_VECTOR_SUBPARTS (n->simdclone->args[i].vector_type),
    4357          264 :                                        TYPE_VECTOR_SUBPARTS (arginfo[i].vectype))
    4358              :                              /* Verify we can compute the mask argument.  */
    4359          111 :                              || !expand_vec_cond_expr_p (n->simdclone->args[i].vector_type,
    4360          111 :                                                          arginfo[i].vectype)))
    4361              :                   i = -1;
    4362          125 :                 else if (SCALAR_INT_MODE_P (n->simdclone->mask_mode)
    4363              :                          /* FORNOW we only have partial support for
    4364              :                             integer-type masks that represent the same number
    4365              :                             of lanes as the vectorized mask inputs.  */
    4366          151 :                          && maybe_ne (exact_div (n->simdclone->simdlen,
    4367              :                                                  n->simdclone->args[i].linear_step),
    4368           26 :                                       TYPE_VECTOR_SUBPARTS (arginfo[i].vectype)))
    4369              :                   i = -1;
    4370          107 :                 else if (!SCALAR_INT_MODE_P (n->simdclone->mask_mode)
    4371          107 :                          && SCALAR_INT_MODE_P (TYPE_MODE (arginfo[i].vectype)))
    4372            8 :                   this_badness += 2048;
    4373              :                 break;
    4374              :               }
    4375          183 :             if (i == (size_t) -1)
    4376              :               break;
    4377         2746 :             if (n->simdclone->args[i].alignment > arginfo[i].align)
    4378              :               {
    4379              :                 i = -1;
    4380              :                 break;
    4381              :               }
    4382         2746 :             if (arginfo[i].align)
    4383          110 :               this_badness += (exact_log2 (arginfo[i].align)
    4384          160 :                                - exact_log2 (n->simdclone->args[i].alignment));
    4385              :           }
    4386         1400 :         if (i == (size_t) -1)
    4387          248 :           continue;
    4388         1152 :         if (masked_call_offset == 0
    4389         1045 :             && n->simdclone->inbranch
    4390          340 :             && n->simdclone->nargs > nargs)
    4391              :           {
    4392          340 :             gcc_assert (n->simdclone->args[n->simdclone->nargs - 1].arg_type ==
    4393              :                         SIMD_CLONE_ARG_TYPE_MASK);
    4394              :             /* Penalize using a masked SIMD clone in a non-masked loop, that is
    4395              :                not in a branch, as we'd have to construct an all-true mask.  */
    4396          340 :             this_badness += 64;
    4397              :           }
    4398         1152 :         if (bestn == NULL || this_badness < badness)
    4399              :           {
    4400          797 :             bestn = n;
    4401          797 :             badness = this_badness;
    4402              :           }
    4403         1152 :         if (n->simdclone->inbranch
    4404          447 :             && (bestn_inbranch == NULL || this_badness < badness_inbranch))
    4405              :           {
    4406         4946 :             bestn_inbranch = n;
    4407         4946 :             badness_inbranch = this_badness;
    4408              :           }
    4409              :       }
    4410              : 
    4411         1390 :   if (bestn == NULL)
    4412              :     return false;
    4413              : 
    4414          809 :   fndecl = bestn->decl;
    4415          809 :   nunits = bestn->simdclone->simdlen;
    4416          809 :   int ncopies = vector_unroll_factor (vf * group_size, nunits);
    4417              : 
    4418              :   /* If the function isn't const, only allow it in simd loops where user
    4419              :      has asserted that at least nunits consecutive iterations can be
    4420              :      performed using SIMD instructions.  */
    4421          804 :   if ((loop == NULL || maybe_lt ((unsigned) loop->safelen, nunits))
    4422          966 :       && gimple_vuse (stmt))
    4423              :     return false;
    4424              : 
    4425              :   /* ncopies is the number of SIMD clone calls we create, since simdlen
    4426              :      is not necessarily matching nunits of the vector types used, track
    4427              :      that in ncopies_in.  */
    4428          809 :   int ncopies_in = vect_get_num_vectors (vf * group_size, vectype);
    4429              : 
    4430              :   /* Sanity check: make sure that at least one copy of the vectorized stmt
    4431              :      needs to be generated.  */
    4432          809 :   gcc_assert (ncopies >= 1);
    4433              : 
    4434          809 :   if (cost_vec) /* transformation not required.  */
    4435              :     {
    4436         1483 :       for (unsigned i = 0; i < nargs; ++i)
    4437         1031 :         if (!vect_maybe_update_slp_op_vectype (slp_op[i], arginfo[i].vectype))
    4438              :           {
    4439            0 :             if (dump_enabled_p ())
    4440            0 :               dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    4441              :                                "incompatible vector types for invariants\n");
    4442            0 :             return false;
    4443              :           }
    4444              : 
    4445          452 :       if (!bestn_inbranch && loop_vinfo)
    4446              :         {
    4447          237 :           if (dump_enabled_p ()
    4448          237 :               && LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo))
    4449          171 :             dump_printf_loc (MSG_NOTE, vect_location,
    4450              :                              "can't use a fully-masked loop because no"
    4451              :                              " masked simd clone was available.\n");
    4452          237 :           LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo) = false;
    4453              :         }
    4454              : 
    4455              :       /* When the original call is pure or const but the SIMD ABI dictates
    4456              :          an aggregate return we will have to use a virtual definition and
    4457              :          in a loop eventually even need to add a virtual PHI.  That's
    4458              :          not straight-forward so allow to fix this up via renaming.  */
    4459          452 :       if (gimple_call_lhs (stmt)
    4460          446 :           && !gimple_vdef (stmt)
    4461          802 :           && TREE_CODE (TREE_TYPE (TREE_TYPE (bestn->decl))) == ARRAY_TYPE)
    4462           27 :         vinfo->any_known_not_updated_vssa = true;
    4463              :       /* ???  For SLP code-gen we end up inserting after the last
    4464              :          vector argument def rather than at the original call position
    4465              :          so automagic virtual operand updating doesn't work.  */
    4466          904 :       if (gimple_vuse (stmt))
    4467          139 :         vinfo->any_known_not_updated_vssa = true;
    4468              : 
    4469          452 :       data.clone = bestn;
    4470          452 :       data.clone_inbranch = bestn_inbranch;
    4471              : 
    4472          452 :       simd_clone_info.safe_push (NULL_TREE);
    4473         1628 :       for (i = 0;
    4474         2445 :            i < (bestn_inbranch ? bestn_inbranch : bestn)->simdclone->nargs; i++)
    4475              :         {
    4476         1176 :           if (loop_vinfo
    4477         1170 :               && LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo)
    4478          473 :               && (bestn_inbranch->simdclone->args[i].arg_type
    4479              :                   == SIMD_CLONE_ARG_TYPE_MASK))
    4480              :             {
    4481          170 :               if (masked_call_offset)
    4482              :                 /* When there is an explicit mask we require the
    4483              :                    number of elements to match up.  */
    4484           49 :                 vect_record_loop_mask (loop_vinfo,
    4485              :                                        &LOOP_VINFO_MASKS (loop_vinfo),
    4486              :                                        ncopies_in, vectype, NULL_TREE);
    4487              :               else
    4488              :                 {
    4489              :                   /* When there is no explicit mask on the call we have
    4490              :                      more relaxed requirements.  */
    4491          121 :                   tree masktype;
    4492          121 :                   poly_uint64 callee_nelements;
    4493          121 :                   if (SCALAR_INT_MODE_P (bestn_inbranch->simdclone->mask_mode))
    4494              :                     {
    4495           12 :                       callee_nelements
    4496           12 :                           = exact_div (bestn_inbranch->simdclone->simdlen,
    4497              :                                        bestn_inbranch->simdclone->args[i].linear_step);
    4498           12 :                       masktype = get_related_vectype_for_scalar_type
    4499           12 :                           (vinfo->vector_mode, TREE_TYPE (vectype),
    4500              :                            callee_nelements);
    4501              :                     }
    4502              :                   else
    4503              :                     {
    4504          109 :                       masktype = bestn_inbranch->simdclone->args[i].vector_type;
    4505              :                       /* The aarch64 port will add custom attributes to types
    4506              :                          for SVE simdclones which make the types different.  We
    4507              :                          should use canonincal types for masks within the
    4508              :                          vectorizer, hence we construct the related vectype
    4509              :                          here.  */
    4510          109 :                       masktype
    4511              :                         = build_truth_vector_type_for_mode
    4512          109 :                           (TYPE_VECTOR_SUBPARTS (masktype),
    4513          109 :                            TYPE_MODE (masktype));
    4514          109 :                       callee_nelements = TYPE_VECTOR_SUBPARTS (masktype);
    4515              :                     }
    4516          121 :                   auto o = vector_unroll_factor (nunits, callee_nelements);
    4517          121 :                   vect_record_loop_mask (loop_vinfo,
    4518              :                                          &LOOP_VINFO_MASKS (loop_vinfo),
    4519              :                                          ncopies  * o, masktype, NULL_TREE);
    4520              :                 }
    4521              :             }
    4522         1006 :           else if ((bestn->simdclone->args[i].arg_type
    4523              :                     == SIMD_CLONE_ARG_TYPE_LINEAR_CONSTANT_STEP)
    4524          899 :                    || (bestn->simdclone->args[i].arg_type
    4525              :                        == SIMD_CLONE_ARG_TYPE_LINEAR_REF_CONSTANT_STEP)
    4526          888 :                    || (bestn_inbranch
    4527          359 :                        && ((bestn_inbranch->simdclone->args[i].arg_type
    4528              :                             == SIMD_CLONE_ARG_TYPE_LINEAR_CONSTANT_STEP)
    4529          359 :                            || (bestn_inbranch->simdclone->args[i].arg_type
    4530              :                                == SIMD_CLONE_ARG_TYPE_LINEAR_REF_CONSTANT_STEP))))
    4531              :             {
    4532          118 :               simd_clone_info.safe_grow_cleared (i * 3 + 1, true);
    4533          118 :               simd_clone_info.safe_push (arginfo[i].op);
    4534          202 :               tree lst = (POINTER_TYPE_P (TREE_TYPE (arginfo[i].op))
    4535          202 :                           ? size_type_node : TREE_TYPE (arginfo[i].op));
    4536          118 :               tree ls = build_int_cst (lst, arginfo[i].linear_step);
    4537          118 :               simd_clone_info.safe_push (ls);
    4538          118 :               tree sll = (arginfo[i].simd_lane_linear
    4539          118 :                           ? boolean_true_node : boolean_false_node);
    4540          118 :               simd_clone_info.safe_push (sll);
    4541              :             }
    4542              :         }
    4543              : 
    4544          452 :       SLP_TREE_TYPE (slp_node) = call_simd_clone_vec_info_type;
    4545          452 :       slp_node->data = new vect_simd_clone_data (std::move (_data));
    4546          452 :       DUMP_VECT_SCOPE ("vectorizable_simd_clone_call");
    4547              : /*      vect_model_simple_cost (vinfo, 1, slp_node, cost_vec); */
    4548          452 :       return true;
    4549              :     }
    4550              : 
    4551              :   /* Transform.  */
    4552              : 
    4553          357 :   if (dump_enabled_p ())
    4554          246 :     dump_printf_loc (MSG_NOTE, vect_location, "transform call.\n");
    4555              : 
    4556              :   /* Handle def.  */
    4557          357 :   scalar_dest = gimple_call_lhs (stmt);
    4558          357 :   vec_dest = NULL_TREE;
    4559          357 :   rtype = NULL_TREE;
    4560          357 :   ratype = NULL_TREE;
    4561          357 :   if (scalar_dest)
    4562              :     {
    4563          351 :       vec_dest = vect_create_destination_var (scalar_dest, vectype);
    4564          351 :       rtype = TREE_TYPE (TREE_TYPE (fndecl));
    4565          351 :       if (TREE_CODE (rtype) == ARRAY_TYPE)
    4566              :         {
    4567            9 :           ratype = rtype;
    4568            9 :           rtype = TREE_TYPE (ratype);
    4569              :         }
    4570              :     }
    4571              : 
    4572          714 :   auto_vec<vec<tree> > vec_oprnds;
    4573          357 :   auto_vec<unsigned> vec_oprnds_i;
    4574          357 :   vec_oprnds_i.safe_grow_cleared (nargs, true);
    4575          357 :   vec_oprnds.reserve_exact (nargs);
    4576          357 :   vect_get_slp_defs (vinfo, slp_node, &vec_oprnds);
    4577          823 :   for (j = 0; j < ncopies; ++j)
    4578              :     {
    4579          466 :       poly_uint64 callee_nelements;
    4580          466 :       poly_uint64 caller_nelements;
    4581              :       /* Build argument list for the vectorized call.  */
    4582          466 :       if (j == 0)
    4583          357 :         vargs.create (nargs);
    4584              :       else
    4585          109 :         vargs.truncate (0);
    4586              : 
    4587         1570 :       for (i = 0; i < nargs; i++)
    4588              :         {
    4589         1104 :           unsigned int k, l, m, o;
    4590         1104 :           tree atype;
    4591         1104 :           tree op = gimple_call_arg (stmt, i + masked_call_offset);
    4592         1104 :           switch (bestn->simdclone->args[i].arg_type)
    4593              :             {
    4594          815 :             case SIMD_CLONE_ARG_TYPE_VECTOR:
    4595          815 :               atype = bestn->simdclone->args[i].vector_type;
    4596          815 :               caller_nelements = TYPE_VECTOR_SUBPARTS (arginfo[i].vectype);
    4597          815 :               callee_nelements = TYPE_VECTOR_SUBPARTS (atype);
    4598          815 :               o = vector_unroll_factor (nunits, callee_nelements);
    4599         1860 :               for (m = j * o; m < (j + 1) * o; m++)
    4600              :                 {
    4601         1045 :                   if (known_lt (callee_nelements, caller_nelements))
    4602              :                     {
    4603          516 :                       poly_uint64 prec = GET_MODE_BITSIZE (TYPE_MODE (atype));
    4604          258 :                       if (!constant_multiple_p (caller_nelements,
    4605              :                                                 callee_nelements, &k))
    4606            0 :                         gcc_unreachable ();
    4607              : 
    4608          258 :                       gcc_assert ((k & (k - 1)) == 0);
    4609          258 :                       if (m == 0)
    4610              :                         {
    4611           57 :                           vec_oprnds_i[i] = 0;
    4612           57 :                           vec_oprnd0 = vec_oprnds[i][vec_oprnds_i[i]++];
    4613              :                         }
    4614              :                       else
    4615              :                         {
    4616          201 :                           vec_oprnd0 = arginfo[i].op;
    4617          201 :                           if ((m & (k - 1)) == 0)
    4618           72 :                             vec_oprnd0 = vec_oprnds[i][vec_oprnds_i[i]++];
    4619              :                         }
    4620          258 :                       arginfo[i].op = vec_oprnd0;
    4621          258 :                       vec_oprnd0
    4622          258 :                         = build3 (BIT_FIELD_REF, atype, vec_oprnd0,
    4623          258 :                                   bitsize_int (prec),
    4624          258 :                                   bitsize_int ((m & (k - 1)) * prec));
    4625          258 :                       gassign *new_stmt
    4626          258 :                         = gimple_build_assign (make_ssa_name (atype),
    4627              :                                                vec_oprnd0);
    4628          258 :                       vect_finish_stmt_generation (vinfo, stmt_info,
    4629              :                                                    new_stmt, gsi);
    4630          258 :                       vargs.safe_push (gimple_assign_lhs (new_stmt));
    4631              :                     }
    4632              :                   else
    4633              :                     {
    4634          787 :                       if (!constant_multiple_p (callee_nelements,
    4635              :                                                 caller_nelements, &k))
    4636            0 :                         gcc_unreachable ();
    4637          787 :                       gcc_assert ((k & (k - 1)) == 0);
    4638          787 :                       vec<constructor_elt, va_gc> *ctor_elts;
    4639          787 :                       if (k != 1)
    4640           14 :                         vec_alloc (ctor_elts, k);
    4641              :                       else
    4642          773 :                         ctor_elts = NULL;
    4643          815 :                       for (l = 0; l < k; l++)
    4644              :                         {
    4645          801 :                           if (m == 0 && l == 0)
    4646              :                             {
    4647          449 :                               vec_oprnds_i[i] = 0;
    4648          449 :                               vec_oprnd0 = vec_oprnds[i][vec_oprnds_i[i]++];
    4649              :                             }
    4650              :                           else
    4651          352 :                             vec_oprnd0 = vec_oprnds[i][vec_oprnds_i[i]++];
    4652          801 :                           arginfo[i].op = vec_oprnd0;
    4653          801 :                           if (k == 1)
    4654              :                             break;
    4655           28 :                           CONSTRUCTOR_APPEND_ELT (ctor_elts, NULL_TREE,
    4656              :                                                   vec_oprnd0);
    4657              :                         }
    4658          787 :                       if (k == 1)
    4659          773 :                         if (!useless_type_conversion_p (TREE_TYPE (vec_oprnd0),
    4660              :                                                        atype))
    4661              :                           {
    4662            0 :                             vec_oprnd0 = build1 (VIEW_CONVERT_EXPR, atype,
    4663              :                                                  vec_oprnd0);
    4664            0 :                             gassign *new_stmt
    4665            0 :                               = gimple_build_assign (make_ssa_name (atype),
    4666              :                                                      vec_oprnd0);
    4667            0 :                             vect_finish_stmt_generation (vinfo, stmt_info,
    4668              :                                                          new_stmt, gsi);
    4669            0 :                             vargs.safe_push (gimple_get_lhs (new_stmt));
    4670              :                           }
    4671              :                         else
    4672          773 :                           vargs.safe_push (vec_oprnd0);
    4673              :                       else
    4674              :                         {
    4675           14 :                           vec_oprnd0 = build_constructor (atype, ctor_elts);
    4676           14 :                           gassign *new_stmt
    4677           14 :                             = gimple_build_assign (make_ssa_name (atype),
    4678              :                                                    vec_oprnd0);
    4679           14 :                           vect_finish_stmt_generation (vinfo, stmt_info,
    4680              :                                                        new_stmt, gsi);
    4681           14 :                           vargs.safe_push (gimple_assign_lhs (new_stmt));
    4682              :                         }
    4683              :                     }
    4684              :                 }
    4685              :               break;
    4686           66 :             case SIMD_CLONE_ARG_TYPE_MASK:
    4687           66 :               if (bestn->simdclone->mask_mode == VOIDmode)
    4688              :                 {
    4689           60 :                   atype = bestn->simdclone->args[i].vector_type;
    4690           60 :                   tree elt_type = TREE_TYPE (atype);
    4691           60 :                   tree one = fold_convert (elt_type, integer_one_node);
    4692           60 :                   tree zero = fold_convert (elt_type, integer_zero_node);
    4693           60 :                   callee_nelements = TYPE_VECTOR_SUBPARTS (atype);
    4694           60 :                   caller_nelements = TYPE_VECTOR_SUBPARTS (arginfo[i].vectype);
    4695           60 :                   o = vector_unroll_factor (nunits, callee_nelements);
    4696          120 :                   for (m = j * o; m < (j + 1) * o; m++)
    4697              :                     {
    4698           60 :                       if (maybe_lt (callee_nelements, caller_nelements))
    4699              :                         {
    4700              :                           /* The mask type has fewer elements than simdlen.  */
    4701              : 
    4702              :                           /* FORNOW */
    4703            0 :                           gcc_unreachable ();
    4704              :                         }
    4705           60 :                       else if (known_eq (callee_nelements, caller_nelements))
    4706              :                         {
    4707              :                           /* The SIMD clone function has the same number of
    4708              :                              elements as the current function.  */
    4709           60 :                           if (m == 0)
    4710           60 :                             vec_oprnds_i[i] = 0;
    4711           60 :                           vec_oprnd0 = vec_oprnds[i][vec_oprnds_i[i]++];
    4712           60 :                           if (loop_vinfo
    4713           60 :                               && LOOP_VINFO_FULLY_MASKED_P (loop_vinfo))
    4714              :                             {
    4715            0 :                               vec_loop_masks *loop_masks
    4716              :                                 = &LOOP_VINFO_MASKS (loop_vinfo);
    4717            0 :                               tree loop_mask
    4718            0 :                                 = vect_get_loop_mask (loop_vinfo, gsi,
    4719              :                                                       loop_masks, ncopies_in,
    4720            0 :                                                       vectype, j);
    4721            0 :                               vec_oprnd0
    4722            0 :                                 = prepare_vec_mask (loop_vinfo,
    4723            0 :                                                     TREE_TYPE (loop_mask),
    4724              :                                                     loop_mask, vec_oprnd0,
    4725              :                                                     gsi);
    4726            0 :                               loop_vinfo->vec_cond_masked_set.add ({ vec_oprnd0,
    4727              :                                                                      loop_mask });
    4728              : 
    4729              :                             }
    4730           60 :                           vec_oprnd0
    4731           60 :                             = build3 (VEC_COND_EXPR, atype, vec_oprnd0,
    4732              :                                       build_vector_from_val (atype, one),
    4733              :                                       build_vector_from_val (atype, zero));
    4734           60 :                           gassign *new_stmt
    4735           60 :                             = gimple_build_assign (make_ssa_name (atype),
    4736              :                                                    vec_oprnd0);
    4737           60 :                           vect_finish_stmt_generation (vinfo, stmt_info,
    4738              :                                                        new_stmt, gsi);
    4739           60 :                           vargs.safe_push (gimple_assign_lhs (new_stmt));
    4740              :                         }
    4741              :                       else
    4742              :                         {
    4743              :                           /* The mask type has more elements than simdlen.  */
    4744              : 
    4745              :                           /* FORNOW */
    4746            0 :                           gcc_unreachable ();
    4747              :                         }
    4748              :                     }
    4749              :                 }
    4750            6 :               else if (SCALAR_INT_MODE_P (bestn->simdclone->mask_mode))
    4751              :                 {
    4752            6 :                   atype = bestn->simdclone->args[i].vector_type;
    4753            6 :                   poly_uint64 atype_subparts
    4754            6 :                     = exact_div (bestn->simdclone->simdlen,
    4755              :                                  bestn->simdclone->args[i].linear_step);
    4756            6 :                   o = bestn->simdclone->args[i].linear_step;
    4757           12 :                   for (m = j * o; m < (j + 1) * o; m++)
    4758              :                     {
    4759            6 :                       if (m == 0)
    4760            6 :                         vec_oprnds_i[i] = 0;
    4761            6 :                       if (maybe_lt (atype_subparts,
    4762            6 :                                     TYPE_VECTOR_SUBPARTS (arginfo[i].vectype)))
    4763              :                         {
    4764              :                           /* The mask argument has fewer elements than the
    4765              :                              input vector.  */
    4766              :                           /* FORNOW */
    4767            0 :                           gcc_unreachable ();
    4768              :                         }
    4769            6 :                       else if (known_eq (atype_subparts,
    4770              :                                          TYPE_VECTOR_SUBPARTS (arginfo[i].vectype)))
    4771              :                         {
    4772            6 :                           vec_oprnd0 = vec_oprnds[i][vec_oprnds_i[i]++];
    4773            6 :                           if (loop_vinfo
    4774            6 :                               && LOOP_VINFO_FULLY_MASKED_P (loop_vinfo))
    4775              :                             {
    4776            1 :                               vec_loop_masks *loop_masks
    4777              :                                 = &LOOP_VINFO_MASKS (loop_vinfo);
    4778            1 :                               tree loop_mask
    4779            1 :                                 = vect_get_loop_mask (loop_vinfo, gsi,
    4780              :                                                       loop_masks, ncopies_in,
    4781              :                                                       vectype, j);
    4782            1 :                               vec_oprnd0
    4783            1 :                                 = prepare_vec_mask (loop_vinfo,
    4784            1 :                                                     TREE_TYPE (loop_mask),
    4785              :                                                     loop_mask, vec_oprnd0,
    4786              :                                                     gsi);
    4787              :                             }
    4788              :                           /* The vector mask argument matches the input
    4789              :                              in the number of lanes, but not necessarily
    4790              :                              in the mode.  */
    4791            6 :                           tree st = lang_hooks.types.type_for_mode
    4792            6 :                                       (TYPE_MODE (TREE_TYPE (vec_oprnd0)), 1);
    4793            6 :                           vec_oprnd0 = build1 (VIEW_CONVERT_EXPR, st,
    4794              :                                                vec_oprnd0);
    4795            6 :                           gassign *new_stmt
    4796            6 :                             = gimple_build_assign (make_ssa_name (st),
    4797              :                                                    vec_oprnd0);
    4798            6 :                           vect_finish_stmt_generation (vinfo, stmt_info,
    4799              :                                                        new_stmt, gsi);
    4800            6 :                           if (!types_compatible_p (atype, st))
    4801              :                             {
    4802            6 :                               new_stmt
    4803            6 :                                 = gimple_build_assign (make_ssa_name (atype),
    4804              :                                                        NOP_EXPR,
    4805              :                                                        gimple_assign_lhs
    4806              :                                                          (new_stmt));
    4807            6 :                               vect_finish_stmt_generation (vinfo, stmt_info,
    4808              :                                                            new_stmt, gsi);
    4809              :                             }
    4810            6 :                           vargs.safe_push (gimple_assign_lhs (new_stmt));
    4811              :                         }
    4812              :                       else
    4813              :                         {
    4814              :                           /* The mask argument has more elements than the
    4815              :                              input vector.  */
    4816              :                           /* FORNOW */
    4817            0 :                           gcc_unreachable ();
    4818              :                         }
    4819              :                     }
    4820              :                 }
    4821              :               else
    4822            0 :                 gcc_unreachable ();
    4823              :               break;
    4824          102 :             case SIMD_CLONE_ARG_TYPE_UNIFORM:
    4825          102 :               vargs.safe_push (op);
    4826          102 :               break;
    4827          121 :             case SIMD_CLONE_ARG_TYPE_LINEAR_CONSTANT_STEP:
    4828          121 :             case SIMD_CLONE_ARG_TYPE_LINEAR_REF_CONSTANT_STEP:
    4829          121 :               if (j == 0)
    4830              :                 {
    4831          118 :                   gimple_seq stmts;
    4832          118 :                   arginfo[i].op
    4833          118 :                     = force_gimple_operand (unshare_expr (arginfo[i].op),
    4834              :                                             &stmts, true, NULL_TREE);
    4835          118 :                   if (stmts != NULL)
    4836              :                     {
    4837            0 :                       basic_block new_bb;
    4838            0 :                       edge pe = loop_preheader_edge (loop);
    4839            0 :                       new_bb = gsi_insert_seq_on_edge_immediate (pe, stmts);
    4840            0 :                       gcc_assert (!new_bb);
    4841              :                     }
    4842          118 :                   if (arginfo[i].simd_lane_linear)
    4843              :                     {
    4844            6 :                       vargs.safe_push (arginfo[i].op);
    4845            6 :                       break;
    4846              :                     }
    4847          112 :                   tree phi_res = copy_ssa_name (op);
    4848          112 :                   gphi *new_phi = create_phi_node (phi_res, loop->header);
    4849          112 :                   add_phi_arg (new_phi, arginfo[i].op,
    4850              :                                loop_preheader_edge (loop), UNKNOWN_LOCATION);
    4851          112 :                   enum tree_code code
    4852          196 :                     = POINTER_TYPE_P (TREE_TYPE (op))
    4853          112 :                       ? POINTER_PLUS_EXPR : PLUS_EXPR;
    4854          196 :                   tree type = POINTER_TYPE_P (TREE_TYPE (op))
    4855          196 :                               ? sizetype : TREE_TYPE (op);
    4856          112 :                   poly_widest_int cst
    4857          112 :                     = wi::mul (bestn->simdclone->args[i].linear_step,
    4858          112 :                                ncopies * nunits);
    4859          112 :                   tree tcst = wide_int_to_tree (type, cst);
    4860          112 :                   tree phi_arg = copy_ssa_name (op);
    4861          112 :                   gassign *new_stmt
    4862          112 :                     = gimple_build_assign (phi_arg, code, phi_res, tcst);
    4863          112 :                   gimple_stmt_iterator si = gsi_after_labels (loop->header);
    4864          112 :                   gsi_insert_after (&si, new_stmt, GSI_NEW_STMT);
    4865          112 :                   add_phi_arg (new_phi, phi_arg, loop_latch_edge (loop),
    4866              :                                UNKNOWN_LOCATION);
    4867          112 :                   arginfo[i].op = phi_res;
    4868          112 :                   vargs.safe_push (phi_res);
    4869          112 :                 }
    4870              :               else
    4871              :                 {
    4872            3 :                   enum tree_code code
    4873            6 :                     = POINTER_TYPE_P (TREE_TYPE (op))
    4874            3 :                       ? POINTER_PLUS_EXPR : PLUS_EXPR;
    4875            6 :                   tree type = POINTER_TYPE_P (TREE_TYPE (op))
    4876            6 :                               ? sizetype : TREE_TYPE (op);
    4877            3 :                   poly_widest_int cst
    4878            3 :                     = wi::mul (bestn->simdclone->args[i].linear_step,
    4879            3 :                                j * nunits);
    4880            3 :                   tree tcst = wide_int_to_tree (type, cst);
    4881            3 :                   new_temp = make_ssa_name (TREE_TYPE (op));
    4882            3 :                   gassign *new_stmt
    4883            6 :                     = gimple_build_assign (new_temp, code,
    4884            3 :                                            arginfo[i].op, tcst);
    4885            3 :                   vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    4886            3 :                   vargs.safe_push (new_temp);
    4887            3 :                 }
    4888              :               break;
    4889            0 :             case SIMD_CLONE_ARG_TYPE_LINEAR_VAL_CONSTANT_STEP:
    4890            0 :             case SIMD_CLONE_ARG_TYPE_LINEAR_UVAL_CONSTANT_STEP:
    4891            0 :             case SIMD_CLONE_ARG_TYPE_LINEAR_VARIABLE_STEP:
    4892            0 :             case SIMD_CLONE_ARG_TYPE_LINEAR_REF_VARIABLE_STEP:
    4893            0 :             case SIMD_CLONE_ARG_TYPE_LINEAR_VAL_VARIABLE_STEP:
    4894            0 :             case SIMD_CLONE_ARG_TYPE_LINEAR_UVAL_VARIABLE_STEP:
    4895            0 :             default:
    4896            0 :               gcc_unreachable ();
    4897              :             }
    4898              :         }
    4899              : 
    4900          466 :       if (masked_call_offset == 0
    4901          400 :           && bestn->simdclone->inbranch
    4902            8 :           && bestn->simdclone->nargs > nargs)
    4903              :         {
    4904            8 :           unsigned long m, o;
    4905            8 :           size_t mask_i = bestn->simdclone->nargs - 1;
    4906            8 :           tree mask;
    4907            8 :           gcc_assert (bestn->simdclone->args[mask_i].arg_type ==
    4908              :                       SIMD_CLONE_ARG_TYPE_MASK);
    4909              : 
    4910            8 :           tree mask_argtype = bestn->simdclone->args[mask_i].vector_type;
    4911            8 :           tree mask_vectype;
    4912            8 :           if (SCALAR_INT_MODE_P (bestn->simdclone->mask_mode))
    4913              :             {
    4914            2 :               callee_nelements = exact_div (bestn->simdclone->simdlen,
    4915              :                                             bestn->simdclone->args[i].linear_step);
    4916            2 :               mask_vectype = get_related_vectype_for_scalar_type
    4917            2 :                   (vinfo->vector_mode, TREE_TYPE (vectype), callee_nelements);
    4918              :             }
    4919              :           else
    4920              :             {
    4921            6 :               mask_vectype = mask_argtype;
    4922            6 :               callee_nelements = TYPE_VECTOR_SUBPARTS (mask_vectype);
    4923              :             }
    4924            8 :           o = vector_unroll_factor (nunits, callee_nelements);
    4925           16 :           for (m = j * o; m < (j + 1) * o; m++)
    4926              :             {
    4927            8 :               if (loop_vinfo && LOOP_VINFO_FULLY_MASKED_P (loop_vinfo))
    4928              :                 {
    4929            1 :                   vec_loop_masks *loop_masks = &LOOP_VINFO_MASKS (loop_vinfo);
    4930            1 :                   mask = vect_get_loop_mask (loop_vinfo, gsi, loop_masks,
    4931              :                                              ncopies * o, mask_vectype, m);
    4932              :                 }
    4933              :               else
    4934            7 :                 mask = vect_build_all_ones_mask (vinfo, stmt_info,
    4935              :                                                  mask_argtype);
    4936              : 
    4937            8 :               gassign *new_stmt;
    4938            8 :               if (SCALAR_INT_MODE_P (bestn->simdclone->mask_mode))
    4939              :                 {
    4940              :                   /* This means we are dealing with integer mask modes.
    4941              :                      First convert to an integer type with the same size as
    4942              :                      the current vector type.  */
    4943            2 :                   unsigned HOST_WIDE_INT intermediate_size
    4944            2 :                       = tree_to_uhwi (TYPE_SIZE (TREE_TYPE (mask)));
    4945            2 :                   tree mid_int_type =
    4946            2 :                       build_nonstandard_integer_type (intermediate_size, 1);
    4947            2 :                   mask = build1 (VIEW_CONVERT_EXPR, mid_int_type, mask);
    4948            2 :                   new_stmt
    4949            2 :                       = gimple_build_assign (make_ssa_name (mid_int_type),
    4950              :                                              mask);
    4951            2 :                   gsi_insert_before (gsi, new_stmt, GSI_SAME_STMT);
    4952              :                   /* Then zero-extend to the mask mode.  */
    4953            2 :                   mask = fold_build1 (NOP_EXPR, mask_argtype,
    4954              :                                       gimple_get_lhs (new_stmt));
    4955              :                 }
    4956            6 :               else if (bestn->simdclone->mask_mode == VOIDmode)
    4957            6 :                 mask = build3 (VEC_COND_EXPR, mask_argtype, mask,
    4958              :                                build_one_cst (mask_argtype),
    4959              :                                build_zero_cst (mask_argtype));
    4960              :               else
    4961            0 :                 gcc_unreachable ();
    4962              : 
    4963            8 :               new_stmt = gimple_build_assign (make_ssa_name (mask_argtype),
    4964              :                                               mask);
    4965            8 :               vect_finish_stmt_generation (vinfo, stmt_info,
    4966              :                                            new_stmt, gsi);
    4967            8 :               mask = gimple_assign_lhs (new_stmt);
    4968            8 :               vargs.safe_push (mask);
    4969              :             }
    4970              :         }
    4971              : 
    4972          466 :       gcall *new_call = gimple_build_call_vec (fndecl, vargs);
    4973          466 :       if (vec_dest)
    4974              :         {
    4975          460 :           gcc_assert (ratype
    4976              :                       || known_eq (TYPE_VECTOR_SUBPARTS (rtype), nunits));
    4977          460 :           if (ratype)
    4978           15 :             new_temp = create_tmp_var (ratype);
    4979          445 :           else if (useless_type_conversion_p (vectype, rtype))
    4980          423 :             new_temp = make_ssa_name (vec_dest, new_call);
    4981              :           else
    4982           22 :             new_temp = make_ssa_name (rtype, new_call);
    4983          460 :           gimple_call_set_lhs (new_call, new_temp);
    4984              :         }
    4985          466 :       vect_finish_stmt_generation (vinfo, stmt_info, new_call, gsi);
    4986          466 :       gimple *new_stmt = new_call;
    4987              : 
    4988          466 :       if (vec_dest)
    4989              :         {
    4990          460 :           if (!multiple_p (TYPE_VECTOR_SUBPARTS (vectype), nunits))
    4991              :             {
    4992           21 :               unsigned int k, l;
    4993           42 :               poly_uint64 prec = GET_MODE_BITSIZE (TYPE_MODE (vectype));
    4994           42 :               poly_uint64 bytes = GET_MODE_SIZE (TYPE_MODE (vectype));
    4995           21 :               k = vector_unroll_factor (nunits,
    4996              :                                         TYPE_VECTOR_SUBPARTS (vectype));
    4997           21 :               gcc_assert ((k & (k - 1)) == 0);
    4998           75 :               for (l = 0; l < k; l++)
    4999              :                 {
    5000           54 :                   tree t;
    5001           54 :                   if (ratype)
    5002              :                     {
    5003           42 :                       t = build_fold_addr_expr (new_temp);
    5004           42 :                       t = build2 (MEM_REF, vectype, t,
    5005           42 :                                   build_int_cst (TREE_TYPE (t), l * bytes));
    5006              :                     }
    5007              :                   else
    5008           12 :                     t = build3 (BIT_FIELD_REF, vectype, new_temp,
    5009           12 :                                 bitsize_int (prec), bitsize_int (l * prec));
    5010           54 :                   new_stmt = gimple_build_assign (make_ssa_name (vectype), t);
    5011           54 :                   vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    5012              : 
    5013           54 :                   SLP_TREE_VEC_DEFS (slp_node)
    5014           54 :                     .quick_push (gimple_assign_lhs (new_stmt));
    5015              :                 }
    5016              : 
    5017           21 :               if (ratype)
    5018           15 :                 vect_clobber_variable (vinfo, stmt_info, gsi, new_temp);
    5019           21 :               continue;
    5020           21 :             }
    5021          439 :           else if (!multiple_p (nunits, TYPE_VECTOR_SUBPARTS (vectype)))
    5022              :             {
    5023           16 :               unsigned int k;
    5024           16 :               if (!constant_multiple_p (TYPE_VECTOR_SUBPARTS (vectype),
    5025           16 :                                         TYPE_VECTOR_SUBPARTS (rtype), &k))
    5026            0 :                 gcc_unreachable ();
    5027           16 :               gcc_assert ((k & (k - 1)) == 0);
    5028           16 :               if ((j & (k - 1)) == 0)
    5029            8 :                 vec_alloc (ret_ctor_elts, k);
    5030           16 :               if (ratype)
    5031              :                 {
    5032            0 :                   unsigned int m, o;
    5033            0 :                   o = vector_unroll_factor (nunits,
    5034              :                                             TYPE_VECTOR_SUBPARTS (rtype));
    5035            0 :                   for (m = 0; m < o; m++)
    5036              :                     {
    5037            0 :                       tree tem = build4 (ARRAY_REF, rtype, new_temp,
    5038            0 :                                          size_int (m), NULL_TREE, NULL_TREE);
    5039            0 :                       new_stmt = gimple_build_assign (make_ssa_name (rtype),
    5040              :                                                       tem);
    5041            0 :                       vect_finish_stmt_generation (vinfo, stmt_info,
    5042              :                                                    new_stmt, gsi);
    5043            0 :                       CONSTRUCTOR_APPEND_ELT (ret_ctor_elts, NULL_TREE,
    5044              :                                               gimple_assign_lhs (new_stmt));
    5045              :                     }
    5046            0 :                   vect_clobber_variable (vinfo, stmt_info, gsi, new_temp);
    5047              :                 }
    5048              :               else
    5049           16 :                 CONSTRUCTOR_APPEND_ELT (ret_ctor_elts, NULL_TREE, new_temp);
    5050           16 :               if ((j & (k - 1)) != k - 1)
    5051            8 :                 continue;
    5052            8 :               vec_oprnd0 = build_constructor (vectype, ret_ctor_elts);
    5053            8 :               new_stmt
    5054            8 :                 = gimple_build_assign (make_ssa_name (vec_dest), vec_oprnd0);
    5055            8 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    5056              : 
    5057            8 :               SLP_TREE_VEC_DEFS (slp_node)
    5058            8 :                 .quick_push (gimple_assign_lhs (new_stmt));
    5059            8 :               continue;
    5060            8 :             }
    5061          423 :           else if (ratype)
    5062              :             {
    5063            0 :               tree t = build_fold_addr_expr (new_temp);
    5064            0 :               t = build2 (MEM_REF, vectype, t,
    5065            0 :                           build_int_cst (TREE_TYPE (t), 0));
    5066            0 :               new_stmt = gimple_build_assign (make_ssa_name (vec_dest), t);
    5067            0 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    5068            0 :               vect_clobber_variable (vinfo, stmt_info, gsi, new_temp);
    5069              :             }
    5070          423 :           else if (!useless_type_conversion_p (vectype, rtype))
    5071              :             {
    5072            0 :               vec_oprnd0 = build1 (VIEW_CONVERT_EXPR, vectype, new_temp);
    5073            0 :               new_stmt
    5074            0 :                 = gimple_build_assign (make_ssa_name (vec_dest), vec_oprnd0);
    5075            0 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    5076              :             }
    5077              :         }
    5078              : 
    5079          429 :       if (gimple_get_lhs (new_stmt))
    5080          423 :         SLP_TREE_VEC_DEFS (slp_node).quick_push (gimple_get_lhs (new_stmt));
    5081              :     }
    5082              : 
    5083         1149 :   for (i = 0; i < nargs; ++i)
    5084              :     {
    5085          792 :       vec<tree> oprndsi = vec_oprnds[i];
    5086          792 :       oprndsi.release ();
    5087              :     }
    5088          357 :   vargs.release ();
    5089              : 
    5090              :   /* Mark the clone as no longer being a candidate for GC.  */
    5091          357 :   bestn->gc_candidate = false;
    5092              : 
    5093          357 :   return true;
    5094         1390 : }
    5095              : 
    5096              : 
    5097              : /* Function vect_gen_widened_results_half
    5098              : 
    5099              :    Create a vector stmt whose code, type, number of arguments, and result
    5100              :    variable are CODE, OP_TYPE, and VEC_DEST, and its arguments are
    5101              :    VEC_OPRND0 and VEC_OPRND1.  The new vector stmt is to be inserted at GSI.
    5102              :    In the case that CODE is a CALL_EXPR, this means that a call to DECL
    5103              :    needs to be created (DECL is a function-decl of a target-builtin).
    5104              :    STMT_INFO is the original scalar stmt that we are vectorizing.  */
    5105              : 
    5106              : static gimple *
    5107        32664 : vect_gen_widened_results_half (vec_info *vinfo, code_helper ch,
    5108              :                                tree vec_oprnd0, tree vec_oprnd1, int op_type,
    5109              :                                tree vec_dest, gimple_stmt_iterator *gsi,
    5110              :                                stmt_vec_info stmt_info)
    5111              : {
    5112        32664 :   gimple *new_stmt;
    5113        32664 :   tree new_temp;
    5114              : 
    5115              :   /* Generate half of the widened result:  */
    5116        32664 :   if (op_type != binary_op)
    5117        31544 :     vec_oprnd1 = NULL;
    5118        32664 :   new_stmt = vect_gimple_build (vec_dest, ch, vec_oprnd0, vec_oprnd1);
    5119        32664 :   new_temp = make_ssa_name (vec_dest, new_stmt);
    5120        32664 :   gimple_set_lhs (new_stmt, new_temp);
    5121        32664 :   vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    5122              : 
    5123        32664 :   return new_stmt;
    5124              : }
    5125              : 
    5126              : 
    5127              : /* Create vectorized demotion statements for vector operands from VEC_OPRNDS.
    5128              :    For multi-step conversions store the resulting vectors and call the function
    5129              :    recursively. When NARROW_SRC_P is true, there's still a conversion after
    5130              :    narrowing, don't store the vectors in the SLP_NODE or in vector info of
    5131              :    the scalar statement(or in STMT_VINFO_RELATED_STMT chain).  */
    5132              : 
    5133              : static void
    5134        11978 : vect_create_vectorized_demotion_stmts (vec_info *vinfo, vec<tree> *vec_oprnds,
    5135              :                                        int multi_step_cvt,
    5136              :                                        stmt_vec_info stmt_info,
    5137              :                                        vec<tree> &vec_dsts,
    5138              :                                        gimple_stmt_iterator *gsi,
    5139              :                                        slp_tree slp_node, code_helper code,
    5140              :                                        bool narrow_src_p)
    5141              : {
    5142        11978 :   unsigned int i;
    5143        11978 :   tree vop0, vop1, new_tmp, vec_dest;
    5144              : 
    5145        11978 :   vec_dest = vec_dsts.pop ();
    5146              : 
    5147        28350 :   for (i = 0; i < vec_oprnds->length (); i += 2)
    5148              :     {
    5149              :       /* Create demotion operation.  */
    5150        16372 :       vop0 = (*vec_oprnds)[i];
    5151        16372 :       vop1 = (*vec_oprnds)[i + 1];
    5152        16372 :       gimple *new_stmt = vect_gimple_build (vec_dest, code, vop0, vop1);
    5153        16372 :       new_tmp = make_ssa_name (vec_dest, new_stmt);
    5154        16372 :       gimple_set_lhs (new_stmt, new_tmp);
    5155        16372 :       vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    5156        16372 :       if (multi_step_cvt || narrow_src_p)
    5157              :         /* Store the resulting vector for next recursive call,
    5158              :            or return the resulting vector_tmp for NARROW FLOAT_EXPR.  */
    5159         6699 :         (*vec_oprnds)[i/2] = new_tmp;
    5160              :       else
    5161              :         {
    5162              :           /* This is the last step of the conversion sequence. Store the
    5163              :              vectors in SLP_NODE.  */
    5164         9673 :           slp_node->push_vec_def (new_stmt);
    5165              :         }
    5166              :     }
    5167              : 
    5168              :   /* For multi-step demotion operations we first generate demotion operations
    5169              :      from the source type to the intermediate types, and then combine the
    5170              :      results (stored in VEC_OPRNDS) in demotion operation to the destination
    5171              :      type.  */
    5172        11978 :   if (multi_step_cvt)
    5173              :     {
    5174              :       /* At each level of recursion we have half of the operands we had at the
    5175              :          previous level.  */
    5176         2971 :       vec_oprnds->truncate ((i+1)/2);
    5177         2971 :       vect_create_vectorized_demotion_stmts (vinfo, vec_oprnds,
    5178              :                                              multi_step_cvt - 1,
    5179              :                                              stmt_info, vec_dsts, gsi,
    5180         2971 :                                              slp_node, VEC_PACK_TRUNC_EXPR,
    5181              :                                              narrow_src_p);
    5182              :     }
    5183              : 
    5184        11978 :   vec_dsts.quick_push (vec_dest);
    5185        11978 : }
    5186              : 
    5187              : 
    5188              : /* Create vectorized promotion statements for vector operands from VEC_OPRNDS0
    5189              :    and VEC_OPRNDS1, for a binary operation associated with scalar statement
    5190              :    STMT_INFO.  For multi-step conversions store the resulting vectors and
    5191              :    call the function recursively.  */
    5192              : 
    5193              : static void
    5194        11861 : vect_create_vectorized_promotion_stmts (vec_info *vinfo,
    5195              :                                         vec<tree> *vec_oprnds0,
    5196              :                                         vec<tree> *vec_oprnds1,
    5197              :                                         stmt_vec_info stmt_info, tree vec_dest,
    5198              :                                         gimple_stmt_iterator *gsi,
    5199              :                                         code_helper ch1,
    5200              :                                         code_helper ch2, int op_type)
    5201              : {
    5202        11861 :   int i;
    5203        11861 :   tree vop0, vop1, new_tmp1, new_tmp2;
    5204        11861 :   gimple *new_stmt1, *new_stmt2;
    5205        11861 :   vec<tree> vec_tmp = vNULL;
    5206              : 
    5207        11861 :   vec_tmp.create (vec_oprnds0->length () * 2);
    5208        40054 :   FOR_EACH_VEC_ELT (*vec_oprnds0, i, vop0)
    5209              :     {
    5210        16332 :       if (op_type == binary_op)
    5211          560 :         vop1 = (*vec_oprnds1)[i];
    5212              :       else
    5213              :         vop1 = NULL_TREE;
    5214              : 
    5215              :       /* Generate the two halves of promotion operation.  */
    5216        16332 :       new_stmt1 = vect_gen_widened_results_half (vinfo, ch1, vop0, vop1,
    5217              :                                                  op_type, vec_dest, gsi,
    5218              :                                                  stmt_info);
    5219        16332 :       new_stmt2 = vect_gen_widened_results_half (vinfo, ch2, vop0, vop1,
    5220              :                                                  op_type, vec_dest, gsi,
    5221              :                                                  stmt_info);
    5222        16332 :       if (is_gimple_call (new_stmt1))
    5223              :         {
    5224            0 :           new_tmp1 = gimple_call_lhs (new_stmt1);
    5225            0 :           new_tmp2 = gimple_call_lhs (new_stmt2);
    5226              :         }
    5227              :       else
    5228              :         {
    5229        16332 :           new_tmp1 = gimple_assign_lhs (new_stmt1);
    5230        16332 :           new_tmp2 = gimple_assign_lhs (new_stmt2);
    5231              :         }
    5232              : 
    5233              :       /* Store the results for the next step.  */
    5234        16332 :       vec_tmp.quick_push (new_tmp1);
    5235        16332 :       vec_tmp.quick_push (new_tmp2);
    5236              :     }
    5237              : 
    5238        11861 :   vec_oprnds0->release ();
    5239        11861 :   *vec_oprnds0 = vec_tmp;
    5240        11861 : }
    5241              : 
    5242              : /* Create vectorized promotion stmts for widening stmts using only half the
    5243              :    potential vector size for input.  */
    5244              : static void
    5245           14 : vect_create_half_widening_stmts (vec_info *vinfo,
    5246              :                                         vec<tree> *vec_oprnds0,
    5247              :                                         vec<tree> *vec_oprnds1,
    5248              :                                         stmt_vec_info stmt_info, tree vec_dest,
    5249              :                                         gimple_stmt_iterator *gsi,
    5250              :                                         code_helper code1,
    5251              :                                         int op_type)
    5252              : {
    5253           14 :   int i;
    5254           14 :   tree vop0, vop1;
    5255           14 :   gimple *new_stmt1;
    5256           14 :   gimple *new_stmt2;
    5257           14 :   gimple *new_stmt3;
    5258           14 :   vec<tree> vec_tmp = vNULL;
    5259              : 
    5260           14 :   vec_tmp.create (vec_oprnds0->length ());
    5261           28 :   FOR_EACH_VEC_ELT (*vec_oprnds0, i, vop0)
    5262              :     {
    5263           14 :       tree new_tmp1, new_tmp2, new_tmp3, out_type;
    5264              : 
    5265           14 :       gcc_assert (op_type == binary_op);
    5266           14 :       vop1 = (*vec_oprnds1)[i];
    5267              : 
    5268              :       /* Widen the first vector input.  */
    5269           14 :       out_type = TREE_TYPE (vec_dest);
    5270           14 :       new_tmp1 = make_ssa_name (out_type);
    5271           14 :       new_stmt1 = gimple_build_assign (new_tmp1, NOP_EXPR, vop0);
    5272           14 :       vect_finish_stmt_generation (vinfo, stmt_info, new_stmt1, gsi);
    5273           14 :       if (VECTOR_TYPE_P (TREE_TYPE (vop1)))
    5274              :         {
    5275              :           /* Widen the second vector input.  */
    5276           14 :           new_tmp2 = make_ssa_name (out_type);
    5277           14 :           new_stmt2 = gimple_build_assign (new_tmp2, NOP_EXPR, vop1);
    5278           14 :           vect_finish_stmt_generation (vinfo, stmt_info, new_stmt2, gsi);
    5279              :           /* Perform the operation.  With both vector inputs widened.  */
    5280           14 :           new_stmt3 = vect_gimple_build (vec_dest, code1, new_tmp1, new_tmp2);
    5281              :         }
    5282              :       else
    5283              :         {
    5284              :           /* Perform the operation.  With the single vector input widened.  */
    5285            0 :           new_stmt3 = vect_gimple_build (vec_dest, code1, new_tmp1, vop1);
    5286              :         }
    5287              : 
    5288           14 :       new_tmp3 = make_ssa_name (vec_dest, new_stmt3);
    5289           14 :       gimple_assign_set_lhs (new_stmt3, new_tmp3);
    5290           14 :       vect_finish_stmt_generation (vinfo, stmt_info, new_stmt3, gsi);
    5291              : 
    5292              :       /* Store the results for the next step.  */
    5293           14 :       vec_tmp.quick_push (new_tmp3);
    5294              :     }
    5295              : 
    5296           14 :   vec_oprnds0->release ();
    5297           14 :   *vec_oprnds0 = vec_tmp;
    5298           14 : }
    5299              : 
    5300              : 
    5301              : /* Check if STMT_INFO performs a conversion operation that can be vectorized.
    5302              :    If COST_VEC is passed, calculate costs but don't change anything,
    5303              :    otherwise, vectorize STMT_INFO: create a vectorized stmt to replace
    5304              :    it, and insert it at GSI.
    5305              :    Return true if STMT_INFO is vectorizable in this way.  */
    5306              : 
    5307              : static bool
    5308      2346893 : vectorizable_conversion (vec_info *vinfo,
    5309              :                          stmt_vec_info stmt_info, gimple_stmt_iterator *gsi,
    5310              :                          slp_tree slp_node,
    5311              :                          stmt_vector_for_cost *cost_vec)
    5312              : {
    5313      2346893 :   tree vec_dest, cvt_op = NULL_TREE;
    5314      2346893 :   tree scalar_dest;
    5315      2346893 :   tree op0, op1 = NULL_TREE;
    5316      2346893 :   tree_code tc1;
    5317      2346893 :   code_helper code, code1, code2;
    5318      2346893 :   code_helper codecvt1 = ERROR_MARK, codecvt2 = ERROR_MARK;
    5319      2346893 :   tree new_temp;
    5320      2346893 :   enum vect_def_type dt[2] = {vect_unknown_def_type, vect_unknown_def_type};
    5321      2346893 :   poly_uint64 nunits_in;
    5322      2346893 :   poly_uint64 nunits_out;
    5323      2346893 :   tree vectype_out, vectype_in;
    5324      2346893 :   int i;
    5325      2346893 :   tree lhs_type, rhs_type;
    5326              :   /* For conversions between floating point and integer, there're 2 NARROW
    5327              :      cases. NARROW_SRC is for FLOAT_EXPR, means
    5328              :      integer --DEMOTION--> integer --FLOAT_EXPR--> floating point.
    5329              :      This is safe when the range of the source integer can fit into the lower
    5330              :      precision. NARROW_DST is for FIX_TRUNC_EXPR, means
    5331              :      floating point --FIX_TRUNC_EXPR--> integer --DEMOTION--> INTEGER.
    5332              :      For other conversions, when there's narrowing, NARROW_DST is used as
    5333              :      default.  */
    5334      2346893 :   enum { NARROW_SRC, NARROW_DST, NONE, WIDEN } modifier;
    5335      2346893 :   vec<tree> vec_oprnds0 = vNULL;
    5336      2346893 :   vec<tree> vec_oprnds1 = vNULL;
    5337      2346893 :   tree vop0;
    5338      2346893 :   bb_vec_info bb_vinfo = dyn_cast <bb_vec_info> (vinfo);
    5339      2346893 :   loop_vec_info loop_vinfo = dyn_cast <loop_vec_info> (vinfo);
    5340      2346893 :   int multi_step_cvt = 0;
    5341      2346893 :   vec<tree> interm_types = vNULL;
    5342      2346893 :   tree intermediate_type, cvt_type = NULL_TREE;
    5343      2346893 :   int op_type;
    5344      2346893 :   unsigned short fltsz;
    5345              : 
    5346              :   /* Is STMT a vectorizable conversion?   */
    5347              : 
    5348      2346893 :   if (!STMT_VINFO_RELEVANT_P (stmt_info) && !bb_vinfo)
    5349              :     return false;
    5350              : 
    5351      2346893 :   if (STMT_VINFO_DEF_TYPE (stmt_info) != vect_internal_def
    5352       194522 :       && cost_vec)
    5353              :     return false;
    5354              : 
    5355      2152371 :   gimple* stmt = stmt_info->stmt;
    5356      2152371 :   if (!(is_gimple_assign (stmt) || is_gimple_call (stmt)))
    5357              :     return false;
    5358              : 
    5359      2094595 :   if (gimple_get_lhs (stmt) == NULL_TREE
    5360      2094595 :       || TREE_CODE (gimple_get_lhs (stmt)) != SSA_NAME)
    5361       772893 :     return false;
    5362              : 
    5363      1321702 :   if (TREE_CODE (gimple_get_lhs (stmt)) != SSA_NAME)
    5364              :     return false;
    5365              : 
    5366      1321702 :   if (is_gimple_assign (stmt))
    5367              :     {
    5368      1313470 :       code = gimple_assign_rhs_code (stmt);
    5369      1313470 :       op_type = TREE_CODE_LENGTH ((tree_code) code);
    5370              :     }
    5371         8232 :   else if (gimple_call_internal_p (stmt))
    5372              :     {
    5373         4359 :       code = gimple_call_internal_fn (stmt);
    5374         4359 :       op_type = gimple_call_num_args (stmt);
    5375              :     }
    5376              :   else
    5377              :     return false;
    5378              : 
    5379      1317829 :   bool widen_arith = (code == WIDEN_MULT_EXPR
    5380      1315426 :                  || code == WIDEN_LSHIFT_EXPR
    5381      2633255 :                  || widening_fn_p (code));
    5382              : 
    5383      1315426 :   if (!widen_arith
    5384      1315426 :       && !CONVERT_EXPR_CODE_P (code)
    5385      1177797 :       && code != FIX_TRUNC_EXPR
    5386      1176315 :       && code != FLOAT_EXPR)
    5387              :     return false;
    5388              : 
    5389              :   /* Check types of lhs and rhs.  */
    5390       154935 :   scalar_dest = gimple_get_lhs (stmt);
    5391       154935 :   lhs_type = TREE_TYPE (scalar_dest);
    5392       154935 :   vectype_out = SLP_TREE_VECTYPE (slp_node);
    5393              : 
    5394              :   /* Check the operands of the operation.  */
    5395       154935 :   slp_tree slp_op0, slp_op1 = NULL;
    5396       154935 :   if (!vect_is_simple_use (vinfo, slp_node,
    5397              :                            0, &op0, &slp_op0, &dt[0], &vectype_in))
    5398              :     {
    5399            0 :       if (dump_enabled_p ())
    5400            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    5401              :                          "use not simple.\n");
    5402            0 :       return false;
    5403              :     }
    5404              : 
    5405       154935 :   rhs_type = TREE_TYPE (op0);
    5406       153453 :   if ((code != FIX_TRUNC_EXPR && code != FLOAT_EXPR)
    5407       298321 :       && !((INTEGRAL_TYPE_P (lhs_type)
    5408       131799 :             && INTEGRAL_TYPE_P (rhs_type))
    5409              :            || (SCALAR_FLOAT_TYPE_P (lhs_type)
    5410         7162 :                && SCALAR_FLOAT_TYPE_P (rhs_type))))
    5411              :     return false;
    5412              : 
    5413       150510 :   if (!VECTOR_BOOLEAN_TYPE_P (vectype_out)
    5414       134739 :       && INTEGRAL_TYPE_P (lhs_type)
    5415       264666 :       && !type_has_mode_precision_p (lhs_type))
    5416              :     {
    5417          445 :       if (dump_enabled_p ())
    5418            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    5419              :                          "type conversion to bit-precision unsupported\n");
    5420          445 :       return false;
    5421              :     }
    5422              : 
    5423       150065 :   if (op_type == binary_op)
    5424              :     {
    5425         2403 :       gcc_assert (code == WIDEN_MULT_EXPR
    5426              :                   || code == WIDEN_LSHIFT_EXPR
    5427              :                   || widening_fn_p (code));
    5428              : 
    5429         2403 :       op1 = is_gimple_assign (stmt) ? gimple_assign_rhs2 (stmt) :
    5430            0 :                                      gimple_call_arg (stmt, 0);
    5431         2403 :       tree vectype1_in;
    5432         2403 :       if (!vect_is_simple_use (vinfo, slp_node, 1,
    5433              :                                &op1, &slp_op1, &dt[1], &vectype1_in))
    5434              :         {
    5435            0 :           if (dump_enabled_p ())
    5436            0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    5437              :                              "use not simple.\n");
    5438            0 :           return false;
    5439              :         }
    5440              :       /* For WIDEN_MULT_EXPR, if OP0 is a constant, use the type of
    5441              :          OP1.  */
    5442         2403 :       if (!vectype_in)
    5443          101 :         vectype_in = vectype1_in;
    5444              :     }
    5445              : 
    5446              :   /* If op0 is an external or constant def, infer the vector type
    5447              :      from the scalar type.  */
    5448       150065 :   if (!vectype_in)
    5449        20024 :     vectype_in = get_vectype_for_scalar_type (vinfo, rhs_type, slp_node);
    5450       150065 :   if (!cost_vec)
    5451        22934 :     gcc_assert (vectype_in);
    5452       150065 :   if (!vectype_in)
    5453              :     {
    5454          252 :       if (dump_enabled_p ())
    5455            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    5456              :                          "no vectype for scalar type %T\n", rhs_type);
    5457              : 
    5458          252 :       return false;
    5459              :     }
    5460              : 
    5461       299626 :   if (VECTOR_BOOLEAN_TYPE_P (vectype_out)
    5462       149813 :       != VECTOR_BOOLEAN_TYPE_P (vectype_in))
    5463              :     {
    5464          229 :       if (dump_enabled_p ())
    5465           36 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    5466              :                          "can't convert between boolean and non "
    5467              :                          "boolean vectors %T\n", rhs_type);
    5468              : 
    5469          229 :       return false;
    5470              :     }
    5471              : 
    5472       149584 :   nunits_in = TYPE_VECTOR_SUBPARTS (vectype_in);
    5473       149584 :   nunits_out = TYPE_VECTOR_SUBPARTS (vectype_out);
    5474       149584 :   if (known_eq (nunits_out, nunits_in))
    5475        70926 :     if (widen_arith)
    5476              :       modifier = WIDEN;
    5477              :     else
    5478       149584 :       modifier = NONE;
    5479        78658 :   else if (multiple_p (nunits_out, nunits_in))
    5480              :     modifier = NARROW_DST;
    5481              :   else
    5482              :     {
    5483        43987 :       gcc_checking_assert (multiple_p (nunits_in, nunits_out));
    5484              :       modifier = WIDEN;
    5485              :     }
    5486              : 
    5487       149584 :   bool found_mode = false;
    5488       149584 :   scalar_mode lhs_mode = SCALAR_TYPE_MODE (lhs_type);
    5489       149584 :   scalar_mode rhs_mode = SCALAR_TYPE_MODE (rhs_type);
    5490       149584 :   opt_scalar_mode rhs_mode_iter;
    5491       149584 :   auto_vec<std::pair<tree, tree_code>, 2> converts;
    5492       149584 :   bool evenodd_ok = false;
    5493              : 
    5494              :   /* Supportable by target?  */
    5495       149584 :   switch (modifier)
    5496              :     {
    5497        70683 :     case NONE:
    5498        70683 :       if (code != FIX_TRUNC_EXPR
    5499        69808 :           && code != FLOAT_EXPR
    5500       134307 :           && !CONVERT_EXPR_CODE_P (code))
    5501              :         return false;
    5502        70683 :       gcc_assert (code.is_tree_code ());
    5503        70683 :       if (supportable_indirect_convert_operation (code,
    5504              :                                                   vectype_out, vectype_in,
    5505              :                                                   converts, op0, slp_op0))
    5506              :         {
    5507        16045 :           gcc_assert (converts.length () <= 2);
    5508        16045 :           if (converts.length () == 1)
    5509        15971 :             code1 = converts[0].second;
    5510              :           else
    5511              :             {
    5512           74 :               cvt_type = NULL_TREE;
    5513           74 :               multi_step_cvt = converts.length () - 1;
    5514           74 :               codecvt1 = converts[0].second;
    5515           74 :               code1 = converts[1].second;
    5516           74 :               interm_types.safe_push (converts[0].first);
    5517              :             }
    5518              :           break;
    5519              :         }
    5520              : 
    5521              :       /* FALLTHRU */
    5522        54638 :     unsupported:
    5523        61076 :       if (dump_enabled_p ())
    5524         5888 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    5525              :                          "conversion not supported by target.\n");
    5526              :       return false;
    5527              : 
    5528        44230 :     case WIDEN:
    5529        44230 :       if (known_eq (nunits_in, nunits_out))
    5530              :         {
    5531          486 :           if (!(code.is_tree_code ()
    5532          243 :                 && supportable_half_widening_operation ((tree_code) code,
    5533              :                                                         vectype_out, vectype_in,
    5534              :                                                         &tc1)))
    5535           74 :             goto unsupported;
    5536          169 :           code1 = tc1;
    5537          169 :           gcc_assert (!(multi_step_cvt && op_type == binary_op));
    5538              :           break;
    5539              :         }
    5540              :       /* Elements in a vector can only be reordered if used in a reduction
    5541              :          operation only.  */
    5542        43987 :       if (code == WIDEN_MULT_EXPR
    5543         2160 :           && loop_vinfo
    5544         2111 :           && !nested_in_vect_loop_p (LOOP_VINFO_LOOP (loop_vinfo), stmt_info)
    5545              :           /* For a SLP reduction we cannot swizzle lanes, detecting a
    5546              :              reduction chain isn't possible here.  */
    5547        46076 :           && SLP_TREE_LANES (slp_node) == 1)
    5548              :         {
    5549              :           /* ???  There is no way to look for SLP uses, so work on
    5550              :              the stmt and what the stmt-based cycle detection gives us.  */
    5551         1991 :           tree lhs = gimple_get_lhs (vect_orig_stmt (stmt_info)->stmt);
    5552         1991 :           stmt_vec_info use_stmt_info
    5553         1991 :             = lhs ? loop_vinfo->lookup_single_use (lhs) : NULL;
    5554         1991 :           if (use_stmt_info
    5555         1843 :               && STMT_VINFO_REDUC_DEF (use_stmt_info))
    5556        43987 :             evenodd_ok = true;
    5557              :         }
    5558        43987 :       if (supportable_widening_operation (code, vectype_out, vectype_in,
    5559              :                                           evenodd_ok, &code1,
    5560              :                                           &code2, &multi_step_cvt,
    5561              :                                           &interm_types))
    5562              :         {
    5563              :           /* Binary widening operation can only be supported directly by the
    5564              :              architecture.  */
    5565        42285 :           gcc_assert (!(multi_step_cvt && op_type == binary_op));
    5566              :           break;
    5567              :         }
    5568              : 
    5569         1702 :       if (code != FLOAT_EXPR
    5570         2026 :           || GET_MODE_SIZE (lhs_mode) <= GET_MODE_SIZE (rhs_mode))
    5571         1540 :         goto unsupported;
    5572              : 
    5573          162 :       fltsz = GET_MODE_SIZE (lhs_mode);
    5574          237 :       FOR_EACH_2XWIDER_MODE (rhs_mode_iter, rhs_mode)
    5575              :         {
    5576          237 :           rhs_mode = rhs_mode_iter.require ();
    5577          474 :           if (GET_MODE_SIZE (rhs_mode) > fltsz)
    5578              :             break;
    5579              : 
    5580          237 :           cvt_type
    5581          237 :             = build_nonstandard_integer_type (GET_MODE_BITSIZE (rhs_mode), 0);
    5582          237 :           cvt_type = get_same_sized_vectype (cvt_type, vectype_in);
    5583          237 :           if (cvt_type == NULL_TREE)
    5584            0 :             goto unsupported;
    5585              : 
    5586          474 :           if (GET_MODE_SIZE (rhs_mode) == fltsz)
    5587              :             {
    5588           57 :               tc1 = ERROR_MARK;
    5589           57 :               gcc_assert (code.is_tree_code ());
    5590           57 :               if (!supportable_convert_operation ((tree_code) code, vectype_out,
    5591              :                                                   cvt_type, &tc1))
    5592           22 :                 goto unsupported;
    5593           35 :               codecvt1 = tc1;
    5594              :             }
    5595          180 :           else if (!supportable_widening_operation (code, vectype_out,
    5596              :                                                     cvt_type, evenodd_ok,
    5597              :                                                     &codecvt1,
    5598              :                                                     &codecvt2, &multi_step_cvt,
    5599              :                                                     &interm_types))
    5600           75 :             continue;
    5601              :           else
    5602          105 :             gcc_assert (multi_step_cvt == 0);
    5603              : 
    5604          140 :           if (supportable_widening_operation (NOP_EXPR, cvt_type,
    5605              :                                               vectype_in, evenodd_ok, &code1,
    5606              :                                               &code2, &multi_step_cvt,
    5607              :                                               &interm_types))
    5608              :             {
    5609              :               found_mode = true;
    5610              :               break;
    5611              :             }
    5612              :         }
    5613              : 
    5614          140 :       if (!found_mode)
    5615            0 :         goto unsupported;
    5616              : 
    5617          280 :       if (GET_MODE_SIZE (rhs_mode) == fltsz)
    5618           35 :         codecvt2 = ERROR_MARK;
    5619              :       else
    5620              :         {
    5621          105 :           multi_step_cvt++;
    5622          105 :           interm_types.safe_push (cvt_type);
    5623          105 :           cvt_type = NULL_TREE;
    5624              :         }
    5625              :       break;
    5626              : 
    5627        34671 :     case NARROW_DST:
    5628        34671 :       gcc_assert (op_type == unary_op);
    5629        34671 :       if (supportable_narrowing_operation (code, vectype_out, vectype_in,
    5630              :                                            &code1, &multi_step_cvt,
    5631              :                                            &interm_types))
    5632              :         break;
    5633              : 
    5634        14664 :       if (GET_MODE_SIZE (lhs_mode) >= GET_MODE_SIZE (rhs_mode))
    5635          966 :         goto unsupported;
    5636              : 
    5637         3922 :       if (code == FIX_TRUNC_EXPR)
    5638              :         {
    5639           82 :           cvt_type
    5640           82 :             = build_nonstandard_integer_type (GET_MODE_BITSIZE (rhs_mode), 0);
    5641           82 :           cvt_type = get_same_sized_vectype (cvt_type, vectype_in);
    5642           82 :           if (cvt_type == NULL_TREE)
    5643            0 :             goto unsupported;
    5644           82 :           if (supportable_convert_operation ((tree_code) code, cvt_type, vectype_in,
    5645              :                                               &tc1))
    5646           80 :             codecvt1 = tc1;
    5647              :           else
    5648            2 :             goto unsupported;
    5649           80 :           if (supportable_narrowing_operation (NOP_EXPR, vectype_out, cvt_type,
    5650              :                                                &code1, &multi_step_cvt,
    5651              :                                                &interm_types))
    5652              :             break;
    5653              :         }
    5654              :       /* If op0 can be represented with low precision integer,
    5655              :          truncate it to cvt_type and the do FLOAT_EXPR.  */
    5656         3840 :       else if (code == FLOAT_EXPR)
    5657              :         {
    5658           96 :           if (cost_vec)
    5659              :             {
    5660           91 :               wide_int op_min_value, op_max_value;
    5661           91 :               tree def;
    5662              : 
    5663              :               /* ???  Merge ranges in case of more than one lane.  */
    5664           91 :               if (SLP_TREE_LANES (slp_op0) != 1
    5665           89 :                   || !(def = vect_get_slp_scalar_def (slp_op0, 0))
    5666          180 :                   || !vect_get_range_info (def, &op_min_value, &op_max_value))
    5667           86 :                 goto unsupported;
    5668              : 
    5669            5 :               if ((wi::min_precision (op_max_value, SIGNED)
    5670            5 :                    > GET_MODE_BITSIZE (lhs_mode))
    5671            5 :                   || (wi::min_precision (op_min_value, SIGNED)
    5672            5 :                       > GET_MODE_BITSIZE (lhs_mode)))
    5673            0 :                 goto unsupported;
    5674           91 :             }
    5675              : 
    5676           10 :           cvt_type
    5677           10 :             = build_nonstandard_integer_type (GET_MODE_BITSIZE (lhs_mode), 0);
    5678           10 :           cvt_type = get_same_sized_vectype (cvt_type, vectype_out);
    5679           10 :           if (cvt_type == NULL_TREE)
    5680            0 :             goto unsupported;
    5681           10 :           if (!supportable_narrowing_operation (NOP_EXPR, cvt_type, vectype_in,
    5682              :                                                 &code1, &multi_step_cvt,
    5683              :                                                 &interm_types))
    5684            0 :             goto unsupported;
    5685           10 :           if (supportable_convert_operation ((tree_code) code, vectype_out,
    5686              :                                              cvt_type, &tc1))
    5687              :             {
    5688           10 :               codecvt1 = tc1;
    5689           10 :               modifier = NARROW_SRC;
    5690           10 :               break;
    5691              :             }
    5692              :         }
    5693              : 
    5694         3748 :       goto unsupported;
    5695              : 
    5696              :     default:
    5697              :       gcc_unreachable ();
    5698              :     }
    5699              : 
    5700        88508 :   if (modifier == WIDEN
    5701        88508 :       && loop_vinfo
    5702        41447 :       && LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo)
    5703       105672 :       && (code1 == VEC_WIDEN_MULT_EVEN_EXPR
    5704        17148 :           || widening_evenodd_fn_p (code1)))
    5705              :     {
    5706           16 :       if (dump_enabled_p ())
    5707            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    5708              :                          "can't use a fully-masked loop because"
    5709              :                          " widening operation on even/odd elements"
    5710              :                          " mixes up lanes.\n");
    5711           16 :       LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo) = false;
    5712              :     }
    5713              : 
    5714        88508 :   if (cost_vec)         /* transformation not required.  */
    5715              :     {
    5716        65574 :       if (!vect_maybe_update_slp_op_vectype (slp_op0, vectype_in)
    5717        65574 :           || !vect_maybe_update_slp_op_vectype (slp_op1, vectype_in))
    5718              :         {
    5719            0 :           if (dump_enabled_p ())
    5720            0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    5721              :                              "incompatible vector types for invariants\n");
    5722            0 :           return false;
    5723              :         }
    5724        65574 :       DUMP_VECT_SCOPE ("vectorizable_conversion");
    5725        65574 :       unsigned int nvectors = vect_get_num_copies (vinfo, slp_node);
    5726        65574 :       if (modifier == NONE)
    5727              :         {
    5728        12067 :           SLP_TREE_TYPE (slp_node) = type_conversion_vec_info_type;
    5729        12067 :           vect_model_simple_cost (vinfo, (1 + multi_step_cvt),
    5730              :                                   slp_node, cost_vec);
    5731              :         }
    5732        53507 :       else if (modifier == NARROW_SRC || modifier == NARROW_DST)
    5733              :         {
    5734        20862 :           SLP_TREE_TYPE (slp_node) = type_demotion_vec_info_type;
    5735              :           /* The final packing step produces one vector result per copy.  */
    5736        20862 :           vect_model_promotion_demotion_cost (slp_node, nvectors,
    5737              :                                               multi_step_cvt, cost_vec,
    5738              :                                               widen_arith);
    5739              :         }
    5740              :       else
    5741              :         {
    5742        32645 :           SLP_TREE_TYPE (slp_node) = type_promotion_vec_info_type;
    5743              :           /* The initial unpacking step produces two vector results
    5744              :              per copy.  MULTI_STEP_CVT is 0 for a single conversion,
    5745              :              so >> MULTI_STEP_CVT divides by 2^(number of steps - 1).  */
    5746        32645 :           vect_model_promotion_demotion_cost (slp_node,
    5747              :                                               nvectors >> multi_step_cvt,
    5748              :                                               multi_step_cvt, cost_vec,
    5749              :                                               widen_arith);
    5750              :         }
    5751        65574 :       interm_types.release ();
    5752        65574 :       return true;
    5753        65574 :     }
    5754              : 
    5755              :   /* Transform.  */
    5756        22934 :   if (dump_enabled_p ())
    5757         4266 :     dump_printf_loc (MSG_NOTE, vect_location, "transform conversion.\n");
    5758              : 
    5759        22934 :   if (op_type == binary_op)
    5760              :     {
    5761          513 :       if (CONSTANT_CLASS_P (op0))
    5762            0 :         op0 = fold_convert (TREE_TYPE (op1), op0);
    5763          513 :       else if (CONSTANT_CLASS_P (op1))
    5764          237 :         op1 = fold_convert (TREE_TYPE (op0), op1);
    5765              :     }
    5766              : 
    5767              :   /* In case of multi-step conversion, we first generate conversion operations
    5768              :      to the intermediate types, and then from that types to the final one.
    5769              :      We create vector destinations for the intermediate type (TYPES) received
    5770              :      from supportable_*_operation, and store them in the correct order
    5771              :      for future use in vect_create_vectorized_*_stmts ().  */
    5772        22934 :   auto_vec<tree> vec_dsts (multi_step_cvt + 1);
    5773        22934 :   bool widen_or_narrow_float_p
    5774        22934 :     = cvt_type && (modifier == WIDEN || modifier == NARROW_SRC);
    5775        22934 :   vec_dest = vect_create_destination_var (scalar_dest,
    5776              :                                           widen_or_narrow_float_p
    5777              :                                           ? cvt_type : vectype_out);
    5778        22934 :   vec_dsts.quick_push (vec_dest);
    5779              : 
    5780        22934 :   if (multi_step_cvt)
    5781              :     {
    5782         9344 :       for (i = interm_types.length () - 1;
    5783         9344 :            interm_types.iterate (i, &intermediate_type); i--)
    5784              :         {
    5785         4918 :           vec_dest = vect_create_destination_var (scalar_dest,
    5786              :                                                   intermediate_type);
    5787         4918 :           vec_dsts.quick_push (vec_dest);
    5788              :         }
    5789              :     }
    5790              : 
    5791        22934 :   if (cvt_type)
    5792           73 :     vec_dest = vect_create_destination_var (scalar_dest,
    5793              :                                             widen_or_narrow_float_p
    5794              :                                             ? vectype_out : cvt_type);
    5795              : 
    5796        22934 :   switch (modifier)
    5797              :     {
    5798         3978 :     case NONE:
    5799         3978 :       vect_get_vec_defs (vinfo, slp_node, op0, &vec_oprnds0);
    5800              :       /* vec_dest is intermediate type operand when multi_step_cvt.  */
    5801         3978 :       if (multi_step_cvt)
    5802              :         {
    5803           21 :           cvt_op = vec_dest;
    5804           21 :           vec_dest = vec_dsts[0];
    5805              :         }
    5806              : 
    5807         8332 :       FOR_EACH_VEC_ELT (vec_oprnds0, i, vop0)
    5808              :         {
    5809              :           /* Arguments are ready, create the new vector stmt.  */
    5810         4354 :           gimple* new_stmt;
    5811         4354 :           if (multi_step_cvt)
    5812              :             {
    5813           21 :               gcc_assert (multi_step_cvt == 1);
    5814           21 :               new_stmt = vect_gimple_build (cvt_op, codecvt1, vop0);
    5815           21 :               new_temp = make_ssa_name (cvt_op, new_stmt);
    5816           21 :               gimple_assign_set_lhs (new_stmt, new_temp);
    5817           21 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    5818           21 :               vop0 = new_temp;
    5819              :             }
    5820         4354 :           new_stmt = vect_gimple_build (vec_dest, code1, vop0);
    5821         4354 :           new_temp = make_ssa_name (vec_dest, new_stmt);
    5822         4354 :           gimple_set_lhs (new_stmt, new_temp);
    5823         4354 :           vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    5824              : 
    5825         4354 :           slp_node->push_vec_def (new_stmt);
    5826              :         }
    5827              :       break;
    5828              : 
    5829         9949 :     case WIDEN:
    5830              :       /* In case the vectorization factor (VF) is bigger than the number
    5831              :          of elements that we can fit in a vectype (nunits), we have to
    5832              :          generate more than one vector stmt - i.e - we need to "unroll"
    5833              :          the vector stmt by a factor VF/nunits.  */
    5834         9949 :       vect_get_vec_defs (vinfo, slp_node, op0, &vec_oprnds0,
    5835         9949 :                          code == WIDEN_LSHIFT_EXPR ? NULL_TREE : op1,
    5836              :                          &vec_oprnds1);
    5837         9949 :       if (code == WIDEN_LSHIFT_EXPR)
    5838              :         {
    5839            0 :           int oprnds_size = vec_oprnds0.length ();
    5840            0 :           vec_oprnds1.create (oprnds_size);
    5841            0 :           for (i = 0; i < oprnds_size; ++i)
    5842            0 :             vec_oprnds1.quick_push (op1);
    5843              :         }
    5844              :       /* Arguments are ready.  Create the new vector stmts.  */
    5845        21824 :       for (i = multi_step_cvt; i >= 0; i--)
    5846              :         {
    5847        11875 :           tree this_dest = vec_dsts[i];
    5848        11875 :           code_helper c1 = code1, c2 = code2;
    5849        11875 :           if (i == 0 && codecvt2 != ERROR_MARK)
    5850              :             {
    5851           48 :               c1 = codecvt1;
    5852           48 :               c2 = codecvt2;
    5853              :             }
    5854        11875 :           if (known_eq (nunits_out, nunits_in))
    5855           14 :             vect_create_half_widening_stmts (vinfo, &vec_oprnds0, &vec_oprnds1,
    5856              :                                              stmt_info, this_dest, gsi, c1,
    5857              :                                              op_type);
    5858              :           else
    5859        11861 :             vect_create_vectorized_promotion_stmts (vinfo, &vec_oprnds0,
    5860              :                                                     &vec_oprnds1, stmt_info,
    5861              :                                                     this_dest, gsi,
    5862              :                                                     c1, c2, op_type);
    5863              :         }
    5864              : 
    5865        38155 :       FOR_EACH_VEC_ELT (vec_oprnds0, i, vop0)
    5866              :         {
    5867        28206 :           gimple *new_stmt;
    5868        28206 :           if (cvt_type)
    5869              :             {
    5870          120 :               new_temp = make_ssa_name (vec_dest);
    5871          120 :               new_stmt = vect_gimple_build (new_temp, codecvt1, vop0);
    5872          120 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    5873              :             }
    5874              :           else
    5875        28086 :             new_stmt = SSA_NAME_DEF_STMT (vop0);
    5876              : 
    5877        28206 :           slp_node->push_vec_def (new_stmt);
    5878              :         }
    5879              :       break;
    5880              : 
    5881         9007 :     case NARROW_SRC:
    5882         9007 :     case NARROW_DST:
    5883              :       /* In case the vectorization factor (VF) is bigger than the number
    5884              :          of elements that we can fit in a vectype (nunits), we have to
    5885              :          generate more than one vector stmt - i.e - we need to "unroll"
    5886              :          the vector stmt by a factor VF/nunits.  */
    5887         9007 :       vect_get_vec_defs (vinfo, slp_node, op0, &vec_oprnds0);
    5888              :       /* Arguments are ready.  Create the new vector stmts.  */
    5889         9007 :       if (cvt_type && modifier == NARROW_DST)
    5890          153 :         FOR_EACH_VEC_ELT (vec_oprnds0, i, vop0)
    5891              :           {
    5892          124 :             new_temp = make_ssa_name (vec_dest);
    5893          124 :             gimple *new_stmt = vect_gimple_build (new_temp, codecvt1, vop0);
    5894          124 :             vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    5895          124 :             vec_oprnds0[i] = new_temp;
    5896              :           }
    5897              : 
    5898         9007 :       vect_create_vectorized_demotion_stmts (vinfo, &vec_oprnds0,
    5899              :                                              multi_step_cvt,
    5900              :                                              stmt_info, vec_dsts, gsi,
    5901              :                                              slp_node, code1,
    5902              :                                              modifier == NARROW_SRC);
    5903              :       /* After demoting op0 to cvt_type, convert it to dest.  */
    5904         9007 :       if (cvt_type && code == FLOAT_EXPR)
    5905              :         {
    5906           10 :           for (unsigned int i = 0; i != vec_oprnds0.length() / 2;  i++)
    5907              :             {
    5908              :               /* Arguments are ready, create the new vector stmt.  */
    5909            5 :               gcc_assert (TREE_CODE_LENGTH ((tree_code) codecvt1) == unary_op);
    5910            5 :               gimple *new_stmt
    5911            5 :                 = vect_gimple_build (vec_dest, codecvt1, vec_oprnds0[i]);
    5912            5 :               new_temp = make_ssa_name (vec_dest, new_stmt);
    5913            5 :               gimple_set_lhs (new_stmt, new_temp);
    5914            5 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    5915              : 
    5916              :               /* This is the last step of the conversion sequence. Store the
    5917              :                  vectors in SLP_NODE or in vector info of the scalar statement
    5918              :                  (or in STMT_VINFO_RELATED_STMT chain).  */
    5919            5 :               slp_node->push_vec_def (new_stmt);
    5920              :             }
    5921              :         }
    5922              :       break;
    5923              :     }
    5924              : 
    5925        22934 :   vec_oprnds0.release ();
    5926        22934 :   vec_oprnds1.release ();
    5927        22934 :   interm_types.release ();
    5928              : 
    5929        22934 :   return true;
    5930       149584 : }
    5931              : 
    5932              : /* Return true if we can assume from the scalar form of STMT_INFO that
    5933              :    neither the scalar nor the vector forms will generate code.  STMT_INFO
    5934              :    is known not to involve a data reference.  */
    5935              : 
    5936              : bool
    5937      1013205 : vect_nop_conversion_p (stmt_vec_info stmt_info)
    5938              : {
    5939      1013205 :   gassign *stmt = dyn_cast <gassign *> (stmt_info->stmt);
    5940       749129 :   if (!stmt)
    5941              :     return false;
    5942              : 
    5943       749129 :   tree lhs = gimple_assign_lhs (stmt);
    5944       749129 :   tree_code code = gimple_assign_rhs_code (stmt);
    5945       749129 :   tree rhs = gimple_assign_rhs1 (stmt);
    5946              : 
    5947       749129 :   if (code == SSA_NAME || code == VIEW_CONVERT_EXPR)
    5948              :     return true;
    5949              : 
    5950       746836 :   if (CONVERT_EXPR_CODE_P (code))
    5951       194066 :     return tree_nop_conversion_p (TREE_TYPE (lhs), TREE_TYPE (rhs));
    5952              : 
    5953              :   return false;
    5954              : }
    5955              : 
    5956              : /* Function vectorizable_assignment.
    5957              : 
    5958              :    Check if STMT_INFO performs an assignment (copy) that can be vectorized.
    5959              :    If COST_VEC is passed, calculate costs but don't change anything,
    5960              :    otherwise, vectorize STMT_INFO: create a vectorized stmt to replace
    5961              :    it, and insert it at GSI.
    5962              :    Return true if STMT_INFO is vectorizable in this way.  */
    5963              : 
    5964              : static bool
    5965      1855434 : vectorizable_assignment (vec_info *vinfo,
    5966              :                          stmt_vec_info stmt_info, gimple_stmt_iterator *gsi,
    5967              :                          slp_tree slp_node,
    5968              :                          stmt_vector_for_cost *cost_vec)
    5969              : {
    5970      1855434 :   tree vec_dest;
    5971      1855434 :   tree scalar_dest;
    5972      1855434 :   tree op;
    5973      1855434 :   tree new_temp;
    5974      1855434 :   enum vect_def_type dt[1] = {vect_unknown_def_type};
    5975      1855434 :   int i;
    5976      1855434 :   vec<tree> vec_oprnds = vNULL;
    5977      1855434 :   tree vop;
    5978      1855434 :   bb_vec_info bb_vinfo = dyn_cast <bb_vec_info> (vinfo);
    5979      1855434 :   enum tree_code code;
    5980      1855434 :   tree vectype_in;
    5981              : 
    5982      1855434 :   if (!STMT_VINFO_RELEVANT_P (stmt_info) && !bb_vinfo)
    5983              :     return false;
    5984              : 
    5985      1855434 :   if (STMT_VINFO_DEF_TYPE (stmt_info) != vect_internal_def
    5986       194522 :       && cost_vec)
    5987              :     return false;
    5988              : 
    5989              :   /* Is vectorizable assignment?  */
    5990      3377085 :   gassign *stmt = dyn_cast <gassign *> (stmt_info->stmt);
    5991      1593985 :   if (!stmt)
    5992              :     return false;
    5993              : 
    5994      1593985 :   scalar_dest = gimple_assign_lhs (stmt);
    5995      1593985 :   if (TREE_CODE (scalar_dest) != SSA_NAME)
    5996              :     return false;
    5997              : 
    5998       822011 :   if (STMT_VINFO_DATA_REF (stmt_info))
    5999              :     return false;
    6000              : 
    6001       349632 :   code = gimple_assign_rhs_code (stmt);
    6002       349632 :   if (!(gimple_assign_single_p (stmt)
    6003       348280 :         || code == PAREN_EXPR
    6004       347226 :         || CONVERT_EXPR_CODE_P (code)))
    6005              :     return false;
    6006              : 
    6007        82525 :   tree vectype = SLP_TREE_VECTYPE (slp_node);
    6008        82525 :   poly_uint64 nunits = TYPE_VECTOR_SUBPARTS (vectype);
    6009              : 
    6010        82525 :   slp_tree slp_op;
    6011        82525 :   if (!vect_is_simple_use (vinfo, slp_node, 0, &op, &slp_op,
    6012              :                            &dt[0], &vectype_in))
    6013              :     {
    6014            0 :       if (dump_enabled_p ())
    6015            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6016              :                          "use not simple.\n");
    6017            0 :       return false;
    6018              :     }
    6019        82525 :   if (!vectype_in)
    6020        17786 :     vectype_in = get_vectype_for_scalar_type (vinfo, TREE_TYPE (op), slp_node);
    6021              : 
    6022              :   /* We can handle VIEW_CONVERT conversions that do not change the number
    6023              :      of elements or the vector size or other conversions when the component
    6024              :      types are nop-convertible.  */
    6025        82525 :   if (!vectype_in
    6026        82253 :       || maybe_ne (TYPE_VECTOR_SUBPARTS (vectype_in), nunits)
    6027        75511 :       || (code == VIEW_CONVERT_EXPR
    6028         2448 :           && maybe_ne (GET_MODE_SIZE (TYPE_MODE (vectype)),
    6029         2448 :                        GET_MODE_SIZE (TYPE_MODE (vectype_in))))
    6030       158036 :       || (CONVERT_EXPR_CODE_P (code)
    6031        73137 :           && !tree_nop_conversion_p (TREE_TYPE (vectype),
    6032        73137 :                                      TREE_TYPE (vectype_in))))
    6033         9923 :     return false;
    6034              : 
    6035       217728 :   if (VECTOR_BOOLEAN_TYPE_P (vectype) != VECTOR_BOOLEAN_TYPE_P (vectype_in))
    6036              :     {
    6037            2 :       if (dump_enabled_p ())
    6038            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6039              :                          "can't convert between boolean and non "
    6040            0 :                          "boolean vectors %T\n", TREE_TYPE (op));
    6041              : 
    6042            2 :       return false;
    6043              :     }
    6044              : 
    6045              :   /* We do not handle bit-precision changes.  */
    6046        72600 :   if ((CONVERT_EXPR_CODE_P (code)
    6047         2374 :        || code == VIEW_CONVERT_EXPR)
    6048        71450 :       && ((INTEGRAL_TYPE_P (TREE_TYPE (scalar_dest))
    6049        70201 :            && !type_has_mode_precision_p (TREE_TYPE (scalar_dest)))
    6050        71144 :           || (INTEGRAL_TYPE_P (TREE_TYPE (op))
    6051        66553 :               && !type_has_mode_precision_p (TREE_TYPE (op))))
    6052              :       /* But a conversion that does not change the bit-pattern is ok.  */
    6053        73310 :       && !(INTEGRAL_TYPE_P (TREE_TYPE (scalar_dest))
    6054          710 :            && INTEGRAL_TYPE_P (TREE_TYPE (op))
    6055          710 :            && (((TYPE_PRECISION (TREE_TYPE (scalar_dest))
    6056          710 :                > TYPE_PRECISION (TREE_TYPE (op)))
    6057          404 :              && TYPE_UNSIGNED (TREE_TYPE (op)))
    6058          322 :                || (TYPE_PRECISION (TREE_TYPE (scalar_dest))
    6059          322 :                    == TYPE_PRECISION (TREE_TYPE (op))))))
    6060              :     {
    6061          266 :       if (dump_enabled_p ())
    6062            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6063              :                          "type conversion to/from bit-precision "
    6064              :                          "unsupported.\n");
    6065          266 :       return false;
    6066              :     }
    6067              : 
    6068        72334 :   if (cost_vec) /* transformation not required.  */
    6069              :     {
    6070        57314 :       if (!vect_maybe_update_slp_op_vectype (slp_op, vectype_in))
    6071              :         {
    6072            0 :           if (dump_enabled_p ())
    6073            0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6074              :                              "incompatible vector types for invariants\n");
    6075            0 :           return false;
    6076              :         }
    6077        57314 :       SLP_TREE_TYPE (slp_node) = assignment_vec_info_type;
    6078        57314 :       DUMP_VECT_SCOPE ("vectorizable_assignment");
    6079        57314 :       if (!vect_nop_conversion_p (stmt_info))
    6080          827 :         vect_model_simple_cost (vinfo, 1, slp_node, cost_vec);
    6081        57314 :       return true;
    6082              :     }
    6083              : 
    6084              :   /* Transform.  */
    6085        15020 :   if (dump_enabled_p ())
    6086         3591 :     dump_printf_loc (MSG_NOTE, vect_location, "transform assignment.\n");
    6087              : 
    6088              :   /* Handle def.  */
    6089        15020 :   vec_dest = vect_create_destination_var (scalar_dest, vectype);
    6090              : 
    6091              :   /* Handle use.  */
    6092        15020 :   vect_get_vec_defs (vinfo, slp_node, op, &vec_oprnds);
    6093              : 
    6094              :   /* Arguments are ready. create the new vector stmt.  */
    6095        34150 :   FOR_EACH_VEC_ELT (vec_oprnds, i, vop)
    6096              :     {
    6097        19130 :       if (CONVERT_EXPR_CODE_P (code)
    6098          683 :           || code == VIEW_CONVERT_EXPR)
    6099        18581 :         vop = build1 (VIEW_CONVERT_EXPR, vectype, vop);
    6100        19130 :       gassign *new_stmt = gimple_build_assign (vec_dest, vop);
    6101        19130 :       new_temp = make_ssa_name (vec_dest, new_stmt);
    6102        19130 :       gimple_assign_set_lhs (new_stmt, new_temp);
    6103        19130 :       vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    6104        19130 :       slp_node->push_vec_def (new_stmt);
    6105              :     }
    6106              : 
    6107        15020 :   vec_oprnds.release ();
    6108        15020 :   return true;
    6109              : }
    6110              : 
    6111              : 
    6112              : /* Return TRUE if CODE (a shift operation) is supported for SCALAR_TYPE
    6113              :    either as shift by a scalar or by a vector.  */
    6114              : 
    6115              : bool
    6116       279634 : vect_supportable_shift (vec_info *vinfo, enum tree_code code, tree scalar_type)
    6117              : {
    6118       279634 :   optab optab;
    6119       279634 :   tree vectype;
    6120              : 
    6121       279634 :   vectype = get_vectype_for_scalar_type (vinfo, scalar_type);
    6122       279634 :   if (!vectype)
    6123              :     return false;
    6124              : 
    6125       279634 :   optab = optab_for_tree_code (code, vectype, optab_scalar);
    6126       279634 :   if (optab && can_implement_p (optab, TYPE_MODE (vectype)))
    6127              :     return true;
    6128              : 
    6129       246191 :   optab = optab_for_tree_code (code, vectype, optab_vector);
    6130       246191 :   if (optab && can_implement_p (optab, TYPE_MODE (vectype)))
    6131              :     return true;
    6132              : 
    6133              :   return false;
    6134              : }
    6135              : 
    6136              : 
    6137              : /* Function vectorizable_shift.
    6138              : 
    6139              :    Check if STMT_INFO performs a shift operation that can be vectorized.
    6140              :    If COST_VEC is passed, calculate costs but don't change anything,
    6141              :    otherwise, vectorize STMT_INFO: create a vectorized stmt to replace
    6142              :    it, and insert it at GSI.
    6143              :    Return true if STMT_INFO is vectorizable in this way.  */
    6144              : 
    6145              : static bool
    6146       651074 : vectorizable_shift (vec_info *vinfo,
    6147              :                     stmt_vec_info stmt_info, gimple_stmt_iterator *gsi,
    6148              :                     slp_tree slp_node,
    6149              :                     stmt_vector_for_cost *cost_vec)
    6150              : {
    6151       651074 :   tree vec_dest;
    6152       651074 :   tree scalar_dest;
    6153       651074 :   tree op0, op1 = NULL;
    6154       651074 :   tree vec_oprnd1 = NULL_TREE;
    6155       651074 :   tree vectype;
    6156       651074 :   enum tree_code code;
    6157       651074 :   machine_mode vec_mode;
    6158       651074 :   tree new_temp;
    6159       651074 :   optab optab;
    6160       651074 :   int icode;
    6161       651074 :   machine_mode optab_op2_mode;
    6162       651074 :   enum vect_def_type dt[2] = {vect_unknown_def_type, vect_unknown_def_type};
    6163       651074 :   poly_uint64 nunits_in;
    6164       651074 :   poly_uint64 nunits_out;
    6165       651074 :   tree vectype_out;
    6166       651074 :   tree op1_vectype;
    6167       651074 :   int i;
    6168       651074 :   vec<tree> vec_oprnds0 = vNULL;
    6169       651074 :   vec<tree> vec_oprnds1 = vNULL;
    6170       651074 :   tree vop0, vop1;
    6171       651074 :   unsigned int k;
    6172       651074 :   bool scalar_shift_arg = true;
    6173       651074 :   bb_vec_info bb_vinfo = dyn_cast <bb_vec_info> (vinfo);
    6174       651074 :   bool incompatible_op1_vectype_p = false;
    6175              : 
    6176       651074 :   if (!STMT_VINFO_RELEVANT_P (stmt_info) && !bb_vinfo)
    6177              :     return false;
    6178              : 
    6179       651074 :   if (STMT_VINFO_DEF_TYPE (stmt_info) != vect_internal_def
    6180       194522 :       && STMT_VINFO_DEF_TYPE (stmt_info) != vect_nested_cycle
    6181       193095 :       && cost_vec)
    6182              :     return false;
    6183              : 
    6184              :   /* Is STMT a vectorizable binary/unary operation?   */
    6185       989190 :   gassign *stmt = dyn_cast <gassign *> (stmt_info->stmt);
    6186       391398 :   if (!stmt)
    6187              :     return false;
    6188              : 
    6189       391398 :   if (TREE_CODE (gimple_assign_lhs (stmt)) != SSA_NAME)
    6190              :     return false;
    6191              : 
    6192       390916 :   code = gimple_assign_rhs_code (stmt);
    6193              : 
    6194       390916 :   if (!(code == LSHIFT_EXPR || code == RSHIFT_EXPR || code == LROTATE_EXPR
    6195              :       || code == RROTATE_EXPR))
    6196              :     return false;
    6197              : 
    6198        58608 :   scalar_dest = gimple_assign_lhs (stmt);
    6199        58608 :   vectype_out = SLP_TREE_VECTYPE (slp_node);
    6200        58608 :   if (!type_has_mode_precision_p (TREE_TYPE (scalar_dest)))
    6201              :     {
    6202            0 :       if (dump_enabled_p ())
    6203            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6204              :                          "bit-precision shifts not supported.\n");
    6205            0 :       return false;
    6206              :     }
    6207              : 
    6208        58608 :   slp_tree slp_op0;
    6209        58608 :   if (!vect_is_simple_use (vinfo, slp_node,
    6210              :                            0, &op0, &slp_op0, &dt[0], &vectype))
    6211              :     {
    6212            0 :       if (dump_enabled_p ())
    6213            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6214              :                          "use not simple.\n");
    6215            0 :       return false;
    6216              :     }
    6217              :   /* If op0 is an external or constant def, infer the vector type
    6218              :      from the scalar type.  */
    6219        58608 :   if (!vectype)
    6220        12183 :     vectype = get_vectype_for_scalar_type (vinfo, TREE_TYPE (op0), slp_node);
    6221        58608 :   if (!cost_vec)
    6222         7821 :     gcc_assert (vectype);
    6223        58608 :   if (!vectype)
    6224              :     {
    6225            0 :       if (dump_enabled_p ())
    6226            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6227              :                          "no vectype for scalar type\n");
    6228            0 :       return false;
    6229              :     }
    6230              : 
    6231        58608 :   nunits_out = TYPE_VECTOR_SUBPARTS (vectype_out);
    6232        58608 :   nunits_in = TYPE_VECTOR_SUBPARTS (vectype);
    6233        58608 :   if (maybe_ne (nunits_out, nunits_in))
    6234              :     return false;
    6235              : 
    6236        58608 :   stmt_vec_info op1_def_stmt_info;
    6237        58608 :   slp_tree slp_op1;
    6238        58608 :   if (!vect_is_simple_use (vinfo, slp_node, 1, &op1, &slp_op1,
    6239              :                            &dt[1], &op1_vectype, &op1_def_stmt_info))
    6240              :     {
    6241            0 :       if (dump_enabled_p ())
    6242            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6243              :                          "use not simple.\n");
    6244            0 :       return false;
    6245              :     }
    6246              : 
    6247              :   /* Determine whether the shift amount is a vector, or scalar.  If the
    6248              :      shift/rotate amount is a vector, use the vector/vector shift optabs.  */
    6249              : 
    6250        58608 :   if ((dt[1] == vect_internal_def
    6251        58608 :        || dt[1] == vect_induction_def
    6252        45699 :        || dt[1] == vect_nested_cycle)
    6253        12927 :       && SLP_TREE_LANES (slp_node) == 1)
    6254              :     scalar_shift_arg = false;
    6255        45736 :   else if (dt[1] == vect_constant_def
    6256              :            || dt[1] == vect_external_def
    6257        45736 :            || dt[1] == vect_internal_def)
    6258              :     {
    6259              :       /* In SLP, need to check whether the shift count is the same,
    6260              :          in loops if it is a constant or invariant, it is always
    6261              :          a scalar shift.  */
    6262        45730 :       vec<stmt_vec_info> stmts = SLP_TREE_SCALAR_STMTS (slp_node);
    6263        45730 :       stmt_vec_info slpstmt_info;
    6264              : 
    6265       123714 :       FOR_EACH_VEC_ELT (stmts, k, slpstmt_info)
    6266        77984 :         if (slpstmt_info)
    6267              :           {
    6268        77984 :             gassign *slpstmt = as_a <gassign *> (slpstmt_info->stmt);
    6269       155968 :             if (!operand_equal_p (gimple_assign_rhs2 (slpstmt), op1, 0))
    6270        77984 :               scalar_shift_arg = false;
    6271              :           }
    6272              : 
    6273              :       /* For internal SLP defs we have to make sure we see scalar stmts
    6274              :          for all vector elements.
    6275              :          ???  For different vectors we could resort to a different
    6276              :          scalar shift operand but code-generation below simply always
    6277              :          takes the first.  */
    6278        45730 :       if (dt[1] == vect_internal_def
    6279        45779 :           && maybe_ne (nunits_out * vect_get_num_copies (vinfo, slp_node),
    6280           49 :                        stmts.length ()))
    6281              :         scalar_shift_arg = false;
    6282              : 
    6283              :       /* If the shift amount is computed by a pattern stmt we cannot
    6284              :          use the scalar amount directly thus give up and use a vector
    6285              :          shift.  */
    6286        45730 :       if (op1_def_stmt_info && is_pattern_stmt_p (op1_def_stmt_info))
    6287              :         scalar_shift_arg = false;
    6288              :     }
    6289              :   else
    6290              :     {
    6291            6 :       if (dump_enabled_p ())
    6292            6 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6293              :                          "operand mode requires invariant argument.\n");
    6294            6 :       return false;
    6295              :     }
    6296              : 
    6297              :   /* Vector shifted by vector.  */
    6298        58640 :   bool was_scalar_shift_arg = scalar_shift_arg;
    6299        45721 :   if (!scalar_shift_arg)
    6300              :     {
    6301        12919 :       optab = optab_for_tree_code (code, vectype, optab_vector);
    6302        12919 :       if (dump_enabled_p ())
    6303         1196 :         dump_printf_loc (MSG_NOTE, vect_location,
    6304              :                          "vector/vector shift/rotate found.\n");
    6305              : 
    6306        12919 :       if (!op1_vectype)
    6307           15 :         op1_vectype = get_vectype_for_scalar_type (vinfo, TREE_TYPE (op1),
    6308              :                                                    slp_op1);
    6309        12919 :       incompatible_op1_vectype_p
    6310        25838 :         = (op1_vectype == NULL_TREE
    6311        12919 :            || maybe_ne (TYPE_VECTOR_SUBPARTS (op1_vectype),
    6312        12919 :                         TYPE_VECTOR_SUBPARTS (vectype))
    6313        25836 :            || TYPE_MODE (op1_vectype) != TYPE_MODE (vectype));
    6314        12912 :       if (incompatible_op1_vectype_p
    6315            7 :           && (SLP_TREE_DEF_TYPE (slp_op1) != vect_constant_def
    6316            1 :               || slp_op1->refcnt != 1))
    6317              :         {
    6318            6 :           if (dump_enabled_p ())
    6319            0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6320              :                              "unusable type for last operand in"
    6321              :                              " vector/vector shift/rotate.\n");
    6322            6 :           return false;
    6323              :         }
    6324              :     }
    6325              :   /* See if the machine has a vector shifted by scalar insn and if not
    6326              :      then see if it has a vector shifted by vector insn.  */
    6327              :   else
    6328              :     {
    6329        45683 :       optab = optab_for_tree_code (code, vectype, optab_scalar);
    6330        45683 :       if (optab
    6331        45683 :           && can_implement_p (optab, TYPE_MODE (vectype)))
    6332              :         {
    6333        45683 :           if (dump_enabled_p ())
    6334         4914 :             dump_printf_loc (MSG_NOTE, vect_location,
    6335              :                              "vector/scalar shift/rotate found.\n");
    6336              :         }
    6337              :       else
    6338              :         {
    6339            0 :           optab = optab_for_tree_code (code, vectype, optab_vector);
    6340            0 :           if (optab
    6341            0 :               && can_implement_p (optab, TYPE_MODE (vectype)))
    6342              :             {
    6343            0 :               scalar_shift_arg = false;
    6344              : 
    6345            0 :               if (dump_enabled_p ())
    6346            0 :                 dump_printf_loc (MSG_NOTE, vect_location,
    6347              :                                  "vector/vector shift/rotate found.\n");
    6348              : 
    6349            0 :               if (!op1_vectype)
    6350            0 :                 op1_vectype = get_vectype_for_scalar_type (vinfo,
    6351            0 :                                                            TREE_TYPE (op1),
    6352              :                                                            slp_op1);
    6353              : 
    6354              :               /* Unlike the other binary operators, shifts/rotates have
    6355              :                  the rhs being int, instead of the same type as the lhs,
    6356              :                  so make sure the scalar is the right type if we are
    6357              :                  dealing with vectors of long long/long/short/char.  */
    6358            0 :               incompatible_op1_vectype_p
    6359            0 :                 = (!op1_vectype
    6360            0 :                    || !tree_nop_conversion_p (TREE_TYPE (vectype),
    6361            0 :                                               TREE_TYPE (op1)));
    6362            0 :               if (incompatible_op1_vectype_p
    6363            0 :                   && dt[1] == vect_internal_def)
    6364              :                 {
    6365            0 :                   if (dump_enabled_p ())
    6366            0 :                     dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6367              :                                      "unusable type for last operand in"
    6368              :                                      " vector/vector shift/rotate.\n");
    6369            0 :                   return false;
    6370              :                 }
    6371              :             }
    6372              :         }
    6373              :     }
    6374              : 
    6375              :   /* Supportable by target?  */
    6376        58596 :   if (!optab)
    6377              :     {
    6378            0 :       if (dump_enabled_p ())
    6379            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6380              :                          "no shift optab for %s and %T.\n",
    6381              :                          get_tree_code_name (code), vectype);
    6382            0 :       return false;
    6383              :     }
    6384        58596 :   vec_mode = TYPE_MODE (vectype);
    6385        58596 :   icode = (int) optab_handler (optab, vec_mode);
    6386        58596 :   if (icode == CODE_FOR_nothing)
    6387              :     {
    6388         5314 :       if (dump_enabled_p ())
    6389          886 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6390              :                          "shift op not supported by target.\n");
    6391         5314 :       return false;
    6392              :     }
    6393              :   /* vector lowering cannot optimize vector shifts using word arithmetic.  */
    6394        53282 :   if (vect_emulated_vector_p (vectype))
    6395              :     return false;
    6396              : 
    6397        53282 :   if (cost_vec) /* transformation not required.  */
    6398              :     {
    6399        45461 :       if (!vect_maybe_update_slp_op_vectype (slp_op0, vectype)
    6400        45461 :           || ((!scalar_shift_arg || dt[1] == vect_internal_def)
    6401         5462 :               && (!incompatible_op1_vectype_p
    6402            1 :                   || dt[1] == vect_constant_def)
    6403         5462 :               && !vect_maybe_update_slp_op_vectype
    6404         5462 :                          (slp_op1,
    6405              :                           incompatible_op1_vectype_p ? vectype : op1_vectype)))
    6406              :         {
    6407            0 :           if (dump_enabled_p ())
    6408            0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6409              :                              "incompatible vector types for invariants\n");
    6410            0 :           return false;
    6411              :         }
    6412              :       /* Now adjust the constant shift amount in place.  */
    6413        45461 :       if (incompatible_op1_vectype_p
    6414            1 :           && dt[1] == vect_constant_def)
    6415            4 :         for (unsigned i = 0;
    6416            5 :              i < SLP_TREE_SCALAR_OPS (slp_op1).length (); ++i)
    6417              :           {
    6418            4 :             SLP_TREE_SCALAR_OPS (slp_op1)[i]
    6419            4 :               = fold_convert (TREE_TYPE (vectype),
    6420              :                               SLP_TREE_SCALAR_OPS (slp_op1)[i]);
    6421            4 :             gcc_assert ((TREE_CODE (SLP_TREE_SCALAR_OPS (slp_op1)[i])
    6422              :                          == INTEGER_CST));
    6423              :           }
    6424        45461 :       SLP_TREE_TYPE (slp_node) = shift_vec_info_type;
    6425        45461 :       DUMP_VECT_SCOPE ("vectorizable_shift");
    6426        45461 :       vect_model_simple_cost (vinfo, 1, slp_node, cost_vec);
    6427        45461 :       return true;
    6428              :     }
    6429              : 
    6430              :   /* Transform.  */
    6431              : 
    6432         7821 :   if (dump_enabled_p ())
    6433         2014 :     dump_printf_loc (MSG_NOTE, vect_location,
    6434              :                      "transform binary/unary operation.\n");
    6435              : 
    6436              :   /* Handle def.  */
    6437         7821 :   vec_dest = vect_create_destination_var (scalar_dest, vectype);
    6438              : 
    6439         7821 :   unsigned nvectors = vect_get_num_copies (vinfo, slp_node);
    6440         7821 :   if (scalar_shift_arg && dt[1] != vect_internal_def)
    6441              :     {
    6442              :       /* Vector shl and shr insn patterns can be defined with scalar
    6443              :          operand 2 (shift operand).  In this case, use constant or loop
    6444              :          invariant op1 directly, without extending it to vector mode
    6445              :          first.  */
    6446         5664 :       optab_op2_mode = insn_data[icode].operand[2].mode;
    6447         5664 :       if (!VECTOR_MODE_P (optab_op2_mode))
    6448              :         {
    6449         5664 :           if (dump_enabled_p ())
    6450         1899 :             dump_printf_loc (MSG_NOTE, vect_location,
    6451              :                              "operand 1 using scalar mode.\n");
    6452         5664 :           vec_oprnd1 = op1;
    6453         5664 :           vec_oprnds1.create (nvectors);
    6454         5664 :           vec_oprnds1.quick_push (vec_oprnd1);
    6455              :           /* Store vec_oprnd1 for every vector stmt to be created.
    6456              :              We check during the analysis that all the shift arguments
    6457              :              are the same.
    6458              :              TODO: Allow different constants for different vector
    6459              :              stmts generated for an SLP instance.  */
    6460        13355 :           for (k = 0; k < nvectors - 1; k++)
    6461         2027 :             vec_oprnds1.quick_push (vec_oprnd1);
    6462              :         }
    6463              :     }
    6464         2157 :   else if (!scalar_shift_arg && incompatible_op1_vectype_p)
    6465              :     {
    6466            0 :       if (was_scalar_shift_arg)
    6467              :         {
    6468              :           /* If the argument was the same in all lanes create the
    6469              :              correctly typed vector shift amount directly.  Note
    6470              :              we made SLP scheduling think we use the original scalars,
    6471              :              so place the compensation code next to the shift which
    6472              :              is conservative.  See PR119640 where it otherwise breaks.  */
    6473            0 :           op1 = fold_convert (TREE_TYPE (vectype), op1);
    6474            0 :           op1 = vect_init_vector (vinfo, stmt_info, op1, TREE_TYPE (vectype),
    6475              :                                   gsi);
    6476            0 :           vec_oprnd1 = vect_init_vector (vinfo, stmt_info, op1, vectype,
    6477              :                                          gsi);
    6478            0 :           vec_oprnds1.create (nvectors);
    6479            0 :           for (k = 0; k < nvectors; k++)
    6480            0 :             vec_oprnds1.quick_push (vec_oprnd1);
    6481              :         }
    6482            0 :       else if (dt[1] == vect_constant_def)
    6483              :         /* The constant shift amount has been adjusted in place.  */
    6484              :         ;
    6485              :       else
    6486            0 :         gcc_assert (TYPE_MODE (op1_vectype) == TYPE_MODE (vectype));
    6487              :     }
    6488              : 
    6489              :   /* vec_oprnd1 is available if operand 1 should be of a scalar-type
    6490              :      (a special case for certain kind of vector shifts); otherwise,
    6491              :      operand 1 should be of a vector type (the usual case).  */
    6492         2157 :   vect_get_vec_defs (vinfo, slp_node,
    6493              :                      op0, &vec_oprnds0,
    6494         7821 :                      vec_oprnd1 ? NULL_TREE : op1, &vec_oprnds1);
    6495              : 
    6496              :   /* Arguments are ready.  Create the new vector stmt.  */
    6497        21171 :   FOR_EACH_VEC_ELT (vec_oprnds0, i, vop0)
    6498              :     {
    6499              :       /* For internal defs where we need to use a scalar shift arg
    6500              :          extract the first lane.  */
    6501        13350 :       if (scalar_shift_arg && dt[1] == vect_internal_def)
    6502              :         {
    6503           10 :           vop1 = vec_oprnds1[0];
    6504           10 :           new_temp = make_ssa_name (TREE_TYPE (TREE_TYPE (vop1)));
    6505           10 :           gassign *new_stmt
    6506           10 :             = gimple_build_assign (new_temp,
    6507           10 :                                    build3 (BIT_FIELD_REF, TREE_TYPE (new_temp),
    6508              :                                            vop1,
    6509           10 :                                            TYPE_SIZE (TREE_TYPE (new_temp)),
    6510              :                                            bitsize_zero_node));
    6511           10 :           vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    6512           10 :           vop1 = new_temp;
    6513           10 :         }
    6514              :       else
    6515        13340 :         vop1 = vec_oprnds1[i];
    6516        13350 :       gassign *new_stmt = gimple_build_assign (vec_dest, code, vop0, vop1);
    6517        13350 :       new_temp = make_ssa_name (vec_dest, new_stmt);
    6518        13350 :       gimple_assign_set_lhs (new_stmt, new_temp);
    6519        13350 :       vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    6520        13350 :       slp_node->push_vec_def (new_stmt);
    6521              :     }
    6522              : 
    6523         7821 :   vec_oprnds0.release ();
    6524         7821 :   vec_oprnds1.release ();
    6525              : 
    6526         7821 :   return true;
    6527              : }
    6528              : 
    6529              : /* Function vectorizable_operation.
    6530              : 
    6531              :    Check if STMT_INFO performs a binary, unary or ternary operation that can
    6532              :    be vectorized.
    6533              :    If COST_VEC is passed, calculate costs but don't change anything,
    6534              :    otherwise, vectorize STMT_INFO: create a vectorized stmt to replace
    6535              :    it, and insert it at GSI.
    6536              :    Return true if STMT_INFO is vectorizable in this way.  */
    6537              : 
    6538              : static bool
    6539      2373850 : vectorizable_operation (vec_info *vinfo,
    6540              :                         stmt_vec_info stmt_info, gimple_stmt_iterator *gsi,
    6541              :                         slp_tree slp_node,
    6542              :                         stmt_vector_for_cost *cost_vec)
    6543              : {
    6544      2373850 :   tree vec_dest;
    6545      2373850 :   tree scalar_dest;
    6546      2373850 :   tree op0, op1 = NULL_TREE, op2 = NULL_TREE;
    6547      2373850 :   tree vectype;
    6548      2373850 :   loop_vec_info loop_vinfo = dyn_cast <loop_vec_info> (vinfo);
    6549      2373850 :   enum tree_code code, orig_code;
    6550      2373850 :   machine_mode vec_mode;
    6551      2373850 :   tree new_temp;
    6552      2373850 :   int op_type;
    6553      2373850 :   optab optab;
    6554      2373850 :   bool target_support_p;
    6555      2373850 :   enum vect_def_type dt[3]
    6556              :     = {vect_unknown_def_type, vect_unknown_def_type, vect_unknown_def_type};
    6557      2373850 :   poly_uint64 nunits_in;
    6558      2373850 :   poly_uint64 nunits_out;
    6559      2373850 :   tree vectype_out;
    6560      2373850 :   int i;
    6561      2373850 :   vec<tree> vec_oprnds0 = vNULL;
    6562      2373850 :   vec<tree> vec_oprnds1 = vNULL;
    6563      2373850 :   vec<tree> vec_oprnds2 = vNULL;
    6564      2373850 :   tree vop0, vop1, vop2;
    6565      2373850 :   bb_vec_info bb_vinfo = dyn_cast <bb_vec_info> (vinfo);
    6566              : 
    6567      2373850 :   if (!STMT_VINFO_RELEVANT_P (stmt_info) && !bb_vinfo)
    6568              :     return false;
    6569              : 
    6570      2373850 :   if (STMT_VINFO_DEF_TYPE (stmt_info) != vect_internal_def
    6571       194522 :       && cost_vec)
    6572              :     return false;
    6573              : 
    6574              :   /* Is STMT a vectorizable binary/unary operation?   */
    6575      3952815 :   gassign *stmt = dyn_cast <gassign *> (stmt_info->stmt);
    6576      2112401 :   if (!stmt)
    6577              :     return false;
    6578              : 
    6579              :   /* Loads and stores are handled in vectorizable_{load,store}.  */
    6580      2112401 :   if (STMT_VINFO_DATA_REF (stmt_info))
    6581              :     return false;
    6582              : 
    6583       868048 :   orig_code = code = gimple_assign_rhs_code (stmt);
    6584              : 
    6585              :   /* Shifts are handled in vectorizable_shift.  */
    6586       868048 :   if (code == LSHIFT_EXPR
    6587              :       || code == RSHIFT_EXPR
    6588              :       || code == LROTATE_EXPR
    6589       868048 :       || code == RROTATE_EXPR)
    6590              :    return false;
    6591              : 
    6592              :   /* Comparisons are handled in vectorizable_comparison.  */
    6593       817261 :   if (TREE_CODE_CLASS (code) == tcc_comparison)
    6594              :     return false;
    6595              : 
    6596              :   /* Conditions are handled in vectorizable_condition.  */
    6597       650233 :   if (code == COND_EXPR)
    6598              :     return false;
    6599              : 
    6600              :   /* For pointer addition and subtraction, we should use the normal
    6601              :      plus and minus for the vector operation.  */
    6602       630860 :   if (code == POINTER_PLUS_EXPR)
    6603              :     code = PLUS_EXPR;
    6604       611988 :   if (code == POINTER_DIFF_EXPR)
    6605         1026 :     code = MINUS_EXPR;
    6606              : 
    6607              :   /* Support only unary or binary operations.  */
    6608       630860 :   op_type = TREE_CODE_LENGTH (code);
    6609       630860 :   if (op_type != unary_op && op_type != binary_op && op_type != ternary_op)
    6610              :     {
    6611            0 :       if (dump_enabled_p ())
    6612            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6613              :                          "num. args = %d (not unary/binary/ternary op).\n",
    6614              :                          op_type);
    6615            0 :       return false;
    6616              :     }
    6617              : 
    6618       630860 :   scalar_dest = gimple_assign_lhs (stmt);
    6619       630860 :   vectype_out = SLP_TREE_VECTYPE (slp_node);
    6620              : 
    6621              :   /* Most operations cannot handle bit-precision types without extra
    6622              :      truncations.  */
    6623       630860 :   bool mask_op_p = VECTOR_BOOLEAN_TYPE_P (vectype_out);
    6624       622257 :   if (!mask_op_p
    6625       622257 :       && !type_has_mode_precision_p (TREE_TYPE (scalar_dest))
    6626              :       /* Exception are bitwise binary operations.  */
    6627              :       && code != BIT_IOR_EXPR
    6628         1560 :       && code != BIT_XOR_EXPR
    6629         1235 :       && code != BIT_AND_EXPR)
    6630              :     {
    6631          997 :       if (dump_enabled_p ())
    6632            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6633              :                          "bit-precision arithmetic not supported.\n");
    6634          997 :       return false;
    6635              :     }
    6636              : 
    6637       629863 :   slp_tree slp_op0;
    6638       629863 :   if (!vect_is_simple_use (vinfo, slp_node,
    6639              :                            0, &op0, &slp_op0, &dt[0], &vectype))
    6640              :     {
    6641            0 :       if (dump_enabled_p ())
    6642            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6643              :                          "use not simple.\n");
    6644            0 :       return false;
    6645              :     }
    6646       629863 :   bool is_invariant = (dt[0] == vect_external_def
    6647       629863 :                        || dt[0] == vect_constant_def);
    6648              :   /* If op0 is an external or constant def, infer the vector type
    6649              :      from the scalar type.  */
    6650       629863 :   if (!vectype)
    6651              :     {
    6652              :       /* For boolean type we cannot determine vectype by
    6653              :          invariant value (don't know whether it is a vector
    6654              :          of booleans or vector of integers).  We use output
    6655              :          vectype because operations on boolean don't change
    6656              :          type.  */
    6657        70705 :       if (VECT_SCALAR_BOOLEAN_TYPE_P (TREE_TYPE (op0)))
    6658              :         {
    6659         1131 :           if (!VECT_SCALAR_BOOLEAN_TYPE_P (TREE_TYPE (scalar_dest)))
    6660              :             {
    6661          239 :               if (dump_enabled_p ())
    6662            0 :                 dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6663              :                                  "not supported operation on bool value.\n");
    6664          239 :               return false;
    6665              :             }
    6666          892 :           vectype = vectype_out;
    6667              :         }
    6668              :       else
    6669        69574 :         vectype = get_vectype_for_scalar_type (vinfo, TREE_TYPE (op0),
    6670              :                                                slp_node);
    6671              :     }
    6672       629624 :   if (!cost_vec)
    6673       115465 :     gcc_assert (vectype);
    6674       629624 :   if (!vectype)
    6675              :     {
    6676          284 :       if (dump_enabled_p ())
    6677            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6678              :                          "no vectype for scalar type %T\n",
    6679            0 :                          TREE_TYPE (op0));
    6680              : 
    6681          284 :       return false;
    6682              :     }
    6683              : 
    6684       629340 :   nunits_out = TYPE_VECTOR_SUBPARTS (vectype_out);
    6685       629340 :   nunits_in = TYPE_VECTOR_SUBPARTS (vectype);
    6686       629340 :   if (maybe_ne (nunits_out, nunits_in)
    6687       629340 :       || !tree_nop_conversion_p (TREE_TYPE (vectype_out), TREE_TYPE (vectype)))
    6688        10759 :     return false;
    6689              : 
    6690       618581 :   tree vectype2 = NULL_TREE, vectype3 = NULL_TREE;
    6691       618581 :   slp_tree slp_op1 = NULL, slp_op2 = NULL;
    6692       618581 :   if (op_type == binary_op || op_type == ternary_op)
    6693              :     {
    6694       552275 :       if (!vect_is_simple_use (vinfo, slp_node,
    6695              :                                1, &op1, &slp_op1, &dt[1], &vectype2))
    6696              :         {
    6697            0 :           if (dump_enabled_p ())
    6698            0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6699              :                              "use not simple.\n");
    6700            0 :           return false;
    6701              :         }
    6702       552275 :       is_invariant &= (dt[1] == vect_external_def
    6703       552275 :                        || dt[1] == vect_constant_def);
    6704       552275 :       if (vectype2
    6705       919076 :           && (maybe_ne (nunits_out, TYPE_VECTOR_SUBPARTS (vectype2))
    6706       366801 :               || !tree_nop_conversion_p (TREE_TYPE (vectype_out),
    6707       366801 :                                          TREE_TYPE (vectype2))))
    6708            4 :         return false;
    6709              :     }
    6710       618577 :   if (op_type == ternary_op)
    6711              :     {
    6712            0 :       if (!vect_is_simple_use (vinfo, slp_node,
    6713              :                                2, &op2, &slp_op2, &dt[2], &vectype3))
    6714              :         {
    6715            0 :           if (dump_enabled_p ())
    6716            0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6717              :                              "use not simple.\n");
    6718            0 :           return false;
    6719              :         }
    6720            0 :       is_invariant &= (dt[2] == vect_external_def
    6721            0 :                        || dt[2] == vect_constant_def);
    6722            0 :       if (vectype3
    6723            0 :           && (maybe_ne (nunits_out, TYPE_VECTOR_SUBPARTS (vectype3))
    6724            0 :               || !tree_nop_conversion_p (TREE_TYPE (vectype_out),
    6725            0 :                                          TREE_TYPE (vectype3))))
    6726            0 :         return false;
    6727              :     }
    6728              : 
    6729              :   /* Multiple types in SLP are handled by creating the appropriate number of
    6730              :      vectorized stmts for each SLP node.  */
    6731       618577 :   auto vec_num = vect_get_num_copies (vinfo, slp_node);
    6732              : 
    6733              :   /* Reject attempts to combine mask types with nonmask types, e.g. if
    6734              :      we have an AND between a (nonmask) boolean loaded from memory and
    6735              :      a (mask) boolean result of a comparison.
    6736              : 
    6737              :      TODO: We could easily fix these cases up using pattern statements.  */
    6738       618577 :   if (VECTOR_BOOLEAN_TYPE_P (vectype) != mask_op_p
    6739       979596 :       || (vectype2 && VECTOR_BOOLEAN_TYPE_P (vectype2) != mask_op_p)
    6740      1237154 :       || (vectype3 && VECTOR_BOOLEAN_TYPE_P (vectype3) != mask_op_p))
    6741              :     {
    6742            0 :       if (dump_enabled_p ())
    6743            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6744              :                          "mixed mask and nonmask vector types\n");
    6745            0 :       return false;
    6746              :     }
    6747              : 
    6748              :   /* Supportable by target?  */
    6749              : 
    6750       618577 :   vec_mode = TYPE_MODE (vectype);
    6751       618577 :   optab = optab_for_tree_code (code, vectype, optab_default);
    6752       618577 :   if (!optab)
    6753              :     {
    6754        56745 :       if (dump_enabled_p ())
    6755         5801 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6756              :                          "no optab for %s and %T.\n",
    6757              :                          get_tree_code_name (code), vectype);
    6758        56745 :       return false;
    6759              :     }
    6760       561832 :   target_support_p = can_implement_p (optab, vec_mode);
    6761              : 
    6762       561832 :   bool using_emulated_vectors_p = vect_emulated_vector_p (vectype);
    6763       561832 :   if (!target_support_p || using_emulated_vectors_p)
    6764              :     {
    6765        28765 :       if (dump_enabled_p ())
    6766         1112 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6767              :                          "op not supported by target.\n");
    6768              :       /* When vec_mode is not a vector mode and we verified ops we
    6769              :          do not have to lower like AND are natively supported let
    6770              :          those through even when the mode isn't word_mode.  For
    6771              :          ops we have to lower the lowering code assumes we are
    6772              :          dealing with word_mode.  */
    6773        57530 :       if (!INTEGRAL_TYPE_P (TREE_TYPE (vectype))
    6774        28671 :           || !GET_MODE_SIZE (vec_mode).is_constant ()
    6775        28671 :           || (((code == PLUS_EXPR || code == MINUS_EXPR || code == NEGATE_EXPR)
    6776        23525 :                || !target_support_p)
    6777        61172 :               && maybe_ne (GET_MODE_SIZE (vec_mode), UNITS_PER_WORD))
    6778              :           /* Check only during analysis.  */
    6779        39274 :           || (cost_vec && !vect_can_vectorize_without_simd_p (code)))
    6780              :         {
    6781        28217 :           if (dump_enabled_p ())
    6782         1112 :             dump_printf (MSG_NOTE, "using word mode not possible.\n");
    6783        28217 :           return false;
    6784              :         }
    6785          548 :       if (dump_enabled_p ())
    6786            0 :         dump_printf_loc (MSG_NOTE, vect_location,
    6787              :                          "proceeding using word mode.\n");
    6788              :       using_emulated_vectors_p = true;
    6789              :     }
    6790              : 
    6791       533615 :   int reduc_idx = SLP_TREE_REDUC_IDX (slp_node);
    6792       533615 :   vec_loop_masks *masks = (loop_vinfo ? &LOOP_VINFO_MASKS (loop_vinfo) : NULL);
    6793       354725 :   vec_loop_lens *lens = (loop_vinfo ? &LOOP_VINFO_LENS (loop_vinfo) : NULL);
    6794       533615 :   internal_fn cond_fn = get_conditional_internal_fn (code);
    6795       533615 :   internal_fn cond_len_fn = get_conditional_len_internal_fn (code);
    6796              : 
    6797              :   /* If operating on inactive elements could generate spurious traps,
    6798              :      we need to restrict the operation to active lanes.  Note that this
    6799              :      specifically doesn't apply to unhoisted invariants, since they
    6800              :      operate on the same value for every lane.
    6801              : 
    6802              :      Similarly, if this operation is part of a reduction, a fully-masked
    6803              :      loop should only change the active lanes of the reduction chain,
    6804              :      keeping the inactive lanes as-is.  */
    6805       506132 :   bool mask_out_inactive = ((!is_invariant && gimple_could_trap_p (stmt))
    6806       988469 :                             || reduc_idx >= 0);
    6807              : 
    6808       533615 :   if (cost_vec) /* transformation not required.  */
    6809              :     {
    6810       418150 :       if (loop_vinfo
    6811       250870 :           && LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo)
    6812        68346 :           && mask_out_inactive)
    6813              :         {
    6814        15258 :           if (cond_len_fn != IFN_LAST
    6815        15258 :               && direct_internal_fn_supported_p (cond_len_fn, vectype,
    6816              :                                                  OPTIMIZE_FOR_SPEED))
    6817            0 :             vect_record_loop_len (loop_vinfo, lens, vec_num, vectype,
    6818              :                                   1);
    6819        15258 :           else if (cond_fn != IFN_LAST
    6820        15258 :                    && direct_internal_fn_supported_p (cond_fn, vectype,
    6821              :                                                       OPTIMIZE_FOR_SPEED))
    6822         6873 :             vect_record_loop_mask (loop_vinfo, masks, vec_num,
    6823              :                                    vectype, NULL);
    6824              :           else
    6825              :             {
    6826         8385 :               if (dump_enabled_p ())
    6827          591 :                 dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6828              :                                  "can't use a fully-masked loop because no"
    6829              :                                  " conditional operation is available.\n");
    6830         8385 :               LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo) = false;
    6831              :             }
    6832              :         }
    6833              : 
    6834              :       /* Put types on constant and invariant SLP children.  */
    6835       418150 :       if (!vect_maybe_update_slp_op_vectype (slp_op0, vectype)
    6836       418072 :           || !vect_maybe_update_slp_op_vectype (slp_op1, vectype)
    6837       836121 :           || !vect_maybe_update_slp_op_vectype (slp_op2, vectype))
    6838              :         {
    6839          179 :           if (dump_enabled_p ())
    6840            3 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6841              :                              "incompatible vector types for invariants\n");
    6842          179 :           return false;
    6843              :         }
    6844              : 
    6845       417971 :       SLP_TREE_TYPE (slp_node) = op_vec_info_type;
    6846       417971 :       DUMP_VECT_SCOPE ("vectorizable_operation");
    6847       417971 :       vect_model_simple_cost (vinfo, 1, slp_node, cost_vec);
    6848       417971 :       if (using_emulated_vectors_p)
    6849              :         {
    6850              :           /* The above vect_model_simple_cost call handles constants
    6851              :              in the prologue and (mis-)costs one of the stmts as
    6852              :              vector stmt.  See below for the actual lowering that will
    6853              :              be applied.  */
    6854          546 :           unsigned n = vect_get_num_copies (vinfo, slp_node);
    6855          546 :           switch (code)
    6856              :             {
    6857          195 :             case PLUS_EXPR:
    6858          195 :               n *= 5;
    6859          195 :               break;
    6860          324 :             case MINUS_EXPR:
    6861          324 :               n *= 6;
    6862          324 :               break;
    6863            0 :             case NEGATE_EXPR:
    6864            0 :               n *= 4;
    6865            0 :               break;
    6866              :             default:
    6867              :               /* Bit operations do not have extra cost and are accounted
    6868              :                  as vector stmt by vect_model_simple_cost.  */
    6869              :               n = 0;
    6870              :               break;
    6871              :             }
    6872          519 :           if (n != 0)
    6873              :             {
    6874              :               /* We also need to materialize two large constants.  */
    6875          519 :               record_stmt_cost (cost_vec, 2, scalar_stmt, stmt_info,
    6876              :                                 0, vect_prologue);
    6877          519 :               record_stmt_cost (cost_vec, n, scalar_stmt, stmt_info,
    6878              :                                 0, vect_body);
    6879              :             }
    6880              :         }
    6881       417971 :       return true;
    6882              :     }
    6883              : 
    6884              :   /* Transform.  */
    6885              : 
    6886       115465 :   if (dump_enabled_p ())
    6887        16854 :     dump_printf_loc (MSG_NOTE, vect_location,
    6888              :                      "transform binary/unary operation.\n");
    6889              : 
    6890       115465 :   bool masked_loop_p = loop_vinfo && LOOP_VINFO_FULLY_MASKED_P (loop_vinfo);
    6891       103855 :   bool len_loop_p = loop_vinfo && LOOP_VINFO_FULLY_WITH_LENGTH_P (loop_vinfo);
    6892              : 
    6893              :   /* POINTER_DIFF_EXPR has pointer arguments which are vectorized as
    6894              :      vectors with unsigned elements, but the result is signed.  So, we
    6895              :      need to compute the MINUS_EXPR into vectype temporary and
    6896              :      VIEW_CONVERT_EXPR it into the final vectype_out result.  */
    6897       115465 :   tree vec_cvt_dest = NULL_TREE;
    6898       115465 :   if (orig_code == POINTER_DIFF_EXPR)
    6899              :     {
    6900          126 :       vec_dest = vect_create_destination_var (scalar_dest, vectype);
    6901          126 :       vec_cvt_dest = vect_create_destination_var (scalar_dest, vectype_out);
    6902              :     }
    6903              :   /* For reduction operations with undefined overflow behavior make sure to
    6904              :      pun them to unsigned since we change the order of evaluation.
    6905              :      ???  Avoid for in-order reductions?  */
    6906       115339 :   else if (arith_code_with_undefined_signed_overflow (orig_code)
    6907        98855 :            && ANY_INTEGRAL_TYPE_P (vectype)
    6908        48697 :            && TYPE_OVERFLOW_UNDEFINED (vectype)
    6909       141649 :            && SLP_TREE_REDUC_IDX (slp_node) != -1)
    6910              :     {
    6911         2492 :       gcc_assert (orig_code == PLUS_EXPR || orig_code == MINUS_EXPR
    6912              :                   || orig_code == MULT_EXPR || orig_code == POINTER_PLUS_EXPR);
    6913         2492 :       vec_cvt_dest = vect_create_destination_var (scalar_dest, vectype_out);
    6914         2492 :       vectype = unsigned_type_for (vectype);
    6915         2492 :       vec_dest = vect_create_destination_var (scalar_dest, vectype);
    6916              :     }
    6917              :   /* Handle def.  */
    6918              :   else
    6919       112847 :     vec_dest = vect_create_destination_var (scalar_dest, vectype_out);
    6920              : 
    6921       115465 :   vect_get_vec_defs (vinfo, slp_node,
    6922              :                      op0, &vec_oprnds0, op1, &vec_oprnds1, op2, &vec_oprnds2);
    6923              :   /* Arguments are ready.  Create the new vector stmt.  */
    6924       255069 :   FOR_EACH_VEC_ELT (vec_oprnds0, i, vop0)
    6925              :     {
    6926       139604 :       gimple *new_stmt = NULL;
    6927       279208 :       vop1 = ((op_type == binary_op || op_type == ternary_op)
    6928       139604 :               ? vec_oprnds1[i] : NULL_TREE);
    6929       139604 :       vop2 = ((op_type == ternary_op) ? vec_oprnds2[i] : NULL_TREE);
    6930              : 
    6931       139604 :       if (vec_cvt_dest
    6932       139604 :           && !useless_type_conversion_p (vectype, TREE_TYPE (vop0)))
    6933              :         {
    6934         2920 :           new_temp = build1 (VIEW_CONVERT_EXPR, vectype, vop0);
    6935         2920 :           new_stmt = gimple_build_assign (vec_dest, VIEW_CONVERT_EXPR,
    6936              :                                           new_temp);
    6937         2920 :           new_temp = make_ssa_name (vec_dest, new_stmt);
    6938         2920 :           gimple_assign_set_lhs (new_stmt, new_temp);
    6939         2920 :           vect_finish_stmt_generation (vinfo, stmt_info,
    6940              :                                        new_stmt, gsi);
    6941         2920 :           vop0 = new_temp;
    6942              :         }
    6943       139604 :       if (vop1
    6944       137046 :           && vec_cvt_dest
    6945       142665 :           && !useless_type_conversion_p (vectype, TREE_TYPE (vop1)))
    6946              :         {
    6947         2920 :           new_temp = build1 (VIEW_CONVERT_EXPR, vectype, vop1);
    6948         2920 :           new_stmt = gimple_build_assign (vec_dest, VIEW_CONVERT_EXPR,
    6949              :                                           new_temp);
    6950         2920 :           new_temp = make_ssa_name (vec_dest, new_stmt);
    6951         2920 :           gimple_assign_set_lhs (new_stmt, new_temp);
    6952         2920 :           vect_finish_stmt_generation (vinfo, stmt_info,
    6953              :                                        new_stmt, gsi);
    6954         2920 :           vop1 = new_temp;
    6955              :         }
    6956       139604 :       if (vop2
    6957            0 :           && vec_cvt_dest
    6958       139604 :           && !useless_type_conversion_p (vectype, TREE_TYPE (vop2)))
    6959              :         {
    6960            0 :           new_temp = build1 (VIEW_CONVERT_EXPR, vectype, vop2);
    6961            0 :           new_stmt = gimple_build_assign (vec_dest, VIEW_CONVERT_EXPR,
    6962              :                                           new_temp);
    6963            0 :           new_temp = make_ssa_name (vec_dest, new_stmt);
    6964            0 :           gimple_assign_set_lhs (new_stmt, new_temp);
    6965            0 :           vect_finish_stmt_generation (vinfo, stmt_info,
    6966              :                                        new_stmt, gsi);
    6967            0 :           vop2 = new_temp;
    6968              :         }
    6969              : 
    6970       139604 :       if (using_emulated_vectors_p)
    6971              :         {
    6972              :           /* Lower the operation.  This follows vector lowering.  */
    6973            2 :           tree word_type = build_nonstandard_integer_type
    6974            2 :                              (GET_MODE_BITSIZE (vec_mode).to_constant (), 1);
    6975            2 :           tree wvop0 = make_ssa_name (word_type);
    6976            2 :           new_stmt = gimple_build_assign (wvop0, VIEW_CONVERT_EXPR,
    6977              :                                           build1 (VIEW_CONVERT_EXPR,
    6978              :                                                   word_type, vop0));
    6979            2 :           vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    6980            2 :           tree wvop1 = NULL_TREE;
    6981            2 :           if (vop1)
    6982              :             {
    6983            2 :               wvop1 = make_ssa_name (word_type);
    6984            2 :               new_stmt = gimple_build_assign (wvop1, VIEW_CONVERT_EXPR,
    6985              :                                               build1 (VIEW_CONVERT_EXPR,
    6986              :                                                       word_type, vop1));
    6987            2 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    6988              :             }
    6989              : 
    6990            2 :           tree result_low;
    6991            2 :           if (code == PLUS_EXPR || code == MINUS_EXPR || code == NEGATE_EXPR)
    6992              :             {
    6993            1 :               unsigned int width = vector_element_bits (vectype);
    6994            1 :               tree inner_type = TREE_TYPE (vectype);
    6995            1 :               HOST_WIDE_INT max = GET_MODE_MASK (TYPE_MODE (inner_type));
    6996            1 :               tree low_bits
    6997            1 :                 = build_replicated_int_cst (word_type, width, max >> 1);
    6998            1 :               tree high_bits
    6999            2 :                 = build_replicated_int_cst (word_type,
    7000            1 :                                             width, max & ~(max >> 1));
    7001            1 :               tree signs;
    7002            1 :               if (code == PLUS_EXPR || code == MINUS_EXPR)
    7003              :                 {
    7004            1 :                   signs = make_ssa_name (word_type);
    7005            1 :                   new_stmt = gimple_build_assign (signs,
    7006              :                                                   BIT_XOR_EXPR, wvop0, wvop1);
    7007            1 :                   vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    7008            1 :                   tree b_low = make_ssa_name (word_type);
    7009            1 :                   new_stmt = gimple_build_assign (b_low, BIT_AND_EXPR,
    7010              :                                                   wvop1, low_bits);
    7011            1 :                   vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    7012            1 :                   tree a_low = make_ssa_name (word_type);
    7013            1 :                   if (code == PLUS_EXPR)
    7014            1 :                     new_stmt = gimple_build_assign (a_low, BIT_AND_EXPR,
    7015              :                                                     wvop0, low_bits);
    7016              :                   else
    7017            0 :                     new_stmt = gimple_build_assign (a_low, BIT_IOR_EXPR,
    7018              :                                                     wvop0, high_bits);
    7019            1 :                   vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    7020            1 :                   if (code == MINUS_EXPR)
    7021              :                     {
    7022            0 :                       new_stmt = gimple_build_assign (NULL_TREE,
    7023              :                                                       BIT_NOT_EXPR, signs);
    7024            0 :                       signs = make_ssa_name (word_type);
    7025            0 :                       gimple_assign_set_lhs (new_stmt, signs);
    7026            0 :                       vect_finish_stmt_generation (vinfo, stmt_info,
    7027              :                                                    new_stmt, gsi);
    7028              :                     }
    7029            1 :                   new_stmt = gimple_build_assign (NULL_TREE, BIT_AND_EXPR,
    7030              :                                                   signs, high_bits);
    7031            1 :                   signs = make_ssa_name (word_type);
    7032            1 :                   gimple_assign_set_lhs (new_stmt, signs);
    7033            1 :                   vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    7034            1 :                   result_low = make_ssa_name (word_type);
    7035            1 :                   new_stmt = gimple_build_assign (result_low, code,
    7036              :                                                   a_low, b_low);
    7037            1 :                   vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    7038              :                 }
    7039              :               else /* if (code == NEGATE_EXPR) */
    7040              :                 {
    7041            0 :                   tree a_low = make_ssa_name (word_type);
    7042            0 :                   new_stmt = gimple_build_assign (a_low, BIT_AND_EXPR,
    7043              :                                                   wvop0, low_bits);
    7044            0 :                   vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    7045            0 :                   signs = make_ssa_name (word_type);
    7046            0 :                   new_stmt = gimple_build_assign (signs, BIT_NOT_EXPR, wvop0);
    7047            0 :                   vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    7048            0 :                   new_stmt = gimple_build_assign (NULL_TREE, BIT_AND_EXPR,
    7049              :                                                   signs, high_bits);
    7050            0 :                   signs = make_ssa_name (word_type);
    7051            0 :                   gimple_assign_set_lhs (new_stmt, signs);
    7052            0 :                   vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    7053            0 :                   result_low = make_ssa_name (word_type);
    7054            0 :                   new_stmt = gimple_build_assign (result_low,
    7055              :                                                   MINUS_EXPR, high_bits, a_low);
    7056            0 :                   vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    7057              :                 }
    7058            1 :               new_stmt = gimple_build_assign (NULL_TREE, BIT_XOR_EXPR,
    7059              :                                               result_low, signs);
    7060            1 :               result_low = make_ssa_name (word_type);
    7061            1 :               gimple_assign_set_lhs (new_stmt, result_low);
    7062            1 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    7063              :             }
    7064              :           else
    7065              :             {
    7066            1 :               new_stmt = gimple_build_assign (NULL_TREE, code, wvop0, wvop1);
    7067            1 :               result_low = make_ssa_name (word_type);
    7068            1 :               gimple_assign_set_lhs (new_stmt, result_low);
    7069            1 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    7070              : 
    7071              :             }
    7072            2 :           new_stmt = gimple_build_assign (NULL_TREE, VIEW_CONVERT_EXPR,
    7073              :                                           build1 (VIEW_CONVERT_EXPR,
    7074              :                                                   vectype, result_low));
    7075            2 :           new_temp = make_ssa_name (vectype);
    7076            2 :           gimple_assign_set_lhs (new_stmt, new_temp);
    7077            2 :           vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    7078              :         }
    7079       139602 :       else if ((masked_loop_p || len_loop_p) && mask_out_inactive)
    7080              :         {
    7081           16 :           tree mask;
    7082           16 :           if (masked_loop_p)
    7083           16 :             mask = vect_get_loop_mask (loop_vinfo, gsi, masks,
    7084              :                                        vec_num, vectype, i);
    7085              :           else
    7086              :             /* Dummy mask.  */
    7087            0 :             mask = build_minus_one_cst (truth_type_for (vectype));
    7088           16 :           auto_vec<tree> vops (6);
    7089           16 :           vops.quick_push (mask);
    7090           16 :           vops.quick_push (vop0);
    7091           16 :           if (vop1)
    7092           16 :             vops.quick_push (vop1);
    7093           16 :           if (vop2)
    7094            0 :             vops.quick_push (vop2);
    7095           16 :           if (reduc_idx >= 0)
    7096              :             {
    7097              :               /* Perform the operation on active elements only and take
    7098              :                  inactive elements from the reduction chain input.  */
    7099            8 :               gcc_assert (!vop2);
    7100            8 :               vops.quick_push (reduc_idx == 1 ? vop1 : vop0);
    7101              :             }
    7102              :           else
    7103              :             {
    7104            8 :               auto else_value = targetm.preferred_else_value
    7105            8 :                 (cond_fn, vectype, vops.length () - 1, &vops[1]);
    7106            8 :               vops.quick_push (else_value);
    7107              :             }
    7108           16 :           if (len_loop_p)
    7109              :             {
    7110            0 :               tree len = vect_get_loop_len (loop_vinfo, gsi, lens,
    7111            0 :                                             vec_num, vectype, i, 1, true);
    7112            0 :               signed char biasval
    7113            0 :                 = LOOP_VINFO_PARTIAL_LOAD_STORE_BIAS (loop_vinfo);
    7114            0 :               tree bias = build_int_cst (intQI_type_node, biasval);
    7115            0 :               vops.quick_push (len);
    7116            0 :               vops.quick_push (bias);
    7117              :             }
    7118           16 :           gcall *call
    7119           16 :             = gimple_build_call_internal_vec (masked_loop_p ? cond_fn
    7120              :                                                             : cond_len_fn,
    7121              :                                               vops);
    7122           16 :           new_temp = make_ssa_name (vec_dest, call);
    7123           16 :           gimple_call_set_lhs (call, new_temp);
    7124           16 :           gimple_call_set_nothrow (call, true);
    7125           16 :           vect_finish_stmt_generation (vinfo, stmt_info, call, gsi);
    7126           16 :           new_stmt = call;
    7127           16 :         }
    7128              :       else
    7129              :         {
    7130       139586 :           tree mask = NULL_TREE;
    7131              :           /* When combining two masks check if either of them is elsewhere
    7132              :              combined with a loop mask, if that's the case we can mark that the
    7133              :              new combined mask doesn't need to be combined with a loop mask.  */
    7134       139586 :           if (masked_loop_p
    7135       139586 :               && code == BIT_AND_EXPR
    7136       139586 :               && VECTOR_BOOLEAN_TYPE_P (vectype))
    7137              :             {
    7138            8 :               if (loop_vinfo->scalar_cond_masked_set.contains ({ op0, vec_num }))
    7139              :                 {
    7140            0 :                   mask = vect_get_loop_mask (loop_vinfo, gsi, masks,
    7141              :                                              vec_num, vectype, i);
    7142              : 
    7143            0 :                   vop0 = prepare_vec_mask (loop_vinfo, TREE_TYPE (mask), mask,
    7144              :                                            vop0, gsi);
    7145              :                 }
    7146              : 
    7147            8 :               if (loop_vinfo->scalar_cond_masked_set.contains ({ op1, vec_num }))
    7148              :                 {
    7149            0 :                   mask = vect_get_loop_mask (loop_vinfo, gsi, masks,
    7150              :                                              vec_num, vectype, i);
    7151              : 
    7152            0 :                   vop1 = prepare_vec_mask (loop_vinfo, TREE_TYPE (mask), mask,
    7153              :                                            vop1, gsi);
    7154              :                 }
    7155              :             }
    7156              : 
    7157       139586 :           new_stmt = gimple_build_assign (vec_dest, code, vop0, vop1, vop2);
    7158       139586 :           new_temp = make_ssa_name (vec_dest, new_stmt);
    7159       139586 :           gimple_assign_set_lhs (new_stmt, new_temp);
    7160       139586 :           vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    7161       139586 :           if (using_emulated_vectors_p)
    7162              :             suppress_warning (new_stmt, OPT_Wvector_operation_performance);
    7163              : 
    7164              :           /* Enter the combined value into the vector cond hash so we don't
    7165              :              AND it with a loop mask again.  */
    7166       139586 :           if (mask)
    7167            0 :             loop_vinfo->vec_cond_masked_set.add ({ new_temp, mask });
    7168              :         }
    7169              : 
    7170       139604 :       if (vec_cvt_dest)
    7171              :         {
    7172         3061 :           new_temp = build1 (VIEW_CONVERT_EXPR, vectype_out, new_temp);
    7173         3061 :           new_stmt = gimple_build_assign (vec_cvt_dest, VIEW_CONVERT_EXPR,
    7174              :                                           new_temp);
    7175         3061 :           new_temp = make_ssa_name (vec_cvt_dest, new_stmt);
    7176         3061 :           gimple_assign_set_lhs (new_stmt, new_temp);
    7177         3061 :           vect_finish_stmt_generation (vinfo, stmt_info,
    7178              :                                        new_stmt, gsi);
    7179              :         }
    7180              : 
    7181       139604 :       slp_node->push_vec_def (new_stmt);
    7182              :     }
    7183              : 
    7184       115465 :   vec_oprnds0.release ();
    7185       115465 :   vec_oprnds1.release ();
    7186       115465 :   vec_oprnds2.release ();
    7187              : 
    7188       115465 :   return true;
    7189              : }
    7190              : 
    7191              : /* A helper function to ensure data reference DR_INFO's base alignment.  */
    7192              : 
    7193              : static void
    7194      1849435 : ensure_base_align (dr_vec_info *dr_info)
    7195              : {
    7196              :   /* Alignment is only analyzed for the first element of a DR group,
    7197              :      use that to look at base alignment we need to enforce.  */
    7198      1849435 :   if (STMT_VINFO_GROUPED_ACCESS (dr_info->stmt))
    7199      1412157 :     dr_info = STMT_VINFO_DR_INFO (DR_GROUP_FIRST_ELEMENT (dr_info->stmt));
    7200              : 
    7201      1849435 :   gcc_assert (dr_info->misalignment != DR_MISALIGNMENT_UNINITIALIZED);
    7202              : 
    7203      1849435 :   if (dr_info->base_misaligned)
    7204              :     {
    7205       168562 :       tree base_decl = dr_info->base_decl;
    7206              : 
    7207              :       // We should only be able to increase the alignment of a base object if
    7208              :       // we know what its new alignment should be at compile time.
    7209       168562 :       unsigned HOST_WIDE_INT align_base_to =
    7210       168562 :         DR_TARGET_ALIGNMENT (dr_info).to_constant () * BITS_PER_UNIT;
    7211              : 
    7212       168562 :       if (decl_in_symtab_p (base_decl))
    7213         4612 :         symtab_node::get (base_decl)->increase_alignment (align_base_to);
    7214       163950 :       else if (DECL_ALIGN (base_decl) < align_base_to)
    7215              :         {
    7216       131308 :           SET_DECL_ALIGN (base_decl, align_base_to);
    7217       131308 :           DECL_USER_ALIGN (base_decl) = 1;
    7218              :         }
    7219       168562 :       dr_info->base_misaligned = false;
    7220              :     }
    7221      1849435 : }
    7222              : 
    7223              : 
    7224              : /* Function get_group_alias_ptr_type.
    7225              : 
    7226              :    Return the alias type for the group starting at FIRST_STMT_INFO.  */
    7227              : 
    7228              : static tree
    7229      1581257 : get_group_alias_ptr_type (stmt_vec_info first_stmt_info)
    7230              : {
    7231      1581257 :   struct data_reference *first_dr, *next_dr;
    7232              : 
    7233      1581257 :   first_dr = STMT_VINFO_DATA_REF (first_stmt_info);
    7234      1581257 :   stmt_vec_info next_stmt_info = DR_GROUP_NEXT_ELEMENT (first_stmt_info);
    7235      3854849 :   while (next_stmt_info)
    7236              :     {
    7237      2405384 :       next_dr = STMT_VINFO_DATA_REF (next_stmt_info);
    7238      4810768 :       if (get_alias_set (DR_REF (first_dr))
    7239      2405384 :           != get_alias_set (DR_REF (next_dr)))
    7240              :         {
    7241       131792 :           if (dump_enabled_p ())
    7242           30 :             dump_printf_loc (MSG_NOTE, vect_location,
    7243              :                              "conflicting alias set types.\n");
    7244       131792 :           return ptr_type_node;
    7245              :         }
    7246      2273592 :       next_stmt_info = DR_GROUP_NEXT_ELEMENT (next_stmt_info);
    7247              :     }
    7248      1449465 :   return reference_alias_ptr_type (DR_REF (first_dr));
    7249              : }
    7250              : 
    7251              : 
    7252              : /* Function scan_operand_equal_p.
    7253              : 
    7254              :    Helper function for check_scan_store.  Compare two references
    7255              :    with .GOMP_SIMD_LANE bases.  */
    7256              : 
    7257              : static bool
    7258         1284 : scan_operand_equal_p (tree ref1, tree ref2)
    7259              : {
    7260         1284 :   tree ref[2] = { ref1, ref2 };
    7261         1284 :   poly_int64 bitsize[2], bitpos[2];
    7262              :   tree offset[2], base[2];
    7263         3852 :   for (int i = 0; i < 2; ++i)
    7264              :     {
    7265         2568 :       machine_mode mode;
    7266         2568 :       int unsignedp, reversep, volatilep = 0;
    7267         2568 :       base[i] = get_inner_reference (ref[i], &bitsize[i], &bitpos[i],
    7268              :                                      &offset[i], &mode, &unsignedp,
    7269              :                                      &reversep, &volatilep);
    7270         2568 :       if (reversep || volatilep || maybe_ne (bitpos[i], 0))
    7271            0 :         return false;
    7272         2568 :       if (TREE_CODE (base[i]) == MEM_REF
    7273           42 :           && offset[i] == NULL_TREE
    7274         2610 :           && TREE_CODE (TREE_OPERAND (base[i], 0)) == SSA_NAME)
    7275              :         {
    7276           42 :           gimple *def_stmt = SSA_NAME_DEF_STMT (TREE_OPERAND (base[i], 0));
    7277           42 :           if (is_gimple_assign (def_stmt)
    7278           42 :               && gimple_assign_rhs_code (def_stmt) == POINTER_PLUS_EXPR
    7279           42 :               && TREE_CODE (gimple_assign_rhs1 (def_stmt)) == ADDR_EXPR
    7280           84 :               && TREE_CODE (gimple_assign_rhs2 (def_stmt)) == SSA_NAME)
    7281              :             {
    7282           42 :               if (maybe_ne (mem_ref_offset (base[i]), 0))
    7283              :                 return false;
    7284           42 :               base[i] = TREE_OPERAND (gimple_assign_rhs1 (def_stmt), 0);
    7285           42 :               offset[i] = gimple_assign_rhs2 (def_stmt);
    7286              :             }
    7287              :         }
    7288              :     }
    7289              : 
    7290         1284 :   if (!operand_equal_p (base[0], base[1], 0))
    7291              :     return false;
    7292          934 :   if (maybe_ne (bitsize[0], bitsize[1]))
    7293              :     return false;
    7294          934 :   if (offset[0] != offset[1])
    7295              :     {
    7296          916 :       if (!offset[0] || !offset[1])
    7297              :         return false;
    7298          916 :       if (!operand_equal_p (offset[0], offset[1], 0))
    7299              :         {
    7300              :           tree step[2];
    7301            0 :           for (int i = 0; i < 2; ++i)
    7302              :             {
    7303            0 :               step[i] = integer_one_node;
    7304            0 :               if (TREE_CODE (offset[i]) == SSA_NAME)
    7305              :                 {
    7306            0 :                   gimple *def_stmt = SSA_NAME_DEF_STMT (offset[i]);
    7307            0 :                   if (is_gimple_assign (def_stmt)
    7308            0 :                       && gimple_assign_rhs_code (def_stmt) == MULT_EXPR
    7309            0 :                       && (TREE_CODE (gimple_assign_rhs2 (def_stmt))
    7310              :                           == INTEGER_CST))
    7311              :                     {
    7312            0 :                       step[i] = gimple_assign_rhs2 (def_stmt);
    7313            0 :                       offset[i] = gimple_assign_rhs1 (def_stmt);
    7314              :                     }
    7315              :                 }
    7316            0 :               else if (TREE_CODE (offset[i]) == MULT_EXPR)
    7317              :                 {
    7318            0 :                   step[i] = TREE_OPERAND (offset[i], 1);
    7319            0 :                   offset[i] = TREE_OPERAND (offset[i], 0);
    7320              :                 }
    7321            0 :               tree rhs1 = NULL_TREE;
    7322            0 :               if (TREE_CODE (offset[i]) == SSA_NAME)
    7323              :                 {
    7324            0 :                   gimple *def_stmt = SSA_NAME_DEF_STMT (offset[i]);
    7325            0 :                   if (gimple_assign_cast_p (def_stmt))
    7326            0 :                     rhs1 = gimple_assign_rhs1 (def_stmt);
    7327              :                 }
    7328            0 :               else if (CONVERT_EXPR_P (offset[i]))
    7329            0 :                 rhs1 = TREE_OPERAND (offset[i], 0);
    7330            0 :               if (rhs1
    7331            0 :                   && INTEGRAL_TYPE_P (TREE_TYPE (rhs1))
    7332            0 :                   && INTEGRAL_TYPE_P (TREE_TYPE (offset[i]))
    7333            0 :                   && (TYPE_PRECISION (TREE_TYPE (offset[i]))
    7334            0 :                       >= TYPE_PRECISION (TREE_TYPE (rhs1))))
    7335            0 :                 offset[i] = rhs1;
    7336              :             }
    7337            0 :           if (!operand_equal_p (offset[0], offset[1], 0)
    7338            0 :               || !operand_equal_p (step[0], step[1], 0))
    7339            0 :             return false;
    7340              :         }
    7341              :     }
    7342              :   return true;
    7343              : }
    7344              : 
    7345              : 
    7346              : enum scan_store_kind {
    7347              :   /* Normal permutation.  */
    7348              :   scan_store_kind_perm,
    7349              : 
    7350              :   /* Whole vector left shift permutation with zero init.  */
    7351              :   scan_store_kind_lshift_zero,
    7352              : 
    7353              :   /* Whole vector left shift permutation and VEC_COND_EXPR.  */
    7354              :   scan_store_kind_lshift_cond
    7355              : };
    7356              : 
    7357              : /* Function check_scan_store.
    7358              : 
    7359              :    Verify if we can perform the needed permutations or whole vector shifts.
    7360              :    Return -1 on failure, otherwise exact log2 of vectype's nunits.
    7361              :    USE_WHOLE_VECTOR is a vector of enum scan_store_kind which operation
    7362              :    to do at each step.  */
    7363              : 
    7364              : static int
    7365         1024 : scan_store_can_perm_p (tree vectype, tree init,
    7366              :                        vec<enum scan_store_kind> *use_whole_vector = NULL)
    7367              : {
    7368         1024 :   enum machine_mode vec_mode = TYPE_MODE (vectype);
    7369         1024 :   unsigned HOST_WIDE_INT nunits;
    7370         1024 :   if (!TYPE_VECTOR_SUBPARTS (vectype).is_constant (&nunits))
    7371              :     return -1;
    7372         1024 :   int units_log2 = exact_log2 (nunits);
    7373         1024 :   if (units_log2 <= 0)
    7374              :     return -1;
    7375              : 
    7376              :   int i;
    7377              :   enum scan_store_kind whole_vector_shift_kind = scan_store_kind_perm;
    7378         4784 :   for (i = 0; i <= units_log2; ++i)
    7379              :     {
    7380         3760 :       unsigned HOST_WIDE_INT j, k;
    7381         3760 :       enum scan_store_kind kind = scan_store_kind_perm;
    7382         3760 :       vec_perm_builder sel (nunits, nunits, 1);
    7383         3760 :       sel.quick_grow (nunits);
    7384         3760 :       if (i == units_log2)
    7385              :         {
    7386         9728 :           for (j = 0; j < nunits; ++j)
    7387         8704 :             sel[j] = nunits - 1;
    7388              :         }
    7389              :       else
    7390              :         {
    7391        10416 :           for (j = 0; j < (HOST_WIDE_INT_1U << i); ++j)
    7392         7680 :             sel[j] = j;
    7393        26416 :           for (k = 0; j < nunits; ++j, ++k)
    7394        23680 :             sel[j] = nunits + k;
    7395              :         }
    7396         6496 :       vec_perm_indices indices (sel, i == units_log2 ? 1 : 2, nunits);
    7397         3760 :       if (!can_vec_perm_const_p (vec_mode, vec_mode, indices))
    7398              :         {
    7399            0 :           if (i == units_log2)
    7400              :             return -1;
    7401              : 
    7402            0 :           if (whole_vector_shift_kind == scan_store_kind_perm)
    7403              :             {
    7404            0 :               if (!can_implement_p (vec_shl_optab, vec_mode))
    7405              :                 return -1;
    7406            0 :               whole_vector_shift_kind = scan_store_kind_lshift_zero;
    7407              :               /* Whole vector shifts shift in zeros, so if init is all zero
    7408              :                  constant, there is no need to do anything further.  */
    7409            0 :               if ((TREE_CODE (init) != INTEGER_CST
    7410            0 :                    && TREE_CODE (init) != REAL_CST)
    7411            0 :                   || !initializer_zerop (init))
    7412              :                 {
    7413            0 :                   tree masktype = truth_type_for (vectype);
    7414            0 :                   if (!expand_vec_cond_expr_p (vectype, masktype))
    7415              :                     return -1;
    7416              :                   whole_vector_shift_kind = scan_store_kind_lshift_cond;
    7417              :                 }
    7418              :             }
    7419            0 :           kind = whole_vector_shift_kind;
    7420              :         }
    7421         3760 :       if (use_whole_vector)
    7422              :         {
    7423         1880 :           if (kind != scan_store_kind_perm && use_whole_vector->is_empty ())
    7424            0 :             use_whole_vector->safe_grow_cleared (i, true);
    7425         5640 :           if (kind != scan_store_kind_perm || !use_whole_vector->is_empty ())
    7426            0 :             use_whole_vector->safe_push (kind);
    7427              :         }
    7428         3760 :     }
    7429              : 
    7430              :   return units_log2;
    7431              : }
    7432              : 
    7433              : 
    7434              : /* Function check_scan_store.
    7435              : 
    7436              :    Check magic stores for #pragma omp scan {in,ex}clusive reductions.  */
    7437              : 
    7438              : static bool
    7439         1076 : check_scan_store (vec_info *vinfo, stmt_vec_info stmt_info, tree vectype,
    7440              :                   enum vect_def_type rhs_dt, slp_tree slp_node,
    7441              :                   slp_tree mask_node,
    7442              :                   vect_memory_access_type memory_access_type)
    7443              : {
    7444         1076 :   loop_vec_info loop_vinfo = dyn_cast <loop_vec_info> (vinfo);
    7445         1076 :   dr_vec_info *dr_info = STMT_VINFO_DR_INFO (stmt_info);
    7446         1076 :   tree ref_type;
    7447              : 
    7448         1076 :   gcc_assert (STMT_VINFO_SIMD_LANE_ACCESS_P (stmt_info) > 1);
    7449         1076 :   if (SLP_TREE_LANES (slp_node) > 1
    7450         1076 :       || mask_node
    7451         1076 :       || memory_access_type != VMAT_CONTIGUOUS
    7452         1076 :       || TREE_CODE (DR_BASE_ADDRESS (dr_info->dr)) != ADDR_EXPR
    7453         1076 :       || !VAR_P (TREE_OPERAND (DR_BASE_ADDRESS (dr_info->dr), 0))
    7454         1076 :       || loop_vinfo == NULL
    7455         1076 :       || LOOP_VINFO_FULLY_MASKED_P (loop_vinfo)
    7456         1076 :       || LOOP_VINFO_EPILOGUE_P (loop_vinfo)
    7457         1076 :       || STMT_VINFO_GROUPED_ACCESS (stmt_info)
    7458         1076 :       || !integer_zerop (get_dr_vinfo_offset (vinfo, dr_info))
    7459         1076 :       || !integer_zerop (DR_INIT (dr_info->dr))
    7460         1076 :       || !(ref_type = reference_alias_ptr_type (DR_REF (dr_info->dr)))
    7461         2152 :       || !alias_sets_conflict_p (get_alias_set (vectype),
    7462         1076 :                                  get_alias_set (TREE_TYPE (ref_type))))
    7463              :     {
    7464            0 :       if (dump_enabled_p ())
    7465            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    7466              :                          "unsupported OpenMP scan store.\n");
    7467            0 :       return false;
    7468              :     }
    7469              : 
    7470              :   /* We need to pattern match code built by OpenMP lowering and simplified
    7471              :      by following optimizations into something we can handle.
    7472              :      #pragma omp simd reduction(inscan,+:r)
    7473              :      for (...)
    7474              :        {
    7475              :          r += something ();
    7476              :          #pragma omp scan inclusive (r)
    7477              :          use (r);
    7478              :        }
    7479              :      shall have body with:
    7480              :        // Initialization for input phase, store the reduction initializer:
    7481              :        _20 = .GOMP_SIMD_LANE (simduid.3_14(D), 0);
    7482              :        _21 = .GOMP_SIMD_LANE (simduid.3_14(D), 1);
    7483              :        D.2042[_21] = 0;
    7484              :        // Actual input phase:
    7485              :        ...
    7486              :        r.0_5 = D.2042[_20];
    7487              :        _6 = _4 + r.0_5;
    7488              :        D.2042[_20] = _6;
    7489              :        // Initialization for scan phase:
    7490              :        _25 = .GOMP_SIMD_LANE (simduid.3_14(D), 2);
    7491              :        _26 = D.2043[_25];
    7492              :        _27 = D.2042[_25];
    7493              :        _28 = _26 + _27;
    7494              :        D.2043[_25] = _28;
    7495              :        D.2042[_25] = _28;
    7496              :        // Actual scan phase:
    7497              :        ...
    7498              :        r.1_8 = D.2042[_20];
    7499              :        ...
    7500              :      The "omp simd array" variable D.2042 holds the privatized copy used
    7501              :      inside of the loop and D.2043 is another one that holds copies of
    7502              :      the current original list item.  The separate GOMP_SIMD_LANE ifn
    7503              :      kinds are there in order to allow optimizing the initializer store
    7504              :      and combiner sequence, e.g. if it is originally some C++ish user
    7505              :      defined reduction, but allow the vectorizer to pattern recognize it
    7506              :      and turn into the appropriate vectorized scan.
    7507              : 
    7508              :      For exclusive scan, this is slightly different:
    7509              :      #pragma omp simd reduction(inscan,+:r)
    7510              :      for (...)
    7511              :        {
    7512              :          use (r);
    7513              :          #pragma omp scan exclusive (r)
    7514              :          r += something ();
    7515              :        }
    7516              :      shall have body with:
    7517              :        // Initialization for input phase, store the reduction initializer:
    7518              :        _20 = .GOMP_SIMD_LANE (simduid.3_14(D), 0);
    7519              :        _21 = .GOMP_SIMD_LANE (simduid.3_14(D), 1);
    7520              :        D.2042[_21] = 0;
    7521              :        // Actual input phase:
    7522              :        ...
    7523              :        r.0_5 = D.2042[_20];
    7524              :        _6 = _4 + r.0_5;
    7525              :        D.2042[_20] = _6;
    7526              :        // Initialization for scan phase:
    7527              :        _25 = .GOMP_SIMD_LANE (simduid.3_14(D), 3);
    7528              :        _26 = D.2043[_25];
    7529              :        D.2044[_25] = _26;
    7530              :        _27 = D.2042[_25];
    7531              :        _28 = _26 + _27;
    7532              :        D.2043[_25] = _28;
    7533              :        // Actual scan phase:
    7534              :        ...
    7535              :        r.1_8 = D.2044[_20];
    7536              :        ...  */
    7537              : 
    7538         1076 :   if (STMT_VINFO_SIMD_LANE_ACCESS_P (stmt_info) == 2)
    7539              :     {
    7540              :       /* Match the D.2042[_21] = 0; store above.  Just require that
    7541              :          it is a constant or external definition store.  */
    7542          564 :       if (rhs_dt != vect_constant_def && rhs_dt != vect_external_def)
    7543              :         {
    7544            0 :          fail_init:
    7545            0 :           if (dump_enabled_p ())
    7546            0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    7547              :                              "unsupported OpenMP scan initializer store.\n");
    7548            0 :           return false;
    7549              :         }
    7550              : 
    7551          564 :       if (! loop_vinfo->scan_map)
    7552          322 :         loop_vinfo->scan_map = new hash_map<tree, tree>;
    7553          564 :       tree var = TREE_OPERAND (DR_BASE_ADDRESS (dr_info->dr), 0);
    7554          564 :       tree &cached = loop_vinfo->scan_map->get_or_insert (var);
    7555          564 :       if (cached)
    7556            0 :         goto fail_init;
    7557          564 :       cached = gimple_assign_rhs1 (STMT_VINFO_STMT (stmt_info));
    7558              : 
    7559              :       /* These stores can be vectorized normally.  */
    7560          564 :       return true;
    7561              :     }
    7562              : 
    7563          512 :   if (rhs_dt != vect_internal_def)
    7564              :     {
    7565            0 :      fail:
    7566            0 :       if (dump_enabled_p ())
    7567            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    7568              :                          "unsupported OpenMP scan combiner pattern.\n");
    7569            0 :       return false;
    7570              :     }
    7571              : 
    7572          512 :   gimple *stmt = STMT_VINFO_STMT (stmt_info);
    7573          512 :   tree rhs = gimple_assign_rhs1 (stmt);
    7574          512 :   if (TREE_CODE (rhs) != SSA_NAME)
    7575            0 :     goto fail;
    7576              : 
    7577          512 :   gimple *other_store_stmt = NULL;
    7578          512 :   tree var = TREE_OPERAND (DR_BASE_ADDRESS (dr_info->dr), 0);
    7579          512 :   bool inscan_var_store
    7580          512 :     = lookup_attribute ("omp simd inscan", DECL_ATTRIBUTES (var)) != NULL;
    7581              : 
    7582          512 :   if (STMT_VINFO_SIMD_LANE_ACCESS_P (stmt_info) == 4)
    7583              :     {
    7584          252 :       if (!inscan_var_store)
    7585              :         {
    7586          126 :           use_operand_p use_p;
    7587          126 :           imm_use_iterator iter;
    7588          378 :           FOR_EACH_IMM_USE_FAST (use_p, iter, rhs)
    7589              :             {
    7590          252 :               gimple *use_stmt = USE_STMT (use_p);
    7591          252 :               if (use_stmt == stmt || is_gimple_debug (use_stmt))
    7592          126 :                 continue;
    7593          126 :               if (gimple_bb (use_stmt) != gimple_bb (stmt)
    7594          126 :                   || !is_gimple_assign (use_stmt)
    7595          126 :                   || gimple_assign_rhs_class (use_stmt) != GIMPLE_BINARY_RHS
    7596          126 :                   || other_store_stmt
    7597          252 :                   || TREE_CODE (gimple_assign_lhs (use_stmt)) != SSA_NAME)
    7598            0 :                 goto fail;
    7599          126 :               other_store_stmt = use_stmt;
    7600            0 :             }
    7601          126 :           if (other_store_stmt == NULL)
    7602            0 :             goto fail;
    7603          126 :           rhs = gimple_assign_lhs (other_store_stmt);
    7604          126 :           if (!single_imm_use (rhs, &use_p, &other_store_stmt))
    7605            0 :             goto fail;
    7606              :         }
    7607              :     }
    7608          260 :   else if (STMT_VINFO_SIMD_LANE_ACCESS_P (stmt_info) == 3)
    7609              :     {
    7610          260 :       use_operand_p use_p;
    7611          260 :       imm_use_iterator iter;
    7612         1040 :       FOR_EACH_IMM_USE_FAST (use_p, iter, rhs)
    7613              :         {
    7614          520 :           gimple *use_stmt = USE_STMT (use_p);
    7615          520 :           if (use_stmt == stmt || is_gimple_debug (use_stmt))
    7616          260 :             continue;
    7617          260 :           if (other_store_stmt)
    7618            0 :             goto fail;
    7619          260 :           other_store_stmt = use_stmt;
    7620          260 :         }
    7621              :     }
    7622              :   else
    7623            0 :     goto fail;
    7624              : 
    7625          512 :   gimple *def_stmt = SSA_NAME_DEF_STMT (rhs);
    7626          512 :   if (gimple_bb (def_stmt) != gimple_bb (stmt)
    7627          512 :       || !is_gimple_assign (def_stmt)
    7628         1024 :       || gimple_assign_rhs_class (def_stmt) != GIMPLE_BINARY_RHS)
    7629            0 :     goto fail;
    7630              : 
    7631          512 :   enum tree_code code = gimple_assign_rhs_code (def_stmt);
    7632              :   /* For pointer addition, we should use the normal plus for the vector
    7633              :      operation.  */
    7634          512 :   switch (code)
    7635              :     {
    7636            0 :     case POINTER_PLUS_EXPR:
    7637            0 :       code = PLUS_EXPR;
    7638            0 :       break;
    7639            0 :     case MULT_HIGHPART_EXPR:
    7640            0 :       goto fail;
    7641              :     default:
    7642              :       break;
    7643              :     }
    7644          512 :   if (TREE_CODE_LENGTH (code) != binary_op || !commutative_tree_code (code))
    7645            0 :     goto fail;
    7646              : 
    7647          512 :   tree rhs1 = gimple_assign_rhs1 (def_stmt);
    7648          512 :   tree rhs2 = gimple_assign_rhs2 (def_stmt);
    7649          512 :   if (TREE_CODE (rhs1) != SSA_NAME || TREE_CODE (rhs2) != SSA_NAME)
    7650            0 :     goto fail;
    7651              : 
    7652          512 :   gimple *load1_stmt = SSA_NAME_DEF_STMT (rhs1);
    7653          512 :   gimple *load2_stmt = SSA_NAME_DEF_STMT (rhs2);
    7654          512 :   if (gimple_bb (load1_stmt) != gimple_bb (stmt)
    7655          512 :       || !gimple_assign_load_p (load1_stmt)
    7656          512 :       || gimple_bb (load2_stmt) != gimple_bb (stmt)
    7657         1024 :       || !gimple_assign_load_p (load2_stmt))
    7658            0 :     goto fail;
    7659              : 
    7660          512 :   stmt_vec_info load1_stmt_info = loop_vinfo->lookup_stmt (load1_stmt);
    7661          512 :   stmt_vec_info load2_stmt_info = loop_vinfo->lookup_stmt (load2_stmt);
    7662          512 :   if (load1_stmt_info == NULL
    7663          512 :       || load2_stmt_info == NULL
    7664          512 :       || (STMT_VINFO_SIMD_LANE_ACCESS_P (load1_stmt_info)
    7665          512 :           != STMT_VINFO_SIMD_LANE_ACCESS_P (stmt_info))
    7666          512 :       || (STMT_VINFO_SIMD_LANE_ACCESS_P (load2_stmt_info)
    7667          512 :           != STMT_VINFO_SIMD_LANE_ACCESS_P (stmt_info)))
    7668            0 :     goto fail;
    7669              : 
    7670          512 :   if (STMT_VINFO_SIMD_LANE_ACCESS_P (stmt_info) == 4 && inscan_var_store)
    7671              :     {
    7672          126 :       dr_vec_info *load1_dr_info = STMT_VINFO_DR_INFO (load1_stmt_info);
    7673          126 :       if (TREE_CODE (DR_BASE_ADDRESS (load1_dr_info->dr)) != ADDR_EXPR
    7674          126 :           || !VAR_P (TREE_OPERAND (DR_BASE_ADDRESS (load1_dr_info->dr), 0)))
    7675            0 :         goto fail;
    7676          126 :       tree var1 = TREE_OPERAND (DR_BASE_ADDRESS (load1_dr_info->dr), 0);
    7677          126 :       tree lrhs;
    7678          126 :       if (lookup_attribute ("omp simd inscan", DECL_ATTRIBUTES (var1)))
    7679              :         lrhs = rhs1;
    7680              :       else
    7681           16 :         lrhs = rhs2;
    7682          126 :       use_operand_p use_p;
    7683          126 :       imm_use_iterator iter;
    7684          504 :       FOR_EACH_IMM_USE_FAST (use_p, iter, lrhs)
    7685              :         {
    7686          252 :           gimple *use_stmt = USE_STMT (use_p);
    7687          252 :           if (use_stmt == def_stmt || is_gimple_debug (use_stmt))
    7688          126 :             continue;
    7689          126 :           if (other_store_stmt)
    7690            0 :             goto fail;
    7691          126 :           other_store_stmt = use_stmt;
    7692          126 :         }
    7693              :     }
    7694              : 
    7695          512 :   if (other_store_stmt == NULL)
    7696            0 :     goto fail;
    7697          512 :   if (gimple_bb (other_store_stmt) != gimple_bb (stmt)
    7698          512 :       || !gimple_store_p (other_store_stmt))
    7699            0 :     goto fail;
    7700              : 
    7701          512 :   stmt_vec_info other_store_stmt_info
    7702          512 :     = loop_vinfo->lookup_stmt (other_store_stmt);
    7703          512 :   if (other_store_stmt_info == NULL
    7704          512 :       || (STMT_VINFO_SIMD_LANE_ACCESS_P (other_store_stmt_info)
    7705          512 :           != STMT_VINFO_SIMD_LANE_ACCESS_P (stmt_info)))
    7706            0 :     goto fail;
    7707              : 
    7708          512 :   gimple *stmt1 = stmt;
    7709          512 :   gimple *stmt2 = other_store_stmt;
    7710          512 :   if (STMT_VINFO_SIMD_LANE_ACCESS_P (stmt_info) == 4 && !inscan_var_store)
    7711              :     std::swap (stmt1, stmt2);
    7712          512 :   if (scan_operand_equal_p (gimple_assign_lhs (stmt1),
    7713              :                             gimple_assign_rhs1 (load2_stmt)))
    7714              :     {
    7715          162 :       std::swap (rhs1, rhs2);
    7716          162 :       std::swap (load1_stmt, load2_stmt);
    7717          162 :       std::swap (load1_stmt_info, load2_stmt_info);
    7718              :     }
    7719          512 :   if (!scan_operand_equal_p (gimple_assign_lhs (stmt1),
    7720              :                              gimple_assign_rhs1 (load1_stmt)))
    7721            0 :     goto fail;
    7722              : 
    7723          512 :   tree var3 = NULL_TREE;
    7724          512 :   if (STMT_VINFO_SIMD_LANE_ACCESS_P (stmt_info) == 3
    7725          512 :       && !scan_operand_equal_p (gimple_assign_lhs (stmt2),
    7726              :                                 gimple_assign_rhs1 (load2_stmt)))
    7727            0 :     goto fail;
    7728          512 :   else if (STMT_VINFO_SIMD_LANE_ACCESS_P (stmt_info) == 4)
    7729              :     {
    7730          252 :       dr_vec_info *load2_dr_info = STMT_VINFO_DR_INFO (load2_stmt_info);
    7731          252 :       if (TREE_CODE (DR_BASE_ADDRESS (load2_dr_info->dr)) != ADDR_EXPR
    7732          252 :           || !VAR_P (TREE_OPERAND (DR_BASE_ADDRESS (load2_dr_info->dr), 0)))
    7733            0 :         goto fail;
    7734          252 :       var3 = TREE_OPERAND (DR_BASE_ADDRESS (load2_dr_info->dr), 0);
    7735          252 :       if (!lookup_attribute ("omp simd array", DECL_ATTRIBUTES (var3))
    7736          252 :           || lookup_attribute ("omp simd inscan", DECL_ATTRIBUTES (var3))
    7737          504 :           || lookup_attribute ("omp simd inscan exclusive",
    7738          252 :                                DECL_ATTRIBUTES (var3)))
    7739            0 :         goto fail;
    7740              :     }
    7741              : 
    7742          512 :   dr_vec_info *other_dr_info = STMT_VINFO_DR_INFO (other_store_stmt_info);
    7743          512 :   if (TREE_CODE (DR_BASE_ADDRESS (other_dr_info->dr)) != ADDR_EXPR
    7744          512 :       || !VAR_P (TREE_OPERAND (DR_BASE_ADDRESS (other_dr_info->dr), 0)))
    7745            0 :     goto fail;
    7746              : 
    7747          512 :   tree var1 = TREE_OPERAND (DR_BASE_ADDRESS (dr_info->dr), 0);
    7748          512 :   tree var2 = TREE_OPERAND (DR_BASE_ADDRESS (other_dr_info->dr), 0);
    7749          512 :   if (!lookup_attribute ("omp simd array", DECL_ATTRIBUTES (var1))
    7750          512 :       || !lookup_attribute ("omp simd array", DECL_ATTRIBUTES (var2))
    7751         1024 :       || (!lookup_attribute ("omp simd inscan", DECL_ATTRIBUTES (var1)))
    7752          512 :          == (!lookup_attribute ("omp simd inscan", DECL_ATTRIBUTES (var2))))
    7753            0 :     goto fail;
    7754              : 
    7755          512 :   if (lookup_attribute ("omp simd inscan", DECL_ATTRIBUTES (var1)))
    7756          256 :     std::swap (var1, var2);
    7757              : 
    7758          512 :   if (STMT_VINFO_SIMD_LANE_ACCESS_P (stmt_info) == 4)
    7759              :     {
    7760          252 :       if (!lookup_attribute ("omp simd inscan exclusive",
    7761          252 :                              DECL_ATTRIBUTES (var1)))
    7762            0 :         goto fail;
    7763          252 :       var1 = var3;
    7764              :     }
    7765              : 
    7766          512 :   if (loop_vinfo->scan_map == NULL)
    7767            0 :     goto fail;
    7768          512 :   tree *init = loop_vinfo->scan_map->get (var1);
    7769          512 :   if (init == NULL)
    7770            0 :     goto fail;
    7771              : 
    7772              :   /* The IL is as expected, now check if we can actually vectorize it.
    7773              :      Inclusive scan:
    7774              :        _26 = D.2043[_25];
    7775              :        _27 = D.2042[_25];
    7776              :        _28 = _26 + _27;
    7777              :        D.2043[_25] = _28;
    7778              :        D.2042[_25] = _28;
    7779              :      should be vectorized as (where _40 is the vectorized rhs
    7780              :      from the D.2042[_21] = 0; store):
    7781              :        _30 = MEM <vector(8) int> [(int *)&D.2043];
    7782              :        _31 = MEM <vector(8) int> [(int *)&D.2042];
    7783              :        _32 = VEC_PERM_EXPR <_40, _31, { 0, 8, 9, 10, 11, 12, 13, 14 }>;
    7784              :        _33 = _31 + _32;
    7785              :        // _33 = { _31[0], _31[0]+_31[1], _31[1]+_31[2], ..., _31[6]+_31[7] };
    7786              :        _34 = VEC_PERM_EXPR <_40, _33, { 0, 1, 8, 9, 10, 11, 12, 13 }>;
    7787              :        _35 = _33 + _34;
    7788              :        // _35 = { _31[0], _31[0]+_31[1], _31[0]+.._31[2], _31[0]+.._31[3],
    7789              :        //         _31[1]+.._31[4], ... _31[4]+.._31[7] };
    7790              :        _36 = VEC_PERM_EXPR <_40, _35, { 0, 1, 2, 3, 8, 9, 10, 11 }>;
    7791              :        _37 = _35 + _36;
    7792              :        // _37 = { _31[0], _31[0]+_31[1], _31[0]+.._31[2], _31[0]+.._31[3],
    7793              :        //         _31[0]+.._31[4], ... _31[0]+.._31[7] };
    7794              :        _38 = _30 + _37;
    7795              :        _39 = VEC_PERM_EXPR <_38, _38, { 7, 7, 7, 7, 7, 7, 7, 7 }>;
    7796              :        MEM <vector(8) int> [(int *)&D.2043] = _39;
    7797              :        MEM <vector(8) int> [(int *)&D.2042] = _38;
    7798              :      Exclusive scan:
    7799              :        _26 = D.2043[_25];
    7800              :        D.2044[_25] = _26;
    7801              :        _27 = D.2042[_25];
    7802              :        _28 = _26 + _27;
    7803              :        D.2043[_25] = _28;
    7804              :      should be vectorized as (where _40 is the vectorized rhs
    7805              :      from the D.2042[_21] = 0; store):
    7806              :        _30 = MEM <vector(8) int> [(int *)&D.2043];
    7807              :        _31 = MEM <vector(8) int> [(int *)&D.2042];
    7808              :        _32 = VEC_PERM_EXPR <_40, _31, { 0, 8, 9, 10, 11, 12, 13, 14 }>;
    7809              :        _33 = VEC_PERM_EXPR <_40, _32, { 0, 8, 9, 10, 11, 12, 13, 14 }>;
    7810              :        _34 = _32 + _33;
    7811              :        // _34 = { 0, _31[0], _31[0]+_31[1], _31[1]+_31[2], _31[2]+_31[3],
    7812              :        //         _31[3]+_31[4], ... _31[5]+.._31[6] };
    7813              :        _35 = VEC_PERM_EXPR <_40, _34, { 0, 1, 8, 9, 10, 11, 12, 13 }>;
    7814              :        _36 = _34 + _35;
    7815              :        // _36 = { 0, _31[0], _31[0]+_31[1], _31[0]+.._31[2], _31[0]+.._31[3],
    7816              :        //         _31[1]+.._31[4], ... _31[3]+.._31[6] };
    7817              :        _37 = VEC_PERM_EXPR <_40, _36, { 0, 1, 2, 3, 8, 9, 10, 11 }>;
    7818              :        _38 = _36 + _37;
    7819              :        // _38 = { 0, _31[0], _31[0]+_31[1], _31[0]+.._31[2], _31[0]+.._31[3],
    7820              :        //         _31[0]+.._31[4], ... _31[0]+.._31[6] };
    7821              :        _39 = _30 + _38;
    7822              :        _50 = _31 + _39;
    7823              :        _51 = VEC_PERM_EXPR <_50, _50, { 7, 7, 7, 7, 7, 7, 7, 7 }>;
    7824              :        MEM <vector(8) int> [(int *)&D.2044] = _39;
    7825              :        MEM <vector(8) int> [(int *)&D.2042] = _51;  */
    7826          512 :   enum machine_mode vec_mode = TYPE_MODE (vectype);
    7827          512 :   optab optab = optab_for_tree_code (code, vectype, optab_default);
    7828          512 :   if (!optab || !can_implement_p (optab, vec_mode))
    7829            0 :     goto fail;
    7830              : 
    7831          512 :   int units_log2 = scan_store_can_perm_p (vectype, *init);
    7832          512 :   if (units_log2 == -1)
    7833            0 :     goto fail;
    7834              : 
    7835              :   return true;
    7836              : }
    7837              : 
    7838              : 
    7839              : /* Function vectorizable_scan_store.
    7840              : 
    7841              :    Helper of vectorizable_score, arguments like on vectorizable_store.
    7842              :    Handle only the transformation, checking is done in check_scan_store.  */
    7843              : 
    7844              : static bool
    7845          512 : vectorizable_scan_store (vec_info *vinfo, stmt_vec_info stmt_info,
    7846              :                          slp_tree slp_node, gimple_stmt_iterator *gsi)
    7847              : {
    7848          512 :   loop_vec_info loop_vinfo = dyn_cast <loop_vec_info> (vinfo);
    7849          512 :   dr_vec_info *dr_info = STMT_VINFO_DR_INFO (stmt_info);
    7850          512 :   tree ref_type = reference_alias_ptr_type (DR_REF (dr_info->dr));
    7851          512 :   tree vectype = SLP_TREE_VECTYPE (slp_node);
    7852              : 
    7853          512 :   if (dump_enabled_p ())
    7854          492 :     dump_printf_loc (MSG_NOTE, vect_location,
    7855              :                      "transform scan store.\n");
    7856              : 
    7857          512 :   gimple *stmt = STMT_VINFO_STMT (stmt_info);
    7858          512 :   tree rhs = gimple_assign_rhs1 (stmt);
    7859          512 :   gcc_assert (TREE_CODE (rhs) == SSA_NAME);
    7860              : 
    7861          512 :   tree var = TREE_OPERAND (DR_BASE_ADDRESS (dr_info->dr), 0);
    7862          512 :   bool inscan_var_store
    7863          512 :     = lookup_attribute ("omp simd inscan", DECL_ATTRIBUTES (var)) != NULL;
    7864              : 
    7865          512 :   if (STMT_VINFO_SIMD_LANE_ACCESS_P (stmt_info) == 4 && !inscan_var_store)
    7866              :     {
    7867          126 :       use_operand_p use_p;
    7868          126 :       imm_use_iterator iter;
    7869          252 :       FOR_EACH_IMM_USE_FAST (use_p, iter, rhs)
    7870              :         {
    7871          126 :           gimple *use_stmt = USE_STMT (use_p);
    7872          126 :           if (use_stmt == stmt || is_gimple_debug (use_stmt))
    7873            0 :             continue;
    7874          126 :           rhs = gimple_assign_lhs (use_stmt);
    7875          126 :           break;
    7876          126 :         }
    7877              :     }
    7878              : 
    7879          512 :   gimple *def_stmt = SSA_NAME_DEF_STMT (rhs);
    7880          512 :   enum tree_code code = gimple_assign_rhs_code (def_stmt);
    7881          512 :   if (code == POINTER_PLUS_EXPR)
    7882            0 :     code = PLUS_EXPR;
    7883          512 :   gcc_assert (TREE_CODE_LENGTH (code) == binary_op
    7884              :               && commutative_tree_code (code));
    7885          512 :   tree rhs1 = gimple_assign_rhs1 (def_stmt);
    7886          512 :   tree rhs2 = gimple_assign_rhs2 (def_stmt);
    7887          512 :   gcc_assert (TREE_CODE (rhs1) == SSA_NAME && TREE_CODE (rhs2) == SSA_NAME);
    7888          512 :   gimple *load1_stmt = SSA_NAME_DEF_STMT (rhs1);
    7889          512 :   gimple *load2_stmt = SSA_NAME_DEF_STMT (rhs2);
    7890          512 :   stmt_vec_info load1_stmt_info = loop_vinfo->lookup_stmt (load1_stmt);
    7891          512 :   stmt_vec_info load2_stmt_info = loop_vinfo->lookup_stmt (load2_stmt);
    7892          512 :   dr_vec_info *load1_dr_info = STMT_VINFO_DR_INFO (load1_stmt_info);
    7893          512 :   dr_vec_info *load2_dr_info = STMT_VINFO_DR_INFO (load2_stmt_info);
    7894          512 :   tree var1 = TREE_OPERAND (DR_BASE_ADDRESS (load1_dr_info->dr), 0);
    7895          512 :   tree var2 = TREE_OPERAND (DR_BASE_ADDRESS (load2_dr_info->dr), 0);
    7896              : 
    7897          512 :   if (lookup_attribute ("omp simd inscan", DECL_ATTRIBUTES (var1)))
    7898              :     {
    7899          436 :       std::swap (rhs1, rhs2);
    7900          436 :       std::swap (var1, var2);
    7901          436 :       std::swap (load1_dr_info, load2_dr_info);
    7902              :     }
    7903              : 
    7904          512 :   tree *init = loop_vinfo->scan_map->get (var1);
    7905          512 :   gcc_assert (init);
    7906              : 
    7907          512 :   unsigned HOST_WIDE_INT nunits;
    7908          512 :   if (!TYPE_VECTOR_SUBPARTS (vectype).is_constant (&nunits))
    7909              :     gcc_unreachable ();
    7910          512 :   auto_vec<enum scan_store_kind, 16> use_whole_vector;
    7911          512 :   int units_log2 = scan_store_can_perm_p (vectype, *init, &use_whole_vector);
    7912          512 :   gcc_assert (units_log2 > 0);
    7913          512 :   auto_vec<tree, 16> perms;
    7914          512 :   perms.quick_grow (units_log2 + 1);
    7915          512 :   tree zero_vec = NULL_TREE, masktype = NULL_TREE;
    7916         2392 :   for (int i = 0; i <= units_log2; ++i)
    7917              :     {
    7918         1880 :       unsigned HOST_WIDE_INT j, k;
    7919         1880 :       vec_perm_builder sel (nunits, nunits, 1);
    7920         1880 :       sel.quick_grow (nunits);
    7921         1880 :       if (i == units_log2)
    7922         4864 :         for (j = 0; j < nunits; ++j)
    7923         4352 :           sel[j] = nunits - 1;
    7924              :       else
    7925              :         {
    7926         5208 :           for (j = 0; j < (HOST_WIDE_INT_1U << i); ++j)
    7927         3840 :             sel[j] = j;
    7928        13208 :           for (k = 0; j < nunits; ++j, ++k)
    7929        11840 :             sel[j] = nunits + k;
    7930              :         }
    7931         3248 :       vec_perm_indices indices (sel, i == units_log2 ? 1 : 2, nunits);
    7932         1880 :       if (!use_whole_vector.is_empty ()
    7933            0 :           && use_whole_vector[i] != scan_store_kind_perm)
    7934              :         {
    7935            0 :           if (zero_vec == NULL_TREE)
    7936            0 :             zero_vec = build_zero_cst (vectype);
    7937            0 :           if (masktype == NULL_TREE
    7938            0 :               && use_whole_vector[i] == scan_store_kind_lshift_cond)
    7939            0 :             masktype = truth_type_for (vectype);
    7940            0 :           perms[i] = vect_gen_perm_mask_any (vectype, indices);
    7941              :         }
    7942              :       else
    7943         1880 :         perms[i] = vect_gen_perm_mask_checked (vectype, indices);
    7944         1880 :     }
    7945              : 
    7946          512 :   vec_loop_lens *loop_lens
    7947          512 :     = (loop_vinfo && LOOP_VINFO_FULLY_WITH_LENGTH_P (loop_vinfo)
    7948              :        ? &LOOP_VINFO_LENS (loop_vinfo)
    7949            0 :        : NULL);
    7950              : 
    7951          512 :   tree vec_oprnd1 = NULL_TREE;
    7952          512 :   tree vec_oprnd2 = NULL_TREE;
    7953          512 :   tree vec_oprnd3 = NULL_TREE;
    7954          512 :   tree dataref_ptr = DR_BASE_ADDRESS (dr_info->dr);
    7955          512 :   tree dataref_offset = build_int_cst (ref_type, 0);
    7956          512 :   tree bump = vect_get_data_ptr_increment (vinfo, gsi, dr_info,
    7957              :                                            vectype, VMAT_CONTIGUOUS,
    7958              :                                            loop_lens);
    7959          512 :   tree ldataref_ptr = NULL_TREE;
    7960          512 :   tree orig = NULL_TREE;
    7961          512 :   if (STMT_VINFO_SIMD_LANE_ACCESS_P (stmt_info) == 4 && !inscan_var_store)
    7962          126 :     ldataref_ptr = DR_BASE_ADDRESS (load1_dr_info->dr);
    7963              :   /* The initialization is invariant.  */
    7964          512 :   vec_oprnd1 = vect_init_vector (vinfo, stmt_info, *init, vectype, NULL);
    7965          512 :   auto_vec<tree> vec_oprnds2;
    7966          512 :   auto_vec<tree> vec_oprnds3;
    7967          512 :   if (ldataref_ptr == NULL)
    7968              :     {
    7969              :       /* We want to lookup the vector operands of the reduction, not those
    7970              :          of the store - for SLP we have to use the proper SLP node for the
    7971              :          lookup, which should be the single child of the scan store.  */
    7972          386 :       vect_get_vec_defs (vinfo, SLP_TREE_CHILDREN (slp_node)[0],
    7973              :                          rhs1, &vec_oprnds2, rhs2, &vec_oprnds3);
    7974              :       /* ???  For SLP we do not key the def on 'rhs1' or 'rhs2' but get
    7975              :          them in SLP child order.  So we have to swap here with logic
    7976              :          similar to above.  */
    7977          386 :       stmt_vec_info load
    7978          386 :         = SLP_TREE_SCALAR_STMTS (SLP_TREE_CHILDREN
    7979          386 :                                    (SLP_TREE_CHILDREN (slp_node)[0])[0])[0];
    7980          386 :       dr_vec_info *dr_info = STMT_VINFO_DR_INFO (load);
    7981          386 :       tree var = TREE_OPERAND (DR_BASE_ADDRESS (dr_info->dr), 0);
    7982          386 :       if (lookup_attribute ("omp simd inscan", DECL_ATTRIBUTES (var)))
    7983          820 :         for (unsigned i = 0; i < vec_oprnds2.length (); ++i)
    7984          494 :           std::swap (vec_oprnds2[i], vec_oprnds3[i]);;
    7985              :     }
    7986              :   else
    7987          126 :     vect_get_vec_defs (vinfo, slp_node,
    7988              :                        rhs2, &vec_oprnds3);
    7989         1248 :   for (unsigned j = 0; j < vec_oprnds3.length (); j++)
    7990              :     {
    7991          736 :       if (ldataref_ptr == NULL)
    7992          554 :         vec_oprnd2 = vec_oprnds2[j];
    7993          736 :       vec_oprnd3 = vec_oprnds3[j];
    7994          736 :       if (j == 0)
    7995              :         orig = vec_oprnd3;
    7996          224 :       else if (!inscan_var_store)
    7997          112 :         dataref_offset = int_const_binop (PLUS_EXPR, dataref_offset, bump);
    7998              : 
    7999          736 :       if (ldataref_ptr)
    8000              :         {
    8001          182 :           vec_oprnd2 = make_ssa_name (vectype);
    8002          182 :           tree data_ref = fold_build2 (MEM_REF, vectype,
    8003              :                                        unshare_expr (ldataref_ptr),
    8004              :                                        dataref_offset);
    8005          182 :           vect_copy_ref_info (data_ref, DR_REF (load1_dr_info->dr));
    8006          182 :           gimple *g = gimple_build_assign (vec_oprnd2, data_ref);
    8007          182 :           vect_finish_stmt_generation (vinfo, stmt_info, g, gsi);
    8008              :         }
    8009              : 
    8010          736 :       tree v = vec_oprnd2;
    8011         3068 :       for (int i = 0; i < units_log2; ++i)
    8012              :         {
    8013         2332 :           tree new_temp = make_ssa_name (vectype);
    8014         2332 :           gimple *g = gimple_build_assign (new_temp, VEC_PERM_EXPR,
    8015              :                                            (zero_vec
    8016            0 :                                             && (use_whole_vector[i]
    8017            0 :                                                 != scan_store_kind_perm))
    8018              :                                            ? zero_vec : vec_oprnd1, v,
    8019         2332 :                                            perms[i]);
    8020         2332 :           vect_finish_stmt_generation (vinfo, stmt_info, g, gsi);
    8021              : 
    8022         2332 :           if (zero_vec && use_whole_vector[i] == scan_store_kind_lshift_cond)
    8023              :             {
    8024              :               /* Whole vector shift shifted in zero bits, but if *init
    8025              :                  is not initializer_zerop, we need to replace those elements
    8026              :                  with elements from vec_oprnd1.  */
    8027            0 :               tree_vector_builder vb (masktype, nunits, 1);
    8028            0 :               for (unsigned HOST_WIDE_INT k = 0; k < nunits; ++k)
    8029            0 :                 vb.quick_push (k < (HOST_WIDE_INT_1U << i)
    8030              :                                ? boolean_false_node : boolean_true_node);
    8031              : 
    8032            0 :               tree new_temp2 = make_ssa_name (vectype);
    8033            0 :               g = gimple_build_assign (new_temp2, VEC_COND_EXPR, vb.build (),
    8034              :                                        new_temp, vec_oprnd1);
    8035            0 :               vect_finish_stmt_generation (vinfo, stmt_info,
    8036              :                                                            g, gsi);
    8037            0 :               new_temp = new_temp2;
    8038            0 :             }
    8039              : 
    8040              :           /* For exclusive scan, perform the perms[i] permutation once
    8041              :              more.  */
    8042         2332 :           if (i == 0
    8043         1100 :               && STMT_VINFO_SIMD_LANE_ACCESS_P (stmt_info) == 4
    8044          728 :               && v == vec_oprnd2)
    8045              :             {
    8046          364 :               v = new_temp;
    8047          364 :               --i;
    8048          364 :               continue;
    8049              :             }
    8050              : 
    8051         1968 :           tree new_temp2 = make_ssa_name (vectype);
    8052         1968 :           g = gimple_build_assign (new_temp2, code, v, new_temp);
    8053         1968 :           vect_finish_stmt_generation (vinfo, stmt_info, g, gsi);
    8054              : 
    8055         1968 :           v = new_temp2;
    8056              :         }
    8057              : 
    8058          736 :       tree new_temp = make_ssa_name (vectype);
    8059          736 :       gimple *g = gimple_build_assign (new_temp, code, orig, v);
    8060          736 :       vect_finish_stmt_generation (vinfo, stmt_info, g, gsi);
    8061              : 
    8062          736 :       tree last_perm_arg = new_temp;
    8063              :       /* For exclusive scan, new_temp computed above is the exclusive scan
    8064              :          prefix sum.  Turn it into inclusive prefix sum for the broadcast
    8065              :          of the last element into orig.  */
    8066          736 :       if (STMT_VINFO_SIMD_LANE_ACCESS_P (stmt_info) == 4)
    8067              :         {
    8068          364 :           last_perm_arg = make_ssa_name (vectype);
    8069          364 :           g = gimple_build_assign (last_perm_arg, code, new_temp, vec_oprnd2);
    8070          364 :           vect_finish_stmt_generation (vinfo, stmt_info, g, gsi);
    8071              :         }
    8072              : 
    8073          736 :       orig = make_ssa_name (vectype);
    8074         2208 :       g = gimple_build_assign (orig, VEC_PERM_EXPR, last_perm_arg,
    8075          736 :                                last_perm_arg, perms[units_log2]);
    8076          736 :       vect_finish_stmt_generation (vinfo, stmt_info, g, gsi);
    8077              : 
    8078          736 :       if (!inscan_var_store)
    8079              :         {
    8080          368 :           tree data_ref = fold_build2 (MEM_REF, vectype,
    8081              :                                        unshare_expr (dataref_ptr),
    8082              :                                        dataref_offset);
    8083          368 :           vect_copy_ref_info (data_ref, DR_REF (dr_info->dr));
    8084          368 :           g = gimple_build_assign (data_ref, new_temp);
    8085          368 :           vect_finish_stmt_generation (vinfo, stmt_info, g, gsi);
    8086              :         }
    8087              :     }
    8088              : 
    8089          512 :   if (inscan_var_store)
    8090          624 :     for (unsigned j = 0; j < vec_oprnds3.length (); j++)
    8091              :       {
    8092          368 :         if (j != 0)
    8093          112 :           dataref_offset = int_const_binop (PLUS_EXPR, dataref_offset, bump);
    8094              : 
    8095          368 :         tree data_ref = fold_build2 (MEM_REF, vectype,
    8096              :                                      unshare_expr (dataref_ptr),
    8097              :                                      dataref_offset);
    8098          368 :         vect_copy_ref_info (data_ref, DR_REF (dr_info->dr));
    8099          368 :         gimple *g = gimple_build_assign (data_ref, orig);
    8100          368 :         vect_finish_stmt_generation (vinfo, stmt_info, g, gsi);
    8101              :       }
    8102          512 :   return true;
    8103          512 : }
    8104              : 
    8105              : 
    8106              : /* Function vectorizable_store.
    8107              : 
    8108              :    Check if STMT_INFO defines a non scalar data-ref (array/pointer/structure)
    8109              :    that can be vectorized.
    8110              :    If COST_VEC is passed, calculate costs but don't change anything,
    8111              :    otherwise, vectorize STMT_INFO: create a vectorized stmt to replace
    8112              :    it, and insert it at GSI.
    8113              :    Return true if STMT_INFO is vectorizable in this way.  */
    8114              : 
    8115              : static bool
    8116      1959155 : vectorizable_store (vec_info *vinfo,
    8117              :                     stmt_vec_info stmt_info, gimple_stmt_iterator *gsi,
    8118              :                     slp_tree slp_node,
    8119              :                     stmt_vector_for_cost *cost_vec)
    8120              : {
    8121      1959155 :   tree data_ref;
    8122      1959155 :   tree vec_oprnd = NULL_TREE;
    8123      1959155 :   tree elem_type;
    8124      1959155 :   loop_vec_info loop_vinfo = dyn_cast <loop_vec_info> (vinfo);
    8125      1959155 :   class loop *loop = NULL;
    8126      1959155 :   machine_mode vec_mode;
    8127      1959155 :   tree dummy;
    8128      1959155 :   enum vect_def_type rhs_dt = vect_unknown_def_type;
    8129      1959155 :   enum vect_def_type mask_dt = vect_unknown_def_type;
    8130      1959155 :   tree dataref_ptr = NULL_TREE;
    8131      1959155 :   tree dataref_offset = NULL_TREE;
    8132      1959155 :   gimple *ptr_incr = NULL;
    8133      1959155 :   int j;
    8134      1959155 :   stmt_vec_info first_stmt_info;
    8135      1959155 :   bool grouped_store;
    8136      1959155 :   unsigned int group_size, i;
    8137      1959155 :   unsigned int vec_num;
    8138      1959155 :   bb_vec_info bb_vinfo = dyn_cast <bb_vec_info> (vinfo);
    8139      1959155 :   tree aggr_type;
    8140      1959155 :   poly_uint64 vf;
    8141      1959155 :   vec_load_store_type vls_type;
    8142      1959155 :   tree ref_type;
    8143              : 
    8144      1959155 :   if (!STMT_VINFO_RELEVANT_P (stmt_info) && !bb_vinfo)
    8145              :     return false;
    8146              : 
    8147      1959155 :   if (STMT_VINFO_DEF_TYPE (stmt_info) != vect_internal_def
    8148       194522 :       && cost_vec)
    8149              :     return false;
    8150              : 
    8151              :   /* Is vectorizable store? */
    8152              : 
    8153      1764633 :   tree mask_vectype = NULL_TREE;
    8154      1764633 :   slp_tree mask_node = NULL;
    8155      1764633 :   if (gassign *assign = dyn_cast <gassign *> (stmt_info->stmt))
    8156              :     {
    8157      1698205 :       tree scalar_dest = gimple_assign_lhs (assign);
    8158      1698205 :       if (TREE_CODE (scalar_dest) == VIEW_CONVERT_EXPR
    8159      1698205 :           && is_pattern_stmt_p (stmt_info))
    8160         1393 :         scalar_dest = TREE_OPERAND (scalar_dest, 0);
    8161      1698205 :       if (TREE_CODE (scalar_dest) != ARRAY_REF
    8162      1698205 :           && TREE_CODE (scalar_dest) != BIT_FIELD_REF
    8163              :           && TREE_CODE (scalar_dest) != INDIRECT_REF
    8164              :           && TREE_CODE (scalar_dest) != COMPONENT_REF
    8165              :           && TREE_CODE (scalar_dest) != IMAGPART_EXPR
    8166              :           && TREE_CODE (scalar_dest) != REALPART_EXPR
    8167              :           && TREE_CODE (scalar_dest) != MEM_REF)
    8168              :         return false;
    8169              :     }
    8170              :   else
    8171              :     {
    8172       651259 :       gcall *call = dyn_cast <gcall *> (stmt_info->stmt);
    8173         8652 :       if (!call || !gimple_call_internal_p (call))
    8174              :         return false;
    8175              : 
    8176         4779 :       internal_fn ifn = gimple_call_internal_fn (call);
    8177         4779 :       if (!internal_store_fn_p (ifn))
    8178              :         return false;
    8179              : 
    8180         1470 :       int mask_index = internal_fn_mask_index (ifn);
    8181         1470 :       if (mask_index >= 0)
    8182         1470 :         mask_index = vect_slp_child_index_for_operand
    8183         1470 :                     (call, mask_index, STMT_VINFO_GATHER_SCATTER_P (stmt_info));
    8184         1470 :       if (mask_index >= 0
    8185         1470 :           && !vect_check_scalar_mask (vinfo, slp_node, mask_index,
    8186              :                                       &mask_node, &mask_dt,
    8187              :                                       &mask_vectype))
    8188              :         return false;
    8189              :     }
    8190              : 
    8191      1316580 :   tree vectype = SLP_TREE_VECTYPE (slp_node), rhs_vectype = NULL_TREE;
    8192      1316580 :   poly_uint64 nunits = TYPE_VECTOR_SUBPARTS (vectype);
    8193              : 
    8194      1316580 :   if (loop_vinfo)
    8195              :     {
    8196       188080 :       loop = LOOP_VINFO_LOOP (loop_vinfo);
    8197       188080 :       vf = LOOP_VINFO_VECT_FACTOR (loop_vinfo);
    8198              :     }
    8199              :   else
    8200              :     vf = 1;
    8201      1316580 :   vec_num = vect_get_num_copies (vinfo, slp_node);
    8202              : 
    8203              :   /* FORNOW.  This restriction should be relaxed.  */
    8204      1316580 :   if (loop
    8205      1316805 :       && nested_in_vect_loop_p (loop, stmt_info)
    8206      1316813 :       && vec_num > 1)
    8207              :     {
    8208            8 :       if (dump_enabled_p ())
    8209            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    8210              :                          "multiple types in nested loop.\n");
    8211            8 :       return false;
    8212              :     }
    8213              : 
    8214      1316572 :   slp_tree op_node;
    8215      1316572 :   if (!vect_check_store_rhs (vinfo, stmt_info, slp_node,
    8216              :                              &op_node, &rhs_dt, &rhs_vectype, &vls_type))
    8217              :     return false;
    8218              : 
    8219      1316548 :   elem_type = TREE_TYPE (vectype);
    8220      1316548 :   vec_mode = TYPE_MODE (vectype);
    8221              : 
    8222      1316548 :   if (!STMT_VINFO_DATA_REF (stmt_info))
    8223              :     return false;
    8224              : 
    8225      1316548 :   vect_load_store_data _ls_data{};
    8226      1316548 :   vect_load_store_data &ls = slp_node->get_data (_ls_data);
    8227      1316548 :   if (cost_vec
    8228      1316548 :       && !get_load_store_type (vinfo, stmt_info, vectype, slp_node, mask_node,
    8229              :                                vls_type, &_ls_data))
    8230              :     return false;
    8231              :   /* Temporary aliases to analysis data, should not be modified through
    8232              :      these.  */
    8233      1316008 :   const vect_memory_access_type memory_access_type = ls.memory_access_type;
    8234      1316008 :   const dr_alignment_support alignment_support_scheme
    8235              :     = ls.alignment_support_scheme;
    8236      1316008 :   const int misalignment = ls.misalignment;
    8237      1316008 :   const poly_int64 poffset = ls.poffset;
    8238              : 
    8239      1316008 :   if (slp_node->ldst_lanes
    8240            0 :       && memory_access_type != VMAT_LOAD_STORE_LANES)
    8241              :     {
    8242            0 :       if (dump_enabled_p ())
    8243            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    8244              :                          "discovered store-lane but cannot use it.\n");
    8245            0 :       return false;
    8246              :     }
    8247              : 
    8248      1316008 :   if (mask_node)
    8249              :     {
    8250         1380 :       if (memory_access_type == VMAT_CONTIGUOUS)
    8251              :         {
    8252          459 :           if (!VECTOR_MODE_P (vec_mode)
    8253         2276 :               || !can_vec_mask_load_store_p (vec_mode,
    8254         1138 :                                              TYPE_MODE (mask_vectype), false))
    8255           18 :             return false;
    8256              :         }
    8257          242 :       else if (memory_access_type != VMAT_LOAD_STORE_LANES
    8258          242 :                && (!mat_gather_scatter_p (memory_access_type)
    8259          218 :                    || (memory_access_type == VMAT_GATHER_SCATTER_LEGACY
    8260          154 :                        && !VECTOR_BOOLEAN_TYPE_P (mask_vectype))))
    8261              :         {
    8262           24 :           if (dump_enabled_p ())
    8263           24 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    8264              :                              "unsupported access type for masked store.\n");
    8265           24 :           return false;
    8266              :         }
    8267          218 :       else if (memory_access_type == VMAT_GATHER_SCATTER_EMULATED)
    8268              :         {
    8269           64 :           if (dump_enabled_p ())
    8270           24 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    8271              :                              "unsupported masked emulated scatter.\n");
    8272           64 :           return false;
    8273              :         }
    8274              :     }
    8275              :   else
    8276              :     {
    8277              :       /* FORNOW. In some cases can vectorize even if data-type not supported
    8278              :          (e.g. - array initialization with 0).  */
    8279      1314628 :       if (!can_implement_p (mov_optab, vec_mode))
    8280              :         return false;
    8281              :     }
    8282              : 
    8283      1315902 :   dr_vec_info *dr_info = STMT_VINFO_DR_INFO (stmt_info), *first_dr_info = NULL;
    8284      1315902 :   grouped_store = (STMT_VINFO_GROUPED_ACCESS (stmt_info)
    8285      2462069 :                    && !mat_gather_scatter_p (memory_access_type));
    8286      1146167 :   if (grouped_store)
    8287              :     {
    8288      1146167 :       first_stmt_info = DR_GROUP_FIRST_ELEMENT (stmt_info);
    8289      1146167 :       first_dr_info = STMT_VINFO_DR_INFO (first_stmt_info);
    8290      1146167 :       group_size = DR_GROUP_SIZE (first_stmt_info);
    8291              :     }
    8292              :   else
    8293              :     {
    8294      1315902 :       first_stmt_info = stmt_info;
    8295      1315902 :       first_dr_info = dr_info;
    8296              :       group_size = 1;
    8297              :     }
    8298              : 
    8299      1315902 :   if (STMT_VINFO_SIMD_LANE_ACCESS_P (stmt_info) > 1 && cost_vec)
    8300              :     {
    8301         1076 :       if (!check_scan_store (vinfo, stmt_info, vectype, rhs_dt, slp_node,
    8302              :                              mask_node, memory_access_type))
    8303              :         return false;
    8304              :     }
    8305              : 
    8306      2631036 :   bool costing_p = cost_vec;
    8307      1315134 :   if (costing_p) /* transformation not required.  */
    8308              :     {
    8309       772215 :       if (loop_vinfo
    8310       124324 :           && LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo))
    8311        57355 :         check_load_store_for_partial_vectors (loop_vinfo, vectype, slp_node,
    8312              :                                               vls_type, group_size, &ls,
    8313              :                                               mask_node);
    8314              : 
    8315       772215 :       if (!vect_maybe_update_slp_op_vectype (op_node, vectype)
    8316       772215 :           || (mask_node
    8317          723 :               && !vect_maybe_update_slp_op_vectype (mask_node,
    8318              :                                                     mask_vectype)))
    8319              :         {
    8320            0 :           if (dump_enabled_p ())
    8321            0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    8322              :                              "incompatible vector types for invariants\n");
    8323            0 :           return false;
    8324              :         }
    8325              : 
    8326       772215 :       if (dump_enabled_p ()
    8327              :           && memory_access_type != VMAT_ELEMENTWISE
    8328        14643 :           && memory_access_type != VMAT_STRIDED_SLP
    8329        13970 :           && memory_access_type != VMAT_INVARIANT
    8330       786185 :           && alignment_support_scheme != dr_aligned)
    8331         4834 :         dump_printf_loc (MSG_NOTE, vect_location,
    8332              :                          "Vectorizing an unaligned access.\n");
    8333              : 
    8334       772215 :       SLP_TREE_TYPE (slp_node) = store_vec_info_type;
    8335       772215 :       slp_node->data = new vect_load_store_data (std::move (ls));
    8336              :     }
    8337              : 
    8338              :   /* Transform.  */
    8339              : 
    8340      1315902 :   ensure_base_align (dr_info);
    8341              : 
    8342      1315902 :   if (STMT_VINFO_SIMD_LANE_ACCESS_P (stmt_info) >= 3)
    8343              :     {
    8344         1024 :       gcc_assert (memory_access_type == VMAT_CONTIGUOUS);
    8345         1024 :       gcc_assert (SLP_TREE_LANES (slp_node) == 1);
    8346         1024 :       if (costing_p)
    8347              :         {
    8348          512 :           unsigned int inside_cost = 0, prologue_cost = 0;
    8349          512 :           if (vls_type == VLS_STORE_INVARIANT)
    8350            0 :             prologue_cost += record_stmt_cost (cost_vec, 1, scalar_to_vec,
    8351              :                                                slp_node, 0, vect_prologue);
    8352          512 :           vect_get_store_cost (vinfo, stmt_info, slp_node, 1,
    8353              :                                alignment_support_scheme, misalignment,
    8354              :                                &inside_cost, cost_vec);
    8355              : 
    8356          512 :           if (dump_enabled_p ())
    8357          492 :             dump_printf_loc (MSG_NOTE, vect_location,
    8358              :                              "vect_model_store_cost: inside_cost = %d, "
    8359              :                              "prologue_cost = %d .\n",
    8360              :                              inside_cost, prologue_cost);
    8361              : 
    8362          512 :           return true;
    8363              :         }
    8364          512 :       return vectorizable_scan_store (vinfo, stmt_info, slp_node, gsi);
    8365              :     }
    8366              : 
    8367              :   /* FORNOW */
    8368      1314878 :   gcc_assert (!grouped_store
    8369              :               || !loop
    8370              :               || !nested_in_vect_loop_p (loop, stmt_info));
    8371              : 
    8372      1314878 :   grouped_store = false;
    8373      1314878 :   first_stmt_info = SLP_TREE_SCALAR_STMTS (slp_node)[0];
    8374      1314878 :   gcc_assert (!STMT_VINFO_GROUPED_ACCESS (first_stmt_info)
    8375              :               || (DR_GROUP_FIRST_ELEMENT (first_stmt_info) == first_stmt_info));
    8376      1314878 :   first_dr_info = STMT_VINFO_DR_INFO (first_stmt_info);
    8377              : 
    8378      1314878 :   ref_type = get_group_alias_ptr_type (first_stmt_info);
    8379              : 
    8380      1314878 :   if (!costing_p && dump_enabled_p ())
    8381        12238 :     dump_printf_loc (MSG_NOTE, vect_location, "transform store.\n");
    8382              : 
    8383      1314878 :   if (memory_access_type == VMAT_ELEMENTWISE
    8384      1314878 :       || memory_access_type == VMAT_STRIDED_SLP)
    8385              :     {
    8386        28124 :       unsigned inside_cost = 0, prologue_cost = 0;
    8387        28124 :       gimple_stmt_iterator incr_gsi;
    8388        28124 :       bool insert_after;
    8389        28124 :       tree offvar = NULL_TREE;
    8390        28124 :       tree ivstep;
    8391        28124 :       tree running_off;
    8392        28124 :       tree stride_base, stride_step, alias_off;
    8393        28124 :       tree vec_oprnd = NULL_TREE;
    8394        28124 :       tree dr_offset;
    8395              :       /* Checked by get_load_store_type.  */
    8396        28124 :       unsigned int const_nunits = nunits.to_constant ();
    8397              : 
    8398        28124 :       gcc_assert (!LOOP_VINFO_FULLY_MASKED_P (loop_vinfo));
    8399        28124 :       gcc_assert (!nested_in_vect_loop_p (loop, stmt_info));
    8400              : 
    8401        28124 :       dr_offset = get_dr_vinfo_offset (vinfo, first_dr_info);
    8402        28124 :       stride_base
    8403        28124 :         = fold_build_pointer_plus
    8404              :             (DR_BASE_ADDRESS (first_dr_info->dr),
    8405              :              size_binop (PLUS_EXPR,
    8406              :                          convert_to_ptrofftype (dr_offset),
    8407              :                          convert_to_ptrofftype (DR_INIT (first_dr_info->dr))));
    8408        28124 :       stride_step = fold_convert (sizetype, DR_STEP (first_dr_info->dr));
    8409              : 
    8410              :       /* For a store with loop-invariant (but other than power-of-2)
    8411              :          stride (i.e. not a grouped access) like so:
    8412              : 
    8413              :            for (i = 0; i < n; i += stride)
    8414              :              array[i] = ...;
    8415              : 
    8416              :          we generate a new induction variable and new stores from
    8417              :          the components of the (vectorized) rhs:
    8418              : 
    8419              :            for (j = 0; ; j += VF*stride)
    8420              :              vectemp = ...;
    8421              :              tmp1 = vectemp[0];
    8422              :              array[j] = tmp1;
    8423              :              tmp2 = vectemp[1];
    8424              :              array[j + stride] = tmp2;
    8425              :              ...
    8426              :          */
    8427              : 
    8428              :       /* ???  Modify local copies of alignment_support_scheme and
    8429              :          misalignment, but this part of analysis should be done
    8430              :          earlier and remembered, likewise the chosen load mode.  */
    8431        28124 :       const dr_alignment_support tem = alignment_support_scheme;
    8432        28124 :       dr_alignment_support alignment_support_scheme = tem;
    8433        28124 :       const int tem2 = misalignment;
    8434        28124 :       int misalignment = tem2;
    8435              : 
    8436        28124 :       unsigned nstores = const_nunits;
    8437        28124 :       unsigned lnel = 1;
    8438        28124 :       tree ltype = elem_type;
    8439        28124 :       tree lvectype = vectype;
    8440        28124 :       HOST_WIDE_INT n = gcd (group_size, const_nunits);
    8441        28124 :       if (n == const_nunits)
    8442              :         {
    8443         2426 :           int mis_align = dr_misalignment (first_dr_info, vectype);
    8444              :           /* With VF > 1 we advance the DR by step, if that is constant
    8445              :              and only aligned when performed VF times, DR alignment
    8446              :              analysis can analyze this as aligned since it assumes
    8447              :              contiguous accesses.  But that is not how we code generate
    8448              :              here, so adjust for this.  */
    8449         2426 :           if (maybe_gt (vf, 1u)
    8450         3736 :               && !multiple_p (DR_STEP_ALIGNMENT (first_dr_info->dr),
    8451         3510 :                               DR_TARGET_ALIGNMENT (first_dr_info)))
    8452          226 :             mis_align = -1;
    8453         2426 :           dr_alignment_support dr_align
    8454         2426 :               = vect_supportable_dr_alignment (vinfo, dr_info, vectype,
    8455              :                                                mis_align);
    8456         2426 :           if (dr_align == dr_aligned
    8457         2426 :               || dr_align == dr_unaligned_supported)
    8458              :             {
    8459        28124 :               nstores = 1;
    8460        28124 :               lnel = const_nunits;
    8461        28124 :               ltype = vectype;
    8462        28124 :               lvectype = vectype;
    8463        28124 :               alignment_support_scheme = dr_align;
    8464        28124 :               misalignment = mis_align;
    8465              :             }
    8466              :         }
    8467        25698 :       else if (n > 1)
    8468              :         {
    8469         1932 :           nstores = const_nunits / n;
    8470         1932 :           lnel = n;
    8471         1932 :           ltype = build_vector_type (elem_type, n);
    8472         1932 :           lvectype = vectype;
    8473         1932 :           int mis_align = dr_misalignment (first_dr_info, ltype);
    8474         1932 :           if (maybe_gt (vf, 1u)
    8475         3864 :               && !multiple_p (DR_STEP_ALIGNMENT (first_dr_info->dr),
    8476         3048 :                               DR_TARGET_ALIGNMENT (first_dr_info)))
    8477          816 :             mis_align = -1;
    8478         1932 :           dr_alignment_support dr_align
    8479         1932 :             = vect_supportable_dr_alignment (vinfo, dr_info, ltype,
    8480              :                                              mis_align);
    8481         1932 :           alignment_support_scheme = dr_align;
    8482         1932 :           misalignment = mis_align;
    8483              : 
    8484              :           /* First check if vec_extract optab doesn't support extraction
    8485              :              of vector elts directly.  */
    8486         1932 :           scalar_mode elmode = SCALAR_TYPE_MODE (elem_type);
    8487         1932 :           machine_mode vmode;
    8488         3864 :           if (!VECTOR_MODE_P (TYPE_MODE (vectype))
    8489         2160 :               || !related_vector_mode (TYPE_MODE (vectype), elmode,
    8490         1932 :                                        n).exists (&vmode)
    8491         1756 :               || (convert_optab_handler (vec_extract_optab,
    8492         1756 :                                          TYPE_MODE (vectype), vmode)
    8493              :                   == CODE_FOR_nothing)
    8494         1932 :               || !(dr_align == dr_aligned
    8495          228 :                    || dr_align == dr_unaligned_supported))
    8496              :             {
    8497              :               /* Try to avoid emitting an extract of vector elements
    8498              :                  by performing the extracts using an integer type of the
    8499              :                  same size, extracting from a vector of those and then
    8500              :                  re-interpreting it as the original vector type if
    8501              :                  supported.  */
    8502         1704 :               unsigned lsize = n * GET_MODE_BITSIZE (elmode);
    8503         1704 :               unsigned int lnunits = const_nunits / n;
    8504              :               /* If we can't construct such a vector fall back to
    8505              :                  element extracts from the original vector type and
    8506              :                  element size stores.  */
    8507         1704 :               if (int_mode_for_size (lsize, 0).exists (&elmode)
    8508         1704 :                   && VECTOR_MODE_P (TYPE_MODE (vectype))
    8509         1704 :                   && related_vector_mode (TYPE_MODE (vectype), elmode,
    8510         1704 :                                           lnunits).exists (&vmode)
    8511         1670 :                   && (convert_optab_handler (vec_extract_optab,
    8512              :                                              vmode, elmode)
    8513              :                       != CODE_FOR_nothing))
    8514              :                 {
    8515         1670 :                   nstores = lnunits;
    8516         1670 :                   lnel = n;
    8517         1670 :                   ltype = build_nonstandard_integer_type (lsize, 1);
    8518         1670 :                   lvectype = build_vector_type (ltype, nstores);
    8519              :                 }
    8520              :               /* Else fall back to vector extraction anyway.
    8521              :                  Fewer stores are more important than avoiding spilling
    8522              :                  of the vector we extract from.  Compared to the
    8523              :                  construction case in vectorizable_load no store-forwarding
    8524              :                  issue exists here for reasonable archs.  But only
    8525              :                  if the store is supported.  */
    8526           34 :                  else if (!(dr_align == dr_aligned
    8527           34 :                             || dr_align == dr_unaligned_supported))
    8528              :                    {
    8529              :                      nstores = const_nunits;
    8530              :                      lnel = 1;
    8531              :                      ltype = elem_type;
    8532              :                      lvectype = vectype;
    8533              :                    }
    8534              :             }
    8535              :         }
    8536        28124 :       unsigned align;
    8537        28124 :       if (alignment_support_scheme == dr_aligned)
    8538          930 :         align = known_alignment (DR_TARGET_ALIGNMENT (first_dr_info));
    8539              :       else
    8540        27194 :         align = dr_alignment (vect_dr_behavior (vinfo, first_dr_info));
    8541              :       /* Alignment is at most the access size if we do multiple stores.  */
    8542        28124 :       if (nstores > 1)
    8543        25698 :         align = MIN (tree_to_uhwi (TYPE_SIZE_UNIT (ltype)), align);
    8544        28124 :       ltype = build_aligned_type (ltype, align * BITS_PER_UNIT);
    8545        28124 :       int ncopies = vec_num;
    8546              : 
    8547        28124 :       if (!costing_p)
    8548              :         {
    8549         3517 :           ivstep = stride_step;
    8550         3517 :           ivstep = fold_build2 (MULT_EXPR, TREE_TYPE (ivstep), ivstep,
    8551              :                                 build_int_cst (TREE_TYPE (ivstep), vf));
    8552              : 
    8553         3517 :           standard_iv_increment_position (loop, &incr_gsi, &insert_after);
    8554              : 
    8555         3517 :           stride_base = cse_and_gimplify_to_preheader (loop_vinfo, stride_base);
    8556         3517 :           ivstep = cse_and_gimplify_to_preheader (loop_vinfo, ivstep);
    8557         3517 :           create_iv (stride_base, PLUS_EXPR, ivstep, NULL, loop, &incr_gsi,
    8558              :                      insert_after, &offvar, NULL);
    8559              : 
    8560         3517 :           stride_step = cse_and_gimplify_to_preheader (loop_vinfo, stride_step);
    8561              :         }
    8562              : 
    8563        28124 :       alias_off = build_int_cst (ref_type, 0);
    8564        28124 :       auto_vec<tree> vec_oprnds;
    8565              :       /* For costing some adjacent vector stores, we'd like to cost with
    8566              :          the total number of them once instead of cost each one by one. */
    8567        28124 :       unsigned int n_adjacent_stores = 0;
    8568        28124 :       running_off = offvar;
    8569        28124 :       if (!costing_p)
    8570         3517 :         vect_get_slp_defs (op_node, &vec_oprnds);
    8571        28124 :       unsigned int group_el = 0;
    8572        28124 :       unsigned HOST_WIDE_INT elsz
    8573        28124 :         = tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (vectype)));
    8574        66679 :       for (j = 0; j < ncopies; j++)
    8575              :         {
    8576        38555 :           if (!costing_p)
    8577              :             {
    8578         5416 :               vec_oprnd = vec_oprnds[j];
    8579              :               /* Pun the vector to extract from if necessary.  */
    8580         5416 :               if (lvectype != vectype)
    8581              :                 {
    8582         1302 :                   tree tem = make_ssa_name (lvectype);
    8583         1302 :                   tree cvt = build1 (VIEW_CONVERT_EXPR, lvectype, vec_oprnd);
    8584         1302 :                   gimple *pun = gimple_build_assign (tem, cvt);
    8585         1302 :                   vect_finish_stmt_generation (vinfo, stmt_info, pun, gsi);
    8586         1302 :                   vec_oprnd = tem;
    8587              :                 }
    8588              :             }
    8589       173830 :           for (i = 0; i < nstores; i++)
    8590              :             {
    8591       135275 :               if (costing_p)
    8592              :                 {
    8593       118409 :                   n_adjacent_stores++;
    8594       118409 :                   continue;
    8595              :                 }
    8596        16866 :               tree newref, newoff;
    8597        16866 :               gimple *incr, *assign;
    8598        16866 :               tree size = TYPE_SIZE (ltype);
    8599              :               /* Extract the i'th component.  */
    8600        16866 :               tree pos = fold_build2 (MULT_EXPR, bitsizetype,
    8601              :                                       bitsize_int (i), size);
    8602        16866 :               tree elem = fold_build3 (BIT_FIELD_REF, ltype, vec_oprnd,
    8603              :                                        size, pos);
    8604              : 
    8605        16866 :               elem = force_gimple_operand_gsi (gsi, elem, true, NULL_TREE, true,
    8606              :                                                GSI_SAME_STMT);
    8607              : 
    8608        16866 :               tree this_off = build_int_cst (TREE_TYPE (alias_off),
    8609        16866 :                                              group_el * elsz);
    8610        16866 :               newref = build2 (MEM_REF, ltype, running_off, this_off);
    8611        16866 :               vect_copy_ref_info (newref, DR_REF (first_dr_info->dr));
    8612              : 
    8613              :               /* And store it to *running_off.  */
    8614        16866 :               assign = gimple_build_assign (newref, elem);
    8615        16866 :               vect_finish_stmt_generation (vinfo, stmt_info, assign, gsi);
    8616              : 
    8617        16866 :               group_el += lnel;
    8618        16866 :               if (group_el == group_size)
    8619              :                 {
    8620        15143 :                   newoff = copy_ssa_name (running_off, NULL);
    8621        15143 :                   incr = gimple_build_assign (newoff, POINTER_PLUS_EXPR,
    8622              :                                               running_off, stride_step);
    8623        15143 :                   vect_finish_stmt_generation (vinfo, stmt_info, incr, gsi);
    8624              : 
    8625        15143 :                   running_off = newoff;
    8626        15143 :                   group_el = 0;
    8627              :                 }
    8628              :             }
    8629              :         }
    8630              : 
    8631        28124 :       if (costing_p)
    8632              :         {
    8633        24607 :           if (n_adjacent_stores > 0)
    8634              :             {
    8635              :               /* Take a single lane vector type store as scalar
    8636              :                  store to avoid ICE like 110776.  */
    8637        24607 :               if (VECTOR_TYPE_P (ltype)
    8638        24607 :                   && maybe_ne (TYPE_VECTOR_SUBPARTS (ltype), 1U))
    8639         1197 :                 vect_get_store_cost (vinfo, stmt_info, slp_node,
    8640              :                                      n_adjacent_stores, alignment_support_scheme,
    8641              :                                      misalignment, &inside_cost, cost_vec);
    8642              :               else
    8643        23410 :                 inside_cost
    8644        23410 :                   += record_stmt_cost (cost_vec, n_adjacent_stores,
    8645              :                                        scalar_store, slp_node, 0, vect_body);
    8646              :               /* Only need vector extracting when there are more
    8647              :                  than one stores.  */
    8648        24607 :               if (nstores > 1)
    8649        23021 :                 inside_cost
    8650        23021 :                   += record_stmt_cost (cost_vec, n_adjacent_stores,
    8651              :                                        vec_to_scalar, slp_node, 0, vect_body);
    8652              :             }
    8653        24607 :           if (dump_enabled_p ())
    8654          673 :             dump_printf_loc (MSG_NOTE, vect_location,
    8655              :                              "vect_model_store_cost: inside_cost = %d, "
    8656              :                              "prologue_cost = %d .\n",
    8657              :                              inside_cost, prologue_cost);
    8658              :         }
    8659              : 
    8660        28124 :       return true;
    8661        28124 :     }
    8662              : 
    8663      1286754 :   gcc_assert (alignment_support_scheme);
    8664      1286754 :   vec_loop_masks *loop_masks
    8665       158254 :     = (loop_vinfo && LOOP_VINFO_FULLY_MASKED_P (loop_vinfo)
    8666      1286754 :        ? &LOOP_VINFO_MASKS (loop_vinfo)
    8667           11 :        : NULL);
    8668           11 :   vec_loop_lens *loop_lens
    8669       158254 :     = (loop_vinfo && LOOP_VINFO_FULLY_WITH_LENGTH_P (loop_vinfo)
    8670              :        ? &LOOP_VINFO_LENS (loop_vinfo)
    8671            0 :        : NULL);
    8672              : 
    8673              :   /* The vect_transform_stmt and vect_analyze_stmt will go here but there
    8674              :      are some difference here.  We cannot enable both the lens and masks
    8675              :      during transform but it is allowed during analysis.
    8676              :      Shouldn't go with length-based approach if fully masked.  */
    8677      1286754 :   if (cost_vec == NULL)
    8678              :     /* The cost_vec is NULL during transfrom.  */
    8679       539658 :     gcc_assert ((!loop_lens || !loop_masks));
    8680              : 
    8681              :   /* Targets with store-lane instructions must not require explicit
    8682              :      realignment.  vect_supportable_dr_alignment always returns either
    8683              :      dr_aligned or dr_unaligned_supported for masked operations.  */
    8684      1286754 :   gcc_assert ((memory_access_type != VMAT_LOAD_STORE_LANES
    8685              :                && !mask_node
    8686              :                && !loop_masks)
    8687              :               || alignment_support_scheme == dr_aligned
    8688              :               || alignment_support_scheme == dr_unaligned_supported);
    8689              : 
    8690      1286754 :   tree offset = NULL_TREE;
    8691      1286754 :   if (!known_eq (poffset, 0))
    8692         4066 :     offset = size_int (poffset);
    8693              : 
    8694      1286754 :   tree bump;
    8695      1286754 :   tree vec_offset = NULL_TREE;
    8696      1286754 :   if (STMT_VINFO_GATHER_SCATTER_P (stmt_info))
    8697              :     {
    8698         1366 :       aggr_type = NULL_TREE;
    8699         1366 :       bump = NULL_TREE;
    8700              :     }
    8701      1285388 :   else if (mat_gather_scatter_p (memory_access_type))
    8702              :     {
    8703            0 :       aggr_type = elem_type;
    8704            0 :       if (!costing_p)
    8705              :         {
    8706            0 :           tree vtype = ls.ls_type ? ls.ls_type : vectype;
    8707            0 :           vect_get_strided_load_store_ops (stmt_info, slp_node, vtype,
    8708              :                                            ls.strided_offset_vectype,
    8709              :                                            loop_vinfo, gsi,
    8710              :                                            &bump, &vec_offset, loop_lens);
    8711              :         }
    8712              :     }
    8713              :   else
    8714              :     {
    8715      1285388 :       if (memory_access_type == VMAT_LOAD_STORE_LANES)
    8716            0 :         aggr_type = build_array_type_nelts (elem_type, group_size * nunits);
    8717              :       else
    8718              :         aggr_type = vectype;
    8719      1285388 :       if (!costing_p)
    8720       539188 :         bump = vect_get_data_ptr_increment (vinfo, gsi, dr_info, aggr_type,
    8721              :                                             memory_access_type, loop_lens);
    8722              :     }
    8723              : 
    8724      1286754 :   if (loop_vinfo && mask_node && !costing_p)
    8725          550 :     LOOP_VINFO_HAS_MASK_STORE (loop_vinfo) = true;
    8726              : 
    8727              :   /* In case the vectorization factor (VF) is bigger than the number
    8728              :      of elements that we can fit in a vectype (nunits), we have to generate
    8729              :      more than one vector stmt - i.e - we need to "unroll" the
    8730              :      vector stmt by a factor VF/nunits.  */
    8731              : 
    8732      1286754 :   auto_vec<tree> dr_chain (group_size);
    8733      1286754 :   auto_vec<tree> vec_masks;
    8734      1286754 :   tree vec_mask = NULL;
    8735      1286754 :   auto_delete_vec<auto_vec<tree>> gvec_oprnds (group_size);
    8736      5842279 :   for (i = 0; i < group_size; i++)
    8737      3268771 :     gvec_oprnds.quick_push (new auto_vec<tree> ());
    8738              : 
    8739      1286754 :   if (memory_access_type == VMAT_LOAD_STORE_LANES)
    8740              :     {
    8741            0 :       const internal_fn lanes_ifn = ls.lanes_ifn;
    8742              : 
    8743            0 :       if (costing_p)
    8744              :         /* Update all incoming store operand nodes, the general handling
    8745              :            above only handles the mask and the first store operand node.  */
    8746            0 :         for (slp_tree child : SLP_TREE_CHILDREN (slp_node))
    8747            0 :           if (child != mask_node
    8748            0 :               && !vect_maybe_update_slp_op_vectype (child, vectype))
    8749              :             {
    8750            0 :               if (dump_enabled_p ())
    8751            0 :                 dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    8752              :                                  "incompatible vector types for invariants\n");
    8753            0 :               return false;
    8754              :             }
    8755            0 :       unsigned inside_cost = 0, prologue_cost = 0;
    8756              :       /* For costing some adjacent vector stores, we'd like to cost with
    8757              :          the total number of them once instead of cost each one by one. */
    8758            0 :       unsigned int n_adjacent_stores = 0;
    8759            0 :       int ncopies = vec_num / group_size;
    8760            0 :       for (j = 0; j < ncopies; j++)
    8761              :         {
    8762            0 :           if (j == 0)
    8763              :             {
    8764            0 :               if (!costing_p)
    8765              :                 {
    8766            0 :                   if (mask_node)
    8767              :                     {
    8768            0 :                       vect_get_slp_defs (mask_node, &vec_masks);
    8769            0 :                       vec_mask = vec_masks[0];
    8770              :                     }
    8771            0 :                   dataref_ptr
    8772            0 :                     = vect_create_data_ref_ptr (vinfo, first_stmt_info,
    8773              :                                                 aggr_type, NULL, offset, &dummy,
    8774              :                                                 gsi, &ptr_incr, false, bump);
    8775              :                 }
    8776              :             }
    8777            0 :           else if (!costing_p)
    8778              :             {
    8779            0 :               gcc_assert (!LOOP_VINFO_USING_SELECT_VL_P (loop_vinfo));
    8780            0 :               if (mask_node)
    8781            0 :                 vec_mask = vec_masks[j];
    8782            0 :               dataref_ptr = bump_vector_ptr (vinfo, dataref_ptr, ptr_incr, gsi,
    8783              :                                              stmt_info, bump);
    8784              :             }
    8785              : 
    8786            0 :           if (costing_p)
    8787              :             {
    8788            0 :               n_adjacent_stores += group_size;
    8789            0 :               continue;
    8790              :             }
    8791              : 
    8792              :           /* Get an array into which we can store the individual vectors.  */
    8793            0 :           tree vec_array = create_vector_array (vectype, group_size);
    8794              : 
    8795              :           /* Invalidate the current contents of VEC_ARRAY.  This should
    8796              :              become an RTL clobber too, which prevents the vector registers
    8797              :              from being upward-exposed.  */
    8798            0 :           vect_clobber_variable (vinfo, stmt_info, gsi, vec_array);
    8799              : 
    8800              :           /* Store the individual vectors into the array.  */
    8801            0 :           for (i = 0; i < group_size; i++)
    8802              :             {
    8803            0 :               slp_tree child;
    8804            0 :               if (i == 0 || !mask_node)
    8805            0 :                 child = SLP_TREE_CHILDREN (slp_node)[i];
    8806              :               else
    8807            0 :                 child = SLP_TREE_CHILDREN (slp_node)[i + 1];
    8808            0 :               vec_oprnd = SLP_TREE_VEC_DEFS (child)[j];
    8809            0 :               write_vector_array (vinfo, stmt_info, gsi, vec_oprnd, vec_array,
    8810              :                                   i);
    8811              :             }
    8812              : 
    8813            0 :           tree final_mask = NULL;
    8814            0 :           tree final_len = NULL;
    8815            0 :           tree bias = NULL;
    8816            0 :           if (loop_masks)
    8817            0 :             final_mask = vect_get_loop_mask (loop_vinfo, gsi, loop_masks,
    8818              :                                              ncopies, vectype, j);
    8819            0 :           if (vec_mask)
    8820            0 :             final_mask = prepare_vec_mask (loop_vinfo, mask_vectype, final_mask,
    8821              :                                            vec_mask, gsi);
    8822              : 
    8823            0 :           if (lanes_ifn == IFN_MASK_LEN_STORE_LANES)
    8824              :             {
    8825            0 :               if (loop_lens)
    8826            0 :                 final_len = vect_get_loop_len (loop_vinfo, gsi, loop_lens,
    8827              :                                                ncopies, vectype, j, 1, true);
    8828              :               else
    8829            0 :                 final_len = size_int (TYPE_VECTOR_SUBPARTS (vectype));
    8830            0 :               signed char biasval
    8831            0 :                 = LOOP_VINFO_PARTIAL_LOAD_STORE_BIAS (loop_vinfo);
    8832            0 :               bias = build_int_cst (intQI_type_node, biasval);
    8833            0 :               if (!final_mask)
    8834              :                 {
    8835            0 :                   mask_vectype = truth_type_for (vectype);
    8836            0 :                   final_mask = build_minus_one_cst (mask_vectype);
    8837              :                 }
    8838              :             }
    8839              : 
    8840            0 :           gcall *call;
    8841            0 :           if (final_len && final_mask)
    8842              :             {
    8843              :               /* Emit:
    8844              :                    MASK_LEN_STORE_LANES (DATAREF_PTR, ALIAS_PTR, VEC_MASK,
    8845              :                                          LEN, BIAS, VEC_ARRAY).  */
    8846            0 :               unsigned int align = TYPE_ALIGN (TREE_TYPE (vectype));
    8847            0 :               tree alias_ptr = build_int_cst (ref_type, align);
    8848            0 :               call = gimple_build_call_internal (IFN_MASK_LEN_STORE_LANES, 6,
    8849              :                                                  dataref_ptr, alias_ptr,
    8850              :                                                  final_mask, final_len, bias,
    8851              :                                                  vec_array);
    8852              :             }
    8853            0 :           else if (final_mask)
    8854              :             {
    8855              :               /* Emit:
    8856              :                    MASK_STORE_LANES (DATAREF_PTR, ALIAS_PTR, VEC_MASK,
    8857              :                                      VEC_ARRAY).  */
    8858            0 :               unsigned int align = TYPE_ALIGN (TREE_TYPE (vectype));
    8859            0 :               tree alias_ptr = build_int_cst (ref_type, align);
    8860            0 :               call = gimple_build_call_internal (IFN_MASK_STORE_LANES, 4,
    8861              :                                                  dataref_ptr, alias_ptr,
    8862              :                                                  final_mask, vec_array);
    8863              :             }
    8864              :           else
    8865              :             {
    8866              :               /* Emit:
    8867              :                    MEM_REF[...all elements...] = STORE_LANES (VEC_ARRAY).  */
    8868            0 :               data_ref = create_array_ref (aggr_type, dataref_ptr, ref_type);
    8869            0 :               call = gimple_build_call_internal (IFN_STORE_LANES, 1, vec_array);
    8870            0 :               gimple_call_set_lhs (call, data_ref);
    8871              :             }
    8872            0 :           gimple_call_set_nothrow (call, true);
    8873            0 :           vect_finish_stmt_generation (vinfo, stmt_info, call, gsi);
    8874              : 
    8875              :           /* Record that VEC_ARRAY is now dead.  */
    8876            0 :           vect_clobber_variable (vinfo, stmt_info, gsi, vec_array);
    8877              :         }
    8878              : 
    8879            0 :       if (costing_p)
    8880              :         {
    8881            0 :           if (n_adjacent_stores > 0)
    8882            0 :             vect_get_store_cost (vinfo, stmt_info, slp_node, n_adjacent_stores,
    8883              :                                  alignment_support_scheme, misalignment,
    8884              :                                  &inside_cost, cost_vec);
    8885            0 :           if (dump_enabled_p ())
    8886            0 :             dump_printf_loc (MSG_NOTE, vect_location,
    8887              :                              "vect_model_store_cost: inside_cost = %d, "
    8888              :                              "prologue_cost = %d .\n",
    8889              :                              inside_cost, prologue_cost);
    8890              :         }
    8891              : 
    8892            0 :       return true;
    8893              :     }
    8894              : 
    8895      1286754 :   if (mat_gather_scatter_p (memory_access_type))
    8896              :     {
    8897         1366 :       gcc_assert (!grouped_store || ls.ls_type);
    8898         1366 :       if (ls.ls_type)
    8899            0 :         vectype = ls.ls_type;
    8900         1366 :       auto_vec<tree> vec_offsets;
    8901         1366 :       unsigned int inside_cost = 0, prologue_cost = 0;
    8902         1366 :       int num_stmts = vec_num;
    8903         3124 :       for (j = 0; j < num_stmts; j++)
    8904              :         {
    8905         1758 :           gimple *new_stmt;
    8906         1758 :           if (j == 0)
    8907              :             {
    8908         1366 :               if (costing_p && vls_type == VLS_STORE_INVARIANT)
    8909          210 :                 prologue_cost += record_stmt_cost (cost_vec, 1, scalar_to_vec,
    8910              :                                                    slp_node, 0, vect_prologue);
    8911              :               else if (!costing_p)
    8912              :                 {
    8913              :                   /* Since the store is not grouped, DR_GROUP_SIZE is 1, and
    8914              :                      DR_CHAIN is of size 1.  */
    8915          470 :                   gcc_assert (group_size == 1);
    8916          470 :                   vect_get_slp_defs (op_node, gvec_oprnds[0]);
    8917          470 :                   if (mask_node)
    8918           70 :                     vect_get_slp_defs (mask_node, &vec_masks);
    8919              : 
    8920          470 :                   if (STMT_VINFO_GATHER_SCATTER_P (stmt_info))
    8921          470 :                     vect_get_gather_scatter_ops (loop, slp_node,
    8922              :                                                  &dataref_ptr, &vec_offsets);
    8923              :                   else
    8924            0 :                     dataref_ptr
    8925            0 :                       = vect_create_data_ref_ptr (vinfo, first_stmt_info,
    8926              :                                                   aggr_type, NULL, offset,
    8927              :                                                   &dummy, gsi, &ptr_incr, false,
    8928              :                                                   bump);
    8929              :                 }
    8930              :             }
    8931          392 :           else if (!costing_p)
    8932              :             {
    8933           34 :               gcc_assert (!LOOP_VINFO_USING_SELECT_VL_P (loop_vinfo));
    8934           34 :               if (!STMT_VINFO_GATHER_SCATTER_P (stmt_info))
    8935            0 :                 dataref_ptr = bump_vector_ptr (vinfo, dataref_ptr, ptr_incr,
    8936              :                                                gsi, stmt_info, bump);
    8937              :             }
    8938              : 
    8939         2472 :           new_stmt = NULL;
    8940          714 :           if (!costing_p)
    8941              :             {
    8942          504 :               vec_oprnd = (*gvec_oprnds[0])[j];
    8943          504 :               if (mask_node)
    8944           90 :                 vec_mask = vec_masks[j];
    8945              :               /* We should have caught mismatched types earlier.  */
    8946          504 :               gcc_assert (ls.ls_type
    8947              :                           || useless_type_conversion_p
    8948              :                           (vectype, TREE_TYPE (vec_oprnd)));
    8949              :             }
    8950          504 :           tree final_mask = NULL_TREE;
    8951         2262 :           tree final_len = NULL_TREE;
    8952         2262 :           tree bias = NULL_TREE;
    8953          504 :           if (!costing_p)
    8954              :             {
    8955          504 :               if (loop_masks)
    8956            0 :                 final_mask = vect_get_loop_mask (loop_vinfo, gsi,
    8957              :                                                  loop_masks, num_stmts,
    8958              :                                                  vectype, j);
    8959          504 :               if (vec_mask)
    8960           90 :                 final_mask = prepare_vec_mask (loop_vinfo, mask_vectype,
    8961              :                                                final_mask, vec_mask, gsi);
    8962              :             }
    8963              : 
    8964         1758 :           unsigned align = get_object_alignment (DR_REF (first_dr_info->dr));
    8965         1758 :           tree alias_align_ptr = build_int_cst (ref_type, align);
    8966         1758 :           if (memory_access_type == VMAT_GATHER_SCATTER_IFN)
    8967              :             {
    8968            0 :               if (costing_p)
    8969              :                 {
    8970            0 :                   if (ls.supported_offset_vectype)
    8971            0 :                     inside_cost
    8972            0 :                       += record_stmt_cost (cost_vec, 1, vector_stmt,
    8973              :                                            slp_node, 0, vect_body);
    8974            0 :                   if (ls.supported_scale)
    8975            0 :                     inside_cost
    8976            0 :                       += record_stmt_cost (cost_vec, 1, vector_stmt,
    8977              :                                            slp_node, 0, vect_body);
    8978              : 
    8979            0 :                   unsigned int cnunits = vect_nunits_for_cost (vectype);
    8980            0 :                   inside_cost
    8981            0 :                     += record_stmt_cost (cost_vec, cnunits, scalar_store,
    8982              :                                          slp_node, 0, vect_body);
    8983         1758 :                   continue;
    8984            0 :                 }
    8985              : 
    8986            0 :               if (STMT_VINFO_GATHER_SCATTER_P (stmt_info))
    8987            0 :                 vec_offset = vec_offsets[j];
    8988              : 
    8989            0 :               tree scale = size_int (SLP_TREE_GS_SCALE (slp_node));
    8990            0 :               bool strided = !VECTOR_TYPE_P (TREE_TYPE (vec_offset));
    8991              : 
    8992              :               /* Perform the offset conversion and scaling if necessary.  */
    8993            0 :               if (!strided
    8994            0 :                   && (ls.supported_offset_vectype || ls.supported_scale))
    8995              :                 {
    8996            0 :                   gimple_seq stmts = NULL;
    8997            0 :                   if (ls.supported_offset_vectype)
    8998            0 :                     vec_offset = gimple_convert
    8999            0 :                       (&stmts, ls.supported_offset_vectype, vec_offset);
    9000            0 :                   if (ls.supported_scale)
    9001              :                     {
    9002              :                       /* Only scale the vec_offset if we haven't already.  */
    9003            0 :                       if (STMT_VINFO_GATHER_SCATTER_P (stmt_info)
    9004            0 :                           || j == 0)
    9005              :                         {
    9006            0 :                           tree mult_cst = build_int_cst
    9007            0 :                             (TREE_TYPE (TREE_TYPE (vec_offset)),
    9008            0 :                              SLP_TREE_GS_SCALE (slp_node) / ls.supported_scale);
    9009            0 :                           tree mult = build_vector_from_val
    9010            0 :                             (TREE_TYPE (vec_offset), mult_cst);
    9011            0 :                           vec_offset = gimple_build
    9012            0 :                             (&stmts, MULT_EXPR, TREE_TYPE (vec_offset),
    9013              :                              vec_offset, mult);
    9014              :                         }
    9015            0 :                       scale = size_int (ls.supported_scale);
    9016              :                     }
    9017            0 :                   gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
    9018              :                 }
    9019              : 
    9020            0 :               if (ls.gs.ifn == IFN_MASK_LEN_SCATTER_STORE)
    9021              :                 {
    9022            0 :                   if (loop_lens)
    9023            0 :                     final_len = vect_get_loop_len (loop_vinfo, gsi,
    9024              :                                                    loop_lens, num_stmts,
    9025              :                                                    vectype, j, 1, true);
    9026              :                   else
    9027            0 :                     final_len = size_int (TYPE_VECTOR_SUBPARTS (vectype));
    9028              : 
    9029            0 :                   signed char biasval
    9030            0 :                     = LOOP_VINFO_PARTIAL_LOAD_STORE_BIAS (loop_vinfo);
    9031            0 :                   bias = build_int_cst (intQI_type_node, biasval);
    9032            0 :                   if (!final_mask)
    9033              :                     {
    9034            0 :                       mask_vectype = truth_type_for (vectype);
    9035            0 :                       final_mask = build_minus_one_cst (mask_vectype);
    9036              :                     }
    9037              :                 }
    9038              : 
    9039            0 :               if (ls.ls_type)
    9040              :                 {
    9041            0 :                   gimple *conv_stmt
    9042            0 :                     = gimple_build_assign (make_ssa_name (vectype),
    9043              :                                            VIEW_CONVERT_EXPR,
    9044              :                                            build1 (VIEW_CONVERT_EXPR, vectype,
    9045              :                                                    vec_oprnd));
    9046            0 :                   vect_finish_stmt_generation (vinfo, stmt_info, conv_stmt,
    9047              :                                                gsi);
    9048            0 :                   vec_oprnd = gimple_get_lhs (conv_stmt);
    9049              :                 }
    9050              : 
    9051            0 :               gcall *call;
    9052            0 :               if (final_len && final_mask)
    9053              :                 {
    9054            0 :                   if (VECTOR_TYPE_P (TREE_TYPE (vec_offset)))
    9055            0 :                     call = gimple_build_call_internal (
    9056              :                             IFN_MASK_LEN_SCATTER_STORE, 8, dataref_ptr,
    9057              :                             alias_align_ptr,
    9058              :                             vec_offset, scale, vec_oprnd, final_mask, final_len,
    9059              :                             bias);
    9060              :                   else
    9061              :                     /* Non-vector offset indicates that prefer to take
    9062              :                        MASK_LEN_STRIDED_STORE instead of the
    9063              :                        IFN_MASK_SCATTER_STORE with direct stride arg.
    9064              :                        Similar to the gather case we have checked the
    9065              :                        alignment for a scatter already and assume
    9066              :                        that the strided store has the same requirements.  */
    9067            0 :                     call = gimple_build_call_internal (
    9068              :                             IFN_MASK_LEN_STRIDED_STORE, 6, dataref_ptr,
    9069              :                             vec_offset, vec_oprnd, final_mask, final_len, bias);
    9070              :                 }
    9071            0 :               else if (final_mask)
    9072            0 :                 call = gimple_build_call_internal
    9073            0 :                              (IFN_MASK_SCATTER_STORE, 6, dataref_ptr,
    9074              :                               alias_align_ptr,
    9075              :                               vec_offset, scale, vec_oprnd, final_mask);
    9076              :               else
    9077            0 :                 call = gimple_build_call_internal (IFN_SCATTER_STORE, 5,
    9078              :                                                    dataref_ptr,
    9079              :                                                    alias_align_ptr,
    9080              :                                                    vec_offset,
    9081              :                                                    scale, vec_oprnd);
    9082            0 :               gimple_call_set_nothrow (call, true);
    9083            0 :               vect_finish_stmt_generation (vinfo, stmt_info, call, gsi);
    9084            0 :               new_stmt = call;
    9085              :             }
    9086         1758 :           else if (memory_access_type == VMAT_GATHER_SCATTER_LEGACY)
    9087              :             {
    9088              :               /* The builtin decls path for scatter is legacy, x86 only.  */
    9089          310 :               gcc_assert (nunits.is_constant ()
    9090              :                           && (!final_mask
    9091              :                               || SCALAR_INT_MODE_P
    9092              :                                    (TYPE_MODE (TREE_TYPE (final_mask)))));
    9093          310 :               if (costing_p)
    9094              :                 {
    9095          179 :                   unsigned int cnunits = vect_nunits_for_cost (vectype);
    9096          179 :                   inside_cost
    9097          179 :                     += record_stmt_cost (cost_vec, cnunits, scalar_store,
    9098              :                                          slp_node, 0, vect_body);
    9099          179 :                   continue;
    9100          179 :                 }
    9101              : 
    9102          131 :                 tree offset_vectype = TREE_TYPE (vec_offsets[0]);
    9103          131 :                 poly_uint64 offset_nunits
    9104          131 :                   = TYPE_VECTOR_SUBPARTS (offset_vectype);
    9105          131 :                 if (known_eq (nunits, offset_nunits))
    9106              :                   {
    9107           55 :                     new_stmt = vect_build_one_scatter_store_call
    9108          110 :                                    (vinfo, stmt_info, slp_node, gsi,
    9109           55 :                                     ls.gs.decl, dataref_ptr, vec_offsets[j],
    9110              :                                     vec_oprnd, final_mask);
    9111           55 :                     vect_finish_stmt_generation (vinfo, stmt_info,
    9112              :                                                  new_stmt, gsi);
    9113              :                   }
    9114           76 :                 else if (known_eq (nunits, offset_nunits * 2))
    9115              :                   {
    9116              :                     /* We have a offset vector with half the number of
    9117              :                        lanes but the builtins will store full vectype
    9118              :                        data from the lower lanes.  */
    9119           30 :                     new_stmt = vect_build_one_scatter_store_call
    9120           60 :                                    (vinfo, stmt_info, slp_node, gsi, ls.gs.decl,
    9121           30 :                                     dataref_ptr, vec_offsets[2 * j],
    9122              :                                     vec_oprnd, final_mask);
    9123           30 :                     vect_finish_stmt_generation (vinfo, stmt_info,
    9124              :                                                    new_stmt, gsi);
    9125           30 :                     int count = nunits.to_constant ();
    9126           30 :                     vec_perm_builder sel (count, count, 1);
    9127           30 :                     sel.quick_grow (count);
    9128          382 :                     for (int i = 0; i < count; ++i)
    9129          352 :                       sel[i] = i | (count / 2);
    9130           30 :                     vec_perm_indices indices (sel, 2, count);
    9131           30 :                     tree perm_mask
    9132           30 :                       = vect_gen_perm_mask_checked (vectype, indices);
    9133           30 :                     new_stmt = gimple_build_assign (NULL_TREE, VEC_PERM_EXPR,
    9134              :                                                     vec_oprnd, vec_oprnd,
    9135              :                                                     perm_mask);
    9136           30 :                     vec_oprnd = make_ssa_name (vectype);
    9137           30 :                     gimple_set_lhs (new_stmt, vec_oprnd);
    9138           30 :                     vect_finish_stmt_generation (vinfo, stmt_info,
    9139              :                                                  new_stmt, gsi);
    9140           30 :                     if (final_mask)
    9141              :                       {
    9142           20 :                         new_stmt = gimple_build_assign (NULL_TREE,
    9143              :                                                         VEC_UNPACK_HI_EXPR,
    9144              :                                                         final_mask);
    9145           20 :                         final_mask = make_ssa_name
    9146           20 :                                       (truth_type_for (offset_vectype));
    9147           20 :                         gimple_set_lhs (new_stmt, final_mask);
    9148           20 :                         vect_finish_stmt_generation (vinfo, stmt_info,
    9149              :                                                      new_stmt, gsi);
    9150              :                         }
    9151              : 
    9152           30 :                     new_stmt = vect_build_one_scatter_store_call
    9153           60 :                                   (vinfo, stmt_info, slp_node, gsi, ls.gs.decl,
    9154           30 :                                    dataref_ptr, vec_offsets[2 * j + 1],
    9155              :                                    vec_oprnd, final_mask);
    9156           30 :                     vect_finish_stmt_generation (vinfo, stmt_info,
    9157              :                                                  new_stmt, gsi);
    9158           30 :                   }
    9159           46 :                 else if (known_eq (nunits * 2, offset_nunits))
    9160              :                   {
    9161              :                     /* We have a offset vector with double the number of
    9162              :                        lanes.  Select the low/high part accordingly.  */
    9163           46 :                     vec_offset = vec_offsets[j / 2];
    9164           46 :                     if (j & 1)
    9165              :                       {
    9166           23 :                         int count = offset_nunits.to_constant ();
    9167           23 :                         vec_perm_builder sel (count, count, 1);
    9168           23 :                         sel.quick_grow (count);
    9169          263 :                         for (int i = 0; i < count; ++i)
    9170          240 :                           sel[i] = i | (count / 2);
    9171           23 :                         vec_perm_indices indices (sel, 2, count);
    9172           23 :                         tree perm_mask = vect_gen_perm_mask_checked
    9173           23 :                                            (TREE_TYPE (vec_offset), indices);
    9174           23 :                         new_stmt = gimple_build_assign (NULL_TREE,
    9175              :                                                         VEC_PERM_EXPR,
    9176              :                                                         vec_offset,
    9177              :                                                         vec_offset,
    9178              :                                                         perm_mask);
    9179           23 :                         vec_offset = make_ssa_name (TREE_TYPE (vec_offset));
    9180           23 :                         gimple_set_lhs (new_stmt, vec_offset);
    9181           23 :                         vect_finish_stmt_generation (vinfo, stmt_info,
    9182              :                                                      new_stmt, gsi);
    9183           23 :                       }
    9184              : 
    9185           46 :                     new_stmt = vect_build_one_scatter_store_call
    9186           46 :                                    (vinfo, stmt_info, slp_node, gsi,
    9187              :                                     ls.gs.decl, dataref_ptr, vec_offset,
    9188              :                                     vec_oprnd, final_mask);
    9189           46 :                     vect_finish_stmt_generation (vinfo, stmt_info,
    9190              :                                                  new_stmt, gsi);
    9191              :                   }
    9192              :                 else
    9193            0 :                   gcc_unreachable ();
    9194              :             }
    9195              :           else
    9196              :             {
    9197              :               /* Emulated scatter.  */
    9198         1448 :               gcc_assert (!final_mask);
    9199         1448 :               if (costing_p)
    9200              :                 {
    9201         1075 :                   unsigned int cnunits = vect_nunits_for_cost (vectype);
    9202              :                   /* For emulated scatter N offset vector element extracts
    9203              :                      (we assume the scalar scaling and ptr + offset add is
    9204              :                      consumed by the load).  */
    9205         1075 :                   inside_cost
    9206         1075 :                     += record_stmt_cost (cost_vec, cnunits, vec_to_scalar,
    9207              :                                          slp_node, 0, vect_body);
    9208              :                   /* N scalar stores plus extracting the elements.  */
    9209         1075 :                   inside_cost
    9210         1075 :                     += record_stmt_cost (cost_vec, cnunits, vec_to_scalar,
    9211              :                                          slp_node, 0, vect_body);
    9212         1075 :                   inside_cost
    9213         1075 :                     += record_stmt_cost (cost_vec, cnunits, scalar_store,
    9214              :                                          slp_node, 0, vect_body);
    9215         1075 :                   continue;
    9216         1075 :                 }
    9217              : 
    9218          373 :               tree offset_vectype = TREE_TYPE (vec_offsets[0]);
    9219          373 :               unsigned HOST_WIDE_INT const_nunits = nunits.to_constant ();
    9220          373 :               unsigned HOST_WIDE_INT const_offset_nunits
    9221          373 :                 = TYPE_VECTOR_SUBPARTS (offset_vectype).to_constant ();
    9222          373 :               vec<constructor_elt, va_gc> *ctor_elts;
    9223          373 :               vec_alloc (ctor_elts, const_nunits);
    9224          373 :               gimple_seq stmts = NULL;
    9225          373 :               tree elt_type = TREE_TYPE (vectype);
    9226          373 :               unsigned HOST_WIDE_INT elt_size
    9227          373 :                 = tree_to_uhwi (TYPE_SIZE (elt_type));
    9228              :               /* We support offset vectors with more elements
    9229              :                  than the data vector for now.  */
    9230          373 :               unsigned HOST_WIDE_INT factor
    9231              :                 = const_offset_nunits / const_nunits;
    9232          373 :               vec_offset = vec_offsets[j / factor];
    9233          373 :               unsigned elt_offset
    9234          373 :                 = (j % factor) * const_nunits;
    9235          373 :               tree idx_type = TREE_TYPE (TREE_TYPE (vec_offset));
    9236          373 :               tree scale = size_int (SLP_TREE_GS_SCALE (slp_node));
    9237          373 :               tree ltype = build_aligned_type (TREE_TYPE (vectype), align);
    9238         1519 :               for (unsigned k = 0; k < const_nunits; ++k)
    9239              :                 {
    9240              :                   /* Compute the offsetted pointer.  */
    9241         1146 :                   tree boff = size_binop (MULT_EXPR, TYPE_SIZE (idx_type),
    9242              :                                           bitsize_int (k + elt_offset));
    9243         1146 :                   tree idx
    9244         2292 :                     = gimple_build (&stmts, BIT_FIELD_REF, idx_type,
    9245         1146 :                                     vec_offset, TYPE_SIZE (idx_type), boff);
    9246         1146 :                   idx = gimple_convert (&stmts, sizetype, idx);
    9247         1146 :                   idx = gimple_build (&stmts, MULT_EXPR, sizetype,
    9248              :                                       idx, scale);
    9249         1146 :                   tree ptr
    9250         1146 :                     = gimple_build (&stmts, PLUS_EXPR,
    9251         1146 :                                     TREE_TYPE (dataref_ptr),
    9252              :                                     dataref_ptr, idx);
    9253         1146 :                   ptr = gimple_convert (&stmts, ptr_type_node, ptr);
    9254              :                   /* Extract the element to be stored.  */
    9255         1146 :                   tree elt
    9256         2292 :                     = gimple_build (&stmts, BIT_FIELD_REF,
    9257         1146 :                                     TREE_TYPE (vectype),
    9258         1146 :                                     vec_oprnd, TYPE_SIZE (elt_type),
    9259         1146 :                                     bitsize_int (k * elt_size));
    9260         1146 :                   gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
    9261         1146 :                   stmts = NULL;
    9262         1146 :                   tree ref
    9263         1146 :                     = build2 (MEM_REF, ltype, ptr,
    9264              :                               build_int_cst (ref_type, 0));
    9265         1146 :                   new_stmt = gimple_build_assign (ref, elt);
    9266         1146 :                   vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    9267              :                 }
    9268              : 
    9269          373 :               slp_node->push_vec_def (new_stmt);
    9270              :             }
    9271              :         }
    9272              : 
    9273         1366 :       if (costing_p && dump_enabled_p ())
    9274           68 :         dump_printf_loc (MSG_NOTE, vect_location,
    9275              :                          "vect_model_store_cost: inside_cost = %d, "
    9276              :                          "prologue_cost = %d .\n",
    9277              :                          inside_cost, prologue_cost);
    9278              : 
    9279         1366 :       return true;
    9280         1366 :     }
    9281              : 
    9282      1285388 :   gcc_assert (memory_access_type == VMAT_CONTIGUOUS
    9283              :               || memory_access_type == VMAT_CONTIGUOUS_DOWN
    9284              :               || memory_access_type == VMAT_CONTIGUOUS_REVERSE);
    9285              : 
    9286      1285388 :   unsigned inside_cost = 0, prologue_cost = 0;
    9287              :   /* For costing some adjacent vector stores, we'd like to cost with
    9288              :      the total number of them once instead of cost each one by one. */
    9289      1285388 :   unsigned int n_adjacent_stores = 0;
    9290      1285388 :   auto_vec<tree> result_chain (group_size);
    9291      1285388 :   auto_vec<tree, 1> vec_oprnds;
    9292      1285388 :   gimple *new_stmt;
    9293      1285388 :   if (!costing_p)
    9294              :     {
    9295              :       /* Get vectorized arguments for SLP_NODE.  */
    9296       539188 :       vect_get_slp_defs (op_node, &vec_oprnds);
    9297       539188 :       vec_oprnd = vec_oprnds[0];
    9298       539188 :       if (mask_node)
    9299              :         {
    9300          481 :           vect_get_slp_defs (mask_node, &vec_masks);
    9301          481 :           vec_mask = vec_masks[0];
    9302              :         }
    9303              :     }
    9304              : 
    9305              :   /* We should have caught mismatched types earlier.  */
    9306       539188 :   gcc_assert (costing_p
    9307              :               || useless_type_conversion_p (vectype, TREE_TYPE (vec_oprnd)));
    9308      1285388 :   bool simd_lane_access_p
    9309      1285388 :       = STMT_VINFO_SIMD_LANE_ACCESS_P (stmt_info) != 0;
    9310      1285388 :   if (!costing_p
    9311      1285388 :       && simd_lane_access_p
    9312         4374 :       && !loop_masks
    9313         4374 :       && TREE_CODE (DR_BASE_ADDRESS (first_dr_info->dr)) == ADDR_EXPR
    9314         4374 :       && VAR_P (TREE_OPERAND (DR_BASE_ADDRESS (first_dr_info->dr), 0))
    9315         4374 :       && integer_zerop (get_dr_vinfo_offset (vinfo, first_dr_info))
    9316         4374 :       && integer_zerop (DR_INIT (first_dr_info->dr))
    9317      1289762 :       && alias_sets_conflict_p (get_alias_set (aggr_type),
    9318         4374 :                                 get_alias_set (TREE_TYPE (ref_type))))
    9319              :     {
    9320         4366 :       dataref_ptr = unshare_expr (DR_BASE_ADDRESS (first_dr_info->dr));
    9321         4366 :       dataref_offset = build_int_cst (ref_type, 0);
    9322              :     }
    9323      1281022 :   else if (!costing_p)
    9324      1069636 :     dataref_ptr = vect_create_data_ref_ptr (vinfo, first_stmt_info, aggr_type,
    9325              :                                             simd_lane_access_p ? loop : NULL,
    9326              :                                             offset, &dummy, gsi, &ptr_incr,
    9327              :                                             simd_lane_access_p, bump);
    9328              : 
    9329      1285388 :   new_stmt = NULL;
    9330      1285388 :   gcc_assert (!grouped_store);
    9331      2856338 :   for (i = 0; i < vec_num; i++)
    9332              :     {
    9333      1570950 :       if (!costing_p)
    9334       667214 :         vec_oprnd = vec_oprnds[i];
    9335              : 
    9336      1570950 :       if (memory_access_type == VMAT_CONTIGUOUS_REVERSE)
    9337              :         {
    9338         3108 :           if (costing_p)
    9339         1972 :             inside_cost += record_stmt_cost (cost_vec, 1, vec_perm,
    9340              :                                              slp_node, 0, vect_body);
    9341              :           else
    9342              :             {
    9343         1136 :               tree perm_mask = perm_mask_for_reverse (vectype);
    9344         1136 :               tree new_temp = make_ssa_name (vectype);
    9345              : 
    9346              :               /* Generate the permute statement.  */
    9347         1136 :               gimple *perm_stmt
    9348         1136 :                 = gimple_build_assign (new_temp, VEC_PERM_EXPR, vec_oprnd,
    9349              :                                        vec_oprnd, perm_mask);
    9350         1136 :               vect_finish_stmt_generation (vinfo, stmt_info, perm_stmt, gsi);
    9351              : 
    9352         1136 :               perm_stmt = SSA_NAME_DEF_STMT (new_temp);
    9353      1570950 :               vec_oprnd = new_temp;
    9354              :             }
    9355              :         }
    9356              : 
    9357      1570950 :       if (costing_p)
    9358              :         {
    9359       903736 :           n_adjacent_stores++;
    9360       903736 :           continue;
    9361              :         }
    9362              : 
    9363       667214 :       tree final_mask = NULL_TREE;
    9364       667214 :       tree final_len = NULL_TREE;
    9365       667214 :       tree bias = NULL_TREE;
    9366       667214 :       if (loop_masks)
    9367           77 :         final_mask = vect_get_loop_mask (loop_vinfo, gsi, loop_masks,
    9368              :                                          vec_num, vectype, i);
    9369       667214 :       if (vec_mask)
    9370          702 :         vec_mask = vec_masks[i];
    9371          702 :       if (vec_mask)
    9372          702 :         final_mask = prepare_vec_mask (loop_vinfo, mask_vectype, final_mask,
    9373              :                                        vec_mask, gsi);
    9374              : 
    9375       667214 :       if (i > 0)
    9376              :         /* Bump the vector pointer.  */
    9377       128026 :         dataref_ptr = bump_vector_ptr (vinfo, dataref_ptr, ptr_incr, gsi,
    9378              :                                        stmt_info, bump);
    9379              : 
    9380       667214 :       unsigned misalign;
    9381       667214 :       unsigned HOST_WIDE_INT align;
    9382       667214 :       align = known_alignment (DR_TARGET_ALIGNMENT (first_dr_info));
    9383       667214 :       if (alignment_support_scheme == dr_aligned)
    9384              :         misalign = 0;
    9385       308175 :       else if (misalignment == DR_MISALIGNMENT_UNKNOWN)
    9386              :         {
    9387       160198 :           align = dr_alignment (vect_dr_behavior (vinfo, first_dr_info));
    9388       160198 :           misalign = 0;
    9389              :         }
    9390              :       else
    9391       147977 :         misalign = misalignment;
    9392       667214 :       if (dataref_offset == NULL_TREE
    9393       661834 :           && TREE_CODE (dataref_ptr) == SSA_NAME)
    9394       182550 :         set_ptr_info_alignment (get_ptr_info (dataref_ptr), align, misalign);
    9395       667214 :       align = least_bit_hwi (misalign | align);
    9396              : 
    9397              :       /* Compute IFN when LOOP_LENS or final_mask valid.  */
    9398       667214 :       machine_mode vmode = TYPE_MODE (vectype);
    9399       667214 :       machine_mode new_vmode = vmode;
    9400       667214 :       internal_fn partial_ifn = IFN_LAST;
    9401       667214 :       if (loop_lens)
    9402              :         {
    9403            0 :           opt_machine_mode new_ovmode
    9404            0 :             = get_len_load_store_mode (vmode, false, &partial_ifn);
    9405            0 :           new_vmode = new_ovmode.require ();
    9406            0 :           unsigned factor
    9407            0 :             = (new_ovmode == vmode) ? 1 : GET_MODE_UNIT_SIZE (vmode);
    9408            0 :           final_len = vect_get_loop_len (loop_vinfo, gsi, loop_lens,
    9409              :                                          vec_num, vectype, i, factor, true);
    9410              :         }
    9411       667214 :       else if (final_mask)
    9412              :         {
    9413          714 :           if (!can_vec_mask_load_store_p (vmode,
    9414          714 :                                           TYPE_MODE (TREE_TYPE (final_mask)),
    9415              :                                           false, &partial_ifn))
    9416            0 :             gcc_unreachable ();
    9417              :         }
    9418              : 
    9419       667214 :       if (partial_ifn == IFN_MASK_LEN_STORE)
    9420              :         {
    9421            0 :           if (!final_len)
    9422              :             {
    9423              :               /* Pass VF value to 'len' argument of
    9424              :                  MASK_LEN_STORE if LOOP_LENS is invalid.  */
    9425            0 :               final_len = size_int (TYPE_VECTOR_SUBPARTS (vectype));
    9426              :             }
    9427            0 :           if (!final_mask)
    9428              :             {
    9429              :               /* Pass all ones value to 'mask' argument of
    9430              :                  MASK_LEN_STORE if final_mask is invalid.  */
    9431            0 :               mask_vectype = truth_type_for (vectype);
    9432            0 :               final_mask = build_minus_one_cst (mask_vectype);
    9433              :             }
    9434              :         }
    9435       667214 :       if (final_len)
    9436              :         {
    9437            0 :           signed char biasval = LOOP_VINFO_PARTIAL_LOAD_STORE_BIAS (loop_vinfo);
    9438            0 :           bias = build_int_cst (intQI_type_node, biasval);
    9439              :         }
    9440              : 
    9441              :       /* Arguments are ready.  Create the new vector stmt.  */
    9442       667214 :       if (final_len)
    9443              :         {
    9444            0 :           gcall *call;
    9445            0 :           tree ptr = build_int_cst (ref_type, align * BITS_PER_UNIT);
    9446              :           /* Need conversion if it's wrapped with VnQI.  */
    9447            0 :           if (vmode != new_vmode)
    9448              :             {
    9449            0 :               tree new_vtype
    9450            0 :                 = build_vector_type_for_mode (unsigned_intQI_type_node,
    9451              :                                               new_vmode);
    9452            0 :               tree var = vect_get_new_ssa_name (new_vtype, vect_simple_var);
    9453            0 :               vec_oprnd = build1 (VIEW_CONVERT_EXPR, new_vtype, vec_oprnd);
    9454            0 :               gassign *new_stmt
    9455            0 :                 = gimple_build_assign (var, VIEW_CONVERT_EXPR, vec_oprnd);
    9456            0 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    9457            0 :               vec_oprnd = var;
    9458              :             }
    9459              : 
    9460            0 :           if (partial_ifn == IFN_MASK_LEN_STORE)
    9461            0 :             call = gimple_build_call_internal (IFN_MASK_LEN_STORE, 6,
    9462              :                                                dataref_ptr, ptr, final_mask,
    9463              :                                                final_len, bias, vec_oprnd);
    9464              :           else
    9465            0 :             call = gimple_build_call_internal (IFN_LEN_STORE, 5,
    9466              :                                                dataref_ptr, ptr, final_len,
    9467              :                                                bias, vec_oprnd);
    9468            0 :           gimple_call_set_nothrow (call, true);
    9469            0 :           vect_finish_stmt_generation (vinfo, stmt_info, call, gsi);
    9470            0 :           new_stmt = call;
    9471              :         }
    9472       667214 :       else if (final_mask)
    9473              :         {
    9474          714 :           tree ptr = build_int_cst (ref_type, align * BITS_PER_UNIT);
    9475          714 :           gcall *call
    9476          714 :             = gimple_build_call_internal (IFN_MASK_STORE, 4, dataref_ptr,
    9477              :                                           ptr, final_mask, vec_oprnd);
    9478          714 :           gimple_call_set_nothrow (call, true);
    9479          714 :           vect_finish_stmt_generation (vinfo, stmt_info, call, gsi);
    9480          714 :           new_stmt = call;
    9481              :         }
    9482              :       else
    9483              :         {
    9484       666500 :           data_ref = fold_build2 (MEM_REF, vectype, dataref_ptr,
    9485              :                                   dataref_offset ? dataref_offset
    9486              :                                   : build_int_cst (ref_type, 0));
    9487       666500 :           if (alignment_support_scheme == dr_aligned
    9488       666500 :               && align >= TYPE_ALIGN_UNIT (vectype))
    9489              :             ;
    9490              :           else
    9491       307631 :             TREE_TYPE (data_ref)
    9492       615262 :               = build_aligned_type (TREE_TYPE (data_ref),
    9493              :                                     align * BITS_PER_UNIT);
    9494       666500 :           vect_copy_ref_info (data_ref, DR_REF (first_dr_info->dr));
    9495       666500 :           new_stmt = gimple_build_assign (data_ref, vec_oprnd);
    9496       666500 :           vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    9497              :         }
    9498              :     }
    9499              : 
    9500      1285388 :   if (costing_p)
    9501              :     {
    9502       746200 :       if (n_adjacent_stores > 0)
    9503       746200 :         vect_get_store_cost (vinfo, stmt_info, slp_node, n_adjacent_stores,
    9504              :                              alignment_support_scheme, misalignment,
    9505              :                              &inside_cost, cost_vec);
    9506              : 
    9507              :       /* When vectorizing a store into the function result assign
    9508              :          a penalty if the function returns in a multi-register location.
    9509              :          In this case we assume we'll end up with having to spill the
    9510              :          vector result and do piecewise loads as a conservative estimate.  */
    9511       746200 :       tree base = get_base_address (STMT_VINFO_DATA_REF (stmt_info)->ref);
    9512       746200 :       if (base
    9513       746200 :           && (TREE_CODE (base) == RESULT_DECL
    9514       695958 :               || (DECL_P (base) && cfun_returns (base)))
    9515       808067 :           && !aggregate_value_p (base, cfun->decl))
    9516              :         {
    9517        11037 :           rtx reg = hard_function_value (TREE_TYPE (base), cfun->decl, 0, 1);
    9518              :           /* ???  Handle PARALLEL in some way.  */
    9519        11037 :           if (REG_P (reg))
    9520              :             {
    9521        10835 :               int nregs = hard_regno_nregs (REGNO (reg), GET_MODE (reg));
    9522              :               /* Assume that a single reg-reg move is possible and cheap,
    9523              :                  do not account for vector to gp register move cost.  */
    9524        10835 :               if (nregs > 1)
    9525              :                 {
    9526              :                   /* Spill.  */
    9527        10025 :                   prologue_cost
    9528        10025 :                     += record_stmt_cost (cost_vec, 1, vector_store,
    9529              :                                          slp_node, 0, vect_epilogue);
    9530              :                   /* Loads.  */
    9531        10025 :                   prologue_cost
    9532        10025 :                     += record_stmt_cost (cost_vec, nregs, scalar_load,
    9533              :                                          slp_node, 0, vect_epilogue);
    9534              :                 }
    9535              :             }
    9536              :         }
    9537       746200 :       if (dump_enabled_p ())
    9538        13410 :         dump_printf_loc (MSG_NOTE, vect_location,
    9539              :                          "vect_model_store_cost: inside_cost = %d, "
    9540              :                          "prologue_cost = %d .\n",
    9541              :                          inside_cost, prologue_cost);
    9542              :     }
    9543              : 
    9544      1285388 :   return true;
    9545      2601936 : }
    9546              : 
    9547              : /* Given a vector type VECTYPE, turns permutation SEL into the equivalent
    9548              :    VECTOR_CST mask.  No checks are made that the target platform supports the
    9549              :    mask, so callers may wish to test can_vec_perm_const_p separately, or use
    9550              :    vect_gen_perm_mask_checked.  */
    9551              : 
    9552              : tree
    9553        61452 : vect_gen_perm_mask_any (tree vectype, const vec_perm_indices &sel)
    9554              : {
    9555        61452 :   tree mask_type;
    9556              : 
    9557        61452 :   poly_uint64 nunits = sel.length ();
    9558        61452 :   gcc_assert (known_eq (nunits, TYPE_VECTOR_SUBPARTS (vectype)));
    9559              : 
    9560        61452 :   mask_type = build_vector_type (ssizetype, nunits);
    9561        61452 :   return vec_perm_indices_to_tree (mask_type, sel);
    9562              : }
    9563              : 
    9564              : /* Checked version of vect_gen_perm_mask_any.  Asserts can_vec_perm_const_p,
    9565              :    i.e. that the target supports the pattern _for arbitrary input vectors_.  */
    9566              : 
    9567              : tree
    9568        58689 : vect_gen_perm_mask_checked (tree vectype, const vec_perm_indices &sel)
    9569              : {
    9570        58689 :   machine_mode vmode = TYPE_MODE (vectype);
    9571        58689 :   gcc_assert (can_vec_perm_const_p (vmode, vmode, sel));
    9572        58689 :   return vect_gen_perm_mask_any (vectype, sel);
    9573              : }
    9574              : 
    9575              : /* Given a vector variable X and Y, that was generated for the scalar
    9576              :    STMT_INFO, generate instructions to permute the vector elements of X and Y
    9577              :    using permutation mask MASK_VEC, insert them at *GSI and return the
    9578              :    permuted vector variable.  */
    9579              : 
    9580              : static tree
    9581         1431 : permute_vec_elements (vec_info *vinfo,
    9582              :                       tree x, tree y, tree mask_vec, stmt_vec_info stmt_info,
    9583              :                       gimple_stmt_iterator *gsi)
    9584              : {
    9585         1431 :   tree vectype = TREE_TYPE (x);
    9586         1431 :   tree perm_dest, data_ref;
    9587         1431 :   gimple *perm_stmt;
    9588              : 
    9589         1431 :   tree scalar_dest = gimple_get_lhs (stmt_info->stmt);
    9590         1431 :   if (scalar_dest && TREE_CODE (scalar_dest) == SSA_NAME)
    9591         1431 :     perm_dest = vect_create_destination_var (scalar_dest, vectype);
    9592              :   else
    9593            0 :     perm_dest = vect_get_new_vect_var (vectype, vect_simple_var, NULL);
    9594         1431 :   data_ref = make_ssa_name (perm_dest);
    9595              : 
    9596              :   /* Generate the permute statement.  */
    9597         1431 :   perm_stmt = gimple_build_assign (data_ref, VEC_PERM_EXPR, x, y, mask_vec);
    9598         1431 :   vect_finish_stmt_generation (vinfo, stmt_info, perm_stmt, gsi);
    9599              : 
    9600         1431 :   return data_ref;
    9601              : }
    9602              : 
    9603              : /* Hoist the definitions of all SSA uses on STMT_INFO out of the loop LOOP,
    9604              :    inserting them on the loops preheader edge.  Returns true if we
    9605              :    were successful in doing so (and thus STMT_INFO can be moved then),
    9606              :    otherwise returns false.  HOIST_P indicates if we want to hoist the
    9607              :    definitions of all SSA uses, it would be false when we are costing.  */
    9608              : 
    9609              : static bool
    9610         3765 : hoist_defs_of_uses (gimple *stmt, class loop *loop, bool hoist_p)
    9611              : {
    9612         3765 :   ssa_op_iter i;
    9613         3765 :   use_operand_p use_p;
    9614         3765 :   auto_vec<use_operand_p, 8> to_hoist;
    9615              : 
    9616         7188 :   FOR_EACH_SSA_USE_OPERAND (use_p, stmt, i, SSA_OP_USE)
    9617              :     {
    9618         3451 :       gimple *def_stmt = SSA_NAME_DEF_STMT (USE_FROM_PTR (use_p));
    9619         3451 :       if (!gimple_nop_p (def_stmt)
    9620         3451 :           && flow_bb_inside_loop_p (loop, gimple_bb (def_stmt)))
    9621              :         {
    9622              :           /* Make sure we don't need to recurse.  While we could do
    9623              :              so in simple cases when there are more complex use webs
    9624              :              we don't have an easy way to preserve stmt order to fulfil
    9625              :              dependencies within them.  */
    9626          111 :           tree op2;
    9627          111 :           ssa_op_iter i2;
    9628          111 :           if (gimple_code (def_stmt) == GIMPLE_PHI
    9629          111 :               || (single_ssa_def_operand (def_stmt, SSA_OP_DEF)
    9630              :                   == NULL_DEF_OPERAND_P))
    9631           28 :             return false;
    9632          226 :           FOR_EACH_SSA_TREE_OPERAND (op2, def_stmt, i2, SSA_OP_USE)
    9633              :             {
    9634          143 :               gimple *def_stmt2 = SSA_NAME_DEF_STMT (op2);
    9635          143 :               if (!gimple_nop_p (def_stmt2)
    9636          143 :                   && flow_bb_inside_loop_p (loop, gimple_bb (def_stmt2)))
    9637              :                 return false;
    9638              :             }
    9639           83 :           to_hoist.safe_push (use_p);
    9640              :         }
    9641              :     }
    9642              : 
    9643         7474 :   if (to_hoist.is_empty ())
    9644              :     return true;
    9645              : 
    9646           59 :   if (!hoist_p)
    9647              :     return true;
    9648              : 
    9649              :   /* Instead of moving defs we copy them so we can zero their UID to not
    9650              :      confuse dominance queries in the preheader.  */
    9651            9 :   gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
    9652           36 :   for (use_operand_p use_p : to_hoist)
    9653              :     {
    9654            9 :       gimple *def_stmt = SSA_NAME_DEF_STMT (USE_FROM_PTR (use_p));
    9655            9 :       gimple *copy = gimple_copy (def_stmt);
    9656            9 :       gimple_set_uid (copy, 0);
    9657            9 :       def_operand_p def_p = single_ssa_def_operand (def_stmt, SSA_OP_DEF);
    9658            9 :       tree new_def = duplicate_ssa_name (DEF_FROM_PTR (def_p), copy);
    9659            9 :       update_stmt (copy);
    9660            9 :       def_p = single_ssa_def_operand (copy, SSA_OP_DEF);
    9661            9 :       SET_DEF (def_p, new_def);
    9662            9 :       SET_USE (use_p, new_def);
    9663            9 :       gsi_insert_before (&gsi, copy, GSI_SAME_STMT);
    9664              :     }
    9665              : 
    9666              :   return true;
    9667         3765 : }
    9668              : 
    9669              : /* vectorizable_load.
    9670              : 
    9671              :    Check if STMT_INFO reads a non scalar data-ref (array/pointer/structure)
    9672              :    that can be vectorized.
    9673              :    If COST_VEC is passed, calculate costs but don't change anything,
    9674              :    otherwise, vectorize STMT_INFO: create a vectorized stmt to replace
    9675              :    it, and insert it at GSI.
    9676              :    Return true if STMT_INFO is vectorizable in this way.  */
    9677              : 
    9678              : static bool
    9679      1949001 : vectorizable_load (vec_info *vinfo,
    9680              :                    stmt_vec_info stmt_info, gimple_stmt_iterator *gsi,
    9681              :                    slp_tree slp_node,
    9682              :                    stmt_vector_for_cost *cost_vec)
    9683              : {
    9684      1949001 :   tree scalar_dest;
    9685      1949001 :   tree vec_dest = NULL;
    9686      1949001 :   tree data_ref = NULL;
    9687      1949001 :   loop_vec_info loop_vinfo = dyn_cast <loop_vec_info> (vinfo);
    9688      1949001 :   class loop *loop = NULL;
    9689      1949001 :   class loop *containing_loop = gimple_bb (stmt_info->stmt)->loop_father;
    9690      1949001 :   bool nested_in_vect_loop = false;
    9691      1949001 :   tree elem_type;
    9692              :   /* Avoid false positive uninitialized warning, see PR110652.  */
    9693      1949001 :   tree new_temp = NULL_TREE;
    9694      1949001 :   machine_mode mode;
    9695      1949001 :   tree dummy;
    9696      1949001 :   tree dataref_ptr = NULL_TREE;
    9697      1949001 :   tree dataref_offset = NULL_TREE;
    9698      1949001 :   gimple *ptr_incr = NULL;
    9699      1949001 :   int i, j;
    9700      1949001 :   unsigned int group_size;
    9701      1949001 :   poly_uint64 group_gap_adj;
    9702      1949001 :   tree msq = NULL_TREE, lsq;
    9703      1949001 :   tree realignment_token = NULL_TREE;
    9704      1949001 :   gphi *phi = NULL;
    9705      1949001 :   bool grouped_load = false;
    9706      1949001 :   stmt_vec_info first_stmt_info;
    9707      1949001 :   stmt_vec_info first_stmt_info_for_drptr = NULL;
    9708      1949001 :   bool compute_in_loop = false;
    9709      1949001 :   class loop *at_loop;
    9710      1949001 :   int vec_num;
    9711      1949001 :   bb_vec_info bb_vinfo = dyn_cast <bb_vec_info> (vinfo);
    9712      1949001 :   poly_uint64 vf;
    9713      1949001 :   tree aggr_type;
    9714      1949001 :   tree ref_type;
    9715      1949001 :   enum vect_def_type mask_dt = vect_unknown_def_type;
    9716      1949001 :   enum vect_def_type els_dt = vect_unknown_def_type;
    9717              : 
    9718      1949001 :   if (!STMT_VINFO_RELEVANT_P (stmt_info) && !bb_vinfo)
    9719              :     return false;
    9720              : 
    9721      1949001 :   if (STMT_VINFO_DEF_TYPE (stmt_info) != vect_internal_def
    9722       194522 :       && cost_vec)
    9723              :     return false;
    9724              : 
    9725      1754479 :   if (!STMT_VINFO_DATA_REF (stmt_info))
    9726              :     return false;
    9727              : 
    9728      1412946 :   tree mask_vectype = NULL_TREE;
    9729      1412946 :   tree els = NULL_TREE; tree els_vectype = NULL_TREE;
    9730              : 
    9731      1412946 :   int mask_index = -1;
    9732      1412946 :   int els_index = -1;
    9733      1412946 :   slp_tree mask_node = NULL;
    9734      1412946 :   slp_tree els_op = NULL;
    9735      1412946 :   if (gassign *assign = dyn_cast <gassign *> (stmt_info->stmt))
    9736              :     {
    9737      1409620 :       scalar_dest = gimple_assign_lhs (assign);
    9738      1409620 :       if (TREE_CODE (scalar_dest) != SSA_NAME)
    9739              :         return false;
    9740              : 
    9741       637646 :       tree_code code = gimple_assign_rhs_code (assign);
    9742       637646 :       if (code != ARRAY_REF
    9743       637646 :           && code != BIT_FIELD_REF
    9744       637646 :           && code != INDIRECT_REF
    9745       443226 :           && code != COMPONENT_REF
    9746       443226 :           && code != IMAGPART_EXPR
    9747       310571 :           && code != REALPART_EXPR
    9748       310571 :           && code != MEM_REF
    9749          237 :           && TREE_CODE_CLASS (code) != tcc_declaration)
    9750              :         return false;
    9751              :     }
    9752              :   else
    9753              :     {
    9754      1312669 :       gcall *call = dyn_cast <gcall *> (stmt_info->stmt);
    9755         3326 :       if (!call || !gimple_call_internal_p (call))
    9756              :         return false;
    9757              : 
    9758         3326 :       internal_fn ifn = gimple_call_internal_fn (call);
    9759         3326 :       if (!internal_load_fn_p (ifn))
    9760              :         return false;
    9761              : 
    9762         2407 :       scalar_dest = gimple_call_lhs (call);
    9763         2407 :       if (!scalar_dest)
    9764              :         return false;
    9765              : 
    9766         2407 :       mask_index = internal_fn_mask_index (ifn);
    9767         2407 :       if (mask_index >= 0)
    9768         2407 :         mask_index = vect_slp_child_index_for_operand
    9769         2407 :                     (call, mask_index, STMT_VINFO_GATHER_SCATTER_P (stmt_info));
    9770         2407 :       if (mask_index >= 0
    9771         2407 :           && !vect_check_scalar_mask (vinfo, slp_node, mask_index,
    9772              :                                       &mask_node, &mask_dt, &mask_vectype))
    9773              :         return false;
    9774              : 
    9775         2407 :       els_index = internal_fn_else_index (ifn);
    9776         2407 :       if (els_index >= 0)
    9777         2407 :         els_index = vect_slp_child_index_for_operand
    9778         2407 :           (call, els_index, STMT_VINFO_GATHER_SCATTER_P (stmt_info));
    9779         2407 :       if (els_index >= 0
    9780         2407 :           && !vect_is_simple_use (vinfo, slp_node, els_index,
    9781              :                                   &els, &els_op, &els_dt, &els_vectype))
    9782              :         return false;
    9783              :     }
    9784              : 
    9785       639986 :   tree vectype = SLP_TREE_VECTYPE (slp_node);
    9786       639986 :   poly_uint64 nunits = TYPE_VECTOR_SUBPARTS (vectype);
    9787              : 
    9788       639986 :   if (loop_vinfo)
    9789              :     {
    9790       424968 :       loop = LOOP_VINFO_LOOP (loop_vinfo);
    9791       424968 :       nested_in_vect_loop = nested_in_vect_loop_p (loop, stmt_info);
    9792       424968 :       vf = LOOP_VINFO_VECT_FACTOR (loop_vinfo);
    9793              :     }
    9794              :   else
    9795              :     vf = 1;
    9796              : 
    9797       639986 :   vec_num = vect_get_num_copies (vinfo, slp_node);
    9798              : 
    9799              :   /* FORNOW. This restriction should be relaxed.  */
    9800       639986 :   if (nested_in_vect_loop && vec_num > 1)
    9801              :     {
    9802          316 :       if (dump_enabled_p ())
    9803           66 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    9804              :                          "multiple types in nested loop.\n");
    9805          316 :       return false;
    9806              :     }
    9807              : 
    9808       639670 :   elem_type = TREE_TYPE (vectype);
    9809       639670 :   mode = TYPE_MODE (vectype);
    9810              : 
    9811              :   /* FORNOW. In some cases can vectorize even if data-type not supported
    9812              :     (e.g. - data copies).  */
    9813       639670 :   if (!can_implement_p (mov_optab, mode))
    9814              :     {
    9815            0 :       if (dump_enabled_p ())
    9816            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    9817              :                          "Aligned load, but unsupported type.\n");
    9818            0 :       return false;
    9819              :     }
    9820              : 
    9821              :   /* Check if the load is a part of an interleaving chain.  */
    9822       639670 :   if (STMT_VINFO_GROUPED_ACCESS (stmt_info))
    9823              :     {
    9824       301850 :       grouped_load = true;
    9825              :       /* FORNOW */
    9826       301850 :       gcc_assert (!nested_in_vect_loop);
    9827       301850 :       gcc_assert (!STMT_VINFO_GATHER_SCATTER_P (stmt_info));
    9828              : 
    9829       301850 :       first_stmt_info = DR_GROUP_FIRST_ELEMENT (stmt_info);
    9830       301850 :       group_size = DR_GROUP_SIZE (first_stmt_info);
    9831              : 
    9832              :       /* Invalidate assumptions made by dependence analysis when vectorization
    9833              :          on the unrolled body effectively re-orders stmts.  */
    9834       301850 :       if (STMT_VINFO_MIN_NEG_DIST (stmt_info) != 0
    9835       301850 :           && maybe_gt (LOOP_VINFO_VECT_FACTOR (loop_vinfo),
    9836              :                        STMT_VINFO_MIN_NEG_DIST (stmt_info)))
    9837              :         {
    9838           12 :           if (dump_enabled_p ())
    9839           12 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    9840              :                              "cannot perform implicit CSE when performing "
    9841              :                              "group loads with negative dependence distance\n");
    9842           12 :           return false;
    9843              :         }
    9844              :     }
    9845              :   else
    9846              :     group_size = 1;
    9847              : 
    9848       639658 :   vect_load_store_data _ls_data{};
    9849       639658 :   vect_load_store_data &ls = slp_node->get_data (_ls_data);
    9850       639658 :   if (cost_vec
    9851       639658 :       && !get_load_store_type (vinfo, stmt_info, vectype, slp_node, mask_node,
    9852              :                                VLS_LOAD, &ls))
    9853              :     return false;
    9854              :   /* Temporary aliases to analysis data, should not be modified through
    9855              :      these.  */
    9856       534138 :   const vect_memory_access_type memory_access_type = ls.memory_access_type;
    9857       534138 :   const dr_alignment_support alignment_support_scheme
    9858              :     = ls.alignment_support_scheme;
    9859       534138 :   const int misalignment = ls.misalignment;
    9860       534138 :   const poly_int64 poffset = ls.poffset;
    9861       534138 :   const vec<int> &elsvals = ls.elsvals;
    9862              : 
    9863       534138 :   int maskload_elsval = 0;
    9864       534138 :   bool need_zeroing = false;
    9865              : 
    9866              :   /* We might need to explicitly zero inactive elements if there are
    9867              :      padding bits in the type that might leak otherwise.
    9868              :      Refer to PR115336.  */
    9869       534138 :   tree scalar_type = TREE_TYPE (scalar_dest);
    9870       534138 :   bool type_mode_padding_p
    9871      1068276 :     = TYPE_PRECISION (scalar_type) < GET_MODE_PRECISION (GET_MODE_INNER (mode));
    9872              : 
    9873       534138 :   if (slp_node->ldst_lanes
    9874            0 :       && memory_access_type != VMAT_LOAD_STORE_LANES)
    9875              :     {
    9876            0 :       if (dump_enabled_p ())
    9877            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    9878              :                          "discovered load-lane but cannot use it.\n");
    9879            0 :       return false;
    9880              :     }
    9881              : 
    9882       534138 :   if (mask_node)
    9883              :     {
    9884         2289 :       if (memory_access_type == VMAT_CONTIGUOUS)
    9885              :         {
    9886         1507 :           machine_mode vec_mode = TYPE_MODE (vectype);
    9887          395 :           if (!VECTOR_MODE_P (vec_mode)
    9888         3014 :               || !can_vec_mask_load_store_p (vec_mode,
    9889         1507 :                                              TYPE_MODE (mask_vectype),
    9890              :                                              true, NULL, &ls.elsvals))
    9891           67 :             return false;
    9892              :         }
    9893          782 :       else if (memory_access_type == VMAT_ELEMENTWISE
    9894          782 :                || memory_access_type == VMAT_STRIDED_SLP)
    9895              :         {
    9896            0 :           if (dump_enabled_p ())
    9897            0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    9898              :                              "unsupported masked strided access.\n");
    9899            0 :           return false;
    9900              :         }
    9901          782 :       else if (memory_access_type != VMAT_LOAD_STORE_LANES
    9902          782 :                && !mat_gather_scatter_p (memory_access_type))
    9903              :         {
    9904           62 :           if (dump_enabled_p ())
    9905            0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    9906              :                              "unsupported access type for masked load.\n");
    9907           62 :           return false;
    9908              :         }
    9909          720 :       else if (memory_access_type == VMAT_GATHER_SCATTER_EMULATED)
    9910              :         {
    9911          476 :           if (dump_enabled_p ())
    9912           26 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    9913              :                              "unsupported masked emulated gather.\n");
    9914          476 :           return false;
    9915              :         }
    9916              :     }
    9917              : 
    9918       533533 :   bool costing_p = cost_vec;
    9919              : 
    9920       533533 :   if (costing_p) /* transformation not required.  */
    9921              :     {
    9922       367632 :       if (mask_node
    9923       367632 :           && !vect_maybe_update_slp_op_vectype (mask_node,
    9924              :                                                 mask_vectype))
    9925              :         {
    9926            0 :           if (dump_enabled_p ())
    9927            0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    9928              :                              "incompatible vector types for invariants\n");
    9929            0 :           return false;
    9930              :         }
    9931              : 
    9932       367632 :       if (loop_vinfo
    9933       244029 :           && LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo))
    9934       167040 :         check_load_store_for_partial_vectors (loop_vinfo, vectype, slp_node,
    9935              :                                               VLS_LOAD, group_size, &ls,
    9936              :                                               mask_node, &ls.elsvals);
    9937              : 
    9938       367632 :       if (dump_enabled_p ()
    9939        24393 :           && memory_access_type != VMAT_ELEMENTWISE
    9940        24284 :           && !mat_gather_scatter_p (memory_access_type)
    9941        24062 :           && memory_access_type != VMAT_STRIDED_SLP
    9942        24062 :           && memory_access_type != VMAT_INVARIANT
    9943       390801 :           && alignment_support_scheme != dr_aligned)
    9944         9405 :         dump_printf_loc (MSG_NOTE, vect_location,
    9945              :                          "Vectorizing an unaligned access.\n");
    9946              : 
    9947       367632 :       if (memory_access_type == VMAT_LOAD_STORE_LANES)
    9948            0 :         vinfo->any_known_not_updated_vssa = true;
    9949              : 
    9950       367632 :       SLP_TREE_TYPE (slp_node) = load_vec_info_type;
    9951       367632 :       slp_node->data = new vect_load_store_data (std::move (ls));
    9952              :     }
    9953              : 
    9954              :   /* If the type needs padding we must zero inactive elements.
    9955              :      Check if we can do that with a VEC_COND_EXPR and store the
    9956              :      elsval we choose in MASKLOAD_ELSVAL.  */
    9957       533533 :   if (elsvals.length ()
    9958        23231 :       && type_mode_padding_p
    9959            3 :       && !elsvals.contains (MASK_LOAD_ELSE_ZERO)
    9960        23231 :       && !expand_vec_cond_expr_p (vectype, truth_type_for (vectype)))
    9961              :     {
    9962            0 :       if (dump_enabled_p ())
    9963            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    9964              :                          "cannot zero inactive elements.\n");
    9965            0 :       return false;
    9966              :     }
    9967              : 
    9968              :   /* For now just use the first available else value.
    9969              :      get_supported_else_vals tries MASK_LOAD_ELSE_ZERO first so we will
    9970              :      select it here if it is supported.  */
    9971       533533 :   if (elsvals.length ())
    9972        23231 :     maskload_elsval = *elsvals.begin ();
    9973              : 
    9974       533533 :   if (dump_enabled_p () && !costing_p)
    9975        16586 :     dump_printf_loc (MSG_NOTE, vect_location, "transform load.\n");
    9976              : 
    9977              :   /* Transform.  */
    9978              : 
    9979       533533 :   dr_vec_info *dr_info = STMT_VINFO_DR_INFO (stmt_info), *first_dr_info = NULL;
    9980       533533 :   ensure_base_align (dr_info);
    9981              : 
    9982       533533 :   if (memory_access_type == VMAT_INVARIANT)
    9983              :     {
    9984         3854 :       gcc_assert (!grouped_load && !mask_node && !bb_vinfo);
    9985              :       /* If we have versioned for aliasing or the loop doesn't
    9986              :          have any data dependencies that would preclude this,
    9987              :          then we are sure this is a loop invariant load and
    9988              :          thus we can insert it on the preheader edge.
    9989              :          TODO: hoist_defs_of_uses should ideally be computed
    9990              :          once at analysis time, remembered and used in the
    9991              :          transform time.  */
    9992         7708 :       bool hoist_p = (LOOP_VINFO_NO_DATA_DEPENDENCIES (loop_vinfo)
    9993         3854 :                       && !nested_in_vect_loop);
    9994              : 
    9995         3854 :       bool uniform_p = true;
    9996        16096 :       for (stmt_vec_info sinfo : SLP_TREE_SCALAR_STMTS (slp_node))
    9997              :         {
    9998              :           /* It is unsafe to hoist a conditional load over the conditions that
    9999              :              make it valid.  When early break this means that any invariant load
   10000              :              can't be hoisted unless it's in the loop header or if we know
   10001              :              something else has verified the load is valid to do.  Alignment
   10002              :              peeling would do this since getting through the prologue means the
   10003              :              load was done at least once and so the vector main body is free to
   10004              :              hoist it.  However today GCC will hoist the load above the PFA
   10005              :              loop.  As such that makes it still invalid and so we can't allow it
   10006              :              today.  */
   10007         4534 :           if (LOOP_VINFO_EARLY_BREAKS (loop_vinfo)
   10008         1050 :               && !DR_SCALAR_KNOWN_BOUNDS (STMT_VINFO_DR_INFO (sinfo))
   10009         5552 :               && gimple_bb (STMT_VINFO_STMT (vect_orig_stmt (sinfo)))
   10010         1018 :                   != loop->header)
   10011              :             {
   10012          918 :               if (LOOP_VINFO_PEELING_FOR_ALIGNMENT (loop_vinfo)
   10013          918 :                   && dump_enabled_p ())
   10014            6 :                 dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
   10015              :                              "not hoisting invariant load due to early break"
   10016              :                              "constraints\n");
   10017          912 :               else if (dump_enabled_p ())
   10018           16 :                dump_printf_loc (MSG_NOTE, vect_location,
   10019              :                              "not hoisting invariant load due to early break"
   10020              :                              "constraints\n");
   10021              :             hoist_p = false;
   10022              :           }
   10023              : 
   10024         3616 :           hoist_p = hoist_p && hoist_defs_of_uses (sinfo->stmt, loop, false);
   10025         4534 :           if (sinfo != SLP_TREE_SCALAR_STMTS (slp_node)[0])
   10026          211 :             uniform_p = false;
   10027              :         }
   10028         3854 :       if (costing_p)
   10029              :         {
   10030         2984 :           if (!uniform_p && (!hoist_p || !vf.is_constant ()))
   10031              :             {
   10032            0 :               if (dump_enabled_p ())
   10033            0 :                 dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
   10034              :                                  "not vectorizing non-uniform invariant "
   10035              :                                  "load\n");
   10036            0 :               return false;
   10037              :             }
   10038         1379 :           enum vect_cost_model_location cost_loc
   10039         2984 :             = hoist_p ? vect_prologue : vect_body;
   10040         2984 :           unsigned int cost = record_stmt_cost (cost_vec, 1, scalar_load,
   10041              :                                                 slp_node, 0, cost_loc);
   10042         2984 :           cost += record_stmt_cost (cost_vec, 1, scalar_to_vec,
   10043              :                                     slp_node, 0, cost_loc);
   10044         2984 :           unsigned int prologue_cost = hoist_p ? cost : 0;
   10045         1379 :           unsigned int inside_cost = hoist_p ? 0 : cost;
   10046         2984 :           if (dump_enabled_p ())
   10047          508 :             dump_printf_loc (MSG_NOTE, vect_location,
   10048              :                              "vect_model_load_cost: inside_cost = %d, "
   10049              :                              "prologue_cost = %d .\n",
   10050              :                              inside_cost, prologue_cost);
   10051         2984 :           return true;
   10052              :         }
   10053          870 :       if (hoist_p)
   10054              :         {
   10055              :           /* ???  For non-uniform lanes there could be still duplicates.
   10056              :              We're leaving those to post-vectorizer CSE for the moment.  */
   10057          675 :           auto_vec<tree> scalar_defs (SLP_TREE_LANES (slp_node));
   10058         2182 :           for (stmt_vec_info sinfo : SLP_TREE_SCALAR_STMTS (slp_node))
   10059              :             {
   10060          777 :               gassign *stmt = as_a <gassign *> (sinfo->stmt);
   10061          777 :               if (dump_enabled_p ())
   10062          368 :                 dump_printf_loc (MSG_NOTE, vect_location,
   10063              :                                  "hoisting out of the vectorized loop: %G",
   10064              :                                  (gimple *) stmt);
   10065          777 :               scalar_dest = copy_ssa_name (gimple_assign_lhs (stmt));
   10066          777 :               tree rhs = unshare_expr (gimple_assign_rhs1 (stmt));
   10067          777 :               edge pe = loop_preheader_edge (loop);
   10068          777 :               gphi *vphi = get_virtual_phi (loop->header);
   10069          777 :               tree vuse;
   10070          777 :               if (vphi)
   10071          771 :                 vuse = PHI_ARG_DEF_FROM_EDGE (vphi, pe);
   10072              :               else
   10073            6 :                 vuse = gimple_vuse (gsi_stmt (*gsi));
   10074          777 :               gimple *new_stmt = gimple_build_assign (scalar_dest, rhs);
   10075          777 :               gimple_set_vuse (new_stmt, vuse);
   10076          777 :               gsi_insert_on_edge_immediate (pe, new_stmt);
   10077          777 :               hoist_defs_of_uses (new_stmt, loop, true);
   10078          777 :               if (!useless_type_conversion_p (TREE_TYPE (vectype),
   10079          777 :                                               TREE_TYPE (scalar_dest)))
   10080              :                 {
   10081           12 :                   tree tem = make_ssa_name (TREE_TYPE (vectype));
   10082           12 :                   new_stmt = gimple_build_assign (tem,
   10083              :                                                   NOP_EXPR, scalar_dest);
   10084           12 :                   gsi_insert_on_edge_immediate (pe, new_stmt);
   10085           12 :                   scalar_dest = tem;
   10086              :                 }
   10087          777 :               scalar_defs.quick_push (scalar_dest);
   10088          777 :               if (uniform_p)
   10089              :                 break;
   10090              :             }
   10091          675 :           if (!uniform_p)
   10092              :             {
   10093           55 :               unsigned const_nunits
   10094           55 :                 = TYPE_VECTOR_SUBPARTS (vectype).to_constant ();
   10095          124 :               for (j = 0; j < (int) vec_num; ++j)
   10096              :                 {
   10097           69 :                   vec<constructor_elt, va_gc> *v = NULL;
   10098           69 :                   vec_safe_reserve (v, const_nunits, true);
   10099          405 :                   for (unsigned i = 0; i < const_nunits; ++i)
   10100              :                     {
   10101          336 :                       unsigned def_idx
   10102          336 :                         = (j * const_nunits + i) % SLP_TREE_LANES (slp_node);
   10103          336 :                       CONSTRUCTOR_APPEND_ELT (v, NULL_TREE,
   10104              :                                               scalar_defs[def_idx]);
   10105              :                     }
   10106           69 :                   scalar_dest = build_constructor (vectype, v);
   10107           69 :                   new_temp = vect_init_vector (vinfo, stmt_info, scalar_dest,
   10108              :                                                vectype, NULL);
   10109           69 :                   slp_node->push_vec_def (new_temp);
   10110              :                 }
   10111           55 :               return true;
   10112              :             }
   10113          620 :           new_temp = vect_init_vector (vinfo, stmt_info, scalar_dest,
   10114              :                                        vectype, NULL);
   10115          675 :         }
   10116              :       else
   10117              :         {
   10118          195 :           gcc_assert (uniform_p);
   10119          195 :           gimple_stmt_iterator gsi2 = *gsi;
   10120          195 :           gsi_next (&gsi2);
   10121          195 :           new_temp = vect_init_vector (vinfo, stmt_info, scalar_dest,
   10122              :                                        vectype, &gsi2);
   10123              :         }
   10124         1704 :       for (j = 0; j < (int) vec_num; ++j)
   10125          889 :         slp_node->push_vec_def (new_temp);
   10126              :       return true;
   10127              :     }
   10128              : 
   10129       529679 :   if (memory_access_type == VMAT_ELEMENTWISE
   10130       529679 :       || memory_access_type == VMAT_STRIDED_SLP)
   10131              :     {
   10132        22822 :       gimple_stmt_iterator incr_gsi;
   10133        22822 :       bool insert_after;
   10134        22822 :       tree offvar = NULL_TREE;
   10135        22822 :       tree ivstep;
   10136        22822 :       tree running_off;
   10137        22822 :       vec<constructor_elt, va_gc> *v = NULL;
   10138        22822 :       tree stride_base, stride_step, alias_off;
   10139              :       /* Checked by get_load_store_type.  */
   10140        22822 :       unsigned int const_nunits = nunits.to_constant ();
   10141        22822 :       unsigned HOST_WIDE_INT cst_offset = 0;
   10142        22822 :       tree dr_offset;
   10143        22822 :       unsigned int inside_cost = 0;
   10144              : 
   10145        22822 :       gcc_assert (!LOOP_VINFO_USING_PARTIAL_VECTORS_P (loop_vinfo));
   10146        22822 :       gcc_assert (!nested_in_vect_loop);
   10147              : 
   10148        22822 :       if (grouped_load)
   10149              :         {
   10150              :           /* If we elided a consecutive load permutation, don't
   10151              :              use the original first statement (which could be elided)
   10152              :              but the one the load permutation starts with.
   10153              :              This ensures the stride_base below is correct.  */
   10154        10165 :           if (!ls.subchain_p)
   10155        10133 :             first_stmt_info = DR_GROUP_FIRST_ELEMENT (stmt_info);
   10156              :           else
   10157           32 :             first_stmt_info = SLP_TREE_SCALAR_STMTS (slp_node)[0];
   10158        10165 :           first_dr_info = STMT_VINFO_DR_INFO (first_stmt_info);
   10159        10165 :           ref_type = get_group_alias_ptr_type (first_stmt_info);
   10160              :         }
   10161              :       else
   10162              :         {
   10163        12657 :           first_stmt_info = stmt_info;
   10164        12657 :           first_dr_info = dr_info;
   10165        12657 :           ref_type = reference_alias_ptr_type (DR_REF (dr_info->dr));
   10166              :         }
   10167              : 
   10168        22822 :       if (grouped_load)
   10169              :         {
   10170        10165 :           if (memory_access_type == VMAT_STRIDED_SLP)
   10171              :             {
   10172              :               /* If we elided a consecutive load permutation, adjust
   10173              :                  the group size here.  */
   10174         3713 :               if (!ls.subchain_p)
   10175         3681 :                 group_size = DR_GROUP_SIZE (first_stmt_info);
   10176              :               else
   10177           32 :                 group_size = SLP_TREE_LANES (slp_node);
   10178              :             }
   10179              :           else /* VMAT_ELEMENTWISE */
   10180         6452 :             group_size = SLP_TREE_LANES (slp_node);
   10181              :         }
   10182              :       else
   10183              :         group_size = 1;
   10184              : 
   10185        22822 :       if (!costing_p)
   10186              :         {
   10187         3348 :           dr_offset = get_dr_vinfo_offset (vinfo, first_dr_info);
   10188         3348 :           stride_base = fold_build_pointer_plus (
   10189              :             DR_BASE_ADDRESS (first_dr_info->dr),
   10190              :             size_binop (PLUS_EXPR, convert_to_ptrofftype (dr_offset),
   10191              :                         convert_to_ptrofftype (DR_INIT (first_dr_info->dr))));
   10192         3348 :           stride_step = fold_convert (sizetype, DR_STEP (first_dr_info->dr));
   10193              : 
   10194              :           /* For a load with loop-invariant (but other than power-of-2)
   10195              :              stride (i.e. not a grouped access) like so:
   10196              : 
   10197              :                for (i = 0; i < n; i += stride)
   10198              :                  ... = array[i];
   10199              : 
   10200              :              we generate a new induction variable and new accesses to
   10201              :              form a new vector (or vectors, depending on ncopies):
   10202              : 
   10203              :                for (j = 0; ; j += VF*stride)
   10204              :                  tmp1 = array[j];
   10205              :                  tmp2 = array[j + stride];
   10206              :                  ...
   10207              :                  vectemp = {tmp1, tmp2, ...}
   10208              :              */
   10209              : 
   10210         3348 :           ivstep = fold_build2 (MULT_EXPR, TREE_TYPE (stride_step), stride_step,
   10211              :                                 build_int_cst (TREE_TYPE (stride_step), vf));
   10212              : 
   10213         3348 :           standard_iv_increment_position (loop, &incr_gsi, &insert_after);
   10214              : 
   10215         3348 :           stride_base = cse_and_gimplify_to_preheader (loop_vinfo, stride_base);
   10216         3348 :           ivstep = cse_and_gimplify_to_preheader (loop_vinfo, ivstep);
   10217         3348 :           create_iv (stride_base, PLUS_EXPR, ivstep, NULL,
   10218              :                      loop, &incr_gsi, insert_after,
   10219              :                      &offvar, NULL);
   10220              : 
   10221         3348 :           stride_step = cse_and_gimplify_to_preheader (loop_vinfo, stride_step);
   10222              :         }
   10223              : 
   10224        22822 :       running_off = offvar;
   10225        22822 :       alias_off = build_int_cst (ref_type, 0);
   10226        22822 :       int nloads = const_nunits;
   10227        22822 :       int lnel = 1;
   10228        22822 :       tree ltype = TREE_TYPE (vectype);
   10229        22822 :       tree lvectype = vectype;
   10230        22822 :       auto_vec<tree> dr_chain;
   10231              :       /* ???  Modify local copies of alignment_support_scheme and
   10232              :          misalignment, but this part of analysis should be done
   10233              :          earlier and remembered, likewise the chosen load mode.  */
   10234        22822 :       const dr_alignment_support tem = alignment_support_scheme;
   10235        22822 :       dr_alignment_support alignment_support_scheme = tem;
   10236        22822 :       const int tem2 = misalignment;
   10237        22822 :       int misalignment = tem2;
   10238        22822 :       if (memory_access_type == VMAT_STRIDED_SLP)
   10239              :         {
   10240        16370 :           HOST_WIDE_INT n = gcd (group_size, const_nunits);
   10241              :           /* Use the target vector type if the group size is a multiple
   10242              :              of it.  */
   10243        16370 :           if (n == const_nunits)
   10244              :             {
   10245         1950 :               int mis_align = dr_misalignment (first_dr_info, vectype);
   10246              :               /* With VF > 1 we advance the DR by step, if that is constant
   10247              :                  and only aligned when performed VF times, DR alignment
   10248              :                  analysis can analyze this as aligned since it assumes
   10249              :                  contiguous accesses.  But that is not how we code generate
   10250              :                  here, so adjust for this.  */
   10251         1950 :               if (maybe_gt (vf, 1u)
   10252         3184 :                   && !multiple_p (DR_STEP_ALIGNMENT (first_dr_info->dr),
   10253         2980 :                                   DR_TARGET_ALIGNMENT (first_dr_info)))
   10254          204 :                 mis_align = -1;
   10255         1950 :               dr_alignment_support dr_align
   10256         1950 :                 = vect_supportable_dr_alignment (vinfo, dr_info, vectype,
   10257              :                                                  mis_align);
   10258         1950 :               if (dr_align == dr_aligned
   10259         1950 :                   || dr_align == dr_unaligned_supported)
   10260              :                 {
   10261        16370 :                   nloads = 1;
   10262        16370 :                   lnel = const_nunits;
   10263        16370 :                   ltype = vectype;
   10264        16370 :                   alignment_support_scheme = dr_align;
   10265        16370 :                   misalignment = mis_align;
   10266              :                 }
   10267              :             }
   10268              :           /* Else use the biggest vector we can load the group without
   10269              :              accessing excess elements.  */
   10270        14420 :           else if (n > 1)
   10271              :             {
   10272         1770 :               tree ptype;
   10273         1770 :               tree vtype
   10274         1770 :                 = vector_vector_composition_type (vectype, const_nunits / n,
   10275              :                                                   &ptype);
   10276         1770 :               if (vtype != NULL_TREE)
   10277              :                 {
   10278         1734 :                   dr_alignment_support dr_align;
   10279         1734 :                   int mis_align = 0;
   10280         1734 :                   if (VECTOR_TYPE_P (ptype))
   10281              :                     {
   10282          888 :                       mis_align = dr_misalignment (first_dr_info, ptype);
   10283          888 :                       if (maybe_gt (vf, 1u)
   10284         1748 :                           && !multiple_p (DR_STEP_ALIGNMENT (first_dr_info->dr),
   10285          894 :                                           DR_TARGET_ALIGNMENT (first_dr_info)))
   10286          854 :                         mis_align = -1;
   10287          888 :                       dr_align
   10288          888 :                         = vect_supportable_dr_alignment (vinfo, dr_info, ptype,
   10289              :                                                          mis_align);
   10290              :                     }
   10291              :                   else
   10292              :                     dr_align = dr_unaligned_supported;
   10293         1734 :                   if (dr_align == dr_aligned
   10294         1734 :                       || dr_align == dr_unaligned_supported)
   10295              :                     {
   10296         1734 :                       nloads = const_nunits / n;
   10297         1734 :                       lnel = n;
   10298         1734 :                       lvectype = vtype;
   10299         1734 :                       ltype = ptype;
   10300         1734 :                       alignment_support_scheme = dr_align;
   10301         1734 :                       misalignment = mis_align;
   10302              :                     }
   10303              :                 }
   10304              :             }
   10305        16370 :           unsigned align;
   10306        16370 :           if (alignment_support_scheme == dr_aligned)
   10307           12 :             align = known_alignment (DR_TARGET_ALIGNMENT (first_dr_info));
   10308              :           else
   10309        16358 :             align = dr_alignment (vect_dr_behavior (vinfo, first_dr_info));
   10310              :           /* Alignment is at most the access size if we do multiple loads.  */
   10311        16370 :           if (nloads > 1)
   10312        14420 :             align = MIN (tree_to_uhwi (TYPE_SIZE_UNIT (ltype)), align);
   10313        16370 :           ltype = build_aligned_type (ltype, align * BITS_PER_UNIT);
   10314              :         }
   10315              : 
   10316              :       /* For SLP permutation support we need to load the whole group,
   10317              :          not only the number of vector stmts the permutation result
   10318              :          fits in.  */
   10319        22822 :       int ncopies;
   10320        22822 :       if (ls.slp_perm)
   10321              :         {
   10322         2384 :           gcc_assert (memory_access_type != VMAT_ELEMENTWISE);
   10323              :           /* We don't yet generate SLP_TREE_LOAD_PERMUTATIONs for
   10324              :              variable VF.  */
   10325         2384 :           unsigned int const_vf = vf.to_constant ();
   10326         2384 :           ncopies = CEIL (group_size * const_vf, const_nunits);
   10327         2384 :           dr_chain.create (ncopies);
   10328              :         }
   10329              :       else
   10330              :         ncopies = vec_num;
   10331              : 
   10332        22822 :       unsigned int group_el = 0;
   10333        22822 :       unsigned HOST_WIDE_INT
   10334        22822 :         elsz = tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (vectype)));
   10335        22822 :       unsigned int n_groups = 0;
   10336              :       /* For costing some adjacent vector loads, we'd like to cost with
   10337              :          the total number of them once instead of cost each one by one. */
   10338        22822 :       unsigned int n_adjacent_loads = 0;
   10339        54292 :       for (j = 0; j < ncopies; j++)
   10340              :         {
   10341        31470 :           if (nloads > 1 && !costing_p)
   10342         2836 :             vec_alloc (v, nloads);
   10343              :           gimple *new_stmt = NULL;
   10344       134752 :           for (i = 0; i < nloads; i++)
   10345              :             {
   10346       103282 :               if (costing_p)
   10347              :                 {
   10348              :                   /* For VMAT_ELEMENTWISE, just cost it as scalar_load to
   10349              :                      avoid ICE, see PR110776.  */
   10350        93390 :                   if (VECTOR_TYPE_P (ltype)
   10351         4634 :                       && memory_access_type != VMAT_ELEMENTWISE)
   10352         4634 :                     n_adjacent_loads++;
   10353              :                   else
   10354        88756 :                     inside_cost += record_stmt_cost (cost_vec, 1, scalar_load,
   10355              :                                                      slp_node, 0, vect_body);
   10356        93390 :                   continue;
   10357              :                 }
   10358         9892 :               unsigned int load_el = group_el;
   10359              :               /* For elementwise accesses apply a load permutation directly.  */
   10360         9892 :               if (memory_access_type == VMAT_ELEMENTWISE
   10361         9892 :                   && SLP_TREE_LOAD_PERMUTATION (slp_node).exists ())
   10362         1978 :                 load_el = SLP_TREE_LOAD_PERMUTATION (slp_node)[group_el];
   10363         9892 :               tree this_off = build_int_cst (TREE_TYPE (alias_off),
   10364         9892 :                                              load_el * elsz + cst_offset);
   10365         9892 :               tree data_ref = build2 (MEM_REF, ltype, running_off, this_off);
   10366         9892 :               vect_copy_ref_info (data_ref, DR_REF (first_dr_info->dr));
   10367         9892 :               new_temp = make_ssa_name (ltype);
   10368         9892 :               new_stmt = gimple_build_assign (new_temp, data_ref);
   10369         9892 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
   10370         9892 :               if (nloads > 1)
   10371         8238 :                 CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, new_temp);
   10372              : 
   10373         9892 :               group_el += lnel;
   10374         9892 :               if (group_el == group_size)
   10375              :                 {
   10376         9497 :                   n_groups++;
   10377              :                   /* When doing SLP make sure to not load elements from
   10378              :                      the next vector iteration, those will not be accessed
   10379              :                      so just use the last element again.  See PR107451.  */
   10380         9497 :                   if (known_lt (n_groups, vf))
   10381              :                     {
   10382         6127 :                       tree newoff = copy_ssa_name (running_off);
   10383         6127 :                       gimple *incr
   10384         6127 :                         = gimple_build_assign (newoff, POINTER_PLUS_EXPR,
   10385              :                                                running_off, stride_step);
   10386         6127 :                       vect_finish_stmt_generation (vinfo, stmt_info, incr, gsi);
   10387         6127 :                       running_off = newoff;
   10388              :                     }
   10389              :                   group_el = 0;
   10390              :                 }
   10391              :             }
   10392              : 
   10393        31470 :           if (nloads > 1)
   10394              :             {
   10395        23188 :               if (costing_p)
   10396        20352 :                 inside_cost += record_stmt_cost (cost_vec, 1, vec_construct,
   10397              :                                                  slp_node, 0, vect_body);
   10398              :               else
   10399              :                 {
   10400         2836 :                   tree vec_inv = build_constructor (lvectype, v);
   10401         2836 :                   new_temp = vect_init_vector (vinfo, stmt_info, vec_inv,
   10402              :                                                lvectype, gsi);
   10403         2836 :                   new_stmt = SSA_NAME_DEF_STMT (new_temp);
   10404         2836 :                   if (lvectype != vectype)
   10405              :                     {
   10406          239 :                       new_stmt
   10407          239 :                         = gimple_build_assign (make_ssa_name (vectype),
   10408              :                                                VIEW_CONVERT_EXPR,
   10409              :                                                build1 (VIEW_CONVERT_EXPR,
   10410              :                                                        vectype, new_temp));
   10411          239 :                       vect_finish_stmt_generation (vinfo, stmt_info, new_stmt,
   10412              :                                                    gsi);
   10413              :                     }
   10414              :                 }
   10415              :             }
   10416         8282 :           else if (!costing_p && ltype != vectype)
   10417              :             {
   10418         1629 :               new_stmt = gimple_build_assign (make_ssa_name (vectype),
   10419              :                                               VIEW_CONVERT_EXPR,
   10420              :                                               build1 (VIEW_CONVERT_EXPR,
   10421              :                                                       vectype, new_temp));
   10422         1629 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt,
   10423              :                                            gsi);
   10424              :             }
   10425              : 
   10426        31470 :           if (!costing_p)
   10427              :             {
   10428         4490 :               if (ls.slp_perm)
   10429         1330 :                 dr_chain.quick_push (gimple_assign_lhs (new_stmt));
   10430              :               else
   10431         3160 :                 slp_node->push_vec_def (new_stmt);
   10432              :             }
   10433              :         }
   10434        22822 :       if (ls.slp_perm)
   10435              :         {
   10436         2384 :           if (costing_p)
   10437              :             {
   10438         1763 :               gcc_assert (ls.n_perms != -1U);
   10439         1763 :               inside_cost += record_stmt_cost (cost_vec, ls.n_perms, vec_perm,
   10440              :                                                slp_node, 0, vect_body);
   10441              :             }
   10442              :           else
   10443              :             {
   10444          621 :               unsigned n_perms2;
   10445          621 :               vect_transform_slp_perm_load (vinfo, slp_node, dr_chain, gsi, vf,
   10446              :                                             false, &n_perms2);
   10447          621 :               gcc_assert (ls.n_perms == n_perms2);
   10448              :             }
   10449              :         }
   10450              : 
   10451        22822 :       if (costing_p)
   10452              :         {
   10453        19474 :           if (n_adjacent_loads > 0)
   10454         1766 :             vect_get_load_cost (vinfo, stmt_info, slp_node, n_adjacent_loads,
   10455              :                                 alignment_support_scheme, misalignment, false,
   10456              :                                 &inside_cost, nullptr, cost_vec, cost_vec,
   10457              :                                 true);
   10458        19474 :           if (dump_enabled_p ())
   10459          494 :             dump_printf_loc (MSG_NOTE, vect_location,
   10460              :                              "vect_model_load_cost: inside_cost = %u, "
   10461              :                              "prologue_cost = 0 .\n",
   10462              :                              inside_cost);
   10463              :         }
   10464              : 
   10465        22822 :       return true;
   10466        22822 :     }
   10467              : 
   10468       506857 :   if (mat_gather_scatter_p (memory_access_type)
   10469       506857 :       && !ls.ls_type)
   10470              :     grouped_load = false;
   10471              : 
   10472       504130 :   if (grouped_load
   10473       506857 :       || SLP_TREE_LOAD_PERMUTATION (slp_node).exists ())
   10474              :     {
   10475       256214 :       if (grouped_load)
   10476              :         {
   10477       255825 :           first_stmt_info = DR_GROUP_FIRST_ELEMENT (stmt_info);
   10478       255825 :           group_size = DR_GROUP_SIZE (first_stmt_info);
   10479              :         }
   10480              :       else
   10481              :         {
   10482              :           first_stmt_info = stmt_info;
   10483              :           group_size = 1;
   10484              :         }
   10485              :       /* For SLP vectorization we directly vectorize a subchain
   10486              :          without permutation.  */
   10487       256214 :       if (! SLP_TREE_LOAD_PERMUTATION (slp_node).exists ())
   10488       207522 :         first_stmt_info = SLP_TREE_SCALAR_STMTS (slp_node)[0];
   10489              :       /* For BB vectorization always use the first stmt to base
   10490              :          the data ref pointer on.  */
   10491       256214 :       if (bb_vinfo)
   10492       208716 :         first_stmt_info_for_drptr
   10493       208716 :           = vect_find_first_scalar_stmt_in_slp (slp_node);
   10494              : 
   10495       256214 :       first_dr_info = STMT_VINFO_DR_INFO (first_stmt_info);
   10496       256214 :       group_gap_adj = 0;
   10497              : 
   10498              :       /* VEC_NUM is the number of vect stmts to be created for this group.  */
   10499       256214 :       grouped_load = false;
   10500              :       /* If an SLP permutation is from N elements to N elements,
   10501              :          and if one vector holds a whole number of N, we can load
   10502              :          the inputs to the permutation in the same way as an
   10503              :          unpermuted sequence.  In other cases we need to load the
   10504              :          whole group, not only the number of vector stmts the
   10505              :          permutation result fits in.  */
   10506       256214 :       unsigned scalar_lanes = SLP_TREE_LANES (slp_node);
   10507       256214 :       if (nested_in_vect_loop)
   10508              :         /* We do not support grouped accesses in a nested loop,
   10509              :            instead the access is contiguous but it might be
   10510              :            permuted.  No gap adjustment is needed though.  */
   10511              :         ;
   10512       256212 :       else if (ls.slp_perm
   10513       256212 :                && (group_size != scalar_lanes
   10514        11088 :                    || !multiple_p (nunits, group_size)))
   10515              :         {
   10516              :           /* We don't yet generate such SLP_TREE_LOAD_PERMUTATIONs for
   10517              :              variable VF; see vect_transform_slp_perm_load.  */
   10518        38707 :           unsigned int const_vf = vf.to_constant ();
   10519        38707 :           unsigned int const_nunits = nunits.to_constant ();
   10520        38707 :           vec_num = CEIL (group_size * const_vf, const_nunits);
   10521        38707 :           group_gap_adj = vf * group_size - nunits * vec_num;
   10522              :         }
   10523              :       else
   10524              :         {
   10525       217505 :           group_gap_adj = group_size - scalar_lanes;
   10526              :         }
   10527              : 
   10528       256214 :       ref_type = get_group_alias_ptr_type (first_stmt_info);
   10529              :     }
   10530              :   else
   10531              :     {
   10532       250643 :       first_stmt_info = stmt_info;
   10533       250643 :       first_dr_info = dr_info;
   10534       250643 :       group_size = 1;
   10535       250643 :       group_gap_adj = 0;
   10536       250643 :       ref_type = reference_alias_ptr_type (DR_REF (first_dr_info->dr));
   10537              :     }
   10538              : 
   10539       506857 :   vec_loop_masks *loop_masks
   10540       298141 :     = (loop_vinfo && LOOP_VINFO_FULLY_MASKED_P (loop_vinfo)
   10541       506857 :        ? &LOOP_VINFO_MASKS (loop_vinfo)
   10542           31 :        : NULL);
   10543           31 :   vec_loop_lens *loop_lens
   10544       298141 :     = (loop_vinfo && LOOP_VINFO_FULLY_WITH_LENGTH_P (loop_vinfo)
   10545              :        ? &LOOP_VINFO_LENS (loop_vinfo)
   10546            0 :        : NULL);
   10547              : 
   10548              :   /* The vect_transform_stmt and vect_analyze_stmt will go here but there
   10549              :      are some difference here.  We cannot enable both the lens and masks
   10550              :      during transform but it is allowed during analysis.
   10551              :      Shouldn't go with length-based approach if fully masked.  */
   10552       506857 :   if (cost_vec == NULL)
   10553              :     /* The cost_vec is NULL during transfrom.  */
   10554       161683 :     gcc_assert ((!loop_lens || !loop_masks));
   10555              : 
   10556              :   /* Targets with store-lane instructions must not require explicit
   10557              :      realignment.  vect_supportable_dr_alignment always returns either
   10558              :      dr_aligned or dr_unaligned_supported for (non-length) masked
   10559              :      operations.  */
   10560       506857 :   gcc_assert ((memory_access_type != VMAT_LOAD_STORE_LANES
   10561              :                && !mask_node
   10562              :                && !loop_masks)
   10563              :               || mat_gather_scatter_p (memory_access_type)
   10564              :               || alignment_support_scheme == dr_aligned
   10565              :               || alignment_support_scheme == dr_unaligned_supported);
   10566              : 
   10567              :   /* In case the vectorization factor (VF) is bigger than the number
   10568              :      of elements that we can fit in a vectype (nunits), we have to generate
   10569              :      more than one vector stmt - i.e - we need to "unroll" the
   10570              :      vector stmt by a factor VF/nunits.  In doing so, we record a pointer
   10571              :      from one copy of the vector stmt to the next, in the field
   10572              :      STMT_VINFO_RELATED_STMT.  This is necessary in order to allow following
   10573              :      stages to find the correct vector defs to be used when vectorizing
   10574              :      stmts that use the defs of the current stmt.  The example below
   10575              :      illustrates the vectorization process when VF=16 and nunits=4 (i.e., we
   10576              :      need to create 4 vectorized stmts):
   10577              : 
   10578              :      before vectorization:
   10579              :                                 RELATED_STMT    VEC_STMT
   10580              :         S1:     x = memref      -               -
   10581              :         S2:     z = x + 1       -               -
   10582              : 
   10583              :      step 1: vectorize stmt S1:
   10584              :         We first create the vector stmt VS1_0, and, as usual, record a
   10585              :         pointer to it in the STMT_VINFO_VEC_STMT of the scalar stmt S1.
   10586              :         Next, we create the vector stmt VS1_1, and record a pointer to
   10587              :         it in the STMT_VINFO_RELATED_STMT of the vector stmt VS1_0.
   10588              :         Similarly, for VS1_2 and VS1_3.  This is the resulting chain of
   10589              :         stmts and pointers:
   10590              :                                 RELATED_STMT    VEC_STMT
   10591              :         VS1_0:  vx0 = memref0   VS1_1           -
   10592              :         VS1_1:  vx1 = memref1   VS1_2           -
   10593              :         VS1_2:  vx2 = memref2   VS1_3           -
   10594              :         VS1_3:  vx3 = memref3   -               -
   10595              :         S1:     x = load        -               VS1_0
   10596              :         S2:     z = x + 1       -               -
   10597              :   */
   10598              : 
   10599              :   /* If the data reference is aligned (dr_aligned) or potentially unaligned
   10600              :      on a target that supports unaligned accesses (dr_unaligned_supported)
   10601              :      we generate the following code:
   10602              :          p = initial_addr;
   10603              :          indx = 0;
   10604              :          loop {
   10605              :            p = p + indx * vectype_size;
   10606              :            vec_dest = *(p);
   10607              :            indx = indx + 1;
   10608              :          }
   10609              : 
   10610              :      Otherwise, the data reference is potentially unaligned on a target that
   10611              :      does not support unaligned accesses (dr_explicit_realign_optimized) -
   10612              :      then generate the following code, in which the data in each iteration is
   10613              :      obtained by two vector loads, one from the previous iteration, and one
   10614              :      from the current iteration:
   10615              :          p1 = initial_addr;
   10616              :          msq_init = *(floor(p1))
   10617              :          p2 = initial_addr + VS - 1;
   10618              :          realignment_token = call target_builtin;
   10619              :          indx = 0;
   10620              :          loop {
   10621              :            p2 = p2 + indx * vectype_size
   10622              :            lsq = *(floor(p2))
   10623              :            vec_dest = realign_load (msq, lsq, realignment_token)
   10624              :            indx = indx + 1;
   10625              :            msq = lsq;
   10626              :          }   */
   10627              : 
   10628              :   /* If the misalignment remains the same throughout the execution of the
   10629              :      loop, we can create the init_addr and permutation mask at the loop
   10630              :      preheader.  Otherwise, it needs to be created inside the loop.
   10631              :      This can only occur when vectorizing memory accesses in the inner-loop
   10632              :      nested within an outer-loop that is being vectorized.  */
   10633              : 
   10634       506857 :   if (nested_in_vect_loop
   10635       506857 :       && !multiple_p (DR_STEP_ALIGNMENT (dr_info->dr),
   10636         1200 :                       GET_MODE_SIZE (TYPE_MODE (vectype))))
   10637              :     {
   10638          191 :       gcc_assert (alignment_support_scheme != dr_explicit_realign_optimized);
   10639              :       compute_in_loop = true;
   10640              :     }
   10641              : 
   10642       506857 :   bool diff_first_stmt_info
   10643       506857 :     = first_stmt_info_for_drptr && first_stmt_info != first_stmt_info_for_drptr;
   10644              : 
   10645       506857 :   tree offset = NULL_TREE;
   10646       506857 :   if ((alignment_support_scheme == dr_explicit_realign_optimized
   10647       506857 :        || alignment_support_scheme == dr_explicit_realign)
   10648            0 :       && !compute_in_loop)
   10649              :     {
   10650              :       /* If we have different first_stmt_info, we can't set up realignment
   10651              :          here, since we can't guarantee first_stmt_info DR has been
   10652              :          initialized yet, use first_stmt_info_for_drptr DR by bumping the
   10653              :          distance from first_stmt_info DR instead as below.  */
   10654            0 :       if (!costing_p)
   10655              :         {
   10656            0 :           if (!diff_first_stmt_info)
   10657            0 :             msq = vect_setup_realignment (vinfo, first_stmt_info, vectype, gsi,
   10658              :                                           &realignment_token,
   10659              :                                           alignment_support_scheme, NULL_TREE,
   10660              :                                           &at_loop);
   10661            0 :           if (alignment_support_scheme == dr_explicit_realign_optimized)
   10662              :             {
   10663            0 :               phi = as_a<gphi *> (SSA_NAME_DEF_STMT (msq));
   10664            0 :               offset = size_binop (MINUS_EXPR, TYPE_SIZE_UNIT (vectype),
   10665              :                                    size_one_node);
   10666            0 :               gcc_assert (!first_stmt_info_for_drptr);
   10667              :             }
   10668              :         }
   10669              :     }
   10670              :   else
   10671       506857 :     at_loop = loop;
   10672              : 
   10673       506857 :   if (!known_eq (poffset, 0))
   10674         4384 :     offset = (offset
   10675         4384 :               ? size_binop (PLUS_EXPR, offset, size_int (poffset))
   10676         4384 :               : size_int (poffset));
   10677              : 
   10678       506857 :   tree bump;
   10679       506857 :   tree vec_offset = NULL_TREE;
   10680              : 
   10681       506857 :   auto_vec<tree> vec_offsets;
   10682       506857 :   auto_vec<tree> vec_masks;
   10683       506857 :   if (mask_node && !costing_p)
   10684          634 :     vect_get_slp_defs (SLP_TREE_CHILDREN (slp_node)[mask_index],
   10685              :                        &vec_masks);
   10686              : 
   10687       506857 :   tree vec_mask = NULL_TREE;
   10688       506857 :   tree vec_els = NULL_TREE;
   10689       506857 :   if (memory_access_type == VMAT_LOAD_STORE_LANES)
   10690              :     {
   10691            0 :       const internal_fn lanes_ifn = ls.lanes_ifn;
   10692              : 
   10693            0 :       gcc_assert (alignment_support_scheme == dr_aligned
   10694              :                   || alignment_support_scheme == dr_unaligned_supported);
   10695              : 
   10696            0 :       aggr_type = build_array_type_nelts (elem_type, group_size * nunits);
   10697            0 :       if (!costing_p)
   10698            0 :         bump = vect_get_data_ptr_increment (vinfo, gsi, dr_info, aggr_type,
   10699              :                                             memory_access_type, loop_lens);
   10700              : 
   10701            0 :       unsigned int inside_cost = 0, prologue_cost = 0;
   10702              :       /* For costing some adjacent vector loads, we'd like to cost with
   10703              :          the total number of them once instead of cost each one by one. */
   10704            0 :       unsigned int n_adjacent_loads = 0;
   10705            0 :       int ncopies = vec_num / group_size;
   10706            0 :       for (j = 0; j < ncopies; j++)
   10707              :         {
   10708            0 :           if (costing_p)
   10709              :             {
   10710              :               /* An IFN_LOAD_LANES will load all its vector results,
   10711              :                  regardless of which ones we actually need.  Account
   10712              :                  for the cost of unused results.  */
   10713            0 :               if (first_stmt_info == stmt_info)
   10714              :                 {
   10715            0 :                   unsigned int gaps = DR_GROUP_SIZE (first_stmt_info);
   10716            0 :                   stmt_vec_info next_stmt_info = first_stmt_info;
   10717            0 :                   do
   10718              :                     {
   10719            0 :                       gaps -= 1;
   10720            0 :                       next_stmt_info = DR_GROUP_NEXT_ELEMENT (next_stmt_info);
   10721              :                     }
   10722            0 :                   while (next_stmt_info);
   10723            0 :                   if (gaps)
   10724              :                     {
   10725            0 :                       if (dump_enabled_p ())
   10726            0 :                         dump_printf_loc (MSG_NOTE, vect_location,
   10727              :                                          "vect_model_load_cost: %d "
   10728              :                                          "unused vectors.\n",
   10729              :                                          gaps);
   10730            0 :                       vect_get_load_cost (vinfo, stmt_info, slp_node, gaps,
   10731              :                                           alignment_support_scheme,
   10732              :                                           misalignment, false, &inside_cost,
   10733              :                                           &prologue_cost, cost_vec, cost_vec,
   10734              :                                           true);
   10735              :                     }
   10736              :                 }
   10737            0 :               n_adjacent_loads++;
   10738            0 :               continue;
   10739            0 :             }
   10740              : 
   10741              :           /* 1. Create the vector or array pointer update chain.  */
   10742            0 :           if (j == 0)
   10743            0 :             dataref_ptr
   10744            0 :               = vect_create_data_ref_ptr (vinfo, first_stmt_info, aggr_type,
   10745              :                                           at_loop, offset, &dummy, gsi,
   10746              :                                           &ptr_incr, false, bump);
   10747              :           else
   10748              :             {
   10749            0 :               gcc_assert (!LOOP_VINFO_USING_SELECT_VL_P (loop_vinfo));
   10750            0 :               dataref_ptr = bump_vector_ptr (vinfo, dataref_ptr, ptr_incr, gsi,
   10751              :                                              stmt_info, bump);
   10752              :             }
   10753            0 :           if (mask_node)
   10754            0 :             vec_mask = vec_masks[j];
   10755              : 
   10756            0 :           tree vec_array = create_vector_array (vectype, group_size);
   10757              : 
   10758            0 :           tree final_mask = NULL_TREE;
   10759            0 :           tree final_len = NULL_TREE;
   10760            0 :           tree bias = NULL_TREE;
   10761            0 :           if (loop_masks)
   10762            0 :             final_mask = vect_get_loop_mask (loop_vinfo, gsi, loop_masks,
   10763              :                                              ncopies, vectype, j);
   10764            0 :           if (vec_mask)
   10765            0 :             final_mask = prepare_vec_mask (loop_vinfo, mask_vectype, final_mask,
   10766              :                                            vec_mask, gsi);
   10767              : 
   10768            0 :           if (lanes_ifn == IFN_MASK_LEN_LOAD_LANES)
   10769              :             {
   10770            0 :               if (loop_lens)
   10771            0 :                 final_len = vect_get_loop_len (loop_vinfo, gsi, loop_lens,
   10772              :                                                ncopies, vectype, j, 1, true);
   10773              :               else
   10774            0 :                 final_len = size_int (TYPE_VECTOR_SUBPARTS (vectype));
   10775            0 :               signed char biasval
   10776            0 :                 = LOOP_VINFO_PARTIAL_LOAD_STORE_BIAS (loop_vinfo);
   10777            0 :               bias = build_int_cst (intQI_type_node, biasval);
   10778            0 :               if (!final_mask)
   10779              :                 {
   10780            0 :                   mask_vectype = truth_type_for (vectype);
   10781            0 :                   final_mask = build_minus_one_cst (mask_vectype);
   10782              :                 }
   10783              :             }
   10784              : 
   10785            0 :           if (final_mask)
   10786              :             {
   10787            0 :               vec_els = vect_get_mask_load_else (maskload_elsval, vectype);
   10788            0 :               if (type_mode_padding_p
   10789            0 :                   && maskload_elsval != MASK_LOAD_ELSE_ZERO)
   10790            0 :                 need_zeroing = true;
   10791              :             }
   10792              : 
   10793            0 :           gcall *call;
   10794            0 :           if (final_len && final_mask)
   10795              :             {
   10796              :               /* Emit:
   10797              :                    VEC_ARRAY = MASK_LEN_LOAD_LANES (DATAREF_PTR, ALIAS_PTR,
   10798              :                                                     VEC_MASK, LEN, BIAS).  */
   10799            0 :               unsigned int align = TYPE_ALIGN (TREE_TYPE (vectype));
   10800            0 :               tree alias_ptr = build_int_cst (ref_type, align);
   10801            0 :               call = gimple_build_call_internal (IFN_MASK_LEN_LOAD_LANES, 6,
   10802              :                                                  dataref_ptr, alias_ptr,
   10803              :                                                  final_mask, vec_els,
   10804              :                                                  final_len, bias);
   10805              :             }
   10806            0 :           else if (final_mask)
   10807              :             {
   10808              :               /* Emit:
   10809              :                    VEC_ARRAY = MASK_LOAD_LANES (DATAREF_PTR, ALIAS_PTR,
   10810              :                                                 VEC_MASK).  */
   10811            0 :               unsigned int align = TYPE_ALIGN (TREE_TYPE (vectype));
   10812            0 :               tree alias_ptr = build_int_cst (ref_type, align);
   10813            0 :               call = gimple_build_call_internal (IFN_MASK_LOAD_LANES, 4,
   10814              :                                                  dataref_ptr, alias_ptr,
   10815              :                                                  final_mask, vec_els);
   10816              :             }
   10817              :           else
   10818              :             {
   10819              :               /* Emit:
   10820              :                    VEC_ARRAY = LOAD_LANES (MEM_REF[...all elements...]).  */
   10821            0 :               data_ref = create_array_ref (aggr_type, dataref_ptr, ref_type);
   10822            0 :               call = gimple_build_call_internal (IFN_LOAD_LANES, 1, data_ref);
   10823              :             }
   10824            0 :           gimple_call_set_lhs (call, vec_array);
   10825            0 :           gimple_call_set_nothrow (call, true);
   10826            0 :           vect_finish_stmt_generation (vinfo, stmt_info, call, gsi);
   10827              : 
   10828              :           /* Extract each vector into an SSA_NAME.  */
   10829            0 :           for (unsigned i = 0; i < group_size; i++)
   10830              :             {
   10831            0 :               new_temp = read_vector_array (vinfo, stmt_info, gsi, scalar_dest,
   10832              :                                             vec_array, i, need_zeroing,
   10833              :                                             final_mask);
   10834            0 :               slp_node->push_vec_def (new_temp);
   10835              :             }
   10836              : 
   10837              :           /* Record that VEC_ARRAY is now dead.  */
   10838            0 :           vect_clobber_variable (vinfo, stmt_info, gsi, vec_array);
   10839              :         }
   10840              : 
   10841            0 :       if (costing_p)
   10842              :         {
   10843            0 :           if (n_adjacent_loads > 0)
   10844            0 :             vect_get_load_cost (vinfo, stmt_info, slp_node, n_adjacent_loads,
   10845              :                                 alignment_support_scheme, misalignment, false,
   10846              :                                 &inside_cost, &prologue_cost, cost_vec,
   10847              :                                 cost_vec, true);
   10848            0 :           if (dump_enabled_p ())
   10849            0 :             dump_printf_loc (MSG_NOTE, vect_location,
   10850              :                              "vect_model_load_cost: inside_cost = %u, "
   10851              :                              "prologue_cost = %u .\n",
   10852              :                              inside_cost, prologue_cost);
   10853              :         }
   10854              : 
   10855            0 :       return true;
   10856              :     }
   10857              : 
   10858       506857 :   if (mat_gather_scatter_p (memory_access_type))
   10859              :     {
   10860         2727 :       gcc_assert ((!grouped_load && !ls.slp_perm) || ls.ls_type);
   10861              : 
   10862         2727 :       auto_vec<tree> dr_chain (vec_num);
   10863              : 
   10864              :       /* If we pun the original vectype the loads as well as costing, length,
   10865              :          etc. is performed with the new type.  After loading we VIEW_CONVERT
   10866              :          the data to the original vectype.  */
   10867         2727 :       tree original_vectype = vectype;
   10868         2727 :       if (ls.ls_type)
   10869            0 :         vectype = ls.ls_type;
   10870              : 
   10871              :       /* 1. Create the vector or array pointer update chain.  */
   10872         2727 :       if (STMT_VINFO_GATHER_SCATTER_P (stmt_info))
   10873              :         {
   10874         2727 :           aggr_type = NULL_TREE;
   10875         2727 :           bump = NULL_TREE;
   10876         2727 :           if (!costing_p)
   10877          749 :             vect_get_gather_scatter_ops (loop, slp_node, &dataref_ptr,
   10878              :                                          &vec_offsets);
   10879              :         }
   10880              :       else
   10881              :         {
   10882            0 :           aggr_type = elem_type;
   10883            0 :           if (!costing_p)
   10884              :             {
   10885            0 :               vect_get_strided_load_store_ops (stmt_info, slp_node, vectype,
   10886              :                                                ls.strided_offset_vectype,
   10887              :                                                loop_vinfo, gsi,
   10888              :                                                &bump, &vec_offset, loop_lens);
   10889            0 :               dataref_ptr
   10890            0 :                   = vect_create_data_ref_ptr (vinfo, first_stmt_info, aggr_type,
   10891              :                                               at_loop, offset, &dummy, gsi,
   10892              :                                               &ptr_incr, false, bump);
   10893              :             }
   10894              :         }
   10895              : 
   10896              :       unsigned int inside_cost = 0, prologue_cost = 0;
   10897              : 
   10898         6147 :       gimple *new_stmt = NULL;
   10899         6147 :       for (i = 0; i < vec_num; i++)
   10900              :         {
   10901         3420 :           tree final_mask = NULL_TREE;
   10902         3420 :           tree final_len = NULL_TREE;
   10903         3420 :           tree bias = NULL_TREE;
   10904         3420 :           if (!costing_p)
   10905              :             {
   10906          963 :               if (mask_node)
   10907          153 :                 vec_mask = vec_masks[i];
   10908          963 :               if (loop_masks)
   10909            0 :                 final_mask = vect_get_loop_mask (loop_vinfo, gsi, loop_masks,
   10910              :                                                  vec_num, vectype, i);
   10911          963 :               if (vec_mask)
   10912          153 :                 final_mask = prepare_vec_mask (loop_vinfo, mask_vectype,
   10913              :                                                final_mask, vec_mask, gsi);
   10914              : 
   10915          963 :               if (i > 0 && !STMT_VINFO_GATHER_SCATTER_P (stmt_info))
   10916            0 :                 dataref_ptr = bump_vector_ptr (vinfo, dataref_ptr, ptr_incr,
   10917              :                                                gsi, stmt_info, bump);
   10918              :             }
   10919              : 
   10920              :           /* 2. Create the vector-load in the loop.  */
   10921         3420 :           unsigned align = get_object_alignment (DR_REF (first_dr_info->dr));
   10922         3420 :           tree alias_align_ptr = build_int_cst (ref_type, align);
   10923         3420 :           if (memory_access_type == VMAT_GATHER_SCATTER_IFN)
   10924              :             {
   10925            0 :               if (costing_p)
   10926              :                 {
   10927            0 :                   if (ls.supported_offset_vectype)
   10928            0 :                     inside_cost
   10929            0 :                       += record_stmt_cost (cost_vec, 1, vector_stmt,
   10930              :                                            slp_node, 0, vect_body);
   10931            0 :                   if (ls.supported_scale)
   10932            0 :                     inside_cost
   10933            0 :                       += record_stmt_cost (cost_vec, 1, vector_stmt,
   10934              :                                            slp_node, 0, vect_body);
   10935              : 
   10936            0 :                   unsigned int cnunits = vect_nunits_for_cost (vectype);
   10937            0 :                   inside_cost
   10938            0 :                     = record_stmt_cost (cost_vec, cnunits, scalar_load,
   10939              :                                         slp_node, 0, vect_body);
   10940         3420 :                   continue;
   10941            0 :                 }
   10942            0 :               if (STMT_VINFO_GATHER_SCATTER_P (stmt_info))
   10943            0 :                 vec_offset = vec_offsets[i];
   10944            0 :               tree zero = build_zero_cst (vectype);
   10945            0 :               tree scale = size_int (SLP_TREE_GS_SCALE (slp_node));
   10946            0 :               bool strided = !VECTOR_TYPE_P (TREE_TYPE (vec_offset));
   10947              : 
   10948              :               /* Perform the offset conversion and scaling if necessary.  */
   10949            0 :               if (!strided
   10950            0 :                   && (ls.supported_offset_vectype || ls.supported_scale))
   10951              :                 {
   10952            0 :                   gimple_seq stmts = NULL;
   10953            0 :                   if (ls.supported_offset_vectype)
   10954            0 :                     vec_offset = gimple_convert
   10955            0 :                       (&stmts, ls.supported_offset_vectype, vec_offset);
   10956            0 :                   if (ls.supported_scale)
   10957              :                     {
   10958              :                       /* Only scale the vec_offset if we haven't already.  */
   10959            0 :                       if (STMT_VINFO_GATHER_SCATTER_P (stmt_info)
   10960            0 :                           || i == 0)
   10961              :                         {
   10962            0 :                           tree mult_cst = build_int_cst
   10963            0 :                             (TREE_TYPE (TREE_TYPE (vec_offset)),
   10964            0 :                              SLP_TREE_GS_SCALE (slp_node) / ls.supported_scale);
   10965            0 :                           tree mult = build_vector_from_val
   10966            0 :                             (TREE_TYPE (vec_offset), mult_cst);
   10967            0 :                           vec_offset = gimple_build
   10968            0 :                             (&stmts, MULT_EXPR, TREE_TYPE (vec_offset),
   10969              :                              vec_offset, mult);
   10970              :                         }
   10971            0 :                       scale = size_int (ls.supported_scale);
   10972              :                     }
   10973            0 :                   gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
   10974              :                 }
   10975              : 
   10976            0 :               if (ls.gs.ifn == IFN_MASK_LEN_GATHER_LOAD)
   10977              :                 {
   10978            0 :                   if (loop_lens)
   10979            0 :                     final_len = vect_get_loop_len (loop_vinfo, gsi, loop_lens,
   10980              :                                                    vec_num, vectype, i, 1, true);
   10981              :                   else
   10982            0 :                     final_len = build_int_cst (sizetype,
   10983            0 :                                                TYPE_VECTOR_SUBPARTS (vectype));
   10984            0 :                   signed char biasval
   10985            0 :                     = LOOP_VINFO_PARTIAL_LOAD_STORE_BIAS (loop_vinfo);
   10986            0 :                   bias = build_int_cst (intQI_type_node, biasval);
   10987            0 :                   if (!final_mask)
   10988              :                     {
   10989            0 :                       mask_vectype = truth_type_for (vectype);
   10990            0 :                       final_mask = build_minus_one_cst (mask_vectype);
   10991              :                     }
   10992              :                 }
   10993              : 
   10994            0 :               if (final_mask)
   10995              :                 {
   10996            0 :                   vec_els = vect_get_mask_load_else (maskload_elsval, vectype);
   10997            0 :                   if (type_mode_padding_p
   10998            0 :                       && maskload_elsval != MASK_LOAD_ELSE_ZERO)
   10999            0 :                     need_zeroing = true;
   11000              :                 }
   11001              : 
   11002            0 :               gcall *call;
   11003            0 :               if (final_len && final_mask)
   11004              :                 {
   11005            0 :                   if (VECTOR_TYPE_P (TREE_TYPE (vec_offset)))
   11006            0 :                     call = gimple_build_call_internal (IFN_MASK_LEN_GATHER_LOAD,
   11007              :                                                        9, dataref_ptr,
   11008              :                                                        alias_align_ptr,
   11009              :                                                        vec_offset, scale, zero,
   11010              :                                                        final_mask, vec_els,
   11011              :                                                        final_len, bias);
   11012              :                   else
   11013              :                     /* Non-vector offset indicates that prefer to take
   11014              :                        MASK_LEN_STRIDED_LOAD instead of the
   11015              :                        MASK_LEN_GATHER_LOAD with direct stride arg.  */
   11016            0 :                     call = gimple_build_call_internal
   11017            0 :                              (IFN_MASK_LEN_STRIDED_LOAD, 7, dataref_ptr,
   11018              :                               vec_offset, zero, final_mask, vec_els, final_len,
   11019              :                               bias);
   11020              :                 }
   11021            0 :               else if (final_mask)
   11022            0 :                 call = gimple_build_call_internal (IFN_MASK_GATHER_LOAD,
   11023              :                                                    7, dataref_ptr,
   11024              :                                                    alias_align_ptr,
   11025              :                                                    vec_offset, scale,
   11026              :                                                    zero, final_mask, vec_els);
   11027              :               else
   11028            0 :                 call = gimple_build_call_internal (IFN_GATHER_LOAD, 5,
   11029              :                                                    dataref_ptr,
   11030              :                                                    alias_align_ptr,
   11031              :                                                    vec_offset, scale, zero);
   11032            0 :               gimple_call_set_nothrow (call, true);
   11033            0 :               new_stmt = call;
   11034            0 :               data_ref = NULL_TREE;
   11035              :             }
   11036         3420 :           else if (memory_access_type == VMAT_GATHER_SCATTER_LEGACY)
   11037              :             {
   11038              :               /* The builtin decls path for gather is legacy, x86 only.  */
   11039          570 :               gcc_assert (!final_len && nunits.is_constant ());
   11040          570 :               if (costing_p)
   11041              :                 {
   11042          287 :                   unsigned int cnunits = vect_nunits_for_cost (vectype);
   11043          287 :                   inside_cost
   11044          287 :                     = record_stmt_cost (cost_vec, cnunits, scalar_load,
   11045              :                                         slp_node, 0, vect_body);
   11046          287 :                   continue;
   11047          287 :                 }
   11048          283 :               tree offset_vectype = TREE_TYPE (vec_offsets[0]);
   11049          283 :               poly_uint64 offset_nunits = TYPE_VECTOR_SUBPARTS (offset_vectype);
   11050          283 :               if (known_eq (nunits, offset_nunits))
   11051              :                 {
   11052          134 :                   new_stmt = vect_build_one_gather_load_call
   11053          134 :                                (vinfo, stmt_info, slp_node, vectype, gsi,
   11054          134 :                                 ls.gs.decl, dataref_ptr, vec_offsets[i],
   11055              :                                 final_mask);
   11056          134 :                   data_ref = NULL_TREE;
   11057              :                 }
   11058          149 :               else if (known_eq (nunits, offset_nunits * 2))
   11059              :                 {
   11060              :                   /* We have a offset vector with half the number of
   11061              :                      lanes but the builtins will produce full vectype
   11062              :                      data with just the lower lanes filled.  */
   11063           63 :                   new_stmt = vect_build_one_gather_load_call
   11064          126 :                                (vinfo, stmt_info, slp_node, vectype, gsi,
   11065           63 :                                 ls.gs.decl, dataref_ptr, vec_offsets[2 * i],
   11066              :                                 final_mask);
   11067           63 :                   tree low = make_ssa_name (vectype);
   11068           63 :                   gimple_set_lhs (new_stmt, low);
   11069           63 :                   vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
   11070              : 
   11071              :                   /* now put upper half of final_mask in final_mask low. */
   11072           63 :                   if (final_mask
   11073           63 :                       && !SCALAR_INT_MODE_P (TYPE_MODE (TREE_TYPE (final_mask))))
   11074              :                     {
   11075           11 :                       int count = nunits.to_constant ();
   11076           11 :                       vec_perm_builder sel (count, count, 1);
   11077           11 :                       sel.quick_grow (count);
   11078           87 :                       for (int i = 0; i < count; ++i)
   11079           76 :                         sel[i] = i | (count / 2);
   11080           11 :                       vec_perm_indices indices (sel, 2, count);
   11081           11 :                       tree perm_mask = vect_gen_perm_mask_checked
   11082           11 :                                          (TREE_TYPE (final_mask), indices);
   11083           11 :                       new_stmt = gimple_build_assign (NULL_TREE, VEC_PERM_EXPR,
   11084              :                                                       final_mask, final_mask,
   11085              :                                                       perm_mask);
   11086           11 :                       final_mask = make_ssa_name (TREE_TYPE (final_mask));
   11087           11 :                       gimple_set_lhs (new_stmt, final_mask);
   11088           11 :                       vect_finish_stmt_generation (vinfo, stmt_info,
   11089              :                                                    new_stmt, gsi);
   11090           11 :                     }
   11091           52 :                   else if (final_mask)
   11092              :                     {
   11093           24 :                       new_stmt = gimple_build_assign (NULL_TREE,
   11094              :                                                       VEC_UNPACK_HI_EXPR,
   11095              :                                                       final_mask);
   11096           24 :                       final_mask = make_ssa_name
   11097           24 :                                     (truth_type_for (offset_vectype));
   11098           24 :                       gimple_set_lhs (new_stmt, final_mask);
   11099           24 :                       vect_finish_stmt_generation (vinfo, stmt_info,
   11100              :                                                    new_stmt, gsi);
   11101              :                     }
   11102              : 
   11103           63 :                   new_stmt = vect_build_one_gather_load_call
   11104          126 :                                (vinfo, stmt_info, slp_node, vectype, gsi,
   11105              :                                 ls.gs.decl, dataref_ptr,
   11106           63 :                                 vec_offsets[2 * i + 1], final_mask);
   11107           63 :                   tree high = make_ssa_name (vectype);
   11108           63 :                   gimple_set_lhs (new_stmt, high);
   11109           63 :                   vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
   11110              : 
   11111              :                   /* compose low + high.  */
   11112           63 :                   int count = nunits.to_constant ();
   11113           63 :                   vec_perm_builder sel (count, count, 1);
   11114           63 :                   sel.quick_grow (count);
   11115          647 :                   for (int i = 0; i < count; ++i)
   11116          584 :                     sel[i] = i < count / 2 ? i : i + count / 2;
   11117           63 :                   vec_perm_indices indices (sel, 2, count);
   11118           63 :                   tree perm_mask
   11119           63 :                     = vect_gen_perm_mask_checked (vectype, indices);
   11120           63 :                   new_stmt = gimple_build_assign (NULL_TREE, VEC_PERM_EXPR,
   11121              :                                                   low, high, perm_mask);
   11122           63 :                   data_ref = NULL_TREE;
   11123           63 :                 }
   11124           86 :               else if (known_eq (nunits * 2, offset_nunits))
   11125              :                 {
   11126              :                   /* We have a offset vector with double the number of
   11127              :                      lanes.  Select the low/high part accordingly.  */
   11128           86 :                   vec_offset = vec_offsets[i / 2];
   11129           86 :                   if (i & 1)
   11130              :                     {
   11131           43 :                       int count = offset_nunits.to_constant ();
   11132           43 :                       vec_perm_builder sel (count, count, 1);
   11133           43 :                       sel.quick_grow (count);
   11134          463 :                       for (int i = 0; i < count; ++i)
   11135          420 :                         sel[i] = i | (count / 2);
   11136           43 :                       vec_perm_indices indices (sel, 2, count);
   11137           43 :                       tree perm_mask = vect_gen_perm_mask_checked
   11138           43 :                                          (TREE_TYPE (vec_offset), indices);
   11139           43 :                       new_stmt = gimple_build_assign (NULL_TREE, VEC_PERM_EXPR,
   11140              :                                                       vec_offset, vec_offset,
   11141              :                                                       perm_mask);
   11142           43 :                       vec_offset = make_ssa_name (TREE_TYPE (vec_offset));
   11143           43 :                       gimple_set_lhs (new_stmt, vec_offset);
   11144           43 :                       vect_finish_stmt_generation (vinfo, stmt_info,
   11145              :                                                    new_stmt, gsi);
   11146           43 :                     }
   11147           86 :                   new_stmt = vect_build_one_gather_load_call
   11148           86 :                                (vinfo, stmt_info, slp_node, vectype, gsi,
   11149              :                                 ls.gs.decl,
   11150              :                                 dataref_ptr, vec_offset, final_mask);
   11151           86 :                   data_ref = NULL_TREE;
   11152              :                 }
   11153              :               else
   11154            0 :                 gcc_unreachable ();
   11155              :             }
   11156              :           else
   11157              :             {
   11158              :               /* Emulated gather-scatter.  */
   11159         2850 :               gcc_assert (!final_mask);
   11160         2850 :               unsigned HOST_WIDE_INT const_nunits = nunits.to_constant ();
   11161         2850 :               if (costing_p)
   11162              :                 {
   11163              :                   /* For emulated gathers N offset vector element
   11164              :                      offset add is consumed by the load).  */
   11165         2170 :                   inside_cost = record_stmt_cost (cost_vec, const_nunits,
   11166              :                                                   vec_to_scalar,
   11167              :                                                   slp_node, 0, vect_body);
   11168              :                   /* N scalar loads plus gathering them into a
   11169              :                      vector.  */
   11170         2170 :                   inside_cost
   11171         2170 :                     = record_stmt_cost (cost_vec, const_nunits, scalar_load,
   11172              :                                         slp_node, 0, vect_body);
   11173         2170 :                   inside_cost
   11174         2170 :                     = record_stmt_cost (cost_vec, 1, vec_construct,
   11175              :                                         slp_node, 0, vect_body);
   11176         2170 :                   continue;
   11177              :                 }
   11178          680 :               tree offset_vectype = TREE_TYPE (vec_offsets[0]);
   11179          680 :               unsigned HOST_WIDE_INT const_offset_nunits
   11180          680 :                 = TYPE_VECTOR_SUBPARTS (offset_vectype).to_constant ();
   11181          680 :               vec<constructor_elt, va_gc> *ctor_elts;
   11182          680 :               vec_alloc (ctor_elts, const_nunits);
   11183          680 :               gimple_seq stmts = NULL;
   11184              :               /* We support offset vectors with more elements
   11185              :                  than the data vector for now.  */
   11186          680 :               unsigned HOST_WIDE_INT factor
   11187              :                 = const_offset_nunits / const_nunits;
   11188          680 :               vec_offset = vec_offsets[i / factor];
   11189          680 :               unsigned elt_offset = (i % factor) * const_nunits;
   11190          680 :               tree idx_type = TREE_TYPE (TREE_TYPE (vec_offset));
   11191          680 :               tree scale = size_int (SLP_TREE_GS_SCALE (slp_node));
   11192          680 :               tree ltype = build_aligned_type (TREE_TYPE (vectype), align);
   11193         2828 :               for (unsigned k = 0; k < const_nunits; ++k)
   11194              :                 {
   11195         2148 :                   tree boff = size_binop (MULT_EXPR, TYPE_SIZE (idx_type),
   11196              :                                           bitsize_int (k + elt_offset));
   11197         6444 :                   tree idx = gimple_build (&stmts, BIT_FIELD_REF, idx_type,
   11198         2148 :                                            vec_offset, TYPE_SIZE (idx_type),
   11199              :                                            boff);
   11200         2148 :                   idx = gimple_convert (&stmts, sizetype, idx);
   11201         2148 :                   idx = gimple_build (&stmts, MULT_EXPR, sizetype, idx, scale);
   11202         2148 :                   tree ptr = gimple_build (&stmts, PLUS_EXPR,
   11203         2148 :                                            TREE_TYPE (dataref_ptr),
   11204              :                                            dataref_ptr, idx);
   11205         2148 :                   ptr = gimple_convert (&stmts, ptr_type_node, ptr);
   11206         2148 :                   tree elt = make_ssa_name (TREE_TYPE (vectype));
   11207         2148 :                   tree ref = build2 (MEM_REF, ltype, ptr,
   11208              :                                      build_int_cst (ref_type, 0));
   11209         2148 :                   new_stmt = gimple_build_assign (elt, ref);
   11210         4296 :                   gimple_set_vuse (new_stmt, gimple_vuse (gsi_stmt (*gsi)));
   11211         2148 :                   gimple_seq_add_stmt (&stmts, new_stmt);
   11212         2148 :                   CONSTRUCTOR_APPEND_ELT (ctor_elts, NULL_TREE, elt);
   11213              :                 }
   11214          680 :               gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
   11215          680 :               new_stmt = gimple_build_assign (NULL_TREE,
   11216              :                                               build_constructor (vectype,
   11217              :                                                                  ctor_elts));
   11218          680 :               data_ref = NULL_TREE;
   11219              :             }
   11220              : 
   11221          963 :           vec_dest = vect_create_destination_var (scalar_dest, vectype);
   11222              :           /* DATA_REF is null if we've already built the statement.  */
   11223          963 :           if (data_ref)
   11224              :             {
   11225              :               vect_copy_ref_info (data_ref, DR_REF (first_dr_info->dr));
   11226              :               new_stmt = gimple_build_assign (vec_dest, data_ref);
   11227              :             }
   11228         1926 :           new_temp = (need_zeroing
   11229          963 :                       ? make_ssa_name (vectype)
   11230          963 :                       : make_ssa_name (vec_dest, new_stmt));
   11231          963 :           gimple_set_lhs (new_stmt, new_temp);
   11232          963 :           vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
   11233              : 
   11234              :           /* If we need to explicitly zero inactive elements emit a
   11235              :              VEC_COND_EXPR that does so.  */
   11236          963 :           if (need_zeroing)
   11237              :             {
   11238            0 :               vec_els = vect_get_mask_load_else (MASK_LOAD_ELSE_ZERO,
   11239              :                                                  vectype);
   11240              : 
   11241            0 :               tree new_temp2 = make_ssa_name (vec_dest, new_stmt);
   11242            0 :               new_stmt = gimple_build_assign (new_temp2, VEC_COND_EXPR,
   11243              :                                               final_mask, new_temp, vec_els);
   11244            0 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
   11245            0 :               new_temp = new_temp2;
   11246              :             }
   11247              : 
   11248          963 :           if (ls.ls_type)
   11249              :             {
   11250            0 :               new_stmt = gimple_build_assign (make_ssa_name
   11251              :                                               (original_vectype),
   11252              :                                               VIEW_CONVERT_EXPR,
   11253              :                                               build1 (VIEW_CONVERT_EXPR,
   11254              :                                                       original_vectype,
   11255              :                                                       new_temp));
   11256            0 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
   11257              :             }
   11258              : 
   11259              :           /* Store vector loads in the corresponding SLP_NODE.  */
   11260          963 :           if (!costing_p)
   11261              :             {
   11262          963 :               if (ls.slp_perm)
   11263            0 :                 dr_chain.quick_push (gimple_assign_lhs (new_stmt));
   11264              :               else
   11265          963 :                 slp_node->push_vec_def (new_stmt);
   11266              :             }
   11267              :         }
   11268              : 
   11269         2727 :       if (ls.slp_perm)
   11270              :         {
   11271            0 :           if (costing_p)
   11272              :             {
   11273            0 :               gcc_assert (ls.n_perms != -1U);
   11274            0 :               inside_cost += record_stmt_cost (cost_vec, ls.n_perms, vec_perm,
   11275              :                                                slp_node, 0, vect_body);
   11276              :             }
   11277              :           else
   11278              :             {
   11279            0 :               unsigned n_perms2;
   11280            0 :               vect_transform_slp_perm_load (vinfo, slp_node, dr_chain, gsi, vf,
   11281              :                                             false, &n_perms2);
   11282            0 :               gcc_assert (ls.n_perms == n_perms2);
   11283              :             }
   11284              :         }
   11285              : 
   11286         2727 :       if (costing_p && dump_enabled_p ())
   11287          222 :         dump_printf_loc (MSG_NOTE, vect_location,
   11288              :                          "vect_model_load_cost: inside_cost = %u, "
   11289              :                          "prologue_cost = %u .\n",
   11290              :                          inside_cost, prologue_cost);
   11291         2727 :       return true;
   11292         2727 :     }
   11293              : 
   11294       504130 :   aggr_type = vectype;
   11295       504130 :   if (!costing_p)
   11296       160934 :     bump = vect_get_data_ptr_increment (vinfo, gsi, dr_info, aggr_type,
   11297              :                                         memory_access_type, loop_lens);
   11298              : 
   11299       504130 :   poly_uint64 group_elt = 0;
   11300       504130 :   unsigned int inside_cost = 0, prologue_cost = 0;
   11301              :   /* For costing some adjacent vector loads, we'd like to cost with
   11302              :      the total number of them once instead of cost each one by one. */
   11303       504130 :   unsigned int n_adjacent_loads = 0;
   11304              : 
   11305              :   /* 1. Create the vector or array pointer update chain.  */
   11306       504130 :   if (!costing_p)
   11307              :     {
   11308       160934 :       bool simd_lane_access_p
   11309       160934 :           = STMT_VINFO_SIMD_LANE_ACCESS_P (stmt_info) != 0;
   11310       160934 :       if (simd_lane_access_p
   11311         1629 :           && TREE_CODE (DR_BASE_ADDRESS (first_dr_info->dr)) == ADDR_EXPR
   11312         1629 :           && VAR_P (TREE_OPERAND (DR_BASE_ADDRESS (first_dr_info->dr), 0))
   11313         1629 :           && integer_zerop (get_dr_vinfo_offset (vinfo, first_dr_info))
   11314         1629 :           && integer_zerop (DR_INIT (first_dr_info->dr))
   11315         1629 :           && alias_sets_conflict_p (get_alias_set (aggr_type),
   11316         1629 :                                     get_alias_set (TREE_TYPE (ref_type)))
   11317       160934 :           && (alignment_support_scheme == dr_aligned
   11318         1629 :               || alignment_support_scheme == dr_unaligned_supported))
   11319              :         {
   11320         1629 :           dataref_ptr = unshare_expr (DR_BASE_ADDRESS (first_dr_info->dr));
   11321         1629 :           dataref_offset = build_int_cst (ref_type, 0);
   11322              :         }
   11323       159305 :       else if (diff_first_stmt_info)
   11324              :         {
   11325         3478 :           dataref_ptr
   11326         3478 :             = vect_create_data_ref_ptr (vinfo, first_stmt_info_for_drptr,
   11327              :                                         aggr_type, at_loop, offset, &dummy,
   11328              :                                         gsi, &ptr_incr, simd_lane_access_p,
   11329              :                                         bump);
   11330              :           /* Adjust the pointer by the difference to first_stmt.  */
   11331         3478 :           data_reference_p ptrdr
   11332              :             = STMT_VINFO_DATA_REF (first_stmt_info_for_drptr);
   11333         3478 :           tree diff = fold_convert (sizetype,
   11334              :                                     size_binop (MINUS_EXPR,
   11335              :                                                 DR_INIT (first_dr_info->dr),
   11336              :                                                 DR_INIT (ptrdr)));
   11337         3478 :           dataref_ptr = bump_vector_ptr (vinfo, dataref_ptr, ptr_incr, gsi,
   11338              :                                          stmt_info, diff);
   11339         3478 :           if (alignment_support_scheme == dr_explicit_realign)
   11340              :             {
   11341            0 :               msq = vect_setup_realignment (vinfo, first_stmt_info_for_drptr,
   11342              :                                             vectype, gsi,
   11343              :                                             &realignment_token,
   11344              :                                             alignment_support_scheme,
   11345              :                                             dataref_ptr, &at_loop);
   11346            0 :               gcc_assert (!compute_in_loop);
   11347              :             }
   11348              :         }
   11349              :       else
   11350       155827 :         dataref_ptr
   11351       155827 :           = vect_create_data_ref_ptr (vinfo, first_stmt_info, aggr_type,
   11352              :                                       at_loop,
   11353              :                                       offset, &dummy, gsi, &ptr_incr,
   11354              :                                       simd_lane_access_p, bump);
   11355              :     }
   11356              :   else if (!costing_p)
   11357              :     {
   11358              :       gcc_assert (!LOOP_VINFO_USING_SELECT_VL_P (loop_vinfo));
   11359              :       if (dataref_offset)
   11360              :         dataref_offset = int_const_binop (PLUS_EXPR, dataref_offset, bump);
   11361              :       else
   11362              :         dataref_ptr = bump_vector_ptr (vinfo, dataref_ptr, ptr_incr, gsi,
   11363              :                                        stmt_info, bump);
   11364              :     }
   11365              : 
   11366       504130 :   auto_vec<tree> dr_chain;
   11367       504130 :   if (grouped_load || ls.slp_perm)
   11368        48692 :     dr_chain.create (vec_num);
   11369              : 
   11370              :   gimple *new_stmt = NULL;
   11371      1334175 :   for (i = 0; i < vec_num; i++)
   11372              :     {
   11373       830045 :       tree final_mask = NULL_TREE;
   11374       830045 :       tree final_len = NULL_TREE;
   11375       830045 :       tree bias = NULL_TREE;
   11376              : 
   11377       830045 :       if (!costing_p)
   11378              :         {
   11379       251108 :           if (mask_node)
   11380          707 :             vec_mask = vec_masks[i];
   11381       251108 :           if (loop_masks)
   11382           48 :             final_mask = vect_get_loop_mask (loop_vinfo, gsi, loop_masks,
   11383              :                                              vec_num, vectype, i);
   11384       251108 :           if (vec_mask)
   11385          707 :             final_mask = prepare_vec_mask (loop_vinfo, mask_vectype,
   11386              :                                            final_mask, vec_mask, gsi);
   11387              : 
   11388       251108 :           if (i > 0)
   11389        90174 :             dataref_ptr = bump_vector_ptr (vinfo, dataref_ptr, ptr_incr,
   11390              :                                            gsi, stmt_info, bump);
   11391              :         }
   11392              : 
   11393              :       /* 2. Create the vector-load in the loop.  */
   11394       830045 :       switch (alignment_support_scheme)
   11395              :         {
   11396       830045 :         case dr_aligned:
   11397       830045 :         case dr_unaligned_supported:
   11398       830045 :           {
   11399       830045 :             if (costing_p)
   11400              :               break;
   11401              : 
   11402       251108 :             unsigned int misalign;
   11403       251108 :             unsigned HOST_WIDE_INT align;
   11404       251108 :             align = known_alignment (DR_TARGET_ALIGNMENT (first_dr_info));
   11405       251108 :             if (alignment_support_scheme == dr_aligned)
   11406              :               misalign = 0;
   11407       162843 :             else if (misalignment == DR_MISALIGNMENT_UNKNOWN)
   11408              :               {
   11409       124014 :                 align = dr_alignment (vect_dr_behavior (vinfo, first_dr_info));
   11410       124014 :                 misalign = 0;
   11411              :               }
   11412              :             else
   11413        38829 :               misalign = misalignment;
   11414       251108 :             if (dataref_offset == NULL_TREE
   11415       248981 :                 && TREE_CODE (dataref_ptr) == SSA_NAME)
   11416       169910 :               set_ptr_info_alignment (get_ptr_info (dataref_ptr), align,
   11417              :                                       misalign);
   11418       251108 :             align = least_bit_hwi (misalign | align);
   11419              : 
   11420              :             /* Compute IFN when LOOP_LENS or final_mask valid.  */
   11421       251108 :             machine_mode vmode = TYPE_MODE (vectype);
   11422       251108 :             machine_mode new_vmode = vmode;
   11423       251108 :             internal_fn partial_ifn = IFN_LAST;
   11424       251108 :             if (loop_lens)
   11425              :               {
   11426            0 :                 opt_machine_mode new_ovmode
   11427            0 :                   = get_len_load_store_mode (vmode, true, &partial_ifn);
   11428            0 :                 new_vmode = new_ovmode.require ();
   11429            0 :                 unsigned factor
   11430            0 :                   = (new_ovmode == vmode) ? 1 : GET_MODE_UNIT_SIZE (vmode);
   11431            0 :                 final_len = vect_get_loop_len (loop_vinfo, gsi, loop_lens,
   11432              :                                                vec_num, vectype, i, factor, true);
   11433              :               }
   11434       251108 :             else if (final_mask)
   11435              :               {
   11436          735 :                 if (!can_vec_mask_load_store_p (vmode,
   11437          735 :                                                 TYPE_MODE
   11438              :                                                   (TREE_TYPE (final_mask)),
   11439              :                                                 true, &partial_ifn))
   11440            0 :                   gcc_unreachable ();
   11441              :               }
   11442              : 
   11443       251108 :             if (partial_ifn == IFN_MASK_LEN_LOAD)
   11444              :               {
   11445            0 :                 if (!final_len)
   11446              :                   {
   11447              :                     /* Pass VF value to 'len' argument of
   11448              :                        MASK_LEN_LOAD if LOOP_LENS is invalid.  */
   11449            0 :                     final_len = size_int (TYPE_VECTOR_SUBPARTS (vectype));
   11450              :                   }
   11451            0 :                 if (!final_mask)
   11452              :                   {
   11453              :                     /* Pass all ones value to 'mask' argument of
   11454              :                        MASK_LEN_LOAD if final_mask is invalid.  */
   11455            0 :                     mask_vectype = truth_type_for (vectype);
   11456            0 :                     final_mask = build_minus_one_cst (mask_vectype);
   11457              :                   }
   11458              :               }
   11459       251108 :             if (final_len)
   11460              :               {
   11461            0 :                 signed char biasval
   11462            0 :                   = LOOP_VINFO_PARTIAL_LOAD_STORE_BIAS (loop_vinfo);
   11463            0 :                 bias = build_int_cst (intQI_type_node, biasval);
   11464              :               }
   11465              : 
   11466       251108 :             tree vec_els;
   11467              : 
   11468       251108 :             if (final_len)
   11469              :               {
   11470            0 :                 tree ptr = build_int_cst (ref_type, align * BITS_PER_UNIT);
   11471            0 :                 gcall *call;
   11472              : 
   11473              :                 /* Need conversion if the vectype is punned by VnQI.  */
   11474            0 :                 els_vectype = vectype;
   11475            0 :                 if (vmode != new_vmode)
   11476            0 :                   els_vectype
   11477            0 :                     = build_vector_type_for_mode (unsigned_intQI_type_node,
   11478              :                                                   new_vmode);
   11479            0 :                 vec_els = vect_get_mask_load_else (maskload_elsval,
   11480              :                                                    els_vectype);
   11481              : 
   11482            0 :                 if (partial_ifn == IFN_MASK_LEN_LOAD)
   11483              :                   {
   11484            0 :                     if (type_mode_padding_p
   11485            0 :                         && maskload_elsval != MASK_LOAD_ELSE_ZERO)
   11486            0 :                       need_zeroing = true;
   11487            0 :                     call = gimple_build_call_internal (IFN_MASK_LEN_LOAD,
   11488              :                                                        6, dataref_ptr, ptr,
   11489              :                                                        final_mask, vec_els,
   11490              :                                                        final_len, bias);
   11491              :                   }
   11492              :                 else
   11493            0 :                   call = gimple_build_call_internal (IFN_LEN_LOAD, 5,
   11494              :                                                      dataref_ptr, ptr,
   11495              :                                                      vec_els, final_len,
   11496              :                                                      bias);
   11497            0 :                 gimple_call_set_nothrow (call, true);
   11498            0 :                 new_stmt = call;
   11499            0 :                 data_ref = NULL_TREE;
   11500              : 
   11501              :                 /* Need conversion if it's wrapped with VnQI.  */
   11502            0 :                 if (vmode != new_vmode)
   11503              :                   {
   11504            0 :                     tree new_vtype
   11505            0 :                       = build_vector_type_for_mode (unsigned_intQI_type_node,
   11506              :                                                     new_vmode);
   11507            0 :                     tree var = vect_get_new_ssa_name (new_vtype,
   11508              :                                                       vect_simple_var);
   11509            0 :                     gimple_set_lhs (call, var);
   11510            0 :                     vect_finish_stmt_generation (vinfo, stmt_info, call,
   11511              :                                                  gsi);
   11512            0 :                     tree op = build1 (VIEW_CONVERT_EXPR, vectype, var);
   11513            0 :                     new_stmt = gimple_build_assign (vec_dest,
   11514              :                                                     VIEW_CONVERT_EXPR, op);
   11515              :                   }
   11516              :               }
   11517       251108 :             else if (final_mask)
   11518              :               {
   11519          735 :                 tree ptr = build_int_cst (ref_type, align * BITS_PER_UNIT);
   11520          735 :                 vec_els = vect_get_mask_load_else (maskload_elsval, vectype);
   11521          735 :                 if (type_mode_padding_p
   11522          735 :                     && maskload_elsval != MASK_LOAD_ELSE_ZERO)
   11523            0 :                   need_zeroing = true;
   11524          735 :                 gcall *call = gimple_build_call_internal (IFN_MASK_LOAD, 4,
   11525              :                                                           dataref_ptr, ptr,
   11526              :                                                           final_mask,
   11527              :                                                           vec_els);
   11528          735 :                 gimple_call_set_nothrow (call, true);
   11529          735 :                 new_stmt = call;
   11530          735 :                 data_ref = NULL_TREE;
   11531              :               }
   11532              :             else
   11533              :               {
   11534       250373 :                 tree ltype = vectype;
   11535       250373 :                 tree new_vtype = NULL_TREE;
   11536       250373 :                 unsigned HOST_WIDE_INT gap = DR_GROUP_GAP (first_stmt_info);
   11537       250373 :                 unsigned HOST_WIDE_INT dr_size
   11538       250373 :                   = vect_get_scalar_dr_size (first_dr_info);
   11539       250373 :                 poly_int64 off = 0;
   11540       250373 :                 if (memory_access_type == VMAT_CONTIGUOUS_REVERSE)
   11541         1431 :                   off = (TYPE_VECTOR_SUBPARTS (vectype) - 1) * -dr_size;
   11542       250373 :                 unsigned int vect_align
   11543       250373 :                   = vect_known_alignment_in_bytes (first_dr_info, vectype,
   11544       250373 :                                                    off);
   11545              :                 /* Try to use a single smaller load when we are about
   11546              :                    to load excess elements compared to the unrolled
   11547              :                    scalar loop.  */
   11548       250373 :                 if (known_gt ((i + 1) * nunits,
   11549              :                               (group_size * vf - gap)))
   11550              :                   {
   11551         6850 :                     poly_uint64 remain = ((group_size * vf - gap) - i * nunits);
   11552         6850 :                     if (known_ge ((i + 1) * nunits - (group_size * vf - gap),
   11553              :                                   nunits))
   11554              :                       /* DR will be unused.  */
   11555              :                       ltype = NULL_TREE;
   11556         2179 :                     else if (known_ge (vect_align,
   11557              :                                        tree_to_poly_uint64
   11558              :                                          (TYPE_SIZE_UNIT (vectype))))
   11559              :                       /* Aligned access to excess elements is OK if
   11560              :                          at least one element is accessed in the
   11561              :                          scalar loop.  */
   11562              :                       ;
   11563         1840 :                     else if (known_gt (vect_align,
   11564              :                                        ((nunits - remain) * dr_size)))
   11565              :                       /* Aligned access to the gap area when there's
   11566              :                          at least one element in it is OK.  */
   11567              :                       ;
   11568              :                     else
   11569              :                       {
   11570              :                         /* remain should now be > 0 and < nunits.  */
   11571         1837 :                         unsigned num;
   11572         1837 :                         if (known_ne (remain, 0u)
   11573         1837 :                             && constant_multiple_p (nunits, remain, &num))
   11574              :                           {
   11575         1379 :                             tree ptype;
   11576         1379 :                             new_vtype
   11577         1379 :                               = vector_vector_composition_type (vectype, num,
   11578              :                                                                 &ptype);
   11579         1379 :                             if (new_vtype)
   11580         1379 :                               ltype = ptype;
   11581              :                           }
   11582              :                         /* Else use multiple loads or a masked load?  */
   11583              :                         /* For loop vectorization we now should have
   11584              :                            an alternate type or LOOP_VINFO_PEELING_FOR_GAPS
   11585              :                            set.  */
   11586         1837 :                         if (loop_vinfo)
   11587         1598 :                           gcc_assert (new_vtype
   11588              :                                       || LOOP_VINFO_PEELING_FOR_GAPS
   11589              :                                            (loop_vinfo));
   11590              :                         /* But still reduce the access size to the next
   11591              :                            required power-of-two so peeling a single
   11592              :                            scalar iteration is sufficient.  */
   11593         1837 :                         unsigned HOST_WIDE_INT cremain;
   11594         1837 :                         if (remain.is_constant (&cremain))
   11595              :                           {
   11596         1837 :                             unsigned HOST_WIDE_INT cpart_size
   11597         1837 :                               = 1 << ceil_log2 (cremain);
   11598         1837 :                             if (known_gt (nunits, cpart_size)
   11599         1837 :                                 && constant_multiple_p (nunits, cpart_size,
   11600              :                                                         &num))
   11601              :                               {
   11602         1391 :                                 tree ptype;
   11603         1391 :                                 new_vtype
   11604         2782 :                                   = vector_vector_composition_type (vectype,
   11605         1391 :                                                                     num,
   11606              :                                                                     &ptype);
   11607         1391 :                                 if (new_vtype)
   11608         1391 :                                   ltype = ptype;
   11609              :                               }
   11610              :                           }
   11611              :                       }
   11612              :                   }
   11613       250373 :                 tree offset = (dataref_offset ? dataref_offset
   11614       248246 :                                : build_int_cst (ref_type, 0));
   11615       250373 :                 if (!ltype)
   11616              :                   ;
   11617       245702 :                 else if (ltype != vectype
   11618       245702 :                          && memory_access_type == VMAT_CONTIGUOUS_REVERSE)
   11619              :                   {
   11620           21 :                     poly_uint64 gap_offset
   11621           21 :                       = (tree_to_poly_uint64 (TYPE_SIZE_UNIT (vectype))
   11622           21 :                          - tree_to_poly_uint64 (TYPE_SIZE_UNIT (ltype)));
   11623           21 :                     tree gapcst = build_int_cstu (ref_type, gap_offset);
   11624           21 :                     offset = size_binop (PLUS_EXPR, offset, gapcst);
   11625              :                   }
   11626       250373 :                 if (ltype)
   11627              :                   {
   11628       245702 :                     data_ref = fold_build2 (MEM_REF, ltype,
   11629              :                                             dataref_ptr, offset);
   11630       245702 :                     if (alignment_support_scheme == dr_aligned
   11631       245702 :                         && align >= TYPE_ALIGN_UNIT (ltype))
   11632              :                       ;
   11633              :                     else
   11634       161127 :                       TREE_TYPE (data_ref)
   11635       322254 :                         = build_aligned_type (TREE_TYPE (data_ref),
   11636              :                                               align * BITS_PER_UNIT);
   11637              :                   }
   11638       250373 :                 if (!ltype)
   11639         4671 :                   data_ref = build_constructor (vectype, NULL);
   11640       245702 :                 else if (ltype != vectype)
   11641              :                   {
   11642         1391 :                     vect_copy_ref_info (data_ref,
   11643         1391 :                                         DR_REF (first_dr_info->dr));
   11644         1391 :                     tree tem = make_ssa_name (ltype);
   11645         1391 :                     new_stmt = gimple_build_assign (tem, data_ref);
   11646         1391 :                     vect_finish_stmt_generation (vinfo, stmt_info, new_stmt,
   11647              :                                                  gsi);
   11648         1391 :                     data_ref = NULL;
   11649         1391 :                     vec<constructor_elt, va_gc> *v;
   11650              :                     /* We've computed 'num' above to statically two
   11651              :                        or via constant_multiple_p.  */
   11652         1391 :                     unsigned num
   11653         1391 :                       = (exact_div (tree_to_poly_uint64
   11654         1391 :                                       (TYPE_SIZE_UNIT (vectype)),
   11655              :                                     tree_to_poly_uint64
   11656         1391 :                                       (TYPE_SIZE_UNIT (ltype)))
   11657         1391 :                          .to_constant ());
   11658         1391 :                     vec_alloc (v, num);
   11659         1391 :                     if (memory_access_type == VMAT_CONTIGUOUS_REVERSE)
   11660              :                       {
   11661           54 :                         while (--num)
   11662           54 :                           CONSTRUCTOR_APPEND_ELT (v, NULL_TREE,
   11663              :                                                   build_zero_cst (ltype));
   11664           21 :                         CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, tem);
   11665              :                       }
   11666              :                     else
   11667              :                       {
   11668         1370 :                         CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, tem);
   11669         1370 :                         while (--num)
   11670         3094 :                           CONSTRUCTOR_APPEND_ELT (v, NULL_TREE,
   11671              :                                                   build_zero_cst (ltype));
   11672              :                       }
   11673         1391 :                     gcc_assert (new_vtype != NULL_TREE);
   11674         1391 :                     if (new_vtype == vectype)
   11675         1361 :                       new_stmt
   11676         1361 :                         = gimple_build_assign (vec_dest,
   11677              :                                                build_constructor (vectype, v));
   11678              :                     else
   11679              :                       {
   11680           30 :                         tree new_vname = make_ssa_name (new_vtype);
   11681           30 :                         new_stmt
   11682           30 :                           = gimple_build_assign (new_vname,
   11683              :                                                  build_constructor (new_vtype,
   11684              :                                                                     v));
   11685           30 :                         vect_finish_stmt_generation (vinfo, stmt_info,
   11686              :                                                      new_stmt, gsi);
   11687           30 :                         new_stmt
   11688           30 :                           = gimple_build_assign (vec_dest,
   11689              :                                                  build1 (VIEW_CONVERT_EXPR,
   11690              :                                                          vectype, new_vname));
   11691              :                       }
   11692              :                   }
   11693              :               }
   11694              :             break;
   11695              :           }
   11696            0 :         case dr_explicit_realign:
   11697            0 :           {
   11698            0 :             if (costing_p)
   11699              :               break;
   11700            0 :             tree ptr, bump;
   11701              : 
   11702            0 :             tree vs = size_int (TYPE_VECTOR_SUBPARTS (vectype));
   11703              : 
   11704            0 :             if (compute_in_loop)
   11705            0 :               msq = vect_setup_realignment (vinfo, first_stmt_info, vectype,
   11706              :                                             gsi, &realignment_token,
   11707              :                                             dr_explicit_realign,
   11708              :                                             dataref_ptr, NULL);
   11709              : 
   11710            0 :             if (TREE_CODE (dataref_ptr) == SSA_NAME)
   11711            0 :               ptr = copy_ssa_name (dataref_ptr);
   11712              :             else
   11713            0 :               ptr = make_ssa_name (TREE_TYPE (dataref_ptr));
   11714              :             // For explicit realign the target alignment should be
   11715              :             // known at compile time.
   11716            0 :             unsigned HOST_WIDE_INT align
   11717            0 :               = DR_TARGET_ALIGNMENT (first_dr_info).to_constant ();
   11718            0 :             new_stmt = gimple_build_assign (ptr, BIT_AND_EXPR, dataref_ptr,
   11719              :                                             build_int_cst
   11720            0 :                                               (TREE_TYPE (dataref_ptr),
   11721            0 :                                                -(HOST_WIDE_INT) align));
   11722            0 :             vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
   11723            0 :             data_ref = build2 (MEM_REF, vectype,
   11724              :                                ptr, build_int_cst (ref_type, 0));
   11725            0 :             vect_copy_ref_info (data_ref, DR_REF (first_dr_info->dr));
   11726            0 :             vec_dest = vect_create_destination_var (scalar_dest, vectype);
   11727            0 :             new_stmt = gimple_build_assign (vec_dest, data_ref);
   11728            0 :             new_temp = make_ssa_name (vec_dest, new_stmt);
   11729            0 :             gimple_assign_set_lhs (new_stmt, new_temp);
   11730            0 :             gimple_move_vops (new_stmt, stmt_info->stmt);
   11731            0 :             vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
   11732            0 :             msq = new_temp;
   11733              : 
   11734            0 :             bump = size_binop (MULT_EXPR, vs, TYPE_SIZE_UNIT (elem_type));
   11735            0 :             bump = size_binop (MINUS_EXPR, bump, size_one_node);
   11736            0 :             ptr = bump_vector_ptr (vinfo, dataref_ptr, NULL, gsi, stmt_info,
   11737              :                                    bump);
   11738            0 :             new_stmt = gimple_build_assign (NULL_TREE, BIT_AND_EXPR, ptr,
   11739            0 :                                             build_int_cst (TREE_TYPE (ptr),
   11740            0 :                                                            -(HOST_WIDE_INT) align));
   11741            0 :             if (TREE_CODE (ptr) == SSA_NAME)
   11742            0 :               ptr = copy_ssa_name (ptr, new_stmt);
   11743              :             else
   11744            0 :               ptr = make_ssa_name (TREE_TYPE (ptr), new_stmt);
   11745            0 :             gimple_assign_set_lhs (new_stmt, ptr);
   11746            0 :             vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
   11747            0 :             data_ref = build2 (MEM_REF, vectype,
   11748              :                                ptr, build_int_cst (ref_type, 0));
   11749            0 :             break;
   11750              :           }
   11751            0 :         case dr_explicit_realign_optimized:
   11752            0 :           {
   11753            0 :             if (costing_p)
   11754              :               break;
   11755            0 :             if (TREE_CODE (dataref_ptr) == SSA_NAME)
   11756            0 :               new_temp = copy_ssa_name (dataref_ptr);
   11757              :             else
   11758            0 :               new_temp = make_ssa_name (TREE_TYPE (dataref_ptr));
   11759              :             // We should only be doing this if we know the target
   11760              :             // alignment at compile time.
   11761            0 :             unsigned HOST_WIDE_INT align
   11762            0 :               = DR_TARGET_ALIGNMENT (first_dr_info).to_constant ();
   11763            0 :             new_stmt = gimple_build_assign (new_temp, BIT_AND_EXPR, dataref_ptr,
   11764            0 :                                             build_int_cst (TREE_TYPE (dataref_ptr),
   11765            0 :                                                            -(HOST_WIDE_INT) align));
   11766            0 :             vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
   11767            0 :             data_ref = build2 (MEM_REF, vectype, new_temp,
   11768              :                                build_int_cst (ref_type, 0));
   11769            0 :             break;
   11770              :           }
   11771            0 :         default:
   11772            0 :         gcc_unreachable ();
   11773              :         }
   11774              : 
   11775              :       /* One common place to cost the above vect load for different
   11776              :          alignment support schemes.  */
   11777       830045 :       if (costing_p)
   11778              :         {
   11779              :           /* For the prologue cost for realign,
   11780              :              we only need to count it once for the whole group.  */
   11781       578937 :           bool first_stmt_info_p = first_stmt_info == stmt_info;
   11782       578937 :           bool add_realign_cost = first_stmt_info_p && i == 0;
   11783       578937 :           if (memory_access_type == VMAT_CONTIGUOUS
   11784       578937 :               || memory_access_type == VMAT_CONTIGUOUS_REVERSE)
   11785              :             {
   11786              :               /* Leave realign cases alone to keep them simple.  */
   11787       578937 :               if (alignment_support_scheme == dr_explicit_realign_optimized
   11788              :                   || alignment_support_scheme == dr_explicit_realign)
   11789            0 :                 vect_get_load_cost (vinfo, stmt_info, slp_node, 1,
   11790              :                                     alignment_support_scheme, misalignment,
   11791              :                                     add_realign_cost, &inside_cost,
   11792              :                                     &prologue_cost, cost_vec, cost_vec,
   11793              :                                     true);
   11794              :               else
   11795       578937 :                 n_adjacent_loads++;
   11796              :             }
   11797              :         }
   11798              :       else
   11799              :         {
   11800       251108 :           vec_dest = vect_create_destination_var (scalar_dest, vectype);
   11801              :           /* DATA_REF is null if we've already built the statement.  */
   11802       251108 :           if (data_ref)
   11803              :             {
   11804       248982 :               vect_copy_ref_info (data_ref, DR_REF (first_dr_info->dr));
   11805       248982 :               new_stmt = gimple_build_assign (vec_dest, data_ref);
   11806              :             }
   11807              : 
   11808       502216 :           new_temp = (need_zeroing
   11809       251108 :                       ? make_ssa_name (vectype)
   11810       251108 :                       : make_ssa_name (vec_dest, new_stmt));
   11811       251108 :           gimple_set_lhs (new_stmt, new_temp);
   11812       251108 :           vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
   11813              : 
   11814              :           /* If we need to explicitly zero inactive elements emit a
   11815              :              VEC_COND_EXPR that does so.  */
   11816       251108 :           if (need_zeroing)
   11817              :             {
   11818            0 :               vec_els = vect_get_mask_load_else (MASK_LOAD_ELSE_ZERO,
   11819              :                                                  vectype);
   11820              : 
   11821            0 :               tree new_temp2 = make_ssa_name (vec_dest, new_stmt);
   11822            0 :               new_stmt = gimple_build_assign (new_temp2, VEC_COND_EXPR,
   11823              :                                               final_mask, new_temp, vec_els);
   11824            0 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt,
   11825              :                                            gsi);
   11826            0 :               new_temp = new_temp2;
   11827              :             }
   11828              :         }
   11829              : 
   11830              :       /* 3. Handle explicit realignment if necessary/supported.
   11831              :          Create in loop:
   11832              :          vec_dest = realign_load (msq, lsq, realignment_token)  */
   11833       830045 :       if (!costing_p
   11834       251108 :           && (alignment_support_scheme == dr_explicit_realign_optimized
   11835              :               || alignment_support_scheme == dr_explicit_realign))
   11836              :         {
   11837            0 :           lsq = gimple_assign_lhs (new_stmt);
   11838            0 :           if (!realignment_token)
   11839            0 :             realignment_token = dataref_ptr;
   11840            0 :           vec_dest = vect_create_destination_var (scalar_dest, vectype);
   11841            0 :           new_stmt = gimple_build_assign (vec_dest, REALIGN_LOAD_EXPR, msq,
   11842              :                                           lsq, realignment_token);
   11843            0 :           new_temp = make_ssa_name (vec_dest, new_stmt);
   11844            0 :           gimple_assign_set_lhs (new_stmt, new_temp);
   11845            0 :           vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
   11846              : 
   11847            0 :           if (alignment_support_scheme == dr_explicit_realign_optimized)
   11848              :             {
   11849            0 :               gcc_assert (phi);
   11850            0 :               if (i == vec_num - 1)
   11851            0 :                 add_phi_arg (phi, lsq, loop_latch_edge (containing_loop),
   11852              :                              UNKNOWN_LOCATION);
   11853              :               msq = lsq;
   11854              :             }
   11855              :         }
   11856              : 
   11857       830045 :       if (memory_access_type == VMAT_CONTIGUOUS_REVERSE)
   11858              :         {
   11859         5580 :           if (costing_p)
   11860         4149 :             inside_cost = record_stmt_cost (cost_vec, 1, vec_perm,
   11861              :                                             slp_node, 0, vect_body);
   11862              :           else
   11863              :             {
   11864         1431 :               tree perm_mask = perm_mask_for_reverse (vectype);
   11865         1431 :               new_temp = permute_vec_elements (vinfo, new_temp, new_temp,
   11866              :                                                perm_mask, stmt_info, gsi);
   11867         1431 :               new_stmt = SSA_NAME_DEF_STMT (new_temp);
   11868              :             }
   11869              :         }
   11870              : 
   11871              :       /* Collect vector loads and later create their permutation in
   11872              :          vect_transform_slp_perm_load.  */
   11873       830045 :       if (!costing_p && (grouped_load || ls.slp_perm))
   11874        72213 :         dr_chain.quick_push (new_temp);
   11875              : 
   11876              :       /* Store vector loads in the corresponding SLP_NODE.  */
   11877       251108 :       if (!costing_p && !ls.slp_perm)
   11878       178895 :         slp_node->push_vec_def (new_stmt);
   11879              : 
   11880              :       /* With SLP permutation we load the gaps as well, without
   11881              :          we need to skip the gaps after we manage to fully load
   11882              :          all elements.  group_gap_adj is DR_GROUP_SIZE here.  */
   11883       830045 :       group_elt += nunits;
   11884       830045 :       if (!costing_p
   11885       251108 :           && maybe_ne (group_gap_adj, 0U)
   11886        44821 :           && !ls.slp_perm
   11887       850064 :           && known_eq (group_elt, group_size - group_gap_adj))
   11888              :         {
   11889        15831 :           poly_wide_int bump_val
   11890        15831 :             = (wi::to_wide (TYPE_SIZE_UNIT (elem_type)) * group_gap_adj);
   11891        15831 :           if (tree_int_cst_sgn (vect_dr_behavior (vinfo, dr_info)->step) == -1)
   11892            0 :             bump_val = -bump_val;
   11893        15831 :           tree bump = wide_int_to_tree (sizetype, bump_val);
   11894        15831 :           dataref_ptr = bump_vector_ptr (vinfo, dataref_ptr, ptr_incr, gsi,
   11895              :                                          stmt_info, bump);
   11896        15831 :           group_elt = 0;
   11897        15831 :         }
   11898              :     }
   11899              :   /* Bump the vector pointer to account for a gap or for excess
   11900              :      elements loaded for a permuted SLP load.  */
   11901       504130 :   if (!costing_p
   11902       160934 :       && maybe_ne (group_gap_adj, 0U)
   11903       520395 :       && ls.slp_perm)
   11904              :     {
   11905          434 :       poly_wide_int bump_val
   11906          434 :         = (wi::to_wide (TYPE_SIZE_UNIT (elem_type)) * group_gap_adj);
   11907          434 :       if (tree_int_cst_sgn (vect_dr_behavior (vinfo, dr_info)->step) == -1)
   11908            9 :         bump_val = -bump_val;
   11909          434 :       tree bump = wide_int_to_tree (sizetype, bump_val);
   11910          434 :       dataref_ptr = bump_vector_ptr (vinfo, dataref_ptr, ptr_incr, gsi,
   11911              :                                      stmt_info, bump);
   11912          434 :     }
   11913              : 
   11914       504130 :   if (ls.slp_perm)
   11915              :     {
   11916              :       /* For SLP we know we've seen all possible uses of dr_chain so
   11917              :          direct vect_transform_slp_perm_load to DCE the unused parts.
   11918              :          ???  This is a hack to prevent compile-time issues as seen
   11919              :          in PR101120 and friends.  */
   11920        48692 :       if (costing_p)
   11921              :         {
   11922        31537 :           gcc_assert (ls.n_perms != -1U && ls.n_loads != -1U);
   11923        31537 :           if (ls.n_perms != 0)
   11924        31173 :             inside_cost = record_stmt_cost (cost_vec, ls.n_perms, vec_perm,
   11925              :                                             slp_node, 0, vect_body);
   11926        31537 :           if (n_adjacent_loads > 0)
   11927        31537 :             n_adjacent_loads = ls.n_loads;
   11928              :         }
   11929              :       else
   11930              :         {
   11931        17155 :           unsigned n_perms2, n_loads2;
   11932        17155 :           bool ok = vect_transform_slp_perm_load (vinfo, slp_node, dr_chain,
   11933              :                                                   gsi, vf, false, &n_perms2,
   11934              :                                                   &n_loads2, true);
   11935        17155 :           gcc_assert (ok && ls.n_perms == n_perms2 && ls.n_loads == n_loads2);
   11936              :         }
   11937              :     }
   11938              : 
   11939       504130 :   if (costing_p)
   11940              :     {
   11941       343196 :       gcc_assert (memory_access_type == VMAT_CONTIGUOUS
   11942              :                   || memory_access_type == VMAT_CONTIGUOUS_REVERSE);
   11943       343196 :       if (n_adjacent_loads > 0)
   11944       343196 :         vect_get_load_cost (vinfo, stmt_info, slp_node, n_adjacent_loads,
   11945              :                             alignment_support_scheme, misalignment, false,
   11946              :                             &inside_cost, &prologue_cost, cost_vec, cost_vec,
   11947              :                             true);
   11948       343196 :       if (dump_enabled_p ())
   11949        23169 :         dump_printf_loc (MSG_NOTE, vect_location,
   11950              :                          "vect_model_load_cost: inside_cost = %u, "
   11951              :                          "prologue_cost = %u .\n",
   11952              :                          inside_cost, prologue_cost);
   11953              :     }
   11954              : 
   11955       504130 :   return true;
   11956      1650645 : }
   11957              : 
   11958              : /* Function vect_is_simple_cond.
   11959              : 
   11960              :    Input:
   11961              :    LOOP - the loop that is being vectorized.
   11962              :    COND - Condition that is checked for simple use.
   11963              : 
   11964              :    Output:
   11965              :    *COMP_VECTYPE - the vector type for the comparison.
   11966              :    *DTS - The def types for the arguments of the comparison
   11967              : 
   11968              :    Returns whether a COND can be vectorized.  Checks whether
   11969              :    condition operands are supportable using vec_is_simple_use.  */
   11970              : 
   11971              : static bool
   11972        27854 : vect_is_simple_cond (tree cond, vec_info *vinfo,
   11973              :                      slp_tree slp_node, tree *comp_vectype,
   11974              :                      enum vect_def_type *dts, tree vectype)
   11975              : {
   11976        27854 :   tree lhs, rhs;
   11977        27854 :   tree vectype1 = NULL_TREE, vectype2 = NULL_TREE;
   11978        27854 :   slp_tree slp_op;
   11979              : 
   11980              :   /* Mask case.  */
   11981        27854 :   if (TREE_CODE (cond) == SSA_NAME
   11982        27854 :       && VECT_SCALAR_BOOLEAN_TYPE_P (TREE_TYPE (cond)))
   11983              :     {
   11984        27842 :       if (!vect_is_simple_use (vinfo, slp_node, 0, &cond,
   11985              :                                &slp_op, &dts[0], comp_vectype)
   11986        27842 :           || !*comp_vectype
   11987        55669 :           || !VECTOR_BOOLEAN_TYPE_P (*comp_vectype))
   11988              :         return false;
   11989              :       return true;
   11990              :     }
   11991              : 
   11992           12 :   if (!COMPARISON_CLASS_P (cond))
   11993              :     return false;
   11994              : 
   11995            0 :   lhs = TREE_OPERAND (cond, 0);
   11996            0 :   rhs = TREE_OPERAND (cond, 1);
   11997              : 
   11998            0 :   if (TREE_CODE (lhs) == SSA_NAME)
   11999              :     {
   12000            0 :       if (!vect_is_simple_use (vinfo, slp_node, 0,
   12001              :                                &lhs, &slp_op, &dts[0], &vectype1))
   12002              :         return false;
   12003              :     }
   12004            0 :   else if (TREE_CODE (lhs) == INTEGER_CST || TREE_CODE (lhs) == REAL_CST
   12005            0 :            || TREE_CODE (lhs) == FIXED_CST)
   12006            0 :     dts[0] = vect_constant_def;
   12007              :   else
   12008              :     return false;
   12009              : 
   12010            0 :   if (TREE_CODE (rhs) == SSA_NAME)
   12011              :     {
   12012            0 :       if (!vect_is_simple_use (vinfo, slp_node, 1,
   12013              :                                &rhs, &slp_op, &dts[1], &vectype2))
   12014              :         return false;
   12015              :     }
   12016            0 :   else if (TREE_CODE (rhs) == INTEGER_CST || TREE_CODE (rhs) == REAL_CST
   12017            0 :            || TREE_CODE (rhs) == FIXED_CST)
   12018            0 :     dts[1] = vect_constant_def;
   12019              :   else
   12020              :     return false;
   12021              : 
   12022            0 :   if (vectype1 && vectype2
   12023            0 :       && maybe_ne (TYPE_VECTOR_SUBPARTS (vectype1),
   12024            0 :                    TYPE_VECTOR_SUBPARTS (vectype2)))
   12025            0 :     return false;
   12026              : 
   12027            0 :   *comp_vectype = vectype1 ? vectype1 : vectype2;
   12028              :   /* Invariant comparison.  */
   12029            0 :   if (! *comp_vectype)
   12030              :     {
   12031            0 :       tree scalar_type = TREE_TYPE (lhs);
   12032            0 :       if (VECT_SCALAR_BOOLEAN_TYPE_P (scalar_type))
   12033            0 :         *comp_vectype = truth_type_for (vectype);
   12034              :       else
   12035              :         {
   12036              :           /* If we can widen the comparison to match vectype do so.  */
   12037            0 :           if (INTEGRAL_TYPE_P (scalar_type)
   12038            0 :               && !slp_node
   12039            0 :               && tree_int_cst_lt (TYPE_SIZE (scalar_type),
   12040            0 :                                   TYPE_SIZE (TREE_TYPE (vectype))))
   12041            0 :             scalar_type = build_nonstandard_integer_type
   12042            0 :               (vector_element_bits (vectype), TYPE_UNSIGNED (scalar_type));
   12043            0 :           *comp_vectype = get_vectype_for_scalar_type (vinfo, scalar_type,
   12044              :                                                        slp_node);
   12045              :         }
   12046              :     }
   12047              : 
   12048              :   return true;
   12049              : }
   12050              : 
   12051              : /* vectorizable_condition.
   12052              : 
   12053              :    Check if STMT_INFO is conditional modify expression that can be vectorized.
   12054              :    If COST_VEC is passed, calculate costs but don't change anything,
   12055              :    otherwise, vectorize STMT_INFO: create a vectorized stmt using
   12056              :    VEC_COND_EXPR to replace it, and insert it at GSI.
   12057              : 
   12058              :    When STMT_INFO is vectorized as a nested cycle, for_reduction is true.
   12059              : 
   12060              :    Return true if STMT_INFO is vectorizable in this way.  */
   12061              : 
   12062              : static bool
   12063       606273 : vectorizable_condition (vec_info *vinfo,
   12064              :                         stmt_vec_info stmt_info, gimple_stmt_iterator *gsi,
   12065              :                         slp_tree slp_node, stmt_vector_for_cost *cost_vec)
   12066              : {
   12067       606273 :   tree scalar_dest = NULL_TREE;
   12068       606273 :   tree vec_dest = NULL_TREE;
   12069       606273 :   tree cond_expr, cond_expr0 = NULL_TREE, cond_expr1 = NULL_TREE;
   12070       606273 :   tree then_clause, else_clause;
   12071       606273 :   tree comp_vectype = NULL_TREE;
   12072       606273 :   tree vec_cond_lhs = NULL_TREE, vec_cond_rhs = NULL_TREE;
   12073       606273 :   tree vec_then_clause = NULL_TREE, vec_else_clause = NULL_TREE;
   12074       606273 :   tree vec_compare;
   12075       606273 :   tree new_temp;
   12076       606273 :   loop_vec_info loop_vinfo = dyn_cast <loop_vec_info> (vinfo);
   12077       606273 :   enum vect_def_type dts[4]
   12078              :     = {vect_unknown_def_type, vect_unknown_def_type,
   12079              :        vect_unknown_def_type, vect_unknown_def_type};
   12080       606273 :   enum tree_code code, cond_code, bitop1 = NOP_EXPR, bitop2 = NOP_EXPR;
   12081       606273 :   int i;
   12082       606273 :   bb_vec_info bb_vinfo = dyn_cast <bb_vec_info> (vinfo);
   12083       606273 :   vec<tree> vec_oprnds0 = vNULL;
   12084       606273 :   vec<tree> vec_oprnds1 = vNULL;
   12085       606273 :   vec<tree> vec_oprnds2 = vNULL;
   12086       606273 :   vec<tree> vec_oprnds3 = vNULL;
   12087       606273 :   tree vec_cmp_type;
   12088       606273 :   bool masked = false;
   12089              : 
   12090       606273 :   if (!STMT_VINFO_RELEVANT_P (stmt_info) && !bb_vinfo)
   12091              :     return false;
   12092              : 
   12093              :   /* Is vectorizable conditional operation?  */
   12094       930997 :   gassign *stmt = dyn_cast <gassign *> (stmt_info->stmt);
   12095       352549 :   if (!stmt)
   12096              :     return false;
   12097              : 
   12098       352549 :   code = gimple_assign_rhs_code (stmt);
   12099       352549 :   if (code != COND_EXPR)
   12100              :     return false;
   12101              : 
   12102        27854 :   int reduc_index = SLP_TREE_REDUC_IDX (slp_node);
   12103        27854 :   vect_reduction_type reduction_type = TREE_CODE_REDUCTION;
   12104        27854 :   bool nested_cycle_p = false;
   12105        27854 :   bool for_reduction = vect_is_reduction (stmt_info);
   12106        27854 :   if (for_reduction)
   12107              :     {
   12108          547 :       if (SLP_TREE_LANES (slp_node) > 1)
   12109              :         return false;
   12110              :       /* ???  With a reduction path we do not get at the reduction info from
   12111              :          every stmt, use the conservative default setting then.  */
   12112          627 :       if (STMT_VINFO_REDUC_DEF (vect_orig_stmt (stmt_info)))
   12113              :         {
   12114          529 :           vect_reduc_info reduc_info
   12115          529 :             = info_for_reduction (loop_vinfo, slp_node);
   12116          529 :           reduction_type = VECT_REDUC_INFO_TYPE (reduc_info);
   12117          529 :           nested_cycle_p = nested_in_vect_loop_p (LOOP_VINFO_LOOP (loop_vinfo),
   12118              :                                                   stmt_info);
   12119              :         }
   12120              :     }
   12121              :   else
   12122              :     {
   12123        27307 :       if (STMT_VINFO_DEF_TYPE (stmt_info) != vect_internal_def)
   12124              :         return false;
   12125              :     }
   12126              : 
   12127        27854 :   tree vectype = SLP_TREE_VECTYPE (slp_node);
   12128        27854 :   tree vectype1 = NULL_TREE, vectype2 = NULL_TREE;
   12129              : 
   12130        27854 :   int vec_num = vect_get_num_copies (vinfo, slp_node);
   12131              : 
   12132        27854 :   cond_expr = gimple_assign_rhs1 (stmt);
   12133        27854 :   gcc_assert (! COMPARISON_CLASS_P (cond_expr));
   12134              : 
   12135        27854 :   if (!vect_is_simple_cond (cond_expr, vinfo, slp_node,
   12136              :                             &comp_vectype, &dts[0], vectype)
   12137        27854 :       || !comp_vectype)
   12138              :     return false;
   12139              : 
   12140        27827 :   unsigned op_adjust = COMPARISON_CLASS_P (cond_expr) ? 1 : 0;
   12141        27827 :   slp_tree then_slp_node, else_slp_node;
   12142        27827 :   if (!vect_is_simple_use (vinfo, slp_node, 1 + op_adjust,
   12143              :                            &then_clause, &then_slp_node, &dts[2], &vectype1))
   12144              :     return false;
   12145        27827 :   if (!vect_is_simple_use (vinfo, slp_node, 2 + op_adjust,
   12146              :                            &else_clause, &else_slp_node, &dts[3], &vectype2))
   12147              :     return false;
   12148              : 
   12149        27827 :   if (vectype1 && !useless_type_conversion_p (vectype, vectype1))
   12150              :     return false;
   12151              : 
   12152        27827 :   if (vectype2 && !useless_type_conversion_p (vectype, vectype2))
   12153              :     return false;
   12154              : 
   12155        27827 :   masked = !COMPARISON_CLASS_P (cond_expr);
   12156        27827 :   vec_cmp_type = truth_type_for (comp_vectype);
   12157        27827 :   if (vec_cmp_type == NULL_TREE
   12158        55654 :       || maybe_ne (TYPE_VECTOR_SUBPARTS (vectype),
   12159        27827 :                    TYPE_VECTOR_SUBPARTS (vec_cmp_type)))
   12160            0 :     return false;
   12161              : 
   12162        27827 :   cond_code = TREE_CODE (cond_expr);
   12163        27827 :   if (!masked)
   12164              :     {
   12165            0 :       cond_expr0 = TREE_OPERAND (cond_expr, 0);
   12166            0 :       cond_expr1 = TREE_OPERAND (cond_expr, 1);
   12167              :     }
   12168              : 
   12169              :   /* For conditional reductions, the "then" value needs to be the candidate
   12170              :      value calculated by this iteration while the "else" value needs to be
   12171              :      the result carried over from previous iterations.  If the COND_EXPR
   12172              :      is the other way around, we need to swap it.  */
   12173        27827 :   bool must_invert_cmp_result = false;
   12174        27827 :   if (reduction_type == EXTRACT_LAST_REDUCTION && reduc_index == 1)
   12175              :     {
   12176            0 :       if (masked)
   12177            0 :         must_invert_cmp_result = true;
   12178              :       else
   12179              :         {
   12180            0 :           bool honor_nans = HONOR_NANS (TREE_TYPE (cond_expr0));
   12181            0 :           tree_code new_code = invert_tree_comparison (cond_code, honor_nans);
   12182            0 :           if (new_code == ERROR_MARK)
   12183              :             must_invert_cmp_result = true;
   12184              :           else
   12185              :             {
   12186            0 :               cond_code = new_code;
   12187              :               /* Make sure we don't accidentally use the old condition.  */
   12188            0 :               cond_expr = NULL_TREE;
   12189              :             }
   12190              :         }
   12191              :       /* ???  The vectorized operand query below doesn't allow swapping
   12192              :          this way for SLP.  */
   12193            0 :       return false;
   12194              :       /* std::swap (then_clause, else_clause); */
   12195              :     }
   12196              : 
   12197        27827 :   if (!masked && VECTOR_BOOLEAN_TYPE_P (comp_vectype))
   12198              :     {
   12199              :       /* Boolean values may have another representation in vectors
   12200              :          and therefore we prefer bit operations over comparison for
   12201              :          them (which also works for scalar masks).  We store opcodes
   12202              :          to use in bitop1 and bitop2.  Statement is vectorized as
   12203              :          BITOP2 (rhs1 BITOP1 rhs2) or rhs1 BITOP2 (BITOP1 rhs2)
   12204              :          depending on bitop1 and bitop2 arity.  */
   12205            0 :       switch (cond_code)
   12206              :         {
   12207              :         case GT_EXPR:
   12208              :           bitop1 = BIT_NOT_EXPR;
   12209              :           bitop2 = BIT_AND_EXPR;
   12210              :           break;
   12211            0 :         case GE_EXPR:
   12212            0 :           bitop1 = BIT_NOT_EXPR;
   12213            0 :           bitop2 = BIT_IOR_EXPR;
   12214            0 :           break;
   12215            0 :         case LT_EXPR:
   12216            0 :           bitop1 = BIT_NOT_EXPR;
   12217            0 :           bitop2 = BIT_AND_EXPR;
   12218            0 :           std::swap (cond_expr0, cond_expr1);
   12219            0 :           break;
   12220            0 :         case LE_EXPR:
   12221            0 :           bitop1 = BIT_NOT_EXPR;
   12222            0 :           bitop2 = BIT_IOR_EXPR;
   12223            0 :           std::swap (cond_expr0, cond_expr1);
   12224            0 :           break;
   12225            0 :         case NE_EXPR:
   12226            0 :           bitop1 = BIT_XOR_EXPR;
   12227            0 :           break;
   12228            0 :         case EQ_EXPR:
   12229            0 :           bitop1 = BIT_XOR_EXPR;
   12230            0 :           bitop2 = BIT_NOT_EXPR;
   12231            0 :           break;
   12232              :         default:
   12233              :           return false;
   12234              :         }
   12235              :       cond_code = SSA_NAME;
   12236              :     }
   12237              : 
   12238        27827 :   if (TREE_CODE_CLASS (cond_code) == tcc_comparison
   12239            0 :       && reduction_type == EXTRACT_LAST_REDUCTION
   12240        27827 :       && !expand_vec_cmp_expr_p (comp_vectype, vec_cmp_type, cond_code))
   12241              :     {
   12242            0 :       if (dump_enabled_p ())
   12243            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
   12244              :                          "reduction comparison operation not supported.\n");
   12245            0 :       return false;
   12246              :     }
   12247              : 
   12248        27827 :   if (cost_vec)
   12249              :     {
   12250        19346 :       if (bitop1 != NOP_EXPR)
   12251              :         {
   12252            0 :           machine_mode mode = TYPE_MODE (comp_vectype);
   12253            0 :           optab optab;
   12254              : 
   12255            0 :           optab = optab_for_tree_code (bitop1, comp_vectype, optab_default);
   12256            0 :           if (!optab || !can_implement_p (optab, mode))
   12257            0 :             return false;
   12258              : 
   12259            0 :           if (bitop2 != NOP_EXPR)
   12260              :             {
   12261            0 :               optab = optab_for_tree_code (bitop2, comp_vectype,
   12262              :                                            optab_default);
   12263            0 :               if (!optab || !can_implement_p (optab, mode))
   12264            0 :                 return false;
   12265              :             }
   12266              :         }
   12267              : 
   12268        19346 :       vect_cost_for_stmt kind = vector_stmt;
   12269        19346 :       if (reduction_type == EXTRACT_LAST_REDUCTION)
   12270              :         /* Count one reduction-like operation per vector.  */
   12271              :         kind = vec_to_scalar;
   12272        19346 :       else if ((masked && !expand_vec_cond_expr_p (vectype, comp_vectype))
   12273        19346 :                || (!masked
   12274            0 :                    && (!expand_vec_cmp_expr_p (comp_vectype, vec_cmp_type,
   12275              :                                                cond_code)
   12276            0 :                        || !expand_vec_cond_expr_p (vectype, vec_cmp_type))))
   12277            2 :         return false;
   12278              : 
   12279        19344 :       if (!vect_maybe_update_slp_op_vectype (SLP_TREE_CHILDREN (slp_node)[0],
   12280              :                                              comp_vectype)
   12281        19344 :           || (op_adjust == 1
   12282            0 :               && !vect_maybe_update_slp_op_vectype
   12283            0 :                               (SLP_TREE_CHILDREN (slp_node)[1], comp_vectype))
   12284        19344 :           || !vect_maybe_update_slp_op_vectype (then_slp_node, vectype)
   12285        38688 :           || !vect_maybe_update_slp_op_vectype (else_slp_node, vectype))
   12286              :         {
   12287            0 :           if (dump_enabled_p ())
   12288            0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
   12289              :                              "incompatible vector types for invariants\n");
   12290            0 :           return false;
   12291              :         }
   12292              : 
   12293        19344 :       if (loop_vinfo && for_reduction
   12294          400 :           && LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo))
   12295              :         {
   12296           65 :           if (reduction_type == EXTRACT_LAST_REDUCTION)
   12297              :             {
   12298            0 :               if (direct_internal_fn_supported_p (IFN_LEN_FOLD_EXTRACT_LAST,
   12299              :                                                   vectype, OPTIMIZE_FOR_SPEED))
   12300            0 :                 vect_record_loop_len (loop_vinfo,
   12301              :                                       &LOOP_VINFO_LENS (loop_vinfo),
   12302              :                                       vec_num, vectype, 1);
   12303              :               else
   12304            0 :                 vect_record_loop_mask (loop_vinfo,
   12305              :                                        &LOOP_VINFO_MASKS (loop_vinfo),
   12306              :                                        vec_num, vectype, NULL);
   12307              :             }
   12308              :           /* Extra inactive lanes should be safe for vect_nested_cycle.  */
   12309           65 :           else if (!nested_cycle_p)
   12310              :             {
   12311           65 :               if (dump_enabled_p ())
   12312            8 :                 dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
   12313              :                                  "conditional reduction prevents the use"
   12314              :                                  " of partial vectors.\n");
   12315           65 :               LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo) = false;
   12316              :             }
   12317              :         }
   12318              : 
   12319        19344 :       SLP_TREE_TYPE (slp_node) = condition_vec_info_type;
   12320        19344 :       vect_model_simple_cost (vinfo, 1, slp_node, cost_vec, kind);
   12321        19344 :       return true;
   12322              :     }
   12323              : 
   12324              :   /* Transform.  */
   12325              : 
   12326              :   /* Handle def.  */
   12327         8481 :   scalar_dest = gimple_assign_lhs (stmt);
   12328         8481 :   if (reduction_type != EXTRACT_LAST_REDUCTION)
   12329         8481 :     vec_dest = vect_create_destination_var (scalar_dest, vectype);
   12330              : 
   12331         8481 :   bool swap_cond_operands = false;
   12332              : 
   12333              :   /* See whether another part of the vectorized code applies a loop
   12334              :      mask to the condition, or to its inverse.  */
   12335              : 
   12336         8481 :   vec_loop_masks *masks = NULL;
   12337         8481 :   vec_loop_lens *lens = NULL;
   12338         8481 :   if (loop_vinfo && LOOP_VINFO_FULLY_WITH_LENGTH_P (loop_vinfo))
   12339              :     {
   12340            0 :       if (reduction_type == EXTRACT_LAST_REDUCTION)
   12341            0 :         lens = &LOOP_VINFO_LENS (loop_vinfo);
   12342              :     }
   12343         8481 :   else if (loop_vinfo && LOOP_VINFO_FULLY_MASKED_P (loop_vinfo))
   12344              :     {
   12345            3 :       if (reduction_type == EXTRACT_LAST_REDUCTION)
   12346            0 :         masks = &LOOP_VINFO_MASKS (loop_vinfo);
   12347              :       else
   12348              :         {
   12349            3 :           scalar_cond_masked_key cond (cond_expr, 1);
   12350            3 :           if (loop_vinfo->scalar_cond_masked_set.contains (cond))
   12351            0 :             masks = &LOOP_VINFO_MASKS (loop_vinfo);
   12352              :           else
   12353              :             {
   12354            3 :               bool honor_nans = HONOR_NANS (TREE_TYPE (cond.op0));
   12355            3 :               tree_code orig_code = cond.code;
   12356            3 :               cond.code = invert_tree_comparison (cond.code, honor_nans);
   12357            3 :               if (!masked && loop_vinfo->scalar_cond_masked_set.contains (cond))
   12358              :                 {
   12359            0 :                   masks = &LOOP_VINFO_MASKS (loop_vinfo);
   12360            0 :                   cond_code = cond.code;
   12361            0 :                   swap_cond_operands = true;
   12362              :                 }
   12363              :               else
   12364              :                 {
   12365              :                   /* Try the inverse of the current mask.  We check if the
   12366              :                      inverse mask is live and if so we generate a negate of
   12367              :                      the current mask such that we still honor NaNs.  */
   12368            3 :                   cond.inverted_p = true;
   12369            3 :                   cond.code = orig_code;
   12370            3 :                   if (loop_vinfo->scalar_cond_masked_set.contains (cond))
   12371              :                     {
   12372            0 :                       masks = &LOOP_VINFO_MASKS (loop_vinfo);
   12373            0 :                       cond_code = cond.code;
   12374            0 :                       swap_cond_operands = true;
   12375            0 :                       must_invert_cmp_result = true;
   12376              :                     }
   12377              :                 }
   12378              :             }
   12379              :         }
   12380              :     }
   12381              : 
   12382              :   /* Handle cond expr.  */
   12383         8481 :   if (masked)
   12384         8481 :     vect_get_vec_defs (vinfo, slp_node,
   12385              :                        cond_expr, &vec_oprnds0,
   12386              :                        then_clause, &vec_oprnds2,
   12387              :                        reduction_type != EXTRACT_LAST_REDUCTION
   12388              :                        ? else_clause : NULL, &vec_oprnds3);
   12389              :   else
   12390            0 :     vect_get_vec_defs (vinfo, slp_node,
   12391              :                        cond_expr0, &vec_oprnds0,
   12392              :                        cond_expr1, &vec_oprnds1,
   12393              :                        then_clause, &vec_oprnds2,
   12394              :                        reduction_type != EXTRACT_LAST_REDUCTION
   12395              :                        ? else_clause : NULL, &vec_oprnds3);
   12396              : 
   12397         8481 :   if (reduction_type == EXTRACT_LAST_REDUCTION)
   12398            0 :     vec_else_clause = else_clause;
   12399              : 
   12400              :   /* Arguments are ready.  Create the new vector stmt.  */
   12401        19959 :   FOR_EACH_VEC_ELT (vec_oprnds0, i, vec_cond_lhs)
   12402              :     {
   12403        11478 :       vec_then_clause = vec_oprnds2[i];
   12404        11478 :       if (reduction_type != EXTRACT_LAST_REDUCTION)
   12405        11478 :         vec_else_clause = vec_oprnds3[i];
   12406              : 
   12407        11478 :       if (swap_cond_operands)
   12408            0 :         std::swap (vec_then_clause, vec_else_clause);
   12409              : 
   12410        11478 :       if (masked)
   12411              :         vec_compare = vec_cond_lhs;
   12412              :       else
   12413              :         {
   12414            0 :           vec_cond_rhs = vec_oprnds1[i];
   12415            0 :           if (bitop1 == NOP_EXPR)
   12416              :             {
   12417            0 :               gimple_seq stmts = NULL;
   12418            0 :               vec_compare = gimple_build (&stmts, cond_code, vec_cmp_type,
   12419              :                                            vec_cond_lhs, vec_cond_rhs);
   12420            0 :               gsi_insert_before (gsi, stmts, GSI_SAME_STMT);
   12421              :             }
   12422              :           else
   12423              :             {
   12424            0 :               new_temp = make_ssa_name (vec_cmp_type);
   12425            0 :               gassign *new_stmt;
   12426            0 :               if (bitop1 == BIT_NOT_EXPR)
   12427            0 :                 new_stmt = gimple_build_assign (new_temp, bitop1,
   12428              :                                                 vec_cond_rhs);
   12429              :               else
   12430            0 :                 new_stmt
   12431            0 :                   = gimple_build_assign (new_temp, bitop1, vec_cond_lhs,
   12432              :                                          vec_cond_rhs);
   12433            0 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
   12434            0 :               if (bitop2 == NOP_EXPR)
   12435              :                 vec_compare = new_temp;
   12436            0 :               else if (bitop2 == BIT_NOT_EXPR
   12437            0 :                        && reduction_type != EXTRACT_LAST_REDUCTION)
   12438              :                 {
   12439              :                   /* Instead of doing ~x ? y : z do x ? z : y.  */
   12440              :                   vec_compare = new_temp;
   12441              :                   std::swap (vec_then_clause, vec_else_clause);
   12442              :                 }
   12443              :               else
   12444              :                 {
   12445            0 :                   vec_compare = make_ssa_name (vec_cmp_type);
   12446            0 :                   if (bitop2 == BIT_NOT_EXPR)
   12447            0 :                     new_stmt
   12448            0 :                       = gimple_build_assign (vec_compare, bitop2, new_temp);
   12449              :                   else
   12450            0 :                     new_stmt
   12451            0 :                       = gimple_build_assign (vec_compare, bitop2,
   12452              :                                              vec_cond_lhs, new_temp);
   12453            0 :                   vect_finish_stmt_generation (vinfo, stmt_info,
   12454              :                                                new_stmt, gsi);
   12455              :                 }
   12456              :             }
   12457              :         }
   12458              : 
   12459              :       /* If we decided to apply a loop mask to the result of the vector
   12460              :          comparison, AND the comparison with the mask now.  Later passes
   12461              :          should then be able to reuse the AND results between mulitple
   12462              :          vector statements.
   12463              : 
   12464              :          For example:
   12465              :          for (int i = 0; i < 100; ++i)
   12466              :          x[i] = y[i] ? z[i] : 10;
   12467              : 
   12468              :          results in following optimized GIMPLE:
   12469              : 
   12470              :          mask__35.8_43 = vect__4.7_41 != { 0, ... };
   12471              :          vec_mask_and_46 = loop_mask_40 & mask__35.8_43;
   12472              :          _19 = &MEM[base: z_12(D), index: ivtmp_56, step: 4, offset: 0B];
   12473              :          vect_iftmp.11_47 = .MASK_LOAD (_19, 4B, vec_mask_and_46);
   12474              :          vect_iftmp.12_52 = VEC_COND_EXPR <vec_mask_and_46,
   12475              :          vect_iftmp.11_47, { 10, ... }>;
   12476              : 
   12477              :          instead of using a masked and unmasked forms of
   12478              :          vec != { 0, ... } (masked in the MASK_LOAD,
   12479              :          unmasked in the VEC_COND_EXPR).  */
   12480              : 
   12481              :       /* Force vec_compare to be an SSA_NAME rather than a comparison,
   12482              :          in cases where that's necessary.  */
   12483              : 
   12484        11478 :       tree len = NULL_TREE, bias = NULL_TREE;
   12485        11478 :       if (masks || lens || reduction_type == EXTRACT_LAST_REDUCTION)
   12486              :         {
   12487            0 :           if (!is_gimple_val (vec_compare))
   12488              :             {
   12489            0 :               tree vec_compare_name = make_ssa_name (vec_cmp_type);
   12490            0 :               gassign *new_stmt = gimple_build_assign (vec_compare_name,
   12491              :                                                        vec_compare);
   12492            0 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
   12493            0 :               vec_compare = vec_compare_name;
   12494              :             }
   12495              : 
   12496            0 :           if (must_invert_cmp_result)
   12497              :             {
   12498            0 :               tree vec_compare_name = make_ssa_name (vec_cmp_type);
   12499            0 :               gassign *new_stmt = gimple_build_assign (vec_compare_name,
   12500              :                                                        BIT_NOT_EXPR,
   12501              :                                                        vec_compare);
   12502            0 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
   12503            0 :               vec_compare = vec_compare_name;
   12504              :             }
   12505              : 
   12506            0 :           if (direct_internal_fn_supported_p (IFN_LEN_FOLD_EXTRACT_LAST,
   12507              :                                               vectype, OPTIMIZE_FOR_SPEED))
   12508              :             {
   12509            0 :               if (lens)
   12510              :                 {
   12511              :                   /* ??? Do we really want the adjusted LEN here?  Isn't this
   12512              :                      based on number of elements?  */
   12513            0 :                   len = vect_get_loop_len (loop_vinfo, gsi, lens,
   12514              :                                            vec_num, vectype, i, 1, true);
   12515            0 :                   signed char biasval
   12516            0 :                     = LOOP_VINFO_PARTIAL_LOAD_STORE_BIAS (loop_vinfo);
   12517            0 :                   bias = build_int_cst (intQI_type_node, biasval);
   12518              :                 }
   12519              :               else
   12520              :                 {
   12521            0 :                   len = size_int (TYPE_VECTOR_SUBPARTS (vectype));
   12522            0 :                   bias = build_int_cst (intQI_type_node, 0);
   12523              :                 }
   12524              :             }
   12525            0 :           if (masks)
   12526              :             {
   12527            0 :               tree loop_mask
   12528            0 :                 = vect_get_loop_mask (loop_vinfo, gsi, masks, vec_num,
   12529              :                                       vectype, i);
   12530            0 :               tree tmp2 = make_ssa_name (vec_cmp_type);
   12531            0 :               gassign *g
   12532            0 :                 = gimple_build_assign (tmp2, BIT_AND_EXPR, vec_compare,
   12533              :                                        loop_mask);
   12534            0 :               vect_finish_stmt_generation (vinfo, stmt_info, g, gsi);
   12535            0 :               vec_compare = tmp2;
   12536              :             }
   12537              :         }
   12538              : 
   12539            0 :       gimple *new_stmt;
   12540            0 :       if (reduction_type == EXTRACT_LAST_REDUCTION)
   12541              :         {
   12542            0 :           gimple *old_stmt = vect_orig_stmt (stmt_info)->stmt;
   12543            0 :           tree lhs = gimple_get_lhs (old_stmt);
   12544            0 :           if ((unsigned)i != vec_oprnds0.length () - 1)
   12545            0 :             lhs = copy_ssa_name (lhs);
   12546            0 :           if (len)
   12547            0 :             new_stmt = gimple_build_call_internal
   12548            0 :                 (IFN_LEN_FOLD_EXTRACT_LAST, 5, vec_else_clause, vec_compare,
   12549              :                  vec_then_clause, len, bias);
   12550              :           else
   12551            0 :             new_stmt = gimple_build_call_internal
   12552            0 :                 (IFN_FOLD_EXTRACT_LAST, 3, vec_else_clause, vec_compare,
   12553              :                  vec_then_clause);
   12554            0 :           gimple_call_set_lhs (new_stmt, lhs);
   12555            0 :           SSA_NAME_DEF_STMT (lhs) = new_stmt;
   12556            0 :           if ((unsigned)i != vec_oprnds0.length () - 1)
   12557              :             {
   12558            0 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
   12559            0 :               vec_else_clause = lhs;
   12560              :             }
   12561            0 :           else if (old_stmt == gsi_stmt (*gsi))
   12562            0 :             vect_finish_replace_stmt (vinfo, stmt_info, new_stmt);
   12563              :           else
   12564              :             {
   12565              :               /* In this case we're moving the definition to later in the
   12566              :                  block.  That doesn't matter because the only uses of the
   12567              :                  lhs are in phi statements.  */
   12568            0 :               gimple_stmt_iterator old_gsi = gsi_for_stmt (old_stmt);
   12569            0 :               gsi_remove (&old_gsi, true);
   12570            0 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
   12571              :             }
   12572              :         }
   12573              :       else
   12574              :         {
   12575        11478 :           new_temp = make_ssa_name (vec_dest);
   12576        11478 :           new_stmt = gimple_build_assign (new_temp, VEC_COND_EXPR, vec_compare,
   12577              :                                           vec_then_clause, vec_else_clause);
   12578        11478 :           vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
   12579              :         }
   12580        11478 :       slp_node->push_vec_def (new_stmt);
   12581              :     }
   12582              : 
   12583         8481 :   vec_oprnds0.release ();
   12584         8481 :   vec_oprnds1.release ();
   12585         8481 :   vec_oprnds2.release ();
   12586         8481 :   vec_oprnds3.release ();
   12587              : 
   12588         8481 :   return true;
   12589              : }
   12590              : 
   12591              : /* Helper of vectorizable_comparison.
   12592              : 
   12593              :    Check if STMT_INFO is comparison expression CODE that can be vectorized.
   12594              :    If COST_VEC is passed, calculate costs but don't change anything,
   12595              :    otherwise, vectorize STMT_INFO: create a vectorized comparison, and insert
   12596              :    it at GSI.
   12597              : 
   12598              :    Return true if STMT_INFO is vectorizable in this way.  */
   12599              : 
   12600              : static bool
   12601       333155 : vectorizable_comparison_1 (vec_info *vinfo, tree vectype,
   12602              :                            stmt_vec_info stmt_info, tree_code code,
   12603              :                            gimple_stmt_iterator *gsi,
   12604              :                            slp_tree slp_node, stmt_vector_for_cost *cost_vec)
   12605              : {
   12606       333155 :   tree lhs, rhs1, rhs2;
   12607       333155 :   tree vectype1 = NULL_TREE, vectype2 = NULL_TREE;
   12608       333155 :   tree vec_rhs1 = NULL_TREE, vec_rhs2 = NULL_TREE;
   12609       333155 :   tree new_temp;
   12610       333155 :   enum vect_def_type dts[2] = {vect_unknown_def_type, vect_unknown_def_type};
   12611       333155 :   poly_uint64 nunits;
   12612       333155 :   enum tree_code bitop1 = NOP_EXPR, bitop2 = NOP_EXPR;
   12613       333155 :   int i;
   12614       333155 :   bb_vec_info bb_vinfo = dyn_cast <bb_vec_info> (vinfo);
   12615       333155 :   vec<tree> vec_oprnds0 = vNULL;
   12616       333155 :   vec<tree> vec_oprnds1 = vNULL;
   12617       333155 :   tree mask_type;
   12618       333155 :   tree mask = NULL_TREE;
   12619              : 
   12620       333155 :   if (!STMT_VINFO_RELEVANT_P (stmt_info) && !bb_vinfo)
   12621              :     return false;
   12622              : 
   12623       333155 :   if (!vectype || !VECTOR_BOOLEAN_TYPE_P (vectype))
   12624              :     return false;
   12625              : 
   12626       142884 :   mask_type = vectype;
   12627       142884 :   nunits = TYPE_VECTOR_SUBPARTS (vectype);
   12628              : 
   12629       142884 :   if (TREE_CODE_CLASS (code) != tcc_comparison)
   12630              :     return false;
   12631              : 
   12632       141132 :   slp_tree slp_rhs1, slp_rhs2;
   12633       141132 :   if (!vect_is_simple_use (vinfo, slp_node,
   12634              :                            0, &rhs1, &slp_rhs1, &dts[0], &vectype1))
   12635              :     return false;
   12636              : 
   12637       141132 :   if (!vect_is_simple_use (vinfo, slp_node,
   12638              :                            1, &rhs2, &slp_rhs2, &dts[1], &vectype2))
   12639              :     return false;
   12640              : 
   12641       106407 :   if (vectype1 && vectype2
   12642       203830 :       && maybe_ne (TYPE_VECTOR_SUBPARTS (vectype1),
   12643        62698 :                    TYPE_VECTOR_SUBPARTS (vectype2)))
   12644           16 :     return false;
   12645              : 
   12646       141116 :   vectype = vectype1 ? vectype1 : vectype2;
   12647              : 
   12648              :   /* Invariant comparison.  */
   12649       141116 :   if (!vectype)
   12650              :     {
   12651        30019 :       vectype = get_vectype_for_scalar_type (vinfo, TREE_TYPE (rhs1), slp_node);
   12652        30019 :       if (!vectype || maybe_ne (TYPE_VECTOR_SUBPARTS (vectype), nunits))
   12653            7 :         return false;
   12654              :     }
   12655       111097 :   else if (maybe_ne (nunits, TYPE_VECTOR_SUBPARTS (vectype)))
   12656              :     return false;
   12657              : 
   12658              :   /* Can't compare mask and non-mask types.  */
   12659       106391 :   if (vectype1 && vectype2
   12660       328617 :       && (VECTOR_BOOLEAN_TYPE_P (vectype1) ^ VECTOR_BOOLEAN_TYPE_P (vectype2)))
   12661              :     return false;
   12662              : 
   12663              :   /* Boolean values may have another representation in vectors
   12664              :      and therefore we prefer bit operations over comparison for
   12665              :      them (which also works for scalar masks).  We store opcodes
   12666              :      to use in bitop1 and bitop2.  Statement is vectorized as
   12667              :        BITOP2 (rhs1 BITOP1 rhs2) or
   12668              :        rhs1 BITOP2 (BITOP1 rhs2)
   12669              :      depending on bitop1 and bitop2 arity.  */
   12670       141101 :   bool swap_p = false;
   12671       141101 :   if (VECTOR_BOOLEAN_TYPE_P (vectype))
   12672              :     {
   12673          635 :       if (code == GT_EXPR)
   12674              :         {
   12675              :           bitop1 = BIT_NOT_EXPR;
   12676              :           bitop2 = BIT_AND_EXPR;
   12677              :         }
   12678              :       else if (code == GE_EXPR)
   12679              :         {
   12680              :           bitop1 = BIT_NOT_EXPR;
   12681              :           bitop2 = BIT_IOR_EXPR;
   12682              :         }
   12683              :       else if (code == LT_EXPR)
   12684              :         {
   12685              :           bitop1 = BIT_NOT_EXPR;
   12686              :           bitop2 = BIT_AND_EXPR;
   12687              :           swap_p = true;
   12688              :         }
   12689              :       else if (code == LE_EXPR)
   12690              :         {
   12691              :           bitop1 = BIT_NOT_EXPR;
   12692              :           bitop2 = BIT_IOR_EXPR;
   12693              :           swap_p = true;
   12694              :         }
   12695              :       else
   12696              :         {
   12697              :           bitop1 = BIT_XOR_EXPR;
   12698              :           if (code == EQ_EXPR)
   12699              :             bitop2 = BIT_NOT_EXPR;
   12700              :         }
   12701              :     }
   12702              : 
   12703       141101 :   if (cost_vec)
   12704              :     {
   12705       128709 :       if (bitop1 == NOP_EXPR)
   12706              :         {
   12707       128206 :           if (!expand_vec_cmp_expr_p (vectype, mask_type, code))
   12708              :             return false;
   12709              :         }
   12710              :       else
   12711              :         {
   12712          503 :           machine_mode mode = TYPE_MODE (vectype);
   12713          503 :           optab optab;
   12714              : 
   12715          503 :           optab = optab_for_tree_code (bitop1, vectype, optab_default);
   12716          503 :           if (!optab || !can_implement_p (optab, mode))
   12717            0 :             return false;
   12718              : 
   12719          503 :           if (bitop2 != NOP_EXPR)
   12720              :             {
   12721           91 :               optab = optab_for_tree_code (bitop2, vectype, optab_default);
   12722           91 :               if (!optab || !can_implement_p (optab, mode))
   12723            0 :                 return false;
   12724              :             }
   12725              :         }
   12726              : 
   12727              :       /* Put types on constant and invariant SLP children.  */
   12728       121142 :       if (!vect_maybe_update_slp_op_vectype (slp_rhs1, vectype)
   12729       121142 :           || !vect_maybe_update_slp_op_vectype (slp_rhs2, vectype))
   12730              :         {
   12731            2 :           if (dump_enabled_p ())
   12732            2 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
   12733              :                              "incompatible vector types for invariants\n");
   12734            2 :           return false;
   12735              :         }
   12736              : 
   12737       121140 :       vect_model_simple_cost (vinfo, 1 + (bitop2 != NOP_EXPR),
   12738              :                               slp_node, cost_vec);
   12739       121140 :       return true;
   12740              :     }
   12741              : 
   12742              :   /* Transform.  */
   12743              : 
   12744              :   /* Handle def.  */
   12745        12392 :   lhs = gimple_get_lhs (STMT_VINFO_STMT (stmt_info));
   12746        12392 :   if (lhs)
   12747        12392 :     mask = vect_create_destination_var (lhs, mask_type);
   12748              : 
   12749        12392 :   vect_get_vec_defs (vinfo, slp_node, rhs1, &vec_oprnds0, rhs2, &vec_oprnds1);
   12750        12392 :   if (swap_p)
   12751           58 :     std::swap (vec_oprnds0, vec_oprnds1);
   12752              : 
   12753              :   /* Arguments are ready.  Create the new vector stmt.  */
   12754        31179 :   FOR_EACH_VEC_ELT (vec_oprnds0, i, vec_rhs1)
   12755              :     {
   12756        18787 :       gimple *new_stmt;
   12757        18787 :       vec_rhs2 = vec_oprnds1[i];
   12758              : 
   12759        18787 :       if (lhs)
   12760        18787 :         new_temp = make_ssa_name (mask);
   12761              :       else
   12762            0 :         new_temp = make_temp_ssa_name (mask_type, NULL, "cmp");
   12763        18787 :       if (bitop1 == NOP_EXPR)
   12764              :         {
   12765        18645 :           new_stmt = gimple_build_assign (new_temp, code,
   12766              :                                           vec_rhs1, vec_rhs2);
   12767        18645 :           vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
   12768              :         }
   12769              :       else
   12770              :         {
   12771          142 :           if (bitop1 == BIT_NOT_EXPR)
   12772           84 :             new_stmt = gimple_build_assign (new_temp, bitop1, vec_rhs2);
   12773              :           else
   12774           58 :             new_stmt = gimple_build_assign (new_temp, bitop1, vec_rhs1,
   12775              :                                             vec_rhs2);
   12776          142 :           vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
   12777          142 :           if (bitop2 != NOP_EXPR)
   12778              :             {
   12779           84 :               tree res = make_ssa_name (mask);
   12780           84 :               if (bitop2 == BIT_NOT_EXPR)
   12781            0 :                 new_stmt = gimple_build_assign (res, bitop2, new_temp);
   12782              :               else
   12783           84 :                 new_stmt = gimple_build_assign (res, bitop2, vec_rhs1,
   12784              :                                                 new_temp);
   12785           84 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
   12786              :             }
   12787              :         }
   12788        18787 :       slp_node->push_vec_def (new_stmt);
   12789              :     }
   12790              : 
   12791        12392 :   vec_oprnds0.release ();
   12792        12392 :   vec_oprnds1.release ();
   12793              : 
   12794        12392 :   return true;
   12795              : }
   12796              : 
   12797              : /* vectorizable_comparison.
   12798              : 
   12799              :    Check if STMT_INFO is comparison expression that can be vectorized.
   12800              :    If COST_VEC is passed, calculate costs but don't change anything,
   12801              :    otherwise, vectorize STMT_INFO: create a vectorized comparison, and insert
   12802              :    it at GSI.
   12803              : 
   12804              :    Return true if STMT_INFO is vectorizable in this way.  */
   12805              : 
   12806              : static bool
   12807       590840 : vectorizable_comparison (vec_info *vinfo,
   12808              :                          stmt_vec_info stmt_info, gimple_stmt_iterator *gsi,
   12809              :                          slp_tree slp_node, stmt_vector_for_cost *cost_vec)
   12810              : {
   12811       590840 :   bb_vec_info bb_vinfo = dyn_cast <bb_vec_info> (vinfo);
   12812              : 
   12813       590840 :   if (!STMT_VINFO_RELEVANT_P (stmt_info) && !bb_vinfo)
   12814              :     return false;
   12815              : 
   12816       590840 :   if (STMT_VINFO_DEF_TYPE (stmt_info) != vect_internal_def)
   12817              :     return false;
   12818              : 
   12819       790463 :   gassign *stmt = dyn_cast <gassign *> (stmt_info->stmt);
   12820       331164 :   if (!stmt)
   12821              :     return false;
   12822              : 
   12823       331164 :   enum tree_code code = gimple_assign_rhs_code (stmt);
   12824       331164 :   tree vectype = SLP_TREE_VECTYPE (slp_node);
   12825       331164 :   if (!vectorizable_comparison_1 (vinfo, vectype, stmt_info, code, gsi,
   12826              :                                   slp_node, cost_vec))
   12827              :     return false;
   12828              : 
   12829       131541 :   if (cost_vec)
   12830       119149 :     SLP_TREE_TYPE (slp_node) = comparison_vec_info_type;
   12831              : 
   12832              :   return true;
   12833              : }
   12834              : 
   12835              : /* Check to see if the target supports any of the compare and branch optabs for
   12836              :    vectors with MODE as these would be required when expanding.  */
   12837              : static bool
   12838        57416 : supports_vector_compare_and_branch (loop_vec_info loop_vinfo, machine_mode mode)
   12839              : {
   12840        57416 :   bool masked_loop_p = LOOP_VINFO_FULLY_MASKED_P (loop_vinfo);
   12841        57416 :   bool len_loop_p = LOOP_VINFO_FULLY_WITH_LENGTH_P (loop_vinfo);
   12842              : 
   12843              :   /* The vectorizer only produces vec_cbranch_any_optab directly.  So only
   12844              :      check for support for that or vec_cbranch_any_optab when masked.
   12845              :      We can't produce vcond_cbranch_any directly from the vectorizer as we
   12846              :      want to keep gimple_cond as the GIMPLE representation.  But we'll fold
   12847              :      it in expand.  For that reason we require a backend to support the
   12848              :      unconditional vector cbranch optab if they support the conditional one,
   12849              :      which is just an optimization on the unconditional one.  */
   12850        57416 :   if (masked_loop_p
   12851        57416 :       && direct_optab_handler (cond_vec_cbranch_any_optab, mode)
   12852              :                 != CODE_FOR_nothing)
   12853              :     return true;
   12854        57416 :   else if (len_loop_p
   12855        57416 :            && direct_optab_handler (cond_len_vec_cbranch_any_optab, mode)
   12856              :                 != CODE_FOR_nothing)
   12857              :     return true;
   12858        57416 :   else if (!masked_loop_p && !len_loop_p
   12859       114832 :            && direct_optab_handler (vec_cbranch_any_optab, mode)
   12860              :                 != CODE_FOR_nothing)
   12861              :     return true;
   12862              : 
   12863              :   /* The target can implement cbranch to distinguish between boolean vector
   12864              :      types and data types if they don't have a different mode for both.  */
   12865        57416 :   return direct_optab_handler (cbranch_optab, mode) != CODE_FOR_nothing;
   12866              : }
   12867              : 
   12868              : /* Determine the type to use for early break vectorization's scalar IV.  If
   12869              :    no type is possible return false.  */
   12870              : 
   12871              : static bool
   12872         1991 : vect_compute_type_for_early_break_scalar_iv (loop_vec_info loop_vinfo)
   12873              : {
   12874              :   /* Check if we have a usable scalar IV type for vectorization.  */
   12875         1991 :   tree iters_vf_type = sizetype;
   12876         1991 :   if (!LOOP_VINFO_NITERS_UNCOUNTED_P (loop_vinfo))
   12877              :     {
   12878              :       /* Find the type with the minimum precision we can use
   12879              :          for the scalar IV.  */
   12880         1776 :       tree cand_type = TREE_TYPE (LOOP_VINFO_NITERS (loop_vinfo));
   12881              : 
   12882              :       /* Work out how many bits we need to represent the limit.  */
   12883         1776 :       unsigned int min_ni_width
   12884         1776 :         = vect_min_prec_for_max_niters (loop_vinfo, 1);
   12885              : 
   12886              :       /* Check if we're using PFA, if so we need a signed IV and an
   12887              :          extra bit for the sign.  */
   12888         1776 :       if (TYPE_UNSIGNED (cand_type)
   12889         1776 :           && LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo)
   12890         2844 :           && LOOP_VINFO_PEELING_FOR_ALIGNMENT (loop_vinfo))
   12891          164 :         min_ni_width += 1;
   12892              : 
   12893         1776 :       if (TYPE_PRECISION (cand_type) >= min_ni_width)
   12894         1701 :         iters_vf_type = unsigned_type_for (cand_type);
   12895              :       else
   12896              :         {
   12897           75 :           opt_scalar_int_mode cmp_mode_iter;
   12898           75 :           tree iv_type = NULL_TREE;
   12899          367 :           FOR_EACH_MODE_IN_CLASS (cmp_mode_iter, MODE_INT)
   12900              :             {
   12901          367 :               auto cmp_mode = cmp_mode_iter.require ();
   12902          367 :               unsigned int cmp_bits = GET_MODE_BITSIZE (cmp_mode);
   12903          367 :               if (cmp_bits >= min_ni_width
   12904          367 :                   && targetm.scalar_mode_supported_p (cmp_mode))
   12905              :                 {
   12906           75 :                   iv_type = build_nonstandard_integer_type (cmp_bits, true);
   12907           75 :                   if (iv_type)
   12908              :                     break;
   12909              :                 }
   12910              :             }
   12911              : 
   12912           75 :           if (!iv_type)
   12913              :             {
   12914            0 :               if (dump_enabled_p ())
   12915            0 :                 dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
   12916              :                        "can't vectorize early exit because the "
   12917              :                        "target doesn't support a scalar type wide "
   12918              :                        "wide enough to hold niters.\n");
   12919            0 :               return false;
   12920              :             }
   12921           75 :           iters_vf_type = iv_type;
   12922              :         }
   12923              :     }
   12924              : 
   12925         1991 :   LOOP_VINFO_EARLY_BRK_IV_TYPE (loop_vinfo) = iters_vf_type;
   12926         1991 :   return true;
   12927              : }
   12928              : 
   12929              : /* Check to see if the current early break given in STMT_INFO is valid for
   12930              :    vectorization.  */
   12931              : 
   12932              : bool
   12933       231855 : vectorizable_early_exit (loop_vec_info loop_vinfo, stmt_vec_info stmt_info,
   12934              :                          gimple_stmt_iterator *gsi,
   12935              :                          slp_tree slp_node, stmt_vector_for_cost *cost_vec)
   12936              : {
   12937       231855 :   if (!is_a <gcond *> (STMT_VINFO_STMT (stmt_info)))
   12938              :     return false;
   12939              : 
   12940        58980 :   if (STMT_VINFO_DEF_TYPE (stmt_info) != vect_condition_def)
   12941              :     return false;
   12942              : 
   12943        58980 :   if (!STMT_VINFO_RELEVANT_P (stmt_info))
   12944              :     return false;
   12945              : 
   12946        58980 :   DUMP_VECT_SCOPE ("vectorizable_early_exit");
   12947              : 
   12948        58980 :   auto code = gimple_cond_code (STMT_VINFO_STMT (stmt_info));
   12949              : 
   12950              :   /* For SLP we don't want to use the type of the operands of the SLP node, when
   12951              :      vectorizing using SLP slp_node will be the children of the gcond and we
   12952              :      want to use the type of the direct children which since the gcond is root
   12953              :      will be the current node, rather than a child node as vect_is_simple_use
   12954              :      assumes.  */
   12955        58980 :   tree vectype = SLP_TREE_VECTYPE (slp_node);
   12956        58980 :   if (!vectype)
   12957              :     return false;
   12958              : 
   12959        58980 :   machine_mode mode = TYPE_MODE (vectype);
   12960        58980 :   int vec_num = vect_get_num_copies (loop_vinfo, slp_node);
   12961              : 
   12962        58980 :   vec_loop_masks *masks = &LOOP_VINFO_MASKS (loop_vinfo);
   12963        58980 :   vec_loop_lens *lens = &LOOP_VINFO_LENS (loop_vinfo);
   12964        58980 :   bool masked_loop_p = LOOP_VINFO_FULLY_MASKED_P (loop_vinfo);
   12965        58980 :   bool len_loop_p = LOOP_VINFO_FULLY_WITH_LENGTH_P (loop_vinfo);
   12966              : 
   12967              :   /* Now build the new conditional.  Pattern gimple_conds get dropped during
   12968              :      codegen so we must replace the original insn.  */
   12969        58980 :   gimple *orig_stmt = STMT_VINFO_STMT (vect_orig_stmt (stmt_info));
   12970        58980 :   gcond *cond_stmt = as_a <gcond *>(orig_stmt);
   12971              : 
   12972        58980 :   tree vectype_out = vectype;
   12973        58980 :   auto bb = gimple_bb (cond_stmt);
   12974        58980 :   edge exit_true_edge = EDGE_SUCC (bb, 0);
   12975        58980 :   if (exit_true_edge->flags & EDGE_FALSE_VALUE)
   12976          628 :     exit_true_edge = EDGE_SUCC (bb, 1);
   12977        58980 :   gcc_assert (exit_true_edge->flags & EDGE_TRUE_VALUE);
   12978              : 
   12979              :   /* When vectorizing we assume that if the branch edge is taken that we're
   12980              :      exiting the loop.  This is not however always the case as the compiler will
   12981              :      rewrite conditions to always be a comparison against 0.  To do this it
   12982              :      sometimes flips the edges.  This is fine for scalar,  but for vector we
   12983              :      then have to negate the result of the test, as we're still assuming that if
   12984              :      you take the branch edge that we found the exit condition.  i.e. we need to
   12985              :      know whether we are generating a `forall` or an `exist` condition.  */
   12986       117960 :   bool flipped = flow_bb_inside_loop_p (LOOP_VINFO_LOOP (loop_vinfo),
   12987        58980 :                                         exit_true_edge->dest);
   12988              : 
   12989              :   /* See if we support ADDHN and use that for the reduction.  */
   12990        58980 :   internal_fn ifn = IFN_VEC_TRUNC_ADD_HIGH;
   12991        58980 :   bool addhn_supported_p
   12992        58980 :     = direct_internal_fn_supported_p (ifn, vectype, OPTIMIZE_FOR_BOTH);
   12993        58980 :   tree narrow_type = NULL_TREE;
   12994        58980 :   if (addhn_supported_p)
   12995              :     {
   12996              :       /* Calculate the narrowing type for the result.  */
   12997            0 :       auto halfprec = TYPE_PRECISION (TREE_TYPE (vectype)) / 2;
   12998            0 :       auto unsignedp = TYPE_UNSIGNED (TREE_TYPE (vectype));
   12999            0 :       tree itype = build_nonstandard_integer_type (halfprec, unsignedp);
   13000            0 :       tree tmp_type = build_vector_type (itype, TYPE_VECTOR_SUBPARTS (vectype));
   13001            0 :       narrow_type = truth_type_for (tmp_type);
   13002              : 
   13003            0 :       if (!supports_vector_compare_and_branch (loop_vinfo,
   13004            0 :                                                TYPE_MODE (narrow_type)))
   13005              :         {
   13006            0 :           if (dump_enabled_p ())
   13007            0 :               dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
   13008              :                                "can't use ADDHN reduction because cbranch for "
   13009              :                                "the narrowed type is not supported by the "
   13010              :                                "target.\n");
   13011              :           addhn_supported_p = false;
   13012              :         }
   13013              :     }
   13014              : 
   13015              :   /* Analyze only.  */
   13016        58980 :   if (cost_vec)
   13017              :     {
   13018        57416 :       if (!addhn_supported_p
   13019        57416 :           && !supports_vector_compare_and_branch (loop_vinfo, mode))
   13020              :         {
   13021        55425 :           if (dump_enabled_p ())
   13022          573 :               dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
   13023              :                                "can't vectorize early exit because the "
   13024              :                                "target doesn't support flag setting vector "
   13025              :                                "comparisons.\n");
   13026        55425 :           return false;
   13027              :         }
   13028              : 
   13029         1991 :       if (!vectorizable_comparison_1 (loop_vinfo, vectype, stmt_info, code, gsi,
   13030              :                                       slp_node, cost_vec))
   13031              :         return false;
   13032              : 
   13033         1991 :       if (LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo))
   13034              :         {
   13035         1068 :           if (direct_internal_fn_supported_p (IFN_VCOND_MASK_LEN, vectype,
   13036              :                                               OPTIMIZE_FOR_SPEED))
   13037            0 :             vect_record_loop_len (loop_vinfo, lens, vec_num, vectype, 1);
   13038              :           else
   13039         1068 :             vect_record_loop_mask (loop_vinfo, masks, vec_num, vectype, NULL);
   13040              :         }
   13041              : 
   13042         1991 :       if (!vect_compute_type_for_early_break_scalar_iv (loop_vinfo))
   13043              :         return false;
   13044              : 
   13045              :       return true;
   13046              :     }
   13047              : 
   13048              :   /* Tranform.  */
   13049              : 
   13050         1564 :   tree new_temp = NULL_TREE;
   13051         1564 :   gimple *new_stmt = NULL;
   13052              : 
   13053         1564 :   if (dump_enabled_p ())
   13054          387 :     dump_printf_loc (MSG_NOTE, vect_location, "transform early-exit.\n");
   13055              : 
   13056              :   /* For SLP we don't do codegen of the body starting from the gcond, the gconds are
   13057              :      roots and so by the time we get to them we have already codegened the SLP tree
   13058              :      and so we shouldn't try to do so again.  The arguments have already been
   13059              :      vectorized.  It's not very clean to do this here, But the masking code below is
   13060              :      complex and this keeps it all in one place to ease fixes and backports.  Once we
   13061              :      drop the non-SLP loop vect or split vectorizable_* this can be simplified.  */
   13062              : 
   13063         1564 :   gimple *stmt = STMT_VINFO_STMT (stmt_info);
   13064         1564 :   basic_block cond_bb = gimple_bb (stmt);
   13065         1564 :   gimple_stmt_iterator  cond_gsi = gsi_last_bb (cond_bb);
   13066              : 
   13067         1564 :   auto_vec<tree> stmts;
   13068         1564 :   stmts.safe_splice (SLP_TREE_VEC_DEFS (slp_node));
   13069              : 
   13070              :   /* If we're comparing against a previous forall we need to negate the resullts
   13071              :      before we do the final comparison or reduction.  */
   13072         1564 :   if (flipped)
   13073              :     {
   13074              :       /* Rewrite the if(all(mask)) into if (!all(mask)) which is the same as
   13075              :          if (any(~mask)) by negating the masks and flipping the branches.
   13076              : 
   13077              :         1. For unmasked loops we simply reduce the ~mask.
   13078              :         2. For masked loops we reduce (~mask & loop_mask) which is the same as
   13079              :            doing (mask & loop_mask) ^ loop_mask.  */
   13080          294 :       for (unsigned i = 0; i < stmts.length (); i++)
   13081              :         {
   13082          173 :           tree inv_lhs = make_temp_ssa_name (vectype, NULL, "vexit_inv");
   13083          173 :           auto inv_stmt = gimple_build_assign (inv_lhs, BIT_NOT_EXPR, stmts[i]);
   13084          173 :           vect_finish_stmt_generation (loop_vinfo, stmt_info, inv_stmt,
   13085              :                                        &cond_gsi);
   13086          173 :           stmts[i] = inv_lhs;
   13087              :         }
   13088              : 
   13089          121 :       EDGE_SUCC (bb, 0)->flags ^= (EDGE_TRUE_VALUE|EDGE_FALSE_VALUE);
   13090          121 :       EDGE_SUCC (bb, 1)->flags ^= (EDGE_TRUE_VALUE|EDGE_FALSE_VALUE);
   13091              :     }
   13092              : 
   13093              :   /* Determine if we need to reduce the final value.  */
   13094         1564 :   if (stmts.length () > 1)
   13095              :     {
   13096              :       /* We build the reductions in a way to maintain as much parallelism as
   13097              :          possible.  */
   13098          141 :       auto_vec<tree> workset (stmts.length ());
   13099              : 
   13100              :       /* Mask the statements as we queue them up.  Normally we loop over
   13101              :          vec_num,  but since we inspect the exact results of vectorization
   13102              :          we don't need to and instead can just use the stmts themselves.  */
   13103          141 :       if (masked_loop_p)
   13104            0 :         for (unsigned i = 0; i < stmts.length (); i++)
   13105              :           {
   13106            0 :             tree stmt_mask
   13107            0 :               = vect_get_loop_mask (loop_vinfo, gsi, masks, vec_num,
   13108              :                                     vectype, i);
   13109            0 :             stmt_mask
   13110            0 :               = prepare_vec_mask (loop_vinfo, TREE_TYPE (stmt_mask), stmt_mask,
   13111            0 :                                   stmts[i], &cond_gsi);
   13112            0 :             workset.quick_push (stmt_mask);
   13113              :           }
   13114          141 :       else if (len_loop_p)
   13115            0 :         for (unsigned i = 0; i < stmts.length (); i++)
   13116              :           {
   13117            0 :             tree len_mask = vect_gen_loop_len_mask (loop_vinfo, gsi, &cond_gsi,
   13118              :                                                     lens, vec_num,
   13119            0 :                                                     vectype, stmts[i], i, 1);
   13120              : 
   13121            0 :             workset.quick_push (len_mask);
   13122              :           }
   13123              :       else
   13124          141 :         workset.splice (stmts);
   13125              : 
   13126          430 :       while (workset.length () > 1)
   13127              :         {
   13128          289 :           tree arg0 = workset.pop ();
   13129          289 :           tree arg1 = workset.pop ();
   13130          289 :           if (addhn_supported_p && workset.length () == 0)
   13131              :             {
   13132            0 :               new_stmt = gimple_build_call_internal (ifn, 2, arg0, arg1);
   13133            0 :               vectype_out = narrow_type;
   13134            0 :               new_temp = make_temp_ssa_name (vectype_out, NULL, "vexit_reduc");
   13135            0 :               gimple_call_set_lhs (as_a <gcall *> (new_stmt), new_temp);
   13136            0 :               gimple_call_set_nothrow (as_a <gcall *> (new_stmt), true);
   13137              :             }
   13138              :           else
   13139              :             {
   13140          289 :               new_temp = make_temp_ssa_name (vectype_out, NULL, "vexit_reduc");
   13141          289 :               new_stmt
   13142          289 :                 = gimple_build_assign (new_temp, BIT_IOR_EXPR, arg0, arg1);
   13143              :             }
   13144          289 :           vect_finish_stmt_generation (loop_vinfo, stmt_info, new_stmt,
   13145              :                                        &cond_gsi);
   13146          289 :           workset.quick_insert (0, new_temp);
   13147              :         }
   13148          141 :     }
   13149              :   else
   13150              :     {
   13151         1423 :       new_temp = stmts[0];
   13152         1423 :       if (masked_loop_p)
   13153              :         {
   13154            0 :           tree mask
   13155            0 :             = vect_get_loop_mask (loop_vinfo, gsi, masks, 1, vectype, 0);
   13156            0 :           new_temp = prepare_vec_mask (loop_vinfo, TREE_TYPE (mask), mask,
   13157              :                                        new_temp, &cond_gsi);
   13158              :         }
   13159         1423 :       else if (len_loop_p)
   13160            0 :         new_temp = vect_gen_loop_len_mask (loop_vinfo, gsi, &cond_gsi, lens,
   13161              :                                            1, vectype, new_temp, 0, 1);
   13162              :     }
   13163              : 
   13164         1564 :   gcc_assert (new_temp);
   13165              : 
   13166         1564 :   tree cst = build_zero_cst (vectype_out);
   13167         1564 :   gimple_cond_set_condition (cond_stmt, NE_EXPR, new_temp, cst);
   13168         1564 :   update_stmt (orig_stmt);
   13169              : 
   13170              :   /* ??? */
   13171         1564 :   SLP_TREE_VEC_DEFS (slp_node).truncate (0);
   13172              : 
   13173         1564 :   return true;
   13174         1564 : }
   13175              : 
   13176              : /* If SLP_NODE is nonnull, return true if vectorizable_live_operation
   13177              :    can handle all live statements in the node.  Otherwise return true
   13178              :    if STMT_INFO is not live or if vectorizable_live_operation can handle it.
   13179              :    VEC_STMT_P is as for vectorizable_live_operation.  */
   13180              : 
   13181              : static bool
   13182      1423603 : can_vectorize_live_stmts (vec_info *vinfo,
   13183              :                           slp_tree slp_node, slp_instance slp_node_instance,
   13184              :                           bool vec_stmt_p,
   13185              :                           stmt_vector_for_cost *cost_vec)
   13186              : {
   13187      1423603 :   stmt_vec_info slp_stmt_info;
   13188      1423603 :   unsigned int i;
   13189      3211130 :   FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_STMTS (slp_node), i, slp_stmt_info)
   13190              :     {
   13191      1787527 :       if (slp_stmt_info
   13192      1768060 :           && STMT_VINFO_LIVE_P (slp_stmt_info)
   13193      1958375 :           && !vectorizable_live_operation (vinfo, slp_stmt_info, slp_node,
   13194              :                                            slp_node_instance, i,
   13195              :                                            vec_stmt_p, cost_vec))
   13196              :         return false;
   13197              :     }
   13198              : 
   13199              :   return true;
   13200              : }
   13201              : 
   13202              : /* Make sure the statement is vectorizable.  */
   13203              : 
   13204              : opt_result
   13205      2329924 : vect_analyze_stmt (vec_info *vinfo,
   13206              :                    slp_tree node, slp_instance node_instance,
   13207              :                    stmt_vector_for_cost *cost_vec)
   13208              : {
   13209      2329924 :   stmt_vec_info stmt_info = SLP_TREE_REPRESENTATIVE (node);
   13210      2329924 :   bb_vec_info bb_vinfo = dyn_cast <bb_vec_info> (vinfo);
   13211      2329924 :   enum vect_relevant relevance = STMT_VINFO_RELEVANT (stmt_info);
   13212      2329924 :   bool ok;
   13213              : 
   13214      2329924 :   if (dump_enabled_p ())
   13215        97851 :     dump_printf_loc (MSG_NOTE, vect_location, "==> examining statement: %G",
   13216              :                      stmt_info->stmt);
   13217              : 
   13218      4414436 :   if (gimple_has_volatile_ops (stmt_info->stmt))
   13219              :     {
   13220              :       /* ???  This shouldn't really happen, volatile stmts should
   13221              :          not end up in the SLP graph.  */
   13222            0 :       return opt_result::failure_at (stmt_info->stmt,
   13223              :                                      "not vectorized:"
   13224              :                                      " stmt has volatile operands: %G\n",
   13225              :                                      stmt_info->stmt);
   13226              :     }
   13227              : 
   13228              :   /* Skip stmts that do not need to be vectorized.  */
   13229      2329924 :   if (!STMT_VINFO_RELEVANT_P (stmt_info)
   13230            0 :       && !STMT_VINFO_LIVE_P (stmt_info))
   13231              :     {
   13232            0 :       if (dump_enabled_p ())
   13233            0 :         dump_printf_loc (MSG_NOTE, vect_location, "irrelevant.\n");
   13234              : 
   13235              :       /* ???  This shouldn't really happen, irrelevant stmts should
   13236              :          not end up in the SLP graph.  */
   13237            0 :       return opt_result::failure_at (stmt_info->stmt,
   13238              :                                      "not vectorized:"
   13239              :                                      " irrelevant stmt as SLP node %p "
   13240              :                                      "representative.\n",
   13241              :                                      (void *)node);
   13242              :     }
   13243              : 
   13244      2329924 :   switch (STMT_VINFO_DEF_TYPE (stmt_info))
   13245              :     {
   13246              :       case vect_internal_def:
   13247              :       case vect_condition_def:
   13248              :         break;
   13249              : 
   13250        57445 :       case vect_reduction_def:
   13251        57445 :       case vect_nested_cycle:
   13252        57445 :          gcc_assert (!bb_vinfo
   13253              :                      && (relevance == vect_used_in_outer
   13254              :                          || relevance == vect_used_in_outer_by_reduction
   13255              :                          || relevance == vect_used_by_reduction
   13256              :                          || relevance == vect_unused_in_scope
   13257              :                          || relevance == vect_used_only_live));
   13258              :          break;
   13259              : 
   13260          287 :       case vect_double_reduction_def:
   13261          287 :         gcc_assert (!bb_vinfo && node);
   13262              :         break;
   13263              : 
   13264       136784 :       case vect_induction_def:
   13265       136784 :       case vect_first_order_recurrence:
   13266       136784 :         gcc_assert (!bb_vinfo);
   13267              :         break;
   13268              : 
   13269            0 :       case vect_constant_def:
   13270            0 :       case vect_external_def:
   13271            0 :       case vect_unknown_def_type:
   13272            0 :       default:
   13273            0 :         gcc_unreachable ();
   13274              :     }
   13275              : 
   13276      2329924 :   tree saved_vectype = STMT_VINFO_VECTYPE (stmt_info);
   13277      2329924 :   STMT_VINFO_VECTYPE (stmt_info) = NULL_TREE;
   13278              : 
   13279      2329924 :   if (STMT_VINFO_RELEVANT_P (stmt_info))
   13280              :     {
   13281      2329924 :       gcall *call = dyn_cast <gcall *> (stmt_info->stmt);
   13282      2329924 :       gcc_assert (SLP_TREE_VECTYPE (node)
   13283              :                   || gimple_code (stmt_info->stmt) == GIMPLE_COND
   13284              :                   || (call && gimple_call_lhs (call) == NULL_TREE));
   13285              :     }
   13286              : 
   13287      2329924 :   ok = true;
   13288      2329924 :   if (bb_vinfo
   13289      1177638 :       || (STMT_VINFO_RELEVANT_P (stmt_info)
   13290            0 :           || STMT_VINFO_DEF_TYPE (stmt_info) == vect_reduction_def))
   13291              :     /* Prefer vectorizable_call over vectorizable_simd_clone_call so
   13292              :        -mveclibabi= takes preference over library functions with
   13293              :        the simd attribute.  */
   13294      2329924 :     ok = (vectorizable_call (vinfo, stmt_info, NULL, node, cost_vec)
   13295      2324411 :           || vectorizable_simd_clone_call (vinfo, stmt_info, NULL, node,
   13296              :                                            cost_vec)
   13297      2323959 :           || vectorizable_conversion (vinfo, stmt_info, NULL, node, cost_vec)
   13298      2258385 :           || vectorizable_operation (vinfo, stmt_info, NULL, node, cost_vec)
   13299      1840414 :           || vectorizable_assignment (vinfo, stmt_info, NULL, node, cost_vec)
   13300      1783100 :           || vectorizable_load (vinfo, stmt_info, NULL, node, cost_vec)
   13301      1415468 :           || vectorizable_store (vinfo, stmt_info, NULL, node, cost_vec)
   13302       643253 :           || vectorizable_shift (vinfo, stmt_info, NULL, node, cost_vec)
   13303       597792 :           || vectorizable_condition (vinfo, stmt_info, NULL, node, cost_vec)
   13304       578448 :           || vectorizable_comparison (vinfo, stmt_info, NULL, node, cost_vec)
   13305       459299 :           || (bb_vinfo
   13306       124415 :               && vectorizable_phi (bb_vinfo, stmt_info, node, cost_vec))
   13307      2732244 :           || (is_a <loop_vec_info> (vinfo)
   13308       334884 :               && (vectorizable_lane_reducing (as_a <loop_vec_info> (vinfo),
   13309              :                                               stmt_info, node, cost_vec)
   13310       334430 :                   || vectorizable_reduction (as_a <loop_vec_info> (vinfo),
   13311              :                                              stmt_info,
   13312              :                                              node, node_instance, cost_vec)
   13313       279208 :                   || vectorizable_induction (as_a <loop_vec_info> (vinfo),
   13314              :                                              stmt_info, node, cost_vec)
   13315       173884 :                   || vectorizable_lc_phi (as_a <loop_vec_info> (vinfo),
   13316              :                                           stmt_info, node)
   13317       173123 :                   || vectorizable_recurr (as_a <loop_vec_info> (vinfo),
   13318              :                                           stmt_info, node, cost_vec)
   13319       172875 :                   || vectorizable_early_exit (as_a <loop_vec_info> (vinfo),
   13320              :                                               stmt_info, NULL, node,
   13321              :                                               cost_vec))));
   13322              : 
   13323      2329924 :   STMT_VINFO_VECTYPE (stmt_info) = saved_vectype;
   13324              : 
   13325      2089613 :   if (!ok)
   13326       240311 :     return opt_result::failure_at (stmt_info->stmt,
   13327              :                                    "not vectorized:"
   13328              :                                    " relevant stmt not supported: %G",
   13329              :                                    stmt_info->stmt);
   13330              : 
   13331              :   /* Stmts that are (also) "live" (i.e. - that are used out of the loop)
   13332              :       need extra handling, except for vectorizable reductions.  */
   13333      2089613 :   if (!bb_vinfo
   13334      1004763 :       && SLP_TREE_TYPE (node) != reduc_vec_info_type
   13335       997429 :       && (SLP_TREE_TYPE (node) != lc_phi_info_type
   13336          761 :           || SLP_TREE_DEF_TYPE (node) == vect_internal_def)
   13337       997429 :       && (!node->ldst_lanes || SLP_TREE_PERMUTE_P (node))
   13338      3087042 :       && !can_vectorize_live_stmts (as_a <loop_vec_info> (vinfo),
   13339              :                                     node, node_instance,
   13340              :                                     false, cost_vec))
   13341            0 :     return opt_result::failure_at (stmt_info->stmt,
   13342              :                                    "not vectorized:"
   13343              :                                    " live stmt not supported: %G",
   13344              :                                    stmt_info->stmt);
   13345              : 
   13346      2089613 :   return opt_result::success ();
   13347              : }
   13348              : 
   13349              : 
   13350              : /* Function vect_transform_stmt.
   13351              : 
   13352              :    Create a vectorized stmt to replace STMT_INFO, and insert it at GSI.  */
   13353              : 
   13354              : bool
   13355       969861 : vect_transform_stmt (vec_info *vinfo,
   13356              :                      stmt_vec_info stmt_info, gimple_stmt_iterator *gsi,
   13357              :                      slp_tree slp_node, slp_instance slp_node_instance)
   13358              : {
   13359       969861 :   bool is_store = false;
   13360       969861 :   bool done;
   13361              : 
   13362       969861 :   gcc_assert (slp_node);
   13363              : 
   13364       969861 :   if (stmt_info)
   13365       969020 :     STMT_VINFO_VECTYPE (stmt_info) = NULL_TREE;
   13366              : 
   13367       969861 :   switch (SLP_TREE_TYPE (slp_node))
   13368              :     {
   13369        22934 :     case type_demotion_vec_info_type:
   13370        22934 :     case type_promotion_vec_info_type:
   13371        22934 :     case type_conversion_vec_info_type:
   13372        22934 :       done = vectorizable_conversion (vinfo, stmt_info, gsi, slp_node, NULL);
   13373        22934 :       gcc_assert (done);
   13374              :       break;
   13375              : 
   13376        16173 :     case induc_vec_info_type:
   13377        16173 :       done = vectorizable_induction (as_a <loop_vec_info> (vinfo),
   13378              :                                      stmt_info, slp_node, NULL);
   13379        16173 :       gcc_assert (done);
   13380              :       break;
   13381              : 
   13382         7821 :     case shift_vec_info_type:
   13383         7821 :       done = vectorizable_shift (vinfo, stmt_info, gsi, slp_node, NULL);
   13384         7821 :       gcc_assert (done);
   13385              :       break;
   13386              : 
   13387       115465 :     case op_vec_info_type:
   13388       115465 :       done = vectorizable_operation (vinfo, stmt_info, gsi, slp_node, NULL);
   13389       115465 :       gcc_assert (done);
   13390              :       break;
   13391              : 
   13392        15020 :     case assignment_vec_info_type:
   13393        15020 :       done = vectorizable_assignment (vinfo, stmt_info, gsi, slp_node, NULL);
   13394        15020 :       gcc_assert (done);
   13395              :       break;
   13396              : 
   13397       165901 :     case load_vec_info_type:
   13398       165901 :       done = vectorizable_load (vinfo, stmt_info, gsi, slp_node, NULL);
   13399       165901 :       gcc_assert (done);
   13400              :       break;
   13401              : 
   13402       543687 :     case store_vec_info_type:
   13403       543687 :       done = vectorizable_store (vinfo, stmt_info, gsi, slp_node, NULL);
   13404       543687 :       gcc_assert (done);
   13405              :       is_store = true;
   13406              :       break;
   13407              : 
   13408         8481 :     case condition_vec_info_type:
   13409         8481 :       done = vectorizable_condition (vinfo, stmt_info, gsi, slp_node, NULL);
   13410         8481 :       gcc_assert (done);
   13411              :       break;
   13412              : 
   13413        12392 :     case comparison_vec_info_type:
   13414        12392 :       done = vectorizable_comparison (vinfo, stmt_info, gsi, slp_node, NULL);
   13415        12392 :       gcc_assert (done);
   13416              :       break;
   13417              : 
   13418         4210 :     case call_vec_info_type:
   13419         4210 :       done = vectorizable_call (vinfo, stmt_info, gsi, slp_node, NULL);
   13420         4210 :       break;
   13421              : 
   13422          357 :     case call_simd_clone_vec_info_type:
   13423          357 :       done = vectorizable_simd_clone_call (vinfo, stmt_info, gsi,
   13424              :                                            slp_node, NULL);
   13425          357 :       break;
   13426              : 
   13427         2575 :     case reduc_vec_info_type:
   13428         2575 :       done = vect_transform_reduction (as_a <loop_vec_info> (vinfo), stmt_info,
   13429              :                                        gsi, slp_node);
   13430         2575 :       gcc_assert (done);
   13431              :       break;
   13432              : 
   13433        23709 :     case cycle_phi_info_type:
   13434        23709 :       done = vect_transform_cycle_phi (as_a <loop_vec_info> (vinfo), stmt_info,
   13435              :                                        slp_node, slp_node_instance);
   13436        23709 :       gcc_assert (done);
   13437              :       break;
   13438              : 
   13439          504 :     case lc_phi_info_type:
   13440          504 :       done = vect_transform_lc_phi (as_a <loop_vec_info> (vinfo),
   13441              :                                     stmt_info, slp_node);
   13442          504 :       gcc_assert (done);
   13443              :       break;
   13444              : 
   13445           40 :     case recurr_info_type:
   13446           40 :       done = vectorizable_recurr (as_a <loop_vec_info> (vinfo),
   13447              :                                   stmt_info, slp_node, NULL);
   13448           40 :       gcc_assert (done);
   13449              :       break;
   13450              : 
   13451        14115 :     case phi_info_type:
   13452        14115 :       done = vectorizable_phi (as_a <bb_vec_info> (vinfo),
   13453              :                                stmt_info, slp_node, NULL);
   13454        14115 :       gcc_assert (done);
   13455              :       break;
   13456              : 
   13457            0 :     case loop_exit_ctrl_vec_info_type:
   13458            0 :       done = vectorizable_early_exit (as_a <loop_vec_info> (vinfo),
   13459              :                                       stmt_info, gsi, slp_node, NULL);
   13460            0 :       gcc_assert (done);
   13461              :       break;
   13462              : 
   13463        16477 :     case permute_info_type:
   13464        16477 :       done = vectorizable_slp_permutation (vinfo, gsi, slp_node, NULL);
   13465        16477 :       gcc_assert (done);
   13466              :       break;
   13467              : 
   13468            0 :     default:
   13469            0 :       if (!STMT_VINFO_LIVE_P (stmt_info))
   13470              :         {
   13471            0 :           if (dump_enabled_p ())
   13472            0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
   13473              :                              "stmt not supported.\n");
   13474            0 :           gcc_unreachable ();
   13475              :         }
   13476       969861 :       done = true;
   13477              :     }
   13478              : 
   13479       969861 :   if (SLP_TREE_TYPE (slp_node) != store_vec_info_type
   13480       426174 :       && (!slp_node->ldst_lanes || SLP_TREE_PERMUTE_P (slp_node)))
   13481              :     {
   13482              :       /* Handle stmts whose DEF is used outside the loop-nest that is
   13483              :          being vectorized.  */
   13484       426174 :       done = can_vectorize_live_stmts (vinfo, slp_node,
   13485              :                                        slp_node_instance, true, NULL);
   13486       426174 :       gcc_assert (done);
   13487              :     }
   13488              : 
   13489       969861 :   return is_store;
   13490              : }
   13491              : 
   13492              : 
   13493              : /* Remove a group of stores (for SLP or interleaving), free their
   13494              :    stmt_vec_info.  */
   13495              : 
   13496              : void
   13497            0 : vect_remove_stores (vec_info *vinfo, stmt_vec_info first_stmt_info)
   13498              : {
   13499            0 :   stmt_vec_info next_stmt_info = first_stmt_info;
   13500              : 
   13501            0 :   while (next_stmt_info)
   13502              :     {
   13503            0 :       stmt_vec_info tmp = DR_GROUP_NEXT_ELEMENT (next_stmt_info);
   13504            0 :       next_stmt_info = vect_orig_stmt (next_stmt_info);
   13505              :       /* Free the attached stmt_vec_info and remove the stmt.  */
   13506            0 :       vinfo->remove_stmt (next_stmt_info);
   13507            0 :       next_stmt_info = tmp;
   13508              :     }
   13509            0 : }
   13510              : 
   13511              : /* If NUNITS is nonzero, return a vector type that contains NUNITS
   13512              :    elements of type SCALAR_TYPE, or null if the target doesn't support
   13513              :    such a type.
   13514              : 
   13515              :    If NUNITS is zero, return a vector type that contains elements of
   13516              :    type SCALAR_TYPE, choosing whichever vector size the target prefers.
   13517              : 
   13518              :    If PREVAILING_MODE is VOIDmode, we have not yet chosen a vector mode
   13519              :    for this vectorization region and want to "autodetect" the best choice.
   13520              :    Otherwise, PREVAILING_MODE is a previously-chosen vector TYPE_MODE
   13521              :    and we want the new type to be interoperable with it.   PREVAILING_MODE
   13522              :    in this case can be a scalar integer mode or a vector mode; when it
   13523              :    is a vector mode, the function acts like a tree-level version of
   13524              :    related_vector_mode.  */
   13525              : 
   13526              : tree
   13527     30101309 : get_related_vectype_for_scalar_type (machine_mode prevailing_mode,
   13528              :                                      tree scalar_type, poly_uint64 nunits)
   13529              : {
   13530     30101309 :   tree orig_scalar_type = scalar_type;
   13531     30101309 :   scalar_mode inner_mode;
   13532     30101309 :   machine_mode simd_mode;
   13533     30101309 :   tree vectype;
   13534              : 
   13535     30101309 :   if ((!INTEGRAL_TYPE_P (scalar_type)
   13536     10307679 :        && !POINTER_TYPE_P (scalar_type)
   13537      1650598 :        && !SCALAR_FLOAT_TYPE_P (scalar_type))
   13538     39904339 :       || (!is_int_mode (TYPE_MODE (scalar_type), &inner_mode)
   13539      1146031 :           && !is_float_mode (TYPE_MODE (scalar_type), &inner_mode)))
   13540       507864 :     return NULL_TREE;
   13541              : 
   13542     29593445 :   unsigned int nbytes = GET_MODE_SIZE (inner_mode);
   13543              : 
   13544              :   /* Interoperability between modes requires one to be a constant multiple
   13545              :      of the other, so that the number of vectors required for each operation
   13546              :      is a compile-time constant.  */
   13547     29593445 :   if (prevailing_mode != VOIDmode
   13548     28467631 :       && !constant_multiple_p (nunits * nbytes,
   13549     28467631 :                                GET_MODE_SIZE (prevailing_mode))
   13550     31071032 :       && !constant_multiple_p (GET_MODE_SIZE (prevailing_mode),
   13551      1477587 :                                nunits * nbytes))
   13552              :     return NULL_TREE;
   13553              : 
   13554              :   /* For vector types of elements whose mode precision doesn't
   13555              :      match their types precision we use a element type of mode
   13556              :      precision.  The vectorization routines will have to make sure
   13557              :      they support the proper result truncation/extension.
   13558              :      We also make sure to build vector types with INTEGER_TYPE
   13559              :      component type only.  */
   13560     29593445 :   if (INTEGRAL_TYPE_P (scalar_type)
   13561     49386993 :       && (GET_MODE_BITSIZE (inner_mode) != TYPE_PRECISION (scalar_type)
   13562     18324615 :           || TREE_CODE (scalar_type) != INTEGER_TYPE))
   13563      1677944 :     scalar_type = build_nonstandard_integer_type (GET_MODE_BITSIZE (inner_mode),
   13564      1677944 :                                                   TYPE_UNSIGNED (scalar_type));
   13565              : 
   13566              :   /* We shouldn't end up building VECTOR_TYPEs of non-scalar components.
   13567              :      When the component mode passes the above test simply use a type
   13568              :      corresponding to that mode.  The theory is that any use that
   13569              :      would cause problems with this will disable vectorization anyway.  */
   13570     27915501 :   else if (!SCALAR_FLOAT_TYPE_P (scalar_type)
   13571              :            && !INTEGRAL_TYPE_P (scalar_type))
   13572      8657081 :     scalar_type = lang_hooks.types.type_for_mode (inner_mode, 1);
   13573              : 
   13574              :   /* We can't build a vector type of elements with alignment bigger than
   13575              :      their size.  */
   13576     19258420 :   else if (nbytes < TYPE_ALIGN_UNIT (scalar_type))
   13577       375360 :     scalar_type = lang_hooks.types.type_for_mode (inner_mode,
   13578       187680 :                                                   TYPE_UNSIGNED (scalar_type));
   13579              : 
   13580              :   /* If we felt back to using the mode fail if there was
   13581              :      no scalar type for it.  */
   13582     29593445 :   if (scalar_type == NULL_TREE)
   13583              :     return NULL_TREE;
   13584              : 
   13585              :   /* If no prevailing mode was supplied, use the mode the target prefers.
   13586              :      Otherwise lookup a vector mode based on the prevailing mode.  */
   13587     29593445 :   if (prevailing_mode == VOIDmode)
   13588              :     {
   13589      1125814 :       gcc_assert (known_eq (nunits, 0U));
   13590      1125814 :       simd_mode = targetm.vectorize.preferred_simd_mode (inner_mode);
   13591      1125814 :       if (SCALAR_INT_MODE_P (simd_mode))
   13592              :         {
   13593              :           /* Traditional behavior is not to take the integer mode
   13594              :              literally, but simply to use it as a way of determining
   13595              :              the vector size.  It is up to mode_for_vector to decide
   13596              :              what the TYPE_MODE should be.
   13597              : 
   13598              :              Note that nunits == 1 is allowed in order to support single
   13599              :              element vector types.  */
   13600        60154 :           if (!multiple_p (GET_MODE_SIZE (simd_mode), nbytes, &nunits)
   13601          545 :               || !mode_for_vector (inner_mode, nunits).exists (&simd_mode))
   13602        29532 :             return NULL_TREE;
   13603              :         }
   13604              :     }
   13605     28467631 :   else if (SCALAR_INT_MODE_P (prevailing_mode)
   13606     28467631 :            || !related_vector_mode (prevailing_mode,
   13607     26487669 :                                     inner_mode, nunits).exists (&simd_mode))
   13608              :     {
   13609              :       /* Fall back to using mode_for_vector, mostly in the hope of being
   13610              :          able to use an integer mode.  */
   13611      1979962 :       if (known_eq (nunits, 0U)
   13612      4628613 :           && !multiple_p (GET_MODE_SIZE (prevailing_mode), nbytes, &nunits))
   13613              :         return NULL_TREE;
   13614              : 
   13615       138670 :       if (!mode_for_vector (inner_mode, nunits).exists (&simd_mode))
   13616       128604 :         return NULL_TREE;
   13617              :     }
   13618              : 
   13619     27594017 :   vectype = build_vector_type_for_mode (scalar_type, simd_mode);
   13620              : 
   13621              :   /* In cases where the mode was chosen by mode_for_vector, check that
   13622              :      the target actually supports the chosen mode, or that it at least
   13623              :      allows the vector mode to be replaced by a like-sized integer.  */
   13624     55188034 :   if (!VECTOR_MODE_P (TYPE_MODE (vectype))
   13625     27604341 :       && !INTEGRAL_MODE_P (TYPE_MODE (vectype)))
   13626              :     return NULL_TREE;
   13627              : 
   13628              :   /* Re-attach the address-space qualifier if we canonicalized the scalar
   13629              :      type.  */
   13630     27585934 :   if (TYPE_ADDR_SPACE (orig_scalar_type) != TYPE_ADDR_SPACE (vectype))
   13631            5 :     return build_qualified_type
   13632            5 :              (vectype, KEEP_QUAL_ADDR_SPACE (TYPE_QUALS (orig_scalar_type)));
   13633              : 
   13634              :   return vectype;
   13635              : }
   13636              : 
   13637              : /* Function get_vectype_for_scalar_type.
   13638              : 
   13639              :    Returns the vector type corresponding to SCALAR_TYPE as supported
   13640              :    by the target.  If GROUP_SIZE is nonzero and we're performing BB
   13641              :    vectorization, make sure that the number of elements in the vector
   13642              :    is no bigger than GROUP_SIZE.  */
   13643              : 
   13644              : tree
   13645     25698445 : get_vectype_for_scalar_type (vec_info *vinfo, tree scalar_type,
   13646              :                              unsigned int group_size)
   13647              : {
   13648              :   /* For BB vectorization, we should always have a group size once we've
   13649              :      constructed the SLP tree; the only valid uses of zero GROUP_SIZEs
   13650              :      are tentative requests during things like early data reference
   13651              :      analysis and pattern recognition.  */
   13652     25698445 :   if (is_a <bb_vec_info> (vinfo))
   13653     23434866 :     gcc_assert (vinfo->slp_instances.is_empty () || group_size != 0);
   13654              :   else
   13655              :     group_size = 0;
   13656              : 
   13657     25698445 :   tree vectype = get_related_vectype_for_scalar_type (vinfo->vector_mode,
   13658              :                                                       scalar_type);
   13659     25698445 :   if (vectype && vinfo->vector_mode == VOIDmode)
   13660      1049591 :     vinfo->vector_mode = TYPE_MODE (vectype);
   13661              : 
   13662              :   /* Register the natural choice of vector type, before the group size
   13663              :      has been applied.  */
   13664            0 :   if (vectype)
   13665     23344940 :     vinfo->used_vector_modes.add (TYPE_MODE (vectype));
   13666              : 
   13667              :   /* If the natural choice of vector type doesn't satisfy GROUP_SIZE,
   13668              :      try again with an explicit number of elements.  */
   13669     23344940 :   if (vectype
   13670     23344940 :       && group_size
   13671     25698445 :       && maybe_ge (TYPE_VECTOR_SUBPARTS (vectype), group_size))
   13672              :     {
   13673              :       /* Start with the biggest number of units that fits within
   13674              :          GROUP_SIZE and halve it until we find a valid vector type.
   13675              :          Usually either the first attempt will succeed or all will
   13676              :          fail (in the latter case because GROUP_SIZE is too small
   13677              :          for the target), but it's possible that a target could have
   13678              :          a hole between supported vector types.
   13679              : 
   13680              :          If GROUP_SIZE is not a power of 2, this has the effect of
   13681              :          trying the largest power of 2 that fits within the group,
   13682              :          even though the group is not a multiple of that vector size.
   13683              :          The BB vectorizer will then try to carve up the group into
   13684              :          smaller pieces.  */
   13685      3012793 :       unsigned int nunits = 1 << floor_log2 (group_size);
   13686      3012793 :       do
   13687              :         {
   13688      3012793 :           vectype = get_related_vectype_for_scalar_type (vinfo->vector_mode,
   13689      3012793 :                                                          scalar_type, nunits);
   13690      3012793 :           nunits /= 2;
   13691              :         }
   13692      3012793 :       while (nunits > 1 && !vectype);
   13693              :     }
   13694              : 
   13695     25698445 :   return vectype;
   13696              : }
   13697              : 
   13698              : /* Return the vector type corresponding to SCALAR_TYPE as supported
   13699              :    by the target.  NODE, if nonnull, is the SLP tree node that will
   13700              :    use the returned vector type.  */
   13701              : 
   13702              : tree
   13703       160252 : get_vectype_for_scalar_type (vec_info *vinfo, tree scalar_type, slp_tree node)
   13704              : {
   13705       160252 :   unsigned int group_size = 0;
   13706       160252 :   if (node)
   13707       160252 :     group_size = SLP_TREE_LANES (node);
   13708       160252 :   return get_vectype_for_scalar_type (vinfo, scalar_type, group_size);
   13709              : }
   13710              : 
   13711              : /* Function get_mask_type_for_scalar_type.
   13712              : 
   13713              :    Returns the mask type corresponding to a result of comparison
   13714              :    of vectors of specified SCALAR_TYPE as supported by target.
   13715              :    If GROUP_SIZE is nonzero and we're performing BB vectorization,
   13716              :    make sure that the number of elements in the vector is no bigger
   13717              :    than GROUP_SIZE.  */
   13718              : 
   13719              : tree
   13720      1057935 : get_mask_type_for_scalar_type (vec_info *vinfo, tree scalar_type,
   13721              :                                unsigned int group_size)
   13722              : {
   13723      1057935 :   tree vectype = get_vectype_for_scalar_type (vinfo, scalar_type, group_size);
   13724              : 
   13725      1057935 :   if (!vectype)
   13726              :     return NULL;
   13727              : 
   13728      1034543 :   return truth_type_for (vectype);
   13729              : }
   13730              : 
   13731              : /* Function get_mask_type_for_scalar_type.
   13732              : 
   13733              :    Returns the mask type corresponding to a result of comparison
   13734              :    of vectors of specified SCALAR_TYPE as supported by target.
   13735              :    NODE, if nonnull, is the SLP tree node that will use the returned
   13736              :    vector type.  */
   13737              : 
   13738              : tree
   13739           17 : get_mask_type_for_scalar_type (vec_info *vinfo, tree scalar_type,
   13740              :                                slp_tree node)
   13741              : {
   13742           17 :   tree vectype = get_vectype_for_scalar_type (vinfo, scalar_type, node);
   13743              : 
   13744           17 :   if (!vectype)
   13745              :     return NULL;
   13746              : 
   13747           17 :   return truth_type_for (vectype);
   13748              : }
   13749              : 
   13750              : /* Function get_same_sized_vectype
   13751              : 
   13752              :    Returns a vector type corresponding to SCALAR_TYPE of size
   13753              :    VECTOR_TYPE if supported by the target.  */
   13754              : 
   13755              : tree
   13756       143359 : get_same_sized_vectype (tree scalar_type, tree vector_type)
   13757              : {
   13758       143359 :   if (VECT_SCALAR_BOOLEAN_TYPE_P (scalar_type))
   13759            0 :     return truth_type_for (vector_type);
   13760              : 
   13761       143359 :   poly_uint64 nunits;
   13762       286718 :   if (!multiple_p (GET_MODE_SIZE (TYPE_MODE (vector_type)),
   13763       286718 :                    GET_MODE_SIZE (TYPE_MODE (scalar_type)), &nunits))
   13764              :     return NULL_TREE;
   13765              : 
   13766       143359 :   return get_related_vectype_for_scalar_type (TYPE_MODE (vector_type),
   13767       143359 :                                               scalar_type, nunits);
   13768              : }
   13769              : 
   13770              : /* Return true if replacing LOOP_VINFO->vector_mode with VECTOR_MODE
   13771              :    would not change the chosen vector modes.  */
   13772              : 
   13773              : bool
   13774      1538518 : vect_chooses_same_modes_p (vec_info *vinfo, machine_mode vector_mode)
   13775              : {
   13776      1538518 :   for (vec_info::mode_set::iterator i = vinfo->used_vector_modes.begin ();
   13777      3560944 :        i != vinfo->used_vector_modes.end (); ++i)
   13778      1806717 :     if (!VECTOR_MODE_P (*i)
   13779      5420151 :         || related_vector_mode (vector_mode, GET_MODE_INNER (*i), 0) != *i)
   13780       795504 :       return false;
   13781       743014 :   return true;
   13782              : }
   13783              : 
   13784              : /* Return true if replacing VECTOR_MODE with ALT_VECTOR_MODE would not
   13785              :    change the chosen vector modes for analysis of a loop.  */
   13786              : 
   13787              : bool
   13788       348262 : vect_chooses_same_modes_p (machine_mode vector_mode,
   13789              :                            machine_mode alt_vector_mode)
   13790              : {
   13791        50801 :   return (VECTOR_MODE_P (vector_mode)
   13792       348262 :           && VECTOR_MODE_P (alt_vector_mode)
   13793       696524 :           && (related_vector_mode (vector_mode,
   13794              :                                    GET_MODE_INNER (alt_vector_mode))
   13795       348262 :               == alt_vector_mode)
   13796       374292 :           && (related_vector_mode (alt_vector_mode,
   13797              :                                    GET_MODE_INNER (vector_mode))
   13798        13015 :               == vector_mode));
   13799              : }
   13800              : 
   13801              : /* Function vect_is_simple_use.
   13802              : 
   13803              :    Input:
   13804              :    VINFO - the vect info of the loop or basic block that is being vectorized.
   13805              :    OPERAND - operand in the loop or bb.
   13806              :    Output:
   13807              :    DEF_STMT_INFO_OUT (optional) - information about the defining stmt in
   13808              :      case OPERAND is an SSA_NAME that is defined in the vectorizable region
   13809              :    DEF_STMT_OUT (optional) - the defining stmt in case OPERAND is an SSA_NAME;
   13810              :      the definition could be anywhere in the function
   13811              :    DT - the type of definition
   13812              : 
   13813              :    Returns whether a stmt with OPERAND can be vectorized.
   13814              :    For loops, supportable operands are constants, loop invariants, and operands
   13815              :    that are defined by the current iteration of the loop.  Unsupportable
   13816              :    operands are those that are defined by a previous iteration of the loop (as
   13817              :    is the case in reduction/induction computations).
   13818              :    For basic blocks, supportable operands are constants and bb invariants.
   13819              :    For now, operands defined outside the basic block are not supported.  */
   13820              : 
   13821              : bool
   13822     39595240 : vect_is_simple_use (tree operand, vec_info *vinfo, enum vect_def_type *dt,
   13823              :                     stmt_vec_info *def_stmt_info_out, gimple **def_stmt_out)
   13824              : {
   13825     39595240 :   if (def_stmt_info_out)
   13826     37750362 :     *def_stmt_info_out = NULL;
   13827     39595240 :   if (def_stmt_out)
   13828      9234056 :     *def_stmt_out = NULL;
   13829     39595240 :   *dt = vect_unknown_def_type;
   13830              : 
   13831     39595240 :   if (dump_enabled_p ())
   13832              :     {
   13833       749070 :       dump_printf_loc (MSG_NOTE, vect_location,
   13834              :                        "vect_is_simple_use: operand ");
   13835       749070 :       if (TREE_CODE (operand) == SSA_NAME
   13836       749070 :           && !SSA_NAME_IS_DEFAULT_DEF (operand))
   13837       687415 :         dump_gimple_expr (MSG_NOTE, TDF_SLIM, SSA_NAME_DEF_STMT (operand), 0);
   13838              :       else
   13839        61655 :         dump_generic_expr (MSG_NOTE, TDF_SLIM, operand);
   13840              :     }
   13841              : 
   13842     39595240 :   if (CONSTANT_CLASS_P (operand))
   13843      2649491 :     *dt = vect_constant_def;
   13844     36945749 :   else if (is_gimple_min_invariant (operand))
   13845       331454 :     *dt = vect_external_def;
   13846     36614295 :   else if (TREE_CODE (operand) != SSA_NAME)
   13847          957 :     *dt = vect_unknown_def_type;
   13848     36613338 :   else if (SSA_NAME_IS_DEFAULT_DEF (operand))
   13849       525503 :     *dt = vect_external_def;
   13850              :   else
   13851              :     {
   13852     36087835 :       gimple *def_stmt = SSA_NAME_DEF_STMT (operand);
   13853     36087835 :       stmt_vec_info stmt_vinfo = vinfo->lookup_def (operand);
   13854     36087835 :       if (!stmt_vinfo)
   13855       753984 :         *dt = vect_external_def;
   13856              :       else
   13857              :         {
   13858     35333851 :           stmt_vinfo = vect_stmt_to_vectorize (stmt_vinfo);
   13859     35333851 :           def_stmt = stmt_vinfo->stmt;
   13860     35333851 :           *dt = STMT_VINFO_DEF_TYPE (stmt_vinfo);
   13861     35333851 :           if (def_stmt_info_out)
   13862     33497927 :             *def_stmt_info_out = stmt_vinfo;
   13863              :         }
   13864     36087835 :       if (def_stmt_out)
   13865      9024650 :         *def_stmt_out = def_stmt;
   13866              :     }
   13867              : 
   13868     39595240 :   if (dump_enabled_p ())
   13869              :     {
   13870       749070 :       dump_printf (MSG_NOTE, ", type of def: ");
   13871       749070 :       switch (*dt)
   13872              :         {
   13873            0 :         case vect_uninitialized_def:
   13874            0 :           dump_printf (MSG_NOTE, "uninitialized\n");
   13875            0 :           break;
   13876        51066 :         case vect_constant_def:
   13877        51066 :           dump_printf (MSG_NOTE, "constant\n");
   13878        51066 :           break;
   13879        25488 :         case vect_external_def:
   13880        25488 :           dump_printf (MSG_NOTE, "external\n");
   13881        25488 :           break;
   13882       537471 :         case vect_internal_def:
   13883       537471 :           dump_printf (MSG_NOTE, "internal\n");
   13884       537471 :           break;
   13885       105316 :         case vect_induction_def:
   13886       105316 :           dump_printf (MSG_NOTE, "induction\n");
   13887       105316 :           break;
   13888        26380 :         case vect_reduction_def:
   13889        26380 :           dump_printf (MSG_NOTE, "reduction\n");
   13890        26380 :           break;
   13891          482 :         case vect_double_reduction_def:
   13892          482 :           dump_printf (MSG_NOTE, "double reduction\n");
   13893          482 :           break;
   13894         2175 :         case vect_nested_cycle:
   13895         2175 :           dump_printf (MSG_NOTE, "nested cycle\n");
   13896         2175 :           break;
   13897          264 :         case vect_first_order_recurrence:
   13898          264 :           dump_printf (MSG_NOTE, "first order recurrence\n");
   13899          264 :           break;
   13900            0 :         case vect_condition_def:
   13901            0 :           dump_printf (MSG_NOTE, "control flow\n");
   13902            0 :           break;
   13903          428 :         case vect_unknown_def_type:
   13904          428 :           dump_printf (MSG_NOTE, "unknown\n");
   13905          428 :           break;
   13906              :         }
   13907              :     }
   13908              : 
   13909     39595240 :   if (*dt == vect_unknown_def_type)
   13910              :     {
   13911        59381 :       if (dump_enabled_p ())
   13912          428 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
   13913              :                          "Unsupported pattern.\n");
   13914        59381 :       return false;
   13915              :     }
   13916              : 
   13917              :   return true;
   13918              : }
   13919              : 
   13920              : /* Function vect_is_simple_use.
   13921              : 
   13922              :    Same as vect_is_simple_use but determines the operand by operand
   13923              :    position OPERAND from either STMT or SLP_NODE, filling in *OP
   13924              :    and *SLP_DEF (when SLP_NODE is not NULL).  */
   13925              : 
   13926              : bool
   13927      3366948 : vect_is_simple_use (vec_info *vinfo, slp_tree slp_node,
   13928              :                     unsigned operand, tree *op, slp_tree *slp_def,
   13929              :                     enum vect_def_type *dt,
   13930              :                     tree *vectype, stmt_vec_info *def_stmt_info_out)
   13931              : {
   13932      3366948 :   slp_tree child = SLP_TREE_CHILDREN (slp_node)[operand];
   13933      3366948 :   *slp_def = child;
   13934      3366948 :   *vectype = SLP_TREE_VECTYPE (child);
   13935      3366948 :   if (SLP_TREE_DEF_TYPE (child) == vect_internal_def)
   13936              :     {
   13937              :       /* ???  VEC_PERM nodes might be intermediate and their lane value
   13938              :          have no representative (nor do we build a VEC_PERM stmt for
   13939              :          the actual operation).  Note for two-operator nodes we set
   13940              :          a representative but leave scalar stmts empty as we'd only
   13941              :          have one for a subset of lanes.  Ideally no caller would
   13942              :          require *op for internal defs.  */
   13943      1745242 :       if (SLP_TREE_REPRESENTATIVE (child))
   13944              :         {
   13945      1744514 :           *op = gimple_get_lhs (SLP_TREE_REPRESENTATIVE (child)->stmt);
   13946      1744514 :           return vect_is_simple_use (*op, vinfo, dt, def_stmt_info_out);
   13947              :         }
   13948              :       else
   13949              :         {
   13950          728 :           gcc_assert (SLP_TREE_PERMUTE_P (child));
   13951          728 :           *op = error_mark_node;
   13952          728 :           *dt = vect_internal_def;
   13953          728 :           if (def_stmt_info_out)
   13954            0 :             *def_stmt_info_out = NULL;
   13955          728 :           return true;
   13956              :         }
   13957              :     }
   13958              :   else
   13959              :     {
   13960      1621706 :       if (def_stmt_info_out)
   13961        50196 :         *def_stmt_info_out = NULL;
   13962      1621706 :       *op = SLP_TREE_SCALAR_OPS (child)[0];
   13963      1621706 :       *dt = SLP_TREE_DEF_TYPE (child);
   13964      1621706 :       return true;
   13965              :     }
   13966              : }
   13967              : 
   13968              : /* If OP is not NULL and is external or constant update its vector
   13969              :    type with VECTYPE.  Returns true if successful or false if not,
   13970              :    for example when conflicting vector types are present.  */
   13971              : 
   13972              : bool
   13973      2955234 : vect_maybe_update_slp_op_vectype (slp_tree op, tree vectype)
   13974              : {
   13975      2955234 :   if (!op || SLP_TREE_DEF_TYPE (op) == vect_internal_def)
   13976              :     return true;
   13977      1068545 :   if (SLP_TREE_VECTYPE (op))
   13978        66689 :     return types_compatible_p (SLP_TREE_VECTYPE (op), vectype);
   13979              :   /* For external defs refuse to produce VECTOR_BOOLEAN_TYPE_P, those
   13980              :      should be handled by patters.  Allow vect_constant_def for now
   13981              :      as well as the trivial single-lane uniform vect_external_def case
   13982              :      both of which we code-generate reasonably.  */
   13983      1001856 :   if (VECTOR_BOOLEAN_TYPE_P (vectype)
   13984         1047 :       && SLP_TREE_DEF_TYPE (op) == vect_external_def
   13985      1002527 :       && SLP_TREE_LANES (op) > 1)
   13986              :     return false;
   13987      1001657 :   SLP_TREE_VECTYPE (op) = vectype;
   13988      1001657 :   return true;
   13989              : }
   13990              : 
   13991              : /* Function supportable_widening_operation
   13992              : 
   13993              :    Check whether an operation represented by the code CODE is a
   13994              :    widening operation that is supported by the target platform in
   13995              :    vector form (i.e., when operating on arguments of type VECTYPE_IN
   13996              :    producing a result of type VECTYPE_OUT).
   13997              : 
   13998              :    Widening operations we currently support are NOP (CONVERT), FLOAT,
   13999              :    FIX_TRUNC and WIDEN_MULT.  This function checks if these operations
   14000              :    are supported by the target platform either directly (via vector
   14001              :    tree-codes), or via target builtins.
   14002              : 
   14003              :    When EVENODD_OK then also lane-swizzling operations are considered.
   14004              : 
   14005              :    Output:
   14006              :    - CODE1 and CODE2 are codes of vector operations to be used when
   14007              :    vectorizing the operation, if available.
   14008              :    - MULTI_STEP_CVT determines the number of required intermediate steps in
   14009              :    case of multi-step conversion (like char->short->int - in that case
   14010              :    MULTI_STEP_CVT will be 1).
   14011              :    - INTERM_TYPES contains the intermediate type required to perform the
   14012              :    widening operation (short in the above example).  */
   14013              : 
   14014              : bool
   14015       446531 : supportable_widening_operation (code_helper code,
   14016              :                                 tree vectype_out, tree vectype_in,
   14017              :                                 bool evenodd_ok,
   14018              :                                 code_helper *code1,
   14019              :                                 code_helper *code2,
   14020              :                                 int *multi_step_cvt,
   14021              :                                 vec<tree> *interm_types)
   14022              : {
   14023       446531 :   machine_mode vec_mode;
   14024       446531 :   enum insn_code icode1, icode2;
   14025       446531 :   optab optab1 = unknown_optab, optab2 = unknown_optab;
   14026       446531 :   tree vectype = vectype_in;
   14027       446531 :   tree wide_vectype = vectype_out;
   14028       446531 :   tree_code c1 = MAX_TREE_CODES, c2 = MAX_TREE_CODES;
   14029       446531 :   int i;
   14030       446531 :   tree prev_type, intermediate_type;
   14031       446531 :   machine_mode intermediate_mode, prev_mode;
   14032       446531 :   optab optab3, optab4;
   14033              : 
   14034       446531 :   *multi_step_cvt = 0;
   14035              : 
   14036       446531 :   switch (code.safe_as_tree_code ())
   14037              :     {
   14038              :     case MAX_TREE_CODES:
   14039              :       /* Don't set c1 and c2 if code is not a tree_code.  */
   14040              :       break;
   14041              : 
   14042       172250 :     case WIDEN_MULT_EXPR:
   14043              :       /* The result of a vectorized widening operation usually requires
   14044              :          two vectors (because the widened results do not fit into one vector).
   14045              :          The generated vector results would normally be expected to be
   14046              :          generated in the same order as in the original scalar computation,
   14047              :          i.e. if 8 results are generated in each vector iteration, they are
   14048              :          to be organized as follows:
   14049              :                 vect1: [res1,res2,res3,res4],
   14050              :                 vect2: [res5,res6,res7,res8].
   14051              : 
   14052              :          However, in the special case that the result of the widening
   14053              :          operation is used in a reduction computation only, the order doesn't
   14054              :          matter (because when vectorizing a reduction we change the order of
   14055              :          the computation).  Some targets can take advantage of this and
   14056              :          generate more efficient code.  For example, targets like Altivec,
   14057              :          that support widen_mult using a sequence of {mult_even,mult_odd}
   14058              :          generate the following vectors:
   14059              :                 vect1: [res1,res3,res5,res7],
   14060              :                 vect2: [res2,res4,res6,res8].
   14061              : 
   14062              :          When vectorizing outer-loops, we execute the inner-loop sequentially
   14063              :          (each vectorized inner-loop iteration contributes to VF outer-loop
   14064              :          iterations in parallel).  We therefore don't allow to change the
   14065              :          order of the computation in the inner-loop during outer-loop
   14066              :          vectorization.  */
   14067              :       /* TODO: Another case in which order doesn't *really* matter is when we
   14068              :          widen and then contract again, e.g. (short)((int)x * y >> 8).
   14069              :          Normally, pack_trunc performs an even/odd permute, whereas the
   14070              :          repack from an even/odd expansion would be an interleave, which
   14071              :          would be significantly simpler for e.g. AVX2.  */
   14072              :       /* In any case, in order to avoid duplicating the code below, recurse
   14073              :          on VEC_WIDEN_MULT_EVEN_EXPR.  If it succeeds, all the return values
   14074              :          are properly set up for the caller.  If we fail, we'll continue with
   14075              :          a VEC_WIDEN_MULT_LO/HI_EXPR check.  */
   14076       172250 :       if (evenodd_ok
   14077       172250 :           && supportable_widening_operation (VEC_WIDEN_MULT_EVEN_EXPR,
   14078              :                                              vectype_out, vectype_in,
   14079              :                                              evenodd_ok, code1,
   14080              :                                              code2, multi_step_cvt,
   14081              :                                              interm_types))
   14082        93193 :         return true;
   14083              :       c1 = VEC_WIDEN_MULT_LO_EXPR;
   14084              :       c2 = VEC_WIDEN_MULT_HI_EXPR;
   14085              :       break;
   14086              : 
   14087              :     case DOT_PROD_EXPR:
   14088       353338 :       c1 = DOT_PROD_EXPR;
   14089       353338 :       c2 = DOT_PROD_EXPR;
   14090              :       break;
   14091              : 
   14092            0 :     case SAD_EXPR:
   14093            0 :       c1 = SAD_EXPR;
   14094            0 :       c2 = SAD_EXPR;
   14095            0 :       break;
   14096              : 
   14097       170220 :     case VEC_WIDEN_MULT_EVEN_EXPR:
   14098              :       /* Support the recursion induced just above.  */
   14099       170220 :       c1 = VEC_WIDEN_MULT_EVEN_EXPR;
   14100       170220 :       c2 = VEC_WIDEN_MULT_ODD_EXPR;
   14101       170220 :       break;
   14102              : 
   14103         9305 :     case WIDEN_LSHIFT_EXPR:
   14104         9305 :       c1 = VEC_WIDEN_LSHIFT_LO_EXPR;
   14105         9305 :       c2 = VEC_WIDEN_LSHIFT_HI_EXPR;
   14106         9305 :       break;
   14107              : 
   14108        34830 :     CASE_CONVERT:
   14109        34830 :       c1 = VEC_UNPACK_LO_EXPR;
   14110        34830 :       c2 = VEC_UNPACK_HI_EXPR;
   14111        34830 :       break;
   14112              : 
   14113         7207 :     case FLOAT_EXPR:
   14114         7207 :       c1 = VEC_UNPACK_FLOAT_LO_EXPR;
   14115         7207 :       c2 = VEC_UNPACK_FLOAT_HI_EXPR;
   14116         7207 :       break;
   14117              : 
   14118          110 :     case FIX_TRUNC_EXPR:
   14119          110 :       c1 = VEC_UNPACK_FIX_TRUNC_LO_EXPR;
   14120          110 :       c2 = VEC_UNPACK_FIX_TRUNC_HI_EXPR;
   14121          110 :       break;
   14122              : 
   14123            0 :     default:
   14124            0 :       gcc_unreachable ();
   14125              :     }
   14126              : 
   14127       353338 :   if (BYTES_BIG_ENDIAN && c1 != VEC_WIDEN_MULT_EVEN_EXPR)
   14128              :     std::swap (c1, c2);
   14129              : 
   14130       353338 :   if (code == FIX_TRUNC_EXPR)
   14131              :     {
   14132              :       /* The signedness is determined from output operand.  */
   14133          110 :       optab1 = optab_for_tree_code (c1, vectype_out, optab_default);
   14134          110 :       optab2 = optab_for_tree_code (c2, vectype_out, optab_default);
   14135              :     }
   14136       625036 :   else if (CONVERT_EXPR_CODE_P (code.safe_as_tree_code ())
   14137        34830 :            && VECTOR_BOOLEAN_TYPE_P (wide_vectype)
   14138         5777 :            && VECTOR_BOOLEAN_TYPE_P (vectype)
   14139         5777 :            && TYPE_MODE (wide_vectype) == TYPE_MODE (vectype)
   14140       300932 :            && SCALAR_INT_MODE_P (TYPE_MODE (vectype)))
   14141              :     {
   14142              :       /* If the input and result modes are the same, a different optab
   14143              :          is needed where we pass in the number of units in vectype.  */
   14144              :       optab1 = vec_unpacks_sbool_lo_optab;
   14145              :       optab2 = vec_unpacks_sbool_hi_optab;
   14146              :     }
   14147              : 
   14148       353338 :   vec_mode = TYPE_MODE (vectype);
   14149       353338 :   if (widening_fn_p (code))
   14150              :      {
   14151              :        /* If this is an internal fn then we must check whether the target
   14152              :           supports either a low-high split or an even-odd split.  */
   14153        52609 :       internal_fn ifn = as_internal_fn ((combined_fn) code);
   14154              : 
   14155        52609 :       internal_fn lo, hi, even, odd;
   14156        52609 :       lookup_hilo_internal_fn (ifn, &lo, &hi);
   14157        52609 :       if (BYTES_BIG_ENDIAN)
   14158              :         std::swap (lo, hi);
   14159        52609 :       *code1 = as_combined_fn (lo);
   14160        52609 :       *code2 = as_combined_fn (hi);
   14161        52609 :       optab1 = direct_internal_fn_optab (lo, {vectype, vectype});
   14162        52609 :       optab2 = direct_internal_fn_optab (hi, {vectype, vectype});
   14163              : 
   14164              :       /* If we don't support low-high, then check for even-odd.  */
   14165        52609 :       if (!optab1
   14166        52609 :           || (icode1 = optab_handler (optab1, vec_mode)) == CODE_FOR_nothing
   14167            0 :           || !optab2
   14168        52609 :           || (icode2 = optab_handler (optab2, vec_mode)) == CODE_FOR_nothing)
   14169              :         {
   14170        52609 :           lookup_evenodd_internal_fn (ifn, &even, &odd);
   14171        52609 :           *code1 = as_combined_fn (even);
   14172        52609 :           *code2 = as_combined_fn (odd);
   14173        52609 :           optab1 = direct_internal_fn_optab (even, {vectype, vectype});
   14174        52609 :           optab2 = direct_internal_fn_optab (odd, {vectype, vectype});
   14175              :         }
   14176              :     }
   14177       300729 :   else if (code.is_tree_code ())
   14178              :     {
   14179       300729 :       if (code == FIX_TRUNC_EXPR)
   14180              :         {
   14181              :           /* The signedness is determined from output operand.  */
   14182          110 :           optab1 = optab_for_tree_code (c1, vectype_out, optab_default);
   14183          110 :           optab2 = optab_for_tree_code (c2, vectype_out, optab_default);
   14184              :         }
   14185       300619 :       else if (CONVERT_EXPR_CODE_P ((tree_code) code.safe_as_tree_code ())
   14186        34830 :                && VECTOR_BOOLEAN_TYPE_P (wide_vectype)
   14187         5777 :                && VECTOR_BOOLEAN_TYPE_P (vectype)
   14188         5777 :                && TYPE_MODE (wide_vectype) == TYPE_MODE (vectype)
   14189       300932 :                && SCALAR_INT_MODE_P (TYPE_MODE (vectype)))
   14190              :         {
   14191              :           /* If the input and result modes are the same, a different optab
   14192              :              is needed where we pass in the number of units in vectype.  */
   14193              :           optab1 = vec_unpacks_sbool_lo_optab;
   14194              :           optab2 = vec_unpacks_sbool_hi_optab;
   14195              :         }
   14196              :       else
   14197              :         {
   14198       300306 :           optab1 = optab_for_tree_code (c1, vectype, optab_default);
   14199       300306 :           optab2 = optab_for_tree_code (c2, vectype, optab_default);
   14200              :         }
   14201       300729 :       *code1 = c1;
   14202       300729 :       *code2 = c2;
   14203              :     }
   14204              : 
   14205       353338 :   if (!optab1 || !optab2)
   14206              :     return false;
   14207              : 
   14208       353338 :   if ((icode1 = optab_handler (optab1, vec_mode)) == CODE_FOR_nothing
   14209       353338 :        || (icode2 = optab_handler (optab2, vec_mode)) == CODE_FOR_nothing)
   14210       209213 :     return false;
   14211              : 
   14212              : 
   14213       144125 :   if (insn_data[icode1].operand[0].mode == TYPE_MODE (wide_vectype)
   14214       144125 :       && insn_data[icode2].operand[0].mode == TYPE_MODE (wide_vectype))
   14215              :     {
   14216       133864 :       if (!VECTOR_BOOLEAN_TYPE_P (vectype))
   14217              :         return true;
   14218              :       /* For scalar masks we may have different boolean
   14219              :          vector types having the same QImode.  Thus we
   14220              :          add additional check for elements number.  */
   14221         2935 :       if (known_eq (TYPE_VECTOR_SUBPARTS (vectype),
   14222              :                     TYPE_VECTOR_SUBPARTS (wide_vectype) * 2))
   14223              :         return true;
   14224              :     }
   14225              : 
   14226              :   /* Check if it's a multi-step conversion that can be done using intermediate
   14227              :      types.  */
   14228              : 
   14229        10382 :   prev_type = vectype;
   14230        10382 :   prev_mode = vec_mode;
   14231              : 
   14232       219844 :   if (!CONVERT_EXPR_CODE_P (code.safe_as_tree_code ()))
   14233              :     return false;
   14234              : 
   14235              :   /* We assume here that there will not be more than MAX_INTERM_CVT_STEPS
   14236              :      intermediate steps in promotion sequence.  We try
   14237              :      MAX_INTERM_CVT_STEPS to get to NARROW_VECTYPE, and fail if we do
   14238              :      not.  */
   14239        10330 :   interm_types->create (MAX_INTERM_CVT_STEPS);
   14240        11604 :   for (i = 0; i < MAX_INTERM_CVT_STEPS; i++)
   14241              :     {
   14242        11604 :       intermediate_mode = insn_data[icode1].operand[0].mode;
   14243        11604 :       if (VECTOR_BOOLEAN_TYPE_P (prev_type))
   14244         3714 :         intermediate_type
   14245         3714 :           = vect_halve_mask_nunits (prev_type, intermediate_mode);
   14246         7890 :       else if (VECTOR_MODE_P (intermediate_mode))
   14247              :         {
   14248         7890 :           tree intermediate_element_type
   14249         7890 :             = lang_hooks.types.type_for_mode (GET_MODE_INNER (intermediate_mode),
   14250         7890 :                                               TYPE_UNSIGNED (prev_type));
   14251         7890 :           intermediate_type
   14252         7890 :             = build_vector_type_for_mode (intermediate_element_type,
   14253              :                                           intermediate_mode);
   14254         7890 :         }
   14255              :       else
   14256            0 :         intermediate_type
   14257            0 :           = lang_hooks.types.type_for_mode (intermediate_mode,
   14258            0 :                                             TYPE_UNSIGNED (prev_type));
   14259              : 
   14260        11604 :       if (VECTOR_BOOLEAN_TYPE_P (intermediate_type)
   14261         3714 :           && VECTOR_BOOLEAN_TYPE_P (wide_vectype)
   14262         3714 :           && intermediate_mode == TYPE_MODE (wide_vectype)
   14263        11761 :           && SCALAR_INT_MODE_P (intermediate_mode))
   14264              :         {
   14265              :           /* If the input and result modes are the same, a different optab
   14266              :              is needed where we pass in the number of units in vectype.  */
   14267              :           optab3 = vec_unpacks_sbool_lo_optab;
   14268              :           optab4 = vec_unpacks_sbool_hi_optab;
   14269              :         }
   14270              :       else
   14271              :         {
   14272        11447 :           optab3 = optab_for_tree_code (c1, intermediate_type, optab_default);
   14273        11447 :           optab4 = optab_for_tree_code (c2, intermediate_type, optab_default);
   14274              :         }
   14275              : 
   14276        11604 :       if (!optab3 || !optab4
   14277        11604 :           || (icode1 = optab_handler (optab1, prev_mode)) == CODE_FOR_nothing
   14278        11588 :           || insn_data[icode1].operand[0].mode != intermediate_mode
   14279        11588 :           || (icode2 = optab_handler (optab2, prev_mode)) == CODE_FOR_nothing
   14280        11588 :           || insn_data[icode2].operand[0].mode != intermediate_mode
   14281        11588 :           || ((icode1 = optab_handler (optab3, intermediate_mode))
   14282              :               == CODE_FOR_nothing)
   14283        22959 :           || ((icode2 = optab_handler (optab4, intermediate_mode))
   14284              :               == CODE_FOR_nothing))
   14285              :         break;
   14286              : 
   14287        11355 :       interm_types->quick_push (intermediate_type);
   14288        11355 :       (*multi_step_cvt)++;
   14289              : 
   14290        11355 :       if (insn_data[icode1].operand[0].mode == TYPE_MODE (wide_vectype)
   14291        11355 :           && insn_data[icode2].operand[0].mode == TYPE_MODE (wide_vectype))
   14292              :         {
   14293        10117 :           if (!VECTOR_BOOLEAN_TYPE_P (vectype))
   14294              :             return true;
   14295         2780 :           if (known_eq (TYPE_VECTOR_SUBPARTS (intermediate_type),
   14296              :                         TYPE_VECTOR_SUBPARTS (wide_vectype) * 2))
   14297              :             return true;
   14298              :         }
   14299              : 
   14300         1274 :       prev_type = intermediate_type;
   14301         1274 :       prev_mode = intermediate_mode;
   14302              :     }
   14303              : 
   14304          249 :   interm_types->release ();
   14305          249 :   return false;
   14306              : }
   14307              : 
   14308              : 
   14309              : /* Function supportable_narrowing_operation
   14310              : 
   14311              :    Check whether an operation represented by the code CODE is a
   14312              :    narrowing operation that is supported by the target platform in
   14313              :    vector form (i.e., when operating on arguments of type VECTYPE_IN
   14314              :    and producing a result of type VECTYPE_OUT).
   14315              : 
   14316              :    Narrowing operations we currently support are NOP (CONVERT), FIX_TRUNC
   14317              :    and FLOAT.  This function checks if these operations are supported by
   14318              :    the target platform directly via vector tree-codes.
   14319              : 
   14320              :    Output:
   14321              :    - CODE1 is the code of a vector operation to be used when
   14322              :    vectorizing the operation, if available.
   14323              :    - MULTI_STEP_CVT determines the number of required intermediate steps in
   14324              :    case of multi-step conversion (like int->short->char - in that case
   14325              :    MULTI_STEP_CVT will be 1).
   14326              :    - INTERM_TYPES contains the intermediate type required to perform the
   14327              :    narrowing operation (short in the above example).   */
   14328              : 
   14329              : bool
   14330        34827 : supportable_narrowing_operation (code_helper code,
   14331              :                                  tree vectype_out, tree vectype_in,
   14332              :                                  code_helper *code1, int *multi_step_cvt,
   14333              :                                  vec<tree> *interm_types)
   14334              : {
   14335        34827 :   machine_mode vec_mode;
   14336        34827 :   enum insn_code icode1;
   14337        34827 :   optab optab1, interm_optab;
   14338        34827 :   tree vectype = vectype_in;
   14339        34827 :   tree narrow_vectype = vectype_out;
   14340        34827 :   enum tree_code c1;
   14341        34827 :   tree intermediate_type, prev_type;
   14342        34827 :   machine_mode intermediate_mode, prev_mode;
   14343        34827 :   int i;
   14344        34827 :   unsigned HOST_WIDE_INT n_elts;
   14345        34827 :   bool uns;
   14346              : 
   14347        34827 :   if (!code.is_tree_code ())
   14348              :     return false;
   14349              : 
   14350        34827 :   *multi_step_cvt = 0;
   14351        34827 :   switch ((tree_code) code)
   14352              :     {
   14353        34134 :     CASE_CONVERT:
   14354        34134 :       c1 = VEC_PACK_TRUNC_EXPR;
   14355        34134 :       if (VECTOR_BOOLEAN_TYPE_P (narrow_vectype)
   14356         9544 :           && VECTOR_BOOLEAN_TYPE_P (vectype)
   14357         9544 :           && SCALAR_INT_MODE_P (TYPE_MODE (vectype))
   14358         4546 :           && TYPE_VECTOR_SUBPARTS (vectype).is_constant (&n_elts)
   14359        38680 :           && n_elts < BITS_PER_UNIT)
   14360              :         optab1 = vec_pack_sbool_trunc_optab;
   14361              :       else
   14362        32331 :         optab1 = optab_for_tree_code (c1, vectype, optab_default);
   14363              :       break;
   14364              : 
   14365          483 :     case FIX_TRUNC_EXPR:
   14366          483 :       c1 = VEC_PACK_FIX_TRUNC_EXPR;
   14367              :       /* The signedness is determined from output operand.  */
   14368          483 :       optab1 = optab_for_tree_code (c1, vectype_out, optab_default);
   14369          483 :       break;
   14370              : 
   14371          210 :     case FLOAT_EXPR:
   14372          210 :       c1 = VEC_PACK_FLOAT_EXPR;
   14373          210 :       optab1 = optab_for_tree_code (c1, vectype, optab_default);
   14374          210 :       break;
   14375              : 
   14376            0 :     default:
   14377            0 :       gcc_unreachable ();
   14378              :     }
   14379              : 
   14380        34827 :   if (!optab1)
   14381              :     return false;
   14382              : 
   14383        34827 :   vec_mode = TYPE_MODE (vectype);
   14384        34827 :   if ((icode1 = optab_handler (optab1, vec_mode)) == CODE_FOR_nothing)
   14385              :     return false;
   14386              : 
   14387        30797 :   *code1 = c1;
   14388              : 
   14389        30797 :   if (insn_data[icode1].operand[0].mode == TYPE_MODE (narrow_vectype))
   14390              :     {
   14391        18719 :       if (!VECTOR_BOOLEAN_TYPE_P (vectype))
   14392              :         return true;
   14393              :       /* For scalar masks we may have different boolean
   14394              :          vector types having the same QImode.  Thus we
   14395              :          add additional check for elements number.  */
   14396         4595 :       if (known_eq (TYPE_VECTOR_SUBPARTS (vectype) * 2,
   14397              :                     TYPE_VECTOR_SUBPARTS (narrow_vectype)))
   14398              :         return true;
   14399              :     }
   14400              : 
   14401        12079 :   if (code == FLOAT_EXPR)
   14402              :     return false;
   14403              : 
   14404              :   /* Check if it's a multi-step conversion that can be done using intermediate
   14405              :      types.  */
   14406        12079 :   prev_mode = vec_mode;
   14407        12079 :   prev_type = vectype;
   14408        12079 :   if (code == FIX_TRUNC_EXPR)
   14409           87 :     uns = TYPE_UNSIGNED (vectype_out);
   14410              :   else
   14411        11992 :     uns = TYPE_UNSIGNED (vectype);
   14412              : 
   14413              :   /* For multi-step FIX_TRUNC_EXPR prefer signed floating to integer
   14414              :      conversion over unsigned, as unsigned FIX_TRUNC_EXPR is often more
   14415              :      costly than signed.  */
   14416        12079 :   if (code == FIX_TRUNC_EXPR && uns)
   14417              :     {
   14418           28 :       enum insn_code icode2;
   14419              : 
   14420           28 :       intermediate_type
   14421           28 :         = lang_hooks.types.type_for_mode (TYPE_MODE (vectype_out), 0);
   14422           28 :       interm_optab
   14423           28 :         = optab_for_tree_code (c1, intermediate_type, optab_default);
   14424           28 :       if (interm_optab != unknown_optab
   14425           28 :           && (icode2 = optab_handler (optab1, vec_mode)) != CODE_FOR_nothing
   14426           28 :           && insn_data[icode1].operand[0].mode
   14427           28 :              == insn_data[icode2].operand[0].mode)
   14428              :         {
   14429              :           uns = false;
   14430              :           optab1 = interm_optab;
   14431              :           icode1 = icode2;
   14432              :         }
   14433              :     }
   14434              : 
   14435              :   /* We assume here that there will not be more than MAX_INTERM_CVT_STEPS
   14436              :      intermediate steps in promotion sequence.  We try
   14437              :      MAX_INTERM_CVT_STEPS to get to NARROW_VECTYPE, and fail if we do not.  */
   14438        12079 :   interm_types->create (MAX_INTERM_CVT_STEPS);
   14439        26066 :   for (i = 0; i < MAX_INTERM_CVT_STEPS; i++)
   14440              :     {
   14441        13987 :       intermediate_mode = insn_data[icode1].operand[0].mode;
   14442        13987 :       if (VECTOR_BOOLEAN_TYPE_P (prev_type))
   14443         5915 :         intermediate_type
   14444         5915 :           = vect_double_mask_nunits (prev_type, intermediate_mode);
   14445              :       else
   14446         8072 :         intermediate_type
   14447         8072 :           = lang_hooks.types.type_for_mode (intermediate_mode, uns);
   14448        13987 :       if (VECTOR_BOOLEAN_TYPE_P (intermediate_type)
   14449         5915 :           && VECTOR_BOOLEAN_TYPE_P (prev_type)
   14450         5915 :           && SCALAR_INT_MODE_P (prev_mode)
   14451         2681 :           && TYPE_VECTOR_SUBPARTS (intermediate_type).is_constant (&n_elts)
   14452        16668 :           && n_elts < BITS_PER_UNIT)
   14453              :         interm_optab = vec_pack_sbool_trunc_optab;
   14454              :       else
   14455        13870 :         interm_optab
   14456        13870 :           = optab_for_tree_code (VEC_PACK_TRUNC_EXPR, intermediate_type,
   14457              :                                  optab_default);
   14458          117 :       if (!interm_optab
   14459        13987 :           || ((icode1 = optab_handler (optab1, prev_mode)) == CODE_FOR_nothing)
   14460        13987 :           || insn_data[icode1].operand[0].mode != intermediate_mode
   14461        27857 :           || ((icode1 = optab_handler (interm_optab, intermediate_mode))
   14462              :               == CODE_FOR_nothing))
   14463              :         break;
   14464              : 
   14465        13094 :       interm_types->quick_push (intermediate_type);
   14466        13094 :       (*multi_step_cvt)++;
   14467              : 
   14468        13094 :       if (insn_data[icode1].operand[0].mode == TYPE_MODE (narrow_vectype))
   14469              :         {
   14470        11186 :           if (!VECTOR_BOOLEAN_TYPE_P (vectype))
   14471              :             return true;
   14472         3984 :           if (known_eq (TYPE_VECTOR_SUBPARTS (intermediate_type) * 2,
   14473              :                         TYPE_VECTOR_SUBPARTS (narrow_vectype)))
   14474              :             return true;
   14475              :         }
   14476              : 
   14477         1908 :       prev_mode = intermediate_mode;
   14478         1908 :       prev_type = intermediate_type;
   14479         1908 :       optab1 = interm_optab;
   14480              :     }
   14481              : 
   14482          893 :   interm_types->release ();
   14483          893 :   return false;
   14484              : }
   14485              : 
   14486              : /* Function supportable_indirect_convert_operation
   14487              : 
   14488              :    Check whether an operation represented by the code CODE is single or multi
   14489              :    operations that are supported by the target platform in
   14490              :    vector form (i.e., when operating on arguments of type VECTYPE_IN
   14491              :    producing a result of type VECTYPE_OUT).
   14492              : 
   14493              :    Convert operations we currently support directly are FIX_TRUNC and FLOAT.
   14494              :    This function checks if these operations are supported
   14495              :    by the target platform directly (via vector tree-codes).
   14496              : 
   14497              :    Output:
   14498              :    - converts contains some pairs to perform the convert operation,
   14499              :    the pair's first is the intermediate type, and its second is the code of
   14500              :    a vector operation to be used when converting the operation from the
   14501              :    previous type to the intermediate type. */
   14502              : bool
   14503        71418 : supportable_indirect_convert_operation (code_helper code,
   14504              :                                         tree vectype_out,
   14505              :                                         tree vectype_in,
   14506              :                                         vec<std::pair<tree, tree_code> > &converts,
   14507              :                                         tree op0, slp_tree slp_op0)
   14508              : {
   14509        71418 :   bool found_mode = false;
   14510        71418 :   scalar_mode lhs_mode = GET_MODE_INNER (TYPE_MODE (vectype_out));
   14511        71418 :   scalar_mode rhs_mode = GET_MODE_INNER (TYPE_MODE (vectype_in));
   14512        71418 :   tree_code tc1, tc2, code1, code2;
   14513              : 
   14514        71418 :   tree cvt_type = NULL_TREE;
   14515        71418 :   poly_uint64 nelts = TYPE_VECTOR_SUBPARTS (vectype_in);
   14516              : 
   14517        71418 :   if (supportable_convert_operation ((tree_code) code,
   14518              :                                      vectype_out,
   14519              :                                      vectype_in,
   14520              :                                      &tc1))
   14521              :     {
   14522        16312 :       converts.safe_push (std::make_pair (vectype_out, tc1));
   14523        16312 :       return true;
   14524              :     }
   14525              : 
   14526              :   /* For conversions between float and integer types try whether
   14527              :      we can use intermediate signed integer types to support the
   14528              :      conversion.  */
   14529       110212 :   if (GET_MODE_SIZE (lhs_mode) != GET_MODE_SIZE (rhs_mode)
   14530        55106 :       && (code == FLOAT_EXPR
   14531         3134 :           || (code == FIX_TRUNC_EXPR && !flag_trapping_math)))
   14532              :     {
   14533          456 :       bool demotion = GET_MODE_SIZE (rhs_mode) > GET_MODE_SIZE (lhs_mode);
   14534          228 :       bool float_expr_p = code == FLOAT_EXPR;
   14535          228 :       unsigned short target_size;
   14536          228 :       scalar_mode intermediate_mode;
   14537          228 :       if (demotion)
   14538              :         {
   14539           84 :           intermediate_mode = lhs_mode;
   14540           84 :           target_size = GET_MODE_SIZE (rhs_mode);
   14541              :         }
   14542              :       else
   14543              :         {
   14544          144 :           target_size = GET_MODE_SIZE (lhs_mode);
   14545          144 :           if (!int_mode_for_size
   14546          144 :               (GET_MODE_BITSIZE (rhs_mode), 0).exists (&intermediate_mode))
   14547          132 :             return false;
   14548              :         }
   14549          228 :       code1 = float_expr_p ? (tree_code) code : NOP_EXPR;
   14550              :       code2 = float_expr_p ? NOP_EXPR : (tree_code) code;
   14551          228 :       opt_scalar_mode mode_iter;
   14552          382 :       FOR_EACH_2XWIDER_MODE (mode_iter, intermediate_mode)
   14553              :         {
   14554          382 :           intermediate_mode = mode_iter.require ();
   14555              : 
   14556          764 :           if (GET_MODE_SIZE (intermediate_mode) > target_size)
   14557              :             break;
   14558              : 
   14559          324 :           scalar_mode cvt_mode;
   14560          324 :           if (!int_mode_for_size
   14561          324 :               (GET_MODE_BITSIZE (intermediate_mode), 0).exists (&cvt_mode))
   14562              :             break;
   14563              : 
   14564          294 :           cvt_type = build_nonstandard_integer_type
   14565          294 :             (GET_MODE_BITSIZE (cvt_mode), 0);
   14566              : 
   14567              :           /* Check if the intermediate type can hold OP0's range.
   14568              :              When converting from float to integer this is not necessary
   14569              :              because values that do not fit the (smaller) target type are
   14570              :              unspecified anyway.  */
   14571          294 :           if (demotion && float_expr_p)
   14572              :             {
   14573            8 :               wide_int op_min_value, op_max_value;
   14574              :               /* For vector form, it looks like op0 doesn't have RANGE_INFO.
   14575              :                  In the future, if it is supported, changes may need to be made
   14576              :                  to this part, such as checking the RANGE of each element
   14577              :                  in the vector.  */
   14578            8 :               if (slp_op0)
   14579              :                 {
   14580            4 :                   tree def;
   14581              :                   /* ???  Merge ranges in case of more than one lane.  */
   14582            4 :                   if (SLP_TREE_LANES (slp_op0) != 1
   14583            0 :                       || !(def = vect_get_slp_scalar_def (slp_op0, 0))
   14584            4 :                       || !vect_get_range_info (def,
   14585              :                                                &op_min_value, &op_max_value))
   14586              :                     break;
   14587              :                 }
   14588            4 :               else if (!op0
   14589            0 :                        || TREE_CODE (op0) != SSA_NAME
   14590            0 :                        || !SSA_NAME_RANGE_INFO (op0)
   14591            4 :                        || !vect_get_range_info (op0, &op_min_value,
   14592              :                                                 &op_max_value))
   14593              :                 break;
   14594              : 
   14595            0 :               if (cvt_type == NULL_TREE
   14596            0 :                   || (wi::min_precision (op_max_value, SIGNED)
   14597            0 :                       > TYPE_PRECISION (cvt_type))
   14598            0 :                   || (wi::min_precision (op_min_value, SIGNED)
   14599            0 :                       > TYPE_PRECISION (cvt_type)))
   14600            0 :                 continue;
   14601            8 :             }
   14602              : 
   14603          286 :           cvt_type = get_related_vectype_for_scalar_type (TYPE_MODE (vectype_in),
   14604              :                                                           cvt_type,
   14605              :                                                           nelts);
   14606              :           /* This should only happened for SLP as long as loop vectorizer
   14607              :              only supports same-sized vector.  */
   14608          440 :           if (cvt_type == NULL_TREE
   14609          418 :               || maybe_ne (TYPE_VECTOR_SUBPARTS (cvt_type), nelts)
   14610          286 :               || !supportable_convert_operation ((tree_code) code1,
   14611              :                                                  vectype_out,
   14612              :                                                  cvt_type, &tc1)
   14613          486 :               || !supportable_convert_operation ((tree_code) code2,
   14614              :                                                  cvt_type,
   14615              :                                                  vectype_in, &tc2))
   14616          154 :             continue;
   14617              : 
   14618              :           found_mode = true;
   14619              :           break;
   14620              :         }
   14621              : 
   14622          228 :       if (found_mode)
   14623              :         {
   14624          132 :           converts.safe_push (std::make_pair (cvt_type, tc2));
   14625          132 :           if (TYPE_MODE (cvt_type) != TYPE_MODE (vectype_out))
   14626          132 :             converts.safe_push (std::make_pair (vectype_out, tc1));
   14627          132 :           return true;
   14628              :         }
   14629              :     }
   14630              :   return false;
   14631              : }
   14632              : 
   14633              : /* Generate and return a vector mask of MASK_TYPE such that
   14634              :    mask[I] is true iff J + START_INDEX < END_INDEX for all J <= I.
   14635              :    Add the statements to SEQ.  */
   14636              : 
   14637              : tree
   14638            0 : vect_gen_while (gimple_seq *seq, tree mask_type, tree start_index,
   14639              :                 tree end_index, const char *name)
   14640              : {
   14641            0 :   tree cmp_type = TREE_TYPE (start_index);
   14642            0 :   gcc_checking_assert (direct_internal_fn_supported_p (IFN_WHILE_ULT,
   14643              :                                                        cmp_type, mask_type,
   14644              :                                                        OPTIMIZE_FOR_SPEED));
   14645            0 :   gcall *call = gimple_build_call_internal (IFN_WHILE_ULT, 3,
   14646              :                                             start_index, end_index,
   14647              :                                             build_zero_cst (mask_type));
   14648            0 :   tree tmp;
   14649            0 :   if (name)
   14650            0 :     tmp = make_temp_ssa_name (mask_type, NULL, name);
   14651              :   else
   14652            0 :     tmp = make_ssa_name (mask_type);
   14653            0 :   gimple_call_set_lhs (call, tmp);
   14654            0 :   gimple_seq_add_stmt (seq, call);
   14655            0 :   return tmp;
   14656              : }
   14657              : 
   14658              : /* Generate a vector mask of type MASK_TYPE for which index I is false iff
   14659              :    J + START_INDEX < END_INDEX for all J <= I.  Add the statements to SEQ.  */
   14660              : 
   14661              : tree
   14662            0 : vect_gen_while_not (gimple_seq *seq, tree mask_type, tree start_index,
   14663              :                     tree end_index)
   14664              : {
   14665            0 :   tree tmp = vect_gen_while (seq, mask_type, start_index, end_index);
   14666            0 :   return gimple_build (seq, BIT_NOT_EXPR, mask_type, tmp);
   14667              : }
   14668              : 
   14669              : /* Try to compute the vector types required to vectorize STMT_INFO,
   14670              :    returning true on success and false if vectorization isn't possible.
   14671              :    If GROUP_SIZE is nonzero and we're performing BB vectorization,
   14672              :    take sure that the number of elements in the vectors is no bigger
   14673              :    than GROUP_SIZE.
   14674              : 
   14675              :    On success:
   14676              : 
   14677              :    - Set *STMT_VECTYPE_OUT to:
   14678              :      - NULL_TREE if the statement doesn't need to be vectorized;
   14679              :      - the equivalent of STMT_VINFO_VECTYPE otherwise.
   14680              : 
   14681              :    - Set *NUNITS_VECTYPE_OUT to the vector type that contains the maximum
   14682              :      number of units needed to vectorize STMT_INFO, or NULL_TREE if the
   14683              :      statement does not help to determine the overall number of units.  */
   14684              : 
   14685              : opt_result
   14686      5253029 : vect_get_vector_types_for_stmt (vec_info *vinfo, stmt_vec_info stmt_info,
   14687              :                                 tree *stmt_vectype_out,
   14688              :                                 tree *nunits_vectype_out,
   14689              :                                 unsigned int group_size)
   14690              : {
   14691      5253029 :   gimple *stmt = stmt_info->stmt;
   14692              : 
   14693              :   /* For BB vectorization, we should always have a group size once we've
   14694              :      constructed the SLP tree; the only valid uses of zero GROUP_SIZEs
   14695              :      are tentative requests during things like early data reference
   14696              :      analysis and pattern recognition.  */
   14697      5253029 :   if (is_a <bb_vec_info> (vinfo))
   14698      4429478 :     gcc_assert (vinfo->slp_instances.is_empty () || group_size != 0);
   14699              :   else
   14700              :     group_size = 0;
   14701              : 
   14702      5253029 :   *stmt_vectype_out = NULL_TREE;
   14703      5253029 :   *nunits_vectype_out = NULL_TREE;
   14704              : 
   14705      5253029 :   if (gimple_get_lhs (stmt) == NULL_TREE
   14706              :       /* Allow vector conditionals through here.  */
   14707         1543 :       && !is_a <gcond *> (stmt)
   14708              :       /* MASK_STORE and friends have no lhs, but are ok.  */
   14709      5256095 :       && !(is_gimple_call (stmt)
   14710         1543 :            && gimple_call_internal_p (stmt)
   14711         1523 :            && internal_store_fn_p (gimple_call_internal_fn (stmt))))
   14712              :     {
   14713           20 :       if (is_a <gcall *> (stmt))
   14714              :         {
   14715              :           /* Ignore calls with no lhs.  These must be calls to
   14716              :              #pragma omp simd functions, and what vectorization factor
   14717              :              it really needs can't be determined until
   14718              :              vectorizable_simd_clone_call.  */
   14719           20 :           if (dump_enabled_p ())
   14720           18 :             dump_printf_loc (MSG_NOTE, vect_location,
   14721              :                              "defer to SIMD clone analysis.\n");
   14722           20 :           return opt_result::success ();
   14723              :         }
   14724              : 
   14725            0 :       return opt_result::failure_at (stmt,
   14726              :                                      "not vectorized: irregular stmt: %G", stmt);
   14727              :     }
   14728              : 
   14729      5253009 :   tree vectype;
   14730      5253009 :   tree scalar_type = NULL_TREE;
   14731      5253009 :   if (group_size == 0 && STMT_VINFO_VECTYPE (stmt_info))
   14732              :     {
   14733      1349591 :       vectype = STMT_VINFO_VECTYPE (stmt_info);
   14734      1349591 :       if (dump_enabled_p ())
   14735        76898 :         dump_printf_loc (MSG_NOTE, vect_location,
   14736              :                          "precomputed vectype: %T\n", vectype);
   14737              :     }
   14738      3903418 :   else if (vect_use_mask_type_p (stmt_info))
   14739              :     {
   14740       176180 :       unsigned int precision = stmt_info->mask_precision;
   14741       176180 :       scalar_type = build_nonstandard_integer_type (precision, 1);
   14742       176180 :       vectype = get_mask_type_for_scalar_type (vinfo, scalar_type, group_size);
   14743       176180 :       if (!vectype)
   14744            0 :         return opt_result::failure_at (stmt, "not vectorized: unsupported"
   14745              :                                        " data-type %T\n", scalar_type);
   14746       176180 :       if (dump_enabled_p ())
   14747         4504 :         dump_printf_loc (MSG_NOTE, vect_location, "vectype: %T\n", vectype);
   14748              :     }
   14749              :   else
   14750              :     {
   14751              :       /* If we got here with a gcond it means that the target had no available vector
   14752              :          mode for the scalar type.  We can't vectorize so abort.  */
   14753      3727238 :       if (is_a <gcond *> (stmt))
   14754            0 :         return opt_result::failure_at (stmt,
   14755              :                                        "not vectorized:"
   14756              :                                        " unsupported data-type for gcond %T\n",
   14757              :                                        scalar_type);
   14758              : 
   14759      3727238 :       if (data_reference *dr = STMT_VINFO_DATA_REF (stmt_info))
   14760      1445074 :         scalar_type = TREE_TYPE (DR_REF (dr));
   14761              :       else
   14762      2282164 :         scalar_type = TREE_TYPE (gimple_get_lhs (stmt));
   14763              : 
   14764      3727238 :       if (dump_enabled_p ())
   14765              :         {
   14766        60872 :           if (group_size)
   14767         7373 :             dump_printf_loc (MSG_NOTE, vect_location,
   14768              :                              "get vectype for scalar type (group size %d):"
   14769              :                              " %T\n", group_size, scalar_type);
   14770              :           else
   14771        53499 :             dump_printf_loc (MSG_NOTE, vect_location,
   14772              :                              "get vectype for scalar type: %T\n", scalar_type);
   14773              :         }
   14774      3727238 :       vectype = get_vectype_for_scalar_type (vinfo, scalar_type, group_size);
   14775      3727238 :       if (!vectype)
   14776       194857 :         return opt_result::failure_at (stmt,
   14777              :                                        "not vectorized:"
   14778              :                                        " unsupported data-type %T\n",
   14779              :                                        scalar_type);
   14780              : 
   14781      3532381 :       if (dump_enabled_p ())
   14782        60679 :         dump_printf_loc (MSG_NOTE, vect_location, "vectype: %T\n", vectype);
   14783              :     }
   14784              : 
   14785      3785459 :   if (scalar_type && VECTOR_MODE_P (TYPE_MODE (scalar_type)))
   14786            0 :     return opt_result::failure_at (stmt,
   14787              :                                    "not vectorized: vector stmt in loop:%G",
   14788              :                                    stmt);
   14789              : 
   14790      5058152 :   *stmt_vectype_out = vectype;
   14791              : 
   14792              :   /* Don't try to compute scalar types if the stmt produces a boolean
   14793              :      vector; use the existing vector type instead.  */
   14794      5058152 :   tree nunits_vectype = vectype;
   14795      5058152 :   if (!VECTOR_BOOLEAN_TYPE_P (vectype))
   14796              :     {
   14797              :       /* The number of units is set according to the smallest scalar
   14798              :          type (or the largest vector size, but we only support one
   14799              :          vector size per vectorization).  */
   14800      4576843 :       scalar_type = vect_get_smallest_scalar_type (stmt_info,
   14801      4576843 :                                                    TREE_TYPE (vectype));
   14802      4576843 :       if (!types_compatible_p (scalar_type, TREE_TYPE (vectype)))
   14803              :         {
   14804       970491 :           if (dump_enabled_p ())
   14805         9541 :             dump_printf_loc (MSG_NOTE, vect_location,
   14806              :                              "get vectype for smallest scalar type: %T\n",
   14807              :                              scalar_type);
   14808       970491 :           nunits_vectype = get_vectype_for_scalar_type (vinfo, scalar_type,
   14809              :                                                         group_size);
   14810       970491 :           if (!nunits_vectype)
   14811           10 :             return opt_result::failure_at
   14812           10 :               (stmt, "not vectorized: unsupported data-type %T\n",
   14813              :                scalar_type);
   14814       970481 :           if (dump_enabled_p ())
   14815         9541 :             dump_printf_loc (MSG_NOTE, vect_location, "nunits vectype: %T\n",
   14816              :                              nunits_vectype);
   14817              :         }
   14818              :     }
   14819              : 
   14820      5058142 :   if (!multiple_p (TYPE_VECTOR_SUBPARTS (nunits_vectype),
   14821      5058142 :                    TYPE_VECTOR_SUBPARTS (*stmt_vectype_out)))
   14822            0 :     return opt_result::failure_at (stmt,
   14823              :                                    "Not vectorized: Incompatible number "
   14824              :                                    "of vector subparts between %T and %T\n",
   14825              :                                    nunits_vectype, *stmt_vectype_out);
   14826              : 
   14827      5058142 :   if (dump_enabled_p ())
   14828              :     {
   14829       142081 :       dump_printf_loc (MSG_NOTE, vect_location, "nunits = ");
   14830       142081 :       dump_dec (MSG_NOTE, TYPE_VECTOR_SUBPARTS (nunits_vectype));
   14831       142081 :       dump_printf (MSG_NOTE, "\n");
   14832              :     }
   14833              : 
   14834      5058142 :   *nunits_vectype_out = nunits_vectype;
   14835      5058142 :   return opt_result::success ();
   14836              : }
   14837              : 
   14838              : /* Generate and return statement sequence that sets vector length LEN that is:
   14839              : 
   14840              :    min_of_start_and_end = min (START_INDEX, END_INDEX);
   14841              :    left_len = END_INDEX - min_of_start_and_end;
   14842              :    rhs = min (left_len, LEN_LIMIT);
   14843              :    LEN = rhs;
   14844              : 
   14845              :    Note: the cost of the code generated by this function is modeled
   14846              :    by vect_estimate_min_profitable_iters, so changes here may need
   14847              :    corresponding changes there.  */
   14848              : 
   14849              : gimple_seq
   14850            0 : vect_gen_len (tree len, tree start_index, tree end_index, tree len_limit)
   14851              : {
   14852            0 :   gimple_seq stmts = NULL;
   14853            0 :   tree len_type = TREE_TYPE (len);
   14854            0 :   gcc_assert (TREE_TYPE (start_index) == len_type);
   14855              : 
   14856            0 :   tree min = gimple_build (&stmts, MIN_EXPR, len_type, start_index, end_index);
   14857            0 :   tree left_len = gimple_build (&stmts, MINUS_EXPR, len_type, end_index, min);
   14858            0 :   tree rhs = gimple_build (&stmts, MIN_EXPR, len_type, left_len, len_limit);
   14859            0 :   gimple* stmt = gimple_build_assign (len, rhs);
   14860            0 :   gimple_seq_add_stmt (&stmts, stmt);
   14861              : 
   14862            0 :   return stmts;
   14863              : }
   14864              : 
        

Generated by: LCOV version 2.4-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.