LCOV - code coverage report
Current view: top level - gcc - tree-vect-stmts.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 82.1 % 7114 5839
Test Date: 2026-12-05 16:10:02 Functions: 89.8 % 108 97
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              : #include "hierarchical_discriminator.h"
      62              : 
      63              : /* For lang_hooks.types.type_for_mode.  */
      64              : #include "langhooks.h"
      65              : 
      66              : static tree vector_vector_composition_type (tree, poly_uint64, tree *,
      67              :                                             bool = false);
      68              : 
      69              : /* Return TRUE iff the given statement is in an inner loop relative to
      70              :    the loop being vectorized.  */
      71              : bool
      72      6677665 : stmt_in_inner_loop_p (vec_info *vinfo, class _stmt_vec_info *stmt_info)
      73              : {
      74      6677665 :   gimple *stmt = STMT_VINFO_STMT (stmt_info);
      75      6677665 :   basic_block bb = gimple_bb (stmt);
      76      6677665 :   loop_vec_info loop_vinfo = dyn_cast <loop_vec_info> (vinfo);
      77      3187572 :   class loop* loop;
      78              : 
      79      3187572 :   if (!loop_vinfo)
      80              :     return false;
      81              : 
      82      3187572 :   loop = LOOP_VINFO_LOOP (loop_vinfo);
      83              : 
      84      3187572 :   return (bb->loop_father == loop->inner);
      85              : }
      86              : 
      87              : /* Record the cost of a statement, either by directly informing the
      88              :    target model or by saving it in a vector for later processing.
      89              :    Return a preliminary estimate of the statement's cost.  */
      90              : 
      91              : unsigned
      92      9344175 : record_stmt_cost (stmt_vector_for_cost *body_cost_vec, int count,
      93              :                   enum vect_cost_for_stmt kind,
      94              :                   stmt_vec_info stmt_info, slp_tree node,
      95              :                   tree vectype, int misalign,
      96              :                   enum vect_cost_model_location where)
      97              : {
      98      9344175 :   if ((kind == vector_load || kind == unaligned_load)
      99      1714536 :       && (stmt_info && STMT_VINFO_GATHER_SCATTER_P (stmt_info)))
     100              :     kind = vector_gather_load;
     101      9344175 :   if ((kind == vector_store || kind == unaligned_store)
     102      1062624 :       && (stmt_info && STMT_VINFO_GATHER_SCATTER_P (stmt_info)))
     103      9344175 :     kind = vector_scatter_store;
     104              : 
     105      9344175 :   stmt_info_for_cost si
     106      9344175 :     = { count, kind, where, stmt_info, node, vectype, misalign };
     107      9344175 :   body_cost_vec->safe_push (si);
     108              : 
     109      9344175 :   return (unsigned)
     110      9344175 :       (builtin_vectorization_cost (kind, vectype, misalign) * count);
     111              : }
     112              : 
     113              : unsigned
     114      4328438 : record_stmt_cost (stmt_vector_for_cost *body_cost_vec, int count,
     115              :                   enum vect_cost_for_stmt kind, stmt_vec_info stmt_info,
     116              :                   tree vectype, int misalign,
     117              :                   enum vect_cost_model_location where)
     118              : {
     119      4328438 :   return record_stmt_cost (body_cost_vec, count, kind, stmt_info, NULL,
     120      4328438 :                            vectype, misalign, where);
     121              : }
     122              : 
     123              : unsigned
     124      1812299 : record_stmt_cost (stmt_vector_for_cost *body_cost_vec, int count,
     125              :                   enum vect_cost_for_stmt kind, slp_tree node,
     126              :                   tree vectype, int misalign,
     127              :                   enum vect_cost_model_location where)
     128              : {
     129      1812299 :   return record_stmt_cost (body_cost_vec, count, kind,
     130              :                            SLP_TREE_REPRESENTATIVE (node), node,
     131      1812299 :                            vectype, misalign, where);
     132              : }
     133              : 
     134              : unsigned
     135            0 : record_stmt_cost (stmt_vector_for_cost *body_cost_vec, int count,
     136              :                   enum vect_cost_for_stmt kind,
     137              :                   enum vect_cost_model_location where)
     138              : {
     139            0 :   gcc_assert (kind == cond_branch_taken || kind == cond_branch_not_taken
     140              :               || kind == scalar_stmt);
     141            0 :   return record_stmt_cost (body_cost_vec, count, kind, NULL, NULL,
     142            0 :                            NULL_TREE, 0, where);
     143              : }
     144              : 
     145              : /* Return a variable of type ELEM_TYPE[NELEMS].  */
     146              : 
     147              : static tree
     148            0 : create_vector_array (tree elem_type, unsigned HOST_WIDE_INT nelems)
     149              : {
     150            0 :   return create_tmp_var (build_array_type_nelts (elem_type, nelems),
     151            0 :                          "vect_array");
     152              : }
     153              : 
     154              : /* ARRAY is an array of vectors created by create_vector_array.
     155              :    Return an SSA_NAME for the vector in index N.  The reference
     156              :    is part of the vectorization of STMT_INFO and the vector is associated
     157              :    with scalar destination SCALAR_DEST.
     158              :    If we need to ensure that inactive elements are set to zero,
     159              :    NEED_ZEROING is true, MASK contains the loop mask to be used.  */
     160              : 
     161              : static tree
     162            0 : read_vector_array (vec_info *vinfo,
     163              :                    stmt_vec_info stmt_info, gimple_stmt_iterator *gsi,
     164              :                    tree scalar_dest, tree array, unsigned HOST_WIDE_INT n,
     165              :                    bool need_zeroing, tree mask)
     166              : {
     167            0 :   tree vect_type, vect, vect_name, tmp, tmp_name, array_ref;
     168            0 :   gassign *new_stmt;
     169              : 
     170            0 :   gcc_assert (TREE_CODE (TREE_TYPE (array)) == ARRAY_TYPE);
     171            0 :   vect_type = TREE_TYPE (TREE_TYPE (array));
     172            0 :   tmp = vect_create_destination_var (scalar_dest, vect_type);
     173            0 :   vect = vect_create_destination_var (scalar_dest, vect_type);
     174            0 :   array_ref = build4 (ARRAY_REF, vect_type, array,
     175            0 :                       build_int_cst (size_type_node, n),
     176              :                       NULL_TREE, NULL_TREE);
     177              : 
     178            0 :   new_stmt = gimple_build_assign (tmp, array_ref);
     179            0 :   tmp_name = make_ssa_name (vect, new_stmt);
     180            0 :   gimple_assign_set_lhs (new_stmt, tmp_name);
     181            0 :   vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
     182              : 
     183            0 :   if (need_zeroing)
     184              :     {
     185            0 :       tree vec_els = vect_get_mask_load_else (MASK_LOAD_ELSE_ZERO,
     186              :                                               vect_type);
     187            0 :       vect_name = make_ssa_name (vect, new_stmt);
     188            0 :       new_stmt
     189            0 :         = gimple_build_assign (vect_name, VEC_COND_EXPR,
     190              :                                mask, tmp_name, vec_els);
     191            0 :       vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
     192              :     }
     193              :   else
     194              :     vect_name = tmp_name;
     195              : 
     196            0 :   return vect_name;
     197              : }
     198              : 
     199              : /* ARRAY is an array of vectors created by create_vector_array.
     200              :    Emit code to store SSA_NAME VECT in index N of the array.
     201              :    The store is part of the vectorization of STMT_INFO.  */
     202              : 
     203              : static void
     204            0 : write_vector_array (vec_info *vinfo,
     205              :                     stmt_vec_info stmt_info, gimple_stmt_iterator *gsi,
     206              :                     tree vect, tree array, unsigned HOST_WIDE_INT n)
     207              : {
     208            0 :   tree array_ref;
     209            0 :   gimple *new_stmt;
     210              : 
     211            0 :   array_ref = build4 (ARRAY_REF, TREE_TYPE (vect), array,
     212            0 :                       build_int_cst (size_type_node, n),
     213              :                       NULL_TREE, NULL_TREE);
     214              : 
     215            0 :   new_stmt = gimple_build_assign (array_ref, vect);
     216            0 :   vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
     217            0 : }
     218              : 
     219              : /* PTR is a pointer to an array of type TYPE.  Return a representation
     220              :    of *PTR.  The memory reference replaces those in FIRST_DR
     221              :    (and its group).  */
     222              : 
     223              : static tree
     224            0 : create_array_ref (tree type, tree ptr, tree alias_ptr_type)
     225              : {
     226            0 :   tree mem_ref;
     227              : 
     228            0 :   mem_ref = build2 (MEM_REF, type, ptr, build_int_cst (alias_ptr_type, 0));
     229              :   /* Arrays have the same alignment as their type.  */
     230            0 :   set_ssa_name_alignment (ptr, TYPE_ALIGN_UNIT (type), 0);
     231            0 :   return mem_ref;
     232              : }
     233              : 
     234              : /* Add a clobber of variable VAR to the vectorization of STMT_INFO.
     235              :    Emit the clobber before *GSI.  */
     236              : 
     237              : static void
     238           20 : vect_clobber_variable (vec_info *vinfo, stmt_vec_info stmt_info,
     239              :                        gimple_stmt_iterator *gsi, tree var)
     240              : {
     241           20 :   tree clobber = build_clobber (TREE_TYPE (var));
     242           20 :   gimple *new_stmt = gimple_build_assign (var, clobber);
     243           20 :   vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
     244           20 : }
     245              : 
     246              : /* Utility functions used by vect_mark_stmts_to_be_vectorized.  */
     247              : 
     248              : /* Function vect_mark_relevant.
     249              : 
     250              :    Mark STMT_INFO as "relevant for vectorization" and add it to WORKLIST.  */
     251              : 
     252              : static void
     253      3397780 : vect_mark_relevant (vec<stmt_vec_info> *worklist, stmt_vec_info stmt_info,
     254              :                     enum vect_relevant relevant, bool live_p)
     255              : {
     256      3397780 :   enum vect_relevant save_relevant = STMT_VINFO_RELEVANT (stmt_info);
     257      3397780 :   bool save_live_p = STMT_VINFO_LIVE_P (stmt_info);
     258              : 
     259      3397780 :   if (dump_enabled_p ())
     260       178642 :     dump_printf_loc (MSG_NOTE, vect_location,
     261              :                      "mark relevant %d, live %d: %G", relevant, live_p,
     262              :                      stmt_info->stmt);
     263              : 
     264              :   /* If this stmt is an original stmt in a pattern, we might need to mark its
     265              :      related pattern stmt instead of the original stmt.  However, such stmts
     266              :      may have their own uses that are not in any pattern, in such cases the
     267              :      stmt itself should be marked.  */
     268      3397780 :   if (STMT_VINFO_IN_PATTERN_P (stmt_info))
     269              :     {
     270              :       /* This is the last stmt in a sequence that was detected as a
     271              :          pattern that can potentially be vectorized.  Don't mark the stmt
     272              :          as relevant/live because it's not going to be vectorized.
     273              :          Instead mark the pattern-stmt that replaces it.  */
     274              : 
     275       261715 :       if (dump_enabled_p ())
     276         3289 :         dump_printf_loc (MSG_NOTE, vect_location,
     277              :                          "last stmt in pattern. don't mark"
     278              :                          " relevant/live.\n");
     279              : 
     280       261715 :       stmt_vec_info old_stmt_info = stmt_info;
     281       261715 :       stmt_info = STMT_VINFO_RELATED_STMT (stmt_info);
     282       261715 :       gcc_assert (STMT_VINFO_RELATED_STMT (stmt_info) == old_stmt_info);
     283       261715 :       save_relevant = STMT_VINFO_RELEVANT (stmt_info);
     284       261715 :       save_live_p = STMT_VINFO_LIVE_P (stmt_info);
     285              : 
     286       261715 :       if (live_p && relevant == vect_unused_in_scope)
     287              :         {
     288          119 :           if (dump_enabled_p ())
     289           10 :             dump_printf_loc (MSG_NOTE, vect_location,
     290              :                              "vec_stmt_relevant_p: forcing live pattern stmt "
     291              :                              "relevant.\n");
     292              :           relevant = vect_used_only_live;
     293              :         }
     294              : 
     295       261715 :       if (dump_enabled_p ())
     296         3289 :         dump_printf_loc (MSG_NOTE, vect_location,
     297              :                          "mark relevant %d, live %d: %G", relevant, live_p,
     298              :                          stmt_info->stmt);
     299              :     }
     300              : 
     301      3397780 :   STMT_VINFO_LIVE_P (stmt_info) |= live_p;
     302      3397780 :   if (relevant > STMT_VINFO_RELEVANT (stmt_info))
     303      3054500 :     STMT_VINFO_RELEVANT (stmt_info) = relevant;
     304              : 
     305      3397780 :   if (STMT_VINFO_RELEVANT (stmt_info) == save_relevant
     306       343280 :       && STMT_VINFO_LIVE_P (stmt_info) == save_live_p)
     307              :     {
     308       342596 :       if (dump_enabled_p ())
     309        22122 :         dump_printf_loc (MSG_NOTE, vect_location,
     310              :                          "already marked relevant/live.\n");
     311              :       return;
     312              :     }
     313              : 
     314      3055184 :   worklist->safe_push (stmt_info);
     315              : }
     316              : 
     317              : 
     318              : /* Function is_simple_and_all_uses_invariant
     319              : 
     320              :    Return true if STMT_INFO is simple and all uses of it are invariant.  */
     321              : 
     322              : bool
     323       263340 : is_simple_and_all_uses_invariant (stmt_vec_info stmt_info,
     324              :                                   loop_vec_info loop_vinfo)
     325              : {
     326       263340 :   tree op;
     327       263340 :   ssa_op_iter iter;
     328              : 
     329       263340 :   gassign *stmt = dyn_cast <gassign *> (stmt_info->stmt);
     330       206198 :   if (!stmt)
     331              :     return false;
     332              : 
     333       213641 :   FOR_EACH_SSA_TREE_OPERAND (op, stmt, iter, SSA_OP_USE)
     334              :     {
     335       212838 :       enum vect_def_type dt = vect_uninitialized_def;
     336              : 
     337       212838 :       if (!vect_is_simple_use (op, loop_vinfo, &dt))
     338              :         {
     339         5594 :           if (dump_enabled_p ())
     340           24 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
     341              :                              "use not simple.\n");
     342       205395 :           return false;
     343              :         }
     344              : 
     345       207244 :       if (dt != vect_external_def && dt != vect_constant_def)
     346              :         return false;
     347              :     }
     348              :   return true;
     349              : }
     350              : 
     351              : /* Function vect_stmt_relevant_p.
     352              : 
     353              :    Return true if STMT_INFO, in the loop that is represented by LOOP_VINFO,
     354              :    is "relevant for vectorization".
     355              : 
     356              :    A stmt is considered "relevant for vectorization" if:
     357              :    - it has uses outside the loop.
     358              :    - it has vdefs (it alters memory).
     359              :    - control stmts in the loop (except for the exit condition).
     360              : 
     361              :    CHECKME: what other side effects would the vectorizer allow?  */
     362              : 
     363              : static bool
     364      5478941 : vect_stmt_relevant_p (stmt_vec_info stmt_info, loop_vec_info loop_vinfo,
     365              :                       enum vect_relevant *relevant, bool *live_p)
     366              : {
     367      5478941 :   class loop *loop = LOOP_VINFO_LOOP (loop_vinfo);
     368      5478941 :   ssa_op_iter op_iter;
     369      5478941 :   imm_use_iterator imm_iter;
     370      5478941 :   use_operand_p use_p;
     371      5478941 :   def_operand_p def_p;
     372              : 
     373      5478941 :   *relevant = vect_unused_in_scope;
     374      5478941 :   *live_p = false;
     375              : 
     376              :   /* cond stmt other than loop exit cond.  */
     377      5478941 :   gimple *stmt = STMT_VINFO_STMT (stmt_info);
     378      5478941 :   if (is_ctrl_stmt (stmt)
     379       653855 :       && LOOP_VINFO_LOOP_IV_COND (loop_vinfo) != stmt
     380      5726945 :       && (!loop->inner || gimple_bb (stmt)->loop_father == loop))
     381       245990 :     *relevant = vect_used_in_scope;
     382              : 
     383              :   /* changing memory.  */
     384      5478941 :   if (gimple_code (stmt_info->stmt) != GIMPLE_PHI)
     385      4537990 :     if (gimple_vdef (stmt_info->stmt)
     386      3884135 :         && !gimple_clobber_p (stmt_info->stmt))
     387              :       {
     388       392043 :         if (dump_enabled_p ())
     389        29603 :           dump_printf_loc (MSG_NOTE, vect_location,
     390              :                            "vec_stmt_relevant_p: stmt has vdefs.\n");
     391       392043 :         *relevant = vect_used_in_scope;
     392       392043 :         if (! STMT_VINFO_DATA_REF (stmt_info)
     393       392043 :             && zero_ssa_operands (stmt_info->stmt, SSA_OP_DEF))
     394           26 :           LOOP_VINFO_ALTERNATE_DEFS (loop_vinfo).safe_push (stmt_info);
     395              :       }
     396              : 
     397              :   /* uses outside the loop.  */
     398     15384315 :   FOR_EACH_PHI_OR_STMT_DEF (def_p, stmt_info->stmt, op_iter, SSA_OP_DEF)
     399              :     {
     400     11866645 :       FOR_EACH_IMM_USE_FAST (use_p, imm_iter, DEF_FROM_PTR (def_p))
     401              :         {
     402      7440212 :           basic_block bb = gimple_bb (USE_STMT (use_p));
     403      7440212 :           if (!flow_bb_inside_loop_p (loop, bb))
     404              :             {
     405       279952 :               if (is_gimple_debug (USE_STMT (use_p)))
     406         1196 :                 continue;
     407              : 
     408       278756 :               if (dump_enabled_p ())
     409         6569 :                 dump_printf_loc (MSG_NOTE, vect_location,
     410              :                                  "vec_stmt_relevant_p: used out of loop.\n");
     411              : 
     412              :               /* We expect all such uses to be in the loop exit phis
     413              :                  (because of loop closed form)   */
     414       278756 :               gcc_assert (gimple_code (USE_STMT (use_p)) == GIMPLE_PHI);
     415              : 
     416       278756 :               *live_p = true;
     417       278756 :               LOOP_VINFO_EARLY_BRK_NEEDS_EPILOG (loop_vinfo) = true;
     418              :             }
     419      4426433 :         }
     420              :     }
     421              : 
     422       263342 :   if (*live_p && *relevant == vect_unused_in_scope
     423      5742281 :       && !is_simple_and_all_uses_invariant (stmt_info, loop_vinfo))
     424              :     {
     425       262537 :       if (dump_enabled_p ())
     426         6435 :         dump_printf_loc (MSG_NOTE, vect_location,
     427              :                          "vec_stmt_relevant_p: stmt live but not relevant.\n");
     428       262537 :       *relevant = vect_used_only_live;
     429              :     }
     430              : 
     431      5478941 :   return (*live_p || *relevant);
     432              : }
     433              : 
     434              : 
     435              : /* Function exist_non_indexing_operands_for_use_p
     436              : 
     437              :    USE is one of the uses attached to STMT_INFO.  Check if USE is
     438              :    used in STMT_INFO for anything other than indexing an array.  */
     439              : 
     440              : static bool
     441      4561748 : exist_non_indexing_operands_for_use_p (tree use, stmt_vec_info stmt_info)
     442              : {
     443      4561748 :   tree operand;
     444              : 
     445              :   /* USE corresponds to some operand in STMT.  If there is no data
     446              :      reference in STMT, then any operand that corresponds to USE
     447              :      is not indexing an array.  */
     448      4561748 :   if (!STMT_VINFO_DATA_REF (stmt_info))
     449              :     return true;
     450              : 
     451              :   /* STMT has a data_ref. FORNOW this means that its of one of
     452              :      the following forms:
     453              :      -1- ARRAY_REF = var
     454              :      -2- var = ARRAY_REF
     455              :      (This should have been verified in analyze_data_refs).
     456              : 
     457              :      'var' in the second case corresponds to a def, not a use,
     458              :      so USE cannot correspond to any operands that are not used
     459              :      for array indexing.
     460              : 
     461              :      Therefore, all we need to check is if STMT falls into the
     462              :      first case, and whether var corresponds to USE.  */
     463              : 
     464      1555792 :   gassign *assign = dyn_cast <gassign *> (stmt_info->stmt);
     465      1537315 :   if (!assign || !gimple_assign_copy_p (assign))
     466              :     {
     467       833014 :       gcall *call = dyn_cast <gcall *> (stmt_info->stmt);
     468        18477 :       if (call && gimple_call_internal_p (call))
     469              :         {
     470        18477 :           internal_fn ifn = gimple_call_internal_fn (call);
     471        18477 :           int mask_index = internal_fn_mask_index (ifn);
     472        18477 :           if (mask_index >= 0
     473        18477 :               && use == gimple_call_arg (call, mask_index))
     474              :             return true;
     475        12060 :           int els_index = internal_fn_else_index (ifn);
     476        12060 :           if (els_index >= 0
     477        12060 :               && use == gimple_call_arg (call, els_index))
     478              :             return true;
     479        10558 :           int stored_value_index = internal_fn_stored_value_index (ifn);
     480        10558 :           if (stored_value_index >= 0
     481        10558 :               && use == gimple_call_arg (call, stored_value_index))
     482              :             return true;
     483         8150 :           if (internal_gather_scatter_fn_p (ifn)
     484         8150 :               && use == gimple_call_arg (call, 1))
     485              :             return true;
     486              :         }
     487       822687 :       return false;
     488              :     }
     489              : 
     490       722778 :   if (TREE_CODE (gimple_assign_lhs (assign)) == SSA_NAME)
     491              :     return false;
     492       722778 :   operand = gimple_assign_rhs1 (assign);
     493       722778 :   if (TREE_CODE (operand) != SSA_NAME)
     494              :     return false;
     495              : 
     496       625067 :   if (operand == use)
     497       294963 :     return true;
     498              : 
     499              :   return false;
     500              : }
     501              : 
     502              : 
     503              : /*
     504              :    Function process_use.
     505              : 
     506              :    Inputs:
     507              :    - a USE in STMT_VINFO in a loop represented by LOOP_VINFO
     508              :    - RELEVANT - enum value to be set in the STMT_VINFO of the stmt
     509              :      that defined USE.  This is done by calling mark_relevant and passing it
     510              :      the WORKLIST (to add DEF_STMT to the WORKLIST in case it is relevant).
     511              :    - FORCE is true if exist_non_indexing_operands_for_use_p check shouldn't
     512              :      be performed.
     513              : 
     514              :    Outputs:
     515              :    Generally, LIVE_P and RELEVANT are used to define the liveness and
     516              :    relevance info of the DEF_STMT of this USE:
     517              :        STMT_VINFO_LIVE_P (DEF_stmt_vinfo) <-- live_p
     518              :        STMT_VINFO_RELEVANT (DEF_stmt_vinfo) <-- relevant
     519              :    Exceptions:
     520              :    - case 1: If USE is used only for address computations (e.g. array indexing),
     521              :    which does not need to be directly vectorized, then the liveness/relevance
     522              :    of the respective DEF_STMT is left unchanged.
     523              :    - case 2: If STMT_VINFO is a reduction phi and DEF_STMT is a reduction stmt,
     524              :    we skip DEF_STMT cause it had already been processed.
     525              :    - case 3: If DEF_STMT and STMT_VINFO are in different nests, then
     526              :    "relevant" will be modified accordingly.
     527              : 
     528              :    Return true if everything is as expected. Return false otherwise.  */
     529              : 
     530              : static opt_result
     531      4619925 : process_use (stmt_vec_info stmt_vinfo, tree use, loop_vec_info loop_vinfo,
     532              :              enum vect_relevant relevant, vec<stmt_vec_info> *worklist,
     533              :              bool force)
     534              : {
     535      4619925 :   stmt_vec_info dstmt_vinfo;
     536      4619925 :   enum vect_def_type dt;
     537              : 
     538              :   /* case 1: we are only interested in uses that need to be vectorized.  Uses
     539              :      that are used for address computation are not considered relevant.  */
     540      4619925 :   if (!force && !exist_non_indexing_operands_for_use_p (use, stmt_vinfo))
     541      1250502 :     return opt_result::success ();
     542              : 
     543      3369423 :   if (!vect_is_simple_use (use, loop_vinfo, &dt, &dstmt_vinfo))
     544        36433 :     return opt_result::failure_at (stmt_vinfo->stmt,
     545              :                                    "not vectorized:"
     546              :                                    " unsupported use in stmt.\n");
     547              : 
     548      3332990 :   if (!dstmt_vinfo)
     549       633872 :     return opt_result::success ();
     550              : 
     551      2699118 :   basic_block def_bb = gimple_bb (dstmt_vinfo->stmt);
     552      2699118 :   basic_block bb = gimple_bb (stmt_vinfo->stmt);
     553              : 
     554              :   /* case 2: A reduction phi (STMT) defined by a reduction stmt (DSTMT_VINFO).
     555              :      We have to force the stmt live since the epilogue loop needs it to
     556              :      continue computing the reduction.  */
     557      2699118 :   if (gimple_code (stmt_vinfo->stmt) == GIMPLE_PHI
     558       285613 :       && STMT_VINFO_DEF_TYPE (stmt_vinfo) == vect_reduction_def
     559        87605 :       && gimple_code (dstmt_vinfo->stmt) != GIMPLE_PHI
     560        87605 :       && STMT_VINFO_DEF_TYPE (dstmt_vinfo) == vect_reduction_def
     561      2786723 :       && bb->loop_father == def_bb->loop_father)
     562              :     {
     563        87605 :       if (dump_enabled_p ())
     564         4147 :         dump_printf_loc (MSG_NOTE, vect_location,
     565              :                          "reduc-stmt defining reduc-phi in the same nest.\n");
     566        87605 :       vect_mark_relevant (worklist, dstmt_vinfo, relevant, true);
     567        87605 :       return opt_result::success ();
     568              :     }
     569              : 
     570              :   /* case 3a: outer-loop stmt defining an inner-loop stmt:
     571              :         outer-loop-header-bb:
     572              :                 d = dstmt_vinfo
     573              :         inner-loop:
     574              :                 stmt # use (d)
     575              :         outer-loop-tail-bb:
     576              :                 ...               */
     577      2611513 :   if (flow_loop_nested_p (def_bb->loop_father, bb->loop_father))
     578              :     {
     579         2185 :       if (dump_enabled_p ())
     580          335 :         dump_printf_loc (MSG_NOTE, vect_location,
     581              :                          "outer-loop def-stmt defining inner-loop stmt.\n");
     582              : 
     583         2185 :       switch (relevant)
     584              :         {
     585            0 :         case vect_unused_in_scope:
     586            0 :           relevant = (STMT_VINFO_DEF_TYPE (stmt_vinfo) == vect_nested_cycle) ?
     587              :                       vect_used_in_scope : vect_unused_in_scope;
     588              :           break;
     589              : 
     590          791 :         case vect_used_in_outer_by_reduction:
     591          791 :           gcc_assert (STMT_VINFO_DEF_TYPE (stmt_vinfo) != vect_reduction_def);
     592              :           relevant = vect_used_by_reduction;
     593              :           break;
     594              : 
     595         1090 :         case vect_used_in_outer:
     596         1090 :           gcc_assert (STMT_VINFO_DEF_TYPE (stmt_vinfo) != vect_reduction_def);
     597              :           relevant = vect_used_in_scope;
     598              :           break;
     599              : 
     600              :         case vect_used_in_scope:
     601              :           break;
     602              : 
     603            0 :         default:
     604            0 :           gcc_unreachable ();
     605              :         }
     606              :     }
     607              : 
     608              :   /* case 3b: inner-loop stmt defining an outer-loop stmt:
     609              :         outer-loop-header-bb:
     610              :                 ...
     611              :         inner-loop:
     612              :                 d = dstmt_vinfo
     613              :         outer-loop-tail-bb (or outer-loop-exit-bb in double reduction):
     614              :                 stmt # use (d)          */
     615      2609328 :   else if (flow_loop_nested_p (bb->loop_father, def_bb->loop_father))
     616              :     {
     617         2099 :       if (dump_enabled_p ())
     618          629 :         dump_printf_loc (MSG_NOTE, vect_location,
     619              :                          "inner-loop def-stmt defining outer-loop stmt.\n");
     620              : 
     621         2099 :       switch (relevant)
     622              :         {
     623            0 :         case vect_unused_in_scope:
     624      2419811 :           relevant = (STMT_VINFO_DEF_TYPE (stmt_vinfo) == vect_reduction_def
     625            0 :             || STMT_VINFO_DEF_TYPE (stmt_vinfo) == vect_double_reduction_def) ?
     626              :                       vect_used_in_outer_by_reduction : vect_unused_in_scope;
     627              :           break;
     628              : 
     629              :         case vect_used_by_reduction:
     630              :         case vect_used_only_live:
     631              :           relevant = vect_used_in_outer_by_reduction;
     632              :           break;
     633              : 
     634              :         case vect_used_in_scope:
     635      2419811 :           relevant = vect_used_in_outer;
     636              :           break;
     637              : 
     638            0 :         default:
     639            0 :           gcc_unreachable ();
     640              :         }
     641              :     }
     642              :   /* We are also not interested in uses on loop PHI backedges that are
     643              :      inductions.  Otherwise we'll needlessly vectorize the IV increment
     644              :      and cause hybrid SLP for SLP inductions.  */
     645      2607229 :   else if (gimple_code (stmt_vinfo->stmt) == GIMPLE_PHI
     646       194754 :            && STMT_VINFO_DEF_TYPE (stmt_vinfo) == vect_induction_def
     647      2798931 :            && (PHI_ARG_DEF_FROM_EDGE (stmt_vinfo->stmt,
     648              :                                       loop_latch_edge (bb->loop_father))
     649              :                == use))
     650              :     {
     651       191702 :       if (dump_enabled_p ())
     652         5628 :         dump_printf_loc (MSG_NOTE, vect_location,
     653              :                          "induction value on backedge.\n");
     654       191702 :       return opt_result::success ();
     655              :     }
     656              : 
     657      2419811 :   vect_mark_relevant (worklist, dstmt_vinfo, relevant, false);
     658      2419811 :   return opt_result::success ();
     659              : }
     660              : 
     661              : 
     662              : /* Function vect_mark_stmts_to_be_vectorized.
     663              : 
     664              :    Not all stmts in the loop need to be vectorized. For example:
     665              : 
     666              :      for i...
     667              :        for j...
     668              :    1.    T0 = i + j
     669              :    2.    T1 = a[T0]
     670              : 
     671              :    3.    j = j + 1
     672              : 
     673              :    Stmt 1 and 3 do not need to be vectorized, because loop control and
     674              :    addressing of vectorized data-refs are handled differently.
     675              : 
     676              :    This pass detects such stmts.  */
     677              : 
     678              : opt_result
     679       464405 : vect_mark_stmts_to_be_vectorized (loop_vec_info loop_vinfo, bool *fatal)
     680              : {
     681       464405 :   class loop *loop = LOOP_VINFO_LOOP (loop_vinfo);
     682       464405 :   basic_block *bbs = LOOP_VINFO_BBS (loop_vinfo);
     683       464405 :   unsigned int nbbs = loop->num_nodes;
     684       464405 :   gimple_stmt_iterator si;
     685       464405 :   unsigned int i;
     686       464405 :   basic_block bb;
     687       464405 :   bool live_p;
     688       464405 :   enum vect_relevant relevant;
     689              : 
     690       464405 :   DUMP_VECT_SCOPE ("vect_mark_stmts_to_be_vectorized");
     691              : 
     692       464405 :   auto_vec<stmt_vec_info, 64> worklist;
     693              : 
     694              :   /* 1. Init worklist.  */
     695      1575553 :   for (i = 0; i < nbbs; i++)
     696              :     {
     697      1122302 :       bb = bbs[i];
     698      2296014 :       for (si = gsi_start_phis (bb); !gsi_end_p (si); gsi_next (&si))
     699              :         {
     700      2369442 :           if (virtual_operand_p (gimple_phi_result (gsi_stmt (si))))
     701       243770 :             continue;
     702       940951 :           stmt_vec_info phi_info = loop_vinfo->lookup_stmt (gsi_stmt (si));
     703       940951 :           if (dump_enabled_p ())
     704        44582 :             dump_printf_loc (MSG_NOTE, vect_location, "init: phi relevant? %G",
     705              :                              phi_info->stmt);
     706              : 
     707       940951 :           if (vect_stmt_relevant_p (phi_info, loop_vinfo, &relevant, &live_p))
     708              :             {
     709        47924 :               if (STMT_VINFO_DEF_TYPE (phi_info) == vect_unknown_def_type)
     710        11009 :                 return opt_result::failure_at
     711        11009 :                   (*si, "not vectorized: unhandled relevant PHI: %G", *si);
     712        36915 :               vect_mark_relevant (&worklist, phi_info, relevant, live_p);
     713              :             }
     714              :         }
     715      8806594 :       for (si = gsi_after_labels (bb); !gsi_end_p (si); gsi_next (&si))
     716              :         {
     717      7695446 :           gimple *stmt = gsi_stmt (si);
     718      7695446 :           if (is_gimple_debug (stmt))
     719      3157311 :             continue;
     720      4538135 :           stmt_vec_info stmt_info = loop_vinfo->lookup_stmt (stmt);
     721      4538135 :           if (dump_enabled_p ())
     722       243045 :               dump_printf_loc (MSG_NOTE, vect_location,
     723              :                                "init: stmt relevant? %G", stmt);
     724              : 
     725      4538135 :           if (gimple_get_lhs (stmt) == NULL_TREE
     726       660347 :               && !is_a <gcond *> (stmt)
     727      4544627 :               && !is_a <gcall *> (stmt))
     728          145 :             return opt_result::failure_at
     729          145 :                 (stmt, "not vectorized: irregular stmt: %G", stmt);
     730              : 
     731      4537990 :           if (vect_stmt_relevant_p (stmt_info, loop_vinfo, &relevant, &live_p))
     732       853449 :             vect_mark_relevant (&worklist, stmt_info, relevant, live_p);
     733              :         }
     734              :     }
     735              : 
     736              :   /* 2. Process_worklist */
     737      3379344 :   while (worklist.length () > 0)
     738              :     {
     739      2962529 :       use_operand_p use_p;
     740      2962529 :       ssa_op_iter iter;
     741              : 
     742      2962529 :       stmt_vec_info stmt_vinfo = worklist.pop ();
     743      2962529 :       if (dump_enabled_p ())
     744       155826 :         dump_printf_loc (MSG_NOTE, vect_location,
     745              :                          "worklist: examine stmt: %G", stmt_vinfo->stmt);
     746              : 
     747              :       /* Examine the USEs of STMT. For each USE, mark the stmt that defines it
     748              :          (DEF_STMT) as relevant/irrelevant according to the relevance property
     749              :          of STMT.  */
     750      2962529 :       relevant = STMT_VINFO_RELEVANT (stmt_vinfo);
     751              : 
     752              :       /* Generally, the relevance property of STMT (in STMT_VINFO_RELEVANT) is
     753              :          propagated as is to the DEF_STMTs of its USEs.
     754              : 
     755              :          One exception is when STMT has been identified as defining a reduction
     756              :          variable; in this case we set the relevance to vect_used_by_reduction.
     757              :          This is because we distinguish between two kinds of relevant stmts -
     758              :          those that are used by a reduction computation, and those that are
     759              :          (also) used by a regular computation.  This allows us later on to
     760              :          identify stmts that are used solely by a reduction, and therefore the
     761              :          order of the results that they produce does not have to be kept.  */
     762              : 
     763      2962529 :       switch (STMT_VINFO_DEF_TYPE (stmt_vinfo))
     764              :         {
     765       177342 :           case vect_reduction_def:
     766       177342 :             gcc_assert (relevant != vect_unused_in_scope);
     767       177342 :             if (relevant != vect_unused_in_scope
     768       177342 :                 && relevant != vect_used_in_scope
     769       177342 :                 && relevant != vect_used_by_reduction
     770       177342 :                 && relevant != vect_used_only_live)
     771            0 :               return opt_result::failure_at
     772            0 :                 (stmt_vinfo->stmt, "unsupported use of reduction.\n");
     773              :             break;
     774              : 
     775         2107 :           case vect_nested_cycle:
     776         2107 :             if (relevant != vect_unused_in_scope
     777         2107 :                 && relevant != vect_used_in_outer_by_reduction
     778         1500 :                 && relevant != vect_used_in_outer)
     779            3 :               return opt_result::failure_at
     780            3 :                 (stmt_vinfo->stmt, "unsupported use of nested cycle.\n");
     781              :             break;
     782              : 
     783         1245 :           case vect_double_reduction_def:
     784         1245 :             if (relevant != vect_unused_in_scope
     785         1245 :                 && relevant != vect_used_by_reduction
     786          421 :                 && relevant != vect_used_only_live)
     787            0 :               return opt_result::failure_at
     788            0 :                 (stmt_vinfo->stmt, "unsupported use of double reduction.\n");
     789              :             break;
     790              : 
     791              :           default:
     792              :             break;
     793              :         }
     794              : 
     795      2962526 :       if (is_pattern_stmt_p (stmt_vinfo))
     796              :         {
     797              :           /* Pattern statements are not inserted into the code, so
     798              :              FOR_EACH_PHI_OR_STMT_USE optimizes their operands out, and we
     799              :              have to scan the RHS or function arguments instead.  */
     800       671761 :           if (gassign *assign = dyn_cast <gassign *> (stmt_vinfo->stmt))
     801              :             {
     802       435218 :               enum tree_code rhs_code = gimple_assign_rhs_code (assign);
     803       435218 :               tree op = gimple_assign_rhs1 (assign);
     804              : 
     805       435218 :               i = 1;
     806       435218 :               if (rhs_code == COND_EXPR && COMPARISON_CLASS_P (op))
     807              :                 {
     808            0 :                   opt_result res
     809            0 :                     = process_use (stmt_vinfo, TREE_OPERAND (op, 0),
     810              :                                    loop_vinfo, relevant, &worklist, false);
     811            0 :                   if (!res)
     812            0 :                     return res;
     813            0 :                   res = process_use (stmt_vinfo, TREE_OPERAND (op, 1),
     814              :                                      loop_vinfo, relevant, &worklist, false);
     815            0 :                   if (!res)
     816            0 :                     return res;
     817       435218 :                   i = 2;
     818              :                 }
     819      1253657 :               for (; i < gimple_num_ops (assign); i++)
     820              :                 {
     821       822504 :                   op = gimple_op (assign, i);
     822       822504 :                   if (TREE_CODE (op) == SSA_NAME)
     823              :                     {
     824       624861 :                       opt_result res
     825       624861 :                         = process_use (stmt_vinfo, op, loop_vinfo, relevant,
     826              :                                        &worklist, false);
     827       624861 :                       if (!res)
     828         4065 :                         return res;
     829              :                     }
     830              :                  }
     831              :             }
     832       236543 :           else if (gcond *cond = dyn_cast <gcond *> (stmt_vinfo->stmt))
     833              :             {
     834       229262 :               tree_code rhs_code = gimple_cond_code (cond);
     835       229262 :               gcc_assert (TREE_CODE_CLASS (rhs_code) == tcc_comparison);
     836       229262 :               opt_result res
     837       229262 :                 = process_use (stmt_vinfo, gimple_cond_lhs (cond),
     838              :                                loop_vinfo, relevant, &worklist, false);
     839       229262 :               if (!res)
     840        36436 :                 return res;
     841       229262 :               res = process_use (stmt_vinfo, gimple_cond_rhs (cond),
     842              :                                 loop_vinfo, relevant, &worklist, false);
     843       229262 :               if (!res)
     844            0 :                 return res;
     845              :             }
     846         7281 :           else if (gcall *call = dyn_cast <gcall *> (stmt_vinfo->stmt))
     847              :             {
     848        34054 :               for (i = 0; i < gimple_call_num_args (call); i++)
     849              :                 {
     850        26773 :                   tree arg = gimple_call_arg (call, i);
     851        26773 :                   opt_result res
     852        26773 :                     = process_use (stmt_vinfo, arg, loop_vinfo, relevant,
     853              :                                    &worklist, false);
     854        26773 :                   if (!res)
     855            0 :                     return res;
     856              :                 }
     857              :             }
     858              :           else
     859            0 :             gcc_unreachable ();
     860              :         }
     861              :       else
     862      8014775 :         FOR_EACH_PHI_OR_STMT_USE (use_p, stmt_vinfo->stmt, iter, SSA_OP_USE)
     863              :           {
     864      3451590 :             tree op = USE_FROM_PTR (use_p);
     865      3451590 :             opt_result res
     866      3451590 :               = process_use (stmt_vinfo, op, loop_vinfo, relevant,
     867              :                              &worklist, false);
     868      3451590 :             if (!res)
     869        18345 :               return res;
     870              :           }
     871              : 
     872      2940116 :       if (STMT_VINFO_GATHER_SCATTER_P (stmt_vinfo))
     873              :         {
     874        58177 :           gather_scatter_info gs_info;
     875        58177 :           if (!vect_check_gather_scatter (stmt_vinfo,
     876              :                                           STMT_VINFO_VECTYPE (stmt_vinfo),
     877              :                                           loop_vinfo, &gs_info))
     878            0 :             gcc_unreachable ();
     879        58177 :           opt_result res
     880        58177 :             = process_use (stmt_vinfo, gs_info.offset, loop_vinfo, relevant,
     881              :                            &worklist, true);
     882        58177 :           if (!res)
     883              :             {
     884        14023 :               if (fatal)
     885        14023 :                 *fatal = false;
     886        14023 :               return res;
     887              :             }
     888              :         }
     889              :     } /* while worklist */
     890              : 
     891       416815 :   return opt_result::success ();
     892       464405 : }
     893              : 
     894              : /* Function vect_model_simple_cost.
     895              : 
     896              :    Models cost for simple operations, i.e. those that only emit N operations
     897              :    of the same KIND.  */
     898              : 
     899              : static void
     900       683450 : vect_model_simple_cost (vec_info *vinfo, int n, slp_tree node,
     901              :                         stmt_vector_for_cost *cost_vec,
     902              :                         vect_cost_for_stmt kind = vector_stmt)
     903              : {
     904       683450 :   int inside_cost = 0, prologue_cost = 0;
     905              : 
     906       683450 :   gcc_assert (cost_vec != NULL);
     907              : 
     908       683450 :   n *= vect_get_num_copies (vinfo, node);
     909              : 
     910              :   /* Pass the inside-of-loop statements to the target-specific cost model.  */
     911       683450 :   inside_cost += record_stmt_cost (cost_vec, n, kind, node, 0, vect_body);
     912              : 
     913       683450 :   if (dump_enabled_p ())
     914        36851 :     dump_printf_loc (MSG_NOTE, vect_location,
     915              :                      "vect_model_simple_cost: inside_cost = %d, "
     916              :                      "prologue_cost = %d .\n", inside_cost, prologue_cost);
     917       683450 : }
     918              : 
     919              : 
     920              : /* Model cost for type demotion and promotion operations.  PWR is
     921              :    normally zero for single-step promotions and demotions.  It will be
     922              :    one if two-step promotion/demotion is required, and so on.  NCOPIES
     923              :    is the number of vector results (and thus number of instructions)
     924              :    for the narrowest end of the operation chain.  Each additional
     925              :    step doubles the number of instructions required.  If WIDEN_ARITH
     926              :    is true the stmt is doing widening arithmetic.  */
     927              : 
     928              : static void
     929        70986 : vect_model_promotion_demotion_cost (slp_tree slp_node,
     930              :                                     unsigned int ncopies, int pwr,
     931              :                                     stmt_vector_for_cost *cost_vec,
     932              :                                     bool widen_arith)
     933              : {
     934        70986 :   int i;
     935        70986 :   int inside_cost = 0, prologue_cost = 0;
     936              : 
     937       165137 :   for (i = 0; i < pwr + 1; i++)
     938              :     {
     939       186307 :       inside_cost += record_stmt_cost (cost_vec, ncopies,
     940              :                                        widen_arith
     941              :                                        ? vector_stmt : vec_promote_demote,
     942              :                                        slp_node, 0, vect_body);
     943        94151 :       ncopies *= 2;
     944              :     }
     945              : 
     946        70986 :   if (dump_enabled_p ())
     947         6666 :     dump_printf_loc (MSG_NOTE, vect_location,
     948              :                      "vect_model_promotion_demotion_cost: inside_cost = %d, "
     949              :                      "prologue_cost = %d .\n", inside_cost, prologue_cost);
     950        70986 : }
     951              : 
     952              : /* Returns true if the current function returns DECL.  */
     953              : 
     954              : static bool
     955       574952 : cfun_returns (tree decl)
     956              : {
     957       574952 :   edge_iterator ei;
     958       574952 :   edge e;
     959      1132422 :   FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR_FOR_FN (cfun)->preds)
     960              :     {
     961      1138472 :       greturn *ret = safe_dyn_cast <greturn *> (*gsi_last_bb (e->src));
     962       569236 :       if (!ret)
     963            0 :         continue;
     964       569236 :       if (gimple_return_retval (ret) == decl)
     965              :         return true;
     966              :       /* We often end up with an aggregate copy to the result decl,
     967              :          handle that case as well.  First skip intermediate clobbers
     968              :          though.  */
     969              :       gimple *def = ret;
     970      1798522 :       do
     971              :         {
     972      3597044 :           def = SSA_NAME_DEF_STMT (gimple_vuse (def));
     973              :         }
     974      1798522 :       while (gimple_clobber_p (def));
     975       558142 :       if (is_a <gassign *> (def)
     976        63612 :           && gimple_assign_lhs (def) == gimple_return_retval (ret)
     977       564957 :           && gimple_assign_rhs1 (def) == decl)
     978              :         return true;
     979              :     }
     980              :   return false;
     981              : }
     982              : 
     983              : /* Calculate cost of DR's memory access.  */
     984              : void
     985      1052496 : vect_get_store_cost (vec_info *, stmt_vec_info stmt_info, slp_tree slp_node,
     986              :                      int ncopies, dr_alignment_support alignment_support_scheme,
     987              :                      int misalignment,
     988              :                      unsigned int *inside_cost,
     989              :                      stmt_vector_for_cost *body_cost_vec)
     990              : {
     991      1052496 :   tree vectype
     992      1052496 :     = slp_node ? SLP_TREE_VECTYPE (slp_node) : STMT_VINFO_VECTYPE (stmt_info);
     993      1052496 :   switch (alignment_support_scheme)
     994              :     {
     995       584839 :     case dr_aligned:
     996       584839 :       {
     997       584839 :         *inside_cost += record_stmt_cost (body_cost_vec, ncopies,
     998              :                                           vector_store, stmt_info, slp_node,
     999              :                                           vectype, 0, vect_body);
    1000              : 
    1001       584839 :         if (dump_enabled_p ())
    1002        15830 :           dump_printf_loc (MSG_NOTE, vect_location,
    1003              :                            "vect_model_store_cost: aligned.\n");
    1004              :         break;
    1005              :       }
    1006              : 
    1007       467657 :     case dr_unaligned_supported:
    1008       467657 :       {
    1009              :         /* Here, we assign an additional cost for the unaligned store.  */
    1010       467657 :         *inside_cost += record_stmt_cost (body_cost_vec, ncopies,
    1011              :                                           unaligned_store, stmt_info, slp_node,
    1012              :                                           vectype, misalignment, vect_body);
    1013       467657 :         if (dump_enabled_p ())
    1014        14604 :           dump_printf_loc (MSG_NOTE, vect_location,
    1015              :                            "vect_model_store_cost: unaligned supported by "
    1016              :                            "hardware.\n");
    1017              :         break;
    1018              :       }
    1019              : 
    1020            0 :     case dr_unaligned_unsupported:
    1021            0 :       {
    1022            0 :         *inside_cost = VECT_MAX_COST;
    1023              : 
    1024            0 :         if (dump_enabled_p ())
    1025            0 :           dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    1026              :                            "vect_model_store_cost: unsupported access.\n");
    1027              :         break;
    1028              :       }
    1029              : 
    1030            0 :     default:
    1031            0 :       gcc_unreachable ();
    1032              :     }
    1033      1052496 : }
    1034              : 
    1035              : /* Calculate cost of DR's memory access.  */
    1036              : void
    1037      1023784 : vect_get_load_cost (vec_info *, stmt_vec_info stmt_info, slp_tree slp_node,
    1038              :                     int ncopies, dr_alignment_support alignment_support_scheme,
    1039              :                     int misalignment,
    1040              :                     bool add_realign_cost, unsigned int *inside_cost,
    1041              :                     unsigned int *prologue_cost,
    1042              :                     stmt_vector_for_cost *prologue_cost_vec,
    1043              :                     stmt_vector_for_cost *body_cost_vec,
    1044              :                     bool record_prologue_costs)
    1045              : {
    1046      1023784 :   tree vectype
    1047      1023784 :     = slp_node ? SLP_TREE_VECTYPE (slp_node) : STMT_VINFO_VECTYPE (stmt_info);
    1048      1023784 :   switch (alignment_support_scheme)
    1049              :     {
    1050       593292 :     case dr_aligned:
    1051       593292 :       {
    1052       593292 :         *inside_cost += record_stmt_cost (body_cost_vec, ncopies, vector_load,
    1053              :                                           stmt_info, slp_node, vectype,
    1054              :                                           0, vect_body);
    1055              : 
    1056       593292 :         if (dump_enabled_p ())
    1057        20531 :           dump_printf_loc (MSG_NOTE, vect_location,
    1058              :                            "vect_model_load_cost: aligned.\n");
    1059              : 
    1060              :         break;
    1061              :       }
    1062       369856 :     case dr_unaligned_supported:
    1063       369856 :       {
    1064              :         /* Here, we assign an additional cost for the unaligned load.  */
    1065       369856 :         *inside_cost += record_stmt_cost (body_cost_vec, ncopies,
    1066              :                                           unaligned_load, stmt_info, slp_node,
    1067              :                                           vectype, misalignment, vect_body);
    1068              : 
    1069       369856 :         if (dump_enabled_p ())
    1070        25063 :           dump_printf_loc (MSG_NOTE, vect_location,
    1071              :                            "vect_model_load_cost: unaligned supported by "
    1072              :                            "hardware.\n");
    1073              : 
    1074              :         break;
    1075              :       }
    1076            0 :     case dr_explicit_realign:
    1077            0 :       {
    1078            0 :         *inside_cost += record_stmt_cost (body_cost_vec, ncopies * 2,
    1079              :                                           vector_load, stmt_info, slp_node,
    1080              :                                           vectype, 0, vect_body);
    1081            0 :         *inside_cost += record_stmt_cost (body_cost_vec, ncopies,
    1082              :                                           vec_perm, stmt_info, slp_node,
    1083              :                                           vectype, 0, vect_body);
    1084              : 
    1085              :         /* FIXME: If the misalignment remains fixed across the iterations of
    1086              :            the containing loop, the following cost should be added to the
    1087              :            prologue costs.  */
    1088            0 :         if (targetm.vectorize.builtin_mask_for_load)
    1089            0 :           *inside_cost += record_stmt_cost (body_cost_vec, 1, vector_stmt,
    1090              :                                             stmt_info, slp_node, vectype,
    1091              :                                             0, vect_body);
    1092              : 
    1093            0 :         if (dump_enabled_p ())
    1094            0 :           dump_printf_loc (MSG_NOTE, vect_location,
    1095              :                            "vect_model_load_cost: explicit realign\n");
    1096              : 
    1097              :         break;
    1098              :       }
    1099            0 :     case dr_explicit_realign_optimized:
    1100            0 :       {
    1101            0 :         if (dump_enabled_p ())
    1102            0 :           dump_printf_loc (MSG_NOTE, vect_location,
    1103              :                            "vect_model_load_cost: unaligned software "
    1104              :                            "pipelined.\n");
    1105              : 
    1106              :         /* Unaligned software pipeline has a load of an address, an initial
    1107              :            load, and possibly a mask operation to "prime" the loop.  However,
    1108              :            if this is an access in a group of loads, which provide grouped
    1109              :            access, then the above cost should only be considered for one
    1110              :            access in the group.  Inside the loop, there is a load op
    1111              :            and a realignment op.  */
    1112              : 
    1113            0 :         if (add_realign_cost && record_prologue_costs)
    1114              :           {
    1115            0 :             *prologue_cost += record_stmt_cost (prologue_cost_vec, 2,
    1116              :                                                 vector_stmt, stmt_info,
    1117              :                                                 slp_node, vectype,
    1118              :                                                 0, vect_prologue);
    1119            0 :             if (targetm.vectorize.builtin_mask_for_load)
    1120            0 :               *prologue_cost += record_stmt_cost (prologue_cost_vec, 1,
    1121              :                                                   vector_stmt, stmt_info,
    1122              :                                                   slp_node, vectype,
    1123              :                                                   0, vect_prologue);
    1124              :           }
    1125              : 
    1126            0 :         *inside_cost += record_stmt_cost (body_cost_vec, ncopies, vector_load,
    1127              :                                           stmt_info, slp_node, vectype,
    1128              :                                           0, vect_body);
    1129            0 :         *inside_cost += record_stmt_cost (body_cost_vec, ncopies, vec_perm,
    1130              :                                           stmt_info, slp_node, vectype,
    1131              :                                           0, vect_body);
    1132              : 
    1133            0 :         if (dump_enabled_p ())
    1134            0 :           dump_printf_loc (MSG_NOTE, vect_location,
    1135              :                            "vect_model_load_cost: explicit realign optimized"
    1136              :                            "\n");
    1137              : 
    1138              :         break;
    1139              :       }
    1140              : 
    1141        60636 :     case dr_unaligned_unsupported:
    1142        60636 :       {
    1143        60636 :         *inside_cost = VECT_MAX_COST;
    1144              : 
    1145        60636 :         if (dump_enabled_p ())
    1146          135 :           dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    1147              :                            "vect_model_load_cost: unsupported access.\n");
    1148              :         break;
    1149              :       }
    1150              : 
    1151            0 :     default:
    1152            0 :       gcc_unreachable ();
    1153              :     }
    1154      1023784 : }
    1155              : 
    1156              : /* Insert the new stmt NEW_STMT at *GSI or at the appropriate place in
    1157              :    the loop preheader for the vectorized stmt STMT_VINFO.  */
    1158              : 
    1159              : static void
    1160         7120 : vect_init_vector_1 (vec_info *vinfo, stmt_vec_info stmt_vinfo, gimple *new_stmt,
    1161              :                     gimple_stmt_iterator *gsi)
    1162              : {
    1163         7120 :   if (gsi)
    1164         3582 :     vect_finish_stmt_generation (vinfo, stmt_vinfo, new_stmt, gsi);
    1165              :   else
    1166         3538 :     vinfo->insert_on_entry (stmt_vinfo, new_stmt);
    1167              : 
    1168         7120 :   if (dump_enabled_p ())
    1169         1866 :     dump_printf_loc (MSG_NOTE, vect_location,
    1170              :                      "created new init_stmt: %G", new_stmt);
    1171         7120 : }
    1172              : 
    1173              : /* Function vect_init_vector.
    1174              : 
    1175              :    Insert a new stmt (INIT_STMT) that initializes a new variable of type
    1176              :    TYPE with the value VAL.  If TYPE is a vector type and VAL does not have
    1177              :    vector type a vector with all elements equal to VAL is created first.
    1178              :    Place the initialization at GSI if it is not NULL.  Otherwise, place the
    1179              :    initialization at the loop preheader.
    1180              :    Return the DEF of INIT_STMT.
    1181              :    It will be used in the vectorization of STMT_INFO.  */
    1182              : 
    1183              : tree
    1184         5123 : vect_init_vector (vec_info *vinfo, stmt_vec_info stmt_info, tree val, tree type,
    1185              :                   gimple_stmt_iterator *gsi)
    1186              : {
    1187         5123 :   gimple *init_stmt;
    1188         5123 :   tree new_temp;
    1189              : 
    1190              :   /* We abuse this function to push sth to a SSA name with initial 'val'.  */
    1191         5123 :   if (! useless_type_conversion_p (type, TREE_TYPE (val)))
    1192              :     {
    1193         1318 :       gcc_assert (VECTOR_TYPE_P (type));
    1194         1318 :       if (! types_compatible_p (TREE_TYPE (type), TREE_TYPE (val)))
    1195              :         {
    1196              :           /* Scalar boolean value should be transformed into
    1197              :              all zeros or all ones value before building a vector.  */
    1198           11 :           if (VECTOR_BOOLEAN_TYPE_P (type))
    1199              :             {
    1200            3 :               tree true_val = build_all_ones_cst (TREE_TYPE (type));
    1201            3 :               tree false_val = build_zero_cst (TREE_TYPE (type));
    1202              : 
    1203            3 :               if (CONSTANT_CLASS_P (val))
    1204            0 :                 val = integer_zerop (val) ? false_val : true_val;
    1205              :               else
    1206              :                 {
    1207            3 :                   new_temp = make_ssa_name (TREE_TYPE (type));
    1208            3 :                   init_stmt = gimple_build_assign (new_temp, COND_EXPR,
    1209              :                                                    val, true_val, false_val);
    1210            3 :                   vect_init_vector_1 (vinfo, stmt_info, init_stmt, gsi);
    1211            3 :                   val = new_temp;
    1212              :                 }
    1213              :             }
    1214              :           else
    1215              :             {
    1216            8 :               gimple_seq stmts = NULL;
    1217            8 :               if (! INTEGRAL_TYPE_P (TREE_TYPE (val)))
    1218            8 :                 val = gimple_build (&stmts, VIEW_CONVERT_EXPR,
    1219            8 :                                     TREE_TYPE (type), val);
    1220              :               else
    1221              :                 /* ???  Condition vectorization expects us to do
    1222              :                    promotion of invariant/external defs.  */
    1223            0 :                 val = gimple_convert (&stmts, TREE_TYPE (type), val);
    1224           16 :               for (gimple_stmt_iterator gsi2 = gsi_start (stmts);
    1225           16 :                    !gsi_end_p (gsi2); )
    1226              :                 {
    1227            8 :                   init_stmt = gsi_stmt (gsi2);
    1228            8 :                   gsi_remove (&gsi2, false);
    1229            8 :                   vect_init_vector_1 (vinfo, stmt_info, init_stmt, gsi);
    1230              :                 }
    1231              :             }
    1232              :         }
    1233         1318 :       val = build_vector_from_val (type, val);
    1234              :     }
    1235              : 
    1236         5123 :   new_temp = vect_get_new_ssa_name (type, vect_simple_var, "cst_");
    1237         5123 :   init_stmt = gimple_build_assign (new_temp, val);
    1238         5123 :   vect_init_vector_1 (vinfo, stmt_info, init_stmt, gsi);
    1239         5123 :   return new_temp;
    1240              : }
    1241              : 
    1242              : 
    1243              : /* Get vectorized definitions for OP0 and OP1.  */
    1244              : 
    1245              : void
    1246       200361 : vect_get_vec_defs (vec_info *, slp_tree slp_node,
    1247              :                    bool op0, vec<tree> *vec_oprnds0,
    1248              :                    bool op1, vec<tree> *vec_oprnds1,
    1249              :                    bool op2, vec<tree> *vec_oprnds2,
    1250              :                    bool op3, vec<tree> *vec_oprnds3)
    1251              : {
    1252       200361 :   if (op0)
    1253       198722 :     vect_get_slp_defs (SLP_TREE_CHILDREN (slp_node)[0], vec_oprnds0);
    1254       200361 :   if (op1)
    1255       147294 :     vect_get_slp_defs (SLP_TREE_CHILDREN (slp_node)[1], vec_oprnds1);
    1256       200361 :   if (op2)
    1257         9787 :     vect_get_slp_defs (SLP_TREE_CHILDREN (slp_node)[2], vec_oprnds2);
    1258       200361 :   if (op3)
    1259            0 :     vect_get_slp_defs (SLP_TREE_CHILDREN (slp_node)[3], vec_oprnds3);
    1260       200361 : }
    1261              : 
    1262              : /* Helper function called by vect_finish_replace_stmt and
    1263              :    vect_finish_stmt_generation.  Set the location of the new
    1264              :    statement and create and return a stmt_vec_info for it.  */
    1265              : 
    1266              : static void
    1267      1458277 : vect_finish_stmt_generation_1 (vec_info *,
    1268              :                                stmt_vec_info stmt_info, gimple *vec_stmt)
    1269              : {
    1270      1458277 :   if (dump_enabled_p ())
    1271       152894 :     dump_printf_loc (MSG_NOTE, vect_location, "add new stmt: %G", vec_stmt);
    1272              : 
    1273      1458277 :   if (stmt_info)
    1274              :     {
    1275      1429493 :       gimple_set_location (vec_stmt, gimple_location (stmt_info->stmt));
    1276              : 
    1277              :       /* While EH edges will generally prevent vectorization, stmt might
    1278              :          e.g. be in a must-not-throw region.  Ensure newly created stmts
    1279              :          that could throw are part of the same region.  */
    1280      1429493 :       int lp_nr = lookup_stmt_eh_lp (stmt_info->stmt);
    1281      1429493 :       if (lp_nr != 0 && stmt_could_throw_p (cfun, vec_stmt))
    1282           48 :         add_stmt_to_eh_lp (vec_stmt, lp_nr);
    1283              :     }
    1284              :   else
    1285        28784 :     gcc_assert (!stmt_could_throw_p (cfun, vec_stmt));
    1286      1458277 : }
    1287              : 
    1288              : /* Replace the scalar statement STMT_INFO with a new vector statement VEC_STMT,
    1289              :    which sets the same scalar result as STMT_INFO did.  Create and return a
    1290              :    stmt_vec_info for VEC_STMT.  */
    1291              : 
    1292              : void
    1293         1021 : vect_finish_replace_stmt (vec_info *vinfo,
    1294              :                           stmt_vec_info stmt_info, gimple *vec_stmt)
    1295              : {
    1296         1021 :   gimple *scalar_stmt = vect_orig_stmt (stmt_info)->stmt;
    1297         1021 :   gcc_assert (gimple_get_lhs (scalar_stmt) == gimple_get_lhs (vec_stmt));
    1298              : 
    1299         1021 :   gimple_stmt_iterator gsi = gsi_for_stmt (scalar_stmt);
    1300         1021 :   gsi_replace (&gsi, vec_stmt, true);
    1301              : 
    1302         1021 :   vect_finish_stmt_generation_1 (vinfo, stmt_info, vec_stmt);
    1303         1021 : }
    1304              : 
    1305              : /* Add VEC_STMT to the vectorized implementation of STMT_INFO and insert it
    1306              :    before *GSI.  Create and return a stmt_vec_info for VEC_STMT.  */
    1307              : 
    1308              : void
    1309      1457256 : vect_finish_stmt_generation (vec_info *vinfo,
    1310              :                              stmt_vec_info stmt_info, gimple *vec_stmt,
    1311              :                              gimple_stmt_iterator *gsi)
    1312              : {
    1313      1457256 :   gcc_assert (!stmt_info || gimple_code (stmt_info->stmt) != GIMPLE_LABEL);
    1314              : 
    1315      1457256 :   if (!gsi_end_p (*gsi)
    1316      2913526 :       && gimple_has_mem_ops (vec_stmt))
    1317              :     {
    1318      1456270 :       gimple *at_stmt = gsi_stmt (*gsi);
    1319      1456270 :       tree vuse = gimple_vuse (at_stmt);
    1320      1450170 :       if (vuse && TREE_CODE (vuse) == SSA_NAME)
    1321              :         {
    1322      1297783 :           tree vdef = gimple_vdef (at_stmt);
    1323      1297783 :           gimple_set_vuse (vec_stmt, gimple_vuse (at_stmt));
    1324      1297783 :           gimple_set_modified (vec_stmt, true);
    1325              :           /* If we have an SSA vuse and insert a store, update virtual
    1326              :              SSA form to avoid triggering the renamer.  Do so only
    1327              :              if we can easily see all uses - which is what almost always
    1328              :              happens with the way vectorized stmts are inserted.  */
    1329       767592 :           if ((vdef && TREE_CODE (vdef) == SSA_NAME)
    1330      2065339 :               && ((is_gimple_assign (vec_stmt)
    1331       766668 :                    && !is_gimple_reg (gimple_assign_lhs (vec_stmt)))
    1332        66211 :                   || (is_gimple_call (vec_stmt)
    1333          888 :                       && (!(gimple_call_flags (vec_stmt)
    1334          888 :                             & (ECF_CONST|ECF_PURE|ECF_NOVOPS))
    1335            3 :                           || (gimple_call_lhs (vec_stmt)
    1336            3 :                               && !is_gimple_reg (gimple_call_lhs (vec_stmt)))))))
    1337              :             {
    1338       702230 :               tree new_vdef = copy_ssa_name (vuse, vec_stmt);
    1339       702230 :               gimple_set_vdef (vec_stmt, new_vdef);
    1340       702230 :               SET_USE (gimple_vuse_op (at_stmt), new_vdef);
    1341              :             }
    1342              :         }
    1343              :     }
    1344      1457256 :   gsi_insert_before (gsi, vec_stmt, GSI_SAME_STMT);
    1345      1457256 :   vect_finish_stmt_generation_1 (vinfo, stmt_info, vec_stmt);
    1346      1457256 : }
    1347              : 
    1348              : /* We want to vectorize a call to combined function CFN with function
    1349              :    decl FNDECL, using VECTYPE_OUT as the type of the output and VECTYPE_IN
    1350              :    as the types of all inputs.  Check whether this is possible using
    1351              :    an internal function, returning its code if so or IFN_LAST if not.  */
    1352              : 
    1353              : static internal_fn
    1354        19298 : vectorizable_internal_function (combined_fn cfn, tree fndecl,
    1355              :                                 tree vectype_out, tree vectype_in)
    1356              : {
    1357        19298 :   internal_fn ifn;
    1358        19298 :   if (internal_fn_p (cfn))
    1359        15327 :     ifn = as_internal_fn (cfn);
    1360              :   else
    1361         3971 :     ifn = associated_internal_fn (fndecl);
    1362        19298 :   if (ifn != IFN_LAST && direct_internal_fn_p (ifn))
    1363              :     {
    1364        15176 :       const direct_internal_fn_info &info = direct_internal_fn (ifn);
    1365        15176 :       if (info.vectorizable)
    1366              :         {
    1367        15176 :           bool same_size_p = TYPE_SIZE (vectype_in) == TYPE_SIZE (vectype_out);
    1368        15176 :           tree type0 = (info.type0 < 0 ? vectype_out : vectype_in);
    1369        15176 :           tree type1 = (info.type1 < 0 ? vectype_out : vectype_in);
    1370              : 
    1371              :           /* The type size of both the vectype_in and vectype_out should be
    1372              :              exactly the same when vectype_out isn't participating the optab.
    1373              :              While there is no restriction for type size when vectype_out
    1374              :              is part of the optab query.  */
    1375        15176 :           if (type0 != vectype_out && type1 != vectype_out && !same_size_p)
    1376        19298 :             return IFN_LAST;
    1377              : 
    1378        15139 :           if (direct_internal_fn_supported_p (ifn, tree_pair (type0, type1),
    1379              :                                               OPTIMIZE_FOR_SPEED))
    1380         8379 :             return ifn;
    1381              :         }
    1382              :     }
    1383              :   return IFN_LAST;
    1384              : }
    1385              : 
    1386              : 
    1387              : static tree permute_vec_elements (vec_info *, tree, tree, tree, stmt_vec_info,
    1388              :                                   gimple_stmt_iterator *);
    1389              : 
    1390              : enum vect_load_store_partial_vector_style {
    1391              :   vect_load_store_partial_vectors_none,
    1392              :   vect_load_store_partial_vectors_mask,
    1393              :   vect_load_store_partial_vectors_len
    1394              : };
    1395              : 
    1396              : /* If target supports vector load/store (determined by IS_LOAD) with length for
    1397              :    VECTYPE, return VECT_LOAD_STORE_PARTIAL_VECTORS_LEN; otherwise, if it
    1398              :    supports vector masked load/store for mode for VECTYPE, return
    1399              :    VECT_LOAD_STORE_PARTIAL_VECTORS_MASK; otherwise, return
    1400              :    VECT_LOAD_STORE_PARTIAL_VECTORS_NONE.  If load/store with length or mask is
    1401              :    supported and ELSVALS is not null, store the possible else values in the
    1402              :    vector it points to.  Unless FACTOR is null, *FACTOR is set to the number of
    1403              :    separate subelements that each element of VECTYPE should be split into.
    1404              :    (This is always 1 except in the case of VECT_LOAD_STORE_PARTIAL_VECTORS_LEN
    1405              :    when the machine mode of VECTYPE can only be supported by using a length in
    1406              :    bytes instead of a length in lanes.)
    1407              :  */
    1408              : static enum vect_load_store_partial_vector_style
    1409       278289 : vect_get_load_store_partial_vector_style (tree vectype, bool is_load,
    1410              :                                           unsigned *factor = nullptr,
    1411              :                                           vec<int> *elsvals = nullptr)
    1412              : {
    1413       278289 :   machine_mode vecmode = TYPE_MODE (vectype);
    1414              : 
    1415              :   /* TYPE_MODE tries to map vector modes that are unsupported by the target to
    1416              :      same-sized scalar modes, so reject scalar modes here.  */
    1417       278289 :   if (VECTOR_MODE_P (vecmode))
    1418              :     {
    1419       278289 :       machine_mode mask_mode, vmode;
    1420       278289 :       if (get_len_load_store_mode (vecmode, is_load, nullptr, elsvals)
    1421       278289 :             .exists (&vmode))
    1422              :         {
    1423            0 :           if (factor)
    1424            0 :             *factor = (vecmode == vmode) ? 1 : GET_MODE_UNIT_SIZE (vecmode);
    1425       278289 :           return vect_load_store_partial_vectors_len;
    1426              :         }
    1427              : 
    1428       278289 :       if (factor)
    1429       278289 :         *factor = 1;
    1430              : 
    1431       463787 :       if (targetm.vectorize.get_mask_mode (vecmode).exists (&mask_mode)
    1432       278289 :           && can_vec_mask_load_store_p (vecmode, mask_mode, is_load, NULL,
    1433              :                                         elsvals))
    1434        92791 :         return vect_load_store_partial_vectors_mask;
    1435              :     }
    1436              : 
    1437       185498 :   if (dump_enabled_p ())
    1438        15964 :     dump_printf_loc (MSG_NOTE, vect_location,
    1439              :                      "the target doesn't have the appropriate partial"
    1440              :                      " vector %s for vector data type %T.\n",
    1441              :                      is_load ? "load" : "store", vectype);
    1442              :   return vect_load_store_partial_vectors_none;
    1443              : }
    1444              : 
    1445              : /* Check whether a load or store statement in the loop described by
    1446              :    LOOP_VINFO is possible in a loop using partial vectors.  This is
    1447              :    testing whether the vectorizer pass has the appropriate support,
    1448              :    as well as whether the target does.
    1449              : 
    1450              :    VLS_TYPE says whether the statement is a load or store and VECTYPE
    1451              :    is the type of the vector being loaded or stored.  SLP_NODE is the SLP
    1452              :    node that contains the statement, or null if none.  MEMORY_ACCESS_TYPE
    1453              :    says how the load or store is going to be implemented and GROUP_SIZE
    1454              :    is the number of load or store statements in the containing group.
    1455              :    If the access is a gather load or scatter store, GS_INFO describes
    1456              :    its arguments.  If the load or store is conditional, SCALAR_MASK is the
    1457              :    condition under which it occurs.
    1458              : 
    1459              :    Return false if a loop using partial vectors is not supported, otherwise
    1460              :    record the required rgroup control types.
    1461              : 
    1462              :    If partial vectors can be used and ELSVALS is nonzero the supported
    1463              :    else values will be added to the vector ELSVALS points to.  */
    1464              : 
    1465              : static bool
    1466       309264 : check_load_store_for_partial_vectors (loop_vec_info loop_vinfo, tree vectype,
    1467              :                                       slp_tree slp_node,
    1468              :                                       vec_load_store_type vls_type,
    1469              :                                       int group_size,
    1470              :                                       vect_load_store_data *ls,
    1471              :                                       slp_tree mask_node,
    1472              :                                       vec<int> *elsvals = nullptr)
    1473              : {
    1474       309264 :   vect_memory_access_type memory_access_type = ls->memory_access_type;
    1475              : 
    1476              :   /* Invariant loads need no special support.  */
    1477       309264 :   if (memory_access_type == VMAT_INVARIANT)
    1478              :     return true;
    1479              : 
    1480              :   /* Figure whether the mask is uniform.  scalar_mask is used to
    1481              :      populate the scalar_cond_masked_set.  */
    1482       308039 :   tree scalar_mask = NULL_TREE;
    1483       308039 :   if (mask_node)
    1484         5160 :     for (unsigned i = 0; i < SLP_TREE_LANES (mask_node); ++i)
    1485              :       {
    1486         2687 :         tree def = vect_get_slp_scalar_def (mask_node, i);
    1487         2687 :         if (!def
    1488         2687 :             || (scalar_mask && def != scalar_mask))
    1489              :           {
    1490              :             scalar_mask = NULL;
    1491              :             break;
    1492              :           }
    1493              :         else
    1494         2646 :           scalar_mask = def;
    1495              :       }
    1496              : 
    1497       308039 :   unsigned int nvectors = vect_get_num_copies (loop_vinfo, slp_node);
    1498       308039 :   machine_mode vecmode = TYPE_MODE (vectype);
    1499       308039 :   bool is_load = (vls_type == VLS_LOAD);
    1500       308039 :   if (memory_access_type == VMAT_LOAD_STORE_LANES)
    1501              :     {
    1502            0 :       nvectors /= group_size;
    1503            0 :       internal_fn ifn
    1504            0 :         = (is_load ? vect_load_lanes_supported (vectype, group_size, true,
    1505              :                                                 elsvals)
    1506            0 :                    : vect_store_lanes_supported (vectype, group_size, true));
    1507            0 :       if (ifn == IFN_MASK_LEN_LOAD_LANES || ifn == IFN_MASK_LEN_STORE_LANES)
    1508            0 :         vect_record_len (loop_vinfo, nvectors, vectype, 1);
    1509            0 :       else if (ifn == IFN_MASK_LOAD_LANES || ifn == IFN_MASK_STORE_LANES)
    1510            0 :         vect_record_mask (loop_vinfo, nvectors, vectype, scalar_mask);
    1511              :       else
    1512              :         {
    1513            0 :           if (dump_enabled_p ())
    1514            0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    1515              :                              "can't operate on partial vectors because"
    1516              :                              " the target doesn't have an appropriate"
    1517              :                              " load/store-lanes instruction.\n");
    1518              :           return false;
    1519              :         }
    1520              :       return true;
    1521              :     }
    1522              : 
    1523       308039 :   if (mat_gather_scatter_p (memory_access_type))
    1524              :     {
    1525         1765 :       internal_fn ifn = (is_load
    1526         1765 :                          ? IFN_MASK_GATHER_LOAD
    1527              :                          : IFN_MASK_SCATTER_STORE);
    1528          374 :       internal_fn len_ifn = (is_load
    1529              :                              ? IFN_MASK_LEN_GATHER_LOAD
    1530              :                              : IFN_MASK_LEN_SCATTER_STORE);
    1531         1765 :       stmt_vec_info repr = SLP_TREE_REPRESENTATIVE (slp_node);
    1532         1765 :       tree off_vectype = (STMT_VINFO_GATHER_SCATTER_P (repr)
    1533         1765 :                           ? SLP_TREE_VECTYPE (SLP_TREE_CHILDREN (slp_node)[0])
    1534         1765 :                           : ls->strided_offset_vectype);
    1535         1765 :       tree memory_type = TREE_TYPE (DR_REF (STMT_VINFO_DR_INFO (repr)->dr));
    1536         1765 :       int scale = SLP_TREE_GS_SCALE (slp_node);
    1537              : 
    1538              :       /* The following "supported" checks just verify what we established in
    1539              :          get_load_store_type and don't try different offset types.
    1540              :          Therefore, off_vectype must be a supported offset type.  In case
    1541              :          we chose a different one use this instead.  */
    1542         1765 :       if (ls->supported_offset_vectype)
    1543            0 :         off_vectype = ls->supported_offset_vectype;
    1544              :       /* Same for scale.  */
    1545         1765 :       if (ls->supported_scale)
    1546            0 :         scale = ls->supported_scale;
    1547              : 
    1548         1765 :       if (internal_gather_scatter_fn_supported_p (len_ifn, vectype,
    1549              :                                                   memory_type,
    1550              :                                                   off_vectype, scale,
    1551              :                                                   elsvals))
    1552            0 :         vect_record_len (loop_vinfo, nvectors, vectype, 1);
    1553         1765 :       else if (internal_gather_scatter_fn_supported_p (ifn, vectype,
    1554              :                                                        memory_type,
    1555              :                                                        off_vectype, scale,
    1556              :                                                        elsvals)
    1557         1765 :                || memory_access_type == VMAT_GATHER_SCATTER_LEGACY)
    1558          565 :         vect_record_mask (loop_vinfo, nvectors, vectype, scalar_mask);
    1559              :       else
    1560              :         {
    1561         1200 :           if (dump_enabled_p ())
    1562          126 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    1563              :                              "can't operate on partial vectors because"
    1564              :                              " the target doesn't have an appropriate"
    1565              :                              " gather load or scatter store instruction.\n");
    1566              :           return false;
    1567              :         }
    1568              :       return true;
    1569              :     }
    1570              : 
    1571       306274 :   if (memory_access_type != VMAT_CONTIGUOUS)
    1572              :     {
    1573              :       /* Element X of the data must come from iteration i * VF + X of the
    1574              :          scalar loop.  We need more work to support other mappings.  */
    1575        27766 :       if (dump_enabled_p ())
    1576          756 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    1577              :                          "can't operate on partial vectors because an"
    1578              :                          " access isn't contiguous.\n");
    1579              :       return false;
    1580              :     }
    1581              : 
    1582       278508 :   if (!VECTOR_MODE_P (vecmode))
    1583              :     {
    1584            0 :       if (dump_enabled_p ())
    1585            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    1586              :                          "can't operate on partial vectors when emulating"
    1587              :                          " vector operations.\n");
    1588              :       return false;
    1589              :     }
    1590              : 
    1591       278508 :   poly_uint64 nunits = TYPE_VECTOR_SUBPARTS (vectype);
    1592       278508 :   poly_uint64 vf = LOOP_VINFO_VECT_FACTOR (loop_vinfo);
    1593              : 
    1594              :   /* For permuted SLP loads the group accessed in one vector iteration
    1595              :      might not fill a whole number of vectors, for example when the
    1596              :      load permutation duplicates elements.  The loop masks and lengths
    1597              :      are computed based on NVECTORS * NUNITS / VF scalars per iteration
    1598              :      which would then enable more elements than the scalar loop accesses.  */
    1599       278508 :   if (!constant_multiple_p (group_size * vf, nunits, &nvectors))
    1600              :     {
    1601          219 :       if (dump_enabled_p ())
    1602           75 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    1603              :                          "can't operate on partial vectors because the"
    1604              :                          " access does not cover a whole number of"
    1605              :                          " vectors.\n");
    1606              :       return false;
    1607              :     }
    1608              : 
    1609       278289 :   unsigned factor;
    1610       278289 :   vect_load_store_partial_vector_style partial_vector_style
    1611       278289 :     = vect_get_load_store_partial_vector_style (vectype, is_load, &factor,
    1612              :                                                 elsvals);
    1613              : 
    1614       278289 :   if (partial_vector_style == vect_load_store_partial_vectors_len)
    1615              :     {
    1616            0 :       vect_record_len (loop_vinfo, nvectors, vectype, factor);
    1617              :     }
    1618       278289 :   else if (partial_vector_style == vect_load_store_partial_vectors_mask)
    1619              :     {
    1620        92791 :       vect_record_mask (loop_vinfo, nvectors, vectype, scalar_mask);
    1621              :     }
    1622              :   else
    1623              :     {
    1624       185498 :       gcc_assert (partial_vector_style == vect_load_store_partial_vectors_none);
    1625       185498 :       if (dump_enabled_p ())
    1626        13044 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    1627              :                          "can't operate on partial vectors because the"
    1628              :                          " target doesn't have the appropriate partial"
    1629              :                          " vectorization load or store.\n");
    1630              :       return false;
    1631              :     }
    1632              :   return true;
    1633              : }
    1634              : 
    1635              : /* Return the mask input to a masked load or store.  VEC_MASK is the vectorized
    1636              :    form of the scalar mask condition and LOOP_OR_TAIL_MASK, if nonnull, is the
    1637              :    mask that needs to be applied because partial vectors are used in the loop or
    1638              :    SLP region represented by VINFO.  Return VEC_MASK if LOOP_OR_TAIL_MASK is
    1639              :    null or if VEC_MASK is already masked, otherwise return VEC_MASK &
    1640              :    LOOP_OR_TAIL_MASK.
    1641              : 
    1642              :    MASK_TYPE is the type of both masks.  If new statements are needed,
    1643              :    insert them before GSI.  */
    1644              : 
    1645              : tree
    1646         1697 : prepare_vec_mask (vec_info *vinfo, tree mask_type, tree loop_or_tail_mask,
    1647              :                   tree vec_mask, gimple_stmt_iterator *gsi)
    1648              : {
    1649         1697 :   gcc_assert (useless_type_conversion_p (mask_type, TREE_TYPE (vec_mask)));
    1650         1697 :   if (!loop_or_tail_mask)
    1651              :     return vec_mask;
    1652              : 
    1653          145 :   gcc_assert (TREE_TYPE (loop_or_tail_mask) == mask_type);
    1654              : 
    1655          145 :   if (vinfo->vec_cond_masked_set.contains ({ vec_mask, loop_or_tail_mask }))
    1656              :     return vec_mask;
    1657              : 
    1658          145 :   tree and_res = make_temp_ssa_name (mask_type, NULL, "vec_mask_and");
    1659          145 :   gimple *and_stmt
    1660          145 :     = gimple_build_assign (and_res, BIT_AND_EXPR, vec_mask, loop_or_tail_mask);
    1661              : 
    1662          145 :   gsi_insert_before (gsi, and_stmt, GSI_SAME_STMT);
    1663          145 :   return and_res;
    1664              : }
    1665              : 
    1666              : /* Determine whether we can use a gather load or scatter store to vectorize
    1667              :    strided load or store STMT_INFO by truncating the current offset to a
    1668              :    smaller width.  We need to be able to construct an offset vector:
    1669              : 
    1670              :      { 0, X, X*2, X*3, ... }
    1671              : 
    1672              :    without loss of precision, where X is STMT_INFO's DR_STEP.
    1673              : 
    1674              :    Return true if this is possible, describing the gather load or scatter
    1675              :    store in GS_INFO.  MASKED_P is true if the load or store is conditional.
    1676              : 
    1677              :    If we can use gather/scatter and ELSVALS is nonzero the supported
    1678              :    else values will be stored in the vector ELSVALS points to.  */
    1679              : 
    1680              : static bool
    1681        56933 : vect_truncate_gather_scatter_offset (stmt_vec_info stmt_info, tree vectype,
    1682              :                                      loop_vec_info loop_vinfo, bool masked_p,
    1683              :                                      gather_scatter_info *gs_info,
    1684              :                                      vec<int> *elsvals)
    1685              : {
    1686        56933 :   dr_vec_info *dr_info = STMT_VINFO_DR_INFO (stmt_info);
    1687        56933 :   data_reference *dr = dr_info->dr;
    1688        56933 :   tree step = DR_STEP (dr);
    1689        56933 :   if (TREE_CODE (step) != INTEGER_CST)
    1690              :     {
    1691              :       /* ??? Perhaps we could use range information here?  */
    1692        30022 :       if (dump_enabled_p ())
    1693          203 :         dump_printf_loc (MSG_NOTE, vect_location,
    1694              :                          "cannot truncate variable step.\n");
    1695              :       return false;
    1696              :     }
    1697              : 
    1698              :   /* Get the number of bits in an element.  */
    1699        26911 :   scalar_mode element_mode = SCALAR_TYPE_MODE (TREE_TYPE (vectype));
    1700        26911 :   unsigned int element_bits = GET_MODE_BITSIZE (element_mode);
    1701              : 
    1702              :   /* Set COUNT to the upper limit on the number of elements - 1.
    1703              :      Start with the maximum vectorization factor.  */
    1704        26911 :   unsigned HOST_WIDE_INT count = vect_max_vf (loop_vinfo) - 1;
    1705              : 
    1706              :   /* Try lowering COUNT to the number of scalar latch iterations.  Peeling
    1707              :      for alignment by masking shifts the active lanes up, and we cannot tell
    1708              :      yet whether peeling will be done by masking, or whether masks will be
    1709              :      needed at all, so be conservative and do not lower COUNT when peeling
    1710              :      for alignment.  */
    1711        26911 :   class loop *loop = LOOP_VINFO_LOOP (loop_vinfo);
    1712        26911 :   widest_int max_iters;
    1713        26911 :   if (!LOOP_VINFO_PEELING_FOR_ALIGNMENT (loop_vinfo)
    1714        26872 :       && max_loop_iterations (loop, &max_iters)
    1715        53705 :       && max_iters < count)
    1716         2075 :     count = max_iters.to_shwi ();
    1717              : 
    1718              :   /* Try scales of 1 and the element size.  */
    1719        26911 :   unsigned int scales[] = { 1, vect_get_scalar_dr_size (dr_info) };
    1720        26911 :   wi::overflow_type overflow = wi::OVF_NONE;
    1721        80733 :   for (int i = 0; i < 2; ++i)
    1722              :     {
    1723        53822 :       unsigned int scale = scales[i];
    1724        53822 :       widest_int factor;
    1725        53822 :       if (!wi::multiple_of_p (wi::to_widest (step), scale, SIGNED, &factor))
    1726            0 :         continue;
    1727              : 
    1728              :       /* Determine the minimum precision of (COUNT - 1) * STEP / SCALE.  */
    1729        53822 :       widest_int range = wi::mul (count, factor, SIGNED, &overflow);
    1730        53822 :       if (overflow)
    1731            0 :         continue;
    1732        53822 :       signop sign = range >= 0 ? UNSIGNED : SIGNED;
    1733        53822 :       unsigned int min_offset_bits = wi::min_precision (range, sign);
    1734              : 
    1735              :       /* Find the narrowest viable offset type.  */
    1736        53822 :       unsigned int offset_bits = 1U << ceil_log2 (min_offset_bits);
    1737        53822 :       tree offset_type = build_nonstandard_integer_type (offset_bits,
    1738              :                                                          sign == UNSIGNED);
    1739              : 
    1740              :       /* See whether the target supports the operation with an offset
    1741              :          no narrower than OFFSET_TYPE.  */
    1742        53822 :       tree memory_type = TREE_TYPE (DR_REF (dr));
    1743        53822 :       tree tmp_offset_vectype;
    1744        53822 :       int tmp_scale;
    1745        53822 :       if (!vect_gather_scatter_fn_p (loop_vinfo, DR_IS_READ (dr), masked_p,
    1746              :                                      vectype, memory_type, offset_type,
    1747              :                                      scale, &tmp_scale,
    1748              :                                      &gs_info->ifn, &gs_info->offset_vectype,
    1749              :                                      &tmp_offset_vectype, elsvals)
    1750        53822 :           || gs_info->ifn == IFN_LAST)
    1751        53822 :         continue;
    1752              : 
    1753            0 :       gs_info->decl = NULL_TREE;
    1754              :       /* Logically the sum of DR_BASE_ADDRESS, DR_INIT and DR_OFFSET,
    1755              :          but we don't need to store that here.  */
    1756            0 :       gs_info->base = NULL_TREE;
    1757            0 :       gs_info->alias_ptr = build_int_cst
    1758            0 :         (reference_alias_ptr_type (DR_REF (dr)),
    1759            0 :          get_object_alignment (DR_REF (dr)));
    1760            0 :       gs_info->element_type = TREE_TYPE (vectype);
    1761            0 :       gs_info->offset = fold_convert (offset_type, step);
    1762            0 :       gs_info->scale = scale;
    1763            0 :       gs_info->memory_type = memory_type;
    1764            0 :       return true;
    1765        53822 :     }
    1766              : 
    1767        26911 :   if (overflow && dump_enabled_p ())
    1768            0 :     dump_printf_loc (MSG_NOTE, vect_location,
    1769              :                      "truncating gather/scatter offset to %d bits"
    1770              :                      " might change its value.\n", element_bits);
    1771              : 
    1772              :   return false;
    1773        56933 : }
    1774              : 
    1775              : /* Return true if we can use gather/scatter or strided internal functions
    1776              :    to vectorize STMT_INFO, which is a grouped or strided load or store
    1777              :    with multiple lanes and will be implemented by a type-punned access
    1778              :    of a vector with element size that matches the number of lanes.
    1779              : 
    1780              :    MASKED_P is true if load or store is conditional.
    1781              :    When returning true, fill in GS_INFO with the information required to
    1782              :    perform the operation.  Also, store the punning type in PUNNED_VECTYPE.
    1783              : 
    1784              :    If successful and ELSVALS is nonzero the supported
    1785              :    else values will be stored in the vector ELSVALS points to.  */
    1786              : 
    1787              : static bool
    1788         4632 : vect_use_grouped_gather (dr_vec_info *dr_info, tree vectype,
    1789              :                          loop_vec_info loop_vinfo, bool masked_p,
    1790              :                          unsigned int nelts,
    1791              :                          gather_scatter_info *info, vec<int> *elsvals,
    1792              :                          tree *pun_vectype)
    1793              : {
    1794         4632 :   data_reference *dr = dr_info->dr;
    1795              : 
    1796              :   /* TODO: We can support nelts > BITS_PER_UNIT or non-power-of-two by
    1797              :      multiple gathers/scatter.  */
    1798         4632 :   if (nelts > BITS_PER_UNIT || !pow2p_hwi (nelts))
    1799              :     return false;
    1800              : 
    1801              :   /* Pun the vectype with one of the same size but an element spanning
    1802              :      NELTS elements of VECTYPE.
    1803              :      The punned type of a V16QI with NELTS = 4 would be V4SI.
    1804              :      */
    1805         4011 :   tree tmp;
    1806         4011 :   unsigned int pieces;
    1807         4011 :   if (!can_div_trunc_p (TYPE_VECTOR_SUBPARTS (vectype), nelts, &pieces)
    1808         4011 :       || pieces <= 1)
    1809         2002 :     return false;
    1810              : 
    1811         2009 :   *pun_vectype = vector_vector_composition_type (vectype, pieces, &tmp, true);
    1812              : 
    1813         2009 :   if (!*pun_vectype || !VECTOR_TYPE_P (*pun_vectype))
    1814              :     return false;
    1815              : 
    1816         1863 :   internal_fn ifn;
    1817         1863 :   tree offset_vectype = *pun_vectype;
    1818              : 
    1819         1260 :   internal_fn strided_ifn = DR_IS_READ (dr)
    1820         1863 :     ? IFN_MASK_LEN_STRIDED_LOAD : IFN_MASK_LEN_STRIDED_STORE;
    1821              : 
    1822              :   /* Check if we have a gather/scatter with the new type.  We're just trying
    1823              :      with the type itself as offset for now.  If not, check if we have a
    1824              :      strided load/store.  These have fewer constraints (for example no offset
    1825              :      type must exist) so it is possible that even though a gather/scatter is
    1826              :      not available we still have a strided load/store.  */
    1827         1863 :   bool ok = false;
    1828         1863 :   tree tmp_vectype;
    1829         1863 :   int tmp_scale;
    1830         1863 :   if (vect_gather_scatter_fn_p
    1831         1863 :       (loop_vinfo, DR_IS_READ (dr), masked_p, *pun_vectype,
    1832         1863 :        TREE_TYPE (*pun_vectype), *pun_vectype, 1, &tmp_scale, &ifn,
    1833              :        &offset_vectype, &tmp_vectype, elsvals))
    1834              :     ok = true;
    1835         1863 :   else if (internal_strided_fn_supported_p (strided_ifn, *pun_vectype,
    1836              :                                             elsvals))
    1837              :     {
    1838              :       /* Use gather/scatter IFNs, vect_get_strided_load_store_ops
    1839              :          will switch back to the strided variants.  */
    1840            0 :       ifn = DR_IS_READ (dr) ? IFN_MASK_LEN_GATHER_LOAD :
    1841              :         IFN_MASK_LEN_SCATTER_STORE;
    1842            0 :       ok = true;
    1843              :     }
    1844              : 
    1845            0 :   if (ok)
    1846              :     {
    1847            0 :       info->ifn = ifn;
    1848            0 :       info->decl = NULL_TREE;
    1849            0 :       info->base = dr->ref;
    1850            0 :       info->alias_ptr = build_int_cst
    1851            0 :         (reference_alias_ptr_type (DR_REF (dr)),
    1852            0 :          get_object_alignment (DR_REF (dr)));
    1853            0 :       info->element_type = TREE_TYPE (*pun_vectype);
    1854            0 :       info->offset_vectype = offset_vectype;
    1855              :       /* No need to set the offset, vect_get_strided_load_store_ops
    1856              :          will do that.  */
    1857            0 :       info->scale = 1;
    1858            0 :       info->memory_type = TREE_TYPE (DR_REF (dr));
    1859            0 :       return true;
    1860              :     }
    1861              : 
    1862              :   return false;
    1863              : }
    1864              : 
    1865              : 
    1866              : /* Return true if we can use gather/scatter internal functions to
    1867              :    vectorize STMT_INFO, which is a grouped or strided load or store.
    1868              :    MASKED_P is true if load or store is conditional.  When returning
    1869              :    true, fill in GS_INFO with the information required to perform the
    1870              :    operation.
    1871              : 
    1872              :    If we can use gather/scatter and ELSVALS is nonzero the supported
    1873              :    else values will be stored in the vector ELSVALS points to.  */
    1874              : 
    1875              : static bool
    1876        56933 : vect_use_strided_gather_scatters_p (stmt_vec_info stmt_info, tree vectype,
    1877              :                                     loop_vec_info loop_vinfo, bool masked_p,
    1878              :                                     gather_scatter_info *gs_info,
    1879              :                                     vec<int> *elsvals,
    1880              :                                     unsigned int group_size,
    1881              :                                     bool single_element_p)
    1882              : {
    1883        56933 :   if (!vect_check_gather_scatter (stmt_info, vectype,
    1884              :                                   loop_vinfo, gs_info, elsvals)
    1885        56933 :       || gs_info->ifn == IFN_LAST)
    1886              :     {
    1887        56933 :       if (!vect_truncate_gather_scatter_offset (stmt_info, vectype, loop_vinfo,
    1888              :                                                 masked_p, gs_info, elsvals))
    1889              :         return false;
    1890              :     }
    1891              : 
    1892            0 :   if (!single_element_p
    1893            0 :       && !targetm.vectorize.prefer_gather_scatter (TYPE_MODE (vectype),
    1894              :                                                    gs_info->scale,
    1895              :                                                    group_size))
    1896              :     return false;
    1897              : 
    1898            0 :   if (dump_enabled_p ())
    1899            0 :     dump_printf_loc (MSG_NOTE, vect_location,
    1900              :                      "using gather/scatter for strided/grouped access,"
    1901              :                      " scale = %d\n", gs_info->scale);
    1902              : 
    1903              :   return true;
    1904              : }
    1905              : 
    1906              : /* STMT_INFO is a non-strided load or store, meaning that it accesses
    1907              :    elements with a known constant step.  Return -1 if that step
    1908              :    is negative, 0 if it is zero, and 1 if it is greater than zero.  */
    1909              : 
    1910              : int
    1911      1528364 : compare_step_with_zero (vec_info *vinfo, stmt_vec_info stmt_info)
    1912              : {
    1913      1528364 :   dr_vec_info *dr_info = STMT_VINFO_DR_INFO (stmt_info);
    1914      1528364 :   return tree_int_cst_compare (vect_dr_behavior (vinfo, dr_info)->step,
    1915      1528364 :                                size_zero_node);
    1916              : }
    1917              : 
    1918              : /* If the target supports a permute mask that reverses the elements in
    1919              :    a vector of type VECTYPE, return that mask, otherwise return null.  */
    1920              : 
    1921              : tree
    1922        14073 : perm_mask_for_reverse (tree vectype)
    1923              : {
    1924        14073 :   poly_uint64 nunits = TYPE_VECTOR_SUBPARTS (vectype);
    1925              : 
    1926              :   /* The encoding has a single stepped pattern.  */
    1927        14073 :   vec_perm_builder sel (nunits, 1, 3);
    1928        70365 :   for (int i = 0; i < 3; ++i)
    1929        42219 :     sel.quick_push (nunits - 1 - i);
    1930              : 
    1931        14073 :   vec_perm_indices indices (sel, 1, nunits);
    1932        14073 :   if (!can_vec_perm_const_p (TYPE_MODE (vectype), TYPE_MODE (vectype),
    1933              :                              indices))
    1934              :     return NULL_TREE;
    1935        12835 :   return vect_gen_perm_mask_checked (vectype, indices);
    1936        14073 : }
    1937              : 
    1938              : /* A subroutine of get_load_store_type, with a subset of the same
    1939              :    arguments.  Handle the case where STMT_INFO is a load or store that
    1940              :    accesses consecutive elements with a negative step.  Sets *POFFSET
    1941              :    to the offset to be applied to the DR for the first access.  */
    1942              : 
    1943              : static vect_memory_access_type
    1944         8102 : get_negative_load_store_type (vec_info *vinfo,
    1945              :                               stmt_vec_info stmt_info, tree vectype,
    1946              :                               vec_load_store_type vls_type,
    1947              :                               unsigned int ncopies, poly_int64 *poffset)
    1948              : {
    1949         8102 :   dr_vec_info *dr_info = STMT_VINFO_DR_INFO (stmt_info);
    1950         8102 :   dr_alignment_support alignment_support_scheme;
    1951              : 
    1952         8102 :   if (ncopies > 1)
    1953              :     {
    1954            0 :       if (dump_enabled_p ())
    1955            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    1956              :                          "multiple types with negative step.\n");
    1957              :       return VMAT_ELEMENTWISE;
    1958              :     }
    1959              : 
    1960              :   /* For backward running DRs the first access in vectype actually is
    1961              :      N-1 elements before the address of the DR.  */
    1962         8102 :   *poffset = ((-TYPE_VECTOR_SUBPARTS (vectype) + 1)
    1963         8102 :               * TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (vectype))));
    1964              : 
    1965              :   /* Check the whole speculative read window, rather than just the first
    1966              :      vector load.  POFFSET still describes that individual load.  */
    1967         8102 :   poly_int64 align_offset
    1968         8102 :     = vect_get_misalign_offset (true, vectype, stmt_info,
    1969              :                                dyn_cast <loop_vec_info> (vinfo));
    1970         8102 :   int misalignment = dr_misalignment (dr_info, vectype, align_offset);
    1971         8102 :   alignment_support_scheme
    1972         8102 :     = vect_supportable_dr_alignment (vinfo, dr_info, vectype, misalignment);
    1973         8102 :   if (alignment_support_scheme != dr_aligned
    1974         8102 :       && alignment_support_scheme != dr_unaligned_supported)
    1975              :     {
    1976            0 :       if (dump_enabled_p ())
    1977            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    1978              :                          "negative step but alignment required.\n");
    1979            0 :       *poffset = 0;
    1980            0 :       return VMAT_ELEMENTWISE;
    1981              :     }
    1982              : 
    1983         8102 :   if (vls_type == VLS_STORE_INVARIANT)
    1984              :     {
    1985         1084 :       if (dump_enabled_p ())
    1986           21 :         dump_printf_loc (MSG_NOTE, vect_location,
    1987              :                          "negative step with invariant source;"
    1988              :                          " no permute needed.\n");
    1989              :       return VMAT_CONTIGUOUS_DOWN;
    1990              :     }
    1991              : 
    1992         7018 :   if (!perm_mask_for_reverse (vectype))
    1993              :     {
    1994         1238 :       if (dump_enabled_p ())
    1995           52 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    1996              :                          "negative step and reversing not supported.\n");
    1997         1238 :       *poffset = 0;
    1998         1238 :       return VMAT_ELEMENTWISE;
    1999              :     }
    2000              : 
    2001              :   return VMAT_CONTIGUOUS_REVERSE;
    2002              : }
    2003              : 
    2004              : /* STMT_INFO is either a masked or unconditional store.  Return the value
    2005              :    being stored.  */
    2006              : 
    2007              : tree
    2008            0 : vect_get_store_rhs (stmt_vec_info stmt_info)
    2009              : {
    2010            0 :   if (gassign *assign = dyn_cast <gassign *> (stmt_info->stmt))
    2011              :     {
    2012            0 :       gcc_assert (gimple_assign_single_p (assign));
    2013            0 :       return gimple_assign_rhs1 (assign);
    2014              :     }
    2015            0 :   if (gcall *call = dyn_cast <gcall *> (stmt_info->stmt))
    2016              :     {
    2017            0 :       internal_fn ifn = gimple_call_internal_fn (call);
    2018            0 :       int index = internal_fn_stored_value_index (ifn);
    2019            0 :       gcc_assert (index >= 0);
    2020            0 :       return gimple_call_arg (call, index);
    2021              :     }
    2022            0 :   gcc_unreachable ();
    2023              : }
    2024              : 
    2025              : /* Function VECTOR_VECTOR_COMPOSITION_TYPE
    2026              : 
    2027              :    This function returns a vector type which can be composed with NELTS pieces,
    2028              :    whose type is recorded in PTYPE.  VTYPE should be a vector type, and has the
    2029              :    same vector size as the return vector.  It checks target whether supports
    2030              :    pieces-size vector mode for construction firstly, if target fails to, check
    2031              :    pieces-size scalar mode for construction further.  It returns NULL_TREE if
    2032              :    fails to find the available composition.  If the caller only wants scalar
    2033              :    pieces where PTYPE e.g. is a possible gather/scatter element type
    2034              :    SCALAR_PTYPE_ONLY must be true.
    2035              : 
    2036              :    For example, for (vtype=V16QI, nelts=4), we can probably get:
    2037              :      - V16QI with PTYPE V4QI.
    2038              :      - V4SI with PTYPE SI.
    2039              :      - NULL_TREE.  */
    2040              : 
    2041              : static tree
    2042        12837 : vector_vector_composition_type (tree vtype, poly_uint64 nelts, tree *ptype,
    2043              :                                 bool scalar_ptype_only)
    2044              : {
    2045        12837 :   gcc_assert (VECTOR_TYPE_P (vtype));
    2046        12837 :   gcc_assert (known_gt (nelts, 0U));
    2047              : 
    2048        12837 :   machine_mode vmode = TYPE_MODE (vtype);
    2049        12837 :   if (!VECTOR_MODE_P (vmode))
    2050              :     return NULL_TREE;
    2051              : 
    2052              :   /* When we are asked to compose the vector from its components let
    2053              :      that happen directly.  */
    2054        12837 :   if (known_eq (TYPE_VECTOR_SUBPARTS (vtype), nelts))
    2055              :     {
    2056         6105 :       *ptype = TREE_TYPE (vtype);
    2057         6105 :       return vtype;
    2058              :     }
    2059              : 
    2060        13464 :   poly_uint64 vbsize = GET_MODE_BITSIZE (vmode);
    2061         6732 :   unsigned int pbsize;
    2062         6732 :   if (constant_multiple_p (vbsize, nelts, &pbsize))
    2063              :     {
    2064              :       /* First check if vec_init optab supports construction from
    2065              :          vector pieces directly.  */
    2066         6732 :       scalar_mode elmode = SCALAR_TYPE_MODE (TREE_TYPE (vtype));
    2067        13464 :       poly_uint64 inelts = pbsize / GET_MODE_BITSIZE (elmode);
    2068         6732 :       machine_mode rmode;
    2069         6732 :       if (!scalar_ptype_only
    2070         8338 :           && related_vector_mode (vmode, elmode, inelts).exists (&rmode)
    2071        10993 :           && (convert_optab_handler (vec_init_optab, vmode, rmode)
    2072              :               != CODE_FOR_nothing))
    2073              :         {
    2074         3615 :           *ptype = build_vector_type (TREE_TYPE (vtype), inelts);
    2075         3615 :           return vtype;
    2076              :         }
    2077              : 
    2078              :       /* Otherwise check if exists an integer type of the same piece size and
    2079              :          if vec_init optab supports construction from it directly.  */
    2080         3117 :       if (int_mode_for_size (pbsize, 0).exists (&elmode)
    2081         3117 :           && related_vector_mode (vmode, elmode, nelts).exists (&rmode))
    2082              :         {
    2083         2933 :           if (scalar_ptype_only
    2084         2933 :               || convert_optab_handler (vec_init_optab, rmode, elmode)
    2085              :               != CODE_FOR_nothing)
    2086              :             {
    2087         2933 :               *ptype = build_nonstandard_integer_type (pbsize, 1);
    2088         2933 :               return build_vector_type (*ptype, nelts);
    2089              :             }
    2090              :         }
    2091              :     }
    2092              : 
    2093              :   return NULL_TREE;
    2094              : }
    2095              : 
    2096              : /* Check if the load permutation of NODE only refers to a consecutive
    2097              :    subset of the group indices.  We also require the length of the
    2098              :    permutation to be a power of two.
    2099              :    Such load permutations can be elided in strided access schemes as
    2100              :    we can "jump over" the gap they leave.  */
    2101              : 
    2102              : static bool
    2103        46843 : has_consecutive_load_permutation (slp_tree node)
    2104              : {
    2105        46843 :   load_permutation_t perm = SLP_TREE_LOAD_PERMUTATION (node);
    2106        46843 :   if (!perm.exists ()
    2107         2207 :       || perm.length () <= 1
    2108        47348 :       || !pow2p_hwi (perm.length ()))
    2109              :     return false;
    2110              : 
    2111          489 :   return vect_load_perm_consecutive_p (node);
    2112              : }
    2113              : 
    2114              : 
    2115              : /* Analyze load or store SLP_NODE of type VLS_TYPE.  Return true
    2116              :    if there is a memory access type that the vectorized form can use,
    2117              :    storing it in *MEMORY_ACCESS_TYPE if so.  If we decide to use gathers
    2118              :    or scatters, fill in GS_INFO accordingly.  In addition
    2119              :    *ALIGNMENT_SUPPORT_SCHEME is filled out and false is returned if
    2120              :    the target does not support the alignment scheme.  *MISALIGNMENT
    2121              :    is set according to the alignment of the access (including
    2122              :    DR_MISALIGNMENT_UNKNOWN when it is unknown).
    2123              : 
    2124              :    MASKED_P is true if the statement is conditional on a vectorized mask.
    2125              :    VECTYPE is the vector type that the vectorized statements will use.
    2126              : 
    2127              :    If ELSVALS is nonzero the supported else values will be stored in the
    2128              :    vector ELSVALS points to.  */
    2129              : 
    2130              : static bool
    2131      1420656 : get_load_store_type (vec_info  *vinfo, stmt_vec_info stmt_info,
    2132              :                      tree vectype, slp_tree slp_node,
    2133              :                      bool masked_p, vec_load_store_type vls_type,
    2134              :                      vect_load_store_data *ls)
    2135              : {
    2136      1420656 :   vect_memory_access_type *memory_access_type = &ls->memory_access_type;
    2137      1420656 :   poly_int64 *poffset = &ls->poffset;
    2138      1420656 :   dr_alignment_support *alignment_support_scheme
    2139              :     = &ls->alignment_support_scheme;
    2140      1420656 :   int *misalignment = &ls->misalignment;
    2141      1420656 :   internal_fn *lanes_ifn = &ls->lanes_ifn;
    2142      1420656 :   vec<int> *elsvals = &ls->elsvals;
    2143      1420656 :   tree *ls_type = &ls->ls_type;
    2144      1420656 :   bool *slp_perm = &ls->slp_perm;
    2145      1420656 :   unsigned *n_perms = &ls->n_perms;
    2146      1420656 :   unsigned *n_loads = &ls->n_loads;
    2147      1420656 :   tree *supported_offset_vectype = &ls->supported_offset_vectype;
    2148      1420656 :   int *supported_scale = &ls->supported_scale;
    2149      1420656 :   loop_vec_info loop_vinfo = dyn_cast <loop_vec_info> (vinfo);
    2150      1420656 :   poly_uint64 nunits = TYPE_VECTOR_SUBPARTS (vectype);
    2151      1420656 :   class loop *loop = loop_vinfo ? LOOP_VINFO_LOOP (loop_vinfo) : NULL;
    2152      1420656 :   stmt_vec_info first_stmt_info;
    2153      1420656 :   unsigned int group_size;
    2154      1420656 :   unsigned HOST_WIDE_INT gap;
    2155      1420656 :   bool single_element_p;
    2156      1420656 :   poly_int64 neg_ldst_offset = 0;
    2157              : 
    2158      1420656 :   *misalignment = DR_MISALIGNMENT_UNKNOWN;
    2159      1420656 :   *poffset = 0;
    2160      1420656 :   *ls_type = NULL_TREE;
    2161      1420656 :   *slp_perm = false;
    2162      1420656 :   *n_perms = -1U;
    2163      1420656 :   *n_loads = -1U;
    2164      1420656 :   ls->subchain_p = false;
    2165      1420656 :   ls->gs_offset_uniform_p = false;
    2166              : 
    2167      1420656 :   bool perm_ok = true;
    2168      1420656 :   poly_int64 vf = loop_vinfo ? LOOP_VINFO_VECT_FACTOR (loop_vinfo) : 1;
    2169              : 
    2170      1420656 :   if (SLP_TREE_LOAD_PERMUTATION (slp_node).exists ())
    2171        75140 :     perm_ok = vect_transform_slp_perm_load (vinfo, slp_node, vNULL, NULL,
    2172        75140 :                                             vf, true, ls, n_perms, n_loads);
    2173              : 
    2174      1420656 :   if (STMT_VINFO_GROUPED_ACCESS (stmt_info))
    2175              :     {
    2176       895684 :       first_stmt_info = DR_GROUP_FIRST_ELEMENT (stmt_info);
    2177       895684 :       group_size = DR_GROUP_SIZE (first_stmt_info);
    2178       895684 :       gap = DR_GROUP_GAP (first_stmt_info);
    2179       895684 :       single_element_p = (stmt_info == first_stmt_info
    2180       895684 :                           && !DR_GROUP_NEXT_ELEMENT (stmt_info));
    2181              :     }
    2182              :   else
    2183              :     {
    2184              :       first_stmt_info = stmt_info;
    2185              :       group_size = 1;
    2186              :       gap = 0;
    2187              :       single_element_p = true;
    2188              :     }
    2189      1420656 :   dr_vec_info *first_dr_info = STMT_VINFO_DR_INFO (first_stmt_info);
    2190              : 
    2191              :   /* There can only be a gap at the end of the group if the stride is
    2192              :      known at compile time.  */
    2193      1420656 :   gcc_assert (!STMT_VINFO_STRIDED_P (first_stmt_info) || gap == 0);
    2194              : 
    2195              :   /* For SLP vectorization we directly vectorize a subchain
    2196              :      without permutation.  */
    2197      1420656 :   if (! SLP_TREE_LOAD_PERMUTATION (slp_node).exists ())
    2198      1345516 :     first_dr_info = STMT_VINFO_DR_INFO (SLP_TREE_SCALAR_STMTS (slp_node)[0]);
    2199              : 
    2200      1420656 :   if (STMT_VINFO_STRIDED_P (first_stmt_info))
    2201              :     {
    2202              :       /* Try to use consecutive accesses of as many elements as possible,
    2203              :          separated by the stride, until we have a complete vector.
    2204              :          Fall back to scalar accesses if that isn't possible.  */
    2205        46843 :       *memory_access_type = VMAT_STRIDED_SLP;
    2206              : 
    2207              :       /* If the load permutation is consecutive we can reduce the group to
    2208              :          the elements the permutation accesses.  Then we release the
    2209              :          permutation.  */
    2210        46843 :       if (has_consecutive_load_permutation (slp_node))
    2211              :         {
    2212           51 :           ls->subchain_p = true;
    2213           51 :           group_size = SLP_TREE_LANES (slp_node);
    2214           51 :           SLP_TREE_LOAD_PERMUTATION (slp_node).release ();
    2215              :         }
    2216              :     }
    2217      1373813 :   else if (STMT_VINFO_GATHER_SCATTER_P (stmt_info))
    2218              :     {
    2219        11529 :       slp_tree offset_node = SLP_TREE_CHILDREN (slp_node)[0];
    2220        11529 :       tree offset_vectype = SLP_TREE_VECTYPE (offset_node);
    2221        11529 :       int scale = SLP_TREE_GS_SCALE (slp_node);
    2222        11529 :       tree memory_type = TREE_TYPE (DR_REF (first_dr_info->dr));
    2223        11529 :       tree tem;
    2224        11529 :       if (vect_gather_scatter_fn_p (loop_vinfo, vls_type == VLS_LOAD,
    2225              :                                     masked_p, vectype, memory_type,
    2226              :                                     offset_vectype, scale, supported_scale,
    2227              :                                     &ls->gs.ifn, &tem,
    2228              :                                     supported_offset_vectype, elsvals))
    2229              :         {
    2230            0 :           if (dump_enabled_p ())
    2231              :             {
    2232            0 :               dump_printf_loc (MSG_NOTE, vect_location,
    2233              :                                "gather/scatter with required "
    2234              :                                "offset type "
    2235              :                                "%T and offset scale %d.\n",
    2236              :                                offset_vectype, scale);
    2237            0 :               if (*supported_offset_vectype)
    2238            0 :                 dump_printf_loc (MSG_NOTE, vect_location,
    2239              :                                  " target supports offset type %T.\n",
    2240              :                                  *supported_offset_vectype);
    2241            0 :               if (*supported_scale)
    2242            0 :                 dump_printf_loc (MSG_NOTE, vect_location,
    2243              :                                  " target supports offset scale %d.\n",
    2244              :                                  *supported_scale);
    2245              :             }
    2246            0 :           *memory_access_type = VMAT_GATHER_SCATTER_IFN;
    2247              :         }
    2248        11529 :       else if (vls_type == VLS_LOAD
    2249        11529 :                ? (targetm.vectorize.builtin_gather
    2250         9976 :                   && (ls->gs.decl
    2251         9976 :                         = targetm.vectorize.builtin_gather (vectype,
    2252         9976 :                                                             TREE_TYPE
    2253              :                                                               (offset_vectype),
    2254              :                                                             scale)))
    2255         1553 :                : (targetm.vectorize.builtin_scatter
    2256         1553 :                   && (ls->gs.decl
    2257         1553 :                         = targetm.vectorize.builtin_scatter (vectype,
    2258         1553 :                                                              TREE_TYPE
    2259              :                                                                (offset_vectype),
    2260              :                                                              scale))))
    2261          565 :         *memory_access_type = VMAT_GATHER_SCATTER_LEGACY;
    2262              :       else
    2263              :         {
    2264              :           /* GATHER_SCATTER_EMULATED_P.  */
    2265        10964 :           if (!TYPE_VECTOR_SUBPARTS (vectype).is_constant ()
    2266        10964 :               || !TYPE_VECTOR_SUBPARTS (offset_vectype).is_constant ()
    2267        10964 :               || VECTOR_BOOLEAN_TYPE_P (offset_vectype)
    2268        10964 :               || !constant_multiple_p (TYPE_VECTOR_SUBPARTS (offset_vectype),
    2269        14570 :                                        TYPE_VECTOR_SUBPARTS (vectype)))
    2270              :             {
    2271         3606 :               if (dump_enabled_p ())
    2272          486 :                 dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2273              :                                  "unsupported vector types for emulated "
    2274              :                                  "gather.\n");
    2275         3606 :               return false;
    2276              :             }
    2277         7358 :           *memory_access_type = VMAT_GATHER_SCATTER_EMULATED;
    2278              : 
    2279              :           /* A single-lane gather load whose offset is the same for all lanes
    2280              :              of each vector can use a scalar load plus broadcast.  The
    2281              :              uniformity check assumes each vector starts at a scalar iteration
    2282              :              that is a multiple of the number of lanes.  Peeling for alignment
    2283              :              (with or without masks) and epilogue loops shift the start, so
    2284              :              reject those.  */
    2285         7358 :           if (vls_type == VLS_LOAD
    2286         6494 :               && SLP_TREE_LANES (slp_node) == 1
    2287        13803 :               && vect_check_gather_load_offset_uniform
    2288         6445 :                    (loop, nunits.to_constant (),
    2289              :                     vect_get_slp_scalar_def (offset_node, 0)))
    2290              :             {
    2291           80 :               if (LOOP_VINFO_PEELING_FOR_ALIGNMENT (loop_vinfo) != 0
    2292           71 :                   || LOOP_VINFO_EPILOGUE_P (loop_vinfo))
    2293              :                 {
    2294           38 :                   if (dump_enabled_p ())
    2295           38 :                     dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2296              :                                      "not using broadcast for uniform gather "
    2297              :                                      "offset because of peeling or epilogue\n");
    2298              :                 }
    2299              :               else
    2300           42 :                 ls->gs_offset_uniform_p = true;
    2301              :             }
    2302              :         }
    2303              :     }
    2304              :   else
    2305              :     {
    2306      1362284 :       int cmp = compare_step_with_zero (vinfo, stmt_info);
    2307      1362284 :       if (cmp < 0)
    2308              :         {
    2309         8282 :           if (single_element_p)
    2310              :             /* ???  The VMAT_CONTIGUOUS_REVERSE code generation is
    2311              :                only correct for single element "interleaving" SLP.  */
    2312         8102 :             *memory_access_type = get_negative_load_store_type
    2313         8102 :                 (vinfo, stmt_info, vectype, vls_type, 1,
    2314              :                  &neg_ldst_offset);
    2315              :           else
    2316              :             /* We can fall back to VMAT_STRIDED_SLP since that does
    2317              :                not care whether the stride between the group instances
    2318              :                is positive or negative.  */
    2319          180 :             *memory_access_type = VMAT_STRIDED_SLP;
    2320              :         }
    2321      1354002 :       else if (cmp == 0 && loop_vinfo)
    2322              :         {
    2323         5184 :           gcc_assert (vls_type == VLS_LOAD);
    2324         5184 :           *memory_access_type = VMAT_INVARIANT;
    2325              :         }
    2326              :       /* Try using LOAD/STORE_LANES.  */
    2327      1348818 :       else if (slp_node->ldst_lanes
    2328      1348818 :                && (*lanes_ifn
    2329            0 :                    = (vls_type == VLS_LOAD
    2330            0 :                       ? vect_load_lanes_supported (vectype, group_size,
    2331              :                                                    masked_p, elsvals)
    2332            0 :                       : vect_store_lanes_supported (vectype, group_size,
    2333              :                                                     masked_p))) != IFN_LAST)
    2334            0 :         *memory_access_type = VMAT_LOAD_STORE_LANES;
    2335      1348818 :       else if (!loop_vinfo && slp_node->avoid_stlf_fail)
    2336              :         {
    2337           66 :           *memory_access_type = VMAT_ELEMENTWISE;
    2338           66 :           if (dump_enabled_p ())
    2339            2 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2340              :                              "using element-wise load to avoid disrupting "
    2341              :                              "cross iteration store-to-load forwarding\n");
    2342              :         }
    2343              :       else
    2344      1348752 :         *memory_access_type = VMAT_CONTIGUOUS;
    2345              : 
    2346              :       /* True if the vectorized statements would access beyond the last
    2347              :          statement in the group.  */
    2348      1362284 :       bool overrun_p = false;
    2349              : 
    2350              :       /* True if we can cope with such overrun by peeling for gaps, so that
    2351              :          there is at least one final scalar iteration after the vector loop.  */
    2352      2724568 :       bool can_overrun_p = (!masked_p
    2353      1362284 :                             && vls_type == VLS_LOAD
    2354       555611 :                             && loop_vinfo
    2355       408791 :                             && !loop->inner
    2356      1769217 :                             && (*memory_access_type != VMAT_STRIDED_SLP
    2357           76 :                                 || cmp > 0));
    2358              : 
    2359              :       /* If this is single-element interleaving with an element
    2360              :          distance that leaves unused vector loads around fall back
    2361              :          to elementwise access if possible - we otherwise least
    2362              :          create very sub-optimal code in that case (and
    2363              :          blow up memory, see PR65518).  */
    2364      1362284 :       if (loop_vinfo
    2365      1362284 :           && single_element_p
    2366       498732 :           && (*memory_access_type == VMAT_CONTIGUOUS
    2367        13286 :               || *memory_access_type == VMAT_CONTIGUOUS_REVERSE)
    2368      1861016 :           && maybe_gt (group_size, TYPE_VECTOR_SUBPARTS (vectype)))
    2369              :         {
    2370        13387 :           *memory_access_type = VMAT_ELEMENTWISE;
    2371        13387 :           if (dump_enabled_p ())
    2372          206 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2373              :                              "single-element interleaving not supported "
    2374              :                              "for not adjacent vector loads, using "
    2375              :                              "elementwise access\n");
    2376              :         }
    2377              : 
    2378              :       /* Also fall back to elementwise access in case we did not lower a
    2379              :          permutation and cannot code generate it.  */
    2380      1362284 :       if (loop_vinfo
    2381       556470 :           && *memory_access_type != VMAT_ELEMENTWISE
    2382       541845 :           && SLP_TREE_LOAD_PERMUTATION (slp_node).exists ()
    2383      1388481 :           && !perm_ok)
    2384              :         {
    2385         2135 :           *memory_access_type = VMAT_ELEMENTWISE;
    2386         2135 :           if (dump_enabled_p ())
    2387          251 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2388              :                              "permutation not supported, using elementwise "
    2389              :                              "access\n");
    2390              :         }
    2391              : 
    2392       556470 :       overrun_p = (loop_vinfo && gap != 0
    2393      1406270 :                    && *memory_access_type != VMAT_ELEMENTWISE);
    2394      1362284 :       if (overrun_p && vls_type != VLS_LOAD)
    2395              :         {
    2396            0 :           if (dump_enabled_p ())
    2397            0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2398              :                              "Grouped store with gaps requires"
    2399              :                              " non-consecutive accesses\n");
    2400           19 :           return false;
    2401              :         }
    2402              : 
    2403      1362284 :       unsigned HOST_WIDE_INT dr_size = vect_get_scalar_dr_size (first_dr_info);
    2404      1362284 :       poly_int64 off = 0;
    2405      1362284 :       if (*memory_access_type == VMAT_CONTIGUOUS_REVERSE)
    2406         5618 :         off = (TYPE_VECTOR_SUBPARTS (vectype) - 1) * -dr_size;
    2407              : 
    2408              :       /* An overrun is fine if the trailing elements are smaller
    2409              :          than the alignment boundary B.  Every vector access will
    2410              :          be a multiple of B and so we are guaranteed to access a
    2411              :          non-gap element in the same B-sized block.  */
    2412      1362284 :       if (overrun_p
    2413      1362284 :           && gap < (vect_known_alignment_in_bytes (first_dr_info,
    2414        28729 :                                                    vectype, off) / dr_size))
    2415              :         overrun_p = false;
    2416              : 
    2417              :       /* When we have a contiguous access across loop iterations
    2418              :          but the access in the loop doesn't cover the full vector
    2419              :          we can end up with no gap recorded but still excess
    2420              :          elements accessed, see PR103116.  Make sure we peel for
    2421              :          gaps if necessary and sufficient and give up if not.
    2422              : 
    2423              :          If there is a combination of the access not covering the full
    2424              :          vector and a gap recorded then we may need to peel twice.  */
    2425      1362284 :       bool large_vector_overrun_p = false;
    2426      1362284 :       if (loop_vinfo
    2427       556470 :           && (*memory_access_type == VMAT_CONTIGUOUS
    2428        28821 :               || *memory_access_type == VMAT_CONTIGUOUS_REVERSE)
    2429       533267 :           && SLP_TREE_LOAD_PERMUTATION (slp_node).exists ()
    2430      1385968 :           && !multiple_p (group_size * LOOP_VINFO_VECT_FACTOR (loop_vinfo),
    2431              :                           nunits))
    2432              :         large_vector_overrun_p = overrun_p = true;
    2433              : 
    2434              :       /* If the gap splits the vector in half and the target
    2435              :          can do half-vector operations avoid the epilogue peeling
    2436              :          by simply loading half of the vector only.  Usually
    2437              :          the construction with an upper zero half will be elided.  */
    2438      1362284 :       dr_alignment_support alss;
    2439      1362284 :       poly_int64 align_offset
    2440      1362284 :         = vect_get_misalign_offset (cmp < 0, vectype, first_stmt_info,
    2441              :                                     loop_vinfo);
    2442      1362284 :       int misalign = dr_misalignment (first_dr_info, vectype, align_offset);
    2443      1362284 :       tree half_vtype;
    2444      1362284 :       poly_uint64 remain;
    2445      1362284 :       unsigned HOST_WIDE_INT tem, num;
    2446      1362284 :       if (overrun_p
    2447      1362284 :           && !masked_p
    2448        23105 :           && (*memory_access_type == VMAT_CONTIGUOUS
    2449          344 :               || *memory_access_type == VMAT_CONTIGUOUS_REVERSE)
    2450        23095 :           && (((alss = vect_supportable_dr_alignment (vinfo, first_dr_info,
    2451              :                                                       vectype, misalign)))
    2452              :               == dr_aligned
    2453        17880 :               || alss == dr_unaligned_supported)
    2454        12697 :           && can_div_trunc_p (group_size
    2455        12697 :                               * LOOP_VINFO_VECT_FACTOR (loop_vinfo) - gap,
    2456              :                               nunits, &tem, &remain)
    2457      1374981 :           && (known_eq (remain, 0u)
    2458         7514 :               || (known_ne (remain, 0u)
    2459         5823 :                   && constant_multiple_p (nunits, remain, &num)
    2460      1362284 :                   && (vector_vector_composition_type (vectype, num, &half_vtype)
    2461              :                       != NULL_TREE))))
    2462              :         overrun_p = false;
    2463              : 
    2464      1362284 :       if (overrun_p && !can_overrun_p)
    2465              :         {
    2466           16 :           if (dump_enabled_p ())
    2467           12 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2468              :                              "Peeling for outer loop is not supported\n");
    2469              :           return false;
    2470              :         }
    2471              : 
    2472              :       /* Peeling for gaps assumes that a single scalar iteration
    2473              :          is enough to make sure the last vector iteration doesn't
    2474              :          access excess elements.  */
    2475      1362268 :       if (overrun_p
    2476      1362268 :           && (!can_div_trunc_p (group_size
    2477        12083 :                                 * LOOP_VINFO_VECT_FACTOR (loop_vinfo) - gap,
    2478              :                                 nunits, &tem, &remain)
    2479        12083 :               || maybe_lt (remain + group_size, nunits)))
    2480              :         {
    2481              :           /* But peeling a single scalar iteration is enough if
    2482              :              we can use the next power-of-two sized partial
    2483              :              access and that is sufficiently small to be covered
    2484              :              by the single scalar iteration.  */
    2485           16 :           unsigned HOST_WIDE_INT cnunits, cvf, cremain, cpart_size;
    2486           16 :           if (masked_p
    2487           16 :               || !nunits.is_constant (&cnunits)
    2488           16 :               || !LOOP_VINFO_VECT_FACTOR (loop_vinfo).is_constant (&cvf)
    2489           16 :               || (((cremain = (group_size * cvf - gap) % cnunits), true)
    2490           16 :                   && ((cpart_size = (1 << ceil_log2 (cremain))), true)
    2491           16 :                   && (cremain + group_size < cpart_size
    2492           16 :                       || (vector_vector_composition_type (vectype,
    2493           13 :                                                          cnunits / cpart_size,
    2494              :                                                          &half_vtype)
    2495              :                           == NULL_TREE))))
    2496              :             {
    2497              :               /* If all fails we can still resort to niter masking unless
    2498              :                  the vectors used are too big, so enforce the use of
    2499              :                  partial vectors.  */
    2500            3 :               if (LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo)
    2501            3 :                   && !large_vector_overrun_p)
    2502              :                 {
    2503            0 :                   if (dump_enabled_p ())
    2504            0 :                     dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2505              :                                      "peeling for gaps insufficient for "
    2506              :                                      "access unless using partial "
    2507              :                                      "vectors\n");
    2508            0 :                   LOOP_VINFO_MUST_USE_PARTIAL_VECTORS_P (loop_vinfo) = true;
    2509              :                 }
    2510              :               else
    2511              :                 {
    2512            3 :                   if (dump_enabled_p ())
    2513            3 :                     dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2514              :                                      "peeling for gaps insufficient for "
    2515              :                                      "access\n");
    2516           19 :                   return false;
    2517              :                 }
    2518              :             }
    2519           13 :           else if (large_vector_overrun_p)
    2520              :             {
    2521           13 :               if (dump_enabled_p ())
    2522           12 :                 dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2523              :                                  "can't operate on partial vectors because "
    2524              :                                  "only unmasked loads handle access "
    2525              :                                  "shortening required because of gaps at "
    2526              :                                  "the end of the access\n");
    2527           13 :               LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo) = false;
    2528              :             }
    2529              :         }
    2530              : 
    2531      1362265 :       if (overrun_p)
    2532              :         {
    2533        12080 :           gcc_assert (can_overrun_p);
    2534        12080 :           if (dump_enabled_p ())
    2535          508 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2536              :                              "Data access with gaps requires scalar "
    2537              :                              "epilogue loop\n");
    2538        12080 :           LOOP_VINFO_PEELING_FOR_GAPS (loop_vinfo) = true;
    2539              :         }
    2540              :     }
    2541              : 
    2542              :   /* As a last resort, trying using a gather load or scatter store.
    2543              : 
    2544              :      ??? Although the code can handle all group sizes correctly,
    2545              :      it probably isn't a win to use separate strided accesses based
    2546              :      on nearby locations.  Or, even if it's a win over scalar code,
    2547              :      it might not be a win over vectorizing at a lower VF, if that
    2548              :      allows us to use contiguous accesses.  */
    2549      1417031 :   vect_memory_access_type grouped_gather_fallback = VMAT_UNINITIALIZED;
    2550      1417031 :   if (loop_vinfo
    2551       611217 :       && (*memory_access_type == VMAT_ELEMENTWISE
    2552       611217 :           || *memory_access_type == VMAT_STRIDED_SLP))
    2553              :     {
    2554        63768 :       gather_scatter_info gs_info;
    2555        63768 :       tree tem;
    2556        63768 :       if (SLP_TREE_LANES (slp_node) == 1
    2557        59023 :           && (!SLP_TREE_LOAD_PERMUTATION (slp_node).exists ()
    2558        17005 :               || single_element_p)
    2559       120701 :           && vect_use_strided_gather_scatters_p (stmt_info, vectype, loop_vinfo,
    2560              :                                                  masked_p, &gs_info, elsvals,
    2561              :                                                  group_size, single_element_p))
    2562              :         {
    2563              :           /* vect_use_strided_gather_scatters_p does not save the actually
    2564              :              supported scale and offset type so do that here.
    2565              :              We need it later in check_load_store_for_partial_vectors
    2566              :              where we only check if the given internal function is supported
    2567              :              (to choose whether to use the IFN, LEGACY, or EMULATED flavor
    2568              :              of gather/scatter) and don't re-do the full analysis.  */
    2569            0 :           tree tmp;
    2570            0 :           gcc_assert (vect_gather_scatter_fn_p
    2571              :                       (loop_vinfo, vls_type == VLS_LOAD, masked_p, vectype,
    2572              :                        gs_info.memory_type, TREE_TYPE (gs_info.offset),
    2573              :                        gs_info.scale, supported_scale, &gs_info.ifn,
    2574              :                        &tmp, supported_offset_vectype, elsvals));
    2575              : 
    2576            0 :           SLP_TREE_GS_SCALE (slp_node) = gs_info.scale;
    2577            0 :           SLP_TREE_GS_BASE (slp_node) = error_mark_node;
    2578            0 :           ls->gs.ifn = gs_info.ifn;
    2579            0 :           ls->strided_offset_vectype = gs_info.offset_vectype;
    2580            0 :           *memory_access_type = VMAT_GATHER_SCATTER_IFN;
    2581              :         }
    2582        63768 :       else if (SLP_TREE_LANES (slp_node) > 1
    2583              :                && !masked_p
    2584         4745 :                && !single_element_p
    2585        68400 :                && vect_use_grouped_gather (STMT_VINFO_DR_INFO (stmt_info),
    2586              :                                            vectype, loop_vinfo,
    2587              :                                            masked_p, group_size,
    2588              :                                            &gs_info, elsvals, &tem))
    2589              :         {
    2590            0 :           SLP_TREE_GS_SCALE (slp_node) = gs_info.scale;
    2591            0 :           SLP_TREE_GS_BASE (slp_node) = error_mark_node;
    2592            0 :           grouped_gather_fallback = *memory_access_type;
    2593            0 :           *memory_access_type = VMAT_GATHER_SCATTER_IFN;
    2594            0 :           ls->gs.ifn = gs_info.ifn;
    2595            0 :           vectype = *ls_type = tem;
    2596            0 :           ls->strided_offset_vectype = gs_info.offset_vectype;
    2597              :         }
    2598              :     }
    2599              : 
    2600      1417031 :   if (*memory_access_type == VMAT_CONTIGUOUS_DOWN
    2601      1417031 :       || *memory_access_type == VMAT_CONTIGUOUS_REVERSE)
    2602         6698 :     *poffset = neg_ldst_offset;
    2603              : 
    2604      1417031 :   if (*memory_access_type == VMAT_ELEMENTWISE
    2605      1400205 :       || *memory_access_type == VMAT_GATHER_SCATTER_LEGACY
    2606      1399640 :       || *memory_access_type == VMAT_STRIDED_SLP
    2607      1352632 :       || *memory_access_type == VMAT_INVARIANT)
    2608              :     {
    2609        69583 :       *alignment_support_scheme = dr_unaligned_supported;
    2610        69583 :       *misalignment = DR_MISALIGNMENT_UNKNOWN;
    2611              :     }
    2612              :   else
    2613              :     {
    2614      1347448 :       if (mat_gather_scatter_p (*memory_access_type)
    2615              :           && !first_dr_info)
    2616              :         *misalignment = DR_MISALIGNMENT_UNKNOWN;
    2617              :       else
    2618      1347448 :         *misalignment = dr_misalignment (first_dr_info, vectype, *poffset);
    2619              : 
    2620      1347448 :       int align_misalignment = *misalignment;
    2621      1347448 :       if (*memory_access_type == VMAT_CONTIGUOUS_REVERSE)
    2622              :         {
    2623         5614 :           poly_int64 align_offset
    2624         5614 :             = vect_get_misalign_offset (true, vectype, first_stmt_info,
    2625              :                                        loop_vinfo);
    2626         5614 :           align_misalignment
    2627         5614 :             = dr_misalignment (first_dr_info, vectype, align_offset);
    2628              :         }
    2629              : 
    2630      1347448 :       *alignment_support_scheme
    2631      1347448 :         = vect_supportable_dr_alignment
    2632      1347448 :            (vinfo, first_dr_info, vectype, align_misalignment,
    2633              :             mat_gather_scatter_p (*memory_access_type));
    2634      1347448 :       if (grouped_gather_fallback != VMAT_UNINITIALIZED
    2635            0 :           && *alignment_support_scheme != dr_aligned
    2636            0 :           && *alignment_support_scheme != dr_unaligned_supported)
    2637              :         {
    2638              :           /* No supportable alignment for a grouped gather, fall back to the
    2639              :              original memory access type.  Even though VMAT_STRIDED_SLP might
    2640              :              also try aligned vector loads it can still choose vector
    2641              :              construction from scalars.  */
    2642            0 :           *memory_access_type = grouped_gather_fallback;
    2643            0 :           *alignment_support_scheme = dr_unaligned_supported;
    2644            0 :           *misalignment = DR_MISALIGNMENT_UNKNOWN;
    2645              :         }
    2646              :     }
    2647              : 
    2648      1417031 :   if ((*memory_access_type == VMAT_ELEMENTWISE
    2649      1417031 :        || *memory_access_type == VMAT_STRIDED_SLP)
    2650              :       && !nunits.is_constant ())
    2651              :     {
    2652              :       if (dump_enabled_p ())
    2653              :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2654              :                          "Not using elementwise accesses due to variable "
    2655              :                          "vectorization factor.\n");
    2656              :       return false;
    2657              :     }
    2658              : 
    2659              :   /* Checks if all scalar iterations are known to be inbounds.  */
    2660      1417031 :   bool inbounds = DR_SCALAR_KNOWN_BOUNDS (STMT_VINFO_DR_INFO (stmt_info));
    2661              : 
    2662              :   /* Check if we support the operation if early breaks are needed.  Here we
    2663              :      must ensure that we don't access any more than the scalar code would
    2664              :      have.  A masked operation would ensure this, so for these load types
    2665              :      force masking.  */
    2666      1417031 :   if (loop_vinfo
    2667       611217 :       && dr_safe_speculative_read_required (stmt_info)
    2668      1615424 :       && LOOP_VINFO_EARLY_BREAKS (loop_vinfo))
    2669              :     {
    2670       198393 :       if (mat_gather_scatter_p (*memory_access_type)
    2671       198393 :           || *memory_access_type == VMAT_STRIDED_SLP)
    2672              :         {
    2673         9800 :           if (dump_enabled_p ())
    2674           12 :             dump_printf_loc (MSG_NOTE, vect_location,
    2675              :                              "early break not supported: cannot peel for "
    2676              :                              "alignment. With non-contiguous memory vectorization"
    2677              :                              " could read out of bounds at %G ",
    2678              :                              STMT_VINFO_STMT (stmt_info));
    2679         9800 :           if (inbounds)
    2680            0 :             LOOP_VINFO_MUST_USE_PARTIAL_VECTORS_P (loop_vinfo) = true;
    2681              :           else
    2682              :             return false;
    2683              :         }
    2684              :       /* Block-level alignment: Even though individual accesses of
    2685              :          VMAT_ELEMENTWISE type do not cause alignment problems, loading the
    2686              :          whole vector's worth of values in a speculative early-break context
    2687              :          might cross a page boundary.  Set the alignment scheme to `dr_aligned'
    2688              :          here in order to force checking of whether such accesses meet
    2689              :          alignment criteria.  */
    2690       188593 :       else if (*memory_access_type == VMAT_ELEMENTWISE && !inbounds)
    2691         5688 :         *alignment_support_scheme = dr_aligned;
    2692              :     }
    2693              : 
    2694              :   /* If this DR needs alignment for correctness, we must ensure the target
    2695              :      alignment is a constant power-of-two multiple of the amount read per
    2696              :      vector iteration or force masking.  */
    2697      1407231 :   if (dr_safe_speculative_read_required (stmt_info)
    2698      1407231 :       && (*alignment_support_scheme == dr_aligned
    2699       107436 :           && !mat_gather_scatter_p (*memory_access_type)))
    2700              :     {
    2701              :       /* We can only peel for loops, of course.  */
    2702       107436 :       gcc_checking_assert (loop_vinfo);
    2703              : 
    2704       107436 :       poly_uint64 vf = LOOP_VINFO_VECT_FACTOR (loop_vinfo);
    2705       107436 :       poly_uint64 read_amount
    2706       107436 :         = vf * TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (vectype)));
    2707       107436 :       if (STMT_VINFO_GROUPED_ACCESS (stmt_info))
    2708       107436 :         read_amount *= group_size;
    2709              : 
    2710       107436 :       auto target_alignment
    2711       107436 :         = DR_TARGET_ALIGNMENT (STMT_VINFO_DR_INFO (stmt_info));
    2712       107436 :       if (!multiple_p (target_alignment, read_amount))
    2713              :         {
    2714        10410 :           if (dump_enabled_p ())
    2715              :             {
    2716           28 :               dump_printf_loc (MSG_NOTE, vect_location,
    2717              :                                "desired alignment not met, target was ");
    2718           28 :               dump_dec (MSG_NOTE, target_alignment);
    2719           28 :               dump_printf (MSG_NOTE, " previously, but read amount is ");
    2720           28 :               dump_dec (MSG_NOTE, read_amount);
    2721           28 :               dump_printf (MSG_NOTE, " at %G.\n", STMT_VINFO_STMT (stmt_info));
    2722              :             }
    2723        12564 :           return false;
    2724              :         }
    2725              : 
    2726              :       /* When using a group access the first element may be aligned but the
    2727              :          subsequent loads may not be.  For LOAD_LANES since the loads are based
    2728              :          on the first DR then all loads in the group are aligned.  For
    2729              :          non-LOAD_LANES this is not the case. In particular a load + blend when
    2730              :          there are gaps can have the non first loads issued unaligned, even
    2731              :          partially overlapping the memory of the first load in order to simplify
    2732              :          the blend.  This is what the x86_64 backend does for instance.  As
    2733              :          such only the first load in the group is aligned, the rest are not.
    2734              :          Because of this the permutes may break the alignment requirements that
    2735              :          have been set, and as such we should for now, reject them.  */
    2736        97026 :       if (SLP_TREE_LOAD_PERMUTATION (slp_node).exists ())
    2737              :         {
    2738         2154 :           if (dump_enabled_p ())
    2739           96 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2740              :                              "loads with load permutations not supported for "
    2741              :                              "speculative early break loads for %G",
    2742              :                              STMT_VINFO_STMT (stmt_info));
    2743              :           return false;
    2744              :         }
    2745              : 
    2746              :       /* Reject vectorization if we know the read mount per vector iteration
    2747              :          exceeds the min page size.  */
    2748        94872 :       if (known_gt (read_amount, (unsigned) param_min_pagesize))
    2749              :         {
    2750            0 :           if (dump_enabled_p ())
    2751              :             {
    2752            0 :               dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2753              :                                "alignment required for correctness (");
    2754            0 :               dump_dec (MSG_MISSED_OPTIMIZATION, read_amount);
    2755            0 :               dump_printf (MSG_NOTE, ") may exceed page size.\n");
    2756              :             }
    2757              :           return false;
    2758              :         }
    2759              : 
    2760        94872 :       if (!vf.is_constant ())
    2761              :         {
    2762              :           /* For VLA modes, we need a runtime check to ensure any speculative
    2763              :              read amount does not exceed the page size.  Here we record the max
    2764              :              possible read amount for the check.  */
    2765              :           if (maybe_gt (read_amount,
    2766              :                         LOOP_VINFO_MAX_SPEC_READ_AMOUNT (loop_vinfo)))
    2767              :             LOOP_VINFO_MAX_SPEC_READ_AMOUNT (loop_vinfo) = read_amount;
    2768              : 
    2769              :           /* For VLA modes, we must use partial vectors.  */
    2770              :           LOOP_VINFO_MUST_USE_PARTIAL_VECTORS_P (loop_vinfo) = true;
    2771              :         }
    2772              :     }
    2773              : 
    2774      1394667 :   if (*alignment_support_scheme == dr_unaligned_unsupported)
    2775              :     {
    2776        75873 :       if (dump_enabled_p ())
    2777          256 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2778              :                          "unsupported unaligned access\n");
    2779              :       return false;
    2780              :     }
    2781              : 
    2782              :   /* FIXME: At the moment the cost model seems to underestimate the
    2783              :      cost of using elementwise accesses.  This check preserves the
    2784              :      traditional behavior until that can be fixed.  */
    2785      1318794 :   if (*memory_access_type == VMAT_ELEMENTWISE
    2786        11294 :       && !STMT_VINFO_STRIDED_P (first_stmt_info)
    2787      1330088 :       && !(STMT_VINFO_GROUPED_ACCESS (stmt_info)
    2788        10147 :            && single_element_p
    2789         9506 :            && !pow2p_hwi (group_size)))
    2790              :     {
    2791         5240 :       if (dump_enabled_p ())
    2792          366 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2793              :                          "not falling back to elementwise accesses\n");
    2794              :       return false;
    2795              :     }
    2796              : 
    2797              :   /* For BB vectorization build up the vector from existing scalar defs.  */
    2798      1313554 :   if (!loop_vinfo && *memory_access_type == VMAT_ELEMENTWISE)
    2799              :     return false;
    2800              : 
    2801              :   /* Some loads need to explicitly permute the loaded data if there
    2802              :      is a load permutation.  Among those are:
    2803              :       - VMAT_ELEMENTWISE.
    2804              :       - VMAT_STRIDED_SLP.
    2805              :       - VMAT_GATHER_SCATTER:
    2806              :         - Strided gather (fallback for VMAT_STRIDED_SLP if #lanes == 1).
    2807              :         - Grouped strided gather (ditto but for #lanes > 1).
    2808              : 
    2809              :      For VMAT_ELEMENTWISE we can fold the load permutation into the
    2810              :      individual indices we access directly, eliding the permutation.
    2811              :      Strided gather only allows load permutations for the
    2812              :      single-element case.  */
    2813              : 
    2814      1313554 :   if (SLP_TREE_LOAD_PERMUTATION (slp_node).exists ()
    2815      1313554 :       && !(*memory_access_type == VMAT_ELEMENTWISE
    2816        52313 :            || (mat_gather_scatter_p (*memory_access_type)
    2817            0 :                && SLP_TREE_LANES (slp_node) == 1
    2818            0 :                && single_element_p)))
    2819              :     {
    2820        52313 :       if (!loop_vinfo)
    2821              :         {
    2822              :           /* In BB vectorization we may not actually use a loaded vector
    2823              :              accessing elements in excess of DR_GROUP_SIZE.  */
    2824        33293 :           stmt_vec_info group_info = SLP_TREE_SCALAR_STMTS (slp_node)[0];
    2825        33293 :           group_info = DR_GROUP_FIRST_ELEMENT (group_info);
    2826        33293 :           unsigned HOST_WIDE_INT nunits;
    2827        33293 :           unsigned j, k, maxk = 0;
    2828       115623 :           FOR_EACH_VEC_ELT (SLP_TREE_LOAD_PERMUTATION (slp_node), j, k)
    2829        82330 :             if (k > maxk)
    2830              :               maxk = k;
    2831        33293 :           tree vectype = SLP_TREE_VECTYPE (slp_node);
    2832        60787 :           if (!TYPE_VECTOR_SUBPARTS (vectype).is_constant (&nunits)
    2833        33293 :               || maxk >= (DR_GROUP_SIZE (group_info) & ~(nunits - 1)))
    2834              :             {
    2835         5799 :               if (dump_enabled_p ())
    2836           41 :                 dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2837              :                                  "BB vectorization with gaps at the end of "
    2838              :                                  "a load is not supported\n");
    2839      1420656 :               return false;
    2840              :             }
    2841              :         }
    2842              : 
    2843        46514 :       if (!perm_ok)
    2844              :         {
    2845         2410 :           if (dump_enabled_p ())
    2846            2 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION,
    2847              :                              vect_location,
    2848              :                              "unsupported load permutation\n");
    2849              :           return false;
    2850              :         }
    2851              : 
    2852        44104 :       *slp_perm = true;
    2853              :     }
    2854              : 
    2855              :   /* If we didn't end up using the permute, clear them in the costing structure
    2856              :      as well.  */
    2857      1305345 :   if (!*slp_perm)
    2858      1261241 :     ls->perms.truncate (0);
    2859              : 
    2860              :   return true;
    2861              : }
    2862              : 
    2863              : /* Return true if boolean argument at MASK_INDEX is suitable for vectorizing
    2864              :    conditional operation STMT_INFO.  When returning true, store the mask
    2865              :    in *MASK_NODE, the type of its definition in *MASK_DT_OUT and the type of
    2866              :    the vectorized mask in *MASK_VECTYPE_OUT.  */
    2867              : 
    2868              : static bool
    2869        12699 : vect_check_scalar_mask (vec_info *vinfo,
    2870              :                         slp_tree slp_node, unsigned mask_index,
    2871              :                         slp_tree *mask_node,
    2872              :                         vect_def_type *mask_dt_out, tree *mask_vectype_out)
    2873              : {
    2874        12699 :   enum vect_def_type mask_dt;
    2875        12699 :   tree mask_vectype;
    2876        12699 :   slp_tree mask_node_1;
    2877        12699 :   tree mask_;
    2878        12699 :   if (!vect_is_simple_use (vinfo, slp_node, mask_index,
    2879              :                            &mask_, &mask_node_1, &mask_dt, &mask_vectype))
    2880              :     {
    2881            0 :       if (dump_enabled_p ())
    2882            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2883              :                          "mask use not simple.\n");
    2884              :       return false;
    2885              :     }
    2886              : 
    2887        12699 :   if ((mask_dt == vect_constant_def || mask_dt == vect_external_def)
    2888        12699 :       && !VECT_SCALAR_BOOLEAN_TYPE_P (TREE_TYPE (mask_)))
    2889              :     {
    2890            0 :       if (dump_enabled_p ())
    2891            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2892              :                          "mask argument is not a boolean.\n");
    2893              :       return false;
    2894              :     }
    2895              : 
    2896        12699 :   tree vectype = SLP_TREE_VECTYPE (slp_node);
    2897        12699 :   if (!mask_vectype)
    2898           19 :     mask_vectype = get_mask_type_for_scalar_type (vinfo, TREE_TYPE (vectype),
    2899              :                                                   mask_node_1);
    2900              : 
    2901        12699 :   if (!mask_vectype || !VECTOR_BOOLEAN_TYPE_P (mask_vectype))
    2902              :     {
    2903            0 :       if (dump_enabled_p ())
    2904            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2905              :                          "could not find an appropriate vector mask type.\n");
    2906              :       return false;
    2907              :     }
    2908              : 
    2909        12699 :   if (maybe_ne (TYPE_VECTOR_SUBPARTS (mask_vectype),
    2910        25398 :                 TYPE_VECTOR_SUBPARTS (vectype)))
    2911              :     {
    2912            0 :       if (dump_enabled_p ())
    2913            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2914              :                          "vector mask type %T"
    2915              :                          " does not match vector data type %T.\n",
    2916              :                          mask_vectype, vectype);
    2917              : 
    2918              :       return false;
    2919              :     }
    2920              : 
    2921        12699 :   *mask_dt_out = mask_dt;
    2922        12699 :   *mask_vectype_out = mask_vectype;
    2923        12699 :   *mask_node = mask_node_1;
    2924        12699 :   return true;
    2925              : }
    2926              : 
    2927              : 
    2928              : /* Return true if stored value is suitable for vectorizing store
    2929              :    statement STMT_INFO.  When returning true, store the scalar stored
    2930              :    in *RHS and *RHS_NODE, the type of the definition in *RHS_DT_OUT,
    2931              :    the type of the vectorized store value in
    2932              :    *RHS_VECTYPE_OUT and the type of the store in *VLS_TYPE_OUT.  */
    2933              : 
    2934              : static bool
    2935      1387908 : vect_check_store_rhs (vec_info *vinfo, stmt_vec_info stmt_info,
    2936              :                       slp_tree slp_node, slp_tree *rhs_node,
    2937              :                       vect_def_type *rhs_dt_out, tree *rhs_vectype_out,
    2938              :                       vec_load_store_type *vls_type_out)
    2939              : {
    2940      1387908 :   int op_no = 0;
    2941      1387908 :   if (gcall *call = dyn_cast <gcall *> (stmt_info->stmt))
    2942              :     {
    2943         1924 :       if (gimple_call_internal_p (call)
    2944         1924 :           && internal_store_fn_p (gimple_call_internal_fn (call)))
    2945         1924 :         op_no = internal_fn_stored_value_index (gimple_call_internal_fn (call));
    2946              :     }
    2947      1387908 :   op_no = vect_slp_child_index_for_operand (stmt_info, op_no);
    2948              : 
    2949      1387908 :   enum vect_def_type rhs_dt;
    2950      1387908 :   tree rhs_vectype;
    2951      1387908 :   tree rhs;
    2952      1387908 :   if (!vect_is_simple_use (vinfo, slp_node, op_no,
    2953              :                            &rhs, rhs_node, &rhs_dt, &rhs_vectype))
    2954              :     {
    2955            0 :       if (dump_enabled_p ())
    2956            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2957              :                          "use not simple.\n");
    2958              :       return false;
    2959              :     }
    2960              : 
    2961              :   /* In the case this is a store from a constant make sure
    2962              :      native_encode_expr can handle it.  */
    2963      1387908 :   if (rhs_dt == vect_constant_def
    2964      1387908 :       && CONSTANT_CLASS_P (rhs) && native_encode_expr (rhs, NULL, 64) == 0)
    2965              :     {
    2966            0 :       if (dump_enabled_p ())
    2967            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2968              :                          "cannot encode constant as a byte sequence.\n");
    2969              :       return false;
    2970              :     }
    2971              : 
    2972      1387908 :   tree vectype = SLP_TREE_VECTYPE (slp_node);
    2973      1387908 :   if (rhs_vectype && !useless_type_conversion_p (vectype, rhs_vectype))
    2974              :     {
    2975           24 :       if (dump_enabled_p ())
    2976           24 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    2977              :                          "incompatible vector types.\n");
    2978              :       return false;
    2979              :     }
    2980              : 
    2981      1387884 :   *rhs_dt_out = rhs_dt;
    2982      1387884 :   *rhs_vectype_out = rhs_vectype;
    2983      1387884 :   if (rhs_dt == vect_constant_def || rhs_dt == vect_external_def)
    2984      1022720 :     *vls_type_out = VLS_STORE_INVARIANT;
    2985              :   else
    2986       365164 :     *vls_type_out = VLS_STORE;
    2987              :   return true;
    2988              : }
    2989              : 
    2990              : /* Build an all-ones vector mask of type MASKTYPE while vectorizing STMT_INFO.
    2991              :    Note that we support masks with floating-point type, in which case the
    2992              :    floats are interpreted as a bitmask.  */
    2993              : 
    2994              : static tree
    2995          147 : vect_build_all_ones_mask (vec_info *vinfo,
    2996              :                           stmt_vec_info stmt_info, tree masktype)
    2997              : {
    2998          147 :   if (TREE_CODE (masktype) == INTEGER_TYPE)
    2999           98 :     return build_int_cst (masktype, -1);
    3000           49 :   else if (VECTOR_BOOLEAN_TYPE_P (masktype)
    3001           98 :            || TREE_CODE (TREE_TYPE (masktype)) == INTEGER_TYPE)
    3002              :     {
    3003            0 :       tree mask = build_int_cst (TREE_TYPE (masktype), -1);
    3004            0 :       mask = build_vector_from_val (masktype, mask);
    3005            0 :       return vect_init_vector (vinfo, stmt_info, mask, masktype, NULL);
    3006              :     }
    3007           49 :   else if (SCALAR_FLOAT_TYPE_P (TREE_TYPE (masktype)))
    3008              :     {
    3009              :       REAL_VALUE_TYPE r;
    3010              :       long tmp[6];
    3011          343 :       for (int j = 0; j < 6; ++j)
    3012          294 :         tmp[j] = -1;
    3013           49 :       real_from_target (&r, tmp, TYPE_MODE (TREE_TYPE (masktype)));
    3014           49 :       tree mask = build_real (TREE_TYPE (masktype), r);
    3015           49 :       mask = build_vector_from_val (masktype, mask);
    3016           49 :       return vect_init_vector (vinfo, stmt_info, mask, masktype, NULL);
    3017              :     }
    3018            0 :   gcc_unreachable ();
    3019              : }
    3020              : 
    3021              : /* Build an all-zero merge value of type VECTYPE while vectorizing
    3022              :    STMT_INFO as a gather load.  */
    3023              : 
    3024              : static tree
    3025          146 : vect_build_zero_merge_argument (vec_info *vinfo,
    3026              :                                 stmt_vec_info stmt_info, tree vectype)
    3027              : {
    3028          146 :   tree merge;
    3029          146 :   if (TREE_CODE (TREE_TYPE (vectype)) == INTEGER_TYPE)
    3030           41 :     merge = build_int_cst (TREE_TYPE (vectype), 0);
    3031          105 :   else if (SCALAR_FLOAT_TYPE_P (TREE_TYPE (vectype)))
    3032              :     {
    3033              :       REAL_VALUE_TYPE r;
    3034              :       long tmp[6];
    3035          735 :       for (int j = 0; j < 6; ++j)
    3036          630 :         tmp[j] = 0;
    3037          105 :       real_from_target (&r, tmp, TYPE_MODE (TREE_TYPE (vectype)));
    3038          105 :       merge = build_real (TREE_TYPE (vectype), r);
    3039              :     }
    3040              :   else
    3041            0 :     gcc_unreachable ();
    3042          146 :   merge = build_vector_from_val (vectype, merge);
    3043          146 :   return vect_init_vector (vinfo, stmt_info, merge, vectype, NULL);
    3044              : }
    3045              : 
    3046              : /* Return the corresponding else value for an else value constant
    3047              :    ELSVAL with type TYPE.  */
    3048              : 
    3049              : tree
    3050         2062 : vect_get_mask_load_else (int elsval, tree type)
    3051              : {
    3052         2062 :   tree els;
    3053         2062 :   if (elsval == MASK_LOAD_ELSE_UNDEFINED)
    3054              :     {
    3055            0 :       tree tmp = create_tmp_var (type);
    3056              :       /* No need to warn about anything.  */
    3057            0 :       TREE_NO_WARNING (tmp) = 1;
    3058            0 :       els = get_or_create_ssa_default_def (cfun, tmp);
    3059              :     }
    3060         2062 :   else if (elsval == MASK_LOAD_ELSE_M1)
    3061            0 :     els = build_minus_one_cst (type);
    3062         2062 :   else if (elsval == MASK_LOAD_ELSE_ZERO)
    3063         2062 :     els = build_zero_cst (type);
    3064              :   else
    3065            0 :     gcc_unreachable ();
    3066              : 
    3067         2062 :   return els;
    3068              : }
    3069              : 
    3070              : /* Build a gather load call while vectorizing STMT_INFO.  Insert new
    3071              :    instructions before GSI and add them to VEC_STMT.  GS_INFO describes
    3072              :    the gather load operation.  If the load is conditional, MASK is the
    3073              :    vectorized condition, otherwise MASK is null.  PTR is the base
    3074              :    pointer and OFFSET is the vectorized offset.  */
    3075              : 
    3076              : static gimple *
    3077          329 : vect_build_one_gather_load_call (vec_info *vinfo, stmt_vec_info stmt_info,
    3078              :                                  slp_tree slp_node, tree vectype,
    3079              :                                  gimple_stmt_iterator *gsi, tree decl,
    3080              :                                  tree ptr, tree offset, tree mask)
    3081              : {
    3082          329 :   tree arglist = TYPE_ARG_TYPES (TREE_TYPE (decl));
    3083          329 :   tree rettype = TREE_TYPE (TREE_TYPE (decl));
    3084          329 :   tree srctype = TREE_VALUE (arglist); arglist = TREE_CHAIN (arglist);
    3085          329 :   /* ptrtype */ arglist = TREE_CHAIN (arglist);
    3086          329 :   tree idxtype = TREE_VALUE (arglist); arglist = TREE_CHAIN (arglist);
    3087          329 :   tree masktype = TREE_VALUE (arglist); arglist = TREE_CHAIN (arglist);
    3088          329 :   tree scaletype = TREE_VALUE (arglist);
    3089          329 :   tree var;
    3090          329 :   gcc_checking_assert (types_compatible_p (srctype, rettype)
    3091              :                        && (!mask
    3092              :                            || TREE_CODE (masktype) == INTEGER_TYPE
    3093              :                            || types_compatible_p (srctype, masktype)));
    3094              : 
    3095          329 :   tree op = offset;
    3096          329 :   if (!useless_type_conversion_p (idxtype, TREE_TYPE (op)))
    3097              :     {
    3098           91 :       gcc_assert (known_eq (TYPE_VECTOR_SUBPARTS (TREE_TYPE (op)),
    3099              :                             TYPE_VECTOR_SUBPARTS (idxtype)));
    3100           91 :       var = vect_get_new_ssa_name (idxtype, vect_simple_var);
    3101           91 :       op = build1 (VIEW_CONVERT_EXPR, idxtype, op);
    3102           91 :       gassign *new_stmt = gimple_build_assign (var, VIEW_CONVERT_EXPR, op);
    3103           91 :       vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    3104           91 :       op = var;
    3105              :     }
    3106              : 
    3107          329 :   tree src_op = NULL_TREE;
    3108          329 :   tree mask_op = NULL_TREE;
    3109          329 :   if (mask)
    3110              :     {
    3111          183 :       if (!useless_type_conversion_p (masktype, TREE_TYPE (mask)))
    3112              :         {
    3113          183 :           tree utype, optype = TREE_TYPE (mask);
    3114          183 :           if (VECTOR_TYPE_P (masktype)
    3115          183 :               || TYPE_MODE (masktype) == TYPE_MODE (optype))
    3116              :             utype = masktype;
    3117              :           else
    3118            6 :             utype = lang_hooks.types.type_for_mode (TYPE_MODE (optype), 1);
    3119          183 :           var = vect_get_new_ssa_name (utype, vect_scalar_var);
    3120          183 :           tree mask_arg = build1 (VIEW_CONVERT_EXPR, utype, mask);
    3121          183 :           gassign *new_stmt
    3122          183 :               = gimple_build_assign (var, VIEW_CONVERT_EXPR, mask_arg);
    3123          183 :           vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    3124          183 :           mask_arg = var;
    3125          183 :           if (!useless_type_conversion_p (masktype, utype))
    3126              :             {
    3127            6 :               gcc_assert (TYPE_PRECISION (utype)
    3128              :                           <= TYPE_PRECISION (masktype));
    3129            6 :               var = vect_get_new_ssa_name (masktype, vect_scalar_var);
    3130            6 :               new_stmt = gimple_build_assign (var, NOP_EXPR, mask_arg);
    3131            6 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    3132            6 :               mask_arg = var;
    3133              :             }
    3134          183 :           src_op = build_zero_cst (srctype);
    3135          183 :           mask_op = mask_arg;
    3136              :         }
    3137              :       else
    3138              :         {
    3139              :           src_op = mask;
    3140              :           mask_op = mask;
    3141              :         }
    3142              :     }
    3143              :   else
    3144              :     {
    3145          146 :       src_op = vect_build_zero_merge_argument (vinfo, stmt_info, rettype);
    3146          146 :       mask_op = vect_build_all_ones_mask (vinfo, stmt_info, masktype);
    3147              :     }
    3148              : 
    3149          329 :   tree scale = build_int_cst (scaletype, SLP_TREE_GS_SCALE (slp_node));
    3150          329 :   gimple *new_stmt = gimple_build_call (decl, 5, src_op, ptr, op,
    3151              :                                         mask_op, scale);
    3152              : 
    3153          329 :   if (!useless_type_conversion_p (vectype, rettype))
    3154              :     {
    3155           52 :       gcc_assert (known_eq (TYPE_VECTOR_SUBPARTS (vectype),
    3156              :                             TYPE_VECTOR_SUBPARTS (rettype)));
    3157           52 :       op = vect_get_new_ssa_name (rettype, vect_simple_var);
    3158           52 :       gimple_call_set_lhs (new_stmt, op);
    3159           52 :       vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    3160           52 :       op = build1 (VIEW_CONVERT_EXPR, vectype, op);
    3161           52 :       new_stmt = gimple_build_assign (NULL_TREE, VIEW_CONVERT_EXPR, op);
    3162              :     }
    3163              : 
    3164          329 :   return new_stmt;
    3165              : }
    3166              : 
    3167              : /* Build a scatter store call while vectorizing STMT_INFO.  Insert new
    3168              :    instructions before GSI.  GS_INFO describes the scatter store operation.
    3169              :    PTR is the base pointer, OFFSET the vectorized offsets and OPRND the
    3170              :    vectorized data to store.
    3171              :    If the store is conditional, MASK is the vectorized condition, otherwise
    3172              :    MASK is null.  */
    3173              : 
    3174              : static gimple *
    3175          161 : vect_build_one_scatter_store_call (vec_info *vinfo, stmt_vec_info stmt_info,
    3176              :                                    slp_tree slp_node,
    3177              :                                    gimple_stmt_iterator *gsi,
    3178              :                                    tree decl,
    3179              :                                    tree ptr, tree offset, tree oprnd, tree mask)
    3180              : {
    3181          161 :   tree rettype = TREE_TYPE (TREE_TYPE (decl));
    3182          161 :   tree arglist = TYPE_ARG_TYPES (TREE_TYPE (decl));
    3183          161 :   /* tree ptrtype = TREE_VALUE (arglist); */ arglist = TREE_CHAIN (arglist);
    3184          161 :   tree masktype = TREE_VALUE (arglist); arglist = TREE_CHAIN (arglist);
    3185          161 :   tree idxtype = TREE_VALUE (arglist); arglist = TREE_CHAIN (arglist);
    3186          161 :   tree srctype = TREE_VALUE (arglist); arglist = TREE_CHAIN (arglist);
    3187          161 :   tree scaletype = TREE_VALUE (arglist);
    3188          161 :   gcc_checking_assert (TREE_CODE (masktype) == INTEGER_TYPE
    3189              :                        && TREE_CODE (rettype) == VOID_TYPE);
    3190              : 
    3191          161 :   tree mask_arg = NULL_TREE;
    3192          161 :   if (mask)
    3193              :     {
    3194          110 :       mask_arg = mask;
    3195          110 :       tree optype = TREE_TYPE (mask_arg);
    3196          110 :       tree utype;
    3197          110 :       if (TYPE_MODE (masktype) == TYPE_MODE (optype))
    3198              :         utype = masktype;
    3199              :       else
    3200            8 :         utype = lang_hooks.types.type_for_mode (TYPE_MODE (optype), 1);
    3201          110 :       tree var = vect_get_new_ssa_name (utype, vect_scalar_var);
    3202          110 :       mask_arg = build1 (VIEW_CONVERT_EXPR, utype, mask_arg);
    3203          110 :       gassign *new_stmt
    3204          110 :         = gimple_build_assign (var, VIEW_CONVERT_EXPR, mask_arg);
    3205          110 :       vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    3206          110 :       mask_arg = var;
    3207          110 :       if (!useless_type_conversion_p (masktype, utype))
    3208              :         {
    3209            8 :           gcc_assert (TYPE_PRECISION (utype) <= TYPE_PRECISION (masktype));
    3210            8 :           tree var = vect_get_new_ssa_name (masktype, vect_scalar_var);
    3211            8 :           new_stmt = gimple_build_assign (var, NOP_EXPR, mask_arg);
    3212            8 :           vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    3213            8 :           mask_arg = var;
    3214              :         }
    3215              :     }
    3216              :   else
    3217              :     {
    3218           51 :       mask_arg = build_int_cst (masktype, -1);
    3219           51 :       mask_arg = vect_init_vector (vinfo, stmt_info, mask_arg, masktype, NULL);
    3220              :     }
    3221              : 
    3222          161 :   tree src = oprnd;
    3223          161 :   if (!useless_type_conversion_p (srctype, TREE_TYPE (src)))
    3224              :     {
    3225            0 :       gcc_assert (known_eq (TYPE_VECTOR_SUBPARTS (TREE_TYPE (src)),
    3226              :                             TYPE_VECTOR_SUBPARTS (srctype)));
    3227            0 :       tree var = vect_get_new_ssa_name (srctype, vect_simple_var);
    3228            0 :       src = build1 (VIEW_CONVERT_EXPR, srctype, src);
    3229            0 :       gassign *new_stmt = gimple_build_assign (var, VIEW_CONVERT_EXPR, src);
    3230            0 :       vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    3231            0 :       src = var;
    3232              :     }
    3233              : 
    3234          161 :   tree op = offset;
    3235          161 :   if (!useless_type_conversion_p (idxtype, TREE_TYPE (op)))
    3236              :     {
    3237           16 :       gcc_assert (known_eq (TYPE_VECTOR_SUBPARTS (TREE_TYPE (op)),
    3238              :                             TYPE_VECTOR_SUBPARTS (idxtype)));
    3239           16 :       tree var = vect_get_new_ssa_name (idxtype, vect_simple_var);
    3240           16 :       op = build1 (VIEW_CONVERT_EXPR, idxtype, op);
    3241           16 :       gassign *new_stmt = gimple_build_assign (var, VIEW_CONVERT_EXPR, op);
    3242           16 :       vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    3243           16 :       op = var;
    3244              :     }
    3245              : 
    3246          161 :   tree scale = build_int_cst (scaletype, SLP_TREE_GS_SCALE (slp_node));
    3247          161 :   gcall *new_stmt
    3248          161 :     = gimple_build_call (decl, 5, ptr, mask_arg, op, src, scale);
    3249          161 :   return new_stmt;
    3250              : }
    3251              : 
    3252              : /* Prepare the base and offset in GS_INFO for vectorization.
    3253              :    Set *DATAREF_PTR to the loop-invariant base address and *VEC_OFFSET
    3254              :    to the vectorized offset argument for the first copy of STMT_INFO.
    3255              :    STMT_INFO is the statement described by GS_INFO and LOOP is the
    3256              :    containing loop.  */
    3257              : 
    3258              : static void
    3259         1392 : vect_get_gather_scatter_ops (class loop *loop, slp_tree slp_node,
    3260              :                              tree *dataref_ptr, vec<tree> *vec_offset)
    3261              : {
    3262         1392 :   gimple_seq stmts = NULL;
    3263         1392 :   *dataref_ptr = force_gimple_operand (SLP_TREE_GS_BASE (slp_node),
    3264              :                                        &stmts, true, NULL_TREE);
    3265         1392 :   if (stmts != NULL)
    3266              :     {
    3267         1167 :       basic_block new_bb;
    3268         1167 :       edge pe = loop_preheader_edge (loop);
    3269         1167 :       new_bb = gsi_insert_seq_on_edge_immediate (pe, stmts);
    3270         1167 :       gcc_assert (!new_bb);
    3271              :     }
    3272         1392 :   vect_get_slp_defs (SLP_TREE_CHILDREN (slp_node)[0], vec_offset);
    3273         1392 : }
    3274              : 
    3275              : /* Prepare to implement a grouped or strided load or store using
    3276              :    the gather load or scatter store operation described by GS_INFO.
    3277              :    STMT_INFO is the load or store statement.
    3278              : 
    3279              :    Set *DR_STEP to the amount that should be added to pointer base address
    3280              :    to get to the next iteration's base address.
    3281              :    Set *DR_BUMP to the amount that should be added to the base
    3282              :    address after each copy of the vectorized statement in a grouped read.
    3283              :    Set *VEC_OFFSET to an invariant offset vector in which element I has the
    3284              :    value I * DR_STEP / SCALE.  */
    3285              : 
    3286              : static void
    3287            0 : vect_get_strided_load_store_ops (stmt_vec_info stmt_info, slp_tree node,
    3288              :                                  tree vectype, tree offset_vectype,
    3289              :                                  loop_vec_info loop_vinfo,
    3290              :                                  gimple_stmt_iterator *gsi,
    3291              :                                  tree *dr_step, tree *dr_bump,
    3292              :                                  tree *vec_offset)
    3293              : {
    3294            0 :   struct data_reference *dr = STMT_VINFO_DATA_REF (stmt_info);
    3295              : 
    3296            0 :   tree dr_step_temp
    3297            0 :     = size_binop (MULT_EXPR,
    3298              :                   fold_convert (sizetype, unshare_expr (DR_STEP (dr))),
    3299              :                   LOOP_VINFO_IV_INCREMENT (loop_vinfo));
    3300            0 :   *dr_step = LOOP_VINFO_IV_INCREMENT_INVARIANT_P (loop_vinfo)
    3301            0 :              ? cse_and_gimplify_to_preheader (loop_vinfo, dr_step_temp)
    3302            0 :              : force_gimple_operand_gsi (gsi, dr_step_temp, false, NULL_TREE,
    3303              :                                          true, GSI_SAME_STMT);
    3304            0 :   tree bump = size_binop (MULT_EXPR,
    3305              :                           fold_convert (sizetype, unshare_expr (DR_STEP (dr))),
    3306              :                           size_int (TYPE_VECTOR_SUBPARTS (vectype)));
    3307            0 :   *dr_bump = cse_and_gimplify_to_preheader (loop_vinfo, bump);
    3308              : 
    3309            0 :   internal_fn ifn
    3310            0 :     = DR_IS_READ (dr) ? IFN_MASK_LEN_STRIDED_LOAD : IFN_MASK_LEN_STRIDED_STORE;
    3311            0 :   if (direct_internal_fn_supported_p (ifn, vectype, OPTIMIZE_FOR_SPEED))
    3312              :     {
    3313            0 :       *vec_offset = cse_and_gimplify_to_preheader (loop_vinfo,
    3314              :                                                    unshare_expr (DR_STEP (dr)));
    3315            0 :       return;
    3316              :     }
    3317              : 
    3318              :   /* The offset given in GS_INFO can have pointer type, so use the element
    3319              :      type of the vector instead.  */
    3320            0 :   tree offset_type = TREE_TYPE (offset_vectype);
    3321              : 
    3322              :   /* Calculate X = DR_STEP / SCALE and convert it to the appropriate type.  */
    3323            0 :   tree step = size_binop (EXACT_DIV_EXPR, unshare_expr (DR_STEP (dr)),
    3324              :                           ssize_int (SLP_TREE_GS_SCALE (node)));
    3325            0 :   step = fold_convert (offset_type, step);
    3326              : 
    3327              :   /* Create {0, X, X*2, X*3, ...}.  */
    3328            0 :   tree offset = fold_build2 (VEC_SERIES_EXPR, offset_vectype,
    3329              :                              build_zero_cst (offset_type), step);
    3330            0 :   *vec_offset = cse_and_gimplify_to_preheader (loop_vinfo, offset);
    3331              : }
    3332              : 
    3333              : /* Return the amount that should be added to a vector pointer, represented by
    3334              :    DR_INFO, to increment to the next vectorized iteration.  */
    3335              : 
    3336              : static tree
    3337       705161 : vect_get_data_ptr_step (vec_info *vinfo, dr_vec_info *dr_info,
    3338              :                         vect_memory_access_type memory_access_type)
    3339              : {
    3340       705161 :   if (memory_access_type == VMAT_INVARIANT)
    3341            0 :     return size_zero_node;
    3342              : 
    3343       705161 :   loop_vec_info loop_vinfo = dyn_cast<loop_vec_info> (vinfo);
    3344              : 
    3345              :   /* For BB SLP there is no next iteration.  */
    3346       705161 :   if (!loop_vinfo)
    3347       562510 :     return build_zero_cst (sizetype);
    3348              : 
    3349       142651 :   tree step = vect_dr_behavior (loop_vinfo, dr_info)->step;
    3350              : 
    3351              :   /* gather/scatter never reach here.  */
    3352       142651 :   gcc_assert (!mat_gather_scatter_p (memory_access_type));
    3353              : 
    3354       142651 :   tree iv_increment = LOOP_VINFO_IV_INCREMENT (loop_vinfo);
    3355              : 
    3356       142651 :   return fold_build2 (MULT_EXPR, sizetype, iv_increment,
    3357              :                       fold_convert (sizetype, step));
    3358              : }
    3359              : 
    3360              : /* Return the amount that should be added to a vector pointer to move
    3361              :    to the next or previous copy of AGGR_TYPE.  DR_INFO is the data reference
    3362              :    being vectorized and MEMORY_ACCESS_TYPE describes the type of
    3363              :    vectorization.  */
    3364              : 
    3365              : static tree
    3366       705677 : vect_get_data_ptr_bump (vec_info *vinfo,
    3367              :                         dr_vec_info *dr_info, tree aggr_type,
    3368              :                         vect_memory_access_type memory_access_type)
    3369              : {
    3370       705677 :   if (memory_access_type == VMAT_INVARIANT)
    3371            0 :     return size_zero_node;
    3372              : 
    3373       705677 :   loop_vec_info loop_vinfo = dyn_cast<loop_vec_info> (vinfo);
    3374              :   /* We do not support SLP loads where num_vec != 1 with SELECT_VL so this value
    3375              :      should never be needed.  */
    3376       143167 :   if (loop_vinfo && LOOP_VINFO_USING_SELECT_VL_P (loop_vinfo))
    3377              :     return NULL_TREE;
    3378              : 
    3379       705677 :   tree iv_step = TYPE_SIZE_UNIT (aggr_type);
    3380       705677 :   tree step = vect_dr_behavior (vinfo, dr_info)->step;
    3381       705677 :   if (tree_int_cst_sgn (step) == -1)
    3382         2983 :     iv_step = fold_build1 (NEGATE_EXPR, TREE_TYPE (iv_step), iv_step);
    3383              :   return iv_step;
    3384              : }
    3385              : 
    3386              : /* Check and perform vectorization of BUILT_IN_BSWAP{16,32,64,128}.  */
    3387              : 
    3388              : static bool
    3389          218 : vectorizable_bswap (vec_info *vinfo,
    3390              :                     stmt_vec_info stmt_info, gimple_stmt_iterator *gsi,
    3391              :                     slp_tree slp_node,
    3392              :                     slp_tree *slp_op,
    3393              :                     tree vectype_in, stmt_vector_for_cost *cost_vec)
    3394              : {
    3395          218 :   tree vectype = SLP_TREE_VECTYPE (slp_node);
    3396          218 :   poly_uint64 nunits = TYPE_VECTOR_SUBPARTS (vectype);
    3397          218 :   vect_call_data _data{};
    3398          218 :   vect_call_data &data = slp_node->get_data (_data);
    3399              : 
    3400          218 :   if (TYPE_SIZE (vectype_in) != TYPE_SIZE (vectype))
    3401              :     {
    3402            0 :       if (dump_enabled_p ())
    3403            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    3404              :                          "mismatched vector sizes %T and %T\n",
    3405              :                          vectype_in, vectype);
    3406              :       return false;
    3407              :     }
    3408              : 
    3409          218 :   tree char_vectype = get_same_sized_vectype (char_type_node, vectype_in);
    3410          218 :   if (! char_vectype)
    3411              :     return false;
    3412              : 
    3413          218 :   poly_uint64 num_bytes = TYPE_VECTOR_SUBPARTS (char_vectype);
    3414          218 :   unsigned word_bytes;
    3415          436 :   if (!constant_multiple_p (num_bytes, nunits, &word_bytes))
    3416              :     return false;
    3417              : 
    3418              :   /* The encoding uses one stepped pattern for each byte in the word.  */
    3419          218 :   vec_perm_builder elts (num_bytes, word_bytes, 3);
    3420         1090 :   for (unsigned i = 0; i < 3; ++i)
    3421         3726 :     for (unsigned j = 0; j < word_bytes; ++j)
    3422         3072 :       elts.quick_push ((i + 1) * word_bytes - j - 1);
    3423              : 
    3424          218 :   vec_perm_indices indices (elts, 1, num_bytes);
    3425          218 :   machine_mode vmode = TYPE_MODE (char_vectype);
    3426          218 :   if (!can_vec_perm_const_p (vmode, vmode, indices))
    3427              :     return false;
    3428              : 
    3429          115 :   if (cost_vec)
    3430              :     {
    3431           88 :       if (!vect_maybe_update_slp_op_vectype (slp_op[0], vectype_in))
    3432              :         {
    3433            0 :           if (dump_enabled_p ())
    3434            0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    3435              :                              "incompatible vector types for invariants\n");
    3436              :           return false;
    3437              :         }
    3438              : 
    3439           88 :       unsigned int vec_num = vect_get_num_copies (vinfo, slp_node);
    3440              :       /* Store the permute in the node data.  */
    3441           88 :       data.perms.safe_push ({vec_perm_indices_to_tree (char_vectype, indices),
    3442           88 :                              vec_num, indices.ninputs ()});
    3443              : 
    3444           88 :       SLP_TREE_TYPE (slp_node) = call_vec_info_type;
    3445           88 :       DUMP_VECT_SCOPE ("vectorizable_bswap");
    3446           88 :       record_stmt_cost (cost_vec,
    3447              :                         1, vector_stmt, slp_node, 0, vect_prologue);
    3448           88 :       record_stmt_cost (cost_vec, vec_num,
    3449              :                         vec_perm, slp_node, char_vectype, 0, vect_body);
    3450           88 :       slp_node->data = new vect_call_data (std::move (data));
    3451           88 :       return true;
    3452              :     }
    3453              : 
    3454              :   /* Get the permute that we created during costing.  */
    3455           27 :   gcc_assert (data.perms.length () == 1);
    3456           27 :   tree bswap_vconst = data.perms[0].mask;
    3457              : 
    3458              :   /* Transform.  */
    3459           27 :   vec<tree> vec_oprnds = vNULL;
    3460           27 :   vect_get_vec_defs (vinfo, slp_node, true, &vec_oprnds);
    3461              :   /* Arguments are ready. create the new vector stmt.  */
    3462           27 :   unsigned i;
    3463           27 :   tree vop;
    3464           81 :   FOR_EACH_VEC_ELT (vec_oprnds, i, vop)
    3465              :     {
    3466           27 :       gimple *new_stmt;
    3467           27 :       tree tem = make_ssa_name (char_vectype);
    3468           27 :       new_stmt = gimple_build_assign (tem, build1 (VIEW_CONVERT_EXPR,
    3469              :                                                    char_vectype, vop));
    3470           27 :       vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    3471           27 :       tree tem2 = make_ssa_name (char_vectype);
    3472           27 :       new_stmt = gimple_build_assign (tem2, VEC_PERM_EXPR,
    3473              :                                       tem, tem, bswap_vconst);
    3474           27 :       vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    3475           27 :       tem = make_ssa_name (vectype);
    3476           27 :       new_stmt = gimple_build_assign (tem, build1 (VIEW_CONVERT_EXPR,
    3477              :                                                    vectype, tem2));
    3478           27 :       vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    3479           27 :       slp_node->push_vec_def (new_stmt);
    3480              :     }
    3481              : 
    3482           27 :   vec_oprnds.release ();
    3483           27 :   return true;
    3484          218 : }
    3485              : 
    3486              : /* Return true if vector types VECTYPE_IN and VECTYPE_OUT have
    3487              :    integer elements and if we can narrow VECTYPE_IN to VECTYPE_OUT
    3488              :    in a single step.  On success, store the binary pack code in
    3489              :    *CONVERT_CODE.  */
    3490              : 
    3491              : static bool
    3492          197 : simple_integer_narrowing (tree vectype_out, tree vectype_in,
    3493              :                           code_helper *convert_code)
    3494              : {
    3495          394 :   if (!INTEGRAL_TYPE_P (TREE_TYPE (vectype_out))
    3496          394 :       || !INTEGRAL_TYPE_P (TREE_TYPE (vectype_in)))
    3497              :     return false;
    3498              : 
    3499           81 :   code_helper code;
    3500           81 :   int multi_step_cvt = 0;
    3501           81 :   auto_vec <tree, 8> interm_types;
    3502          121 :   if (!supportable_narrowing_operation (NOP_EXPR, vectype_out, vectype_in,
    3503              :                                         &code, &multi_step_cvt, &interm_types)
    3504           81 :       || multi_step_cvt)
    3505              :     return false;
    3506              : 
    3507           41 :   *convert_code = code;
    3508           41 :   return true;
    3509           81 : }
    3510              : 
    3511              : /* Function vectorizable_call.
    3512              : 
    3513              :    Check if STMT_INFO performs a function call that can be vectorized.
    3514              :    If COST_VEC is passed, calculate costs but don't change anything,
    3515              :    otherwise, vectorize STMT_INFO: create a vectorized stmt to replace
    3516              :    it, and insert it at GSI.
    3517              :    Return true if STMT_INFO is vectorizable in this way.  */
    3518              : 
    3519              : static bool
    3520      2682848 : vectorizable_call (vec_info *vinfo,
    3521              :                    stmt_vec_info stmt_info, gimple_stmt_iterator *gsi,
    3522              :                    slp_tree slp_node,
    3523              :                    stmt_vector_for_cost *cost_vec)
    3524              : {
    3525      2682848 :   gcall *stmt;
    3526      2682848 :   tree vec_dest;
    3527      2682848 :   tree scalar_dest;
    3528      2682848 :   tree vec_oprnd0 = NULL_TREE;
    3529      2682848 :   tree vectype_out, vectype_in;
    3530      2682848 :   poly_uint64 nunits_in;
    3531      2682848 :   poly_uint64 nunits_out;
    3532      2682848 :   loop_vec_info loop_vinfo = dyn_cast <loop_vec_info> (vinfo);
    3533      2682848 :   bb_vec_info bb_vinfo = dyn_cast <bb_vec_info> (vinfo);
    3534      2682848 :   tree fndecl, new_temp, rhs_type;
    3535      2682848 :   enum vect_def_type dt[5]
    3536              :     = { vect_unknown_def_type, vect_unknown_def_type, vect_unknown_def_type,
    3537              :         vect_unknown_def_type, vect_unknown_def_type };
    3538      2682848 :   tree vectypes[ARRAY_SIZE (dt)] = {};
    3539      2682848 :   slp_tree slp_op[ARRAY_SIZE (dt)] = {};
    3540      2682848 :   auto_vec<tree, 8> vargs;
    3541      2682848 :   enum { NARROW, NONE, WIDEN } modifier;
    3542      2682848 :   size_t i, nargs;
    3543      2682848 :   tree clz_ctz_arg1 = NULL_TREE;
    3544              : 
    3545      2682848 :   if (!STMT_VINFO_RELEVANT_P (stmt_info) && !bb_vinfo)
    3546              :     return false;
    3547              : 
    3548      2682848 :   if (STMT_VINFO_DEF_TYPE (stmt_info) != vect_internal_def
    3549       246817 :       && cost_vec)
    3550              :     return false;
    3551              : 
    3552              :   /* Is STMT_INFO a vectorizable call?   */
    3553      2711808 :   stmt = dyn_cast <gcall *> (stmt_info->stmt);
    3554        28960 :   if (!stmt)
    3555              :     return false;
    3556              : 
    3557        28960 :   if (gimple_call_internal_p (stmt)
    3558        28960 :       && (internal_load_fn_p (gimple_call_internal_fn (stmt))
    3559        18131 :           || internal_store_fn_p (gimple_call_internal_fn (stmt))))
    3560              :     /* Handled by vectorizable_load and vectorizable_store.  */
    3561              :     return false;
    3562              : 
    3563        25385 :   if (gimple_call_lhs (stmt) == NULL_TREE
    3564        25385 :       || TREE_CODE (gimple_call_lhs (stmt)) != SSA_NAME)
    3565              :     return false;
    3566              : 
    3567        25371 :   gcc_checking_assert (!stmt_can_throw_internal (cfun, stmt));
    3568              : 
    3569        25371 :   vectype_out = SLP_TREE_VECTYPE (slp_node);
    3570              : 
    3571              :   /* Process function arguments.  */
    3572        25371 :   rhs_type = NULL_TREE;
    3573        25371 :   vectype_in = NULL_TREE;
    3574        25371 :   nargs = gimple_call_num_args (stmt);
    3575              : 
    3576              :   /* Bail out if the function has more than four arguments, we do not have
    3577              :      interesting builtin functions to vectorize with more than two arguments
    3578              :      except for fma (cond_fma has more).  No arguments is also not good.  */
    3579        25371 :   if (nargs == 0 || nargs > 5)
    3580              :     return false;
    3581              : 
    3582              :   /* Ignore the arguments of IFN_GOMP_SIMD_LANE, they are magic.  */
    3583        25299 :   combined_fn cfn = gimple_call_combined_fn (stmt);
    3584        25299 :   if (cfn == CFN_GOMP_SIMD_LANE)
    3585              :     {
    3586         3755 :       nargs = 0;
    3587         3755 :       rhs_type = unsigned_type_node;
    3588              :     }
    3589              :   /* Similarly pretend IFN_CLZ and IFN_CTZ only has one argument, the second
    3590              :      argument just says whether it is well-defined at zero or not and what
    3591              :      value should be returned for it.  */
    3592        25299 :   if ((cfn == CFN_CLZ || cfn == CFN_CTZ) && nargs == 2)
    3593              :     {
    3594          243 :       nargs = 1;
    3595          243 :       clz_ctz_arg1 = gimple_call_arg (stmt, 1);
    3596              :     }
    3597              : 
    3598        25299 :   int mask_opno = -1;
    3599        25299 :   if (internal_fn_p (cfn))
    3600              :     {
    3601              :       /* We can only handle direct internal masked calls here,
    3602              :          vectorizable_simd_clone_call is for the rest.  */
    3603        20442 :       if (cfn == CFN_MASK_CALL)
    3604              :         return false;
    3605        20271 :       mask_opno = internal_fn_mask_index (as_internal_fn (cfn));
    3606              :     }
    3607              : 
    3608        76238 :   for (i = 0; i < nargs; i++)
    3609              :     {
    3610        53228 :       if ((int) i == mask_opno)
    3611              :         {
    3612         7926 :           if (!vect_check_scalar_mask (vinfo, slp_node, mask_opno,
    3613              :                                        &slp_op[i], &dt[i], &vectypes[i]))
    3614              :             return false;
    3615         7926 :           continue;
    3616              :         }
    3617              : 
    3618        45302 :       if (!vect_is_simple_use (vinfo, slp_node,
    3619              :                                i, &slp_op[i], &dt[i], &vectypes[i]))
    3620              :         {
    3621            0 :           if (dump_enabled_p ())
    3622            0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    3623              :                              "use not simple.\n");
    3624              :           return false;
    3625              :         }
    3626              : 
    3627              :       /* We can only handle calls with arguments of the same type.  */
    3628        45302 :       tree op = gimple_call_arg (stmt, i);
    3629        45302 :       if (rhs_type
    3630        45302 :           && !types_compatible_p (rhs_type, TREE_TYPE (op)))
    3631              :         {
    3632         2118 :           if (dump_enabled_p ())
    3633          226 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    3634              :                              "argument types differ.\n");
    3635              :           return false;
    3636              :         }
    3637        43184 :       if (!rhs_type)
    3638        21373 :         rhs_type = TREE_TYPE (op);
    3639              : 
    3640        43184 :       if (!vectype_in)
    3641        22704 :         vectype_in = vectypes[i];
    3642        20480 :       else if (vectypes[i]
    3643        20480 :                && !types_compatible_p (vectypes[i], vectype_in))
    3644              :         {
    3645            0 :           if (dump_enabled_p ())
    3646            0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    3647              :                              "argument vector types differ.\n");
    3648              :           return false;
    3649              :         }
    3650              :     }
    3651              :   /* If all arguments are external or constant defs, infer the vector type
    3652              :      from the scalar type.  */
    3653        23010 :   if (!vectype_in)
    3654         6405 :     vectype_in = get_vectype_for_scalar_type (vinfo, rhs_type, slp_node);
    3655        23010 :   if (!cost_vec)
    3656         4920 :     gcc_assert (vectype_in);
    3657        18090 :   if (!vectype_in)
    3658              :     {
    3659         1102 :       if (dump_enabled_p ())
    3660            2 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    3661              :                          "no vectype for scalar type %T\n", rhs_type);
    3662              : 
    3663              :       return false;
    3664              :     }
    3665              : 
    3666              :   /* During vect-patterns we remembered the defined-at-zero value in the
    3667              :      optional second argument for the natural vector mode.  Now, once we have
    3668              :      the final vector mode, verify that they coincide. If not, bail out.  */
    3669        21908 :   if (clz_ctz_arg1)
    3670              :     {
    3671          243 :       int val;
    3672          243 :       int d = (cfn == CFN_CLZ
    3673          243 :                ? CLZ_DEFINED_VALUE_AT_ZERO (TYPE_MODE (vectype_in), val)
    3674          260 :                : CTZ_DEFINED_VALUE_AT_ZERO (TYPE_MODE (vectype_in), val));
    3675          243 :       if (d != 2 || val != tree_to_shwi (clz_ctz_arg1))
    3676              :         return false;
    3677              :     }
    3678              : 
    3679        43716 :   if (VECTOR_BOOLEAN_TYPE_P (vectype_out)
    3680        21858 :       != VECTOR_BOOLEAN_TYPE_P (vectype_in))
    3681              :     {
    3682           12 :       if (dump_enabled_p ())
    3683           12 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    3684              :                          "mixed mask and nonmask vector types\n");
    3685              :       return false;
    3686              :     }
    3687              : 
    3688        21846 :   if (vect_emulated_vector_p (vectype_in)
    3689        21846 :       || vect_emulated_vector_p (vectype_out))
    3690              :     {
    3691            0 :       if (dump_enabled_p ())
    3692            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    3693              :                          "use emulated vector type for call\n");
    3694              :       return false;
    3695              :     }
    3696              : 
    3697              :   /* FORNOW */
    3698        21846 :   nunits_in = TYPE_VECTOR_SUBPARTS (vectype_in);
    3699        21846 :   nunits_out = TYPE_VECTOR_SUBPARTS (vectype_out);
    3700        21846 :   if (known_eq (nunits_in * 2, nunits_out))
    3701              :     modifier = NARROW;
    3702        21250 :   else if (known_eq (nunits_out, nunits_in))
    3703              :     modifier = NONE;
    3704           50 :   else if (known_eq (nunits_out * 2, nunits_in))
    3705              :     modifier = WIDEN;
    3706              :   else
    3707              :     return false;
    3708              : 
    3709              :   /* We only handle functions that do not read or clobber memory.  */
    3710        43692 :   if (gimple_vuse (stmt))
    3711              :     {
    3712         1467 :       if (dump_enabled_p ())
    3713           18 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    3714              :                          "function reads from or writes to memory.\n");
    3715              :       return false;
    3716              :     }
    3717              : 
    3718              :   /* For now, we only vectorize functions if a target specific builtin
    3719              :      is available.  TODO -- in some cases, it might be profitable to
    3720              :      insert the calls for pieces of the vector, in order to be able
    3721              :      to vectorize other operations in the loop.  */
    3722        20379 :   fndecl = NULL_TREE;
    3723        20379 :   internal_fn ifn = IFN_LAST;
    3724        20379 :   tree callee = gimple_call_fndecl (stmt);
    3725              : 
    3726              :   /* First try using an internal function.  */
    3727        20379 :   code_helper convert_code = MAX_TREE_CODES;
    3728        20379 :   if (cfn != CFN_LAST
    3729        20379 :       && (modifier == NONE
    3730          209 :           || (modifier == NARROW
    3731          197 :               && simple_integer_narrowing (vectype_out, vectype_in,
    3732              :                                            &convert_code))))
    3733        19298 :     ifn = vectorizable_internal_function (cfn, callee, vectype_out,
    3734              :                                           vectype_in);
    3735              : 
    3736              :   /* Check if the operation traps.  */
    3737        20379 :   bool could_trap = gimple_could_trap_p (STMT_VINFO_STMT (stmt_info));
    3738        20379 :   if (could_trap && cost_vec && loop_vinfo)
    3739              :     {
    3740              :       /* If the operation can trap it must be conditional, otherwise fail.  */
    3741          601 :       internal_fn cond_fn = (internal_fn_mask_index (ifn) != -1
    3742          601 :                              ? ifn : get_conditional_internal_fn (ifn));
    3743          601 :       internal_fn cond_len_fn = get_len_internal_fn (cond_fn);
    3744          601 :       if (LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo))
    3745              :         {
    3746              :           /* We assume that BB SLP fills all lanes, so no inactive lanes can
    3747              :              cause issues.  */
    3748          136 :           if ((cond_fn == IFN_LAST
    3749           76 :                || !direct_internal_fn_supported_p (cond_fn, vectype_out,
    3750              :                                                    OPTIMIZE_FOR_SPEED))
    3751          212 :               && (cond_len_fn == IFN_LAST
    3752           76 :                   || !direct_internal_fn_supported_p (cond_len_fn, vectype_out,
    3753              :                                                       OPTIMIZE_FOR_SPEED)))
    3754              :             {
    3755          136 :               if (dump_enabled_p ())
    3756           10 :                 dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    3757              :                                  "can't use a fully-masked loop because no"
    3758              :                                  " conditional operation is available.\n");
    3759          136 :               LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo) = false;
    3760              :             }
    3761              :         }
    3762              :     }
    3763              : 
    3764              :   /* If that fails, try asking for a target-specific built-in function.  */
    3765        20379 :   if (ifn == IFN_LAST)
    3766              :     {
    3767        12000 :       if (cfn != CFN_LAST)
    3768        11087 :         fndecl = targetm.vectorize.builtin_vectorized_function
    3769        11087 :           (cfn, vectype_out, vectype_in);
    3770          913 :       else if (callee && fndecl_built_in_p (callee, BUILT_IN_MD))
    3771           24 :         fndecl = targetm.vectorize.builtin_md_vectorized_function
    3772           24 :           (callee, vectype_out, vectype_in);
    3773              :     }
    3774              : 
    3775        20379 :   if (ifn == IFN_LAST && !fndecl)
    3776              :     {
    3777        10857 :       if (cfn == CFN_GOMP_SIMD_LANE
    3778         3755 :           && SLP_TREE_LANES (slp_node) == 1
    3779         3755 :           && loop_vinfo
    3780         3755 :           && LOOP_VINFO_LOOP (loop_vinfo)->simduid
    3781         3755 :           && TREE_CODE (gimple_call_arg (stmt, 0)) == SSA_NAME
    3782        18367 :           && LOOP_VINFO_LOOP (loop_vinfo)->simduid
    3783         3755 :              == SSA_NAME_VAR (gimple_call_arg (stmt, 0)))
    3784              :         {
    3785              :           /* We can handle IFN_GOMP_SIMD_LANE by returning a
    3786              :              { 0, 1, 2, ... vf - 1 } vector.  */
    3787         3755 :           gcc_assert (nargs == 0);
    3788              :         }
    3789         7102 :       else if (modifier == NONE
    3790         7102 :                && (gimple_call_builtin_p (stmt, BUILT_IN_BSWAP16)
    3791         6715 :                    || gimple_call_builtin_p (stmt, BUILT_IN_BSWAP32)
    3792         6616 :                    || gimple_call_builtin_p (stmt, BUILT_IN_BSWAP64)
    3793         6551 :                    || gimple_call_builtin_p (stmt, BUILT_IN_BSWAP128)))
    3794          218 :         return vectorizable_bswap (vinfo, stmt_info, gsi, slp_node,
    3795          218 :                                    slp_op, vectype_in, cost_vec);
    3796              :       else
    3797              :         {
    3798         6884 :           if (dump_enabled_p ())
    3799          317 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    3800              :                              "function is not vectorizable.\n");
    3801              :           return false;
    3802              :         }
    3803              :     }
    3804              : 
    3805        13277 :   int reduc_idx = SLP_TREE_REDUC_IDX (slp_node);
    3806        13277 :   internal_fn cond_fn = (internal_fn_mask_index (ifn) != -1
    3807        13277 :                          ? ifn : get_conditional_internal_fn (ifn));
    3808        13277 :   internal_fn cond_len_fn = get_len_internal_fn (cond_fn);
    3809        13277 :   unsigned int nvectors = vect_get_num_copies (vinfo, slp_node);
    3810        13277 :   if (cost_vec) /* transformation not required.  */
    3811              :     {
    3812        25337 :       for (i = 0; i < nargs; ++i)
    3813        16953 :         if (!vect_maybe_update_slp_op_vectype (slp_op[i],
    3814        16953 :                                                vectypes[i]
    3815              :                                                ? vectypes[i] : vectype_in))
    3816              :           {
    3817            0 :             if (dump_enabled_p ())
    3818            0 :               dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    3819              :                                "incompatible vector types for invariants\n");
    3820              :             return false;
    3821              :           }
    3822         8384 :       SLP_TREE_TYPE (slp_node) = call_vec_info_type;
    3823         8384 :       DUMP_VECT_SCOPE ("vectorizable_call");
    3824         8384 :       vect_model_simple_cost (vinfo, 1, slp_node, cost_vec);
    3825              : 
    3826         8384 :       if (loop_vinfo
    3827         7157 :           && LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo)
    3828         4708 :           && (reduc_idx >= 0 || could_trap || mask_opno >= 0))
    3829              :         {
    3830         2618 :           if (reduc_idx >= 0
    3831         1631 :               && (cond_fn == IFN_LAST
    3832         1631 :                   || !direct_internal_fn_supported_p (cond_fn, vectype_out,
    3833              :                                                       OPTIMIZE_FOR_SPEED))
    3834         2630 :               && (cond_len_fn == IFN_LAST
    3835           12 :                   || !direct_internal_fn_supported_p (cond_len_fn, vectype_out,
    3836              :                                                       OPTIMIZE_FOR_SPEED)))
    3837              :             {
    3838           12 :               if (dump_enabled_p ())
    3839            6 :                 dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    3840              :                                  "can't use a fully-masked loop because no"
    3841              :                                  " conditional operation is available.\n");
    3842           12 :               LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo) = false;
    3843              :             }
    3844              :           else
    3845              :             {
    3846         2606 :               tree scalar_mask = NULL_TREE;
    3847         2606 :               if (mask_opno >= 0)
    3848         2606 :                 scalar_mask = gimple_call_arg (stmt_info->stmt, mask_opno);
    3849         2606 :               if (cond_len_fn != IFN_LAST
    3850         2606 :                   && direct_internal_fn_supported_p (cond_len_fn, vectype_out,
    3851              :                                                      OPTIMIZE_FOR_SPEED))
    3852            0 :                 vect_record_len (loop_vinfo, nvectors, vectype_out, 1);
    3853              :               else
    3854         2606 :                 vect_record_mask (loop_vinfo, nvectors, vectype_out,
    3855              :                                   scalar_mask);
    3856              :             }
    3857              :         }
    3858         8384 :       return true;
    3859              :     }
    3860              : 
    3861              :   /* Transform.  */
    3862              : 
    3863         4893 :   if (dump_enabled_p ())
    3864          451 :     dump_printf_loc (MSG_NOTE, vect_location, "transform call.\n");
    3865              : 
    3866              :   /* Handle def.  */
    3867         4893 :   scalar_dest = gimple_call_lhs (stmt);
    3868         4893 :   vec_dest = vect_create_destination_var (scalar_dest, vectype_out);
    3869              : 
    3870         4893 :   bool masked_loop_p = loop_vinfo && LOOP_VINFO_FULLY_MASKED_P (loop_vinfo);
    3871         3909 :   bool len_loop_p = loop_vinfo && LOOP_VINFO_FULLY_WITH_LENGTH_P (loop_vinfo);
    3872         4893 :   unsigned int vect_nargs = nargs;
    3873         4893 :   if (len_loop_p && (reduc_idx >= 0 || could_trap || mask_opno >= 0))
    3874              :     {
    3875            0 :       ifn = cond_len_fn;
    3876              :       /* COND_* -> COND_LEN_* takes 2 extra arguments:LEN,BIAS.  */
    3877            0 :       vect_nargs += 2;
    3878              :       /* But unless there's a mask argument already we need that
    3879              :          as well, and an else value.  */
    3880            0 :       if (mask_opno == -1)
    3881            0 :         vect_nargs += 2;
    3882              :     }
    3883         4893 :   else if (masked_loop_p && mask_opno == -1 && (reduc_idx >= 0 || could_trap))
    3884              :     {
    3885            0 :       ifn = cond_fn;
    3886            0 :       vect_nargs += 2;
    3887              :     }
    3888         4893 :   int len_opno = internal_fn_len_index (ifn);
    3889         4893 :   if (clz_ctz_arg1)
    3890           64 :     ++vect_nargs;
    3891              : 
    3892         4893 :   if (modifier == NONE || ifn != IFN_LAST)
    3893              :     {
    3894         4861 :       tree prev_res = NULL_TREE;
    3895         4861 :       vargs.safe_grow (vect_nargs, true);
    3896         4861 :       auto_vec<vec<tree> > vec_defs (nargs);
    3897              : 
    3898              :       /* Build argument list for the vectorized call.  */
    3899         4861 :       if (cfn == CFN_GOMP_SIMD_LANE)
    3900              :         {
    3901         3860 :           for (i = 0; i < nvectors; ++i)
    3902              :             {
    3903              :               /* ???  For multi-lane SLP we'd need to build
    3904              :                  { 0, 0, .., 1, 1, ... }.  */
    3905         1986 :               tree cst = build_index_vector (vectype_out,
    3906              :                                              i * nunits_out, 1);
    3907         1986 :               tree new_var
    3908         1986 :                 = vect_get_new_ssa_name (vectype_out, vect_simple_var, "cst_");
    3909         1986 :               gimple *init_stmt = gimple_build_assign (new_var, cst);
    3910         1986 :               vect_init_vector_1 (vinfo, stmt_info, init_stmt, NULL);
    3911         1986 :               new_temp = make_ssa_name (vec_dest);
    3912         1986 :               gimple *new_stmt = gimple_build_assign (new_temp, new_var);
    3913         1986 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    3914         1986 :               slp_node->push_vec_def (new_stmt);
    3915              :             }
    3916              :         }
    3917              :       else
    3918              :         {
    3919         2987 :           vec<tree> vec_oprnds0;
    3920         2987 :           vect_get_slp_defs (vinfo, slp_node, &vec_defs);
    3921         2987 :           vec_oprnds0 = vec_defs[0];
    3922              : 
    3923              :           /* Arguments are ready.  Create the new vector stmt.  */
    3924         6180 :           FOR_EACH_VEC_ELT (vec_oprnds0, i, vec_oprnd0)
    3925              :             {
    3926         3193 :               int varg = 0;
    3927              :               /* Add the mask if necessary.  */
    3928           38 :               if ((masked_loop_p || len_loop_p) && mask_opno == -1
    3929         3195 :                   && internal_fn_mask_index (ifn) != -1)
    3930              :                 {
    3931            0 :                   gcc_assert (internal_fn_mask_index (ifn) == varg);
    3932            0 :                   if (masked_loop_p)
    3933              :                     {
    3934            0 :                       unsigned int vec_num = vec_oprnds0.length ();
    3935            0 :                       vargs[varg++] = vect_get_mask (loop_vinfo, gsi, vec_num,
    3936              :                                                      vectype_out, i);
    3937              :                     }
    3938              :                   else
    3939              :                     {
    3940            0 :                       tree mask_vectype = truth_type_for (vectype_out);
    3941            0 :                       vargs[varg++] = vect_build_all_ones_mask (loop_vinfo,
    3942              :                                                                 stmt_info,
    3943              :                                                                 mask_vectype);
    3944              :                     }
    3945              :                 }
    3946         3193 :               size_t k;
    3947        11357 :               for (k = 0; k < nargs; k++)
    3948              :                 {
    3949         8164 :                   vec<tree> vec_oprndsk = vec_defs[k];
    3950         8164 :                   vargs[varg++] = vec_oprndsk[i];
    3951              :                 }
    3952              :               /* Add the else value if necessary.  */
    3953           38 :               if ((masked_loop_p || len_loop_p) && mask_opno == -1
    3954         3195 :                   && internal_fn_else_index (ifn) != -1)
    3955              :                 {
    3956            0 :                   gcc_assert (internal_fn_else_index (ifn) == varg);
    3957            0 :                   if (reduc_idx >= 0)
    3958            0 :                     vargs[varg++] = vargs[reduc_idx + 1];
    3959              :                   else
    3960              :                     {
    3961            0 :                       auto else_value = targetm.preferred_else_value
    3962            0 :                         (ifn, vectype_out, varg - 1, &vargs[1]);
    3963            0 :                       vargs[varg++] = else_value;
    3964              :                     }
    3965              :                 }
    3966         3193 :               if (clz_ctz_arg1)
    3967           73 :                 vargs[varg++] = clz_ctz_arg1;
    3968              : 
    3969         3193 :               gimple *new_stmt;
    3970         3193 :               if (modifier == NARROW)
    3971              :                 {
    3972              :                   /* We don't define any narrowing conditional functions
    3973              :                      at present.  */
    3974            0 :                   gcc_assert (mask_opno < 0);
    3975            0 :                   tree half_res = make_ssa_name (vectype_in);
    3976            0 :                   gcall *call = gimple_build_call_internal_vec (ifn, vargs);
    3977            0 :                   gimple_call_set_lhs (call, half_res);
    3978            0 :                   gimple_call_set_nothrow (call, true);
    3979            0 :                   vect_finish_stmt_generation (vinfo, stmt_info, call, gsi);
    3980            0 :                   if ((i & 1) == 0)
    3981              :                     {
    3982            0 :                       prev_res = half_res;
    3983            0 :                       continue;
    3984              :                     }
    3985            0 :                   new_temp = make_ssa_name (vec_dest);
    3986            0 :                   new_stmt = vect_gimple_build (new_temp, convert_code,
    3987              :                                                 prev_res, half_res);
    3988            0 :                   vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    3989              :                 }
    3990              :               else
    3991              :                 {
    3992         3193 :                   if (len_opno >= 0 && len_loop_p)
    3993              :                     {
    3994            0 :                       unsigned int vec_num = vec_oprnds0.length ();
    3995            0 :                       tree len = vect_get_len (loop_vinfo, gsi, vec_num,
    3996              :                                                vectype_out, i, 1, true);
    3997            0 :                       signed char biasval
    3998            0 :                         = LOOP_VINFO_PARTIAL_LOAD_STORE_BIAS (loop_vinfo);
    3999            0 :                       tree bias = build_int_cst (intQI_type_node, biasval);
    4000            0 :                       vargs[len_opno] = len;
    4001            0 :                       vargs[len_opno + 1] = bias;
    4002              :                     }
    4003         3193 :                   else if (mask_opno >= 0 && masked_loop_p)
    4004              :                     {
    4005           36 :                       unsigned int vec_num = vec_oprnds0.length ();
    4006           36 :                       tree mask = vect_get_mask (loop_vinfo, gsi, vec_num,
    4007              :                                                  vectype_out, i);
    4008           36 :                       vargs[mask_opno]
    4009           72 :                         = prepare_vec_mask (loop_vinfo, TREE_TYPE (mask), mask,
    4010           36 :                                             vargs[mask_opno], gsi);
    4011              :                     }
    4012              : 
    4013         3193 :                   gcall *call;
    4014         3193 :                   if (ifn != IFN_LAST)
    4015         2884 :                     call = gimple_build_call_internal_vec (ifn, vargs);
    4016              :                   else
    4017          309 :                     call = gimple_build_call_vec (fndecl, vargs);
    4018         3193 :                   new_temp = make_ssa_name (vec_dest, call);
    4019         3193 :                   gimple_call_set_lhs (call, new_temp);
    4020         3193 :                   gimple_call_set_nothrow (call, true);
    4021         3193 :                   vect_finish_stmt_generation (vinfo, stmt_info, call, gsi);
    4022         3193 :                   new_stmt = call;
    4023              :                 }
    4024         3193 :               slp_node->push_vec_def (new_stmt);
    4025              :             }
    4026              :         }
    4027              : 
    4028        12448 :       for (i = 0; i < nargs; i++)
    4029              :         {
    4030         7587 :           vec<tree> vec_oprndsi = vec_defs[i];
    4031         7587 :           vec_oprndsi.release ();
    4032              :         }
    4033         4861 :     }
    4034           32 :   else if (modifier == NARROW)
    4035              :     {
    4036           32 :       auto_vec<vec<tree> > vec_defs (nargs);
    4037              :       /* We don't define any narrowing conditional functions at present.  */
    4038           32 :       gcc_assert (mask_opno < 0);
    4039              : 
    4040              :       /* Build argument list for the vectorized call.  */
    4041           32 :       vargs.create (nargs * 2);
    4042              : 
    4043           32 :       vect_get_slp_defs (vinfo, slp_node, &vec_defs);
    4044           32 :       vec<tree> vec_oprnds0 = vec_defs[0];
    4045              : 
    4046              :       /* Arguments are ready.  Create the new vector stmt.  */
    4047           64 :       for (i = 0; vec_oprnds0.iterate (i, &vec_oprnd0); i += 2)
    4048              :         {
    4049           32 :           size_t k;
    4050           32 :           vargs.truncate (0);
    4051           96 :           for (k = 0; k < nargs; k++)
    4052              :             {
    4053           32 :               vec<tree> vec_oprndsk = vec_defs[k];
    4054           32 :               vargs.quick_push (vec_oprndsk[i]);
    4055           32 :               vargs.quick_push (vec_oprndsk[i + 1]);
    4056              :             }
    4057           32 :           gcall *call;
    4058           32 :           if (ifn != IFN_LAST)
    4059              :             call = gimple_build_call_internal_vec (ifn, vargs);
    4060              :           else
    4061           32 :             call = gimple_build_call_vec (fndecl, vargs);
    4062           32 :           new_temp = make_ssa_name (vec_dest, call);
    4063           32 :           gimple_call_set_lhs (call, new_temp);
    4064           32 :           gimple_call_set_nothrow (call, true);
    4065           32 :           vect_finish_stmt_generation (vinfo, stmt_info, call, gsi);
    4066           32 :           slp_node->push_vec_def (call);
    4067              :         }
    4068              : 
    4069           64 :       for (i = 0; i < nargs; i++)
    4070              :         {
    4071           32 :           vec<tree> vec_oprndsi = vec_defs[i];
    4072           32 :           vec_oprndsi.release ();
    4073              :         }
    4074           32 :     }
    4075              :   else
    4076              :     /* No current target implements this case.  */
    4077              :     return false;
    4078              : 
    4079         4893 :   vargs.release ();
    4080              : 
    4081         4893 :   return true;
    4082      2682848 : }
    4083              : 
    4084              : 
    4085              : struct simd_call_arg_info
    4086              : {
    4087              :   tree vectype;
    4088              :   tree op;
    4089              :   HOST_WIDE_INT linear_step;
    4090              :   enum vect_def_type dt;
    4091              :   unsigned int align;
    4092              :   bool simd_lane_linear;
    4093              : };
    4094              : 
    4095              : /* Helper function of vectorizable_simd_clone_call.  If OP, an SSA_NAME,
    4096              :    is linear within simd lane (but not within whole loop), note it in
    4097              :    *ARGINFO.  */
    4098              : 
    4099              : static void
    4100           19 : vect_simd_lane_linear (tree op, class loop *loop,
    4101              :                        struct simd_call_arg_info *arginfo)
    4102              : {
    4103           19 :   gassign *assign = dyn_cast<gassign *> (SSA_NAME_DEF_STMT (op));
    4104              : 
    4105           19 :   if (!assign
    4106           19 :       || gimple_assign_rhs_code (assign) != POINTER_PLUS_EXPR
    4107           16 :       || !is_gimple_min_invariant (gimple_assign_rhs1 (assign)))
    4108              :     return;
    4109              : 
    4110           16 :   tree base = gimple_assign_rhs1 (assign);
    4111           16 :   HOST_WIDE_INT linear_step = 0;
    4112           16 :   tree v = gimple_assign_rhs2 (assign);
    4113           48 :   while (TREE_CODE (v) == SSA_NAME)
    4114              :     {
    4115           48 :       tree t;
    4116           48 :       gimple *def_stmt = SSA_NAME_DEF_STMT (v);
    4117           48 :       if (is_gimple_assign (def_stmt))
    4118           32 :         switch (gimple_assign_rhs_code (def_stmt))
    4119              :           {
    4120            0 :           case PLUS_EXPR:
    4121            0 :             t = gimple_assign_rhs2 (def_stmt);
    4122            0 :             if (linear_step || TREE_CODE (t) != INTEGER_CST)
    4123              :               return;
    4124            0 :             base = fold_build2 (POINTER_PLUS_EXPR, TREE_TYPE (base), base, t);
    4125            0 :             v = gimple_assign_rhs1 (def_stmt);
    4126            0 :             continue;
    4127           16 :           case MULT_EXPR:
    4128           16 :             t = gimple_assign_rhs2 (def_stmt);
    4129           16 :             if (linear_step || !tree_fits_shwi_p (t) || integer_zerop (t))
    4130              :               return;
    4131           16 :             linear_step = tree_to_shwi (t);
    4132           16 :             v = gimple_assign_rhs1 (def_stmt);
    4133           16 :             continue;
    4134           16 :           CASE_CONVERT:
    4135           16 :             t = gimple_assign_rhs1 (def_stmt);
    4136           16 :             if (TREE_CODE (TREE_TYPE (t)) != INTEGER_TYPE
    4137           16 :                 || (TYPE_PRECISION (TREE_TYPE (v))
    4138           16 :                     < TYPE_PRECISION (TREE_TYPE (t))))
    4139              :               return;
    4140           16 :             if (!linear_step)
    4141            0 :               linear_step = 1;
    4142           16 :             v = t;
    4143           16 :             continue;
    4144              :           default:
    4145              :             return;
    4146              :           }
    4147           16 :       else if (gimple_call_internal_p (def_stmt, IFN_GOMP_SIMD_LANE)
    4148           16 :                && loop->simduid
    4149           12 :                && TREE_CODE (gimple_call_arg (def_stmt, 0)) == SSA_NAME
    4150           28 :                && (SSA_NAME_VAR (gimple_call_arg (def_stmt, 0))
    4151              :                    == loop->simduid))
    4152              :         {
    4153           12 :           if (!linear_step)
    4154            0 :             linear_step = 1;
    4155           12 :           arginfo->linear_step = linear_step;
    4156           12 :           arginfo->op = base;
    4157           12 :           arginfo->simd_lane_linear = true;
    4158              :         }
    4159              :       return;
    4160              :     }
    4161              : }
    4162              : 
    4163              : /* Function vectorizable_simd_clone_call.
    4164              : 
    4165              :    Check if STMT_INFO performs a function call that can be vectorized
    4166              :    by calling a simd clone of the function.
    4167              :    If COST_VEC is passed, calculate costs but don't change anything,
    4168              :    otherwise, vectorize STMT_INFO: create a vectorized stmt to replace
    4169              :    it, and insert it at GSI.
    4170              :    Return true if STMT_INFO is vectorizable in this way.  */
    4171              : 
    4172              : static bool
    4173      2669846 : vectorizable_simd_clone_call (vec_info *vinfo, stmt_vec_info stmt_info,
    4174              :                               gimple_stmt_iterator *gsi,
    4175              :                               slp_tree slp_node,
    4176              :                               stmt_vector_for_cost *cost_vec)
    4177              : {
    4178      2669846 :   tree vec_dest;
    4179      2669846 :   tree scalar_dest;
    4180      2669846 :   tree vec_oprnd0 = NULL_TREE;
    4181      2669846 :   tree vectype;
    4182      2669846 :   poly_uint64 nunits;
    4183      2669846 :   loop_vec_info loop_vinfo = dyn_cast <loop_vec_info> (vinfo);
    4184      2669846 :   bb_vec_info bb_vinfo = dyn_cast <bb_vec_info> (vinfo);
    4185      2669846 :   class loop *loop = loop_vinfo ? LOOP_VINFO_LOOP (loop_vinfo) : NULL;
    4186      2669846 :   tree fndecl, new_temp;
    4187      2669846 :   int j;
    4188      2669846 :   auto_vec<simd_call_arg_info> arginfo;
    4189      2669846 :   vec<tree> vargs = vNULL;
    4190      2669846 :   size_t i, nargs;
    4191      2669846 :   tree rtype, ratype;
    4192      2669846 :   vec<constructor_elt, va_gc> *ret_ctor_elts = NULL;
    4193      2669846 :   int masked_call_offset = 0;
    4194              : 
    4195              :   /* Is STMT a vectorizable call?   */
    4196      2669846 :   gcall *stmt = dyn_cast <gcall *> (stmt_info->stmt);
    4197        17141 :   if (!stmt)
    4198              :     return false;
    4199              : 
    4200        17141 :   fndecl = gimple_call_fndecl (stmt);
    4201        17141 :   if (fndecl == NULL_TREE
    4202        17141 :       && gimple_call_internal_p (stmt, IFN_MASK_CALL))
    4203              :     {
    4204          240 :       fndecl = gimple_call_arg (stmt, 0);
    4205          240 :       gcc_checking_assert (TREE_CODE (fndecl) == ADDR_EXPR);
    4206          240 :       fndecl = TREE_OPERAND (fndecl, 0);
    4207          240 :       gcc_checking_assert (TREE_CODE (fndecl) == FUNCTION_DECL);
    4208              :       masked_call_offset = 1;
    4209              :     }
    4210        16901 :   if (fndecl == NULL_TREE)
    4211              :     return false;
    4212              : 
    4213         6679 :   struct cgraph_node *node = cgraph_node::get (fndecl);
    4214         6679 :   if (node == NULL || node->simd_clones == NULL)
    4215              :     return false;
    4216              : 
    4217         1588 :   if (!STMT_VINFO_RELEVANT_P (stmt_info) && !bb_vinfo)
    4218              :     return false;
    4219              : 
    4220         1588 :   if (STMT_VINFO_DEF_TYPE (stmt_info) != vect_internal_def
    4221            0 :       && cost_vec)
    4222              :     return false;
    4223              : 
    4224         1588 :   if (gimple_call_lhs (stmt)
    4225         1588 :       && TREE_CODE (gimple_call_lhs (stmt)) != SSA_NAME)
    4226              :     return false;
    4227              : 
    4228         1588 :   gcc_checking_assert (!stmt_can_throw_internal (cfun, stmt));
    4229              : 
    4230         1588 :   vectype = SLP_TREE_VECTYPE (slp_node);
    4231              : 
    4232      2671434 :   if (loop_vinfo && nested_in_vect_loop_p (loop, stmt_info))
    4233              :     return false;
    4234              : 
    4235              :   /* Process function arguments.  */
    4236         1588 :   nargs = gimple_call_num_args (stmt) - masked_call_offset;
    4237              : 
    4238              :   /* Bail out if the function has zero arguments.  */
    4239         1588 :   if (nargs == 0)
    4240              :     return false;
    4241              : 
    4242         1524 :   vect_simd_clone_data _data;
    4243         1524 :   vect_simd_clone_data &data = slp_node->get_data (_data);
    4244         1524 :   vec<tree>& simd_clone_info = data.simd_clone_info;
    4245         1524 :   arginfo.reserve (nargs, true);
    4246         1524 :   auto_vec<slp_tree> slp_op;
    4247         1524 :   slp_op.safe_grow_cleared (nargs);
    4248              : 
    4249         5919 :   for (i = 0; i < nargs; i++)
    4250              :     {
    4251         2879 :       simd_call_arg_info thisarginfo;
    4252         2879 :       affine_iv iv;
    4253         2879 :       tree op;
    4254              : 
    4255         2879 :       thisarginfo.linear_step = 0;
    4256         2879 :       thisarginfo.align = 0;
    4257         2879 :       thisarginfo.op = NULL_TREE;
    4258         2879 :       thisarginfo.simd_lane_linear = false;
    4259              : 
    4260         5758 :       int op_no = vect_slp_child_index_for_operand (stmt_info,
    4261         2879 :                                                     i + masked_call_offset);
    4262         5758 :       if (!vect_is_simple_use (vinfo, slp_node,
    4263         2879 :                                op_no, &op, &slp_op[i],
    4264              :                                &thisarginfo.dt, &thisarginfo.vectype)
    4265         2879 :           || thisarginfo.dt == vect_uninitialized_def)
    4266              :         {
    4267            0 :           if (dump_enabled_p ())
    4268            0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    4269              :                              "use not simple.\n");
    4270            8 :           return false;
    4271              :         }
    4272              : 
    4273         2879 :       if (thisarginfo.dt == vect_constant_def
    4274         2879 :           || thisarginfo.dt == vect_external_def)
    4275              :         {
    4276              :           /* With SLP we determine the vector type of constants/externals
    4277              :              at analysis time, handling conflicts via
    4278              :              vect_maybe_update_slp_op_vectype.  At transform time
    4279              :              we have a vector type recorded for SLP.  */
    4280          690 :           gcc_assert (cost_vec
    4281              :                       || thisarginfo.vectype != NULL_TREE);
    4282              :           if (cost_vec)
    4283              :             {
    4284          558 :               thisarginfo.vectype = get_vectype_for_scalar_type (vinfo,
    4285          558 :                                                                  TREE_TYPE (op),
    4286              :                                                                  slp_node);
    4287              :               /* ???  While for example uniform arguments might not need
    4288              :                  a vector type we are not set up to handle this case
    4289              :                  right now.  */
    4290          558 :               if (!thisarginfo.vectype)
    4291              :                 {
    4292            8 :                   if (dump_enabled_p ())
    4293            8 :                     dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    4294              :                                      "no vector type for argument.\n");
    4295              :                   return false;
    4296              :                 }
    4297              :             }
    4298              :         }
    4299              :       else
    4300         2189 :         gcc_assert (thisarginfo.vectype != NULL_TREE);
    4301              : 
    4302              :       /* For linear arguments, the analyze phase should have saved
    4303              :          the base and step.  */
    4304         2739 :       if (!cost_vec
    4305         1698 :           && i * 3 + 4 <= simd_clone_info.length ()
    4306         2949 :           && simd_clone_info[i * 3 + 2])
    4307              :         {
    4308          118 :           thisarginfo.linear_step = tree_to_shwi (simd_clone_info[i * 3 + 2]);
    4309          118 :           thisarginfo.op = simd_clone_info[i * 3 + 1];
    4310          118 :           thisarginfo.simd_lane_linear
    4311          118 :             = (simd_clone_info[i * 3 + 3] == boolean_true_node);
    4312              :           /* If loop has been peeled for alignment, we need to adjust it.  */
    4313          118 :           tree n1 = LOOP_VINFO_NITERS_UNCHANGED (loop_vinfo);
    4314          118 :           tree n2 = LOOP_VINFO_NITERS (loop_vinfo);
    4315          118 :           if (n1 != n2 && !thisarginfo.simd_lane_linear)
    4316              :             {
    4317            0 :               tree bias = fold_build2 (MINUS_EXPR, TREE_TYPE (n1), n1, n2);
    4318            0 :               tree step = simd_clone_info[i * 3 + 2];
    4319            0 :               tree opt = TREE_TYPE (thisarginfo.op);
    4320            0 :               bias = fold_convert (TREE_TYPE (step), bias);
    4321            0 :               bias = fold_build2 (MULT_EXPR, TREE_TYPE (step), bias, step);
    4322            0 :               thisarginfo.op
    4323            0 :                 = fold_build2 (POINTER_TYPE_P (opt)
    4324              :                                ? POINTER_PLUS_EXPR : PLUS_EXPR, opt,
    4325              :                                thisarginfo.op, bias);
    4326              :             }
    4327              :         }
    4328         2753 :       else if (cost_vec
    4329         2022 :                && thisarginfo.dt != vect_constant_def
    4330         1894 :                && thisarginfo.dt != vect_external_def
    4331         1472 :                && loop_vinfo
    4332         1455 :                && SLP_TREE_LANES (slp_node) == 1
    4333         1431 :                && TREE_CODE (op) == SSA_NAME
    4334         2862 :                && simple_iv (loop, loop_containing_stmt (stmt), op,
    4335              :                              &iv, false)
    4336         2969 :                && tree_fits_shwi_p (iv.step))
    4337              :         {
    4338          216 :           thisarginfo.linear_step = tree_to_shwi (iv.step);
    4339          216 :           thisarginfo.op = iv.base;
    4340              :         }
    4341         2537 :       else if ((thisarginfo.dt == vect_constant_def
    4342         2537 :                 || thisarginfo.dt == vect_external_def)
    4343          682 :                && SLP_TREE_LANES (slp_node) == 1
    4344         2845 :                && POINTER_TYPE_P (TREE_TYPE (op)))
    4345           86 :         thisarginfo.align = get_pointer_alignment (op) / BITS_PER_UNIT;
    4346              :       /* Addresses of array elements indexed by GOMP_SIMD_LANE are
    4347              :          linear too.  */
    4348         2871 :       if (SLP_TREE_LANES (slp_node) == 1
    4349         2427 :           && POINTER_TYPE_P (TREE_TYPE (op))
    4350          200 :           && !thisarginfo.linear_step
    4351          116 :           && cost_vec
    4352           62 :           && thisarginfo.dt != vect_constant_def
    4353           62 :           && thisarginfo.dt != vect_external_def
    4354           19 :           && loop_vinfo
    4355         2890 :           && TREE_CODE (op) == SSA_NAME)
    4356           19 :         vect_simd_lane_linear (op, loop, &thisarginfo);
    4357              : 
    4358         2871 :       if (!vectype)
    4359           12 :         vectype = thisarginfo.vectype;
    4360         2871 :       arginfo.quick_push (thisarginfo);
    4361              :     }
    4362              : 
    4363         1516 :   poly_uint64 vf = loop_vinfo ? LOOP_VINFO_VECT_FACTOR (loop_vinfo) : 1;
    4364         1516 :   unsigned group_size = SLP_TREE_LANES (slp_node);
    4365         1516 :   unsigned int badness = 0;
    4366         1516 :   unsigned int badness_inbranch = 0;
    4367         1516 :   struct cgraph_node *bestn = NULL;
    4368         1516 :   struct cgraph_node *bestn_inbranch = NULL;
    4369         1516 :   if (!cost_vec)
    4370          390 :     bestn = ((loop_vinfo && LOOP_VINFO_FULLY_MASKED_P (loop_vinfo))
    4371          390 :              ? data.clone_inbranch : data.clone);
    4372              :   else
    4373         6422 :     for (struct cgraph_node *n = node->simd_clones; n != NULL;
    4374         5296 :          n = n->simdclone->next_clone)
    4375              :       {
    4376         5296 :         unsigned int this_badness = 0;
    4377         5296 :         unsigned int num_calls;
    4378              :         /* The number of arguments in the call and the number of parameters in
    4379              :            the simdclone should match.  However, when the simdclone is
    4380              :            'inbranch', it could have one more parameter than nargs when using
    4381              :            an inbranch simdclone to call a non-inbranch call, either in a
    4382              :            non-masked loop using a all true constant mask, or inside a masked
    4383              :            loop using it's mask.  */
    4384         5296 :         size_t simd_nargs = n->simdclone->nargs;
    4385         5296 :         if (!masked_call_offset && n->simdclone->inbranch)
    4386         2291 :           simd_nargs--;
    4387         5296 :         if (!constant_multiple_p (vf * group_size, n->simdclone->simdlen,
    4388              :                                   &num_calls)
    4389         2079 :             || (!n->simdclone->inbranch && (masked_call_offset > 0))
    4390         1871 :             || (nargs != simd_nargs))
    4391         3425 :           continue;
    4392         1871 :         if (num_calls != 1)
    4393         1276 :           this_badness += floor_log2 (num_calls) * 4096;
    4394         1871 :         if (n->simdclone->inbranch)
    4395          801 :           this_badness += 8192;
    4396              : 
    4397              :         /* If SLP_TREE_VECTYPE has not been set yet pass the general vector
    4398              :            mode,  which for targets that use it will determine what ISA we can
    4399              :            vectorize this code with.  */
    4400         1871 :         machine_mode vector_mode = vinfo->vector_mode;
    4401         1871 :         if (vectype)
    4402         1871 :           vector_mode = TYPE_MODE (vectype);
    4403         1871 :         int target_badness = targetm.simd_clone.usable (n, vector_mode);
    4404         1871 :         if (target_badness < 0)
    4405          390 :           continue;
    4406         1481 :         this_badness += target_badness * 512;
    4407         4400 :         for (i = 0; i < nargs; i++)
    4408              :           {
    4409         3194 :             switch (n->simdclone->args[i].arg_type)
    4410              :               {
    4411         2232 :               case SIMD_CLONE_ARG_TYPE_VECTOR:
    4412         2232 :                 if (VECTOR_BOOLEAN_TYPE_P (n->simdclone->args[i].vector_type))
    4413              :                   /* Vector mask arguments are not supported.  */
    4414              :                   i = -1;
    4415         2224 :                 else if (!useless_type_conversion_p
    4416         2224 :                          (n->simdclone->args[i].orig_type,
    4417         2224 :                           TREE_TYPE (gimple_call_arg (stmt,
    4418              :                                                       i + masked_call_offset))))
    4419              :                   i = -1;
    4420         2224 :                 else if (arginfo[i].dt == vect_constant_def
    4421         2116 :                          || arginfo[i].dt == vect_external_def
    4422         4276 :                          || arginfo[i].linear_step)
    4423          400 :                   this_badness += 64;
    4424              :                 break;
    4425          310 :               case SIMD_CLONE_ARG_TYPE_UNIFORM:
    4426          310 :                 if ((arginfo[i].dt != vect_constant_def
    4427          145 :                      && arginfo[i].dt != vect_external_def)
    4428          410 :                     || SLP_TREE_LANES (slp_node) != 1)
    4429              :                   i = -1;
    4430              :                 break;
    4431          328 :               case SIMD_CLONE_ARG_TYPE_LINEAR_CONSTANT_STEP:
    4432          328 :               case SIMD_CLONE_ARG_TYPE_LINEAR_REF_CONSTANT_STEP:
    4433          328 :                 if (arginfo[i].dt == vect_constant_def
    4434          328 :                     || arginfo[i].dt == vect_external_def
    4435          328 :                     || (arginfo[i].linear_step
    4436          328 :                         != n->simdclone->args[i].linear_step))
    4437              :                   i = -1;
    4438              :                 break;
    4439              :               case SIMD_CLONE_ARG_TYPE_LINEAR_VARIABLE_STEP:
    4440              :               case SIMD_CLONE_ARG_TYPE_LINEAR_VAL_CONSTANT_STEP:
    4441              :               case SIMD_CLONE_ARG_TYPE_LINEAR_UVAL_CONSTANT_STEP:
    4442              :               case SIMD_CLONE_ARG_TYPE_LINEAR_REF_VARIABLE_STEP:
    4443              :               case SIMD_CLONE_ARG_TYPE_LINEAR_VAL_VARIABLE_STEP:
    4444              :               case SIMD_CLONE_ARG_TYPE_LINEAR_UVAL_VARIABLE_STEP:
    4445              :                 /* FORNOW */
    4446              :                 i = -1;
    4447              :                 break;
    4448          324 :               case SIMD_CLONE_ARG_TYPE_MASK:
    4449          324 :                 if (!SCALAR_INT_MODE_P (n->simdclone->mask_mode)
    4450          285 :                     && n->simdclone->mask_mode != VOIDmode)
    4451              :                   i = -1;
    4452              :                 /* While we can create a traditional data vector from
    4453              :                    an incoming integer mode mask we have no good way to
    4454              :                    force generate an integer mode mask from a traditional
    4455              :                    boolean vector input.  */
    4456          324 :                 else if (SCALAR_INT_MODE_P (n->simdclone->mask_mode)
    4457          324 :                          && !SCALAR_INT_MODE_P (TYPE_MODE (arginfo[i].vectype)))
    4458              :                   i = -1;
    4459          318 :                 else if (n->simdclone->mask_mode == VOIDmode
    4460              :                          /* FORNOW we only have partial support for vector-type
    4461              :                             masks that can't hold all of simdlen. */
    4462          603 :                          && (maybe_ne (TYPE_VECTOR_SUBPARTS (n->simdclone->args[i].vector_type),
    4463          467 :                                        TYPE_VECTOR_SUBPARTS (arginfo[i].vectype))
    4464              :                              /* Verify we can compute the mask argument.  */
    4465          115 :                              || !expand_vec_cond_expr_p (n->simdclone->args[i].vector_type,
    4466          115 :                                                          arginfo[i].vectype)))
    4467              :                   i = -1;
    4468          136 :                 else if (SCALAR_INT_MODE_P (n->simdclone->mask_mode)
    4469              :                          /* FORNOW we only have partial support for
    4470              :                             integer-type masks that represent the same number
    4471              :                             of lanes as the vectorized mask inputs.  */
    4472          169 :                          && maybe_ne (exact_div (n->simdclone->simdlen,
    4473              :                                                  n->simdclone->args[i].linear_step),
    4474           33 :                                       TYPE_VECTOR_SUBPARTS (arginfo[i].vectype)))
    4475              :                   i = -1;
    4476          112 :                 else if (!SCALAR_INT_MODE_P (n->simdclone->mask_mode)
    4477          112 :                          && SCALAR_INT_MODE_P (TYPE_MODE (arginfo[i].vectype)))
    4478           12 :                   this_badness += 2048;
    4479              :                 break;
    4480              :               }
    4481           24 :             if (i == (size_t) -1)
    4482              :               break;
    4483         2919 :             if (n->simdclone->args[i].alignment > arginfo[i].align)
    4484              :               {
    4485              :                 i = -1;
    4486              :                 break;
    4487              :               }
    4488         2919 :             if (arginfo[i].align)
    4489          110 :               this_badness += (exact_log2 (arginfo[i].align)
    4490          160 :                                - exact_log2 (n->simdclone->args[i].alignment));
    4491              :           }
    4492         1481 :         if (i == (size_t) -1)
    4493          275 :           continue;
    4494         1206 :         if (masked_call_offset == 0
    4495         1094 :             && n->simdclone->inbranch
    4496          351 :             && n->simdclone->nargs > nargs)
    4497              :           {
    4498          351 :             gcc_assert (n->simdclone->args[n->simdclone->nargs - 1].arg_type ==
    4499              :                         SIMD_CLONE_ARG_TYPE_MASK);
    4500          351 :             if (!SCALAR_INT_MODE_P (n->simdclone->mask_mode)
    4501          335 :                 && n->simdclone->mask_mode != VOIDmode)
    4502            0 :               continue;
    4503              :             /* Penalize using a masked SIMD clone in a non-masked loop, that is
    4504              :                not in a branch, as we'd have to construct an all-true mask.  */
    4505          351 :             this_badness += 64;
    4506              :           }
    4507         1206 :         if (bestn == NULL || this_badness < badness)
    4508              :           {
    4509          869 :             bestn = n;
    4510          869 :             badness = this_badness;
    4511              :           }
    4512         1206 :         if (n->simdclone->inbranch
    4513          463 :             && (bestn_inbranch == NULL || this_badness < badness_inbranch))
    4514              :           {
    4515         5296 :             bestn_inbranch = n;
    4516         5296 :             badness_inbranch = this_badness;
    4517              :           }
    4518              :       }
    4519              : 
    4520         1516 :   if (bestn == NULL)
    4521              :     return false;
    4522              : 
    4523          899 :   fndecl = bestn->decl;
    4524          899 :   nunits = bestn->simdclone->simdlen;
    4525          899 :   int ncopies = vector_unroll_factor (vf * group_size, nunits);
    4526              : 
    4527              :   /* If the function isn't const, only allow it in simd loops where user
    4528              :      has asserted that at least nunits consecutive iterations can be
    4529              :      performed using SIMD instructions.  */
    4530          882 :   if ((loop == NULL || maybe_lt ((unsigned) loop->safelen, nunits))
    4531         1104 :       && gimple_vuse (stmt))
    4532              :     return false;
    4533              : 
    4534              :   /* ncopies is the number of SIMD clone calls we create, since simdlen
    4535              :      is not necessarily matching nunits of the vector types used, track
    4536              :      that in ncopies_in.  */
    4537          899 :   int ncopies_in = vect_get_num_vectors (vf * group_size, vectype);
    4538              : 
    4539              :   /* Sanity check: make sure that at least one copy of the vectorized stmt
    4540              :      needs to be generated.  */
    4541          899 :   gcc_assert (ncopies >= 1);
    4542              : 
    4543          899 :   if (cost_vec) /* transformation not required.  */
    4544              :     {
    4545         1666 :       for (unsigned i = 0; i < nargs; ++i)
    4546         1157 :         if (!vect_maybe_update_slp_op_vectype (slp_op[i], arginfo[i].vectype))
    4547              :           {
    4548            0 :             if (dump_enabled_p ())
    4549            0 :               dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    4550              :                                "incompatible vector types for invariants\n");
    4551              :             return false;
    4552              :           }
    4553              : 
    4554          509 :       if (!bestn_inbranch && loop_vinfo)
    4555              :         {
    4556          279 :           if (dump_enabled_p ()
    4557          279 :               && LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo))
    4558          193 :             dump_printf_loc (MSG_NOTE, vect_location,
    4559              :                              "can't use a fully-masked loop because no"
    4560              :                              " masked simd clone was available.\n");
    4561          279 :           LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo) = false;
    4562              :         }
    4563              : 
    4564              :       /* When the original call is pure or const but the SIMD ABI dictates
    4565              :          an aggregate return we will have to use a virtual definition and
    4566              :          in a loop eventually even need to add a virtual PHI.  That's
    4567              :          not straight-forward so allow to fix this up via renaming.  */
    4568          509 :       if (gimple_call_lhs (stmt)
    4569          503 :           && !gimple_vdef (stmt)
    4570          904 :           && TREE_CODE (TREE_TYPE (TREE_TYPE (bestn->decl))) == ARRAY_TYPE)
    4571           36 :         vinfo->any_known_not_updated_vssa = true;
    4572              :       /* ???  For SLP code-gen we end up inserting after the last
    4573              :          vector argument def rather than at the original call position
    4574              :          so automagic virtual operand updating doesn't work.  */
    4575         1018 :       if (gimple_vuse (stmt))
    4576          151 :         vinfo->any_known_not_updated_vssa = true;
    4577              : 
    4578          509 :       data.clone = bestn;
    4579          509 :       data.clone_inbranch = bestn_inbranch;
    4580              : 
    4581          509 :       simd_clone_info.safe_push (NULL_TREE);
    4582         1823 :       for (i = 0;
    4583         2777 :            i < (bestn_inbranch ? bestn_inbranch : bestn)->simdclone->nargs; i++)
    4584              :         {
    4585         1314 :           if (loop_vinfo
    4586         1290 :               && LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo)
    4587          480 :               && (bestn_inbranch->simdclone->args[i].arg_type
    4588              :                   == SIMD_CLONE_ARG_TYPE_MASK))
    4589              :             {
    4590          173 :               if (masked_call_offset)
    4591              :                 /* When there is an explicit mask we require the
    4592              :                    number of elements to match up.  */
    4593           52 :                 vect_record_mask (loop_vinfo, ncopies_in, vectype, NULL_TREE);
    4594              :               else
    4595              :                 {
    4596              :                   /* When there is no explicit mask on the call we have
    4597              :                      more relaxed requirements.  */
    4598          121 :                   tree masktype;
    4599          121 :                   poly_uint64 callee_nelements;
    4600          121 :                   if (SCALAR_INT_MODE_P (bestn_inbranch->simdclone->mask_mode))
    4601              :                     {
    4602           16 :                       callee_nelements
    4603           16 :                         = exact_div (bestn_inbranch->simdclone->simdlen,
    4604              :                                      bestn_inbranch->simdclone->args[i].linear_step);
    4605           16 :                       masktype = get_related_vectype_for_scalar_type
    4606           16 :                           (vinfo->vector_mode, TREE_TYPE (vectype),
    4607              :                            callee_nelements);
    4608              :                     }
    4609              :                   else
    4610              :                     {
    4611          105 :                       masktype = bestn_inbranch->simdclone->args[i].vector_type;
    4612          105 :                       if (VECTOR_BOOLEAN_TYPE_P (masktype))
    4613              :                         {
    4614            0 :                           if (VECTOR_MODE_P (TYPE_MODE (masktype)))
    4615              :                             /* The aarch64 port will add custom attributes to
    4616              :                                types for SVE simdclones which make the types
    4617              :                                different.  We should use canonincal types for
    4618              :                                masks within the vectorizer, hence we
    4619              :                                re-construct the vectype from its mode.  */
    4620            0 :                             masktype = build_truth_vector_type_for_mode
    4621            0 :                                          (TYPE_VECTOR_SUBPARTS (masktype),
    4622            0 :                                           TYPE_MODE (masktype));
    4623              :                         }
    4624              :                       else
    4625          105 :                         masktype = truth_type_for (masktype);
    4626          105 :                       callee_nelements = TYPE_VECTOR_SUBPARTS (masktype);
    4627              :                     }
    4628          121 :                   if (!masktype)
    4629              :                     {
    4630            0 :                       if (dump_enabled_p ())
    4631            0 :                         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    4632              :                                          "can't use a fully-masked loop because"
    4633              :                                          " no suitable vector type was found for"
    4634              :                                          " the mask.\n");
    4635            0 :                       LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo) = false;
    4636              :                     }
    4637              :                   else
    4638              :                     {
    4639          121 :                       auto o = vector_unroll_factor (nunits, callee_nelements);
    4640          121 :                       vect_record_mask (loop_vinfo, ncopies * o, masktype,
    4641              :                                         NULL_TREE);
    4642              :                     }
    4643              :                 }
    4644              :             }
    4645         1141 :           else if ((bestn->simdclone->args[i].arg_type
    4646              :                     == SIMD_CLONE_ARG_TYPE_LINEAR_CONSTANT_STEP)
    4647         1034 :                    || (bestn->simdclone->args[i].arg_type
    4648              :                        == SIMD_CLONE_ARG_TYPE_LINEAR_REF_CONSTANT_STEP)
    4649         1023 :                    || (bestn_inbranch
    4650          399 :                        && ((bestn_inbranch->simdclone->args[i].arg_type
    4651              :                             == SIMD_CLONE_ARG_TYPE_LINEAR_CONSTANT_STEP)
    4652          399 :                            || (bestn_inbranch->simdclone->args[i].arg_type
    4653              :                                == SIMD_CLONE_ARG_TYPE_LINEAR_REF_CONSTANT_STEP))))
    4654              :             {
    4655          118 :               simd_clone_info.safe_grow_cleared (i * 3 + 1, true);
    4656          118 :               simd_clone_info.safe_push (arginfo[i].op);
    4657          202 :               tree lst = (POINTER_TYPE_P (TREE_TYPE (arginfo[i].op))
    4658          202 :                           ? size_type_node : TREE_TYPE (arginfo[i].op));
    4659          118 :               tree ls = build_int_cst (lst, arginfo[i].linear_step);
    4660          118 :               simd_clone_info.safe_push (ls);
    4661          118 :               tree sll = (arginfo[i].simd_lane_linear
    4662          118 :                           ? boolean_true_node : boolean_false_node);
    4663          118 :               simd_clone_info.safe_push (sll);
    4664              :             }
    4665              :         }
    4666              : 
    4667          509 :       SLP_TREE_TYPE (slp_node) = call_simd_clone_vec_info_type;
    4668          509 :       slp_node->data = new vect_simd_clone_data (std::move (_data));
    4669          509 :       DUMP_VECT_SCOPE ("vectorizable_simd_clone_call");
    4670              :       /* ???  We're confused by calls w/o LHS.  */
    4671          509 :       if (SLP_TREE_VECTYPE (slp_node))
    4672          503 :         vect_model_simple_cost (vinfo, ncopies, slp_node, cost_vec);
    4673          509 :       return true;
    4674              :     }
    4675              : 
    4676              :   /* Transform.  */
    4677              : 
    4678          390 :   if (dump_enabled_p ())
    4679          259 :     dump_printf_loc (MSG_NOTE, vect_location, "transform call.\n");
    4680              : 
    4681              :   /* Handle def.  */
    4682          390 :   scalar_dest = gimple_call_lhs (stmt);
    4683          390 :   vec_dest = NULL_TREE;
    4684          390 :   rtype = NULL_TREE;
    4685          390 :   ratype = NULL_TREE;
    4686          390 :   if (scalar_dest)
    4687              :     {
    4688          384 :       vec_dest = vect_create_destination_var (scalar_dest, vectype);
    4689          384 :       rtype = TREE_TYPE (TREE_TYPE (fndecl));
    4690          384 :       if (TREE_CODE (rtype) == ARRAY_TYPE)
    4691              :         {
    4692           12 :           ratype = rtype;
    4693           12 :           rtype = TREE_TYPE (ratype);
    4694              :         }
    4695              :     }
    4696              : 
    4697          780 :   auto_vec<vec<tree> > vec_oprnds;
    4698          390 :   auto_vec<unsigned> vec_oprnds_i;
    4699          390 :   vec_oprnds_i.safe_grow_cleared (nargs, true);
    4700          390 :   vec_oprnds.reserve_exact (nargs);
    4701          390 :   vect_get_slp_defs (vinfo, slp_node, &vec_oprnds);
    4702         1308 :   for (j = 0; j < ncopies; ++j)
    4703              :     {
    4704          528 :       poly_uint64 callee_nelements;
    4705          528 :       poly_uint64 caller_nelements;
    4706              :       /* Build argument list for the vectorized call.  */
    4707          528 :       if (j == 0)
    4708          390 :         vargs.create (nargs);
    4709              :       else
    4710          138 :         vargs.truncate (0);
    4711              : 
    4712         1721 :       for (i = 0; i < nargs; i++)
    4713              :         {
    4714         1193 :           unsigned int k, l, m, o;
    4715         1193 :           tree atype;
    4716         1193 :           tree op = gimple_call_arg (stmt, i + masked_call_offset);
    4717         1193 :           switch (bestn->simdclone->args[i].arg_type)
    4718              :             {
    4719          899 :             case SIMD_CLONE_ARG_TYPE_VECTOR:
    4720          899 :               atype = bestn->simdclone->args[i].vector_type;
    4721          899 :               caller_nelements = TYPE_VECTOR_SUBPARTS (arginfo[i].vectype);
    4722          899 :               callee_nelements = TYPE_VECTOR_SUBPARTS (atype);
    4723          899 :               o = vector_unroll_factor (nunits, callee_nelements);
    4724         2033 :               for (m = j * o; m < (j + 1) * o; m++)
    4725              :                 {
    4726         1134 :                   if (known_lt (callee_nelements, caller_nelements))
    4727              :                     {
    4728          596 :                       poly_uint64 prec = GET_MODE_BITSIZE (TYPE_MODE (atype));
    4729          298 :                       if (!constant_multiple_p (caller_nelements,
    4730              :                                                 callee_nelements, &k))
    4731            0 :                         gcc_unreachable ();
    4732              : 
    4733          298 :                       gcc_assert ((k & (k - 1)) == 0);
    4734          298 :                       if (m == 0)
    4735              :                         {
    4736           65 :                           vec_oprnds_i[i] = 0;
    4737           65 :                           vec_oprnd0 = vec_oprnds[i][vec_oprnds_i[i]++];
    4738              :                         }
    4739              :                       else
    4740              :                         {
    4741          233 :                           vec_oprnd0 = arginfo[i].op;
    4742          233 :                           if ((m & (k - 1)) == 0)
    4743           78 :                             vec_oprnd0 = vec_oprnds[i][vec_oprnds_i[i]++];
    4744              :                         }
    4745          298 :                       arginfo[i].op = vec_oprnd0;
    4746          298 :                       vec_oprnd0
    4747          298 :                         = build3 (BIT_FIELD_REF, atype, vec_oprnd0,
    4748          298 :                                   bitsize_int (prec),
    4749          298 :                                   bitsize_int ((m & (k - 1)) * prec));
    4750          298 :                       gassign *new_stmt
    4751          298 :                         = gimple_build_assign (make_ssa_name (atype),
    4752              :                                                vec_oprnd0);
    4753          298 :                       vect_finish_stmt_generation (vinfo, stmt_info,
    4754              :                                                    new_stmt, gsi);
    4755          298 :                       vargs.safe_push (gimple_assign_lhs (new_stmt));
    4756              :                     }
    4757              :                   else
    4758              :                     {
    4759          836 :                       if (!constant_multiple_p (callee_nelements,
    4760              :                                                 caller_nelements, &k))
    4761            0 :                         gcc_unreachable ();
    4762          836 :                       gcc_assert ((k & (k - 1)) == 0);
    4763          836 :                       vec<constructor_elt, va_gc> *ctor_elts;
    4764          836 :                       if (k != 1)
    4765           12 :                         vec_alloc (ctor_elts, k);
    4766              :                       else
    4767          824 :                         ctor_elts = NULL;
    4768          860 :                       for (l = 0; l < k; l++)
    4769              :                         {
    4770          848 :                           if (m == 0 && l == 0)
    4771              :                             {
    4772          495 :                               vec_oprnds_i[i] = 0;
    4773          495 :                               vec_oprnd0 = vec_oprnds[i][vec_oprnds_i[i]++];
    4774              :                             }
    4775              :                           else
    4776          353 :                             vec_oprnd0 = vec_oprnds[i][vec_oprnds_i[i]++];
    4777          848 :                           arginfo[i].op = vec_oprnd0;
    4778          848 :                           if (k == 1)
    4779              :                             break;
    4780           24 :                           CONSTRUCTOR_APPEND_ELT (ctor_elts, NULL_TREE,
    4781              :                                                   vec_oprnd0);
    4782              :                         }
    4783          836 :                       if (k == 1)
    4784          824 :                         if (!useless_type_conversion_p (TREE_TYPE (vec_oprnd0),
    4785              :                                                        atype))
    4786              :                           {
    4787            0 :                             vec_oprnd0 = build1 (VIEW_CONVERT_EXPR, atype,
    4788              :                                                  vec_oprnd0);
    4789            0 :                             gassign *new_stmt
    4790            0 :                               = gimple_build_assign (make_ssa_name (atype),
    4791              :                                                      vec_oprnd0);
    4792            0 :                             vect_finish_stmt_generation (vinfo, stmt_info,
    4793              :                                                          new_stmt, gsi);
    4794            0 :                             vargs.safe_push (gimple_get_lhs (new_stmt));
    4795              :                           }
    4796              :                         else
    4797          824 :                           vargs.safe_push (vec_oprnd0);
    4798              :                       else
    4799              :                         {
    4800           12 :                           vec_oprnd0 = build_constructor (atype, ctor_elts);
    4801           12 :                           gassign *new_stmt
    4802           12 :                             = gimple_build_assign (make_ssa_name (atype),
    4803              :                                                    vec_oprnd0);
    4804           12 :                           vect_finish_stmt_generation (vinfo, stmt_info,
    4805              :                                                        new_stmt, gsi);
    4806           12 :                           vargs.safe_push (gimple_assign_lhs (new_stmt));
    4807              :                         }
    4808              :                     }
    4809              :                 }
    4810              :               break;
    4811           71 :             case SIMD_CLONE_ARG_TYPE_MASK:
    4812           71 :               if (bestn->simdclone->mask_mode == VOIDmode)
    4813              :                 {
    4814           64 :                   atype = bestn->simdclone->args[i].vector_type;
    4815           64 :                   tree elt_type = TREE_TYPE (atype);
    4816           64 :                   tree one = fold_convert (elt_type, integer_one_node);
    4817           64 :                   tree zero = fold_convert (elt_type, integer_zero_node);
    4818           64 :                   callee_nelements = TYPE_VECTOR_SUBPARTS (atype);
    4819           64 :                   caller_nelements = TYPE_VECTOR_SUBPARTS (arginfo[i].vectype);
    4820           64 :                   o = vector_unroll_factor (nunits, callee_nelements);
    4821          132 :                   for (m = j * o; m < (j + 1) * o; m++)
    4822              :                     {
    4823           68 :                       if (maybe_lt (callee_nelements, caller_nelements))
    4824              :                         {
    4825              :                           /* The mask type has fewer elements than simdlen.  */
    4826              : 
    4827              :                           /* FORNOW */
    4828            0 :                           gcc_unreachable ();
    4829              :                         }
    4830           68 :                       else if (known_eq (callee_nelements, caller_nelements))
    4831              :                         {
    4832              :                           /* The SIMD clone function has the same number of
    4833              :                              elements as the current function.  */
    4834           68 :                           if (m == 0)
    4835           62 :                             vec_oprnds_i[i] = 0;
    4836           68 :                           vec_oprnd0 = vec_oprnds[i][vec_oprnds_i[i]++];
    4837           68 :                           if (loop_vinfo
    4838           68 :                               && LOOP_VINFO_FULLY_MASKED_P (loop_vinfo))
    4839              :                             {
    4840            0 :                               tree loop_mask
    4841            0 :                                 = vect_get_mask (loop_vinfo, gsi, ncopies_in,
    4842            0 :                                                  vectype, m);
    4843            0 :                               vec_oprnd0
    4844            0 :                                 = prepare_vec_mask (loop_vinfo,
    4845            0 :                                                     TREE_TYPE (loop_mask),
    4846              :                                                     loop_mask, vec_oprnd0,
    4847              :                                                     gsi);
    4848            0 :                               loop_vinfo->vec_cond_masked_set.add ({ vec_oprnd0,
    4849              :                                                                      loop_mask });
    4850              : 
    4851              :                             }
    4852           68 :                           vec_oprnd0
    4853           68 :                             = build3 (VEC_COND_EXPR, atype, vec_oprnd0,
    4854              :                                       build_vector_from_val (atype, one),
    4855              :                                       build_vector_from_val (atype, zero));
    4856           68 :                           gassign *new_stmt
    4857           68 :                             = gimple_build_assign (make_ssa_name (atype),
    4858              :                                                    vec_oprnd0);
    4859           68 :                           vect_finish_stmt_generation (vinfo, stmt_info,
    4860              :                                                        new_stmt, gsi);
    4861           68 :                           vargs.safe_push (gimple_assign_lhs (new_stmt));
    4862              :                         }
    4863              :                       else
    4864              :                         {
    4865              :                           /* The mask type has more elements than simdlen.  */
    4866              : 
    4867              :                           /* FORNOW */
    4868            0 :                           gcc_unreachable ();
    4869              :                         }
    4870              :                     }
    4871              :                 }
    4872            7 :               else if (SCALAR_INT_MODE_P (bestn->simdclone->mask_mode))
    4873              :                 {
    4874            7 :                   atype = bestn->simdclone->args[i].vector_type;
    4875            7 :                   poly_uint64 atype_subparts
    4876            7 :                     = exact_div (bestn->simdclone->simdlen,
    4877              :                                  bestn->simdclone->args[i].linear_step);
    4878            7 :                   o = bestn->simdclone->args[i].linear_step;
    4879           15 :                   for (m = j * o; m < (j + 1) * o; m++)
    4880              :                     {
    4881            8 :                       if (m == 0)
    4882            7 :                         vec_oprnds_i[i] = 0;
    4883            8 :                       if (maybe_lt (atype_subparts,
    4884            8 :                                     TYPE_VECTOR_SUBPARTS (arginfo[i].vectype)))
    4885              :                         {
    4886              :                           /* The mask argument has fewer elements than the
    4887              :                              input vector.  */
    4888              :                           /* FORNOW */
    4889            0 :                           gcc_unreachable ();
    4890              :                         }
    4891            8 :                       else if (known_eq (atype_subparts,
    4892              :                                          TYPE_VECTOR_SUBPARTS (arginfo[i].vectype)))
    4893              :                         {
    4894            8 :                           vec_oprnd0 = vec_oprnds[i][vec_oprnds_i[i]++];
    4895            8 :                           if (loop_vinfo
    4896            8 :                               && LOOP_VINFO_FULLY_MASKED_P (loop_vinfo))
    4897              :                             {
    4898            3 :                               tree loop_mask
    4899            3 :                                 = vect_get_mask (loop_vinfo, gsi, ncopies_in,
    4900              :                                                  vectype, m);
    4901            3 :                               vec_oprnd0
    4902            3 :                                 = prepare_vec_mask (loop_vinfo,
    4903            3 :                                                     TREE_TYPE (loop_mask),
    4904              :                                                     loop_mask, vec_oprnd0,
    4905              :                                                     gsi);
    4906              :                             }
    4907              :                           /* The vector mask argument matches the input
    4908              :                              in the number of lanes, but not necessarily
    4909              :                              in the mode.  */
    4910            8 :                           tree st = lang_hooks.types.type_for_mode
    4911            8 :                                       (TYPE_MODE (TREE_TYPE (vec_oprnd0)), 1);
    4912            8 :                           vec_oprnd0 = build1 (VIEW_CONVERT_EXPR, st,
    4913              :                                                vec_oprnd0);
    4914            8 :                           gassign *new_stmt
    4915            8 :                             = gimple_build_assign (make_ssa_name (st),
    4916              :                                                    vec_oprnd0);
    4917            8 :                           vect_finish_stmt_generation (vinfo, stmt_info,
    4918              :                                                        new_stmt, gsi);
    4919            8 :                           if (!types_compatible_p (atype, st))
    4920              :                             {
    4921            8 :                               new_stmt
    4922            8 :                                 = gimple_build_assign (make_ssa_name (atype),
    4923              :                                                        NOP_EXPR,
    4924              :                                                        gimple_assign_lhs
    4925              :                                                          (new_stmt));
    4926            8 :                               vect_finish_stmt_generation (vinfo, stmt_info,
    4927              :                                                            new_stmt, gsi);
    4928              :                             }
    4929            8 :                           vargs.safe_push (gimple_assign_lhs (new_stmt));
    4930              :                         }
    4931              :                       else
    4932              :                         {
    4933              :                           /* The mask argument has more elements than the
    4934              :                              input vector.  */
    4935              :                           /* FORNOW */
    4936            0 :                           gcc_unreachable ();
    4937              :                         }
    4938              :                     }
    4939              :                 }
    4940              :               else
    4941            0 :                 gcc_unreachable ();
    4942              :               break;
    4943          102 :             case SIMD_CLONE_ARG_TYPE_UNIFORM:
    4944          102 :               vargs.safe_push (op);
    4945          102 :               break;
    4946          121 :             case SIMD_CLONE_ARG_TYPE_LINEAR_CONSTANT_STEP:
    4947          121 :             case SIMD_CLONE_ARG_TYPE_LINEAR_REF_CONSTANT_STEP:
    4948          121 :               if (j == 0)
    4949              :                 {
    4950          118 :                   gimple_seq stmts;
    4951          118 :                   arginfo[i].op
    4952          118 :                     = force_gimple_operand (unshare_expr (arginfo[i].op),
    4953              :                                             &stmts, true, NULL_TREE);
    4954          118 :                   if (stmts != NULL)
    4955              :                     {
    4956            0 :                       basic_block new_bb;
    4957            0 :                       edge pe = loop_preheader_edge (loop);
    4958            0 :                       new_bb = gsi_insert_seq_on_edge_immediate (pe, stmts);
    4959            0 :                       gcc_assert (!new_bb);
    4960              :                     }
    4961          118 :                   if (arginfo[i].simd_lane_linear)
    4962              :                     {
    4963            6 :                       vargs.safe_push (arginfo[i].op);
    4964            6 :                       break;
    4965              :                     }
    4966          112 :                   tree phi_res = copy_ssa_name (op);
    4967          112 :                   gphi *new_phi = create_phi_node (phi_res, loop->header);
    4968          112 :                   add_phi_arg (new_phi, arginfo[i].op,
    4969              :                                loop_preheader_edge (loop), UNKNOWN_LOCATION);
    4970          112 :                   enum tree_code code
    4971          196 :                     = POINTER_TYPE_P (TREE_TYPE (op))
    4972          112 :                       ? POINTER_PLUS_EXPR : PLUS_EXPR;
    4973          196 :                   tree type = POINTER_TYPE_P (TREE_TYPE (op))
    4974          196 :                               ? sizetype : TREE_TYPE (op);
    4975          112 :                   poly_widest_int cst
    4976          112 :                     = wi::mul (bestn->simdclone->args[i].linear_step,
    4977          112 :                                ncopies * nunits);
    4978          112 :                   tree tcst = wide_int_to_tree (type, cst);
    4979          112 :                   tree phi_arg = copy_ssa_name (op);
    4980          112 :                   gassign *new_stmt
    4981          112 :                     = gimple_build_assign (phi_arg, code, phi_res, tcst);
    4982          112 :                   gimple_stmt_iterator si = gsi_after_labels (loop->header);
    4983          112 :                   gsi_insert_after (&si, new_stmt, GSI_NEW_STMT);
    4984          112 :                   add_phi_arg (new_phi, phi_arg, loop_latch_edge (loop),
    4985              :                                UNKNOWN_LOCATION);
    4986          112 :                   arginfo[i].op = phi_res;
    4987          112 :                   vargs.safe_push (phi_res);
    4988          112 :                 }
    4989              :               else
    4990              :                 {
    4991            3 :                   enum tree_code code
    4992            6 :                     = POINTER_TYPE_P (TREE_TYPE (op))
    4993            3 :                       ? POINTER_PLUS_EXPR : PLUS_EXPR;
    4994            6 :                   tree type = POINTER_TYPE_P (TREE_TYPE (op))
    4995            6 :                               ? sizetype : TREE_TYPE (op);
    4996            3 :                   poly_widest_int cst
    4997            3 :                     = wi::mul (bestn->simdclone->args[i].linear_step,
    4998            3 :                                j * nunits);
    4999            3 :                   tree tcst = wide_int_to_tree (type, cst);
    5000            3 :                   new_temp = make_ssa_name (TREE_TYPE (op));
    5001            3 :                   gassign *new_stmt
    5002            6 :                     = gimple_build_assign (new_temp, code,
    5003            3 :                                            arginfo[i].op, tcst);
    5004            3 :                   vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    5005            3 :                   vargs.safe_push (new_temp);
    5006            3 :                 }
    5007              :               break;
    5008            0 :             case SIMD_CLONE_ARG_TYPE_LINEAR_VAL_CONSTANT_STEP:
    5009            0 :             case SIMD_CLONE_ARG_TYPE_LINEAR_UVAL_CONSTANT_STEP:
    5010            0 :             case SIMD_CLONE_ARG_TYPE_LINEAR_VARIABLE_STEP:
    5011            0 :             case SIMD_CLONE_ARG_TYPE_LINEAR_REF_VARIABLE_STEP:
    5012            0 :             case SIMD_CLONE_ARG_TYPE_LINEAR_VAL_VARIABLE_STEP:
    5013            0 :             case SIMD_CLONE_ARG_TYPE_LINEAR_UVAL_VARIABLE_STEP:
    5014            0 :             default:
    5015            0 :               gcc_unreachable ();
    5016              :             }
    5017              :         }
    5018              : 
    5019          528 :       if (masked_call_offset == 0
    5020          457 :           && bestn->simdclone->inbranch
    5021           37 :           && bestn->simdclone->nargs > nargs)
    5022              :         {
    5023           37 :           unsigned long m, o;
    5024           37 :           size_t mask_i = bestn->simdclone->nargs - 1;
    5025           37 :           tree mask;
    5026           37 :           gcc_assert (bestn->simdclone->args[mask_i].arg_type ==
    5027              :                       SIMD_CLONE_ARG_TYPE_MASK);
    5028              : 
    5029           37 :           tree mask_argtype = bestn->simdclone->args[mask_i].vector_type;
    5030           37 :           tree mask_vectype;
    5031           37 :           if (SCALAR_INT_MODE_P (bestn->simdclone->mask_mode))
    5032              :             {
    5033            2 :               callee_nelements = exact_div (bestn->simdclone->simdlen,
    5034              :                                             bestn->simdclone->args[i].linear_step);
    5035            2 :               mask_vectype = get_related_vectype_for_scalar_type
    5036            2 :                   (vinfo->vector_mode, TREE_TYPE (vectype), callee_nelements);
    5037              :             }
    5038              :           else
    5039              :             {
    5040           35 :               mask_vectype = mask_argtype;
    5041           35 :               callee_nelements = TYPE_VECTOR_SUBPARTS (mask_vectype);
    5042              :             }
    5043           37 :           o = vector_unroll_factor (nunits, callee_nelements);
    5044           74 :           for (m = j * o; m < (j + 1) * o; m++)
    5045              :             {
    5046           37 :               if (loop_vinfo && LOOP_VINFO_FULLY_MASKED_P (loop_vinfo))
    5047              :                 {
    5048            1 :                   mask = vect_get_mask (loop_vinfo, gsi, ncopies * o,
    5049              :                                         mask_vectype, m);
    5050              :                 }
    5051           36 :               else if (bestn->simdclone->mask_mode == VOIDmode)
    5052              :                 {
    5053              :                   /* All lanes are active: pass what the VEC_COND_EXPR below
    5054              :                      would select.  An all-ones floating-point MASK_ARGTYPE
    5055              :                      is not a valid condition.  */
    5056           35 :                   vargs.safe_push (build_one_cst (mask_argtype));
    5057           35 :                   continue;
    5058              :                 }
    5059              :               else
    5060            1 :                 mask = vect_build_all_ones_mask (vinfo, stmt_info,
    5061              :                                                  mask_argtype);
    5062              : 
    5063            2 :               gassign *new_stmt;
    5064            2 :               if (SCALAR_INT_MODE_P (bestn->simdclone->mask_mode))
    5065              :                 {
    5066              :                   /* This means we are dealing with integer mask modes.
    5067              :                      First convert to an integer type with the same size as
    5068              :                      the current vector type.  */
    5069            2 :                   unsigned HOST_WIDE_INT intermediate_size
    5070            2 :                       = tree_to_uhwi (TYPE_SIZE (TREE_TYPE (mask)));
    5071            2 :                   tree mid_int_type =
    5072            2 :                       build_nonstandard_integer_type (intermediate_size, 1);
    5073            2 :                   mask = build1 (VIEW_CONVERT_EXPR, mid_int_type, mask);
    5074            2 :                   new_stmt
    5075            2 :                       = gimple_build_assign (make_ssa_name (mid_int_type),
    5076              :                                              mask);
    5077            2 :                   gsi_insert_before (gsi, new_stmt, GSI_SAME_STMT);
    5078              :                   /* Then zero-extend to the mask mode.  */
    5079            2 :                   mask = fold_build1 (NOP_EXPR, mask_argtype,
    5080              :                                       gimple_get_lhs (new_stmt));
    5081              :                 }
    5082            0 :               else if (bestn->simdclone->mask_mode == VOIDmode)
    5083            0 :                 mask = build3 (VEC_COND_EXPR, mask_argtype, mask,
    5084              :                                build_one_cst (mask_argtype),
    5085              :                                build_zero_cst (mask_argtype));
    5086              :               else
    5087            0 :                 gcc_unreachable ();
    5088              : 
    5089            2 :               new_stmt = gimple_build_assign (make_ssa_name (mask_argtype),
    5090              :                                               mask);
    5091            2 :               vect_finish_stmt_generation (vinfo, stmt_info,
    5092              :                                            new_stmt, gsi);
    5093            2 :               mask = gimple_assign_lhs (new_stmt);
    5094            2 :               vargs.safe_push (mask);
    5095              :             }
    5096              :         }
    5097              : 
    5098          528 :       gcall *new_call = gimple_build_call_vec (fndecl, vargs);
    5099          528 :       if (vec_dest)
    5100              :         {
    5101          522 :           gcc_assert (ratype
    5102              :                       || known_eq (TYPE_VECTOR_SUBPARTS (rtype), nunits));
    5103          522 :           if (ratype)
    5104           20 :             new_temp = create_tmp_var (ratype);
    5105          502 :           else if (useless_type_conversion_p (vectype, rtype))
    5106          446 :             new_temp = make_ssa_name (vec_dest, new_call);
    5107              :           else
    5108           56 :             new_temp = make_ssa_name (rtype, new_call);
    5109          522 :           gimple_call_set_lhs (new_call, new_temp);
    5110              :         }
    5111          528 :       vect_finish_stmt_generation (vinfo, stmt_info, new_call, gsi);
    5112          528 :       gimple *new_stmt = new_call;
    5113              : 
    5114          528 :       if (vec_dest)
    5115              :         {
    5116          522 :           if (!multiple_p (TYPE_VECTOR_SUBPARTS (vectype), nunits))
    5117              :             {
    5118           20 :               unsigned int k, l;
    5119           40 :               poly_uint64 prec = GET_MODE_BITSIZE (TYPE_MODE (vectype));
    5120           40 :               poly_uint64 bytes = GET_MODE_SIZE (TYPE_MODE (vectype));
    5121           20 :               k = vector_unroll_factor (nunits,
    5122              :                                         TYPE_VECTOR_SUBPARTS (vectype));
    5123           20 :               gcc_assert ((k & (k - 1)) == 0);
    5124           72 :               for (l = 0; l < k; l++)
    5125              :                 {
    5126           52 :                   tree t;
    5127           52 :                   if (ratype)
    5128              :                     {
    5129           44 :                       t = build_fold_addr_expr (new_temp);
    5130           44 :                       t = build2 (MEM_REF, vectype, t,
    5131           44 :                                   build_int_cst (TREE_TYPE (t), l * bytes));
    5132              :                     }
    5133              :                   else
    5134            8 :                     t = build3 (BIT_FIELD_REF, vectype, new_temp,
    5135            8 :                                 bitsize_int (prec), bitsize_int (l * prec));
    5136           52 :                   new_stmt = gimple_build_assign (make_ssa_name (vectype), t);
    5137           52 :                   vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    5138              : 
    5139           52 :                   SLP_TREE_VEC_DEFS (slp_node)
    5140           52 :                     .quick_push (gimple_assign_lhs (new_stmt));
    5141              :                 }
    5142              : 
    5143           20 :               if (ratype)
    5144           16 :                 vect_clobber_variable (vinfo, stmt_info, gsi, new_temp);
    5145           20 :               continue;
    5146           20 :             }
    5147          502 :           else if (!multiple_p (nunits, TYPE_VECTOR_SUBPARTS (vectype)))
    5148              :             {
    5149           56 :               unsigned int k;
    5150           56 :               if (!constant_multiple_p (TYPE_VECTOR_SUBPARTS (vectype),
    5151           56 :                                         TYPE_VECTOR_SUBPARTS (rtype), &k))
    5152            0 :                 gcc_unreachable ();
    5153           56 :               gcc_assert ((k & (k - 1)) == 0);
    5154           56 :               if (!ret_ctor_elts)
    5155           18 :                 vec_alloc (ret_ctor_elts, k);
    5156           56 :               if (ratype)
    5157              :                 {
    5158            4 :                   unsigned int m, o;
    5159            4 :                   o = vector_unroll_factor (nunits,
    5160              :                                             TYPE_VECTOR_SUBPARTS (rtype));
    5161           12 :                   for (m = 0; m < o; m++)
    5162              :                     {
    5163            8 :                       tree tem = build4 (ARRAY_REF, rtype, new_temp,
    5164            8 :                                          size_int (m), NULL_TREE, NULL_TREE);
    5165            8 :                       new_stmt = gimple_build_assign (make_ssa_name (rtype),
    5166              :                                                       tem);
    5167            8 :                       vect_finish_stmt_generation (vinfo, stmt_info,
    5168              :                                                    new_stmt, gsi);
    5169            8 :                       CONSTRUCTOR_APPEND_ELT (ret_ctor_elts, NULL_TREE,
    5170              :                                               gimple_assign_lhs (new_stmt));
    5171              :                     }
    5172            4 :                   vect_clobber_variable (vinfo, stmt_info, gsi, new_temp);
    5173              :                 }
    5174              :               else
    5175           52 :                 CONSTRUCTOR_APPEND_ELT (ret_ctor_elts, NULL_TREE, new_temp);
    5176           56 :               if (ret_ctor_elts->length () != k)
    5177           38 :                 continue;
    5178           18 :               vec_oprnd0 = build_constructor (vectype, ret_ctor_elts);
    5179           18 :               new_stmt
    5180           18 :                 = gimple_build_assign (make_ssa_name (vec_dest), vec_oprnd0);
    5181           18 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    5182           18 :               ret_ctor_elts = NULL;
    5183              : 
    5184           18 :               SLP_TREE_VEC_DEFS (slp_node)
    5185           18 :                 .quick_push (gimple_assign_lhs (new_stmt));
    5186           18 :               continue;
    5187           18 :             }
    5188          446 :           else if (ratype)
    5189              :             {
    5190            0 :               tree t = build_fold_addr_expr (new_temp);
    5191            0 :               t = build2 (MEM_REF, vectype, t,
    5192            0 :                           build_int_cst (TREE_TYPE (t), 0));
    5193            0 :               new_stmt = gimple_build_assign (make_ssa_name (vec_dest), t);
    5194            0 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    5195            0 :               vect_clobber_variable (vinfo, stmt_info, gsi, new_temp);
    5196              :             }
    5197          446 :           else if (!useless_type_conversion_p (vectype, rtype))
    5198              :             {
    5199            0 :               vec_oprnd0 = build1 (VIEW_CONVERT_EXPR, vectype, new_temp);
    5200            0 :               new_stmt
    5201            0 :                 = gimple_build_assign (make_ssa_name (vec_dest), vec_oprnd0);
    5202            0 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    5203              :             }
    5204              :         }
    5205              : 
    5206          452 :       if (gimple_get_lhs (new_stmt))
    5207          446 :         SLP_TREE_VEC_DEFS (slp_node).quick_push (gimple_get_lhs (new_stmt));
    5208              :     }
    5209              : 
    5210         1239 :   for (i = 0; i < nargs; ++i)
    5211              :     {
    5212          849 :       vec<tree> oprndsi = vec_oprnds[i];
    5213          849 :       oprndsi.release ();
    5214              :     }
    5215          390 :   vargs.release ();
    5216              : 
    5217              :   /* Mark the clone as no longer being a candidate for GC.  */
    5218          390 :   bestn->gc_candidate = false;
    5219              : 
    5220          390 :   return true;
    5221         1524 : }
    5222              : 
    5223              : 
    5224              : /* Function vect_gen_widened_results_half
    5225              : 
    5226              :    Create a vector stmt whose code, type, number of arguments, and result
    5227              :    variable are CODE, OP_TYPE, and VEC_DEST, and its arguments are
    5228              :    VEC_OPRND0 and VEC_OPRND1.  The new vector stmt is to be inserted at GSI.
    5229              :    In the case that CODE is a CALL_EXPR, this means that a call to DECL
    5230              :    needs to be created (DECL is a function-decl of a target-builtin).
    5231              :    STMT_INFO is the original scalar stmt that we are vectorizing.  */
    5232              : 
    5233              : static gimple *
    5234        32363 : vect_gen_widened_results_half (vec_info *vinfo, code_helper ch,
    5235              :                                tree vec_oprnd0, tree vec_oprnd1, int op_type,
    5236              :                                tree vec_dest, gimple_stmt_iterator *gsi,
    5237              :                                stmt_vec_info stmt_info)
    5238              : {
    5239        32363 :   gimple *new_stmt;
    5240        32363 :   tree new_temp;
    5241              : 
    5242              :   /* Generate half of the widened result:  */
    5243        32363 :   if (op_type != binary_op)
    5244        31187 :     vec_oprnd1 = NULL;
    5245        32363 :   new_stmt = vect_gimple_build (vec_dest, ch, vec_oprnd0, vec_oprnd1);
    5246        32363 :   new_temp = make_ssa_name (vec_dest, new_stmt);
    5247        32363 :   gimple_set_lhs (new_stmt, new_temp);
    5248        32363 :   vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    5249              : 
    5250        32363 :   return new_stmt;
    5251              : }
    5252              : 
    5253              : 
    5254              : /* Create vectorized demotion statements for vector operands from VEC_OPRNDS.
    5255              :    For multi-step conversions store the resulting vectors and call the function
    5256              :    recursively. When NARROW_SRC_P is true, there's still a conversion after
    5257              :    narrowing, don't store the vectors in the SLP_NODE or in vector info of
    5258              :    the scalar statement(or in STMT_VINFO_RELATED_STMT chain).  */
    5259              : 
    5260              : static void
    5261        12525 : vect_create_vectorized_demotion_stmts (vec_info *vinfo, vec<tree> *vec_oprnds,
    5262              :                                        int multi_step_cvt,
    5263              :                                        stmt_vec_info stmt_info,
    5264              :                                        vec<tree> &vec_dsts,
    5265              :                                        gimple_stmt_iterator *gsi,
    5266              :                                        slp_tree slp_node, code_helper code,
    5267              :                                        bool narrow_src_p)
    5268              : {
    5269        12525 :   unsigned int i;
    5270        12525 :   tree vop0, vop1, new_tmp, vec_dest;
    5271              : 
    5272        12525 :   vec_dest = vec_dsts.pop ();
    5273              : 
    5274        29488 :   for (i = 0; i < vec_oprnds->length (); i += 2)
    5275              :     {
    5276              :       /* Create demotion operation.  */
    5277        16963 :       vop0 = (*vec_oprnds)[i];
    5278        16963 :       vop1 = (*vec_oprnds)[i + 1];
    5279        16963 :       gimple *new_stmt = vect_gimple_build (vec_dest, code, vop0, vop1);
    5280        16963 :       new_tmp = make_ssa_name (vec_dest, new_stmt);
    5281        16963 :       gimple_set_lhs (new_stmt, new_tmp);
    5282        16963 :       vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    5283        16963 :       if (multi_step_cvt || narrow_src_p)
    5284              :         /* Store the resulting vector for next recursive call,
    5285              :            or return the resulting vector_tmp for NARROW FLOAT_EXPR.  */
    5286         6992 :         (*vec_oprnds)[i/2] = new_tmp;
    5287              :       else
    5288              :         {
    5289              :           /* This is the last step of the conversion sequence. Store the
    5290              :              vectors in SLP_NODE.  */
    5291         9971 :           slp_node->push_vec_def (new_stmt);
    5292              :         }
    5293              :     }
    5294              : 
    5295              :   /* For multi-step demotion operations we first generate demotion operations
    5296              :      from the source type to the intermediate types, and then combine the
    5297              :      results (stored in VEC_OPRNDS) in demotion operation to the destination
    5298              :      type.  */
    5299        12525 :   if (multi_step_cvt)
    5300              :     {
    5301              :       /* At each level of recursion we have half of the operands we had at the
    5302              :          previous level.  */
    5303         3110 :       vec_oprnds->truncate ((i+1)/2);
    5304         3110 :       vect_create_vectorized_demotion_stmts (vinfo, vec_oprnds,
    5305              :                                              multi_step_cvt - 1,
    5306              :                                              stmt_info, vec_dsts, gsi,
    5307         3110 :                                              slp_node, VEC_PACK_TRUNC_EXPR,
    5308              :                                              narrow_src_p);
    5309              :     }
    5310              : 
    5311        12525 :   vec_dsts.quick_push (vec_dest);
    5312        12525 : }
    5313              : 
    5314              : 
    5315              : /* Create vectorized promotion statements for vector operands from VEC_OPRNDS0
    5316              :    and VEC_OPRNDS1, for a binary operation associated with scalar statement
    5317              :    STMT_INFO.  For multi-step conversions store the resulting vectors and
    5318              :    call the function recursively.  When NUM_VECTORS is not -1U then only
    5319              :    NUM_VECTORS will be produced.  */
    5320              : 
    5321              : static void
    5322        11835 : vect_create_vectorized_promotion_stmts (vec_info *vinfo,
    5323              :                                         vec<tree> *vec_oprnds0,
    5324              :                                         vec<tree> *vec_oprnds1,
    5325              :                                         stmt_vec_info stmt_info, tree vec_dest,
    5326              :                                         gimple_stmt_iterator *gsi,
    5327              :                                         code_helper ch1,
    5328              :                                         code_helper ch2, int op_type,
    5329              :                                         unsigned num_vectors)
    5330              : {
    5331        11835 :   int i;
    5332        11835 :   tree vop0, vop1, new_tmp1, new_tmp2;
    5333        11835 :   gimple *new_stmt1, *new_stmt2;
    5334        11835 :   vec<tree> vec_tmp = vNULL;
    5335              : 
    5336        11835 :   vec_tmp.create (num_vectors != -1U
    5337         1840 :                   ? num_vectors : 2 * vec_oprnds0->length ());
    5338        28022 :   FOR_EACH_VEC_ELT (*vec_oprnds0, i, vop0)
    5339              :     {
    5340        16187 :       if (op_type == binary_op)
    5341          588 :         vop1 = (*vec_oprnds1)[i];
    5342              :       else
    5343              :         vop1 = NULL_TREE;
    5344              : 
    5345              :       /* Generate the two halves of promotion operation.  */
    5346        16187 :       new_stmt1 = vect_gen_widened_results_half (vinfo, ch1, vop0, vop1,
    5347              :                                                  op_type, vec_dest, gsi,
    5348              :                                                  stmt_info);
    5349        16187 :       new_tmp1 = gimple_get_lhs (new_stmt1);
    5350        16187 :       vec_tmp.quick_push (new_tmp1);
    5351              : 
    5352        16187 :       if (vec_tmp.space (1))
    5353              :         {
    5354        16176 :           new_stmt2 = vect_gen_widened_results_half (vinfo, ch2, vop0, vop1,
    5355              :                                                      op_type, vec_dest, gsi,
    5356              :                                                      stmt_info);
    5357        16176 :           new_tmp2 = gimple_get_lhs (new_stmt2);
    5358        16176 :           vec_tmp.quick_push (new_tmp2);
    5359              :         }
    5360              : 
    5361        16187 :       if (!vec_tmp.space (1))
    5362              :         break;
    5363              :     }
    5364              : 
    5365        11835 :   vec_oprnds0->release ();
    5366        11835 :   *vec_oprnds0 = vec_tmp;
    5367        11835 : }
    5368              : 
    5369              : /* Create vectorized promotion stmts for widening stmts using only half the
    5370              :    potential vector size for input.  */
    5371              : static void
    5372           46 : vect_create_half_widening_stmts (vec_info *vinfo,
    5373              :                                         vec<tree> *vec_oprnds0,
    5374              :                                         vec<tree> *vec_oprnds1,
    5375              :                                         stmt_vec_info stmt_info, tree vec_dest,
    5376              :                                         gimple_stmt_iterator *gsi,
    5377              :                                         code_helper code1,
    5378              :                                         int op_type)
    5379              : {
    5380           46 :   int i;
    5381           46 :   tree vop0, vop1;
    5382           46 :   gimple *new_stmt1;
    5383           46 :   gimple *new_stmt2;
    5384           46 :   gimple *new_stmt3;
    5385           46 :   vec<tree> vec_tmp = vNULL;
    5386              : 
    5387           46 :   vec_tmp.create (vec_oprnds0->length ());
    5388          138 :   FOR_EACH_VEC_ELT (*vec_oprnds0, i, vop0)
    5389              :     {
    5390           46 :       tree new_tmp1, new_tmp2, new_tmp3, out_type;
    5391              : 
    5392           46 :       gcc_assert (op_type == binary_op);
    5393           46 :       vop1 = (*vec_oprnds1)[i];
    5394              : 
    5395              :       /* Widen the first vector input.  */
    5396           46 :       out_type = TREE_TYPE (vec_dest);
    5397           46 :       new_tmp1 = make_ssa_name (out_type);
    5398           46 :       new_stmt1 = gimple_build_assign (new_tmp1, NOP_EXPR, vop0);
    5399           46 :       vect_finish_stmt_generation (vinfo, stmt_info, new_stmt1, gsi);
    5400           46 :       if (VECTOR_TYPE_P (TREE_TYPE (vop1)))
    5401              :         {
    5402              :           /* Widen the second vector input.  */
    5403           46 :           new_tmp2 = make_ssa_name (out_type);
    5404           46 :           new_stmt2 = gimple_build_assign (new_tmp2, NOP_EXPR, vop1);
    5405           46 :           vect_finish_stmt_generation (vinfo, stmt_info, new_stmt2, gsi);
    5406              :           /* Perform the operation.  With both vector inputs widened.  */
    5407           46 :           new_stmt3 = vect_gimple_build (vec_dest, code1, new_tmp1, new_tmp2);
    5408              :         }
    5409              :       else
    5410              :         {
    5411              :           /* Perform the operation.  With the single vector input widened.  */
    5412            0 :           new_stmt3 = vect_gimple_build (vec_dest, code1, new_tmp1, vop1);
    5413              :         }
    5414              : 
    5415           46 :       new_tmp3 = make_ssa_name (vec_dest, new_stmt3);
    5416           46 :       gimple_assign_set_lhs (new_stmt3, new_tmp3);
    5417           46 :       vect_finish_stmt_generation (vinfo, stmt_info, new_stmt3, gsi);
    5418              : 
    5419              :       /* Store the results for the next step.  */
    5420           46 :       vec_tmp.quick_push (new_tmp3);
    5421              :     }
    5422              : 
    5423           46 :   vec_oprnds0->release ();
    5424           46 :   *vec_oprnds0 = vec_tmp;
    5425           46 : }
    5426              : 
    5427              : 
    5428              : /* Check if STMT_INFO performs a conversion operation that can be vectorized.
    5429              :    If COST_VEC is passed, calculate costs but don't change anything,
    5430              :    otherwise, vectorize STMT_INFO: create a vectorized stmt to replace
    5431              :    it, and insert it at GSI.
    5432              :    Return true if STMT_INFO is vectorizable in this way.  */
    5433              : 
    5434              : static bool
    5435      2693001 : vectorizable_conversion (vec_info *vinfo,
    5436              :                          stmt_vec_info stmt_info, gimple_stmt_iterator *gsi,
    5437              :                          slp_tree slp_node,
    5438              :                          stmt_vector_for_cost *cost_vec)
    5439              : {
    5440      2693001 :   tree vec_dest, cvt_op = NULL_TREE;
    5441      2693001 :   tree scalar_dest;
    5442      2693001 :   tree_code tc1;
    5443      2693001 :   code_helper code, code1, code2;
    5444      2693001 :   code_helper codecvt1 = ERROR_MARK, codecvt2 = ERROR_MARK;
    5445      2693001 :   tree new_temp;
    5446      2693001 :   enum vect_def_type dt[2] = {vect_unknown_def_type, vect_unknown_def_type};
    5447      2693001 :   poly_uint64 nunits_in;
    5448      2693001 :   poly_uint64 nunits_out;
    5449      2693001 :   tree vectype_out, vectype_in;
    5450      2693001 :   int i;
    5451      2693001 :   tree lhs_type, rhs_type;
    5452              :   /* For conversions between floating point and integer, there're 2 NARROW
    5453              :      cases. NARROW_SRC is for FLOAT_EXPR, means
    5454              :      integer --DEMOTION--> integer --FLOAT_EXPR--> floating point.
    5455              :      This is safe when the range of the source integer can fit into the lower
    5456              :      precision. NARROW_DST is for FIX_TRUNC_EXPR, means
    5457              :      floating point --FIX_TRUNC_EXPR--> integer --DEMOTION--> INTEGER.
    5458              :      For other conversions, when there's narrowing, NARROW_DST is used as
    5459              :      default.  */
    5460      2693001 :   enum { NARROW_SRC, NARROW_DST, NONE, WIDEN } modifier;
    5461      2693001 :   vec<tree> vec_oprnds0 = vNULL;
    5462      2693001 :   vec<tree> vec_oprnds1 = vNULL;
    5463      2693001 :   tree vop0;
    5464      2693001 :   bb_vec_info bb_vinfo = dyn_cast <bb_vec_info> (vinfo);
    5465      2693001 :   loop_vec_info loop_vinfo = dyn_cast <loop_vec_info> (vinfo);
    5466      2693001 :   int multi_step_cvt = 0;
    5467      2693001 :   vec<tree> interm_types = vNULL;
    5468      2693001 :   tree intermediate_type, cvt_type = NULL_TREE;
    5469      2693001 :   int op_type;
    5470      2693001 :   unsigned short fltsz;
    5471              : 
    5472              :   /* Is STMT a vectorizable conversion?   */
    5473              : 
    5474      2693001 :   if (!STMT_VINFO_RELEVANT_P (stmt_info) && !bb_vinfo)
    5475              :     return false;
    5476              : 
    5477      2693001 :   if (STMT_VINFO_DEF_TYPE (stmt_info) != vect_internal_def
    5478       246817 :       && cost_vec)
    5479              :     return false;
    5480              : 
    5481      2446184 :   gimple* stmt = stmt_info->stmt;
    5482      2446184 :   if (!(is_gimple_assign (stmt) || is_gimple_call (stmt)))
    5483              :     return false;
    5484              : 
    5485      2385580 :   if (gimple_get_lhs (stmt) == NULL_TREE
    5486      2385580 :       || TREE_CODE (gimple_get_lhs (stmt)) != SSA_NAME)
    5487              :     return false;
    5488              : 
    5489      1552530 :   if (TREE_CODE (gimple_get_lhs (stmt)) != SSA_NAME)
    5490              :     return false;
    5491              : 
    5492      1552530 :   if (is_gimple_assign (stmt))
    5493              :     {
    5494      1538849 :       code = gimple_assign_rhs_code (stmt);
    5495      1538849 :       op_type = TREE_CODE_LENGTH ((tree_code) code);
    5496              :     }
    5497        13681 :   else if (gimple_call_internal_p (stmt))
    5498              :     {
    5499         7900 :       code = gimple_call_internal_fn (stmt);
    5500         7900 :       op_type = gimple_call_num_args (stmt);
    5501              :     }
    5502              :   else
    5503              :     return false;
    5504              : 
    5505      1546749 :   bool widen_arith = (code == WIDEN_MULT_EXPR
    5506      1544046 :                  || code == WIDEN_LSHIFT_EXPR
    5507      3090795 :                  || widening_fn_p (code));
    5508              : 
    5509      1544046 :   if (!widen_arith
    5510      1544046 :       && !CONVERT_EXPR_CODE_P (code)
    5511              :       && code != FIX_TRUNC_EXPR
    5512              :       && code != FLOAT_EXPR)
    5513              :     return false;
    5514              : 
    5515              :   /* Check types of lhs and rhs.  */
    5516       205605 :   scalar_dest = gimple_get_lhs (stmt);
    5517       205605 :   lhs_type = TREE_TYPE (scalar_dest);
    5518       205605 :   vectype_out = SLP_TREE_VECTYPE (slp_node);
    5519              : 
    5520              :   /* Check the operands of the operation.  */
    5521       205605 :   slp_tree slp_op0, slp_op1 = NULL;
    5522       205605 :   if (!vect_is_simple_use (vinfo, slp_node,
    5523              :                            0, &slp_op0, &dt[0], &vectype_in))
    5524              :     {
    5525            0 :       if (dump_enabled_p ())
    5526            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    5527              :                          "use not simple.\n");
    5528              :       return false;
    5529              :     }
    5530              : 
    5531       205605 :   rhs_type = TREE_TYPE (gimple_arg (stmt, 0));
    5532       205605 :   if ((code != FIX_TRUNC_EXPR && code != FLOAT_EXPR)
    5533       391080 :       && !((INTEGRAL_TYPE_P (lhs_type)
    5534       170226 :             && INTEGRAL_TYPE_P (rhs_type))
    5535              :            || (SCALAR_FLOAT_TYPE_P (lhs_type)
    5536        10233 :                && SCALAR_FLOAT_TYPE_P (rhs_type))))
    5537              :     return false;
    5538              : 
    5539       200589 :   if (!VECTOR_BOOLEAN_TYPE_P (vectype_out)
    5540       179878 :       && INTEGRAL_TYPE_P (lhs_type)
    5541       348019 :       && !type_has_mode_precision_p (lhs_type))
    5542              :     {
    5543          656 :       if (dump_enabled_p ())
    5544           54 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    5545              :                          "type conversion to bit-precision unsupported\n");
    5546              :       return false;
    5547              :     }
    5548              : 
    5549              :   /* _BitInt values are not sign-/zero-extended to mode precision.  */
    5550       199933 :   if (!VECTOR_BOOLEAN_TYPE_P (vectype_out)
    5551       179222 :       && BITINT_TYPE_P (rhs_type)
    5552       200106 :       && !type_has_mode_precision_p (rhs_type))
    5553              :     {
    5554           16 :       if (dump_enabled_p ())
    5555            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    5556              :                          "type conversion from _BitInt unsupported\n");
    5557              :       return false;
    5558              :     }
    5559              : 
    5560       199917 :   if (op_type == binary_op)
    5561              :     {
    5562         2703 :       gcc_assert (code == WIDEN_MULT_EXPR
    5563              :                   || code == WIDEN_LSHIFT_EXPR
    5564              :                   || widening_fn_p (code));
    5565              : 
    5566         2703 :       tree vectype1_in;
    5567         2703 :       if (!vect_is_simple_use (vinfo, slp_node, 1,
    5568              :                                &slp_op1, &dt[1], &vectype1_in))
    5569              :         {
    5570            0 :           if (dump_enabled_p ())
    5571            0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    5572              :                              "use not simple.\n");
    5573            0 :           return false;
    5574              :         }
    5575              :       /* For WIDEN_MULT_EXPR, if OP0 is a constant, use the type of
    5576              :          OP1.  */
    5577         2703 :       if (!vectype_in)
    5578          192 :         vectype_in = vectype1_in;
    5579              :     }
    5580              : 
    5581              :   /* If slp_op0 is an external or constant def, infer the vector type
    5582              :      from the scalar type.  */
    5583       199917 :   if (!cost_vec)
    5584        24054 :     gcc_assert (vectype_in);
    5585       199917 :   if (!vectype_in)
    5586        26564 :     vectype_in = get_vectype_for_scalar_type (vinfo, rhs_type, slp_node);
    5587       199917 :   if (!vectype_in)
    5588              :     {
    5589          286 :       if (dump_enabled_p ())
    5590            2 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    5591              :                          "no vectype for scalar type %T\n", rhs_type);
    5592              : 
    5593              :       return false;
    5594              :     }
    5595              : 
    5596       399262 :   if (VECTOR_BOOLEAN_TYPE_P (vectype_out)
    5597       199631 :       != VECTOR_BOOLEAN_TYPE_P (vectype_in))
    5598              :     {
    5599          315 :       if (dump_enabled_p ())
    5600           36 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    5601              :                          "can't convert between boolean and non "
    5602              :                          "boolean vectors %T\n", rhs_type);
    5603              : 
    5604              :       return false;
    5605              :     }
    5606              : 
    5607       199316 :   nunits_in = TYPE_VECTOR_SUBPARTS (vectype_in);
    5608       199316 :   nunits_out = TYPE_VECTOR_SUBPARTS (vectype_out);
    5609       199316 :   if (known_eq (nunits_out, nunits_in))
    5610        96455 :     if (widen_arith)
    5611              :       modifier = WIDEN;
    5612              :     else
    5613       199316 :       modifier = NONE;
    5614       102861 :   else if (multiple_p (nunits_out, nunits_in))
    5615              :     modifier = NARROW_DST;
    5616              :   else
    5617              :     {
    5618        57472 :       gcc_checking_assert (multiple_p (nunits_in, nunits_out));
    5619              :       modifier = WIDEN;
    5620              :     }
    5621              : 
    5622       199316 :   bool found_mode = false;
    5623       199316 :   scalar_mode lhs_mode = SCALAR_TYPE_MODE (lhs_type);
    5624       199316 :   scalar_mode rhs_mode = SCALAR_TYPE_MODE (rhs_type);
    5625       199316 :   opt_scalar_mode rhs_mode_iter;
    5626       199316 :   auto_vec<std::pair<tree, tree_code>, 2> converts;
    5627       199316 :   bool evenodd_ok = false;
    5628              : 
    5629              :   /* Supportable by target?  */
    5630       199316 :   switch (modifier)
    5631              :     {
    5632        96057 :     case NONE:
    5633        96057 :       if (code != FIX_TRUNC_EXPR
    5634              :           && code != FLOAT_EXPR
    5635              :           && !CONVERT_EXPR_CODE_P (code))
    5636              :         return false;
    5637        96057 :       gcc_assert (code.is_tree_code ());
    5638        96057 :       if (supportable_indirect_convert_operation (code,
    5639              :                                                   vectype_out, vectype_in,
    5640              :                                                   converts, slp_op0))
    5641              :         {
    5642        88350 :           gcc_assert (converts.length () <= 2);
    5643        88350 :           if (converts.length () == 1)
    5644              :             {
    5645        88276 :               code1 = converts[0].second;
    5646        88276 :               if (CONVERT_EXPR_CODE_P (code)
    5647       165850 :                   && tree_nop_conversion_p (TREE_TYPE (vectype_out),
    5648        77574 :                                             TREE_TYPE (vectype_in)))
    5649              :                 /* NOP conversions are handled by vectorizable_assignment.  */
    5650              :                 return false;
    5651              :             }
    5652              :           else
    5653              :             {
    5654           74 :               cvt_type = NULL_TREE;
    5655           74 :               multi_step_cvt = converts.length () - 1;
    5656           74 :               codecvt1 = converts[0].second;
    5657           74 :               code1 = converts[1].second;
    5658           74 :               interm_types.safe_push (converts[0].first);
    5659              :             }
    5660              :           break;
    5661              :         }
    5662              : 
    5663              :       /* FALLTHRU */
    5664         7707 :     unsupported:
    5665        20524 :       if (dump_enabled_p ())
    5666          654 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    5667              :                          "conversion not supported by target.\n");
    5668              :       return false;
    5669              : 
    5670        57870 :     case WIDEN:
    5671        57870 :       if (known_eq (nunits_in, nunits_out))
    5672              :         {
    5673          796 :           if (!(code.is_tree_code ()
    5674          398 :                 && supportable_half_widening_operation ((tree_code) code,
    5675              :                                                         vectype_out, vectype_in,
    5676              :                                                         &tc1)))
    5677          118 :             goto unsupported;
    5678          280 :           code1 = tc1;
    5679          280 :           gcc_assert (!(multi_step_cvt && op_type == binary_op));
    5680              :           break;
    5681              :         }
    5682              :       /* Elements in a vector can only be reordered if used in a reduction
    5683              :          operation only.  */
    5684        57472 :       if (code == WIDEN_MULT_EXPR
    5685         2305 :           && loop_vinfo
    5686         2164 :           && !nested_in_vect_loop_p (LOOP_VINFO_LOOP (loop_vinfo), stmt_info)
    5687              :           /* For a SLP reduction we cannot swizzle lanes, detecting a
    5688              :              reduction chain isn't possible here.  */
    5689        59614 :           && SLP_TREE_LANES (slp_node) == 1)
    5690              :         {
    5691              :           /* ???  There is no way to look for SLP uses, so work on
    5692              :              the stmt and what the stmt-based cycle detection gives us.  */
    5693         4088 :           tree lhs = gimple_get_lhs (vect_orig_stmt (stmt_info)->stmt);
    5694         2044 :           stmt_vec_info use_stmt_info
    5695         2044 :             = lhs ? loop_vinfo->lookup_single_use (lhs) : NULL;
    5696         2044 :           stmt_vec_info reduc_def;
    5697         2044 :           if (use_stmt_info
    5698         1901 :               && (reduc_def = STMT_VINFO_REDUC_DEF (use_stmt_info))
    5699              :               /* Avoid any kind of conditional or masked reduction.  */
    5700          129 :               && STMT_VINFO_REDUC_TYPE (reduc_def) == TREE_CODE_REDUCTION
    5701          129 :               && STMT_VINFO_REDUC_CODE (reduc_def).is_tree_code ()
    5702         2173 :               && !needs_fold_left_reduction_p
    5703          129 :                     (TREE_TYPE (lhs), STMT_VINFO_REDUC_CODE (reduc_def)))
    5704              :             evenodd_ok = true;
    5705              :         }
    5706        57472 :       if (supportable_widening_operation (code, vectype_out, vectype_in,
    5707              :                                           evenodd_ok, &code1,
    5708              :                                           &code2, &multi_step_cvt,
    5709              :                                           &interm_types))
    5710              :         {
    5711              :           /* Binary widening operation can only be supported directly by the
    5712              :              architecture.  */
    5713        50923 :           gcc_assert (!(multi_step_cvt && op_type == binary_op));
    5714              :           break;
    5715              :         }
    5716              : 
    5717         6549 :       if (code != FLOAT_EXPR
    5718         6931 :           || GET_MODE_SIZE (lhs_mode) <= GET_MODE_SIZE (rhs_mode))
    5719         6358 :         goto unsupported;
    5720              : 
    5721          191 :       fltsz = GET_MODE_SIZE (lhs_mode);
    5722          278 :       FOR_EACH_2XWIDER_MODE (rhs_mode_iter, rhs_mode)
    5723              :         {
    5724          278 :           rhs_mode = rhs_mode_iter.require ();
    5725          556 :           if (GET_MODE_SIZE (rhs_mode) > fltsz)
    5726              :             break;
    5727              : 
    5728          278 :           cvt_type
    5729          278 :             = build_nonstandard_integer_type (GET_MODE_BITSIZE (rhs_mode), 0);
    5730          278 :           cvt_type = get_same_sized_vectype (cvt_type, vectype_in);
    5731          278 :           if (cvt_type == NULL_TREE)
    5732            0 :             goto unsupported;
    5733              : 
    5734          556 :           if (GET_MODE_SIZE (rhs_mode) == fltsz)
    5735              :             {
    5736           86 :               gcc_assert (code.is_tree_code ());
    5737           86 :               if (!supportable_convert_operation ((tree_code) code, vectype_out,
    5738              :                                                   cvt_type))
    5739           22 :                 goto unsupported;
    5740           64 :               codecvt1 = code;
    5741              :             }
    5742          192 :           else if (!supportable_widening_operation (code, vectype_out,
    5743              :                                                     cvt_type, evenodd_ok,
    5744              :                                                     &codecvt1,
    5745              :                                                     &codecvt2, &multi_step_cvt,
    5746              :                                                     &interm_types))
    5747           87 :             continue;
    5748              :           else
    5749          105 :             gcc_assert (multi_step_cvt == 0);
    5750              : 
    5751          169 :           if (supportable_widening_operation (NOP_EXPR, cvt_type,
    5752              :                                               vectype_in, evenodd_ok, &code1,
    5753              :                                               &code2, &multi_step_cvt,
    5754              :                                               &interm_types))
    5755              :             {
    5756              :               found_mode = true;
    5757              :               break;
    5758              :             }
    5759              :         }
    5760              : 
    5761          169 :       if (!found_mode)
    5762            0 :         goto unsupported;
    5763              : 
    5764          338 :       if (GET_MODE_SIZE (rhs_mode) == fltsz)
    5765           64 :         codecvt2 = ERROR_MARK;
    5766              :       else
    5767              :         {
    5768          105 :           multi_step_cvt++;
    5769          105 :           interm_types.safe_push (cvt_type);
    5770          105 :           cvt_type = NULL_TREE;
    5771              :         }
    5772              :       break;
    5773              : 
    5774        45389 :     case NARROW_DST:
    5775        45389 :       gcc_assert (op_type == unary_op);
    5776        45389 :       if (supportable_narrowing_operation (code, vectype_out, vectype_in,
    5777              :                                            &code1, &multi_step_cvt,
    5778              :                                            &interm_types))
    5779              :         break;
    5780              : 
    5781        19359 :       if (GET_MODE_SIZE (lhs_mode) >= GET_MODE_SIZE (rhs_mode))
    5782          987 :         goto unsupported;
    5783              : 
    5784         5466 :       if (code == FIX_TRUNC_EXPR)
    5785              :         {
    5786          107 :           cvt_type
    5787          107 :             = build_nonstandard_integer_type (GET_MODE_BITSIZE (rhs_mode), 0);
    5788          107 :           cvt_type = get_same_sized_vectype (cvt_type, vectype_in);
    5789          107 :           if (cvt_type == NULL_TREE)
    5790            0 :             goto unsupported;
    5791          107 :           if (supportable_convert_operation ((tree_code) code, cvt_type,
    5792              :                                              vectype_in))
    5793          105 :             codecvt1 = code;
    5794              :           else
    5795            2 :             goto unsupported;
    5796          105 :           if (supportable_narrowing_operation (NOP_EXPR, vectype_out, cvt_type,
    5797              :                                                &code1, &multi_step_cvt,
    5798              :                                                &interm_types))
    5799              :             break;
    5800              :         }
    5801              :       /* If slp_op0 can be represented with low precision integer,
    5802              :          truncate it to cvt_type and the do FLOAT_EXPR.  */
    5803         5359 :       else if (code == FLOAT_EXPR)
    5804              :         {
    5805          792 :           if (cost_vec)
    5806              :             {
    5807          784 :               wide_int op_min_value, op_max_value;
    5808          784 :               tree def;
    5809              : 
    5810              :               /* ???  Merge ranges in case of more than one lane.  */
    5811          784 :               if (SLP_TREE_LANES (slp_op0) != 1
    5812          133 :                   || !(def = vect_get_slp_scalar_def (slp_op0, 0))
    5813          917 :                   || !vect_get_range_info (def, &op_min_value, &op_max_value))
    5814          755 :                 goto unsupported;
    5815              : 
    5816           29 :               if ((wi::min_precision (op_max_value, SIGNED)
    5817           29 :                    > GET_MODE_BITSIZE (lhs_mode))
    5818           29 :                   || (wi::min_precision (op_min_value, SIGNED)
    5819           27 :                       > GET_MODE_BITSIZE (lhs_mode)))
    5820            2 :                 goto unsupported;
    5821          784 :             }
    5822              : 
    5823           35 :           cvt_type
    5824           35 :             = build_nonstandard_integer_type (GET_MODE_BITSIZE (lhs_mode), 0);
    5825           35 :           cvt_type = get_same_sized_vectype (cvt_type, vectype_out);
    5826           35 :           if (cvt_type == NULL_TREE)
    5827            0 :             goto unsupported;
    5828           35 :           if (!supportable_narrowing_operation (NOP_EXPR, cvt_type, vectype_in,
    5829              :                                                 &code1, &multi_step_cvt,
    5830              :                                                 &interm_types))
    5831            2 :             goto unsupported;
    5832           33 :           if (supportable_convert_operation ((tree_code) code, vectype_out,
    5833              :                                              cvt_type))
    5834              :             {
    5835           33 :               codecvt1 = code;
    5836           33 :               modifier = NARROW_SRC;
    5837           33 :               break;
    5838              :             }
    5839              :         }
    5840              : 
    5841         4571 :       goto unsupported;
    5842              : 
    5843              :     default:
    5844              :       gcc_unreachable ();
    5845              :     }
    5846              : 
    5847       112385 :   if (modifier == WIDEN
    5848       112385 :       && loop_vinfo
    5849        49786 :       && LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo)
    5850       133819 :       && (code1 == VEC_WIDEN_MULT_EVEN_EXPR
    5851        21416 :           || widening_evenodd_fn_p (code1)))
    5852              :     {
    5853           18 :       if (dump_enabled_p ())
    5854            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    5855              :                          "can't use a fully-masked loop because"
    5856              :                          " widening operation on even/odd elements"
    5857              :                          " mixes up lanes.\n");
    5858           18 :       LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo) = false;
    5859              :     }
    5860              : 
    5861       112385 :   if (cost_vec)         /* transformation not required.  */
    5862              :     {
    5863        88331 :       if (!vect_maybe_update_slp_op_vectype (slp_op0, vectype_in)
    5864        88331 :           || !vect_maybe_update_slp_op_vectype (slp_op1, vectype_in))
    5865              :         {
    5866            0 :           if (dump_enabled_p ())
    5867            0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    5868              :                              "incompatible vector types for invariants\n");
    5869              :           return false;
    5870              :         }
    5871        88331 :       DUMP_VECT_SCOPE ("vectorizable_conversion");
    5872        88331 :       unsigned int nvectors = vect_get_num_copies (vinfo, slp_node);
    5873        88331 :       if (modifier == NONE)
    5874              :         {
    5875        17345 :           SLP_TREE_TYPE (slp_node) = type_conversion_vec_info_type;
    5876        17345 :           vect_model_simple_cost (vinfo, (1 + multi_step_cvt),
    5877              :                                   slp_node, cost_vec);
    5878              :         }
    5879        70986 :       else if (modifier == NARROW_SRC || modifier == NARROW_DST)
    5880              :         {
    5881        29655 :           SLP_TREE_TYPE (slp_node) = type_demotion_vec_info_type;
    5882              :           /* The final packing step produces one vector result per copy.  */
    5883        29655 :           vect_model_promotion_demotion_cost (slp_node, nvectors,
    5884              :                                               multi_step_cvt, cost_vec,
    5885              :                                               widen_arith);
    5886              :         }
    5887              :       else
    5888              :         {
    5889        41331 :           SLP_TREE_TYPE (slp_node) = type_promotion_vec_info_type;
    5890              :           /* The initial unpacking step produces two vector results
    5891              :              per copy.  MULTI_STEP_CVT is 0 for a single conversion,
    5892              :              so >> MULTI_STEP_CVT divides by 2^(number of steps - 1).  */
    5893        41331 :           vect_model_promotion_demotion_cost (slp_node,
    5894              :                                               nvectors >> multi_step_cvt,
    5895              :                                               multi_step_cvt, cost_vec,
    5896              :                                               widen_arith);
    5897              :         }
    5898        88331 :       interm_types.release ();
    5899        88331 :       return true;
    5900              :     }
    5901              : 
    5902              :   /* Transform.  */
    5903        24054 :   if (dump_enabled_p ())
    5904         4587 :     dump_printf_loc (MSG_NOTE, vect_location, "transform conversion.\n");
    5905              : 
    5906              :   /* In case of multi-step conversion, we first generate conversion operations
    5907              :      to the intermediate types, and then from that types to the final one.
    5908              :      We create vector destinations for the intermediate type (TYPES) received
    5909              :      from supportable_*_operation, and store them in the correct order
    5910              :      for future use in vect_create_vectorized_*_stmts ().  */
    5911        48108 :   auto_vec<tree> vec_dsts (multi_step_cvt + 1);
    5912        24054 :   bool widen_or_narrow_float_p
    5913        24054 :     = cvt_type && (modifier == WIDEN || modifier == NARROW_SRC);
    5914        24054 :   vec_dest = vect_create_destination_var (scalar_dest,
    5915              :                                           widen_or_narrow_float_p
    5916              :                                           ? cvt_type : vectype_out);
    5917        24054 :   vec_dsts.quick_push (vec_dest);
    5918              : 
    5919        24054 :   if (multi_step_cvt)
    5920              :     {
    5921         8972 :       for (i = interm_types.length () - 1;
    5922         9457 :            interm_types.iterate (i, &intermediate_type); i--)
    5923              :         {
    5924         4971 :           vec_dest = vect_create_destination_var (scalar_dest,
    5925              :                                                   intermediate_type);
    5926         4971 :           vec_dsts.quick_push (vec_dest);
    5927              :         }
    5928              :     }
    5929              : 
    5930        24054 :   if (cvt_type)
    5931           80 :     vec_dest = vect_create_destination_var (scalar_dest,
    5932              :                                             widen_or_narrow_float_p
    5933              :                                             ? vectype_out : cvt_type);
    5934              : 
    5935        24054 :   unsigned num_vectors = vect_get_num_copies (vinfo, slp_node);
    5936        24054 :   switch (modifier)
    5937              :     {
    5938         4598 :     case NONE:
    5939         4598 :       vect_get_vec_defs (vinfo, slp_node, true, &vec_oprnds0);
    5940              :       /* vec_dest is intermediate type operand when multi_step_cvt.  */
    5941         4598 :       if (multi_step_cvt)
    5942              :         {
    5943           21 :           cvt_op = vec_dest;
    5944           21 :           vec_dest = vec_dsts[0];
    5945              :         }
    5946              : 
    5947         9643 :       FOR_EACH_VEC_ELT (vec_oprnds0, i, vop0)
    5948              :         {
    5949              :           /* Arguments are ready, create the new vector stmt.  */
    5950         5045 :           gimple* new_stmt;
    5951         5045 :           if (multi_step_cvt)
    5952              :             {
    5953           21 :               gcc_assert (multi_step_cvt == 1);
    5954           21 :               new_stmt = vect_gimple_build (cvt_op, codecvt1, vop0);
    5955           21 :               new_temp = make_ssa_name (cvt_op, new_stmt);
    5956           21 :               gimple_assign_set_lhs (new_stmt, new_temp);
    5957           21 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    5958           21 :               vop0 = new_temp;
    5959              :             }
    5960         5045 :           if (code1 == COND_EXPR)
    5961              :             {
    5962            1 :               gcc_assert (!multi_step_cvt);
    5963            1 :               new_stmt
    5964            2 :                 = gimple_build_assign (vec_dest, VEC_COND_EXPR, vop0,
    5965              :                                        build_minus_one_cst
    5966            1 :                                          (TREE_TYPE (vec_dest)),
    5967            1 :                                        build_zero_cst (TREE_TYPE (vec_dest)));
    5968            1 :               new_temp = make_ssa_name (vec_dest, new_stmt);
    5969            1 :               gimple_set_lhs (new_stmt, new_temp);
    5970            1 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    5971            1 :               tree new_temp2 = make_ssa_name (vectype_out);
    5972            1 :               new_stmt = gimple_build_assign (new_temp2,
    5973              :                                               build1 (VIEW_CONVERT_EXPR,
    5974              :                                                       vectype_out, new_temp));
    5975            1 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    5976            1 :               slp_node->push_vec_def (new_temp2);
    5977              :             }
    5978              :           else
    5979              :             {
    5980         5044 :               new_stmt = vect_gimple_build (vec_dest, code1, vop0);
    5981         5044 :               new_temp = make_ssa_name (vec_dest, new_stmt);
    5982         5044 :               gimple_set_lhs (new_stmt, new_temp);
    5983         5044 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    5984              : 
    5985         5044 :               slp_node->push_vec_def (new_stmt);
    5986              :             }
    5987              :         }
    5988              :       break;
    5989              : 
    5990        10041 :     case WIDEN:
    5991              :       /* In case the vectorization factor (VF) is bigger than the number
    5992              :          of elements that we can fit in a vectype (nunits), we have to
    5993              :          generate more than one vector stmt - i.e - we need to "unroll"
    5994              :          the vector stmt by a factor VF/nunits.  */
    5995        20082 :       vect_get_vec_defs (vinfo, slp_node, true, &vec_oprnds0,
    5996        10041 :                          code != WIDEN_LSHIFT_EXPR && slp_op1, &vec_oprnds1);
    5997        10041 :       if (code == WIDEN_LSHIFT_EXPR)
    5998              :         {
    5999            0 :           int oprnds_size = vec_oprnds0.length ();
    6000            0 :           vec_oprnds1.create (oprnds_size);
    6001            0 :           for (i = 0; i < oprnds_size; ++i)
    6002            0 :             vec_oprnds1.quick_push (vect_get_slp_scalar_def (slp_op1, 0));
    6003              :         }
    6004              :       /* Arguments are ready.  Create the new vector stmts.  */
    6005        21922 :       for (i = multi_step_cvt; i >= 0; i--)
    6006              :         {
    6007        11881 :           tree this_dest = vec_dsts[i];
    6008        11881 :           code_helper c1 = code1, c2 = code2;
    6009        11881 :           if (i == 0 && codecvt2 != ERROR_MARK)
    6010              :             {
    6011           48 :               c1 = codecvt1;
    6012           48 :               c2 = codecvt2;
    6013              :             }
    6014        11881 :           if (known_eq (nunits_out, nunits_in))
    6015           46 :             vect_create_half_widening_stmts (vinfo, &vec_oprnds0, &vec_oprnds1,
    6016              :                                              stmt_info, this_dest, gsi, c1,
    6017              :                                              op_type);
    6018              :           else
    6019              :             /* ???  For constant/external inputs we can end up with
    6020              :                excess lanes.  When the number of inputs already match
    6021              :                the number of required outputs request half of the
    6022              :                lanes (gcc.dg/vect/O3-vect-pr32243.c).  Low coverage
    6023              :                makes this likely incomplete.  */
    6024        13675 :             vect_create_vectorized_promotion_stmts (vinfo, &vec_oprnds0,
    6025              :                                                     &vec_oprnds1, stmt_info,
    6026              :                                                     this_dest, gsi,
    6027              :                                                     c1, c2, op_type,
    6028              :                                                     i == 0 ? num_vectors : -1u);
    6029              :         }
    6030              : 
    6031        38172 :       FOR_EACH_VEC_ELT (vec_oprnds0, i, vop0)
    6032              :         {
    6033        28131 :           gimple *new_stmt;
    6034        28131 :           if (cvt_type)
    6035              :             {
    6036          128 :               new_temp = make_ssa_name (vec_dest);
    6037          128 :               new_stmt = vect_gimple_build (new_temp, codecvt1, vop0);
    6038          128 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    6039              :             }
    6040              :           else
    6041        28003 :             new_stmt = SSA_NAME_DEF_STMT (vop0);
    6042              : 
    6043        28131 :           slp_node->push_vec_def (new_stmt);
    6044              :         }
    6045              :       break;
    6046              : 
    6047         9415 :     case NARROW_SRC:
    6048         9415 :     case NARROW_DST:
    6049              :       /* In case the vectorization factor (VF) is bigger than the number
    6050              :          of elements that we can fit in a vectype (nunits), we have to
    6051              :          generate more than one vector stmt - i.e - we need to "unroll"
    6052              :          the vector stmt by a factor VF/nunits.  */
    6053         9415 :       vect_get_vec_defs (vinfo, slp_node, true, &vec_oprnds0);
    6054              :       /* Arguments are ready.  Create the new vector stmts.  */
    6055         9415 :       if (cvt_type && modifier == NARROW_DST)
    6056          153 :         FOR_EACH_VEC_ELT (vec_oprnds0, i, vop0)
    6057              :           {
    6058          124 :             new_temp = make_ssa_name (vec_dest);
    6059          124 :             gimple *new_stmt = vect_gimple_build (new_temp, codecvt1, vop0);
    6060          124 :             vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    6061          124 :             vec_oprnds0[i] = new_temp;
    6062              :           }
    6063              : 
    6064         9415 :       vect_create_vectorized_demotion_stmts (vinfo, &vec_oprnds0,
    6065              :                                              multi_step_cvt,
    6066              :                                              stmt_info, vec_dsts, gsi,
    6067              :                                              slp_node, code1,
    6068              :                                              modifier == NARROW_SRC);
    6069              :       /* After demoting slp_op0 to cvt_type, convert it to dest.  */
    6070         9415 :       if (cvt_type && code == FLOAT_EXPR)
    6071              :         {
    6072           32 :           for (unsigned int i = 0; i != vec_oprnds0.length() / 2;  i++)
    6073              :             {
    6074              :               /* Arguments are ready, create the new vector stmt.  */
    6075            8 :               gcc_assert (TREE_CODE_LENGTH ((tree_code) codecvt1) == unary_op);
    6076            8 :               gimple *new_stmt
    6077            8 :                 = vect_gimple_build (vec_dest, codecvt1, vec_oprnds0[i]);
    6078            8 :               new_temp = make_ssa_name (vec_dest, new_stmt);
    6079            8 :               gimple_set_lhs (new_stmt, new_temp);
    6080            8 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    6081              : 
    6082              :               /* This is the last step of the conversion sequence. Store the
    6083              :                  vectors in SLP_NODE or in vector info of the scalar statement
    6084              :                  (or in STMT_VINFO_RELATED_STMT chain).  */
    6085            8 :               slp_node->push_vec_def (new_stmt);
    6086              :             }
    6087              :         }
    6088              :       break;
    6089              :     }
    6090              : 
    6091        24054 :   vec_oprnds0.release ();
    6092        24054 :   vec_oprnds1.release ();
    6093        24054 :   interm_types.release ();
    6094              : 
    6095        24054 :   return true;
    6096       199316 : }
    6097              : 
    6098              : /* Return true if we can assume from the scalar form of STMT_INFO that
    6099              :    neither the scalar nor the vector forms will generate code.  STMT_INFO
    6100              :    is known not to involve a data reference.  */
    6101              : 
    6102              : bool
    6103      3343409 : vect_nop_conversion_p (stmt_vec_info stmt_info)
    6104              : {
    6105      3343409 :   gassign *stmt = dyn_cast <gassign *> (stmt_info->stmt);
    6106      3033954 :   if (!stmt || STMT_VINFO_DATA_REF (stmt_info))
    6107              :     return false;
    6108              : 
    6109      1022328 :   tree lhs = gimple_assign_lhs (stmt);
    6110      1022328 :   tree_code code = gimple_assign_rhs_code (stmt);
    6111      1022328 :   tree rhs = gimple_assign_rhs1 (stmt);
    6112              : 
    6113      1022328 :   if (code == SSA_NAME || code == VIEW_CONVERT_EXPR || code == PAREN_EXPR)
    6114              :     return true;
    6115              : 
    6116      1017223 :   if (CONVERT_EXPR_CODE_P (code))
    6117       252425 :     return tree_nop_conversion_p (TREE_TYPE (lhs), TREE_TYPE (rhs));
    6118              : 
    6119              :   return false;
    6120              : }
    6121              : 
    6122              : /* Function vectorizable_assignment.
    6123              : 
    6124              :    Check if STMT_INFO performs an assignment (copy) that can be vectorized.
    6125              :    If COST_VEC is passed, calculate costs but don't change anything,
    6126              :    otherwise, vectorize STMT_INFO: create a vectorized stmt to replace
    6127              :    it, and insert it at GSI.
    6128              :    Return true if STMT_INFO is vectorizable in this way.  */
    6129              : 
    6130              : static bool
    6131      2170701 : vectorizable_assignment (vec_info *vinfo,
    6132              :                          stmt_vec_info stmt_info, gimple_stmt_iterator *gsi,
    6133              :                          slp_tree slp_node,
    6134              :                          stmt_vector_for_cost *cost_vec)
    6135              : {
    6136      2170701 :   tree vec_dest;
    6137      2170701 :   tree scalar_dest;
    6138      2170701 :   tree op;
    6139      2170701 :   tree new_temp;
    6140      2170701 :   enum vect_def_type dt[1] = {vect_unknown_def_type};
    6141      2170701 :   int i;
    6142      2170701 :   vec<tree> vec_oprnds = vNULL;
    6143      2170701 :   tree vop;
    6144      2170701 :   bb_vec_info bb_vinfo = dyn_cast <bb_vec_info> (vinfo);
    6145      2170701 :   enum tree_code code;
    6146      2170701 :   tree vectype_in;
    6147              : 
    6148      2170701 :   if (!STMT_VINFO_RELEVANT_P (stmt_info) && !bb_vinfo)
    6149              :     return false;
    6150              : 
    6151      2170701 :   if (STMT_VINFO_DEF_TYPE (stmt_info) != vect_internal_def
    6152       246817 :       && cost_vec)
    6153              :     return false;
    6154              : 
    6155              :   /* Is vectorizable assignment?  */
    6156      1923884 :   gassign *stmt = dyn_cast <gassign *> (stmt_info->stmt);
    6157      1848221 :   if (!stmt)
    6158              :     return false;
    6159              : 
    6160      1848221 :   scalar_dest = gimple_assign_lhs (stmt);
    6161      1848221 :   if (TREE_CODE (scalar_dest) != SSA_NAME)
    6162              :     return false;
    6163              : 
    6164      1016549 :   if (STMT_VINFO_DATA_REF (stmt_info))
    6165              :     return false;
    6166              : 
    6167       430724 :   code = gimple_assign_rhs_code (stmt);
    6168       430724 :   if (!(gimple_assign_single_p (stmt)
    6169       429053 :         || code == PAREN_EXPR
    6170       427777 :         || CONVERT_EXPR_CODE_P (code)))
    6171              :     return false;
    6172              : 
    6173       109466 :   tree vectype = SLP_TREE_VECTYPE (slp_node);
    6174       109466 :   poly_uint64 nunits = TYPE_VECTOR_SUBPARTS (vectype);
    6175              : 
    6176       109466 :   slp_tree slp_op;
    6177       109466 :   if (!vect_is_simple_use (vinfo, slp_node, 0, &op, &slp_op,
    6178              :                            &dt[0], &vectype_in))
    6179              :     {
    6180            0 :       if (dump_enabled_p ())
    6181            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6182              :                          "use not simple.\n");
    6183              :       return false;
    6184              :     }
    6185       109466 :   if (!vectype_in)
    6186        21450 :     vectype_in = get_vectype_for_scalar_type (vinfo, TREE_TYPE (op), slp_node);
    6187              : 
    6188              :   /* We can handle VIEW_CONVERT conversions that do not change the number
    6189              :      of elements or the vector size or other conversions when the component
    6190              :      types are nop-convertible.  */
    6191       109466 :   if (!vectype_in
    6192       114944 :       || maybe_ne (TYPE_VECTOR_SUBPARTS (vectype_in), nunits)
    6193        96664 :       || (code == VIEW_CONVERT_EXPR
    6194         3054 :           && maybe_ne (GET_MODE_SIZE (TYPE_MODE (vectype)),
    6195         3054 :                        GET_MODE_SIZE (TYPE_MODE (vectype_in))))
    6196       206130 :       || (CONVERT_EXPR_CODE_P (code)
    6197        93749 :           && !tree_nop_conversion_p (TREE_TYPE (vectype),
    6198        93749 :                                      TREE_TYPE (vectype_in))))
    6199              :     return false;
    6200              : 
    6201       273105 :   if (VECTOR_BOOLEAN_TYPE_P (vectype) != VECTOR_BOOLEAN_TYPE_P (vectype_in))
    6202              :     {
    6203           27 :       if (dump_enabled_p ())
    6204            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6205              :                          "can't convert between boolean and non "
    6206            0 :                          "boolean vectors %T\n", TREE_TYPE (op));
    6207              : 
    6208              :       return false;
    6209              :     }
    6210              : 
    6211              :   /* We do not handle bit-precision changes.  */
    6212        91159 :   if ((CONVERT_EXPR_CODE_P (code)
    6213         2915 :        || code == VIEW_CONVERT_EXPR)
    6214        89771 :       && ((INTEGRAL_TYPE_P (TREE_TYPE (scalar_dest))
    6215        88433 :            && !type_has_mode_precision_p (TREE_TYPE (scalar_dest)))
    6216        89224 :           || (INTEGRAL_TYPE_P (TREE_TYPE (op))
    6217        81078 :               && !type_has_mode_precision_p (TREE_TYPE (op))))
    6218              :       /* But a conversion that does not change the bit-pattern is ok.  */
    6219        92312 :       && !(INTEGRAL_TYPE_P (TREE_TYPE (scalar_dest))
    6220         1153 :            && INTEGRAL_TYPE_P (TREE_TYPE (op))
    6221         1153 :            && (((TYPE_PRECISION (TREE_TYPE (scalar_dest))
    6222         1153 :                > TYPE_PRECISION (TREE_TYPE (op)))
    6223          606 :              && TYPE_UNSIGNED (TREE_TYPE (op)))
    6224          609 :                || (TYPE_PRECISION (TREE_TYPE (scalar_dest))
    6225          609 :                    == TYPE_PRECISION (TREE_TYPE (op))))))
    6226              :     {
    6227          378 :       if (dump_enabled_p ())
    6228           42 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6229              :                          "type conversion to/from bit-precision "
    6230              :                          "unsupported.\n");
    6231              :       return false;
    6232              :     }
    6233              : 
    6234        90781 :   if (cost_vec) /* transformation not required.  */
    6235              :     {
    6236        73366 :       if (!vect_maybe_update_slp_op_vectype (slp_op, vectype_in))
    6237              :         {
    6238            0 :           if (dump_enabled_p ())
    6239            0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6240              :                              "incompatible vector types for invariants\n");
    6241              :           return false;
    6242              :         }
    6243        73366 :       SLP_TREE_TYPE (slp_node) = assignment_vec_info_type;
    6244        73366 :       DUMP_VECT_SCOPE ("vectorizable_assignment");
    6245        73366 :       if (!vect_nop_conversion_p (stmt_info))
    6246          316 :         vect_model_simple_cost (vinfo, 1, slp_node, cost_vec);
    6247        73366 :       return true;
    6248              :     }
    6249              : 
    6250              :   /* Transform.  */
    6251        17415 :   if (dump_enabled_p ())
    6252         3882 :     dump_printf_loc (MSG_NOTE, vect_location, "transform assignment.\n");
    6253              : 
    6254              :   /* Handle def.  */
    6255        17415 :   vec_dest = vect_create_destination_var (scalar_dest, vectype);
    6256              : 
    6257              :   /* Handle use.  */
    6258        17415 :   vect_get_vec_defs (vinfo, slp_node, true, &vec_oprnds);
    6259              : 
    6260              :   /* Arguments are ready. create the new vector stmt.  */
    6261        56317 :   FOR_EACH_VEC_ELT (vec_oprnds, i, vop)
    6262              :     {
    6263        21487 :       gassign *new_stmt;
    6264        21487 :       if (code == PAREN_EXPR)
    6265          509 :         new_stmt = gimple_build_assign (vec_dest, PAREN_EXPR, vop);
    6266              :       else
    6267              :         {
    6268        20978 :           if (CONVERT_EXPR_CODE_P (code)
    6269          218 :               || code == VIEW_CONVERT_EXPR)
    6270        20918 :             vop = build1 (VIEW_CONVERT_EXPR, vectype, vop);
    6271        20978 :           new_stmt = gimple_build_assign (vec_dest, vop);
    6272              :         }
    6273        21487 :       new_temp = make_ssa_name (vec_dest, new_stmt);
    6274        21487 :       gimple_assign_set_lhs (new_stmt, new_temp);
    6275        21487 :       vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    6276        21487 :       slp_node->push_vec_def (new_stmt);
    6277              :     }
    6278              : 
    6279        17415 :   vec_oprnds.release ();
    6280        17415 :   return true;
    6281              : }
    6282              : 
    6283              : 
    6284              : /* Return TRUE if CODE (a shift operation) is supported for SCALAR_TYPE
    6285              :    either as shift by a scalar or by a vector.  */
    6286              : 
    6287              : bool
    6288       325581 : vect_supportable_shift (vec_info *vinfo, enum tree_code code, tree scalar_type)
    6289              : {
    6290       325581 :   optab optab;
    6291       325581 :   tree vectype;
    6292              : 
    6293       325581 :   vectype = get_vectype_for_scalar_type (vinfo, scalar_type);
    6294       325581 :   if (!vectype)
    6295              :     return false;
    6296              : 
    6297       325581 :   optab = optab_for_tree_code (code, vectype, optab_scalar);
    6298       325581 :   if (optab && can_implement_p (optab, TYPE_MODE (vectype)))
    6299              :     return true;
    6300              : 
    6301       284223 :   optab = optab_for_tree_code (code, vectype, optab_vector);
    6302       284223 :   if (optab && can_implement_p (optab, TYPE_MODE (vectype)))
    6303              :     return true;
    6304              : 
    6305              :   return false;
    6306              : }
    6307              : 
    6308              : 
    6309              : /* Function vectorizable_shift.
    6310              : 
    6311              :    Check if STMT_INFO performs a shift operation that can be vectorized.
    6312              :    If COST_VEC is passed, calculate costs but don't change anything,
    6313              :    otherwise, vectorize STMT_INFO: create a vectorized stmt to replace
    6314              :    it, and insert it at GSI.
    6315              :    Return true if STMT_INFO is vectorizable in this way.  */
    6316              : 
    6317              : static bool
    6318       785099 : vectorizable_shift (vec_info *vinfo,
    6319              :                     stmt_vec_info stmt_info, gimple_stmt_iterator *gsi,
    6320              :                     slp_tree slp_node,
    6321              :                     stmt_vector_for_cost *cost_vec)
    6322              : {
    6323       785099 :   tree vec_dest;
    6324       785099 :   tree scalar_dest;
    6325       785099 :   tree op0, op1 = NULL;
    6326       785099 :   tree vec_oprnd1 = NULL_TREE;
    6327       785099 :   tree vectype;
    6328       785099 :   enum tree_code code;
    6329       785099 :   machine_mode vec_mode;
    6330       785099 :   tree new_temp;
    6331       785099 :   optab optab;
    6332       785099 :   int icode;
    6333       785099 :   machine_mode optab_op2_mode;
    6334       785099 :   enum vect_def_type dt[2] = {vect_unknown_def_type, vect_unknown_def_type};
    6335       785099 :   poly_uint64 nunits_in;
    6336       785099 :   poly_uint64 nunits_out;
    6337       785099 :   tree vectype_out;
    6338       785099 :   tree op1_vectype;
    6339       785099 :   int i;
    6340       785099 :   vec<tree> vec_oprnds0 = vNULL;
    6341       785099 :   vec<tree> vec_oprnds1 = vNULL;
    6342       785099 :   tree vop0, vop1;
    6343       785099 :   unsigned int k;
    6344       785099 :   bool scalar_shift_arg = true;
    6345       785099 :   bb_vec_info bb_vinfo = dyn_cast <bb_vec_info> (vinfo);
    6346       785099 :   bool incompatible_op1_vectype_p = false;
    6347              : 
    6348       785099 :   if (!STMT_VINFO_RELEVANT_P (stmt_info) && !bb_vinfo)
    6349              :     return false;
    6350              : 
    6351       785099 :   if (STMT_VINFO_DEF_TYPE (stmt_info) != vect_internal_def
    6352       246817 :       && STMT_VINFO_DEF_TYPE (stmt_info) != vect_nested_cycle
    6353       245415 :       && cost_vec)
    6354              :     return false;
    6355              : 
    6356              :   /* Is STMT a vectorizable binary/unary operation?   */
    6357       539684 :   gassign *stmt = dyn_cast <gassign *> (stmt_info->stmt);
    6358       465177 :   if (!stmt)
    6359              :     return false;
    6360              : 
    6361       465177 :   if (TREE_CODE (gimple_assign_lhs (stmt)) != SSA_NAME)
    6362              :     return false;
    6363              : 
    6364       464601 :   code = gimple_assign_rhs_code (stmt);
    6365              : 
    6366       464601 :   if (!(code == LSHIFT_EXPR || code == RSHIFT_EXPR || code == LROTATE_EXPR
    6367              :       || code == RROTATE_EXPR))
    6368              :     return false;
    6369              : 
    6370        66376 :   scalar_dest = gimple_assign_lhs (stmt);
    6371        66376 :   vectype_out = SLP_TREE_VECTYPE (slp_node);
    6372        66376 :   if (!type_has_mode_precision_p (TREE_TYPE (scalar_dest)))
    6373              :     {
    6374            0 :       if (dump_enabled_p ())
    6375            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6376              :                          "bit-precision shifts not supported.\n");
    6377              :       return false;
    6378              :     }
    6379              : 
    6380        66376 :   slp_tree slp_op0;
    6381        66376 :   if (!vect_is_simple_use (vinfo, slp_node,
    6382              :                            0, &op0, &slp_op0, &dt[0], &vectype))
    6383              :     {
    6384            0 :       if (dump_enabled_p ())
    6385            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6386              :                          "use not simple.\n");
    6387              :       return false;
    6388              :     }
    6389              :   /* If op0 is an external or constant def, infer the vector type
    6390              :      from the scalar type.  */
    6391        66376 :   if (!vectype)
    6392        14759 :     vectype = get_vectype_for_scalar_type (vinfo, TREE_TYPE (op0), slp_node);
    6393        66376 :   if (!cost_vec)
    6394         9583 :     gcc_assert (vectype);
    6395        66376 :   if (!vectype)
    6396              :     {
    6397            0 :       if (dump_enabled_p ())
    6398            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6399              :                          "no vectype for scalar type\n");
    6400              :       return false;
    6401              :     }
    6402              : 
    6403        66376 :   nunits_out = TYPE_VECTOR_SUBPARTS (vectype_out);
    6404        66376 :   nunits_in = TYPE_VECTOR_SUBPARTS (vectype);
    6405        66376 :   if (maybe_ne (nunits_out, nunits_in))
    6406              :     return false;
    6407              : 
    6408        66376 :   stmt_vec_info op1_def_stmt_info;
    6409        66376 :   slp_tree slp_op1;
    6410        66376 :   if (!vect_is_simple_use (vinfo, slp_node, 1, &op1, &slp_op1,
    6411              :                            &dt[1], &op1_vectype, &op1_def_stmt_info))
    6412              :     {
    6413            0 :       if (dump_enabled_p ())
    6414            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6415              :                          "use not simple.\n");
    6416              :       return false;
    6417              :     }
    6418              : 
    6419              :   /* Determine whether the shift amount is a vector, or scalar.  If the
    6420              :      shift/rotate amount is a vector, use the vector/vector shift optabs.  */
    6421              : 
    6422        66376 :   if ((dt[1] == vect_internal_def
    6423        66376 :        || dt[1] == vect_induction_def
    6424        49544 :        || dt[1] == vect_nested_cycle)
    6425        16850 :       && SLP_TREE_LANES (slp_node) == 1)
    6426              :     scalar_shift_arg = false;
    6427        49585 :   else if (dt[1] == vect_constant_def
    6428              :            || dt[1] == vect_external_def
    6429        49585 :            || dt[1] == vect_internal_def)
    6430              :     {
    6431              :       /* For internal SLP defs we have to make sure we see scalar stmts
    6432              :          for all vector elements.
    6433              :          ???  For different vectors we could resort to a different
    6434              :          scalar shift operand but code-generation below simply always
    6435              :          takes the first.  */
    6436        49579 :       if (dt[1] == vect_internal_def
    6437        49579 :           && maybe_ne (nunits_out * vect_get_num_copies (vinfo, slp_node),
    6438              :                        SLP_TREE_LANES (slp_node)))
    6439              :         scalar_shift_arg = false;
    6440              :       /* If the shift amount is computed by a pattern stmt we cannot
    6441              :          use the scalar amount directly thus give up and use a vector
    6442              :          shift.  */
    6443        49569 :       else if (op1_def_stmt_info && is_pattern_stmt_p (op1_def_stmt_info))
    6444              :         scalar_shift_arg = false;
    6445              :       else
    6446              :         {
    6447        49562 :           tree l0 = vect_get_slp_scalar_def (slp_op1, 0);
    6448        49562 :           if (!l0)
    6449              :             scalar_shift_arg = false;
    6450              :           else
    6451        75667 :             for (k = 1; k < SLP_TREE_LANES (slp_node); ++k)
    6452        26135 :               if (!operand_equal_p (vect_get_slp_scalar_def (slp_op1, k), l0))
    6453              :                 {
    6454              :                   scalar_shift_arg = false;
    6455              :                   break;
    6456              :                 }
    6457              :         }
    6458              :     }
    6459              :   else
    6460              :     {
    6461            6 :       if (dump_enabled_p ())
    6462            6 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6463              :                          "operand mode requires invariant argument.\n");
    6464              :       return false;
    6465              :     }
    6466              : 
    6467              :   /* Vector shifted by vector.  */
    6468        66400 :   bool was_scalar_shift_arg = scalar_shift_arg;
    6469        49562 :   if (!scalar_shift_arg)
    6470              :     {
    6471        16838 :       optab = optab_for_tree_code (code, vectype, optab_vector);
    6472        16838 :       if (dump_enabled_p ())
    6473         1263 :         dump_printf_loc (MSG_NOTE, vect_location,
    6474              :                          "vector/vector shift/rotate found.\n");
    6475              : 
    6476        16838 :       if (!op1_vectype)
    6477           15 :         op1_vectype = get_vectype_for_scalar_type (vinfo, TREE_TYPE (op1),
    6478              :                                                    slp_op1);
    6479        16838 :       incompatible_op1_vectype_p
    6480        33676 :         = (op1_vectype == NULL_TREE
    6481        16838 :            || maybe_ne (TYPE_VECTOR_SUBPARTS (op1_vectype),
    6482        16838 :                         TYPE_VECTOR_SUBPARTS (vectype))
    6483        33674 :            || TYPE_MODE (op1_vectype) != TYPE_MODE (vectype));
    6484        16838 :       if (incompatible_op1_vectype_p
    6485            7 :           && (SLP_TREE_DEF_TYPE (slp_op1) != vect_constant_def
    6486            1 :               || slp_op1->refcnt != 1))
    6487              :         {
    6488            6 :           if (dump_enabled_p ())
    6489            0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6490              :                              "unusable type for last operand in"
    6491              :                              " vector/vector shift/rotate.\n");
    6492              :           return false;
    6493              :         }
    6494              :     }
    6495              :   /* See if the machine has a vector shifted by scalar insn and if not
    6496              :      then see if it has a vector shifted by vector insn.  */
    6497              :   else
    6498              :     {
    6499        49532 :       optab = optab_for_tree_code (code, vectype, optab_scalar);
    6500        49532 :       if (optab
    6501        49532 :           && can_implement_p (optab, TYPE_MODE (vectype)))
    6502              :         {
    6503        49268 :           if (dump_enabled_p ())
    6504         5929 :             dump_printf_loc (MSG_NOTE, vect_location,
    6505              :                              "vector/scalar shift/rotate found.\n");
    6506              :         }
    6507              :       else
    6508              :         {
    6509          264 :           optab = optab_for_tree_code (code, vectype, optab_vector);
    6510          264 :           if (optab
    6511          264 :               && can_implement_p (optab, TYPE_MODE (vectype)))
    6512              :             {
    6513            0 :               scalar_shift_arg = false;
    6514              : 
    6515            0 :               if (dump_enabled_p ())
    6516            0 :                 dump_printf_loc (MSG_NOTE, vect_location,
    6517              :                                  "vector/vector shift/rotate found.\n");
    6518              : 
    6519            0 :               if (!op1_vectype)
    6520            0 :                 op1_vectype = get_vectype_for_scalar_type (vinfo,
    6521            0 :                                                            TREE_TYPE (op1),
    6522              :                                                            slp_op1);
    6523              : 
    6524              :               /* Unlike the other binary operators, shifts/rotates have
    6525              :                  the rhs being int, instead of the same type as the lhs,
    6526              :                  so make sure the scalar is the right type if we are
    6527              :                  dealing with vectors of long long/long/short/char.  */
    6528            0 :               incompatible_op1_vectype_p
    6529            0 :                 = (!op1_vectype
    6530            0 :                    || !tree_nop_conversion_p (TREE_TYPE (vectype),
    6531            0 :                                               TREE_TYPE (op1)));
    6532              :               if (incompatible_op1_vectype_p
    6533            0 :                   && dt[1] == vect_internal_def)
    6534              :                 {
    6535            0 :                   if (dump_enabled_p ())
    6536            0 :                     dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6537              :                                      "unusable type for last operand in"
    6538              :                                      " vector/vector shift/rotate.\n");
    6539              :                   return false;
    6540              :                 }
    6541              :             }
    6542              :         }
    6543              :     }
    6544              : 
    6545              :   /* Supportable by target?  */
    6546        66364 :   if (!optab)
    6547              :     {
    6548            0 :       if (dump_enabled_p ())
    6549            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6550              :                          "no shift optab for %s and %T.\n",
    6551              :                          get_tree_code_name (code), vectype);
    6552              :       return false;
    6553              :     }
    6554        66364 :   vec_mode = TYPE_MODE (vectype);
    6555        66364 :   icode = (int) optab_handler (optab, vec_mode);
    6556        66364 :   if (icode == CODE_FOR_nothing)
    6557              :     {
    6558         6722 :       if (dump_enabled_p ())
    6559          972 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6560              :                          "shift op not supported by target.\n");
    6561              :       return false;
    6562              :     }
    6563              :   /* vector lowering cannot optimize vector shifts using word arithmetic.  */
    6564        59642 :   if (vect_emulated_vector_p (vectype))
    6565              :     return false;
    6566              : 
    6567        59642 :   if (cost_vec) /* transformation not required.  */
    6568              :     {
    6569        50059 :       if (!vect_maybe_update_slp_op_vectype (slp_op0, vectype)
    6570        50059 :           || ((!scalar_shift_arg || dt[1] == vect_internal_def)
    6571         8207 :               && (!incompatible_op1_vectype_p
    6572            1 :                   || dt[1] == vect_constant_def)
    6573         8207 :               && !vect_maybe_update_slp_op_vectype
    6574         8207 :                          (slp_op1,
    6575              :                           incompatible_op1_vectype_p ? vectype : op1_vectype)))
    6576              :         {
    6577            0 :           if (dump_enabled_p ())
    6578            0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6579              :                              "incompatible vector types for invariants\n");
    6580              :           return false;
    6581              :         }
    6582              :       /* Now adjust the constant shift amount in place.  */
    6583        50059 :       if (incompatible_op1_vectype_p
    6584            1 :           && dt[1] == vect_constant_def)
    6585              :         {
    6586            1 :           unsigned group_size = SLP_TREE_LANES (slp_op1);
    6587            2 :           gcc_assert (SLP_TREE_SCALAR_OPS (slp_op1).length () == group_size);
    6588            5 :           for (unsigned i = 0; i < group_size; ++i)
    6589              :             {
    6590            4 :               SLP_TREE_SCALAR_OPS (slp_op1)[i]
    6591            4 :                 = fold_convert (TREE_TYPE (vectype),
    6592              :                                 SLP_TREE_SCALAR_OPS (slp_op1)[i]);
    6593            4 :               gcc_assert ((TREE_CODE (SLP_TREE_SCALAR_OPS (slp_op1)[i])
    6594              :                            == INTEGER_CST));
    6595              :             }
    6596              :         }
    6597        50059 :       SLP_TREE_TYPE (slp_node) = shift_vec_info_type;
    6598        50059 :       DUMP_VECT_SCOPE ("vectorizable_shift");
    6599        50059 :       vect_model_simple_cost (vinfo, 1, slp_node, cost_vec);
    6600        50059 :       return true;
    6601              :     }
    6602              : 
    6603              :   /* Transform.  */
    6604              : 
    6605         9583 :   if (dump_enabled_p ())
    6606         2383 :     dump_printf_loc (MSG_NOTE, vect_location,
    6607              :                      "transform binary/unary operation.\n");
    6608              : 
    6609              :   /* Handle def.  */
    6610         9583 :   vec_dest = vect_create_destination_var (scalar_dest, vectype);
    6611              : 
    6612         9583 :   unsigned nvectors = vect_get_num_copies (vinfo, slp_node);
    6613         9583 :   if (scalar_shift_arg && dt[1] != vect_internal_def)
    6614              :     {
    6615              :       /* Vector shl and shr insn patterns can be defined with scalar
    6616              :          operand 2 (shift operand).  In this case, use constant or loop
    6617              :          invariant op1 directly, without extending it to vector mode
    6618              :          first.  */
    6619         7392 :       optab_op2_mode = insn_data[icode].operand[2].mode;
    6620         7392 :       if (!VECTOR_MODE_P (optab_op2_mode))
    6621              :         {
    6622         7392 :           if (dump_enabled_p ())
    6623         2260 :             dump_printf_loc (MSG_NOTE, vect_location,
    6624              :                              "operand 1 using scalar mode.\n");
    6625         7392 :           vec_oprnd1 = op1;
    6626         7392 :           vec_oprnds1.create (nvectors);
    6627         7392 :           vec_oprnds1.quick_push (vec_oprnd1);
    6628              :           /* Store vec_oprnd1 for every vector stmt to be created.
    6629              :              We check during the analysis that all the shift arguments
    6630              :              are the same.
    6631              :              TODO: Allow different constants for different vector
    6632              :              stmts generated for an SLP instance.  */
    6633        16870 :           for (k = 0; k < nvectors - 1; k++)
    6634         2086 :             vec_oprnds1.quick_push (vec_oprnd1);
    6635              :         }
    6636              :     }
    6637         2191 :   else if (!scalar_shift_arg && incompatible_op1_vectype_p)
    6638              :     {
    6639            0 :       if (was_scalar_shift_arg)
    6640              :         {
    6641              :           /* If the argument was the same in all lanes create the
    6642              :              correctly typed vector shift amount directly.  Note
    6643              :              we made SLP scheduling think we use the original scalars,
    6644              :              so place the compensation code next to the shift which
    6645              :              is conservative.  See PR119640 where it otherwise breaks.  */
    6646            0 :           op1 = fold_convert (TREE_TYPE (vectype), op1);
    6647            0 :           op1 = vect_init_vector (vinfo, stmt_info, op1, TREE_TYPE (vectype),
    6648              :                                   gsi);
    6649            0 :           vec_oprnd1 = vect_init_vector (vinfo, stmt_info, op1, vectype,
    6650              :                                          gsi);
    6651            0 :           vec_oprnds1.create (nvectors);
    6652            0 :           for (k = 0; k < nvectors; k++)
    6653            0 :             vec_oprnds1.quick_push (vec_oprnd1);
    6654              :         }
    6655            0 :       else if (dt[1] == vect_constant_def)
    6656              :         /* The constant shift amount has been adjusted in place.  */
    6657              :         ;
    6658              :       else
    6659            0 :         gcc_assert (TYPE_MODE (op1_vectype) == TYPE_MODE (vectype));
    6660              :     }
    6661              : 
    6662              :   /* vec_oprnd1 is available if operand 1 should be of a scalar-type
    6663              :      (a special case for certain kind of vector shifts); otherwise,
    6664              :      operand 1 should be of a vector type (the usual case).  */
    6665         9583 :   vect_get_vec_defs (vinfo, slp_node,
    6666              :                      true, &vec_oprnds0, !vec_oprnd1, &vec_oprnds1);
    6667              : 
    6668              :   /* Arguments are ready.  Create the new vector stmt.  */
    6669        34375 :   FOR_EACH_VEC_ELT (vec_oprnds0, i, vop0)
    6670              :     {
    6671              :       /* For internal defs where we need to use a scalar shift arg
    6672              :          extract the first lane.  */
    6673        15209 :       if (scalar_shift_arg && dt[1] == vect_internal_def)
    6674              :         {
    6675           12 :           vop1 = vec_oprnds1[0];
    6676           12 :           new_temp = make_ssa_name (TREE_TYPE (TREE_TYPE (vop1)));
    6677           12 :           gassign *new_stmt
    6678           12 :             = gimple_build_assign (new_temp,
    6679           12 :                                    build3 (BIT_FIELD_REF, TREE_TYPE (new_temp),
    6680              :                                            vop1,
    6681           12 :                                            TYPE_SIZE (TREE_TYPE (new_temp)),
    6682              :                                            bitsize_zero_node));
    6683           12 :           vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    6684           12 :           vop1 = new_temp;
    6685           12 :         }
    6686              :       else
    6687        15197 :         vop1 = vec_oprnds1[i];
    6688        15209 :       gassign *new_stmt = gimple_build_assign (vec_dest, code, vop0, vop1);
    6689        15209 :       new_temp = make_ssa_name (vec_dest, new_stmt);
    6690        15209 :       gimple_assign_set_lhs (new_stmt, new_temp);
    6691        15209 :       vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    6692        15209 :       slp_node->push_vec_def (new_stmt);
    6693              :     }
    6694              : 
    6695         9583 :   vec_oprnds0.release ();
    6696         9583 :   vec_oprnds1.release ();
    6697              : 
    6698         9583 :   return true;
    6699              : }
    6700              : 
    6701              : /* Function vectorizable_operation.
    6702              : 
    6703              :    Check if STMT_INFO performs a binary, unary or ternary operation that can
    6704              :    be vectorized.
    6705              :    If COST_VEC is passed, calculate costs but don't change anything,
    6706              :    otherwise, vectorize STMT_INFO: create a vectorized stmt to replace
    6707              :    it, and insert it at GSI.
    6708              :    Return true if STMT_INFO is vectorizable in this way.  */
    6709              : 
    6710              : static bool
    6711      2703297 : vectorizable_operation (vec_info *vinfo,
    6712              :                         stmt_vec_info stmt_info, gimple_stmt_iterator *gsi,
    6713              :                         slp_tree slp_node,
    6714              :                         stmt_vector_for_cost *cost_vec)
    6715              : {
    6716      2703297 :   tree vec_dest;
    6717      2703297 :   tree scalar_dest;
    6718      2703297 :   tree op0, op1 = NULL_TREE, op2 = NULL_TREE;
    6719      2703297 :   tree vectype;
    6720      2703297 :   loop_vec_info loop_vinfo = dyn_cast <loop_vec_info> (vinfo);
    6721      2703297 :   enum tree_code code, orig_code;
    6722      2703297 :   machine_mode vec_mode;
    6723      2703297 :   tree new_temp;
    6724      2703297 :   int op_type;
    6725      2703297 :   optab optab;
    6726      2703297 :   bool target_support_p;
    6727      2703297 :   enum vect_def_type dt[3]
    6728              :     = {vect_unknown_def_type, vect_unknown_def_type, vect_unknown_def_type};
    6729      2703297 :   poly_uint64 nunits_in;
    6730      2703297 :   poly_uint64 nunits_out;
    6731      2703297 :   tree vectype_out;
    6732      2703297 :   int i;
    6733      2703297 :   vec<tree> vec_oprnds0 = vNULL;
    6734      2703297 :   vec<tree> vec_oprnds1 = vNULL;
    6735      2703297 :   vec<tree> vec_oprnds2 = vNULL;
    6736      2703297 :   tree vop0, vop1, vop2;
    6737      2703297 :   bb_vec_info bb_vinfo = dyn_cast <bb_vec_info> (vinfo);
    6738              : 
    6739      2703297 :   if (!STMT_VINFO_RELEVANT_P (stmt_info) && !bb_vinfo)
    6740              :     return false;
    6741              : 
    6742      2703297 :   if (STMT_VINFO_DEF_TYPE (stmt_info) != vect_internal_def
    6743       246817 :       && cost_vec)
    6744              :     return false;
    6745              : 
    6746              :   /* Is STMT a vectorizable binary/unary operation?   */
    6747      2456480 :   gassign *stmt = dyn_cast <gassign *> (stmt_info->stmt);
    6748      2380817 :   if (!stmt)
    6749              :     return false;
    6750              : 
    6751              :   /* Loads and stores are handled in vectorizable_{load,store}.  */
    6752      2380817 :   if (STMT_VINFO_DATA_REF (stmt_info))
    6753              :     return false;
    6754              : 
    6755       963320 :   orig_code = code = gimple_assign_rhs_code (stmt);
    6756              : 
    6757              :   /* Shifts are handled in vectorizable_shift.  */
    6758       963320 :   if (code == LSHIFT_EXPR
    6759              :       || code == RSHIFT_EXPR
    6760              :       || code == LROTATE_EXPR
    6761       963320 :       || code == RROTATE_EXPR)
    6762              :    return false;
    6763              : 
    6764              :   /* Comparisons are handled in vectorizable_comparison.  */
    6765       906527 :   if (TREE_CODE_CLASS (code) == tcc_comparison)
    6766              :     return false;
    6767              : 
    6768              :   /* Conditions are handled in vectorizable_condition.  */
    6769       705165 :   if (code == COND_EXPR)
    6770              :     return false;
    6771              : 
    6772              :   /* For pointer addition and subtraction, we should use the normal
    6773              :      plus and minus for the vector operation.  */
    6774       677288 :   if (code == POINTER_PLUS_EXPR)
    6775              :     code = PLUS_EXPR;
    6776       656137 :   if (code == POINTER_DIFF_EXPR)
    6777         3129 :     code = MINUS_EXPR;
    6778              : 
    6779              :   /* Support only unary or binary operations.  */
    6780       677288 :   op_type = TREE_CODE_LENGTH (code);
    6781       677288 :   if (op_type != unary_op && op_type != binary_op && op_type != ternary_op)
    6782              :     {
    6783           15 :       if (dump_enabled_p ())
    6784            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6785              :                          "num. args = %d (not unary/binary/ternary op).\n",
    6786              :                          op_type);
    6787              :       return false;
    6788              :     }
    6789              : 
    6790       677273 :   scalar_dest = gimple_assign_lhs (stmt);
    6791       677273 :   vectype_out = SLP_TREE_VECTYPE (slp_node);
    6792              : 
    6793              :   /* Most operations cannot handle bit-precision types without extra
    6794              :      truncations.  */
    6795       677273 :   bool mask_op_p = VECTOR_BOOLEAN_TYPE_P (vectype_out);
    6796       665592 :   if (!mask_op_p
    6797       665592 :       && !type_has_mode_precision_p (TREE_TYPE (scalar_dest))
    6798              :       /* Exception are bitwise binary operations.  */
    6799              :       && code != BIT_IOR_EXPR
    6800         2288 :       && code != BIT_XOR_EXPR
    6801         1393 :       && code != BIT_AND_EXPR)
    6802              :     {
    6803          926 :       if (dump_enabled_p ())
    6804           54 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6805              :                          "bit-precision arithmetic not supported.\n");
    6806              :       return false;
    6807              :     }
    6808              : 
    6809       676347 :   slp_tree slp_op0;
    6810       676347 :   if (!vect_is_simple_use (vinfo, slp_node,
    6811              :                            0, &op0, &slp_op0, &dt[0], &vectype))
    6812              :     {
    6813            0 :       if (dump_enabled_p ())
    6814            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6815              :                          "use not simple.\n");
    6816              :       return false;
    6817              :     }
    6818       676347 :   bool is_invariant = (dt[0] == vect_external_def
    6819       676347 :                        || dt[0] == vect_constant_def);
    6820              :   /* If op0 is an external or constant def, infer the vector type
    6821              :      from the scalar type.  */
    6822       676347 :   if (!vectype)
    6823              :     {
    6824              :       /* For boolean type we cannot determine vectype by
    6825              :          invariant value (don't know whether it is a vector
    6826              :          of booleans or vector of integers).  We use output
    6827              :          vectype because operations on boolean don't change
    6828              :          type.  */
    6829        80540 :       if (VECT_SCALAR_BOOLEAN_TYPE_P (TREE_TYPE (op0)))
    6830              :         {
    6831         2292 :           if (!VECT_SCALAR_BOOLEAN_TYPE_P (TREE_TYPE (scalar_dest)))
    6832              :             {
    6833          330 :               if (dump_enabled_p ())
    6834            0 :                 dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6835              :                                  "not supported operation on bool value.\n");
    6836              :               return false;
    6837              :             }
    6838         1962 :           vectype = vectype_out;
    6839              :         }
    6840              :       else
    6841        78248 :         vectype = get_vectype_for_scalar_type (vinfo, TREE_TYPE (op0),
    6842              :                                                slp_node);
    6843              :     }
    6844       676017 :   if (!cost_vec)
    6845       122681 :     gcc_assert (vectype);
    6846       676017 :   if (!vectype)
    6847              :     {
    6848          318 :       if (dump_enabled_p ())
    6849            2 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6850              :                          "no vectype for scalar type %T\n",
    6851            2 :                          TREE_TYPE (op0));
    6852              : 
    6853              :       return false;
    6854              :     }
    6855              : 
    6856       675699 :   nunits_out = TYPE_VECTOR_SUBPARTS (vectype_out);
    6857       675699 :   nunits_in = TYPE_VECTOR_SUBPARTS (vectype);
    6858       675699 :   if (maybe_ne (nunits_out, nunits_in)
    6859       675699 :       || !tree_nop_conversion_p (TREE_TYPE (vectype_out), TREE_TYPE (vectype)))
    6860              :     return false;
    6861              : 
    6862       653571 :   tree vectype2 = NULL_TREE, vectype3 = NULL_TREE;
    6863       653571 :   slp_tree slp_op1 = NULL, slp_op2 = NULL;
    6864       653571 :   if (op_type == binary_op || op_type == ternary_op)
    6865              :     {
    6866       569280 :       if (!vect_is_simple_use (vinfo, slp_node,
    6867              :                                1, &op1, &slp_op1, &dt[1], &vectype2))
    6868              :         {
    6869            0 :           if (dump_enabled_p ())
    6870            0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6871              :                              "use not simple.\n");
    6872              :           return false;
    6873              :         }
    6874       569280 :       is_invariant &= (dt[1] == vect_external_def
    6875       569280 :                        || dt[1] == vect_constant_def);
    6876       569280 :       if (vectype2
    6877       917778 :           && (maybe_ne (nunits_out, TYPE_VECTOR_SUBPARTS (vectype2))
    6878       348498 :               || !tree_nop_conversion_p (TREE_TYPE (vectype_out),
    6879       348498 :                                          TREE_TYPE (vectype2))))
    6880              :         return false;
    6881              :     }
    6882       653571 :   if (op_type == ternary_op)
    6883              :     {
    6884            0 :       if (!vect_is_simple_use (vinfo, slp_node,
    6885              :                                2, &op2, &slp_op2, &dt[2], &vectype3))
    6886              :         {
    6887            0 :           if (dump_enabled_p ())
    6888            0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6889              :                              "use not simple.\n");
    6890              :           return false;
    6891              :         }
    6892            0 :       is_invariant &= (dt[2] == vect_external_def
    6893            0 :                        || dt[2] == vect_constant_def);
    6894            0 :       if (vectype3
    6895            0 :           && (maybe_ne (nunits_out, TYPE_VECTOR_SUBPARTS (vectype3))
    6896            0 :               || !tree_nop_conversion_p (TREE_TYPE (vectype_out),
    6897            0 :                                          TREE_TYPE (vectype3))))
    6898              :         return false;
    6899              :     }
    6900              : 
    6901              :   /* Multiple types in SLP are handled by creating the appropriate number of
    6902              :      vectorized stmts for each SLP node.  */
    6903       653571 :   auto vec_num = vect_get_num_copies (vinfo, slp_node);
    6904              : 
    6905              :   /* Reject attempts to combine mask types with nonmask types, e.g. if
    6906              :      we have an AND between a (nonmask) boolean loaded from memory and
    6907              :      a (mask) boolean result of a comparison.
    6908              : 
    6909              :      TODO: We could easily fix these cases up using pattern statements.  */
    6910       653571 :   if (VECTOR_BOOLEAN_TYPE_P (vectype) != mask_op_p
    6911       993770 :       || (vectype2 && VECTOR_BOOLEAN_TYPE_P (vectype2) != mask_op_p)
    6912      1307142 :       || (vectype3 && VECTOR_BOOLEAN_TYPE_P (vectype3) != mask_op_p))
    6913              :     {
    6914            0 :       if (dump_enabled_p ())
    6915            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6916              :                          "mixed mask and nonmask vector types\n");
    6917              :       return false;
    6918              :     }
    6919              : 
    6920              :   /* Supportable by target?  */
    6921              : 
    6922       653571 :   vec_mode = TYPE_MODE (vectype);
    6923       653571 :   optab = optab_for_tree_code (code, vectype, optab_default);
    6924       653571 :   if (!optab)
    6925              :     {
    6926        72669 :       if (dump_enabled_p ())
    6927         6283 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6928              :                          "no optab for %s and %T.\n",
    6929              :                          get_tree_code_name (code), vectype);
    6930              :       return false;
    6931              :     }
    6932       580902 :   target_support_p = can_implement_p (optab, vec_mode);
    6933              : 
    6934       580902 :   bool using_emulated_vectors_p = vect_emulated_vector_p (vectype);
    6935       580902 :   if (!target_support_p || using_emulated_vectors_p)
    6936              :     {
    6937        31331 :       if (dump_enabled_p ())
    6938         1320 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6939              :                          "op not supported by target.\n");
    6940              :       /* When vec_mode is not a vector mode and we verified ops we
    6941              :          do not have to lower like AND are natively supported let
    6942              :          those through even when the mode isn't word_mode.  For
    6943              :          ops we have to lower the lowering code assumes we are
    6944              :          dealing with word_mode.  */
    6945        62662 :       if (!INTEGRAL_TYPE_P (TREE_TYPE (vectype))
    6946        31181 :           || !GET_MODE_SIZE (vec_mode).is_constant ()
    6947        31181 :           || (((code == PLUS_EXPR || code == MINUS_EXPR || code == NEGATE_EXPR)
    6948        26008 :                || !target_support_p)
    6949        66857 :               && maybe_ne (GET_MODE_SIZE (vec_mode), UNITS_PER_WORD))
    6950              :           /* Check only during analysis.  */
    6951        43982 :           || (cost_vec && !vect_can_vectorize_without_simd_p (code)))
    6952              :         {
    6953        30729 :           if (dump_enabled_p ())
    6954         1318 :             dump_printf (MSG_NOTE, "using word mode not possible.\n");
    6955              :           return false;
    6956              :         }
    6957          602 :       if (dump_enabled_p ())
    6958            2 :         dump_printf_loc (MSG_NOTE, vect_location,
    6959              :                          "proceeding using word mode.\n");
    6960              :       using_emulated_vectors_p = true;
    6961              :     }
    6962              : 
    6963       550173 :   int reduc_idx = SLP_TREE_REDUC_IDX (slp_node);
    6964       550173 :   internal_fn cond_fn = get_conditional_internal_fn (code);
    6965       550173 :   internal_fn cond_len_fn = get_conditional_len_internal_fn (code);
    6966              : 
    6967              :   /* If operating on inactive elements could generate spurious traps,
    6968              :      we need to restrict the operation to active lanes.  Note that this
    6969              :      specifically doesn't apply to unhoisted invariants, since they
    6970              :      operate on the same value for every lane.
    6971              : 
    6972              :      Similarly, if this operation is part of a reduction, a fully-masked
    6973              :      loop should only change the active lanes of the reduction chain,
    6974              :      keeping the inactive lanes as-is.  */
    6975       522254 :   bool mask_out_inactive = ((!is_invariant && gimple_could_trap_p (stmt))
    6976      1002617 :                             || reduc_idx >= 0);
    6977              : 
    6978       550173 :   if (cost_vec) /* transformation not required.  */
    6979              :     {
    6980       427492 :       if (loop_vinfo
    6981       336442 :           && LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo)
    6982        96226 :           && mask_out_inactive)
    6983              :         {
    6984        20215 :           if (cond_len_fn != IFN_LAST
    6985        20215 :               && direct_internal_fn_supported_p (cond_len_fn, vectype,
    6986              :                                                  OPTIMIZE_FOR_SPEED))
    6987            0 :             vect_record_len (loop_vinfo, vec_num, vectype, 1);
    6988        20215 :           else if (cond_fn != IFN_LAST
    6989        20215 :                    && direct_internal_fn_supported_p (cond_fn, vectype,
    6990              :                                                       OPTIMIZE_FOR_SPEED))
    6991         8185 :             vect_record_mask (loop_vinfo, vec_num, vectype, NULL_TREE);
    6992              :           else
    6993              :             {
    6994        12030 :               if (dump_enabled_p ())
    6995          614 :                 dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    6996              :                                  "can't use a fully-masked loop because no"
    6997              :                                  " conditional operation is available.\n");
    6998        12030 :               LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo) = false;
    6999              :             }
    7000              :         }
    7001              : 
    7002              :       /* Put types on constant and invariant SLP children.  */
    7003       427492 :       if (!vect_maybe_update_slp_op_vectype (slp_op0, vectype)
    7004       427424 :           || !vect_maybe_update_slp_op_vectype (slp_op1, vectype)
    7005       854822 :           || !vect_maybe_update_slp_op_vectype (slp_op2, vectype))
    7006              :         {
    7007          162 :           if (dump_enabled_p ())
    7008            4 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    7009              :                              "incompatible vector types for invariants\n");
    7010              :           return false;
    7011              :         }
    7012              : 
    7013       427330 :       SLP_TREE_TYPE (slp_node) = op_vec_info_type;
    7014       427330 :       DUMP_VECT_SCOPE ("vectorizable_operation");
    7015       427330 :       vect_model_simple_cost (vinfo, 1, slp_node, cost_vec);
    7016       427330 :       if (using_emulated_vectors_p)
    7017              :         {
    7018              :           /* The above vect_model_simple_cost call handles constants
    7019              :              in the prologue and (mis-)costs one of the stmts as
    7020              :              vector stmt.  See below for the actual lowering that will
    7021              :              be applied.  */
    7022          600 :           unsigned n = vect_get_num_copies (vinfo, slp_node);
    7023          600 :           switch (code)
    7024              :             {
    7025          217 :             case PLUS_EXPR:
    7026          217 :               n *= 5;
    7027          217 :               break;
    7028          346 :             case MINUS_EXPR:
    7029          346 :               n *= 6;
    7030          346 :               break;
    7031            0 :             case NEGATE_EXPR:
    7032            0 :               n *= 4;
    7033            0 :               break;
    7034              :             default:
    7035              :               /* Bit operations do not have extra cost and are accounted
    7036              :                  as vector stmt by vect_model_simple_cost.  */
    7037              :               n = 0;
    7038              :               break;
    7039              :             }
    7040          563 :           if (n != 0)
    7041              :             {
    7042              :               /* We also need to materialize two large constants.  */
    7043          563 :               record_stmt_cost (cost_vec, 2, scalar_stmt, slp_node,
    7044              :                                 0, vect_prologue);
    7045          563 :               record_stmt_cost (cost_vec, n, scalar_stmt, slp_node,
    7046              :                                 0, vect_body);
    7047              :             }
    7048              :         }
    7049       427330 :       return true;
    7050              :     }
    7051              : 
    7052              :   /* Transform.  */
    7053              : 
    7054       122681 :   if (dump_enabled_p ())
    7055        17789 :     dump_printf_loc (MSG_NOTE, vect_location,
    7056              :                      "transform binary/unary operation.\n");
    7057              : 
    7058       122681 :   bool masked_loop_p = loop_vinfo && LOOP_VINFO_FULLY_MASKED_P (loop_vinfo);
    7059       109960 :   bool len_loop_p = loop_vinfo && LOOP_VINFO_FULLY_WITH_LENGTH_P (loop_vinfo);
    7060              : 
    7061              :   /* POINTER_DIFF_EXPR has pointer arguments which are vectorized as
    7062              :      vectors with unsigned elements, but the result is signed.  So, we
    7063              :      need to compute the MINUS_EXPR into vectype temporary and
    7064              :      VIEW_CONVERT_EXPR it into the final vectype_out result.  */
    7065       122681 :   tree vec_cvt_dest = NULL_TREE;
    7066       122681 :   if (orig_code == POINTER_DIFF_EXPR)
    7067              :     {
    7068           69 :       vec_dest = vect_create_destination_var (scalar_dest, vectype);
    7069           69 :       vec_cvt_dest = vect_create_destination_var (scalar_dest, vectype_out);
    7070              :     }
    7071              :   /* For reduction operations with undefined overflow behavior make sure to
    7072              :      pun them to unsigned since we change the order of evaluation.
    7073              :      ???  Avoid for in-order reductions?  */
    7074       122612 :   else if (arith_code_with_undefined_signed_overflow (orig_code)
    7075       103057 :            && ANY_INTEGRAL_TYPE_P (vectype)
    7076        51492 :            && TYPE_OVERFLOW_UNDEFINED (vectype)
    7077       150720 :            && SLP_TREE_REDUC_IDX (slp_node) != -1)
    7078              :     {
    7079         2540 :       gcc_assert (orig_code == PLUS_EXPR || orig_code == MINUS_EXPR
    7080              :                   || orig_code == MULT_EXPR || orig_code == POINTER_PLUS_EXPR);
    7081         2540 :       vec_cvt_dest = vect_create_destination_var (scalar_dest, vectype_out);
    7082         2540 :       vectype = unsigned_type_for (vectype);
    7083         2540 :       vec_dest = vect_create_destination_var (scalar_dest, vectype);
    7084              :     }
    7085              :   /* Handle def.  */
    7086              :   else
    7087       120072 :     vec_dest = vect_create_destination_var (scalar_dest, vectype_out);
    7088              : 
    7089       122681 :   vect_get_vec_defs (vinfo, slp_node, true, &vec_oprnds0,
    7090              :                      slp_op1, &vec_oprnds1, slp_op2, &vec_oprnds2);
    7091              :   /* Arguments are ready.  Create the new vector stmt.  */
    7092       392935 :   FOR_EACH_VEC_ELT (vec_oprnds0, i, vop0)
    7093              :     {
    7094       147573 :       gimple *new_stmt = NULL;
    7095       295146 :       vop1 = ((op_type == binary_op || op_type == ternary_op)
    7096       147573 :               ? vec_oprnds1[i] : NULL_TREE);
    7097       147573 :       vop2 = ((op_type == ternary_op) ? vec_oprnds2[i] : NULL_TREE);
    7098              : 
    7099       147573 :       if (vec_cvt_dest
    7100       147573 :           && !useless_type_conversion_p (vectype, TREE_TYPE (vop0)))
    7101              :         {
    7102         3013 :           new_temp = build1 (VIEW_CONVERT_EXPR, vectype, vop0);
    7103         3013 :           new_stmt = gimple_build_assign (vec_dest, VIEW_CONVERT_EXPR,
    7104              :                                           new_temp);
    7105         3013 :           new_temp = make_ssa_name (vec_dest, new_stmt);
    7106         3013 :           gimple_assign_set_lhs (new_stmt, new_temp);
    7107         3013 :           vect_finish_stmt_generation (vinfo, stmt_info,
    7108              :                                        new_stmt, gsi);
    7109         3013 :           vop0 = new_temp;
    7110              :         }
    7111       147573 :       if (vop1
    7112       144852 :           && vec_cvt_dest
    7113       150676 :           && !useless_type_conversion_p (vectype, TREE_TYPE (vop1)))
    7114              :         {
    7115         3013 :           new_temp = build1 (VIEW_CONVERT_EXPR, vectype, vop1);
    7116         3013 :           new_stmt = gimple_build_assign (vec_dest, VIEW_CONVERT_EXPR,
    7117              :                                           new_temp);
    7118         3013 :           new_temp = make_ssa_name (vec_dest, new_stmt);
    7119         3013 :           gimple_assign_set_lhs (new_stmt, new_temp);
    7120         3013 :           vect_finish_stmt_generation (vinfo, stmt_info,
    7121              :                                        new_stmt, gsi);
    7122         3013 :           vop1 = new_temp;
    7123              :         }
    7124       147573 :       if (vop2
    7125            0 :           && vec_cvt_dest
    7126       147573 :           && !useless_type_conversion_p (vectype, TREE_TYPE (vop2)))
    7127              :         {
    7128            0 :           new_temp = build1 (VIEW_CONVERT_EXPR, vectype, vop2);
    7129            0 :           new_stmt = gimple_build_assign (vec_dest, VIEW_CONVERT_EXPR,
    7130              :                                           new_temp);
    7131            0 :           new_temp = make_ssa_name (vec_dest, new_stmt);
    7132            0 :           gimple_assign_set_lhs (new_stmt, new_temp);
    7133            0 :           vect_finish_stmt_generation (vinfo, stmt_info,
    7134              :                                        new_stmt, gsi);
    7135            0 :           vop2 = new_temp;
    7136              :         }
    7137              : 
    7138       147573 :       if (using_emulated_vectors_p)
    7139              :         {
    7140              :           /* Lower the operation.  This follows vector lowering.  */
    7141            2 :           tree word_type = build_nonstandard_integer_type
    7142            2 :                              (GET_MODE_BITSIZE (vec_mode).to_constant (), 1);
    7143            2 :           tree wvop0 = make_ssa_name (word_type);
    7144            2 :           new_stmt = gimple_build_assign (wvop0, VIEW_CONVERT_EXPR,
    7145              :                                           build1 (VIEW_CONVERT_EXPR,
    7146              :                                                   word_type, vop0));
    7147            2 :           vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    7148            2 :           tree wvop1 = NULL_TREE;
    7149            2 :           if (vop1)
    7150              :             {
    7151            2 :               wvop1 = make_ssa_name (word_type);
    7152            2 :               new_stmt = gimple_build_assign (wvop1, VIEW_CONVERT_EXPR,
    7153              :                                               build1 (VIEW_CONVERT_EXPR,
    7154              :                                                       word_type, vop1));
    7155            2 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    7156              :             }
    7157              : 
    7158            2 :           tree result_low;
    7159            2 :           if (code == PLUS_EXPR || code == MINUS_EXPR || code == NEGATE_EXPR)
    7160              :             {
    7161            1 :               unsigned int width = vector_element_bits (vectype);
    7162            1 :               tree inner_type = TREE_TYPE (vectype);
    7163            1 :               HOST_WIDE_INT max = GET_MODE_MASK (TYPE_MODE (inner_type));
    7164            1 :               tree low_bits
    7165            1 :                 = build_replicated_int_cst (word_type, width, max >> 1);
    7166            1 :               tree high_bits
    7167            2 :                 = build_replicated_int_cst (word_type,
    7168            1 :                                             width, max & ~(max >> 1));
    7169            1 :               tree signs;
    7170            1 :               if (code == PLUS_EXPR || code == MINUS_EXPR)
    7171              :                 {
    7172            1 :                   signs = make_ssa_name (word_type);
    7173            1 :                   new_stmt = gimple_build_assign (signs,
    7174              :                                                   BIT_XOR_EXPR, wvop0, wvop1);
    7175            1 :                   vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    7176            1 :                   tree b_low = make_ssa_name (word_type);
    7177            1 :                   new_stmt = gimple_build_assign (b_low, BIT_AND_EXPR,
    7178              :                                                   wvop1, low_bits);
    7179            1 :                   vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    7180            1 :                   tree a_low = make_ssa_name (word_type);
    7181            1 :                   if (code == PLUS_EXPR)
    7182            1 :                     new_stmt = gimple_build_assign (a_low, BIT_AND_EXPR,
    7183              :                                                     wvop0, low_bits);
    7184              :                   else
    7185            0 :                     new_stmt = gimple_build_assign (a_low, BIT_IOR_EXPR,
    7186              :                                                     wvop0, high_bits);
    7187            1 :                   vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    7188            1 :                   if (code == MINUS_EXPR)
    7189              :                     {
    7190            0 :                       new_stmt = gimple_build_assign (NULL_TREE,
    7191              :                                                       BIT_NOT_EXPR, signs);
    7192            0 :                       signs = make_ssa_name (word_type);
    7193            0 :                       gimple_assign_set_lhs (new_stmt, signs);
    7194            0 :                       vect_finish_stmt_generation (vinfo, stmt_info,
    7195              :                                                    new_stmt, gsi);
    7196              :                     }
    7197            1 :                   new_stmt = gimple_build_assign (NULL_TREE, BIT_AND_EXPR,
    7198              :                                                   signs, high_bits);
    7199            1 :                   signs = make_ssa_name (word_type);
    7200            1 :                   gimple_assign_set_lhs (new_stmt, signs);
    7201            1 :                   vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    7202            1 :                   result_low = make_ssa_name (word_type);
    7203            1 :                   new_stmt = gimple_build_assign (result_low, code,
    7204              :                                                   a_low, b_low);
    7205            1 :                   vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    7206              :                 }
    7207              :               else /* if (code == NEGATE_EXPR) */
    7208              :                 {
    7209            0 :                   tree a_low = make_ssa_name (word_type);
    7210            0 :                   new_stmt = gimple_build_assign (a_low, BIT_AND_EXPR,
    7211              :                                                   wvop0, low_bits);
    7212            0 :                   vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    7213            0 :                   signs = make_ssa_name (word_type);
    7214            0 :                   new_stmt = gimple_build_assign (signs, BIT_NOT_EXPR, wvop0);
    7215            0 :                   vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    7216            0 :                   new_stmt = gimple_build_assign (NULL_TREE, BIT_AND_EXPR,
    7217              :                                                   signs, high_bits);
    7218            0 :                   signs = make_ssa_name (word_type);
    7219            0 :                   gimple_assign_set_lhs (new_stmt, signs);
    7220            0 :                   vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    7221            0 :                   result_low = make_ssa_name (word_type);
    7222            0 :                   new_stmt = gimple_build_assign (result_low,
    7223              :                                                   MINUS_EXPR, high_bits, a_low);
    7224            0 :                   vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    7225              :                 }
    7226            1 :               new_stmt = gimple_build_assign (NULL_TREE, BIT_XOR_EXPR,
    7227              :                                               result_low, signs);
    7228            1 :               result_low = make_ssa_name (word_type);
    7229            1 :               gimple_assign_set_lhs (new_stmt, result_low);
    7230            1 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    7231              :             }
    7232              :           else
    7233              :             {
    7234            1 :               new_stmt = gimple_build_assign (NULL_TREE, code, wvop0, wvop1);
    7235            1 :               result_low = make_ssa_name (word_type);
    7236            1 :               gimple_assign_set_lhs (new_stmt, result_low);
    7237            1 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    7238              : 
    7239              :             }
    7240            2 :           new_stmt = gimple_build_assign (NULL_TREE, VIEW_CONVERT_EXPR,
    7241              :                                           build1 (VIEW_CONVERT_EXPR,
    7242              :                                                   vectype, result_low));
    7243            2 :           new_temp = make_ssa_name (vectype);
    7244            2 :           gimple_assign_set_lhs (new_stmt, new_temp);
    7245            2 :           vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    7246              :         }
    7247       147571 :       else if ((masked_loop_p || len_loop_p) && mask_out_inactive)
    7248              :         {
    7249           16 :           tree mask;
    7250           16 :           if (masked_loop_p)
    7251           16 :             mask = vect_get_mask (loop_vinfo, gsi, vec_num, vectype, i);
    7252              :           else
    7253              :             /* Dummy mask.  */
    7254            0 :             mask = build_minus_one_cst (truth_type_for (vectype));
    7255           16 :           auto_vec<tree> vops (6);
    7256           16 :           vops.quick_push (mask);
    7257           16 :           vops.quick_push (vop0);
    7258           16 :           if (vop1)
    7259           16 :             vops.quick_push (vop1);
    7260           16 :           if (vop2)
    7261            0 :             vops.quick_push (vop2);
    7262           16 :           if (reduc_idx >= 0)
    7263              :             {
    7264              :               /* Perform the operation on active elements only and take
    7265              :                  inactive elements from the reduction chain input.  */
    7266            8 :               gcc_assert (!vop2);
    7267            8 :               vops.quick_push (reduc_idx == 1 ? vop1 : vop0);
    7268              :             }
    7269              :           else
    7270              :             {
    7271            8 :               auto else_value = targetm.preferred_else_value
    7272            8 :                 (cond_fn, vectype, vops.length () - 1, &vops[1]);
    7273            8 :               vops.quick_push (else_value);
    7274              :             }
    7275           16 :           if (len_loop_p)
    7276              :             {
    7277            0 :               tree len
    7278            0 :                 = vect_get_len (loop_vinfo, gsi, vec_num, vectype, i, 1, true);
    7279            0 :               signed char biasval
    7280            0 :                 = LOOP_VINFO_PARTIAL_LOAD_STORE_BIAS (loop_vinfo);
    7281            0 :               tree bias = build_int_cst (intQI_type_node, biasval);
    7282            0 :               vops.quick_push (len);
    7283            0 :               vops.quick_push (bias);
    7284              :             }
    7285           16 :           gcall *call
    7286           16 :             = gimple_build_call_internal_vec (masked_loop_p ? cond_fn
    7287              :                                                             : cond_len_fn,
    7288              :                                               vops);
    7289           16 :           new_temp = make_ssa_name (vec_dest, call);
    7290           16 :           gimple_call_set_lhs (call, new_temp);
    7291           16 :           gimple_call_set_nothrow (call, true);
    7292           16 :           vect_finish_stmt_generation (vinfo, stmt_info, call, gsi);
    7293           16 :           new_stmt = call;
    7294           16 :         }
    7295              :       else
    7296              :         {
    7297       147555 :           tree mask = NULL_TREE;
    7298              :           /* When combining two masks check if either of them is elsewhere
    7299              :              combined with a loop mask, if that's the case we can mark that the
    7300              :              new combined mask doesn't need to be combined with a loop mask.  */
    7301       147555 :           if (masked_loop_p
    7302       147555 :               && code == BIT_AND_EXPR
    7303       147555 :               && VECTOR_BOOLEAN_TYPE_P (vectype))
    7304              :             {
    7305            8 :               if (loop_vinfo->scalar_cond_masked_set.contains ({ op0, vec_num }))
    7306              :                 {
    7307            0 :                   mask = vect_get_mask (loop_vinfo, gsi, vec_num, vectype, i);
    7308              : 
    7309            0 :                   vop0 = prepare_vec_mask (loop_vinfo, TREE_TYPE (mask), mask,
    7310              :                                            vop0, gsi);
    7311              :                 }
    7312              : 
    7313            8 :               if (loop_vinfo->scalar_cond_masked_set.contains ({ op1, vec_num }))
    7314              :                 {
    7315            0 :                   mask = vect_get_mask (loop_vinfo, gsi, vec_num, vectype, i);
    7316              : 
    7317            0 :                   vop1 = prepare_vec_mask (loop_vinfo, TREE_TYPE (mask), mask,
    7318              :                                            vop1, gsi);
    7319              :                 }
    7320              :             }
    7321              : 
    7322       147555 :           new_stmt = gimple_build_assign (vec_dest, code, vop0, vop1, vop2);
    7323       147555 :           new_temp = make_ssa_name (vec_dest, new_stmt);
    7324       147555 :           gimple_assign_set_lhs (new_stmt, new_temp);
    7325       147555 :           vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    7326       147555 :           if (using_emulated_vectors_p)
    7327              :             suppress_warning (new_stmt, OPT_Wvector_operation_performance);
    7328              : 
    7329              :           /* Enter the combined value into the vector cond hash so we don't
    7330              :              AND it with a loop mask again.  */
    7331       147555 :           if (mask)
    7332            0 :             loop_vinfo->vec_cond_masked_set.add ({ new_temp, mask });
    7333              :         }
    7334              : 
    7335       147573 :       if (vec_cvt_dest)
    7336              :         {
    7337         3103 :           new_temp = build1 (VIEW_CONVERT_EXPR, vectype_out, new_temp);
    7338         3103 :           new_stmt = gimple_build_assign (vec_cvt_dest, VIEW_CONVERT_EXPR,
    7339              :                                           new_temp);
    7340         3103 :           new_temp = make_ssa_name (vec_cvt_dest, new_stmt);
    7341         3103 :           gimple_assign_set_lhs (new_stmt, new_temp);
    7342         3103 :           vect_finish_stmt_generation (vinfo, stmt_info,
    7343              :                                        new_stmt, gsi);
    7344              :         }
    7345              : 
    7346       147573 :       slp_node->push_vec_def (new_stmt);
    7347              :     }
    7348              : 
    7349       122681 :   vec_oprnds0.release ();
    7350       122681 :   vec_oprnds1.release ();
    7351       122681 :   vec_oprnds2.release ();
    7352              : 
    7353       122681 :   return true;
    7354              : }
    7355              : 
    7356              : /* A helper function to ensure data reference DR_INFO's base alignment.  */
    7357              : 
    7358              : static void
    7359       715121 : ensure_base_align (dr_vec_info *dr_info)
    7360              : {
    7361              :   /* Alignment is only analyzed for the first element of a DR group,
    7362              :      use that to look at base alignment we need to enforce.  */
    7363       715121 :   if (STMT_VINFO_GROUPED_ACCESS (dr_info->stmt))
    7364       587646 :     dr_info = STMT_VINFO_DR_INFO (DR_GROUP_FIRST_ELEMENT (dr_info->stmt));
    7365              : 
    7366       715121 :   gcc_assert (dr_info->misalignment != DR_MISALIGNMENT_UNINITIALIZED);
    7367              : 
    7368       715121 :   if (dr_info->base_misaligned)
    7369              :     {
    7370       114102 :       tree base_decl = dr_info->base_decl;
    7371              : 
    7372              :       // We should only be able to increase the alignment of a base object if
    7373              :       // we know what its new alignment should be at compile time.
    7374       114102 :       unsigned HOST_WIDE_INT align_base_to =
    7375       114102 :         DR_TARGET_ALIGNMENT (dr_info).to_constant () * BITS_PER_UNIT;
    7376              : 
    7377       114102 :       if (decl_in_symtab_p (base_decl))
    7378         3268 :         symtab_node::get (base_decl)->increase_alignment (align_base_to);
    7379       110834 :       else if (DECL_ALIGN (base_decl) < align_base_to)
    7380              :         {
    7381        92384 :           SET_DECL_ALIGN (base_decl, align_base_to);
    7382        92384 :           DECL_USER_ALIGN (base_decl) = 1;
    7383              :         }
    7384       114102 :       dr_info->base_misaligned = false;
    7385              :     }
    7386       715121 : }
    7387              : 
    7388              : 
    7389              : /* Function get_group_alias_ptr_type.
    7390              : 
    7391              :    Return the alias type for the group starting at FIRST_STMT_INFO.  */
    7392              : 
    7393              : static tree
    7394      1664397 : get_group_alias_ptr_type (stmt_vec_info first_stmt_info)
    7395              : {
    7396      1664397 :   struct data_reference *first_dr, *next_dr;
    7397              : 
    7398      1664397 :   first_dr = STMT_VINFO_DATA_REF (first_stmt_info);
    7399      1664397 :   stmt_vec_info next_stmt_info = DR_GROUP_NEXT_ELEMENT (first_stmt_info);
    7400      3940554 :   while (next_stmt_info)
    7401              :     {
    7402      2463859 :       next_dr = STMT_VINFO_DATA_REF (next_stmt_info);
    7403      4927718 :       if (get_alias_set (DR_REF (first_dr))
    7404      2463859 :           != get_alias_set (DR_REF (next_dr)))
    7405              :         {
    7406       187702 :           if (dump_enabled_p ())
    7407           30 :             dump_printf_loc (MSG_NOTE, vect_location,
    7408              :                              "conflicting alias set types.\n");
    7409       187702 :           return ptr_type_node;
    7410              :         }
    7411      2276157 :       next_stmt_info = DR_GROUP_NEXT_ELEMENT (next_stmt_info);
    7412              :     }
    7413      1476695 :   return reference_alias_ptr_type (DR_REF (first_dr));
    7414              : }
    7415              : 
    7416              : 
    7417              : /* Function scan_operand_equal_p.
    7418              : 
    7419              :    Helper function for check_scan_store.  Compare two references
    7420              :    with .GOMP_SIMD_LANE bases.  */
    7421              : 
    7422              : static bool
    7423         1296 : scan_operand_equal_p (tree ref1, tree ref2)
    7424              : {
    7425         1296 :   tree ref[2] = { ref1, ref2 };
    7426         1296 :   poly_int64 bitsize[2], bitpos[2];
    7427              :   tree offset[2], base[2];
    7428         3888 :   for (int i = 0; i < 2; ++i)
    7429              :     {
    7430         2592 :       machine_mode mode;
    7431         2592 :       int unsignedp, reversep, volatilep = 0;
    7432         2592 :       base[i] = get_inner_reference (ref[i], &bitsize[i], &bitpos[i],
    7433              :                                      &offset[i], &mode, &unsignedp,
    7434              :                                      &reversep, &volatilep);
    7435         2592 :       if (reversep || volatilep || maybe_ne (bitpos[i], 0))
    7436            0 :         return false;
    7437         2592 :       if (TREE_CODE (base[i]) == MEM_REF
    7438           42 :           && offset[i] == NULL_TREE
    7439         2634 :           && TREE_CODE (TREE_OPERAND (base[i], 0)) == SSA_NAME)
    7440              :         {
    7441           42 :           auto *def_stmt
    7442         2634 :             = dyn_cast<gassign *> (SSA_NAME_DEF_STMT
    7443              :                                    (TREE_OPERAND (base[i], 0)));
    7444           42 :           if (def_stmt
    7445           42 :               && gimple_assign_rhs_code (def_stmt) == POINTER_PLUS_EXPR
    7446           42 :               && TREE_CODE (gimple_assign_rhs1 (def_stmt)) == ADDR_EXPR
    7447           42 :               && TREE_CODE (gimple_assign_rhs2 (def_stmt)) == SSA_NAME)
    7448              :             {
    7449           42 :               if (maybe_ne (mem_ref_offset (base[i]), 0))
    7450              :                 return false;
    7451           42 :               base[i] = TREE_OPERAND (gimple_assign_rhs1 (def_stmt), 0);
    7452           84 :               offset[i] = gimple_assign_rhs2 (def_stmt);
    7453              :             }
    7454              :         }
    7455              :     }
    7456              : 
    7457         1296 :   if (!operand_equal_p (base[0], base[1], 0))
    7458              :     return false;
    7459          944 :   if (maybe_ne (bitsize[0], bitsize[1]))
    7460              :     return false;
    7461          944 :   if (offset[0] != offset[1])
    7462              :     {
    7463          926 :       if (!offset[0] || !offset[1])
    7464              :         return false;
    7465          926 :       if (!operand_equal_p (offset[0], offset[1], 0))
    7466              :         {
    7467              :           tree step[2];
    7468            0 :           for (int i = 0; i < 2; ++i)
    7469              :             {
    7470            0 :               step[i] = integer_one_node;
    7471            0 :               if (TREE_CODE (offset[i]) == SSA_NAME)
    7472              :                 {
    7473            0 :                   auto *def_stmt
    7474            0 :                     = dyn_cast<gassign *> (SSA_NAME_DEF_STMT (offset[i]));
    7475            0 :                   if (def_stmt
    7476            0 :                       && gimple_assign_rhs_code (def_stmt) == MULT_EXPR
    7477            0 :                       && (TREE_CODE (gimple_assign_rhs2 (def_stmt))
    7478              :                           == INTEGER_CST))
    7479              :                     {
    7480            0 :                       step[i] = gimple_assign_rhs2 (def_stmt);
    7481            0 :                       offset[i] = gimple_assign_rhs1 (def_stmt);
    7482              :                     }
    7483              :                 }
    7484            0 :               else if (TREE_CODE (offset[i]) == MULT_EXPR)
    7485              :                 {
    7486            0 :                   step[i] = TREE_OPERAND (offset[i], 1);
    7487            0 :                   offset[i] = TREE_OPERAND (offset[i], 0);
    7488              :                 }
    7489            0 :               tree rhs1 = NULL_TREE;
    7490            0 :               if (TREE_CODE (offset[i]) == SSA_NAME)
    7491              :                 {
    7492            0 :                   auto *def_stmt
    7493            0 :                     = dyn_cast<gassign *> (SSA_NAME_DEF_STMT (offset[i]));
    7494            0 :                   if (def_stmt && gimple_assign_cast_p (def_stmt))
    7495            0 :                     rhs1 = gimple_assign_rhs1 (def_stmt);
    7496              :                 }
    7497            0 :               else if (CONVERT_EXPR_P (offset[i]))
    7498            0 :                 rhs1 = TREE_OPERAND (offset[i], 0);
    7499            0 :               if (rhs1
    7500            0 :                   && INTEGRAL_TYPE_P (TREE_TYPE (rhs1))
    7501            0 :                   && INTEGRAL_TYPE_P (TREE_TYPE (offset[i]))
    7502            0 :                   && (TYPE_PRECISION (TREE_TYPE (offset[i]))
    7503            0 :                       >= TYPE_PRECISION (TREE_TYPE (rhs1))))
    7504            0 :                 offset[i] = rhs1;
    7505              :             }
    7506            0 :           if (!operand_equal_p (offset[0], offset[1], 0)
    7507            0 :               || !operand_equal_p (step[0], step[1], 0))
    7508            0 :             return false;
    7509              :         }
    7510              :     }
    7511              :   return true;
    7512              : }
    7513              : 
    7514              : 
    7515              : enum scan_store_kind {
    7516              :   /* Normal permutation.  */
    7517              :   scan_store_kind_perm,
    7518              : 
    7519              :   /* Whole vector left shift permutation with zero init.  */
    7520              :   scan_store_kind_lshift_zero,
    7521              : 
    7522              :   /* Whole vector left shift permutation and VEC_COND_EXPR.  */
    7523              :   scan_store_kind_lshift_cond
    7524              : };
    7525              : 
    7526              : /* Function check_scan_store.
    7527              : 
    7528              :    Verify if we can perform the needed permutations or whole vector shifts.
    7529              :    Return -1 on failure, otherwise exact log2 of vectype's nunits.
    7530              :    USE_WHOLE_VECTOR is a vector of enum scan_store_kind which operation
    7531              :    to do at each step.  */
    7532              : 
    7533              : static int
    7534         1032 : scan_store_can_perm_p (tree vectype, tree init,
    7535              :                        vec<enum scan_store_kind> *use_whole_vector = NULL)
    7536              : {
    7537         1032 :   enum machine_mode vec_mode = TYPE_MODE (vectype);
    7538         1032 :   unsigned HOST_WIDE_INT nunits;
    7539         1032 :   if (!TYPE_VECTOR_SUBPARTS (vectype).is_constant (&nunits))
    7540              :     return -1;
    7541         1032 :   int units_log2 = exact_log2 (nunits);
    7542         1032 :   if (units_log2 <= 0)
    7543              :     return -1;
    7544              : 
    7545              :   int i;
    7546              :   enum scan_store_kind whole_vector_shift_kind = scan_store_kind_perm;
    7547         4816 :   for (i = 0; i <= units_log2; ++i)
    7548              :     {
    7549         3784 :       unsigned HOST_WIDE_INT j, k;
    7550         3784 :       enum scan_store_kind kind = scan_store_kind_perm;
    7551         3784 :       vec_perm_builder sel (nunits, nunits, 1);
    7552         3784 :       sel.quick_grow (nunits);
    7553         3784 :       if (i == units_log2)
    7554              :         {
    7555         9768 :           for (j = 0; j < nunits; ++j)
    7556         8736 :             sel[j] = nunits - 1;
    7557              :         }
    7558              :       else
    7559              :         {
    7560        10456 :           for (j = 0; j < (HOST_WIDE_INT_1U << i); ++j)
    7561         7704 :             sel[j] = j;
    7562        26472 :           for (k = 0; j < nunits; ++j, ++k)
    7563        23720 :             sel[j] = nunits + k;
    7564              :         }
    7565         6536 :       vec_perm_indices indices (sel, i == units_log2 ? 1 : 2, nunits);
    7566         3784 :       if (!can_vec_perm_const_p (vec_mode, vec_mode, indices))
    7567              :         {
    7568            0 :           if (i == units_log2)
    7569              :             return -1;
    7570              : 
    7571            0 :           if (whole_vector_shift_kind == scan_store_kind_perm)
    7572              :             {
    7573            0 :               if (!can_implement_p (vec_shl_optab, vec_mode))
    7574              :                 return -1;
    7575            0 :               whole_vector_shift_kind = scan_store_kind_lshift_zero;
    7576              :               /* Whole vector shifts shift in zeros, so if init is all zero
    7577              :                  constant, there is no need to do anything further.  */
    7578            0 :               if ((TREE_CODE (init) != INTEGER_CST
    7579            0 :                    && TREE_CODE (init) != REAL_CST)
    7580            0 :                   || !initializer_zerop (init))
    7581              :                 {
    7582            0 :                   tree masktype = truth_type_for (vectype);
    7583            0 :                   if (!expand_vec_cond_expr_p (vectype, masktype))
    7584              :                     return -1;
    7585              :                   whole_vector_shift_kind = scan_store_kind_lshift_cond;
    7586              :                 }
    7587              :             }
    7588            0 :           kind = whole_vector_shift_kind;
    7589              :         }
    7590         3784 :       if (use_whole_vector)
    7591              :         {
    7592         1892 :           if (kind != scan_store_kind_perm && use_whole_vector->is_empty ())
    7593            0 :             use_whole_vector->safe_grow_cleared (i, true);
    7594         5676 :           if (kind != scan_store_kind_perm || !use_whole_vector->is_empty ())
    7595            0 :             use_whole_vector->safe_push (kind);
    7596              :         }
    7597         3784 :     }
    7598              : 
    7599              :   return units_log2;
    7600              : }
    7601              : 
    7602              : 
    7603              : /* Function check_scan_store.
    7604              : 
    7605              :    Check magic stores for #pragma omp scan {in,ex}clusive reductions.  */
    7606              : 
    7607              : static bool
    7608         1082 : check_scan_store (vec_info *vinfo, stmt_vec_info stmt_info, tree vectype,
    7609              :                   enum vect_def_type rhs_dt, slp_tree slp_node,
    7610              :                   slp_tree mask_node,
    7611              :                   vect_memory_access_type memory_access_type)
    7612              : {
    7613         1082 :   loop_vec_info loop_vinfo = dyn_cast <loop_vec_info> (vinfo);
    7614         1082 :   dr_vec_info *dr_info = STMT_VINFO_DR_INFO (stmt_info);
    7615         1082 :   tree ref_type;
    7616              : 
    7617         1082 :   gcc_assert (STMT_VINFO_SIMD_LANE_ACCESS_P (stmt_info) > 1);
    7618         1082 :   if (SLP_TREE_LANES (slp_node) > 1
    7619         1082 :       || mask_node
    7620         1082 :       || memory_access_type != VMAT_CONTIGUOUS
    7621         1082 :       || TREE_CODE (DR_BASE_ADDRESS (dr_info->dr)) != ADDR_EXPR
    7622         1082 :       || !VAR_P (TREE_OPERAND (DR_BASE_ADDRESS (dr_info->dr), 0))
    7623         1082 :       || loop_vinfo == NULL
    7624         1082 :       || LOOP_VINFO_FULLY_MASKED_P (loop_vinfo)
    7625         1082 :       || LOOP_VINFO_EPILOGUE_P (loop_vinfo)
    7626         1082 :       || STMT_VINFO_GROUPED_ACCESS (stmt_info)
    7627         1082 :       || !integer_zerop (get_dr_vinfo_offset (vinfo, dr_info))
    7628         1082 :       || !integer_zerop (DR_INIT (dr_info->dr))
    7629         1082 :       || !(ref_type = reference_alias_ptr_type (DR_REF (dr_info->dr)))
    7630         2164 :       || !alias_sets_conflict_p (get_alias_set (vectype),
    7631         1082 :                                  get_alias_set (TREE_TYPE (ref_type))))
    7632              :     {
    7633            0 :       if (dump_enabled_p ())
    7634            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    7635              :                          "unsupported OpenMP scan store.\n");
    7636              :       return false;
    7637              :     }
    7638              : 
    7639              :   /* We need to pattern match code built by OpenMP lowering and simplified
    7640              :      by following optimizations into something we can handle.
    7641              :      #pragma omp simd reduction(inscan,+:r)
    7642              :      for (...)
    7643              :        {
    7644              :          r += something ();
    7645              :          #pragma omp scan inclusive (r)
    7646              :          use (r);
    7647              :        }
    7648              :      shall have body with:
    7649              :        // Initialization for input phase, store the reduction initializer:
    7650              :        _20 = .GOMP_SIMD_LANE (simduid.3_14(D), 0);
    7651              :        _21 = .GOMP_SIMD_LANE (simduid.3_14(D), 1);
    7652              :        D.2042[_21] = 0;
    7653              :        // Actual input phase:
    7654              :        ...
    7655              :        r.0_5 = D.2042[_20];
    7656              :        _6 = _4 + r.0_5;
    7657              :        D.2042[_20] = _6;
    7658              :        // Initialization for scan phase:
    7659              :        _25 = .GOMP_SIMD_LANE (simduid.3_14(D), 2);
    7660              :        _26 = D.2043[_25];
    7661              :        _27 = D.2042[_25];
    7662              :        _28 = _26 + _27;
    7663              :        D.2043[_25] = _28;
    7664              :        D.2042[_25] = _28;
    7665              :        // Actual scan phase:
    7666              :        ...
    7667              :        r.1_8 = D.2042[_20];
    7668              :        ...
    7669              :      The "omp simd array" variable D.2042 holds the privatized copy used
    7670              :      inside of the loop and D.2043 is another one that holds copies of
    7671              :      the current original list item.  The separate GOMP_SIMD_LANE ifn
    7672              :      kinds are there in order to allow optimizing the initializer store
    7673              :      and combiner sequence, e.g. if it is originally some C++ish user
    7674              :      defined reduction, but allow the vectorizer to pattern recognize it
    7675              :      and turn into the appropriate vectorized scan.
    7676              : 
    7677              :      For exclusive scan, this is slightly different:
    7678              :      #pragma omp simd reduction(inscan,+:r)
    7679              :      for (...)
    7680              :        {
    7681              :          use (r);
    7682              :          #pragma omp scan exclusive (r)
    7683              :          r += something ();
    7684              :        }
    7685              :      shall have body with:
    7686              :        // Initialization for input phase, store the reduction initializer:
    7687              :        _20 = .GOMP_SIMD_LANE (simduid.3_14(D), 0);
    7688              :        _21 = .GOMP_SIMD_LANE (simduid.3_14(D), 1);
    7689              :        D.2042[_21] = 0;
    7690              :        // Actual input phase:
    7691              :        ...
    7692              :        r.0_5 = D.2042[_20];
    7693              :        _6 = _4 + r.0_5;
    7694              :        D.2042[_20] = _6;
    7695              :        // Initialization for scan phase:
    7696              :        _25 = .GOMP_SIMD_LANE (simduid.3_14(D), 3);
    7697              :        _26 = D.2043[_25];
    7698              :        D.2044[_25] = _26;
    7699              :        _27 = D.2042[_25];
    7700              :        _28 = _26 + _27;
    7701              :        D.2043[_25] = _28;
    7702              :        // Actual scan phase:
    7703              :        ...
    7704              :        r.1_8 = D.2044[_20];
    7705              :        ...  */
    7706              : 
    7707         1082 :   if (STMT_VINFO_SIMD_LANE_ACCESS_P (stmt_info) == 2)
    7708              :     {
    7709              :       /* Match the D.2042[_21] = 0; store above.  Just require that
    7710              :          it is a constant or external definition store.  */
    7711          566 :       if (rhs_dt != vect_constant_def && rhs_dt != vect_external_def)
    7712              :         {
    7713            0 :          fail_init:
    7714            0 :           if (dump_enabled_p ())
    7715            0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    7716              :                              "unsupported OpenMP scan initializer store.\n");
    7717              :           return false;
    7718              :         }
    7719              : 
    7720          566 :       if (! loop_vinfo->scan_map)
    7721          324 :         loop_vinfo->scan_map = new hash_map<tree, tree>;
    7722          566 :       tree var = TREE_OPERAND (DR_BASE_ADDRESS (dr_info->dr), 0);
    7723          566 :       tree &cached = loop_vinfo->scan_map->get_or_insert (var);
    7724          566 :       if (cached)
    7725            0 :         goto fail_init;
    7726          566 :       cached = gimple_assign_rhs1 (STMT_VINFO_STMT (stmt_info));
    7727              : 
    7728              :       /* These stores can be vectorized normally.  */
    7729          566 :       return true;
    7730              :     }
    7731              : 
    7732          516 :   if (rhs_dt != vect_internal_def)
    7733              :     {
    7734            0 :      fail:
    7735            0 :       if (dump_enabled_p ())
    7736            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    7737              :                          "unsupported OpenMP scan combiner pattern.\n");
    7738              :       return false;
    7739              :     }
    7740              : 
    7741          516 :   gimple *stmt = STMT_VINFO_STMT (stmt_info);
    7742          516 :   tree rhs = gimple_assign_rhs1 (stmt);
    7743          516 :   if (TREE_CODE (rhs) != SSA_NAME)
    7744            0 :     goto fail;
    7745              : 
    7746          516 :   gimple *other_store_stmt = NULL;
    7747          516 :   tree var = TREE_OPERAND (DR_BASE_ADDRESS (dr_info->dr), 0);
    7748          516 :   bool inscan_var_store
    7749          516 :     = lookup_attribute ("omp simd inscan", DECL_ATTRIBUTES (var)) != NULL;
    7750              : 
    7751          516 :   if (STMT_VINFO_SIMD_LANE_ACCESS_P (stmt_info) == 4)
    7752              :     {
    7753          252 :       if (!inscan_var_store)
    7754              :         {
    7755          126 :           use_operand_p use_p;
    7756          126 :           imm_use_iterator iter;
    7757          378 :           FOR_EACH_IMM_USE_FAST (use_p, iter, rhs)
    7758              :             {
    7759          252 :               gimple *use_stmt = USE_STMT (use_p);
    7760          252 :               if (use_stmt == stmt || is_gimple_debug (use_stmt))
    7761          126 :                 continue;
    7762          126 :               if (gimple_bb (use_stmt) != gimple_bb (stmt)
    7763          126 :                   || !is_gimple_assign (use_stmt)
    7764          126 :                   || gimple_assign_rhs_class (use_stmt) != GIMPLE_BINARY_RHS
    7765          126 :                   || other_store_stmt
    7766          252 :                   || TREE_CODE (gimple_assign_lhs (use_stmt)) != SSA_NAME)
    7767            0 :                 goto fail;
    7768          126 :               other_store_stmt = use_stmt;
    7769            0 :             }
    7770          126 :           if (other_store_stmt == NULL)
    7771            0 :             goto fail;
    7772          126 :           rhs = gimple_assign_lhs (other_store_stmt);
    7773          126 :           if (!single_imm_use (rhs, &use_p, &other_store_stmt))
    7774            0 :             goto fail;
    7775              :         }
    7776              :     }
    7777          264 :   else if (STMT_VINFO_SIMD_LANE_ACCESS_P (stmt_info) == 3)
    7778              :     {
    7779          264 :       use_operand_p use_p;
    7780          264 :       imm_use_iterator iter;
    7781          792 :       FOR_EACH_IMM_USE_FAST (use_p, iter, rhs)
    7782              :         {
    7783          528 :           gimple *use_stmt = USE_STMT (use_p);
    7784          528 :           if (use_stmt == stmt || is_gimple_debug (use_stmt))
    7785          264 :             continue;
    7786          264 :           if (other_store_stmt)
    7787            0 :             goto fail;
    7788          264 :           other_store_stmt = use_stmt;
    7789          264 :         }
    7790              :     }
    7791              :   else
    7792            0 :     goto fail;
    7793              : 
    7794          516 :   auto *def_stmt = dyn_cast<gassign *> (SSA_NAME_DEF_STMT (rhs));
    7795          516 :   if (!def_stmt
    7796          516 :                   || gimple_bb (def_stmt) != gimple_bb (stmt)
    7797          516 :       || gimple_assign_rhs_class (def_stmt) != GIMPLE_BINARY_RHS)
    7798            0 :     goto fail;
    7799              : 
    7800          516 :   enum tree_code code = gimple_assign_rhs_code (def_stmt);
    7801              :   /* For pointer addition, we should use the normal plus for the vector
    7802              :      operation.  */
    7803          516 :   switch (code)
    7804              :     {
    7805            0 :     case POINTER_PLUS_EXPR:
    7806            0 :       code = PLUS_EXPR;
    7807            0 :       break;
    7808            0 :     case MULT_HIGHPART_EXPR:
    7809            0 :       goto fail;
    7810              :     default:
    7811              :       break;
    7812              :     }
    7813          516 :   if (TREE_CODE_LENGTH (code) != binary_op || !commutative_tree_code (code))
    7814            0 :     goto fail;
    7815              : 
    7816          516 :   tree rhs1 = gimple_assign_rhs1 (def_stmt);
    7817          516 :   tree rhs2 = gimple_assign_rhs2 (def_stmt);
    7818          516 :   if (TREE_CODE (rhs1) != SSA_NAME || TREE_CODE (rhs2) != SSA_NAME)
    7819            0 :     goto fail;
    7820              : 
    7821          516 :   gimple *load1_stmt = SSA_NAME_DEF_STMT (rhs1);
    7822          516 :   gimple *load2_stmt = SSA_NAME_DEF_STMT (rhs2);
    7823          516 :   if (gimple_bb (load1_stmt) != gimple_bb (stmt)
    7824          516 :       || !gimple_assign_load_p (load1_stmt)
    7825          516 :       || gimple_bb (load2_stmt) != gimple_bb (stmt)
    7826         1032 :       || !gimple_assign_load_p (load2_stmt))
    7827            0 :     goto fail;
    7828              : 
    7829          516 :   stmt_vec_info load1_stmt_info = loop_vinfo->lookup_stmt (load1_stmt);
    7830          516 :   stmt_vec_info load2_stmt_info = loop_vinfo->lookup_stmt (load2_stmt);
    7831          516 :   if (load1_stmt_info == NULL
    7832          516 :       || load2_stmt_info == NULL
    7833          516 :       || (STMT_VINFO_SIMD_LANE_ACCESS_P (load1_stmt_info)
    7834          516 :           != STMT_VINFO_SIMD_LANE_ACCESS_P (stmt_info))
    7835          516 :       || (STMT_VINFO_SIMD_LANE_ACCESS_P (load2_stmt_info)
    7836          516 :           != STMT_VINFO_SIMD_LANE_ACCESS_P (stmt_info)))
    7837            0 :     goto fail;
    7838              : 
    7839          516 :   if (STMT_VINFO_SIMD_LANE_ACCESS_P (stmt_info) == 4 && inscan_var_store)
    7840              :     {
    7841          126 :       dr_vec_info *load1_dr_info = STMT_VINFO_DR_INFO (load1_stmt_info);
    7842          126 :       if (TREE_CODE (DR_BASE_ADDRESS (load1_dr_info->dr)) != ADDR_EXPR
    7843          126 :           || !VAR_P (TREE_OPERAND (DR_BASE_ADDRESS (load1_dr_info->dr), 0)))
    7844            0 :         goto fail;
    7845          126 :       tree var1 = TREE_OPERAND (DR_BASE_ADDRESS (load1_dr_info->dr), 0);
    7846          126 :       tree lrhs;
    7847          126 :       if (lookup_attribute ("omp simd inscan", DECL_ATTRIBUTES (var1)))
    7848              :         lrhs = rhs1;
    7849              :       else
    7850           16 :         lrhs = rhs2;
    7851          126 :       use_operand_p use_p;
    7852          126 :       imm_use_iterator iter;
    7853          378 :       FOR_EACH_IMM_USE_FAST (use_p, iter, lrhs)
    7854              :         {
    7855          252 :           gimple *use_stmt = USE_STMT (use_p);
    7856          252 :           if (use_stmt == def_stmt || is_gimple_debug (use_stmt))
    7857          126 :             continue;
    7858          126 :           if (other_store_stmt)
    7859            0 :             goto fail;
    7860          126 :           other_store_stmt = use_stmt;
    7861          126 :         }
    7862              :     }
    7863              : 
    7864          516 :   if (other_store_stmt == NULL)
    7865            0 :     goto fail;
    7866          516 :   if (gimple_bb (other_store_stmt) != gimple_bb (stmt)
    7867          516 :       || !gimple_store_p (other_store_stmt))
    7868            0 :     goto fail;
    7869              : 
    7870          516 :   stmt_vec_info other_store_stmt_info
    7871          516 :     = loop_vinfo->lookup_stmt (other_store_stmt);
    7872          516 :   if (other_store_stmt_info == NULL
    7873          516 :       || (STMT_VINFO_SIMD_LANE_ACCESS_P (other_store_stmt_info)
    7874          516 :           != STMT_VINFO_SIMD_LANE_ACCESS_P (stmt_info)))
    7875            0 :     goto fail;
    7876              : 
    7877          516 :   gimple *stmt1 = stmt;
    7878          516 :   gimple *stmt2 = other_store_stmt;
    7879          516 :   if (STMT_VINFO_SIMD_LANE_ACCESS_P (stmt_info) == 4 && !inscan_var_store)
    7880              :     std::swap (stmt1, stmt2);
    7881          516 :   if (scan_operand_equal_p (gimple_assign_lhs (stmt1),
    7882              :                             gimple_assign_rhs1 (load2_stmt)))
    7883              :     {
    7884          164 :       std::swap (rhs1, rhs2);
    7885          164 :       std::swap (load1_stmt, load2_stmt);
    7886          164 :       std::swap (load1_stmt_info, load2_stmt_info);
    7887              :     }
    7888          516 :   if (!scan_operand_equal_p (gimple_assign_lhs (stmt1),
    7889              :                              gimple_assign_rhs1 (load1_stmt)))
    7890            0 :     goto fail;
    7891              : 
    7892          516 :   tree var3 = NULL_TREE;
    7893          516 :   if (STMT_VINFO_SIMD_LANE_ACCESS_P (stmt_info) == 3
    7894          516 :       && !scan_operand_equal_p (gimple_assign_lhs (stmt2),
    7895              :                                 gimple_assign_rhs1 (load2_stmt)))
    7896            0 :     goto fail;
    7897          516 :   else if (STMT_VINFO_SIMD_LANE_ACCESS_P (stmt_info) == 4)
    7898              :     {
    7899          252 :       dr_vec_info *load2_dr_info = STMT_VINFO_DR_INFO (load2_stmt_info);
    7900          252 :       if (TREE_CODE (DR_BASE_ADDRESS (load2_dr_info->dr)) != ADDR_EXPR
    7901          252 :           || !VAR_P (TREE_OPERAND (DR_BASE_ADDRESS (load2_dr_info->dr), 0)))
    7902            0 :         goto fail;
    7903          252 :       var3 = TREE_OPERAND (DR_BASE_ADDRESS (load2_dr_info->dr), 0);
    7904          252 :       if (!lookup_attribute ("omp simd array", DECL_ATTRIBUTES (var3))
    7905          252 :           || lookup_attribute ("omp simd inscan", DECL_ATTRIBUTES (var3))
    7906          504 :           || lookup_attribute ("omp simd inscan exclusive",
    7907          252 :                                DECL_ATTRIBUTES (var3)))
    7908            0 :         goto fail;
    7909              :     }
    7910              : 
    7911          516 :   dr_vec_info *other_dr_info = STMT_VINFO_DR_INFO (other_store_stmt_info);
    7912          516 :   if (TREE_CODE (DR_BASE_ADDRESS (other_dr_info->dr)) != ADDR_EXPR
    7913          516 :       || !VAR_P (TREE_OPERAND (DR_BASE_ADDRESS (other_dr_info->dr), 0)))
    7914            0 :     goto fail;
    7915              : 
    7916          516 :   tree var1 = TREE_OPERAND (DR_BASE_ADDRESS (dr_info->dr), 0);
    7917          516 :   tree var2 = TREE_OPERAND (DR_BASE_ADDRESS (other_dr_info->dr), 0);
    7918          516 :   if (!lookup_attribute ("omp simd array", DECL_ATTRIBUTES (var1))
    7919          516 :       || !lookup_attribute ("omp simd array", DECL_ATTRIBUTES (var2))
    7920         1032 :       || (!lookup_attribute ("omp simd inscan", DECL_ATTRIBUTES (var1)))
    7921          516 :          == (!lookup_attribute ("omp simd inscan", DECL_ATTRIBUTES (var2))))
    7922            0 :     goto fail;
    7923              : 
    7924          516 :   if (lookup_attribute ("omp simd inscan", DECL_ATTRIBUTES (var1)))
    7925          258 :     std::swap (var1, var2);
    7926              : 
    7927          516 :   if (STMT_VINFO_SIMD_LANE_ACCESS_P (stmt_info) == 4)
    7928              :     {
    7929          252 :       if (!lookup_attribute ("omp simd inscan exclusive",
    7930          252 :                              DECL_ATTRIBUTES (var1)))
    7931            0 :         goto fail;
    7932          252 :       var1 = var3;
    7933              :     }
    7934              : 
    7935          516 :   if (loop_vinfo->scan_map == NULL)
    7936            0 :     goto fail;
    7937          516 :   tree *init = loop_vinfo->scan_map->get (var1);
    7938          516 :   if (init == NULL)
    7939            0 :     goto fail;
    7940              : 
    7941              :   /* The IL is as expected, now check if we can actually vectorize it.
    7942              :      Inclusive scan:
    7943              :        _26 = D.2043[_25];
    7944              :        _27 = D.2042[_25];
    7945              :        _28 = _26 + _27;
    7946              :        D.2043[_25] = _28;
    7947              :        D.2042[_25] = _28;
    7948              :      should be vectorized as (where _40 is the vectorized rhs
    7949              :      from the D.2042[_21] = 0; store):
    7950              :        _30 = MEM <vector(8) int> [(int *)&D.2043];
    7951              :        _31 = MEM <vector(8) int> [(int *)&D.2042];
    7952              :        _32 = VEC_PERM_EXPR <_40, _31, { 0, 8, 9, 10, 11, 12, 13, 14 }>;
    7953              :        _33 = _31 + _32;
    7954              :        // _33 = { _31[0], _31[0]+_31[1], _31[1]+_31[2], ..., _31[6]+_31[7] };
    7955              :        _34 = VEC_PERM_EXPR <_40, _33, { 0, 1, 8, 9, 10, 11, 12, 13 }>;
    7956              :        _35 = _33 + _34;
    7957              :        // _35 = { _31[0], _31[0]+_31[1], _31[0]+.._31[2], _31[0]+.._31[3],
    7958              :        //         _31[1]+.._31[4], ... _31[4]+.._31[7] };
    7959              :        _36 = VEC_PERM_EXPR <_40, _35, { 0, 1, 2, 3, 8, 9, 10, 11 }>;
    7960              :        _37 = _35 + _36;
    7961              :        // _37 = { _31[0], _31[0]+_31[1], _31[0]+.._31[2], _31[0]+.._31[3],
    7962              :        //         _31[0]+.._31[4], ... _31[0]+.._31[7] };
    7963              :        _38 = _30 + _37;
    7964              :        _39 = VEC_PERM_EXPR <_38, _38, { 7, 7, 7, 7, 7, 7, 7, 7 }>;
    7965              :        MEM <vector(8) int> [(int *)&D.2043] = _39;
    7966              :        MEM <vector(8) int> [(int *)&D.2042] = _38;
    7967              :      Exclusive scan:
    7968              :        _26 = D.2043[_25];
    7969              :        D.2044[_25] = _26;
    7970              :        _27 = D.2042[_25];
    7971              :        _28 = _26 + _27;
    7972              :        D.2043[_25] = _28;
    7973              :      should be vectorized as (where _40 is the vectorized rhs
    7974              :      from the D.2042[_21] = 0; store):
    7975              :        _30 = MEM <vector(8) int> [(int *)&D.2043];
    7976              :        _31 = MEM <vector(8) int> [(int *)&D.2042];
    7977              :        _32 = VEC_PERM_EXPR <_40, _31, { 0, 8, 9, 10, 11, 12, 13, 14 }>;
    7978              :        _33 = VEC_PERM_EXPR <_40, _32, { 0, 8, 9, 10, 11, 12, 13, 14 }>;
    7979              :        _34 = _32 + _33;
    7980              :        // _34 = { 0, _31[0], _31[0]+_31[1], _31[1]+_31[2], _31[2]+_31[3],
    7981              :        //         _31[3]+_31[4], ... _31[5]+.._31[6] };
    7982              :        _35 = VEC_PERM_EXPR <_40, _34, { 0, 1, 8, 9, 10, 11, 12, 13 }>;
    7983              :        _36 = _34 + _35;
    7984              :        // _36 = { 0, _31[0], _31[0]+_31[1], _31[0]+.._31[2], _31[0]+.._31[3],
    7985              :        //         _31[1]+.._31[4], ... _31[3]+.._31[6] };
    7986              :        _37 = VEC_PERM_EXPR <_40, _36, { 0, 1, 2, 3, 8, 9, 10, 11 }>;
    7987              :        _38 = _36 + _37;
    7988              :        // _38 = { 0, _31[0], _31[0]+_31[1], _31[0]+.._31[2], _31[0]+.._31[3],
    7989              :        //         _31[0]+.._31[4], ... _31[0]+.._31[6] };
    7990              :        _39 = _30 + _38;
    7991              :        _50 = _31 + _39;
    7992              :        _51 = VEC_PERM_EXPR <_50, _50, { 7, 7, 7, 7, 7, 7, 7, 7 }>;
    7993              :        MEM <vector(8) int> [(int *)&D.2044] = _39;
    7994              :        MEM <vector(8) int> [(int *)&D.2042] = _51;  */
    7995          516 :   enum machine_mode vec_mode = TYPE_MODE (vectype);
    7996          516 :   optab optab = optab_for_tree_code (code, vectype, optab_default);
    7997          516 :   if (!optab || !can_implement_p (optab, vec_mode))
    7998            0 :     goto fail;
    7999              : 
    8000          516 :   int units_log2 = scan_store_can_perm_p (vectype, *init);
    8001          516 :   if (units_log2 == -1)
    8002            0 :     goto fail;
    8003              : 
    8004              :   return true;
    8005              : }
    8006              : 
    8007              : 
    8008              : /* Function vectorizable_scan_store.
    8009              : 
    8010              :    Helper of vectorizable_score, arguments like on vectorizable_store.
    8011              :    Handle only the transformation, checking is done in check_scan_store.  */
    8012              : 
    8013              : static bool
    8014          516 : vectorizable_scan_store (vec_info *vinfo, stmt_vec_info stmt_info,
    8015              :                          slp_tree slp_node, gimple_stmt_iterator *gsi)
    8016              : {
    8017          516 :   loop_vec_info loop_vinfo = dyn_cast <loop_vec_info> (vinfo);
    8018          516 :   dr_vec_info *dr_info = STMT_VINFO_DR_INFO (stmt_info);
    8019          516 :   tree ref_type = reference_alias_ptr_type (DR_REF (dr_info->dr));
    8020          516 :   tree vectype = SLP_TREE_VECTYPE (slp_node);
    8021              : 
    8022          516 :   if (dump_enabled_p ())
    8023          492 :     dump_printf_loc (MSG_NOTE, vect_location,
    8024              :                      "transform scan store.\n");
    8025              : 
    8026          516 :   gimple *stmt = STMT_VINFO_STMT (stmt_info);
    8027          516 :   tree rhs = gimple_assign_rhs1 (stmt);
    8028          516 :   gcc_assert (TREE_CODE (rhs) == SSA_NAME);
    8029              : 
    8030          516 :   tree var = TREE_OPERAND (DR_BASE_ADDRESS (dr_info->dr), 0);
    8031          516 :   bool inscan_var_store
    8032          516 :     = lookup_attribute ("omp simd inscan", DECL_ATTRIBUTES (var)) != NULL;
    8033              : 
    8034          516 :   if (STMT_VINFO_SIMD_LANE_ACCESS_P (stmt_info) == 4 && !inscan_var_store)
    8035              :     {
    8036          126 :       use_operand_p use_p;
    8037          126 :       imm_use_iterator iter;
    8038          126 :       FOR_EACH_IMM_USE_FAST (use_p, iter, rhs)
    8039              :         {
    8040          126 :           gimple *use_stmt = USE_STMT (use_p);
    8041          126 :           if (use_stmt == stmt || is_gimple_debug (use_stmt))
    8042            0 :             continue;
    8043          126 :           rhs = gimple_assign_lhs (use_stmt);
    8044          126 :           break;
    8045          126 :         }
    8046              :     }
    8047              : 
    8048          516 :   gimple *def_stmt = SSA_NAME_DEF_STMT (rhs);
    8049          516 :   enum tree_code code = gimple_assign_rhs_code (def_stmt);
    8050          516 :   if (code == POINTER_PLUS_EXPR)
    8051            0 :     code = PLUS_EXPR;
    8052          516 :   gcc_assert (TREE_CODE_LENGTH (code) == binary_op
    8053              :               && commutative_tree_code (code));
    8054          516 :   tree rhs1 = gimple_assign_rhs1 (def_stmt);
    8055          516 :   tree rhs2 = gimple_assign_rhs2 (def_stmt);
    8056          516 :   gcc_assert (TREE_CODE (rhs1) == SSA_NAME && TREE_CODE (rhs2) == SSA_NAME);
    8057          516 :   gimple *load1_stmt = SSA_NAME_DEF_STMT (rhs1);
    8058          516 :   gimple *load2_stmt = SSA_NAME_DEF_STMT (rhs2);
    8059          516 :   stmt_vec_info load1_stmt_info = loop_vinfo->lookup_stmt (load1_stmt);
    8060          516 :   stmt_vec_info load2_stmt_info = loop_vinfo->lookup_stmt (load2_stmt);
    8061          516 :   dr_vec_info *load1_dr_info = STMT_VINFO_DR_INFO (load1_stmt_info);
    8062          516 :   dr_vec_info *load2_dr_info = STMT_VINFO_DR_INFO (load2_stmt_info);
    8063          516 :   tree var1 = TREE_OPERAND (DR_BASE_ADDRESS (load1_dr_info->dr), 0);
    8064          516 :   tree var2 = TREE_OPERAND (DR_BASE_ADDRESS (load2_dr_info->dr), 0);
    8065              : 
    8066          516 :   if (lookup_attribute ("omp simd inscan", DECL_ATTRIBUTES (var1)))
    8067              :     {
    8068          440 :       std::swap (rhs1, rhs2);
    8069          440 :       std::swap (var1, var2);
    8070          440 :       std::swap (load1_dr_info, load2_dr_info);
    8071          440 :       std::swap (load1_stmt_info, load2_stmt_info);
    8072              :     }
    8073              : 
    8074          516 :   tree *init = loop_vinfo->scan_map->get (var1);
    8075          516 :   gcc_assert (init);
    8076              : 
    8077          516 :   unsigned HOST_WIDE_INT nunits;
    8078          516 :   if (!TYPE_VECTOR_SUBPARTS (vectype).is_constant (&nunits))
    8079              :     gcc_unreachable ();
    8080          516 :   auto_vec<enum scan_store_kind, 16> use_whole_vector;
    8081          516 :   int units_log2 = scan_store_can_perm_p (vectype, *init, &use_whole_vector);
    8082          516 :   gcc_assert (units_log2 > 0);
    8083          516 :   auto_vec<tree, 16> perms;
    8084          516 :   perms.quick_grow (units_log2 + 1);
    8085          516 :   tree zero_vec = NULL_TREE, masktype = NULL_TREE;
    8086         2924 :   for (int i = 0; i <= units_log2; ++i)
    8087              :     {
    8088         1892 :       unsigned HOST_WIDE_INT j, k;
    8089         1892 :       vec_perm_builder sel (nunits, nunits, 1);
    8090         1892 :       sel.quick_grow (nunits);
    8091         1892 :       if (i == units_log2)
    8092         4884 :         for (j = 0; j < nunits; ++j)
    8093         4368 :           sel[j] = nunits - 1;
    8094              :       else
    8095              :         {
    8096         5228 :           for (j = 0; j < (HOST_WIDE_INT_1U << i); ++j)
    8097         3852 :             sel[j] = j;
    8098        13236 :           for (k = 0; j < nunits; ++j, ++k)
    8099        11860 :             sel[j] = nunits + k;
    8100              :         }
    8101         3268 :       vec_perm_indices indices (sel, i == units_log2 ? 1 : 2, nunits);
    8102         1892 :       if (!use_whole_vector.is_empty ()
    8103            0 :           && use_whole_vector[i] != scan_store_kind_perm)
    8104              :         {
    8105            0 :           if (zero_vec == NULL_TREE)
    8106            0 :             zero_vec = build_zero_cst (vectype);
    8107            0 :           if (masktype == NULL_TREE
    8108            0 :               && use_whole_vector[i] == scan_store_kind_lshift_cond)
    8109            0 :             masktype = truth_type_for (vectype);
    8110            0 :           perms[i] = vect_gen_perm_mask_any (vectype, indices);
    8111              :         }
    8112              :       else
    8113         1892 :         perms[i] = vect_gen_perm_mask_checked (vectype, indices);
    8114         1892 :     }
    8115              : 
    8116          516 :   tree vec_oprnd1 = NULL_TREE;
    8117          516 :   tree vec_oprnd2 = NULL_TREE;
    8118          516 :   tree vec_oprnd3 = NULL_TREE;
    8119          516 :   tree dataref_ptr = DR_BASE_ADDRESS (dr_info->dr);
    8120          516 :   tree dataref_offset = build_int_cst (ref_type, 0);
    8121          516 :   tree bump = vect_get_data_ptr_bump (vinfo, dr_info, vectype, VMAT_CONTIGUOUS);
    8122          516 :   tree ldataref_ptr = NULL_TREE;
    8123          516 :   tree orig = NULL_TREE;
    8124          516 :   if (STMT_VINFO_SIMD_LANE_ACCESS_P (stmt_info) == 4 && !inscan_var_store)
    8125          126 :     ldataref_ptr = DR_BASE_ADDRESS (load1_dr_info->dr);
    8126              :   /* The initialization is invariant.  */
    8127          516 :   vec_oprnd1 = vect_init_vector (vinfo, stmt_info, *init, vectype, NULL);
    8128          516 :   auto_vec<tree> vec_oprnds2;
    8129          516 :   auto_vec<tree> vec_oprnds3;
    8130          516 :   if (ldataref_ptr == NULL)
    8131              :     {
    8132              :       /* We want to lookup the vector operands of the reduction, not those
    8133              :          of the store - for SLP we have to use the proper SLP node for the
    8134              :          lookup, which should be the single child of the scan store.  */
    8135          390 :       vect_get_vec_defs (vinfo, SLP_TREE_CHILDREN (slp_node)[0],
    8136              :                          rhs1, &vec_oprnds2, rhs2, &vec_oprnds3);
    8137              :       /* ???  For SLP we do not key the def on 'rhs1' or 'rhs2' but get
    8138              :          them in SLP child order.  So we have to swap here with logic
    8139              :          similar to above.  */
    8140          390 :       stmt_vec_info load
    8141          390 :         = SLP_TREE_SCALAR_STMTS (SLP_TREE_CHILDREN
    8142          390 :                                    (SLP_TREE_CHILDREN (slp_node)[0])[0])[0];
    8143          390 :       dr_vec_info *dr_info = STMT_VINFO_DR_INFO (load);
    8144          390 :       tree var = TREE_OPERAND (DR_BASE_ADDRESS (dr_info->dr), 0);
    8145          390 :       if (lookup_attribute ("omp simd inscan", DECL_ATTRIBUTES (var)))
    8146          828 :         for (unsigned i = 0; i < vec_oprnds2.length (); ++i)
    8147          498 :           std::swap (vec_oprnds2[i], vec_oprnds3[i]);;
    8148              :     }
    8149              :   else
    8150          126 :     vect_get_vec_defs (vinfo, slp_node,
    8151              :                        rhs2, &vec_oprnds3);
    8152         1256 :   for (unsigned j = 0; j < vec_oprnds3.length (); j++)
    8153              :     {
    8154          740 :       if (ldataref_ptr == NULL)
    8155          558 :         vec_oprnd2 = vec_oprnds2[j];
    8156          740 :       vec_oprnd3 = vec_oprnds3[j];
    8157          740 :       if (j == 0)
    8158              :         orig = vec_oprnd3;
    8159          224 :       else if (!inscan_var_store)
    8160          112 :         dataref_offset = int_const_binop (PLUS_EXPR, dataref_offset, bump);
    8161              : 
    8162          740 :       if (ldataref_ptr)
    8163              :         {
    8164          182 :           vec_oprnd2 = make_ssa_name (vectype);
    8165          182 :           tree data_ref = fold_build2 (MEM_REF, vectype,
    8166              :                                        unshare_expr (ldataref_ptr),
    8167              :                                        dataref_offset);
    8168          182 :           vect_copy_ref_info (data_ref, load1_stmt_info);
    8169          182 :           gimple *g = gimple_build_assign (vec_oprnd2, data_ref);
    8170          182 :           vect_finish_stmt_generation (vinfo, stmt_info, g, gsi);
    8171              :         }
    8172              : 
    8173          740 :       tree v = vec_oprnd2;
    8174         3080 :       for (int i = 0; i < units_log2; ++i)
    8175              :         {
    8176         2340 :           tree new_temp = make_ssa_name (vectype);
    8177         2340 :           gimple *g = gimple_build_assign (new_temp, VEC_PERM_EXPR,
    8178              :                                            (zero_vec
    8179            0 :                                             && (use_whole_vector[i]
    8180            0 :                                                 != scan_store_kind_perm))
    8181              :                                            ? zero_vec : vec_oprnd1, v,
    8182         2340 :                                            perms[i]);
    8183         2340 :           vect_finish_stmt_generation (vinfo, stmt_info, g, gsi);
    8184              : 
    8185         2340 :           if (zero_vec && use_whole_vector[i] == scan_store_kind_lshift_cond)
    8186              :             {
    8187              :               /* Whole vector shift shifted in zero bits, but if *init
    8188              :                  is not initializer_zerop, we need to replace those elements
    8189              :                  with elements from vec_oprnd1.  */
    8190            0 :               tree_vector_builder vb (masktype, nunits, 1);
    8191            0 :               for (unsigned HOST_WIDE_INT k = 0; k < nunits; ++k)
    8192            0 :                 vb.quick_push (k < (HOST_WIDE_INT_1U << i)
    8193              :                                ? boolean_false_node : boolean_true_node);
    8194              : 
    8195            0 :               tree new_temp2 = make_ssa_name (vectype);
    8196            0 :               g = gimple_build_assign (new_temp2, VEC_COND_EXPR, vb.build (),
    8197              :                                        new_temp, vec_oprnd1);
    8198            0 :               vect_finish_stmt_generation (vinfo, stmt_info,
    8199              :                                                            g, gsi);
    8200            0 :               new_temp = new_temp2;
    8201            0 :             }
    8202              : 
    8203              :           /* For exclusive scan, perform the perms[i] permutation once
    8204              :              more.  */
    8205         2340 :           if (i == 0
    8206         1104 :               && STMT_VINFO_SIMD_LANE_ACCESS_P (stmt_info) == 4
    8207          728 :               && v == vec_oprnd2)
    8208              :             {
    8209          364 :               v = new_temp;
    8210          364 :               --i;
    8211          364 :               continue;
    8212              :             }
    8213              : 
    8214         1976 :           tree new_temp2 = make_ssa_name (vectype);
    8215         1976 :           g = gimple_build_assign (new_temp2, code, v, new_temp);
    8216         1976 :           vect_finish_stmt_generation (vinfo, stmt_info, g, gsi);
    8217              : 
    8218         1976 :           v = new_temp2;
    8219              :         }
    8220              : 
    8221          740 :       tree new_temp = make_ssa_name (vectype);
    8222          740 :       gimple *g = gimple_build_assign (new_temp, code, orig, v);
    8223          740 :       vect_finish_stmt_generation (vinfo, stmt_info, g, gsi);
    8224              : 
    8225          740 :       tree last_perm_arg = new_temp;
    8226              :       /* For exclusive scan, new_temp computed above is the exclusive scan
    8227              :          prefix sum.  Turn it into inclusive prefix sum for the broadcast
    8228              :          of the last element into orig.  */
    8229          740 :       if (STMT_VINFO_SIMD_LANE_ACCESS_P (stmt_info) == 4)
    8230              :         {
    8231          364 :           last_perm_arg = make_ssa_name (vectype);
    8232          364 :           g = gimple_build_assign (last_perm_arg, code, new_temp, vec_oprnd2);
    8233          364 :           vect_finish_stmt_generation (vinfo, stmt_info, g, gsi);
    8234              :         }
    8235              : 
    8236          740 :       orig = make_ssa_name (vectype);
    8237         2220 :       g = gimple_build_assign (orig, VEC_PERM_EXPR, last_perm_arg,
    8238          740 :                                last_perm_arg, perms[units_log2]);
    8239          740 :       vect_finish_stmt_generation (vinfo, stmt_info, g, gsi);
    8240              : 
    8241          740 :       if (!inscan_var_store)
    8242              :         {
    8243          370 :           tree data_ref = fold_build2 (MEM_REF, vectype,
    8244              :                                        unshare_expr (dataref_ptr),
    8245              :                                        dataref_offset);
    8246          370 :           vect_copy_ref_info (data_ref, stmt_info);
    8247          370 :           g = gimple_build_assign (data_ref, new_temp);
    8248          370 :           vect_finish_stmt_generation (vinfo, stmt_info, g, gsi);
    8249              :         }
    8250              :     }
    8251              : 
    8252          516 :   if (inscan_var_store)
    8253          628 :     for (unsigned j = 0; j < vec_oprnds3.length (); j++)
    8254              :       {
    8255          370 :         if (j != 0)
    8256          112 :           dataref_offset = int_const_binop (PLUS_EXPR, dataref_offset, bump);
    8257              : 
    8258          370 :         tree data_ref = fold_build2 (MEM_REF, vectype,
    8259              :                                      unshare_expr (dataref_ptr),
    8260              :                                      dataref_offset);
    8261          370 :         vect_copy_ref_info (data_ref, stmt_info);
    8262          370 :         gimple *g = gimple_build_assign (data_ref, orig);
    8263          370 :         vect_finish_stmt_generation (vinfo, stmt_info, g, gsi);
    8264              :       }
    8265          516 :   return true;
    8266          516 : }
    8267              : 
    8268              : 
    8269              : /* Function vectorizable_store.
    8270              : 
    8271              :    Check if STMT_INFO defines a non scalar data-ref (array/pointer/structure)
    8272              :    that can be vectorized.
    8273              :    If COST_VEC is passed, calculate costs but don't change anything,
    8274              :    otherwise, vectorize STMT_INFO: create a vectorized stmt to replace
    8275              :    it, and insert it at GSI.
    8276              :    Return true if STMT_INFO is vectorizable in this way.  */
    8277              : 
    8278              : static bool
    8279      2162562 : vectorizable_store (vec_info *vinfo,
    8280              :                     stmt_vec_info stmt_info, gimple_stmt_iterator *gsi,
    8281              :                     slp_tree slp_node,
    8282              :                     stmt_vector_for_cost *cost_vec)
    8283              : {
    8284      2162562 :   tree data_ref;
    8285      2162562 :   tree vec_oprnd = NULL_TREE;
    8286      2162562 :   tree elem_type;
    8287      2162562 :   loop_vec_info loop_vinfo = dyn_cast <loop_vec_info> (vinfo);
    8288      2162562 :   class loop *loop = NULL;
    8289      2162562 :   machine_mode vec_mode;
    8290      2162562 :   tree dummy;
    8291      2162562 :   enum vect_def_type rhs_dt = vect_unknown_def_type;
    8292      2162562 :   enum vect_def_type mask_dt = vect_unknown_def_type;
    8293      2162562 :   tree dataref_ptr = NULL_TREE;
    8294      2162562 :   tree dataref_offset = NULL_TREE;
    8295      2162562 :   int j;
    8296      2162562 :   stmt_vec_info first_stmt_info;
    8297      2162562 :   bool grouped_store;
    8298      2162562 :   unsigned int group_size, i;
    8299      2162562 :   unsigned int vec_num;
    8300      2162562 :   bb_vec_info bb_vinfo = dyn_cast <bb_vec_info> (vinfo);
    8301      2162562 :   tree aggr_type;
    8302      2162562 :   poly_uint64 vf;
    8303      2162562 :   vec_load_store_type vls_type;
    8304      2162562 :   tree ref_type;
    8305              : 
    8306      2162562 :   if (!STMT_VINFO_RELEVANT_P (stmt_info) && !bb_vinfo)
    8307              :     return false;
    8308              : 
    8309      2162562 :   if (STMT_VINFO_DEF_TYPE (stmt_info) != vect_internal_def
    8310       246817 :       && cost_vec)
    8311              :     return false;
    8312              : 
    8313              :   /* Is vectorizable store? */
    8314              : 
    8315      1915745 :   tree mask_vectype = NULL_TREE;
    8316      1915745 :   slp_tree mask_node = NULL;
    8317      1915745 :   if (gassign *assign = dyn_cast <gassign *> (stmt_info->stmt))
    8318              :     {
    8319      1841008 :       tree scalar_dest = gimple_assign_lhs (assign);
    8320      1841008 :       if (TREE_CODE (scalar_dest) == VIEW_CONVERT_EXPR
    8321      1841008 :           && is_pattern_stmt_p (stmt_info))
    8322         1697 :         scalar_dest = TREE_OPERAND (scalar_dest, 0);
    8323      1841008 :       if (TREE_CODE (scalar_dest) != ARRAY_REF
    8324      1841008 :           && TREE_CODE (scalar_dest) != BIT_FIELD_REF
    8325              :           && TREE_CODE (scalar_dest) != INDIRECT_REF
    8326              :           && TREE_CODE (scalar_dest) != COMPONENT_REF
    8327              :           && TREE_CODE (scalar_dest) != IMAGPART_EXPR
    8328              :           && TREE_CODE (scalar_dest) != REALPART_EXPR
    8329              :           && TREE_CODE (scalar_dest) != MEM_REF)
    8330              :         return false;
    8331              :     }
    8332              :   else
    8333              :     {
    8334        74737 :       gcall *call = dyn_cast <gcall *> (stmt_info->stmt);
    8335        14133 :       if (!call || !gimple_call_internal_p (call))
    8336              :         return false;
    8337              : 
    8338         8344 :       internal_fn ifn = gimple_call_internal_fn (call);
    8339         8344 :       if (!internal_store_fn_p (ifn))
    8340              :         return false;
    8341              : 
    8342         1924 :       int mask_index = internal_fn_mask_index (ifn);
    8343         1924 :       if (mask_index >= 0)
    8344         1924 :         mask_index = vect_slp_child_index_for_operand (stmt_info, mask_index);
    8345         1924 :       if (mask_index >= 0
    8346         1924 :           && !vect_check_scalar_mask (vinfo, slp_node, mask_index,
    8347              :                                       &mask_node, &mask_dt,
    8348              :                                       &mask_vectype))
    8349              :         return false;
    8350              :     }
    8351              : 
    8352      1387914 :   tree vectype = SLP_TREE_VECTYPE (slp_node), rhs_vectype = NULL_TREE;
    8353      1387914 :   poly_uint64 nunits = TYPE_VECTOR_SUBPARTS (vectype);
    8354              : 
    8355      1387914 :   if (loop_vinfo)
    8356              :     {
    8357       242361 :       loop = LOOP_VINFO_LOOP (loop_vinfo);
    8358       242361 :       vf = LOOP_VINFO_VECT_FACTOR (loop_vinfo);
    8359              :     }
    8360              :   else
    8361              :     vf = 1;
    8362      1387914 :   vec_num = vect_get_num_copies (vinfo, slp_node);
    8363              : 
    8364              :   /* FORNOW.  This restriction should be relaxed.  */
    8365      1387914 :   if (loop
    8366      1388203 :       && nested_in_vect_loop_p (loop, stmt_info)
    8367      1388209 :       && vec_num > 1)
    8368              :     {
    8369            6 :       if (dump_enabled_p ())
    8370            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    8371              :                          "multiple types in nested loop.\n");
    8372              :       return false;
    8373              :     }
    8374              : 
    8375      1387908 :   slp_tree op_node;
    8376      1387908 :   if (!vect_check_store_rhs (vinfo, stmt_info, slp_node,
    8377              :                              &op_node, &rhs_dt, &rhs_vectype, &vls_type))
    8378              :     return false;
    8379              : 
    8380      1387884 :   elem_type = TREE_TYPE (vectype);
    8381      1387884 :   vec_mode = TYPE_MODE (vectype);
    8382              : 
    8383      1387884 :   if (!STMT_VINFO_DATA_REF (stmt_info))
    8384              :     return false;
    8385              : 
    8386      1387884 :   vect_load_store_data _ls_data{};
    8387      1387884 :   vect_load_store_data &ls = slp_node->get_data (_ls_data);
    8388      1387884 :   if (cost_vec
    8389      1387884 :       && !get_load_store_type (vinfo, stmt_info, vectype, slp_node, mask_node,
    8390              :                                vls_type, &_ls_data))
    8391              :     return false;
    8392              :   /* Temporary aliases to analysis data, should not be modified through
    8393              :      these.  */
    8394      1387248 :   const vect_memory_access_type memory_access_type = ls.memory_access_type;
    8395      1387248 :   const dr_alignment_support alignment_support_scheme
    8396              :     = ls.alignment_support_scheme;
    8397      1387248 :   const int misalignment = ls.misalignment;
    8398      1387248 :   const poly_int64 poffset = ls.poffset;
    8399              : 
    8400      1387248 :   if (slp_node->ldst_lanes
    8401            0 :       && memory_access_type != VMAT_LOAD_STORE_LANES)
    8402              :     {
    8403            0 :       if (dump_enabled_p ())
    8404            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    8405              :                          "discovered store-lane but cannot use it.\n");
    8406              :       return false;
    8407              :     }
    8408              : 
    8409      1387248 :   if (mask_node)
    8410              :     {
    8411         1834 :       if (memory_access_type == VMAT_CONTIGUOUS)
    8412              :         {
    8413          616 :           if (!VECTOR_MODE_P (vec_mode)
    8414         3152 :               || !can_vec_mask_load_store_p (vec_mode,
    8415         1576 :                                              TYPE_MODE (mask_vectype), false))
    8416              :             return false;
    8417              :         }
    8418          258 :       else if (memory_access_type != VMAT_LOAD_STORE_LANES
    8419          258 :                && (!mat_gather_scatter_p (memory_access_type)
    8420          242 :                    || (memory_access_type == VMAT_GATHER_SCATTER_LEGACY
    8421          170 :                        && !VECTOR_BOOLEAN_TYPE_P (mask_vectype))))
    8422              :         {
    8423           16 :           if (dump_enabled_p ())
    8424           16 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    8425              :                              "unsupported access type for masked store.\n");
    8426              :           return false;
    8427              :         }
    8428          242 :       else if (memory_access_type == VMAT_GATHER_SCATTER_EMULATED)
    8429              :         {
    8430           72 :           if (dump_enabled_p ())
    8431           24 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    8432              :                              "unsupported masked emulated scatter.\n");
    8433              :           return false;
    8434              :         }
    8435              :     }
    8436              :   else
    8437              :     {
    8438              :       /* FORNOW. In some cases can vectorize even if data-type not supported
    8439              :          (e.g. - array initialization with 0).  */
    8440      1385414 :       if (!can_implement_p (mov_optab, vec_mode))
    8441              :         return false;
    8442              :     }
    8443              : 
    8444      1387046 :   dr_vec_info *dr_info = STMT_VINFO_DR_INFO (stmt_info), *first_dr_info = NULL;
    8445      1387046 :   grouped_store = (STMT_VINFO_GROUPED_ACCESS (stmt_info)
    8446      2553639 :                    && !mat_gather_scatter_p (memory_access_type));
    8447      1166593 :   if (grouped_store)
    8448              :     {
    8449      1166593 :       first_stmt_info = DR_GROUP_FIRST_ELEMENT (stmt_info);
    8450      1166593 :       first_dr_info = STMT_VINFO_DR_INFO (first_stmt_info);
    8451      1166593 :       group_size = DR_GROUP_SIZE (first_stmt_info);
    8452              :     }
    8453              :   else
    8454              :     {
    8455      1387046 :       first_stmt_info = stmt_info;
    8456      1387046 :       first_dr_info = dr_info;
    8457              :       group_size = 1;
    8458              :     }
    8459              : 
    8460      1387046 :   if (STMT_VINFO_SIMD_LANE_ACCESS_P (stmt_info) > 1 && cost_vec)
    8461              :     {
    8462         1082 :       if (!check_scan_store (vinfo, stmt_info, vectype, rhs_dt, slp_node,
    8463              :                              mask_node, memory_access_type))
    8464              :         return false;
    8465              :     }
    8466              : 
    8467      1941144 :   bool costing_p = cost_vec;
    8468      1386272 :   if (costing_p) /* transformation not required.  */
    8469              :     {
    8470       832174 :       if (loop_vinfo
    8471       173183 :           && LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo)
    8472       913842 :           && !check_load_store_for_partial_vectors (loop_vinfo, vectype,
    8473              :                                                     slp_node, vls_type,
    8474              :                                                     group_size, &ls, mask_node))
    8475        51096 :         LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo) = false;
    8476              : 
    8477       832174 :       if (!vect_maybe_update_slp_op_vectype (op_node, vectype)
    8478       832174 :           || (mask_node
    8479         1078 :               && !vect_maybe_update_slp_op_vectype (mask_node,
    8480              :                                                     mask_vectype)))
    8481              :         {
    8482            0 :           if (dump_enabled_p ())
    8483            0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    8484              :                              "incompatible vector types for invariants\n");
    8485              :           return false;
    8486              :         }
    8487              : 
    8488       832174 :       if (dump_enabled_p ()
    8489              :           && memory_access_type != VMAT_ELEMENTWISE
    8490        16157 :           && memory_access_type != VMAT_STRIDED_SLP
    8491        15490 :           && memory_access_type != VMAT_INVARIANT
    8492       847664 :           && alignment_support_scheme != dr_aligned)
    8493         5557 :         dump_printf_loc (MSG_NOTE, vect_location,
    8494              :                          "Vectorizing an unaligned access.\n");
    8495              :     }
    8496              : 
    8497              :   /* Transform.  */
    8498              : 
    8499              :   if (!costing_p)
    8500       554872 :     ensure_base_align (dr_info);
    8501              : 
    8502      1387046 :   if (STMT_VINFO_SIMD_LANE_ACCESS_P (stmt_info) >= 3)
    8503              :     {
    8504         1032 :       gcc_assert (memory_access_type == VMAT_CONTIGUOUS);
    8505         1032 :       gcc_assert (SLP_TREE_LANES (slp_node) == 1);
    8506         1032 :       if (costing_p)
    8507              :         {
    8508          516 :           unsigned int inside_cost = 0, prologue_cost = 0;
    8509          516 :           if (vls_type == VLS_STORE_INVARIANT)
    8510            0 :             prologue_cost += record_stmt_cost (cost_vec, 1, scalar_to_vec,
    8511              :                                                slp_node, 0, vect_prologue);
    8512          516 :           vect_get_store_cost (vinfo, stmt_info, slp_node, 1,
    8513              :                                alignment_support_scheme, misalignment,
    8514              :                                &inside_cost, cost_vec);
    8515              : 
    8516          516 :           if (dump_enabled_p ())
    8517          492 :             dump_printf_loc (MSG_NOTE, vect_location,
    8518              :                              "vect_model_store_cost: inside_cost = %d, "
    8519              :                              "prologue_cost = %d .\n",
    8520              :                              inside_cost, prologue_cost);
    8521              : 
    8522          516 :           SLP_TREE_TYPE (slp_node) = store_vec_info_type;
    8523          516 :           slp_node->data = new vect_load_store_data (std::move (ls));
    8524              : 
    8525          516 :           return true;
    8526              :         }
    8527          516 :       return vectorizable_scan_store (vinfo, stmt_info, slp_node, gsi);
    8528              :     }
    8529              : 
    8530              :   /* FORNOW */
    8531      1386014 :   gcc_assert (!grouped_store
    8532              :               || !loop
    8533              :               || !nested_in_vect_loop_p (loop, stmt_info));
    8534              : 
    8535      1386014 :   grouped_store = false;
    8536      1386014 :   first_stmt_info = SLP_TREE_SCALAR_STMTS (slp_node)[0];
    8537      1386014 :   gcc_assert (!STMT_VINFO_GROUPED_ACCESS (first_stmt_info)
    8538              :               || (DR_GROUP_FIRST_ELEMENT (first_stmt_info) == first_stmt_info));
    8539      1386014 :   first_dr_info = STMT_VINFO_DR_INFO (first_stmt_info);
    8540              : 
    8541      1386014 :   ref_type = get_group_alias_ptr_type (first_stmt_info);
    8542              : 
    8543      1386014 :   if (!costing_p && dump_enabled_p ())
    8544        13027 :     dump_printf_loc (MSG_NOTE, vect_location, "transform store.\n");
    8545              : 
    8546      1386014 :   if (memory_access_type == VMAT_ELEMENTWISE
    8547      1386014 :       || memory_access_type == VMAT_STRIDED_SLP)
    8548              :     {
    8549        30096 :       unsigned inside_cost = 0, prologue_cost = 0;
    8550        30096 :       gimple_stmt_iterator incr_gsi;
    8551        30096 :       bool insert_after;
    8552        30096 :       tree offvar = NULL_TREE;
    8553        30096 :       tree ivstep;
    8554        30096 :       tree running_off;
    8555        30096 :       tree stride_base, stride_step, alias_off;
    8556        30096 :       tree vec_oprnd = NULL_TREE;
    8557        30096 :       tree dr_offset;
    8558              :       /* Checked by get_load_store_type.  */
    8559        30096 :       unsigned int const_nunits = nunits.to_constant ();
    8560              : 
    8561        30096 :       gcc_assert (!LOOP_VINFO_FULLY_MASKED_P (loop_vinfo));
    8562        30096 :       gcc_assert (!nested_in_vect_loop_p (loop, stmt_info));
    8563              : 
    8564        30096 :       dr_offset = get_dr_vinfo_offset (vinfo, first_dr_info);
    8565        30096 :       stride_base
    8566        30096 :         = fold_build_pointer_plus
    8567              :             (DR_BASE_ADDRESS (first_dr_info->dr),
    8568              :              size_binop (PLUS_EXPR,
    8569              :                          convert_to_ptrofftype (dr_offset),
    8570              :                          convert_to_ptrofftype (DR_INIT (first_dr_info->dr))));
    8571        30096 :       stride_step = fold_convert (sizetype, DR_STEP (first_dr_info->dr));
    8572              : 
    8573              :       /* For a store with loop-invariant (but other than power-of-2)
    8574              :          stride (i.e. not a grouped access) like so:
    8575              : 
    8576              :            for (i = 0; i < n; i += stride)
    8577              :              array[i] = ...;
    8578              : 
    8579              :          we generate a new induction variable and new stores from
    8580              :          the components of the (vectorized) rhs:
    8581              : 
    8582              :            for (j = 0; ; j += VF*stride)
    8583              :              vectemp = ...;
    8584              :              tmp1 = vectemp[0];
    8585              :              array[j] = tmp1;
    8586              :              tmp2 = vectemp[1];
    8587              :              array[j + stride] = tmp2;
    8588              :              ...
    8589              :          */
    8590              : 
    8591              :       /* ???  Modify local copies of alignment_support_scheme and
    8592              :          misalignment, but this part of analysis should be done
    8593              :          earlier and remembered, likewise the chosen load mode.  */
    8594        30096 :       const dr_alignment_support tem = alignment_support_scheme;
    8595        30096 :       dr_alignment_support alignment_support_scheme = tem;
    8596        30096 :       const int tem2 = misalignment;
    8597        30096 :       int misalignment = tem2;
    8598              : 
    8599        30096 :       unsigned nstores = const_nunits;
    8600        30096 :       unsigned lnel = 1;
    8601        30096 :       tree ltype = elem_type;
    8602        30096 :       tree lvectype = vectype;
    8603        30096 :       HOST_WIDE_INT n = gcd (group_size, const_nunits);
    8604        30096 :       if (n == const_nunits)
    8605              :         {
    8606         2962 :           int mis_align = dr_misalignment (first_dr_info, vectype);
    8607              :           /* With VF > 1 we advance the DR by step, if that is constant
    8608              :              and only aligned when performed VF times, DR alignment
    8609              :              analysis can analyze this as aligned since it assumes
    8610              :              contiguous accesses.  But that is not how we code generate
    8611              :              here, so adjust for this.  */
    8612         2962 :           if (maybe_gt (vf, 1u)
    8613         4498 :               && !multiple_p (DR_STEP_ALIGNMENT (first_dr_info->dr),
    8614         4263 :                               DR_TARGET_ALIGNMENT (first_dr_info)))
    8615          235 :             mis_align = -1;
    8616         2962 :           dr_alignment_support dr_align
    8617         2962 :               = vect_supportable_dr_alignment (vinfo, dr_info, vectype,
    8618              :                                                mis_align);
    8619         2962 :           if (dr_align == dr_aligned
    8620         2962 :               || dr_align == dr_unaligned_supported)
    8621              :             {
    8622        30096 :               nstores = 1;
    8623        30096 :               lnel = const_nunits;
    8624        30096 :               ltype = vectype;
    8625        30096 :               lvectype = vectype;
    8626        30096 :               alignment_support_scheme = dr_align;
    8627        30096 :               misalignment = mis_align;
    8628              :             }
    8629              :         }
    8630        27134 :       else if (n > 1)
    8631              :         {
    8632         1962 :           nstores = const_nunits / n;
    8633         1962 :           lnel = n;
    8634         1962 :           ltype = build_vector_type (elem_type, n);
    8635         1962 :           lvectype = vectype;
    8636         1962 :           int mis_align = dr_misalignment (first_dr_info, ltype);
    8637         1962 :           if (maybe_gt (vf, 1u)
    8638         3924 :               && !multiple_p (DR_STEP_ALIGNMENT (first_dr_info->dr),
    8639         3289 :                               DR_TARGET_ALIGNMENT (first_dr_info)))
    8640          635 :             mis_align = -1;
    8641         1962 :           dr_alignment_support dr_align
    8642         1962 :             = vect_supportable_dr_alignment (vinfo, dr_info, ltype,
    8643              :                                              mis_align);
    8644         1962 :           alignment_support_scheme = dr_align;
    8645         1962 :           misalignment = mis_align;
    8646              : 
    8647              :           /* First check if vec_extract optab doesn't support extraction
    8648              :              of vector elts directly.  */
    8649         1962 :           scalar_mode elmode = SCALAR_TYPE_MODE (elem_type);
    8650         1962 :           machine_mode vmode;
    8651         3924 :           if (!VECTOR_MODE_P (TYPE_MODE (vectype))
    8652         1962 :               || !related_vector_mode (TYPE_MODE (vectype), elmode,
    8653         1962 :                                        n).exists (&vmode)
    8654         2134 :               || can_vec_extract (TYPE_MODE (vectype), vmode) != vmode
    8655         1962 :               || !(dr_align == dr_aligned
    8656          172 :                    || dr_align == dr_unaligned_supported))
    8657              :             {
    8658              :               /* Try to avoid emitting an extract of vector elements
    8659              :                  by performing the extracts using an integer type of the
    8660              :                  same size, extracting from a vector of those and then
    8661              :                  re-interpreting it as the original vector type if
    8662              :                  supported.  */
    8663         1790 :               unsigned lsize = n * GET_MODE_BITSIZE (elmode);
    8664         1790 :               unsigned int lnunits = const_nunits / n;
    8665              :               /* If we can't construct such a vector fall back to
    8666              :                  element extracts from the original vector type and
    8667              :                  element size stores.  */
    8668         1790 :               if (int_mode_for_size (lsize, 0).exists (&elmode)
    8669         1790 :                   && VECTOR_MODE_P (TYPE_MODE (vectype))
    8670         1790 :                   && related_vector_mode (TYPE_MODE (vectype), elmode,
    8671         1790 :                                           lnunits).exists (&vmode)
    8672         1762 :                   && can_vec_extract (vmode, elmode).exists ())
    8673              :                 {
    8674         1762 :                   nstores = lnunits;
    8675         1762 :                   lnel = n;
    8676         1762 :                   ltype = build_nonstandard_integer_type (lsize, 1);
    8677         1762 :                   lvectype = build_vector_type (ltype, nstores);
    8678              :                 }
    8679              :               /* Else fall back to vector extraction anyway.
    8680              :                  Fewer stores are more important than avoiding spilling
    8681              :                  of the vector we extract from.  Compared to the
    8682              :                  construction case in vectorizable_load no store-forwarding
    8683              :                  issue exists here for reasonable archs.  But only
    8684              :                  if the store is supported.  */
    8685           28 :                  else if (!(dr_align == dr_aligned
    8686           28 :                             || dr_align == dr_unaligned_supported))
    8687              :                    {
    8688        30096 :                      nstores = const_nunits;
    8689        30096 :                      lnel = 1;
    8690        30096 :                      ltype = elem_type;
    8691        30096 :                      lvectype = vectype;
    8692              :                    }
    8693              :             }
    8694              :         }
    8695              : 
    8696        30096 :       if (costing_p)
    8697              :         {
    8698              :           /* Record the decomposition type for target access during costing.  */
    8699        26539 :           ls.ls_type = lvectype;
    8700        26539 :           ls.ls_eltype = ltype;
    8701              :         }
    8702              :       else
    8703         3557 :         gcc_assert (ls.ls_type == lvectype && ls.ls_eltype == ltype);
    8704              : 
    8705        30096 :       unsigned align;
    8706        30096 :       if (alignment_support_scheme == dr_aligned)
    8707         1263 :         align = known_alignment (DR_TARGET_ALIGNMENT (first_dr_info));
    8708              :       else
    8709        28833 :         align = dr_alignment (vect_dr_behavior (vinfo, first_dr_info));
    8710              :       /* Alignment is at most the access size if we do multiple stores.  */
    8711        30096 :       if (nstores > 1)
    8712        27134 :         align = MIN (tree_to_uhwi (TYPE_SIZE_UNIT (ltype)), align);
    8713        30096 :       ltype = build_aligned_type (ltype, align * BITS_PER_UNIT);
    8714        30096 :       int ncopies = vec_num;
    8715              : 
    8716        30096 :       if (!costing_p)
    8717              :         {
    8718         3557 :           ivstep = stride_step;
    8719              : 
    8720         3557 :           tree increment = fold_convert (TREE_TYPE (ivstep),
    8721              :                                          LOOP_VINFO_IV_INCREMENT (loop_vinfo));
    8722              : 
    8723         3557 :           ivstep = fold_build2 (MULT_EXPR, TREE_TYPE (ivstep), ivstep,
    8724              :                                 increment);
    8725              : 
    8726         3557 :           standard_iv_increment_position (loop, &incr_gsi, &insert_after);
    8727              : 
    8728         3557 :           stride_base = cse_and_gimplify_to_preheader (loop_vinfo, stride_base);
    8729         3557 :           if (LOOP_VINFO_IV_INCREMENT_INVARIANT_P (loop_vinfo))
    8730         3557 :             ivstep = cse_and_gimplify_to_preheader (loop_vinfo, ivstep);
    8731              :           else
    8732            0 :             ivstep = force_gimple_operand_gsi (&incr_gsi, unshare_expr (ivstep),
    8733              :                                                true, NULL_TREE, true,
    8734              :                                                GSI_SAME_STMT);
    8735              : 
    8736         3557 :           create_iv (stride_base, PLUS_EXPR, ivstep, NULL, loop, &incr_gsi,
    8737              :                      insert_after, &offvar, NULL,
    8738         3557 :                      LOOP_VINFO_IV_INCREMENT_INVARIANT_P (loop_vinfo));
    8739              : 
    8740         3557 :           stride_step = cse_and_gimplify_to_preheader (loop_vinfo, stride_step);
    8741              :         }
    8742              : 
    8743        30096 :       alias_off = build_int_cst (ref_type, 0);
    8744        30096 :       auto_vec<tree> vec_oprnds;
    8745              :       /* For costing some adjacent vector stores, we'd like to cost with
    8746              :          the total number of them once instead of cost each one by one. */
    8747        30096 :       unsigned int n_adjacent_stores = 0;
    8748        30096 :       running_off = offvar;
    8749        30096 :       if (!costing_p)
    8750         3557 :         vect_get_slp_defs (op_node, &vec_oprnds);
    8751        30096 :       unsigned int group_el = 0;
    8752        30096 :       unsigned HOST_WIDE_INT elsz
    8753        30096 :         = tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (vectype)));
    8754        71211 :       for (j = 0; j < ncopies; j++)
    8755              :         {
    8756        41115 :           if (!costing_p)
    8757              :             {
    8758         5335 :               vec_oprnd = vec_oprnds[j];
    8759              :               /* Pun the vector to extract from if necessary.  */
    8760         5335 :               if (lvectype != vectype)
    8761              :                 {
    8762         1012 :                   tree tem = make_ssa_name (lvectype);
    8763         1012 :                   tree cvt = build1 (VIEW_CONVERT_EXPR, lvectype, vec_oprnd);
    8764         1012 :                   gimple *pun = gimple_build_assign (tem, cvt);
    8765         1012 :                   vect_finish_stmt_generation (vinfo, stmt_info, pun, gsi);
    8766         1012 :                   vec_oprnd = tem;
    8767              :                 }
    8768              :             }
    8769       182442 :           for (i = 0; i < nstores; i++)
    8770              :             {
    8771       141327 :               if (costing_p)
    8772              :                 {
    8773       125239 :                   n_adjacent_stores++;
    8774       125239 :                   continue;
    8775              :                 }
    8776        16088 :               tree newref, newoff;
    8777        16088 :               gimple *incr, *assign;
    8778        16088 :               tree size = TYPE_SIZE (ltype);
    8779              :               /* Extract the i'th component.  */
    8780        16088 :               tree pos = fold_build2 (MULT_EXPR, bitsizetype,
    8781              :                                       bitsize_int (i), size);
    8782        16088 :               tree elem = fold_build3 (BIT_FIELD_REF, ltype, vec_oprnd,
    8783              :                                        size, pos);
    8784              : 
    8785        16088 :               elem = force_gimple_operand_gsi (gsi, elem, true, NULL_TREE, true,
    8786              :                                                GSI_SAME_STMT);
    8787              : 
    8788        16088 :               tree this_off = build_int_cst (TREE_TYPE (alias_off),
    8789        16088 :                                              group_el * elsz);
    8790        16088 :               newref = build2 (MEM_REF, ltype, running_off, this_off);
    8791        16088 :               vect_copy_ref_info (newref, first_stmt_info);
    8792              : 
    8793              :               /* And store it to *running_off.  */
    8794        16088 :               assign = gimple_build_assign (newref, elem);
    8795        16088 :               vect_finish_stmt_generation (vinfo, stmt_info, assign, gsi);
    8796              : 
    8797        16088 :               group_el += lnel;
    8798        16088 :               if (group_el == group_size)
    8799              :                 {
    8800        14948 :                   newoff = copy_ssa_name (running_off, NULL);
    8801        14948 :                   incr = gimple_build_assign (newoff, POINTER_PLUS_EXPR,
    8802              :                                               running_off, stride_step);
    8803        14948 :                   vect_finish_stmt_generation (vinfo, stmt_info, incr, gsi);
    8804              : 
    8805        14948 :                   running_off = newoff;
    8806        14948 :                   group_el = 0;
    8807              :                 }
    8808              :             }
    8809              :         }
    8810              : 
    8811        30096 :       if (costing_p)
    8812              :         {
    8813        26539 :           if (n_adjacent_stores > 0)
    8814              :             {
    8815              :               /* Take a single lane vector type store as scalar
    8816              :                  store to avoid ICE like 110776.  */
    8817        26539 :               if (VECTOR_TYPE_P (ltype)
    8818        26539 :                   && maybe_ne (TYPE_VECTOR_SUBPARTS (ltype), 1U))
    8819         1608 :                 vect_get_store_cost (vinfo, stmt_info, slp_node,
    8820              :                                      n_adjacent_stores, alignment_support_scheme,
    8821              :                                      misalignment, &inside_cost, cost_vec);
    8822              :               else
    8823        24931 :                 inside_cost
    8824        24931 :                   += record_stmt_cost (cost_vec, n_adjacent_stores,
    8825              :                                        scalar_store, slp_node, 0, vect_body);
    8826              :               /* Only need vector deconstruction when there is more
    8827              :                  than one store.  */
    8828        26539 :               if (nstores > 1)
    8829        24515 :                 inside_cost
    8830        24515 :                   += record_stmt_cost (cost_vec, ncopies,
    8831              :                                        vec_deconstruct, slp_node, 0, vect_body);
    8832              :             }
    8833        26539 :           if (dump_enabled_p ())
    8834          667 :             dump_printf_loc (MSG_NOTE, vect_location,
    8835              :                              "vect_model_store_cost: inside_cost = %d, "
    8836              :                              "prologue_cost = %d .\n",
    8837              :                              inside_cost, prologue_cost);
    8838              : 
    8839        26539 :           SLP_TREE_TYPE (slp_node) = store_vec_info_type;
    8840        26539 :           slp_node->data = new vect_load_store_data (std::move (ls));
    8841              :         }
    8842              : 
    8843        30096 :       return true;
    8844        30096 :     }
    8845              : 
    8846      1355918 :   gcc_assert (alignment_support_scheme);
    8847      1355918 :   bool masks_p = loop_vinfo && LOOP_VINFO_FULLY_MASKED_P (loop_vinfo);
    8848       210365 :   bool lens_p = loop_vinfo && LOOP_VINFO_FULLY_WITH_LENGTH_P (loop_vinfo);
    8849              : 
    8850              :   /* The vect_transform_stmt and vect_analyze_stmt will go here but there
    8851              :      are some difference here.  We cannot enable both the lens and masks
    8852              :      during transform but it is allowed during analysis.
    8853              :      Shouldn't go with length-based approach if fully masked.  */
    8854      1355918 :   if (cost_vec == NULL)
    8855              :     /* The cost_vec is NULL during transform.  */
    8856       550799 :     gcc_assert ((!lens_p || !masks_p));
    8857              : 
    8858              :   /* Targets with store-lane instructions must not require explicit
    8859              :      realignment.  vect_supportable_dr_alignment always returns either
    8860              :      dr_aligned or dr_unaligned_supported for masked operations.  */
    8861      1355918 :   gcc_assert ((memory_access_type != VMAT_LOAD_STORE_LANES
    8862              :                && !mask_node
    8863              :                && !masks_p)
    8864              :               || alignment_support_scheme == dr_aligned
    8865              :               || alignment_support_scheme == dr_unaligned_supported);
    8866              : 
    8867      1355918 :   tree offset = NULL_TREE;
    8868      1355918 :   if (!known_eq (poffset, 0))
    8869         4754 :     offset = size_int (poffset);
    8870              : 
    8871      1355918 :   tree dr_increment;
    8872      1355918 :   tree dr_bump;
    8873              : 
    8874      1355918 :   tree vec_offset = NULL_TREE;
    8875      1355918 :   if (STMT_VINFO_GATHER_SCATTER_P (stmt_info))
    8876              :     {
    8877         1445 :       aggr_type = NULL_TREE;
    8878         1445 :       dr_increment = NULL_TREE;
    8879         1445 :       dr_bump = NULL_TREE;
    8880              :     }
    8881      1354473 :   else if (mat_gather_scatter_p (memory_access_type))
    8882              :     {
    8883            0 :       aggr_type = elem_type;
    8884            0 :       if (!costing_p)
    8885              :         {
    8886            0 :           tree vtype = ls.ls_type ? ls.ls_type : vectype;
    8887            0 :           vect_get_strided_load_store_ops (stmt_info, slp_node, vtype,
    8888              :                                            ls.strided_offset_vectype,
    8889              :                                            loop_vinfo, gsi,
    8890              :                                            &dr_increment, &dr_bump,
    8891              :                                            &vec_offset);
    8892              :         }
    8893              :     }
    8894              :   else
    8895              :     {
    8896      1354473 :       if (memory_access_type == VMAT_LOAD_STORE_LANES)
    8897            0 :         aggr_type = build_array_type_nelts (elem_type, group_size * nunits);
    8898              :       else
    8899              :         aggr_type = vectype;
    8900      1354473 :       if (!costing_p)
    8901              :         {
    8902       550289 :           dr_increment = vect_get_data_ptr_step (vinfo, dr_info,
    8903              :                                                  memory_access_type);
    8904       550289 :           dr_bump = vect_get_data_ptr_bump (vinfo, dr_info, aggr_type,
    8905              :                                             memory_access_type);
    8906              :         }
    8907              :     }
    8908              : 
    8909      1355918 :   if (loop_vinfo && mask_node && !costing_p)
    8910          554 :     LOOP_VINFO_HAS_MASK_STORE (loop_vinfo) = true;
    8911              : 
    8912              :   /* In case the vectorization factor (VF) is bigger than the number
    8913              :      of elements that we can fit in a vectype (nunits), we have to generate
    8914              :      more than one vector stmt - i.e - we need to "unroll" the
    8915              :      vector stmt by a factor VF/nunits.  */
    8916              : 
    8917      1355918 :   auto_vec<tree> dr_chain (group_size);
    8918      1355918 :   auto_vec<tree> vec_masks;
    8919      1355918 :   tree vec_mask = NULL;
    8920      1355918 :   auto_delete_vec<auto_vec<tree>> gvec_oprnds (group_size);
    8921      6102226 :   for (i = 0; i < group_size; i++)
    8922      3390390 :     gvec_oprnds.quick_push (new auto_vec<tree> ());
    8923              : 
    8924      1355918 :   if (memory_access_type == VMAT_LOAD_STORE_LANES)
    8925              :     {
    8926            0 :       const internal_fn lanes_ifn = ls.lanes_ifn;
    8927              : 
    8928            0 :       if (costing_p)
    8929              :         /* Update all incoming store operand nodes, the general handling
    8930              :            above only handles the mask and the first store operand node.  */
    8931            0 :         for (slp_tree child : SLP_TREE_CHILDREN (slp_node))
    8932            0 :           if (child != mask_node
    8933            0 :               && !vect_maybe_update_slp_op_vectype (child, vectype))
    8934              :             {
    8935            0 :               if (dump_enabled_p ())
    8936            0 :                 dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
    8937              :                                  "incompatible vector types for invariants\n");
    8938              :               return false;
    8939              :             }
    8940            0 :       unsigned inside_cost = 0, prologue_cost = 0;
    8941              :       /* For costing some adjacent vector stores, we'd like to cost with
    8942              :          the total number of them once instead of cost each one by one. */
    8943            0 :       unsigned int n_adjacent_stores = 0;
    8944            0 :       int ncopies = vec_num / group_size;
    8945            0 :       for (j = 0; j < ncopies; j++)
    8946              :         {
    8947            0 :           if (j == 0)
    8948              :             {
    8949            0 :               if (!costing_p)
    8950              :                 {
    8951            0 :                   if (mask_node)
    8952              :                     {
    8953            0 :                       vect_get_slp_defs (mask_node, &vec_masks);
    8954            0 :                       vec_mask = vec_masks[0];
    8955              :                     }
    8956            0 :                   dataref_ptr
    8957            0 :                     = vect_create_data_ref_ptr (vinfo, first_stmt_info,
    8958              :                                                 aggr_type, NULL, offset, &dummy,
    8959              :                                                 gsi, NULL, false, dr_increment);
    8960              :                 }
    8961              :             }
    8962            0 :           else if (!costing_p)
    8963              :             {
    8964            0 :               gcc_assert (!LOOP_VINFO_USING_SELECT_VL_P (loop_vinfo));
    8965            0 :               if (mask_node)
    8966            0 :                 vec_mask = vec_masks[j];
    8967            0 :               dataref_ptr = bump_vector_ptr (vinfo, dataref_ptr, gsi,
    8968              :                                              stmt_info, dr_bump);
    8969              :             }
    8970              : 
    8971            0 :           if (costing_p)
    8972              :             {
    8973            0 :               n_adjacent_stores += group_size;
    8974            0 :               continue;
    8975              :             }
    8976              : 
    8977              :           /* Get an array into which we can store the individual vectors.  */
    8978            0 :           tree vec_array = create_vector_array (vectype, group_size);
    8979              : 
    8980              :           /* Invalidate the current contents of VEC_ARRAY.  This should
    8981              :              become an RTL clobber too, which prevents the vector registers
    8982              :              from being upward-exposed.  */
    8983            0 :           vect_clobber_variable (vinfo, stmt_info, gsi, vec_array);
    8984              : 
    8985              :           /* Store the individual vectors into the array.  */
    8986            0 :           for (i = 0; i < group_size; i++)
    8987              :             {
    8988            0 :               slp_tree child;
    8989            0 :               if (i == 0 || !mask_node)
    8990            0 :                 child = SLP_TREE_CHILDREN (slp_node)[i];
    8991              :               else
    8992            0 :                 child = SLP_TREE_CHILDREN (slp_node)[i + 1];
    8993            0 :               vec_oprnd = SLP_TREE_VEC_DEFS (child)[j];
    8994            0 :               write_vector_array (vinfo, stmt_info, gsi, vec_oprnd, vec_array,
    8995              :                                   i);
    8996              :             }
    8997              : 
    8998            0 :           tree final_mask = NULL;
    8999            0 :           tree final_len = NULL;
    9000            0 :           tree bias = NULL;
    9001            0 :           if (masks_p)
    9002            0 :             final_mask
    9003            0 :               = vect_get_mask (loop_vinfo, gsi, ncopies, vectype, j);
    9004            0 :           if (vec_mask)
    9005            0 :             final_mask = prepare_vec_mask (loop_vinfo, mask_vectype, final_mask,
    9006              :                                            vec_mask, gsi);
    9007              : 
    9008            0 :           if (lanes_ifn == IFN_MASK_LEN_STORE_LANES)
    9009              :             {
    9010            0 :               if (lens_p)
    9011            0 :                 final_len = vect_get_len (loop_vinfo, gsi, ncopies, vectype, j,
    9012              :                                           1, true);
    9013              :               else
    9014            0 :                 final_len = size_int (TYPE_VECTOR_SUBPARTS (vectype));
    9015            0 :               signed char biasval
    9016            0 :                 = LOOP_VINFO_PARTIAL_LOAD_STORE_BIAS (loop_vinfo);
    9017            0 :               bias = build_int_cst (intQI_type_node, biasval);
    9018            0 :               if (!final_mask)
    9019              :                 {
    9020            0 :                   mask_vectype = truth_type_for (vectype);
    9021            0 :                   final_mask = build_minus_one_cst (mask_vectype);
    9022              :                 }
    9023              :             }
    9024              : 
    9025            0 :           gcall *call;
    9026            0 :           if (final_len && final_mask)
    9027              :             {
    9028              :               /* Emit:
    9029              :                    MASK_LEN_STORE_LANES (DATAREF_PTR, ALIAS_PTR, VEC_MASK,
    9030              :                                          LEN, BIAS, VEC_ARRAY).  */
    9031            0 :               unsigned int align = TYPE_ALIGN (TREE_TYPE (vectype));
    9032            0 :               tree alias_ptr = build_int_cst (ref_type, align);
    9033            0 :               call = gimple_build_call_internal (IFN_MASK_LEN_STORE_LANES, 6,
    9034              :                                                  dataref_ptr, alias_ptr,
    9035              :                                                  final_mask, final_len, bias,
    9036              :                                                  vec_array);
    9037              :             }
    9038            0 :           else if (final_mask)
    9039              :             {
    9040              :               /* Emit:
    9041              :                    MASK_STORE_LANES (DATAREF_PTR, ALIAS_PTR, VEC_MASK,
    9042              :                                      VEC_ARRAY).  */
    9043            0 :               unsigned int align = TYPE_ALIGN (TREE_TYPE (vectype));
    9044            0 :               tree alias_ptr = build_int_cst (ref_type, align);
    9045            0 :               call = gimple_build_call_internal (IFN_MASK_STORE_LANES, 4,
    9046              :                                                  dataref_ptr, alias_ptr,
    9047              :                                                  final_mask, vec_array);
    9048              :             }
    9049              :           else
    9050              :             {
    9051              :               /* Emit:
    9052              :                    MEM_REF[...all elements...] = STORE_LANES (VEC_ARRAY).  */
    9053            0 :               data_ref = create_array_ref (aggr_type, dataref_ptr, ref_type);
    9054            0 :               call = gimple_build_call_internal (IFN_STORE_LANES, 1, vec_array);
    9055            0 :               gimple_call_set_lhs (call, data_ref);
    9056              :             }
    9057            0 :           gimple_call_set_nothrow (call, true);
    9058            0 :           vect_finish_stmt_generation (vinfo, stmt_info, call, gsi);
    9059              : 
    9060              :           /* Record that VEC_ARRAY is now dead.  */
    9061            0 :           vect_clobber_variable (vinfo, stmt_info, gsi, vec_array);
    9062              :         }
    9063              : 
    9064            0 :       if (costing_p)
    9065              :         {
    9066            0 :           if (n_adjacent_stores > 0)
    9067            0 :             vect_get_store_cost (vinfo, stmt_info, slp_node, n_adjacent_stores,
    9068              :                                  alignment_support_scheme, misalignment,
    9069              :                                  &inside_cost, cost_vec);
    9070            0 :           if (dump_enabled_p ())
    9071            0 :             dump_printf_loc (MSG_NOTE, vect_location,
    9072              :                              "vect_model_store_cost: inside_cost = %d, "
    9073              :                              "prologue_cost = %d .\n",
    9074              :                              inside_cost, prologue_cost);
    9075              : 
    9076            0 :           SLP_TREE_TYPE (slp_node) = store_vec_info_type;
    9077            0 :           slp_node->data = new vect_load_store_data (std::move (ls));
    9078              :         }
    9079              : 
    9080              :       return true;
    9081              :     }
    9082              : 
    9083      1355918 :   if (mat_gather_scatter_p (memory_access_type))
    9084              :     {
    9085         1445 :       gcc_assert (!grouped_store || ls.ls_type);
    9086         1445 :       if (ls.ls_type)
    9087            0 :         vectype = ls.ls_type;
    9088         1445 :       auto_vec<tree> vec_offsets;
    9089         1445 :       unsigned int inside_cost = 0, prologue_cost = 0;
    9090         1445 :       int num_stmts = vec_num;
    9091         3195 :       for (j = 0; j < num_stmts; j++)
    9092              :         {
    9093         1750 :           gimple *new_stmt;
    9094         1750 :           if (j == 0)
    9095              :             {
    9096         1445 :               if (costing_p && vls_type == VLS_STORE_INVARIANT)
    9097          148 :                 prologue_cost += record_stmt_cost (cost_vec, 1, scalar_to_vec,
    9098              :                                                    slp_node, 0, vect_prologue);
    9099              :               else if (!costing_p)
    9100              :                 {
    9101              :                   /* Since the store is not grouped, DR_GROUP_SIZE is 1, and
    9102              :                      DR_CHAIN is of size 1.  */
    9103          510 :                   gcc_assert (group_size == 1);
    9104          510 :                   vect_get_slp_defs (op_node, gvec_oprnds[0]);
    9105          510 :                   if (mask_node)
    9106           70 :                     vect_get_slp_defs (mask_node, &vec_masks);
    9107              : 
    9108          510 :                   if (STMT_VINFO_GATHER_SCATTER_P (stmt_info))
    9109          510 :                     vect_get_gather_scatter_ops (loop, slp_node,
    9110              :                                                  &dataref_ptr, &vec_offsets);
    9111              :                   else
    9112            0 :                     dataref_ptr
    9113            0 :                       = vect_create_data_ref_ptr (vinfo, first_stmt_info,
    9114              :                                                   aggr_type, NULL, offset,
    9115              :                                                   &dummy, gsi, NULL, false,
    9116              :                                                   dr_increment);
    9117              :                 }
    9118              :             }
    9119          305 :           else if (!costing_p)
    9120              :             {
    9121           59 :               gcc_assert (!LOOP_VINFO_USING_SELECT_VL_P (loop_vinfo));
    9122           59 :               if (!STMT_VINFO_GATHER_SCATTER_P (stmt_info))
    9123            0 :                 dataref_ptr = bump_vector_ptr (vinfo, dataref_ptr,
    9124              :                                                gsi, stmt_info, dr_bump);
    9125              :             }
    9126              : 
    9127         2467 :           new_stmt = NULL;
    9128          717 :           if (!costing_p)
    9129              :             {
    9130          569 :               vec_oprnd = (*gvec_oprnds[0])[j];
    9131          569 :               if (mask_node)
    9132           90 :                 vec_mask = vec_masks[j];
    9133              :               /* We should have caught mismatched types earlier.  */
    9134          569 :               gcc_assert (ls.ls_type
    9135              :                           || useless_type_conversion_p
    9136              :                           (vectype, TREE_TYPE (vec_oprnd)));
    9137              :             }
    9138          569 :           tree final_mask = NULL_TREE;
    9139         2319 :           tree final_len = NULL_TREE;
    9140         2319 :           tree bias = NULL_TREE;
    9141          569 :           if (!costing_p)
    9142              :             {
    9143          569 :               if (masks_p)
    9144            0 :                 final_mask
    9145            0 :                   = vect_get_mask (loop_vinfo, gsi, num_stmts, vectype, j);
    9146          569 :               if (vec_mask)
    9147           90 :                 final_mask = prepare_vec_mask (loop_vinfo, mask_vectype,
    9148              :                                                final_mask, vec_mask, gsi);
    9149              :             }
    9150              : 
    9151         1750 :           unsigned align = get_object_alignment (DR_REF (first_dr_info->dr));
    9152         1750 :           tree alias_align_ptr = build_int_cst (ref_type, align);
    9153         1750 :           if (memory_access_type == VMAT_GATHER_SCATTER_IFN)
    9154              :             {
    9155            0 :               if (costing_p)
    9156              :                 {
    9157            0 :                   if (ls.supported_offset_vectype
    9158            0 :                       && !tree_nop_conversion_p (ls.supported_offset_vectype,
    9159              :                                                  vec_offset))
    9160            0 :                     inside_cost
    9161            0 :                       += record_stmt_cost (cost_vec, 1, vector_stmt,
    9162              :                                            slp_node, 0, vect_body);
    9163            0 :                   if (ls.supported_scale)
    9164            0 :                     inside_cost
    9165            0 :                       += record_stmt_cost (cost_vec, 1, vector_stmt,
    9166              :                                            slp_node, 0, vect_body);
    9167              : 
    9168            0 :                   unsigned int cnunits = vect_nunits_for_cost (vectype);
    9169            0 :                   inside_cost
    9170            0 :                     += record_stmt_cost (cost_vec, cnunits, scalar_store,
    9171              :                                          slp_node, 0, vect_body);
    9172            0 :                   continue;
    9173            0 :                 }
    9174              : 
    9175            0 :               if (STMT_VINFO_GATHER_SCATTER_P (stmt_info))
    9176            0 :                 vec_offset = vec_offsets[j];
    9177              : 
    9178            0 :               tree scale = size_int (SLP_TREE_GS_SCALE (slp_node));
    9179            0 :               bool strided = !VECTOR_TYPE_P (TREE_TYPE (vec_offset));
    9180              : 
    9181              :               /* Perform the offset conversion and scaling if necessary.  */
    9182            0 :               if (!strided
    9183            0 :                   && (ls.supported_offset_vectype || ls.supported_scale))
    9184              :                 {
    9185            0 :                   gimple_seq stmts = NULL;
    9186            0 :                   if (ls.supported_offset_vectype)
    9187            0 :                     vec_offset = gimple_convert
    9188            0 :                       (&stmts, ls.supported_offset_vectype, vec_offset);
    9189            0 :                   if (ls.supported_scale)
    9190              :                     {
    9191              :                       /* Only scale the vec_offset if we haven't already.  */
    9192            0 :                       if (STMT_VINFO_GATHER_SCATTER_P (stmt_info)
    9193            0 :                           || j == 0)
    9194              :                         {
    9195            0 :                           tree mult_cst = build_int_cst
    9196            0 :                             (TREE_TYPE (TREE_TYPE (vec_offset)),
    9197            0 :                              SLP_TREE_GS_SCALE (slp_node) / ls.supported_scale);
    9198            0 :                           tree mult = build_vector_from_val
    9199            0 :                             (TREE_TYPE (vec_offset), mult_cst);
    9200            0 :                           vec_offset = gimple_build
    9201            0 :                             (&stmts, MULT_EXPR, TREE_TYPE (vec_offset),
    9202              :                              vec_offset, mult);
    9203              :                         }
    9204            0 :                       scale = size_int (ls.supported_scale);
    9205              :                     }
    9206            0 :                   gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
    9207              :                 }
    9208              : 
    9209            0 :               if (ls.gs.ifn == IFN_MASK_LEN_SCATTER_STORE)
    9210              :                 {
    9211            0 :                   if (lens_p)
    9212            0 :                     final_len = vect_get_len (loop_vinfo, gsi, num_stmts,
    9213              :                                               vectype, j, 1, true);
    9214              :                   else
    9215            0 :                     final_len = size_int (TYPE_VECTOR_SUBPARTS (vectype));
    9216              : 
    9217            0 :                   signed char biasval
    9218            0 :                     = LOOP_VINFO_PARTIAL_LOAD_STORE_BIAS (loop_vinfo);
    9219            0 :                   bias = build_int_cst (intQI_type_node, biasval);
    9220            0 :                   if (!final_mask)
    9221              :                     {
    9222            0 :                       mask_vectype = truth_type_for (vectype);
    9223            0 :                       final_mask = build_minus_one_cst (mask_vectype);
    9224              :                     }
    9225              :                 }
    9226              : 
    9227            0 :               if (ls.ls_type)
    9228              :                 {
    9229            0 :                   gimple *conv_stmt
    9230            0 :                     = gimple_build_assign (make_ssa_name (vectype),
    9231              :                                            VIEW_CONVERT_EXPR,
    9232              :                                            build1 (VIEW_CONVERT_EXPR, vectype,
    9233              :                                                    vec_oprnd));
    9234            0 :                   vect_finish_stmt_generation (vinfo, stmt_info, conv_stmt,
    9235              :                                                gsi);
    9236            0 :                   vec_oprnd = gimple_get_lhs (conv_stmt);
    9237              :                 }
    9238              : 
    9239            0 :               gcall *call;
    9240            0 :               if (final_len && final_mask)
    9241              :                 {
    9242            0 :                   if (VECTOR_TYPE_P (TREE_TYPE (vec_offset)))
    9243            0 :                     call = gimple_build_call_internal (
    9244              :                             IFN_MASK_LEN_SCATTER_STORE, 8, dataref_ptr,
    9245              :                             alias_align_ptr,
    9246              :                             vec_offset, scale, vec_oprnd, final_mask, final_len,
    9247              :                             bias);
    9248              :                   else
    9249              :                     /* Non-vector offset indicates that prefer to take
    9250              :                        MASK_LEN_STRIDED_STORE instead of the
    9251              :                        IFN_MASK_SCATTER_STORE with direct stride arg.
    9252              :                        Similar to the gather case we have checked the
    9253              :                        alignment for a scatter already and assume
    9254              :                        that the strided store has the same requirements.  */
    9255            0 :                     call = gimple_build_call_internal (
    9256              :                             IFN_MASK_LEN_STRIDED_STORE, 6, dataref_ptr,
    9257              :                             vec_offset, vec_oprnd, final_mask, final_len, bias);
    9258              :                 }
    9259            0 :               else if (final_mask)
    9260            0 :                 call = gimple_build_call_internal
    9261            0 :                              (IFN_MASK_SCATTER_STORE, 6, dataref_ptr,
    9262              :                               alias_align_ptr,
    9263              :                               vec_offset, scale, vec_oprnd, final_mask);
    9264              :               else
    9265            0 :                 call = gimple_build_call_internal (IFN_SCATTER_STORE, 5,
    9266              :                                                    dataref_ptr,
    9267              :                                                    alias_align_ptr,
    9268              :                                                    vec_offset,
    9269              :                                                    scale, vec_oprnd);
    9270            0 :               gimple_call_set_nothrow (call, true);
    9271            0 :               vect_finish_stmt_generation (vinfo, stmt_info, call, gsi);
    9272            0 :               new_stmt = call;
    9273              :             }
    9274         1750 :           else if (memory_access_type == VMAT_GATHER_SCATTER_LEGACY)
    9275              :             {
    9276              :               /* The builtin decls path for scatter is legacy, x86 only.  */
    9277          331 :               gcc_assert (nunits.is_constant ()
    9278              :                           && (!final_mask
    9279              :                               || SCALAR_INT_MODE_P
    9280              :                                    (TYPE_MODE (TREE_TYPE (final_mask)))));
    9281          331 :               if (costing_p)
    9282              :                 {
    9283          200 :                   unsigned int cnunits = vect_nunits_for_cost (vectype);
    9284          200 :                   inside_cost
    9285          200 :                     += record_stmt_cost (cost_vec, cnunits, scalar_store,
    9286              :                                          slp_node, 0, vect_body);
    9287          200 :                   continue;
    9288          200 :                 }
    9289              : 
    9290          131 :                 tree offset_vectype = TREE_TYPE (vec_offsets[0]);
    9291          131 :                 poly_uint64 offset_nunits
    9292          131 :                   = TYPE_VECTOR_SUBPARTS (offset_vectype);
    9293          131 :                 if (known_eq (nunits, offset_nunits))
    9294              :                   {
    9295           55 :                     new_stmt = vect_build_one_scatter_store_call
    9296          110 :                                    (vinfo, stmt_info, slp_node, gsi,
    9297           55 :                                     ls.gs.decl, dataref_ptr, vec_offsets[j],
    9298              :                                     vec_oprnd, final_mask);
    9299           55 :                     vect_finish_stmt_generation (vinfo, stmt_info,
    9300              :                                                  new_stmt, gsi);
    9301              :                   }
    9302           76 :                 else if (known_eq (nunits, offset_nunits * 2))
    9303              :                   {
    9304              :                     /* We have a offset vector with half the number of
    9305              :                        lanes but the builtins will store full vectype
    9306              :                        data from the lower lanes.  */
    9307           30 :                     new_stmt = vect_build_one_scatter_store_call
    9308           60 :                                    (vinfo, stmt_info, slp_node, gsi, ls.gs.decl,
    9309           30 :                                     dataref_ptr, vec_offsets[2 * j],
    9310              :                                     vec_oprnd, final_mask);
    9311           30 :                     vect_finish_stmt_generation (vinfo, stmt_info,
    9312              :                                                    new_stmt, gsi);
    9313           30 :                     int count = nunits.to_constant ();
    9314           30 :                     vec_perm_builder sel (count, count, 1);
    9315           30 :                     sel.quick_grow (count);
    9316          412 :                     for (int i = 0; i < count; ++i)
    9317          352 :                       sel[i] = i | (count / 2);
    9318           30 :                     vec_perm_indices indices (sel, 2, count);
    9319           30 :                     tree perm_mask
    9320           30 :                       = vect_gen_perm_mask_checked (vectype, indices);
    9321           30 :                     new_stmt = gimple_build_assign (NULL_TREE, VEC_PERM_EXPR,
    9322              :                                                     vec_oprnd, vec_oprnd,
    9323              :                                                     perm_mask);
    9324           30 :                     vec_oprnd = make_ssa_name (vectype);
    9325           30 :                     gimple_set_lhs (new_stmt, vec_oprnd);
    9326           30 :                     vect_finish_stmt_generation (vinfo, stmt_info,
    9327              :                                                  new_stmt, gsi);
    9328           30 :                     if (final_mask)
    9329              :                       {
    9330           20 :                         new_stmt = gimple_build_assign (NULL_TREE,
    9331              :                                                         VEC_UNPACK_HI_EXPR,
    9332              :                                                         final_mask);
    9333           20 :                         final_mask = make_ssa_name
    9334           20 :                                       (truth_type_for (offset_vectype));
    9335           20 :                         gimple_set_lhs (new_stmt, final_mask);
    9336           20 :                         vect_finish_stmt_generation (vinfo, stmt_info,
    9337              :                                                      new_stmt, gsi);
    9338              :                         }
    9339              : 
    9340           30 :                     new_stmt = vect_build_one_scatter_store_call
    9341           60 :                                   (vinfo, stmt_info, slp_node, gsi, ls.gs.decl,
    9342           30 :                                    dataref_ptr, vec_offsets[2 * j + 1],
    9343              :                                    vec_oprnd, final_mask);
    9344           30 :                     vect_finish_stmt_generation (vinfo, stmt_info,
    9345              :                                                  new_stmt, gsi);
    9346           30 :                   }
    9347           46 :                 else if (known_eq (nunits * 2, offset_nunits))
    9348              :                   {
    9349              :                     /* We have a offset vector with double the number of
    9350              :                        lanes.  Select the low/high part accordingly.  */
    9351           46 :                     vec_offset = vec_offsets[j / 2];
    9352           46 :                     if (j & 1)
    9353              :                       {
    9354           23 :                         int count = offset_nunits.to_constant ();
    9355           23 :                         vec_perm_builder sel (count, count, 1);
    9356           23 :                         sel.quick_grow (count);
    9357          286 :                         for (int i = 0; i < count; ++i)
    9358          240 :                           sel[i] = i | (count / 2);
    9359           23 :                         vec_perm_indices indices (sel, 2, count);
    9360           23 :                         tree perm_mask = vect_gen_perm_mask_checked
    9361           23 :                                            (TREE_TYPE (vec_offset), indices);
    9362           23 :                         new_stmt = gimple_build_assign (NULL_TREE,
    9363              :                                                         VEC_PERM_EXPR,
    9364              :                                                         vec_offset,
    9365              :                                                         vec_offset,
    9366              :                                                         perm_mask);
    9367           23 :                         vec_offset = make_ssa_name (TREE_TYPE (vec_offset));
    9368           23 :                         gimple_set_lhs (new_stmt, vec_offset);
    9369           23 :                         vect_finish_stmt_generation (vinfo, stmt_info,
    9370              :                                                      new_stmt, gsi);
    9371           23 :                       }
    9372              : 
    9373           46 :                     new_stmt = vect_build_one_scatter_store_call
    9374           46 :                                    (vinfo, stmt_info, slp_node, gsi,
    9375              :                                     ls.gs.decl, dataref_ptr, vec_offset,
    9376              :                                     vec_oprnd, final_mask);
    9377           46 :                     vect_finish_stmt_generation (vinfo, stmt_info,
    9378              :                                                  new_stmt, gsi);
    9379              :                   }
    9380              :                 else
    9381            0 :                   gcc_unreachable ();
    9382              :             }
    9383              :           else
    9384              :             {
    9385              :               /* Emulated scatter.  */
    9386         1419 :               gcc_assert (!final_mask);
    9387         1419 :               if (costing_p)
    9388              :                 {
    9389          981 :                   unsigned int cnunits = vect_nunits_for_cost (vectype);
    9390              :                   /* For emulated scatter N offset vector element extracts
    9391              :                      (we assume the scalar scaling and ptr + offset add is
    9392              :                      consumed by the load).  */
    9393          981 :                   inside_cost
    9394          981 :                     += record_stmt_cost (cost_vec, 1, vec_deconstruct,
    9395              :                                          slp_node, 0, vect_body);
    9396              :                   /* N scalar stores plus extracting the elements.  */
    9397          981 :                   inside_cost
    9398          981 :                     += record_stmt_cost (cost_vec, 1, vec_deconstruct,
    9399              :                                          slp_node, 0, vect_body);
    9400          981 :                   inside_cost
    9401          981 :                     += record_stmt_cost (cost_vec, cnunits, scalar_store,
    9402              :                                          slp_node, 0, vect_body);
    9403          981 :                   continue;
    9404          981 :                 }
    9405              : 
    9406          438 :               tree offset_vectype = TREE_TYPE (vec_offsets[0]);
    9407          438 :               unsigned HOST_WIDE_INT const_nunits = nunits.to_constant ();
    9408          438 :               unsigned HOST_WIDE_INT const_offset_nunits
    9409          438 :                 = TYPE_VECTOR_SUBPARTS (offset_vectype).to_constant ();
    9410          438 :               vec<constructor_elt, va_gc> *ctor_elts;
    9411          438 :               vec_alloc (ctor_elts, const_nunits);
    9412          438 :               gimple_seq stmts = NULL;
    9413          438 :               tree elt_type = TREE_TYPE (vectype);
    9414          438 :               unsigned HOST_WIDE_INT elt_size
    9415          438 :                 = tree_to_uhwi (TYPE_SIZE (elt_type));
    9416              :               /* We support offset vectors with more elements
    9417              :                  than the data vector for now.  */
    9418          438 :               unsigned HOST_WIDE_INT factor
    9419              :                 = const_offset_nunits / const_nunits;
    9420          438 :               vec_offset = vec_offsets[j / factor];
    9421          438 :               unsigned elt_offset
    9422          438 :                 = (j % factor) * const_nunits;
    9423          438 :               tree idx_type = TREE_TYPE (TREE_TYPE (vec_offset));
    9424          438 :               tree scale = size_int (SLP_TREE_GS_SCALE (slp_node));
    9425          438 :               tree ltype = build_aligned_type (TREE_TYPE (vectype), align);
    9426         2226 :               for (unsigned k = 0; k < const_nunits; ++k)
    9427              :                 {
    9428              :                   /* Compute the offsetted pointer.  */
    9429         1350 :                   tree boff = size_binop (MULT_EXPR, TYPE_SIZE (idx_type),
    9430              :                                           bitsize_int (k + elt_offset));
    9431         1350 :                   tree idx
    9432         2700 :                     = gimple_build (&stmts, BIT_FIELD_REF, idx_type,
    9433         1350 :                                     vec_offset, TYPE_SIZE (idx_type), boff);
    9434         1350 :                   idx = gimple_convert (&stmts, sizetype, idx);
    9435         1350 :                   idx = gimple_build (&stmts, MULT_EXPR, sizetype,
    9436              :                                       idx, scale);
    9437         1350 :                   tree ptr
    9438         1350 :                     = gimple_build (&stmts, PLUS_EXPR,
    9439         1350 :                                     TREE_TYPE (dataref_ptr),
    9440              :                                     dataref_ptr, idx);
    9441         1350 :                   ptr = gimple_convert (&stmts, ptr_type_node, ptr);
    9442              :                   /* Extract the element to be stored.  */
    9443         1350 :                   tree elt
    9444         2700 :                     = gimple_build (&stmts, BIT_FIELD_REF,
    9445         1350 :                                     TREE_TYPE (vectype),
    9446         1350 :                                     vec_oprnd, TYPE_SIZE (elt_type),
    9447         1350 :                                     bitsize_int (k * elt_size));
    9448         1350 :                   gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
    9449         1350 :                   stmts = NULL;
    9450         1350 :                   tree ref
    9451         1350 :                     = build2 (MEM_REF, ltype, ptr,
    9452              :                               build_int_cst (ref_type, 0));
    9453         1350 :                   new_stmt = gimple_build_assign (ref, elt);
    9454         1350 :                   vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    9455              :                 }
    9456              : 
    9457          438 :               slp_node->push_vec_def (new_stmt);
    9458              :             }
    9459              :         }
    9460              : 
    9461         1445 :       if (costing_p)
    9462              :         {
    9463          935 :           if (dump_enabled_p ())
    9464           78 :             dump_printf_loc (MSG_NOTE, vect_location,
    9465              :                              "vect_model_store_cost: inside_cost = %d, "
    9466              :                              "prologue_cost = %d .\n",
    9467              :                              inside_cost, prologue_cost);
    9468          935 :           SLP_TREE_TYPE (slp_node) = store_vec_info_type;
    9469          935 :           slp_node->data = new vect_load_store_data (std::move (ls));
    9470              :         }
    9471              : 
    9472         1445 :       return true;
    9473         1445 :     }
    9474              : 
    9475      1354473 :   gcc_assert (memory_access_type == VMAT_CONTIGUOUS
    9476              :               || memory_access_type == VMAT_CONTIGUOUS_DOWN
    9477              :               || memory_access_type == VMAT_CONTIGUOUS_REVERSE);
    9478              : 
    9479      1354473 :   unsigned inside_cost = 0, prologue_cost = 0;
    9480              :   /* For costing some adjacent vector stores, we'd like to cost with
    9481              :      the total number of them once instead of cost each one by one. */
    9482      1354473 :   unsigned int n_adjacent_stores = 0;
    9483      1354473 :   auto_vec<tree> result_chain (group_size);
    9484      1354473 :   auto_vec<tree, 1> vec_oprnds;
    9485      1354473 :   gimple *new_stmt;
    9486      1354473 :   if (!costing_p)
    9487              :     {
    9488              :       /* Get vectorized arguments for SLP_NODE.  */
    9489       550289 :       vect_get_slp_defs (op_node, &vec_oprnds);
    9490       550289 :       vec_oprnd = vec_oprnds[0];
    9491       550289 :       if (mask_node)
    9492              :         {
    9493          484 :           vect_get_slp_defs (mask_node, &vec_masks);
    9494          484 :           vec_mask = vec_masks[0];
    9495              :         }
    9496              :     }
    9497              : 
    9498              :   /* We should have caught mismatched types earlier.  */
    9499       550289 :   gcc_assert (costing_p
    9500              :               || useless_type_conversion_p (vectype, TREE_TYPE (vec_oprnd)));
    9501      1354473 :   bool simd_lane_access_p
    9502      1354473 :       = STMT_VINFO_SIMD_LANE_ACCESS_P (stmt_info) != 0;
    9503      1354473 :   if (!costing_p
    9504      1354473 :       && simd_lane_access_p
    9505         5120 :       && !masks_p
    9506         5120 :       && TREE_CODE (DR_BASE_ADDRESS (first_dr_info->dr)) == ADDR_EXPR
    9507         5120 :       && VAR_P (TREE_OPERAND (DR_BASE_ADDRESS (first_dr_info->dr), 0))
    9508         5120 :       && integer_zerop (get_dr_vinfo_offset (vinfo, first_dr_info))
    9509         5120 :       && integer_zerop (DR_INIT (first_dr_info->dr))
    9510      1359593 :       && alias_sets_conflict_p (get_alias_set (aggr_type),
    9511         5120 :                                 get_alias_set (TREE_TYPE (ref_type))))
    9512              :     {
    9513         5112 :       dataref_ptr = unshare_expr (DR_BASE_ADDRESS (first_dr_info->dr));
    9514         5112 :       dataref_offset = build_int_cst (ref_type, 0);
    9515              :     }
    9516      1349361 :   else if (!costing_p)
    9517      1090346 :     dataref_ptr = vect_create_data_ref_ptr (vinfo, first_stmt_info, aggr_type,
    9518              :                                             simd_lane_access_p ? loop : NULL,
    9519              :                                             offset, &dummy, gsi, NULL,
    9520              :                                             simd_lane_access_p, dr_increment);
    9521              : 
    9522      1354473 :   new_stmt = NULL;
    9523      1354473 :   gcc_assert (!grouped_store);
    9524      3014410 :   for (i = 0; i < vec_num; i++)
    9525              :     {
    9526      1659937 :       if (!costing_p)
    9527       683889 :         vec_oprnd = vec_oprnds[i];
    9528              : 
    9529      1659937 :       if (memory_access_type == VMAT_CONTIGUOUS_REVERSE)
    9530              :         {
    9531         3524 :           if (costing_p)
    9532              :             {
    9533         2330 :               tree perm_mask = perm_mask_for_reverse (vectype);
    9534         2330 :               ls.perms.safe_push ({perm_mask, 1, 1});
    9535         2330 :               inside_cost += record_stmt_cost (cost_vec, 1, vec_perm,
    9536              :                                                slp_node, 0, vect_body);
    9537              :             }
    9538              :           else
    9539              :             {
    9540         1194 :               tree new_temp = make_ssa_name (vectype);
    9541              : 
    9542              :               /* Generate the permute statement.  */
    9543         1194 :               gimple *perm_stmt
    9544         2388 :                 = gimple_build_assign (new_temp, VEC_PERM_EXPR, vec_oprnd,
    9545         1194 :                                        vec_oprnd, ls.perms.last ().mask);
    9546         1194 :               vect_finish_stmt_generation (vinfo, stmt_info, perm_stmt, gsi);
    9547              : 
    9548         1194 :               perm_stmt = SSA_NAME_DEF_STMT (new_temp);
    9549      1659937 :               vec_oprnd = new_temp;
    9550              :             }
    9551              :         }
    9552              : 
    9553      1659937 :       if (costing_p)
    9554              :         {
    9555       976048 :           n_adjacent_stores++;
    9556       976048 :           continue;
    9557              :         }
    9558              : 
    9559       683889 :       tree final_mask = NULL_TREE;
    9560       683889 :       tree final_len = NULL_TREE;
    9561       683889 :       tree bias = NULL_TREE;
    9562       683889 :       if (masks_p)
    9563           83 :         final_mask = vect_get_mask (loop_vinfo, gsi, vec_num, vectype, i);
    9564       683889 :       if (vec_mask)
    9565          706 :         vec_mask = vec_masks[i];
    9566          706 :       if (vec_mask)
    9567          706 :         final_mask = prepare_vec_mask (loop_vinfo, mask_vectype, final_mask,
    9568              :                                        vec_mask, gsi);
    9569              : 
    9570       683889 :       if (i > 0)
    9571              :         /* Bump the vector pointer.  */
    9572       133600 :         dataref_ptr = bump_vector_ptr (vinfo, dataref_ptr, gsi, stmt_info,
    9573              :                                        dr_bump);
    9574              : 
    9575       683889 :       unsigned misalign;
    9576       683889 :       unsigned HOST_WIDE_INT align;
    9577       683889 :       align = known_alignment (DR_TARGET_ALIGNMENT (first_dr_info));
    9578       683889 :       if (alignment_support_scheme == dr_aligned)
    9579              :         misalign = 0;
    9580       311713 :       else if (misalignment == DR_MISALIGNMENT_UNKNOWN)
    9581              :         {
    9582       163946 :           align = dr_alignment (vect_dr_behavior (vinfo, first_dr_info));
    9583       163946 :           misalign = 0;
    9584              :         }
    9585              :       else
    9586       147767 :         misalign = misalignment;
    9587       683889 :       if (dataref_offset == NULL_TREE
    9588       677704 :           && TREE_CODE (dataref_ptr) == SSA_NAME)
    9589       190997 :         set_ssa_name_alignment (dataref_ptr, align, misalign);
    9590       683889 :       align = least_bit_hwi (misalign | align);
    9591              : 
    9592              :       /* Compute IFN when LEN_LOOP_P or final_mask valid.  */
    9593       683889 :       machine_mode vmode = TYPE_MODE (vectype);
    9594       683889 :       machine_mode new_vmode = vmode;
    9595       683889 :       internal_fn partial_ifn = IFN_LAST;
    9596       683889 :       if (lens_p)
    9597              :         {
    9598            0 :           opt_machine_mode new_ovmode
    9599            0 :             = get_len_load_store_mode (vmode, false, &partial_ifn);
    9600            0 :           new_vmode = new_ovmode.require ();
    9601            0 :           unsigned factor
    9602            0 :             = (new_ovmode == vmode) ? 1 : GET_MODE_UNIT_SIZE (vmode);
    9603            0 :           final_len
    9604            0 :             = vect_get_len (loop_vinfo, gsi, vec_num, vectype, i, factor, true);
    9605              :         }
    9606       683889 :       else if (final_mask)
    9607              :         {
    9608          722 :           if (!can_vec_mask_load_store_p (vmode,
    9609          722 :                                           TYPE_MODE (TREE_TYPE (final_mask)),
    9610              :                                           false, &partial_ifn))
    9611            0 :             gcc_unreachable ();
    9612              :         }
    9613              : 
    9614       683889 :       if (partial_ifn == IFN_MASK_LEN_STORE)
    9615              :         {
    9616            0 :           if (!final_len)
    9617              :             {
    9618              :               /* Pass VF value to 'len' argument of
    9619              :                  MASK_LEN_STORE if lens_p is false.  */
    9620            0 :               final_len = size_int (TYPE_VECTOR_SUBPARTS (vectype));
    9621              :             }
    9622            0 :           if (!final_mask)
    9623              :             {
    9624              :               /* Pass all ones value to 'mask' argument of
    9625              :                  MASK_LEN_STORE if final_mask is invalid.  */
    9626            0 :               mask_vectype = truth_type_for (vectype);
    9627            0 :               final_mask = build_minus_one_cst (mask_vectype);
    9628              :             }
    9629              :         }
    9630       683889 :       if (final_len)
    9631              :         {
    9632            0 :           signed char biasval = LOOP_VINFO_PARTIAL_LOAD_STORE_BIAS (loop_vinfo);
    9633            0 :           bias = build_int_cst (intQI_type_node, biasval);
    9634              :         }
    9635              : 
    9636              :       /* Arguments are ready.  Create the new vector stmt.  */
    9637            0 :       if (final_len)
    9638              :         {
    9639            0 :           gcall *call;
    9640            0 :           tree ptr = build_int_cst (ref_type, align * BITS_PER_UNIT);
    9641              :           /* Need conversion if it's wrapped with VnQI.  */
    9642            0 :           if (vmode != new_vmode)
    9643              :             {
    9644            0 :               tree new_vtype
    9645            0 :                 = build_vector_type_for_mode (unsigned_intQI_type_node,
    9646              :                                               new_vmode);
    9647            0 :               tree var = vect_get_new_ssa_name (new_vtype, vect_simple_var);
    9648            0 :               vec_oprnd = build1 (VIEW_CONVERT_EXPR, new_vtype, vec_oprnd);
    9649            0 :               gassign *new_stmt
    9650            0 :                 = gimple_build_assign (var, VIEW_CONVERT_EXPR, vec_oprnd);
    9651            0 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    9652            0 :               vec_oprnd = var;
    9653              :             }
    9654              : 
    9655            0 :           if (partial_ifn == IFN_MASK_LEN_STORE)
    9656            0 :             call = gimple_build_call_internal (IFN_MASK_LEN_STORE, 6,
    9657              :                                                dataref_ptr, ptr, final_mask,
    9658              :                                                final_len, bias, vec_oprnd);
    9659              :           else
    9660            0 :             call = gimple_build_call_internal (IFN_LEN_STORE, 5,
    9661              :                                                dataref_ptr, ptr, final_len,
    9662              :                                                bias, vec_oprnd);
    9663            0 :           gimple_call_set_nothrow (call, true);
    9664            0 :           vect_finish_stmt_generation (vinfo, stmt_info, call, gsi);
    9665            0 :           new_stmt = call;
    9666              :         }
    9667       683889 :       else if (final_mask)
    9668              :         {
    9669          722 :           tree ptr = build_int_cst (ref_type, align * BITS_PER_UNIT);
    9670          722 :           gcall *call
    9671          722 :             = gimple_build_call_internal (IFN_MASK_STORE, 4, dataref_ptr,
    9672              :                                           ptr, final_mask, vec_oprnd);
    9673          722 :           gimple_call_set_nothrow (call, true);
    9674          722 :           vect_finish_stmt_generation (vinfo, stmt_info, call, gsi);
    9675          722 :           new_stmt = call;
    9676              :         }
    9677              :       else
    9678              :         {
    9679       683167 :           data_ref = fold_build2 (MEM_REF, vectype, dataref_ptr,
    9680              :                                   dataref_offset ? dataref_offset
    9681              :                                   : build_int_cst (ref_type, 0));
    9682       683167 :           if (alignment_support_scheme == dr_aligned
    9683       683167 :               && align >= TYPE_ALIGN_UNIT (vectype))
    9684              :             ;
    9685              :           else
    9686       311152 :             TREE_TYPE (data_ref)
    9687       622304 :               = build_aligned_type (TREE_TYPE (data_ref),
    9688              :                                     align * BITS_PER_UNIT);
    9689       683167 :           vect_copy_ref_info (data_ref, first_stmt_info);
    9690       683167 :           new_stmt = gimple_build_assign (data_ref, vec_oprnd);
    9691       683167 :           vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
    9692              :         }
    9693              :     }
    9694              : 
    9695      1354473 :   if (costing_p)
    9696              :     {
    9697       804184 :       if (n_adjacent_stores > 0)
    9698       804184 :         vect_get_store_cost (vinfo, stmt_info, slp_node, n_adjacent_stores,
    9699              :                              alignment_support_scheme, misalignment,
    9700              :                              &inside_cost, cost_vec);
    9701              : 
    9702              :       /* When vectorizing a store into the function result assign
    9703              :          a penalty if the function returns in a multi-register location.
    9704              :          In this case we assume we'll end up with having to spill the
    9705              :          vector result and do piecewise loads as a conservative estimate.  */
    9706       804184 :       tree base = get_base_address (STMT_VINFO_DATA_REF (stmt_info)->ref);
    9707       804184 :       if (base
    9708       804184 :           && (TREE_CODE (base) == RESULT_DECL
    9709       755602 :               || (DECL_P (base) && cfun_returns (base)))
    9710       864532 :           && !aggregate_value_p (base, cfun->decl))
    9711              :         {
    9712        11195 :           rtx reg = hard_function_value (TREE_TYPE (base), cfun->decl, 0, 1);
    9713              :           /* ???  Handle PARALLEL in some way.  */
    9714        11195 :           if (REG_P (reg))
    9715              :             {
    9716        10985 :               int nregs = hard_regno_nregs (REGNO (reg), GET_MODE (reg));
    9717              :               /* Assume that a single reg-reg move is possible and cheap,
    9718              :                  do not account for vector to gp register move cost.  */
    9719        10985 :               if (nregs > 1)
    9720              :                 {
    9721              :                   /* Spill.  */
    9722        10128 :                   prologue_cost
    9723        10128 :                     += record_stmt_cost (cost_vec, 1, vector_store,
    9724              :                                          slp_node, 0, vect_epilogue);
    9725              :                   /* Loads.  */
    9726        10128 :                   prologue_cost
    9727        10128 :                     += record_stmt_cost (cost_vec, nregs, scalar_load,
    9728              :                                          slp_node, 0, vect_epilogue);
    9729              :                 }
    9730              :             }
    9731              :         }
    9732       804184 :       if (dump_enabled_p ())
    9733        14920 :         dump_printf_loc (MSG_NOTE, vect_location,
    9734              :                          "vect_model_store_cost: inside_cost = %d, "
    9735              :                          "prologue_cost = %d .\n",
    9736              :                          inside_cost, prologue_cost);
    9737              : 
    9738       804184 :       SLP_TREE_TYPE (slp_node) = store_vec_info_type;
    9739       804184 :       slp_node->data = new vect_load_store_data (std::move (ls));
    9740              :     }
    9741              : 
    9742      1354473 :   return true;
    9743      1387884 : }
    9744              : 
    9745              : /* Given a vector type VECTYPE, turns permutation SEL into the equivalent
    9746              :    VECTOR_CST mask.  No checks are made that the target platform supports the
    9747              :    mask, so callers may wish to test can_vec_perm_const_p separately, or use
    9748              :    vect_gen_perm_mask_checked.  */
    9749              : 
    9750              : tree
    9751       223201 : vect_gen_perm_mask_any (tree vectype, const vec_perm_indices &sel)
    9752              : {
    9753       223201 :   tree mask_type;
    9754              : 
    9755       223201 :   poly_uint64 nunits = sel.length ();
    9756       223201 :   gcc_assert (known_eq (nunits, TYPE_VECTOR_SUBPARTS (vectype)));
    9757              : 
    9758       223201 :   mask_type = build_vector_type (ssizetype, nunits);
    9759       223201 :   return vec_perm_indices_to_tree (mask_type, sel);
    9760              : }
    9761              : 
    9762              : /* Checked version of vect_gen_perm_mask_any.  Asserts can_vec_perm_const_p,
    9763              :    i.e. that the target supports the pattern _for arbitrary input vectors_.  */
    9764              : 
    9765              : tree
    9766        87695 : vect_gen_perm_mask_checked (tree vectype, const vec_perm_indices &sel)
    9767              : {
    9768        87695 :   machine_mode vmode = TYPE_MODE (vectype);
    9769        87695 :   gcc_assert (can_vec_perm_const_p (vmode, vmode, sel));
    9770        87695 :   return vect_gen_perm_mask_any (vectype, sel);
    9771              : }
    9772              : 
    9773              : /* Given a vector variable X and Y, that was generated for the scalar
    9774              :    STMT_INFO, generate instructions to permute the vector elements of X and Y
    9775              :    using permutation mask MASK_VEC, insert them at *GSI and return the
    9776              :    permuted vector variable.  */
    9777              : 
    9778              : static tree
    9779         1594 : permute_vec_elements (vec_info *vinfo,
    9780              :                       tree x, tree y, tree mask_vec, stmt_vec_info stmt_info,
    9781              :                       gimple_stmt_iterator *gsi)
    9782              : {
    9783         1594 :   tree vectype = TREE_TYPE (x);
    9784         1594 :   tree perm_dest, data_ref;
    9785         1594 :   gimple *perm_stmt;
    9786              : 
    9787         1594 :   tree scalar_dest = gimple_get_lhs (stmt_info->stmt);
    9788         1594 :   if (scalar_dest && TREE_CODE (scalar_dest) == SSA_NAME)
    9789         1594 :     perm_dest = vect_create_destination_var (scalar_dest, vectype);
    9790              :   else
    9791            0 :     perm_dest = vect_get_new_vect_var (vectype, vect_simple_var, NULL);
    9792         1594 :   data_ref = make_ssa_name (perm_dest);
    9793              : 
    9794              :   /* Generate the permute statement.  */
    9795         1594 :   perm_stmt = gimple_build_assign (data_ref, VEC_PERM_EXPR, x, y, mask_vec);
    9796         1594 :   vect_finish_stmt_generation (vinfo, stmt_info, perm_stmt, gsi);
    9797              : 
    9798         1594 :   return data_ref;
    9799              : }
    9800              : 
    9801              : /* Hoist the definitions of all SSA uses on STMT_INFO out of the loop LOOP,
    9802              :    inserting them on the loops preheader edge.  Returns true if we
    9803              :    were successful in doing so (and thus STMT_INFO can be moved then),
    9804              :    otherwise returns false.  HOIST_P indicates if we want to hoist the
    9805              :    definitions of all SSA uses, it would be false when we are costing.  */
    9806              : 
    9807              : static bool
    9808         4176 : hoist_defs_of_uses (gimple *stmt, class loop *loop, bool hoist_p)
    9809              : {
    9810         4176 :   ssa_op_iter i;
    9811         4176 :   use_operand_p use_p;
    9812         4176 :   auto_vec<use_operand_p, 8> to_hoist;
    9813              : 
    9814         7950 :   FOR_EACH_SSA_USE_OPERAND (use_p, stmt, i, SSA_OP_USE)
    9815              :     {
    9816         3804 :       gimple *def_stmt = SSA_NAME_DEF_STMT (USE_FROM_PTR (use_p));
    9817         3804 :       if (!gimple_nop_p (def_stmt)
    9818         3804 :           && flow_bb_inside_loop_p (loop, gimple_bb (def_stmt)))
    9819              :         {
    9820              :           /* Make sure we don't need to recurse.  While we could do
    9821              :              so in simple cases when there are more complex use webs
    9822              :              we don't have an easy way to preserve stmt order to fulfil
    9823              :              dependencies within them.  */
    9824           87 :           tree op2;
    9825           87 :           ssa_op_iter i2;
    9826           87 :           if (gimple_code (def_stmt) == GIMPLE_PHI
    9827           87 :               || (single_ssa_def_operand (def_stmt, SSA_OP_DEF)
    9828              :                   == NULL_DEF_OPERAND_P))
    9829           30 :             return false;
    9830          176 :           FOR_EACH_SSA_TREE_OPERAND (op2, def_stmt, i2, SSA_OP_USE)
    9831              :             {
    9832          119 :               gimple *def_stmt2 = SSA_NAME_DEF_STMT (op2);
    9833          119 :               if (!gimple_nop_p (def_stmt2)
    9834          119 :                   && flow_bb_inside_loop_p (loop, gimple_bb (def_stmt2)))
    9835              :                 return false;
    9836              :             }
    9837           57 :           to_hoist.safe_push (use_p);
    9838              :         }
    9839              :     }
    9840              : 
    9841         8322 :   if (to_hoist.is_empty ())
    9842              :     return true;
    9843              : 
    9844           33 :   if (!hoist_p)
    9845              :     return true;
    9846              : 
    9847              :   /* Instead of moving defs we copy them so we can zero their UID to not
    9848              :      confuse dominance queries in the preheader.  */
    9849            3 :   gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
    9850           12 :   for (use_operand_p use_p : to_hoist)
    9851              :     {
    9852            3 :       gimple *def_stmt = SSA_NAME_DEF_STMT (USE_FROM_PTR (use_p));
    9853            3 :       gimple *copy = gimple_copy (def_stmt);
    9854            3 :       assign_discriminators_to_stmt
    9855            3 :         (copy, 0, allocate_copyid_base (gimple_location (copy), 1));
    9856            3 :       gimple_set_uid (copy, 0);
    9857            3 :       def_operand_p def_p = single_ssa_def_operand (def_stmt, SSA_OP_DEF);
    9858            3 :       tree new_def = duplicate_ssa_name (DEF_FROM_PTR (def_p), copy);
    9859            3 :       update_stmt (copy);
    9860            3 :       def_p = single_ssa_def_operand (copy, SSA_OP_DEF);
    9861            3 :       SET_DEF (def_p, new_def);
    9862            3 :       SET_USE (use_p, new_def);
    9863            3 :       gsi_insert_before (&gsi, copy, GSI_SAME_STMT);
    9864              :     }
    9865              : 
    9866              :   return true;
    9867         4176 : }
    9868              : 
    9869              : /* vectorizable_load.
    9870              : 
    9871              :    Check if STMT_INFO reads a non scalar data-ref (array/pointer/structure)
    9872              :    that can be vectorized.
    9873              :    If COST_VEC is passed, calculate costs but don't change anything,
    9874              :    otherwise, vectorize STMT_INFO: create a vectorized stmt to replace
    9875              :    it, and insert it at GSI.
    9876              :    Return true if STMT_INFO is vectorizable in this way.  */
    9877              : 
    9878              : static bool
    9879      2240169 : vectorizable_load (vec_info *vinfo,
    9880              :                    stmt_vec_info stmt_info, gimple_stmt_iterator *gsi,
    9881              :                    slp_tree slp_node,
    9882              :                    stmt_vector_for_cost *cost_vec)
    9883              : {
    9884      2240169 :   tree scalar_dest;
    9885      2240169 :   tree vec_dest = NULL;
    9886      2240169 :   tree data_ref = NULL;
    9887      2240169 :   loop_vec_info loop_vinfo = dyn_cast <loop_vec_info> (vinfo);
    9888      2240169 :   class loop *loop = NULL;
    9889      2240169 :   class loop *containing_loop = gimple_bb (stmt_info->stmt)->loop_father;
    9890      2240169 :   bool nested_in_vect_loop = false;
    9891      2240169 :   tree elem_type;
    9892              :   /* Avoid false positive uninitialized warning, see PR110652.  */
    9893      2240169 :   tree new_temp = NULL_TREE;
    9894      2240169 :   machine_mode mode;
    9895      2240169 :   tree dummy;
    9896      2240169 :   tree dataref_ptr = NULL_TREE;
    9897      2240169 :   tree dataref_offset = NULL_TREE;
    9898      2240169 :   int i, j;
    9899      2240169 :   unsigned int group_size;
    9900      2240169 :   poly_uint64 group_gap_adj;
    9901      2240169 :   tree msq = NULL_TREE, lsq;
    9902      2240169 :   tree realignment_token = NULL_TREE;
    9903      2240169 :   gphi *phi = NULL;
    9904      2240169 :   bool grouped_load = false;
    9905      2240169 :   stmt_vec_info first_stmt_info;
    9906      2240169 :   stmt_vec_info first_stmt_info_for_drptr = NULL;
    9907      2240169 :   bool compute_in_loop = false;
    9908      2240169 :   class loop *at_loop;
    9909      2240169 :   int vec_num;
    9910      2240169 :   bb_vec_info bb_vinfo = dyn_cast <bb_vec_info> (vinfo);
    9911      2240169 :   poly_uint64 vf;
    9912      2240169 :   tree aggr_type;
    9913      2240169 :   tree ref_type;
    9914      2240169 :   enum vect_def_type mask_dt = vect_unknown_def_type;
    9915      2240169 :   enum vect_def_type els_dt = vect_unknown_def_type;
    9916              : 
    9917      2240169 :   if (!STMT_VINFO_RELEVANT_P (stmt_info) && !bb_vinfo)
    9918              :     return false;
    9919              : 
    9920      2240169 :   if (STMT_VINFO_DEF_TYPE (stmt_info) != vect_internal_def
    9921       246817 :       && cost_vec)
    9922              :     return false;
    9923              : 
    9924      1993352 :   if (!STMT_VINFO_DATA_REF (stmt_info))
    9925              :     return false;
    9926              : 
    9927      1581321 :   tree mask_vectype = NULL_TREE;
    9928      1581321 :   tree els = NULL_TREE; tree els_vectype = NULL_TREE;
    9929              : 
    9930      1581321 :   int mask_index = -1;
    9931      1581321 :   int els_index = -1;
    9932      1581321 :   slp_tree mask_node = NULL;
    9933      1581321 :   slp_tree els_op = NULL;
    9934      1581321 :   if (gassign *assign = dyn_cast <gassign *> (stmt_info->stmt))
    9935              :     {
    9936      1577102 :       scalar_dest = gimple_assign_lhs (assign);
    9937      1577102 :       if (TREE_CODE (scalar_dest) != SSA_NAME)
    9938              :         return false;
    9939              : 
    9940       745430 :       tree_code code = gimple_assign_rhs_code (assign);
    9941       745430 :       if (code != ARRAY_REF
    9942       745430 :           && code != BIT_FIELD_REF
    9943       745430 :           && code != INDIRECT_REF
    9944       509693 :           && code != COMPONENT_REF
    9945       509693 :           && code != IMAGPART_EXPR
    9946       366705 :           && code != REALPART_EXPR
    9947       366705 :           && code != MEM_REF
    9948          277 :           && TREE_CODE_CLASS (code) != tcc_declaration)
    9949              :         return false;
    9950              :     }
    9951              :   else
    9952              :     {
    9953         4219 :       gcall *call = dyn_cast <gcall *> (stmt_info->stmt);
    9954         4219 :       if (!call || !gimple_call_internal_p (call))
    9955              :         return false;
    9956              : 
    9957         4219 :       internal_fn ifn = gimple_call_internal_fn (call);
    9958         4219 :       if (!internal_load_fn_p (ifn))
    9959              :         return false;
    9960              : 
    9961         2849 :       scalar_dest = gimple_call_lhs (call);
    9962         2849 :       if (!scalar_dest)
    9963              :         return false;
    9964              : 
    9965         2849 :       mask_index = internal_fn_mask_index (ifn);
    9966         2849 :       if (mask_index >= 0)
    9967         2849 :         mask_index = vect_slp_child_index_for_operand (stmt_info, mask_index);
    9968         2849 :       if (mask_index >= 0
    9969         2849 :           && !vect_check_scalar_mask (vinfo, slp_node, mask_index,
    9970              :                                       &mask_node, &mask_dt, &mask_vectype))
    9971              :         return false;
    9972              : 
    9973         2849 :       els_index = internal_fn_else_index (ifn);
    9974         2849 :       if (els_index >= 0)
    9975         2849 :         els_index = vect_slp_child_index_for_operand (stmt_info, els_index);
    9976         2849 :       if (els_index >= 0
    9977         2849 :           && !vect_is_simple_use (vinfo, slp_node, els_index,
    9978              :                                   &els, &els_op, &els_dt, &els_vectype))
    9979              :         return false;
    9980              :     }
    9981              : 
    9982       748212 :   tree vectype = SLP_TREE_VECTYPE (slp_node);
    9983       748212 :   poly_uint64 nunits = TYPE_VECTOR_SUBPARTS (vectype);
    9984              : 
    9985       748212 :   if (loop_vinfo)
    9986              :     {
    9987       525441 :       loop = LOOP_VINFO_LOOP (loop_vinfo);
    9988       525441 :       nested_in_vect_loop = nested_in_vect_loop_p (loop, stmt_info);
    9989       525441 :       vf = LOOP_VINFO_VECT_FACTOR (loop_vinfo);
    9990              :     }
    9991              :   else
    9992              :     vf = 1;
    9993              : 
    9994       748212 :   vec_num = vect_get_num_copies (vinfo, slp_node);
    9995              : 
    9996              :   /* FORNOW. This restriction should be relaxed.  */
    9997       748212 :   if (nested_in_vect_loop && vec_num > 1)
    9998              :     {
    9999          319 :       if (dump_enabled_p ())
   10000           69 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
   10001              :                          "multiple types in nested loop.\n");
   10002              :       return false;
   10003              :     }
   10004              : 
   10005       747893 :   elem_type = TREE_TYPE (vectype);
   10006       747893 :   mode = TYPE_MODE (vectype);
   10007              : 
   10008              :   /* FORNOW. In some cases can vectorize even if data-type not supported
   10009              :     (e.g. - data copies).  */
   10010       747893 :   if (!can_implement_p (mov_optab, mode))
   10011              :     {
   10012            0 :       if (dump_enabled_p ())
   10013            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
   10014              :                          "Aligned load, but unsupported type.\n");
   10015              :       return false;
   10016              :     }
   10017              : 
   10018              :   /* Check if the load is a part of an interleaving chain.  */
   10019       747893 :   if (STMT_VINFO_GROUPED_ACCESS (stmt_info))
   10020              :     {
   10021       316737 :       grouped_load = true;
   10022              :       /* FORNOW */
   10023       316737 :       gcc_assert (!nested_in_vect_loop);
   10024       316737 :       gcc_assert (!STMT_VINFO_GATHER_SCATTER_P (stmt_info));
   10025              : 
   10026       316737 :       first_stmt_info = DR_GROUP_FIRST_ELEMENT (stmt_info);
   10027       316737 :       group_size = DR_GROUP_SIZE (first_stmt_info);
   10028              : 
   10029              :       /* Invalidate assumptions made by dependence analysis when vectorization
   10030              :          on the unrolled body effectively re-orders stmts.  */
   10031       316737 :       if (STMT_VINFO_MIN_NEG_DIST (stmt_info) != 0
   10032       316737 :           && maybe_gt (LOOP_VINFO_VECT_FACTOR (loop_vinfo),
   10033              :                        STMT_VINFO_MIN_NEG_DIST (stmt_info)))
   10034              :         {
   10035            0 :           if (dump_enabled_p ())
   10036            0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
   10037              :                              "cannot perform implicit CSE when performing "
   10038              :                              "group loads with negative dependence distance\n");
   10039              :           return false;
   10040              :         }
   10041              :     }
   10042              :   else
   10043              :     group_size = 1;
   10044              : 
   10045       747893 :   vect_load_store_data _ls_data{};
   10046       747893 :   vect_load_store_data &ls = slp_node->get_data (_ls_data);
   10047       747893 :   if (cost_vec
   10048       747893 :       && !get_load_store_type (vinfo, stmt_info, vectype, slp_node, mask_node,
   10049              :                                VLS_LOAD, &ls))
   10050              :     return false;
   10051              :   /* Temporary aliases to analysis data, should not be modified through
   10052              :      these.  */
   10053       633218 :   const vect_memory_access_type memory_access_type = ls.memory_access_type;
   10054       633218 :   const dr_alignment_support alignment_support_scheme
   10055              :     = ls.alignment_support_scheme;
   10056       633218 :   const int misalignment = ls.misalignment;
   10057       633218 :   const poly_int64 poffset = ls.poffset;
   10058       633218 :   const vec<int> &elsvals = ls.elsvals;
   10059              : 
   10060       633218 :   int maskload_elsval = 0;
   10061       633218 :   bool need_zeroing = false;
   10062              : 
   10063              :   /* We might need to explicitly zero inactive elements if there are
   10064              :      padding bits in the type that might leak otherwise.
   10065              :      Refer to PR115336.  */
   10066       633218 :   tree scalar_type = TREE_TYPE (scalar_dest);
   10067       633218 :   bool type_mode_padding_p
   10068      1266436 :     = TYPE_PRECISION (scalar_type) < GET_MODE_PRECISION (GET_MODE_INNER (mode));
   10069              : 
   10070       633025 :   if (BITINT_TYPE_P (scalar_type)
   10071       633218 :       && !type_has_mode_precision_p (scalar_type))
   10072              :     {
   10073          140 :       if (dump_enabled_p ())
   10074           18 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
   10075              :                          "_BitInt loads are not fully supported.\n");
   10076              :       return false;
   10077              :     }
   10078              : 
   10079       633078 :   if (slp_node->ldst_lanes
   10080            0 :       && memory_access_type != VMAT_LOAD_STORE_LANES)
   10081              :     {
   10082            0 :       if (dump_enabled_p ())
   10083            0 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
   10084              :                          "discovered load-lane but cannot use it.\n");
   10085              :       return false;
   10086              :     }
   10087              : 
   10088       633078 :   if (mask_node)
   10089              :     {
   10090         2723 :       if (memory_access_type == VMAT_CONTIGUOUS)
   10091              :         {
   10092         2158 :           machine_mode vec_mode = TYPE_MODE (vectype);
   10093          730 :           if (!VECTOR_MODE_P (vec_mode)
   10094         4316 :               || !can_vec_mask_load_store_p (vec_mode,
   10095         2158 :                                              TYPE_MODE (mask_vectype),
   10096              :                                              true, NULL, &ls.elsvals))
   10097              :             return false;
   10098              :         }
   10099          565 :       else if (memory_access_type == VMAT_ELEMENTWISE
   10100          565 :                || memory_access_type == VMAT_STRIDED_SLP)
   10101              :         {
   10102            0 :           if (dump_enabled_p ())
   10103            0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
   10104              :                              "unsupported masked strided access.\n");
   10105              :           return false;
   10106              :         }
   10107          565 :       else if (memory_access_type != VMAT_LOAD_STORE_LANES
   10108          565 :                && !mat_gather_scatter_p (memory_access_type))
   10109              :         {
   10110           32 :           if (dump_enabled_p ())
   10111            0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
   10112              :                              "unsupported access type for masked load.\n");
   10113              :           return false;
   10114              :         }
   10115          533 :       else if (memory_access_type == VMAT_GATHER_SCATTER_EMULATED)
   10116              :         {
   10117          212 :           if (dump_enabled_p ())
   10118           28 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
   10119              :                              "unsupported masked emulated gather.\n");
   10120              :           return false;
   10121              :         }
   10122              :     }
   10123              : 
   10124       632479 :   bool costing_p = cost_vec;
   10125              : 
   10126       632479 :   if (costing_p) /* transformation not required.  */
   10127              :     {
   10128       472230 :       if (loop_vinfo
   10129       333707 :           && LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo)
   10130       699826 :           && !check_load_store_for_partial_vectors (loop_vinfo, vectype,
   10131              :                                                     slp_node, VLS_LOAD,
   10132              :                                                     group_size, &ls, mask_node,
   10133              :                                                     &ls.elsvals))
   10134       163587 :         LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo) = false;
   10135              : 
   10136              :       /* If the type needs padding we must zero inactive elements.
   10137              :          Check if we can do that with a VEC_COND_EXPR and store the
   10138              :          elsval we choose in MASKLOAD_ELSVAL.  */
   10139       472230 :       if (ls.elsvals.length ()
   10140        62393 :           && type_mode_padding_p
   10141            7 :           && !ls.elsvals.contains (MASK_LOAD_ELSE_ZERO)
   10142        62393 :           && !expand_vec_cond_expr_p (vectype, truth_type_for (vectype)))
   10143              :         {
   10144            0 :           if (dump_enabled_p ())
   10145            0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
   10146              :                              "cannot zero inactive elements.\n");
   10147              :           return false;
   10148              :         }
   10149              : 
   10150       472230 :       if (mask_node
   10151       472230 :           && !vect_maybe_update_slp_op_vectype (mask_node,
   10152              :                                                 mask_vectype))
   10153              :         {
   10154            0 :           if (dump_enabled_p ())
   10155            0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
   10156              :                              "incompatible vector types for invariants\n");
   10157              :           return false;
   10158              :         }
   10159              : 
   10160       472230 :       if (dump_enabled_p ()
   10161        27752 :           && memory_access_type != VMAT_ELEMENTWISE
   10162        27635 :           && !mat_gather_scatter_p (memory_access_type)
   10163        27216 :           && memory_access_type != VMAT_STRIDED_SLP
   10164        27216 :           && memory_access_type != VMAT_INVARIANT
   10165       498472 :           && alignment_support_scheme != dr_aligned)
   10166        11031 :         dump_printf_loc (MSG_NOTE, vect_location,
   10167              :                          "Vectorizing an unaligned access.\n");
   10168              : 
   10169       472230 :       if (memory_access_type == VMAT_LOAD_STORE_LANES)
   10170            0 :         vinfo->any_known_not_updated_vssa = true;
   10171              :     }
   10172              : 
   10173              :   /* For now just use the first available else value.
   10174              :      get_supported_else_vals tries MASK_LOAD_ELSE_ZERO first so we will
   10175              :      select it here if it is supported.  */
   10176       632479 :   if (elsvals.length ())
   10177        86146 :     maskload_elsval = *elsvals.begin ();
   10178              : 
   10179       632479 :   if (dump_enabled_p () && !costing_p)
   10180        17460 :     dump_printf_loc (MSG_NOTE, vect_location, "transform load.\n");
   10181              : 
   10182              :   /* Transform.  */
   10183              : 
   10184       632479 :   dr_vec_info *dr_info = STMT_VINFO_DR_INFO (stmt_info), *first_dr_info = NULL;
   10185       632479 :   if (!costing_p)
   10186       160249 :     ensure_base_align (dr_info);
   10187              : 
   10188       632479 :   if (memory_access_type == VMAT_INVARIANT)
   10189              :     {
   10190         5980 :       gcc_assert (!grouped_load && !mask_node && !bb_vinfo);
   10191              :       /* If we have versioned for aliasing or the loop doesn't
   10192              :          have any data dependencies that would preclude this,
   10193              :          then we are sure this is a loop invariant load and
   10194              :          thus we can insert it on the preheader edge.
   10195              :          TODO: hoist_defs_of_uses should ideally be computed
   10196              :          once at analysis time, remembered and used in the
   10197              :          transform time.  */
   10198        11960 :       bool hoist_p = (LOOP_VINFO_NO_DATA_DEPENDENCIES (loop_vinfo)
   10199         5980 :                       && !nested_in_vect_loop);
   10200              : 
   10201         5980 :       bool uniform_p = true;
   10202        24734 :       for (stmt_vec_info sinfo : SLP_TREE_SCALAR_STMTS (slp_node))
   10203              :         {
   10204              :           /* It is unsafe to hoist a conditional load over the conditions that
   10205              :              make it valid.  When early break this means that any invariant load
   10206              :              can't be hoisted unless it's in the loop header or if we know
   10207              :              something else has verified the load is valid to do.  Alignment
   10208              :              peeling would do this since getting through the prologue means the
   10209              :              load was done at least once and so the vector main body is free to
   10210              :              hoist it.  However today GCC will hoist the load above the PFA
   10211              :              loop.  As such that makes it still invalid and so we can't allow it
   10212              :              today.  */
   10213         6794 :           if (LOOP_VINFO_EARLY_BREAKS (loop_vinfo)
   10214         2912 :               && !DR_SCALAR_KNOWN_BOUNDS (STMT_VINFO_DR_INFO (sinfo))
   10215         9670 :               && gimple_bb (STMT_VINFO_STMT (vect_orig_stmt (sinfo)))
   10216         2876 :                   != loop->header)
   10217              :             {
   10218         2586 :               if (LOOP_VINFO_PEELING_FOR_ALIGNMENT (loop_vinfo)
   10219         2586 :                   && dump_enabled_p ())
   10220            6 :                 dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
   10221              :                              "not hoisting invariant load due to early break"
   10222              :                              "constraints\n");
   10223         2580 :               else if (dump_enabled_p ())
   10224           26 :                dump_printf_loc (MSG_NOTE, vect_location,
   10225              :                              "not hoisting invariant load due to early break"
   10226              :                              "constraints\n");
   10227              :             hoist_p = false;
   10228              :           }
   10229              : 
   10230         4240 :           hoist_p = hoist_p && hoist_defs_of_uses (sinfo->stmt, loop, false);
   10231         6794 :           if (sinfo != SLP_TREE_SCALAR_STMTS (slp_node)[0])
   10232          321 :             uniform_p = false;
   10233              :         }
   10234         5980 :       if (costing_p)
   10235              :         {
   10236         5152 :           if (!uniform_p && (!hoist_p || !vf.is_constant ()))
   10237              :             {
   10238            0 :               if (dump_enabled_p ())
   10239            0 :                 dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
   10240              :                                  "not vectorizing non-uniform invariant "
   10241              :                                  "load\n");
   10242              :               return false;
   10243              :             }
   10244         3160 :           enum vect_cost_model_location cost_loc
   10245         5152 :             = hoist_p ? vect_prologue : vect_body;
   10246         5276 :           unsigned int cost = record_stmt_cost (cost_vec,
   10247              :                                                 uniform_p
   10248          124 :                                                 ? 1 : SLP_TREE_LANES (slp_node),
   10249              :                                                 scalar_load,
   10250              :                                                 slp_node, 0, cost_loc);
   10251         5152 :           cost += record_stmt_cost (cost_vec, 1,
   10252              :                                     uniform_p ? scalar_to_vec : vec_construct,
   10253              :                                     slp_node, 0, cost_loc);
   10254         5152 :           unsigned int prologue_cost = hoist_p ? cost : 0;
   10255         3160 :           unsigned int inside_cost = hoist_p ? 0 : cost;
   10256         5152 :           if (dump_enabled_p ())
   10257          560 :             dump_printf_loc (MSG_NOTE, vect_location,
   10258              :                              "vect_model_load_cost: inside_cost = %d, "
   10259              :                              "prologue_cost = %d .\n",
   10260              :                              inside_cost, prologue_cost);
   10261         5152 :           SLP_TREE_TYPE (slp_node) = load_vec_info_type;
   10262         5152 :           slp_node->data = new vect_load_store_data (std::move (ls));
   10263         5152 :           return true;
   10264              :         }
   10265          828 :       if (hoist_p)
   10266              :         {
   10267              :           /* ???  For non-uniform lanes there could be still duplicates.
   10268              :              We're leaving those to post-vectorizer CSE for the moment.  */
   10269          620 :           auto_vec<tree> scalar_defs (SLP_TREE_LANES (slp_node));
   10270         2027 :           for (stmt_vec_info sinfo : SLP_TREE_SCALAR_STMTS (slp_node))
   10271              :             {
   10272          724 :               gassign *stmt = as_a <gassign *> (sinfo->stmt);
   10273          724 :               if (dump_enabled_p ())
   10274          379 :                 dump_printf_loc (MSG_NOTE, vect_location,
   10275              :                                  "hoisting out of the vectorized loop: %G",
   10276              :                                  (gimple *) stmt);
   10277          724 :               scalar_dest = copy_ssa_name (gimple_assign_lhs (stmt));
   10278          724 :               tree rhs = unshare_expr (gimple_assign_rhs1 (stmt));
   10279          724 :               edge pe = loop_preheader_edge (loop);
   10280          724 :               gphi *vphi = get_virtual_phi (loop->header);
   10281          724 :               tree vuse;
   10282          724 :               if (vphi)
   10283          717 :                 vuse = PHI_ARG_DEF_FROM_EDGE (vphi, pe);
   10284              :               else
   10285            7 :                 vuse = gimple_vuse (gsi_stmt (*gsi));
   10286          724 :               gimple *new_stmt = gimple_build_assign (scalar_dest, rhs);
   10287          724 :               gimple_set_vuse (new_stmt, vuse);
   10288          724 :               gsi_insert_on_edge_immediate (pe, new_stmt);
   10289          724 :               hoist_defs_of_uses (new_stmt, loop, true);
   10290          724 :               if (!useless_type_conversion_p (TREE_TYPE (vectype),
   10291          724 :                                               TREE_TYPE (scalar_dest)))
   10292              :                 {
   10293            8 :                   tree tem = make_ssa_name (TREE_TYPE (vectype));
   10294            8 :                   new_stmt = gimple_build_assign (tem,
   10295              :                                                   NOP_EXPR, scalar_dest);
   10296            8 :                   gsi_insert_on_edge_immediate (pe, new_stmt);
   10297            8 :                   scalar_dest = tem;
   10298              :                 }
   10299          724 :               scalar_defs.quick_push (scalar_dest);
   10300          724 :               if (uniform_p)
   10301              :                 break;
   10302              :             }
   10303          620 :           if (!uniform_p)
   10304              :             {
   10305           63 :               unsigned const_nunits
   10306           63 :                 = TYPE_VECTOR_SUBPARTS (vectype).to_constant ();
   10307          144 :               for (j = 0; j < (int) vec_num; ++j)
   10308              :                 {
   10309           81 :                   vec<constructor_elt, va_gc> *v = NULL;
   10310           81 :                   vec_safe_reserve (v, const_nunits, true);
   10311          522 :                   for (unsigned i = 0; i < const_nunits; ++i)
   10312              :                     {
   10313          360 :                       unsigned def_idx
   10314          360 :                         = (j * const_nunits + i) % SLP_TREE_LANES (slp_node);
   10315          360 :                       CONSTRUCTOR_APPEND_ELT (v, NULL_TREE,
   10316              :                                               scalar_defs[def_idx]);
   10317              :                     }
   10318           81 :                   scalar_dest = build_constructor (vectype, v);
   10319           81 :                   new_temp = vect_init_vector (vinfo, stmt_info, scalar_dest,
   10320              :                                                vectype, NULL);
   10321           81 :                   slp_node->push_vec_def (new_temp);
   10322              :                 }
   10323           63 :               return true;
   10324              :             }
   10325          557 :           new_temp = vect_init_vector (vinfo, stmt_info, scalar_dest,
   10326              :                                        vectype, NULL);
   10327          620 :         }
   10328              :       else
   10329              :         {
   10330          208 :           gcc_assert (uniform_p);
   10331          208 :           gimple_stmt_iterator gsi2 = *gsi;
   10332          208 :           gsi_next (&gsi2);
   10333          208 :           new_temp = vect_init_vector (vinfo, stmt_info, scalar_dest,
   10334              :                                        vectype, &gsi2);
   10335              :         }
   10336         1603 :       for (j = 0; j < (int) vec_num; ++j)
   10337          838 :         slp_node->push_vec_def (new_temp);
   10338              :       return true;
   10339              :     }
   10340              : 
   10341       626499 :   if (memory_access_type == VMAT_ELEMENTWISE
   10342       626499 :       || memory_access_type == VMAT_STRIDED_SLP)
   10343              :     {
   10344        24775 :       gimple_stmt_iterator incr_gsi;
   10345        24775 :       bool insert_after;
   10346        24775 :       tree offvar = NULL_TREE;
   10347        24775 :       tree ivstep;
   10348        24775 :       tree running_off;
   10349        24775 :       vec<constructor_elt, va_gc> *v = NULL;
   10350        24775 :       tree stride_base, stride_step = NULL_TREE, alias_off;
   10351              :       /* Checked by get_load_store_type.  */
   10352        24775 :       unsigned int const_nunits = nunits.to_constant ();
   10353        24775 :       unsigned HOST_WIDE_INT cst_offset = 0;
   10354        24775 :       tree dr_offset;
   10355        24775 :       unsigned int inside_cost = 0;
   10356              : 
   10357        24775 :       gcc_assert (!LOOP_VINFO_USING_PARTIAL_VECTORS_P (loop_vinfo));
   10358        24775 :       gcc_assert (!nested_in_vect_loop);
   10359              : 
   10360        24775 :       if (grouped_load)
   10361              :         {
   10362              :           /* If we elided a consecutive load permutation, don't
   10363              :              use the original first statement (which could be elided)
   10364              :              but the one the load permutation starts with.
   10365              :              This ensures the stride_base below is correct.  */
   10366        11407 :           if (!ls.subchain_p)
   10367        11325 :             first_stmt_info = DR_GROUP_FIRST_ELEMENT (stmt_info);
   10368              :           else
   10369           82 :             first_stmt_info = SLP_TREE_SCALAR_STMTS (slp_node)[0];
   10370        11407 :           first_dr_info = STMT_VINFO_DR_INFO (first_stmt_info);
   10371        11407 :           ref_type = get_group_alias_ptr_type (first_stmt_info);
   10372              :         }
   10373              :       else
   10374              :         {
   10375        13368 :           first_stmt_info = stmt_info;
   10376        13368 :           first_dr_info = dr_info;
   10377        13368 :           ref_type = reference_alias_ptr_type (DR_REF (dr_info->dr));
   10378              :         }
   10379              : 
   10380        24775 :       if (grouped_load)
   10381              :         {
   10382        11407 :           if (memory_access_type == VMAT_STRIDED_SLP)
   10383              :             {
   10384              :               /* If we elided a consecutive load permutation, adjust
   10385              :                  the group size here.  */
   10386         4313 :               if (!ls.subchain_p)
   10387         4231 :                 group_size = DR_GROUP_SIZE (first_stmt_info);
   10388              :               else
   10389           82 :                 group_size = SLP_TREE_LANES (slp_node);
   10390              :             }
   10391              :           else /* VMAT_ELEMENTWISE */
   10392         7094 :             group_size = SLP_TREE_LANES (slp_node);
   10393              :         }
   10394              :       else
   10395              :         group_size = 1;
   10396              : 
   10397        24775 :       if (!costing_p)
   10398              :         {
   10399         3667 :           dr_offset = get_dr_vinfo_offset (vinfo, first_dr_info);
   10400         3667 :           stride_base = fold_build_pointer_plus (
   10401              :             DR_BASE_ADDRESS (first_dr_info->dr),
   10402              :             size_binop (PLUS_EXPR, convert_to_ptrofftype (dr_offset),
   10403              :                         convert_to_ptrofftype (DR_INIT (first_dr_info->dr))));
   10404         3667 :           stride_step = fold_convert (sizetype, DR_STEP (first_dr_info->dr));
   10405              : 
   10406              :           /* For a load with loop-invariant (but other than power-of-2)
   10407              :              stride (i.e. not a grouped access) like so:
   10408              : 
   10409              :                for (i = 0; i < n; i += stride)
   10410              :                  ... = array[i];
   10411              : 
   10412              :              we generate a new induction variable and new accesses to
   10413              :              form a new vector (or vectors, depending on ncopies):
   10414              : 
   10415              :                for (j = 0; ; j += VF*stride)
   10416              :                  tmp1 = array[j];
   10417              :                  tmp2 = array[j + stride];
   10418              :                  ...
   10419              :                  vectemp = {tmp1, tmp2, ...}
   10420              :              */
   10421              : 
   10422         3667 :           tree increment = fold_convert (TREE_TYPE (stride_step),
   10423              :                                          LOOP_VINFO_IV_INCREMENT (loop_vinfo));
   10424         3667 :           ivstep = fold_build2 (MULT_EXPR, TREE_TYPE (stride_step),
   10425              :                                 stride_step, increment);
   10426              : 
   10427         3667 :           standard_iv_increment_position (loop, &incr_gsi, &insert_after);
   10428              : 
   10429         3667 :           stride_base = cse_and_gimplify_to_preheader (loop_vinfo, stride_base);
   10430         3667 :           if (LOOP_VINFO_IV_INCREMENT_INVARIANT_P (loop_vinfo))
   10431         3667 :             ivstep = cse_and_gimplify_to_preheader (loop_vinfo, ivstep);
   10432              :           else
   10433            0 :             ivstep = force_gimple_operand_gsi (&incr_gsi, unshare_expr (ivstep),
   10434              :                                                true, NULL_TREE, true,
   10435              :                                                GSI_SAME_STMT);
   10436         3667 :           create_iv (stride_base, PLUS_EXPR, ivstep, NULL, loop, &incr_gsi,
   10437              :                      insert_after, &offvar, NULL, true);
   10438              : 
   10439         3667 :           stride_step = cse_and_gimplify_to_preheader (loop_vinfo, stride_step);
   10440              :         }
   10441              : 
   10442        24775 :       running_off = offvar;
   10443        24775 :       alias_off = build_int_cst (ref_type, 0);
   10444        24775 :       int nloads = const_nunits;
   10445        24775 :       int lnel = 1;
   10446        24775 :       tree ltype = TREE_TYPE (vectype);
   10447        24775 :       tree lvectype = vectype;
   10448        24775 :       auto_vec<tree> dr_chain;
   10449              :       /* ???  Modify local copies of alignment_support_scheme and
   10450              :          misalignment, but this part of analysis should be done
   10451              :          earlier and remembered, likewise the chosen load mode.  */
   10452        24775 :       const dr_alignment_support tem = alignment_support_scheme;
   10453        24775 :       dr_alignment_support alignment_support_scheme = tem;
   10454        24775 :       const int tem2 = misalignment;
   10455        24775 :       int misalignment = tem2;
   10456        24775 :       if (memory_access_type == VMAT_STRIDED_SLP)
   10457              :         {
   10458        17681 :           HOST_WIDE_INT n = gcd (group_size, const_nunits);
   10459              :           /* Use the target vector type if the group size is a multiple
   10460              :              of it.  */
   10461        17681 :           if (n == const_nunits)
   10462              :             {
   10463         2286 :               int mis_align = dr_misalignment (first_dr_info, vectype);
   10464              :               /* With VF > 1 we advance the DR by step, if that is constant
   10465              :                  and only aligned when performed VF times, DR alignment
   10466              :                  analysis can analyze this as aligned since it assumes
   10467              :                  contiguous accesses.  But that is not how we code generate
   10468              :                  here, so adjust for this.  */
   10469         2286 :               if (maybe_gt (vf, 1u)
   10470         3668 :                   && !multiple_p (DR_STEP_ALIGNMENT (first_dr_info->dr),
   10471         3438 :                                   DR_TARGET_ALIGNMENT (first_dr_info)))
   10472          230 :                 mis_align = -1;
   10473         2286 :               dr_alignment_support dr_align
   10474         2286 :                 = vect_supportable_dr_alignment (vinfo, dr_info, vectype,
   10475              :                                                  mis_align);
   10476         2286 :               if (dr_align == dr_aligned
   10477         2286 :                   || dr_align == dr_unaligned_supported)
   10478              :                 {
   10479        17681 :                   nloads = 1;
   10480        17681 :                   lnel = const_nunits;
   10481        17681 :                   ltype = vectype;
   10482        17681 :                   alignment_support_scheme = dr_align;
   10483        17681 :                   misalignment = mis_align;
   10484              :                 }
   10485              :             }
   10486              :           /* Else use the biggest vector we can load the group without
   10487              :              accessing excess elements.  */
   10488        15395 :           else if (n > 1)
   10489              :             {
   10490         2010 :               tree ptype;
   10491         2010 :               tree vtype
   10492         2010 :                 = vector_vector_composition_type (vectype, const_nunits / n,
   10493              :                                                   &ptype);
   10494         2010 :               if (vtype != NULL_TREE)
   10495              :                 {
   10496         1972 :                   dr_alignment_support dr_align;
   10497         1972 :                   int mis_align = 0;
   10498         1972 :                   if (VECTOR_TYPE_P (ptype))
   10499              :                     {
   10500         1052 :                       mis_align = dr_misalignment (first_dr_info, ptype);
   10501         1052 :                       if (maybe_gt (vf, 1u)
   10502         2074 :                           && !multiple_p (DR_STEP_ALIGNMENT (first_dr_info->dr),
   10503         1058 :                                           DR_TARGET_ALIGNMENT (first_dr_info)))
   10504         1016 :                         mis_align = -1;
   10505         1052 :                       dr_align
   10506         1052 :                         = vect_supportable_dr_alignment (vinfo, dr_info, ptype,
   10507              :                                                          mis_align);
   10508              :                     }
   10509              :                   else
   10510              :                     dr_align = dr_unaligned_supported;
   10511         1972 :                   if (dr_align == dr_aligned
   10512         1972 :                       || dr_align == dr_unaligned_supported)
   10513              :                     {
   10514         1972 :                       nloads = const_nunits / n;
   10515         1972 :                       lnel = n;
   10516         1972 :                       lvectype = vtype;
   10517         1972 :                       ltype = ptype;
   10518         1972 :                       alignment_support_scheme = dr_align;
   10519         1972 :                       misalignment = mis_align;
   10520              :                     }
   10521              :                 }
   10522              :             }
   10523        17681 :           unsigned align;
   10524        17681 :           if (alignment_support_scheme == dr_aligned)
   10525           14 :             align = known_alignment (DR_TARGET_ALIGNMENT (first_dr_info));
   10526              :           else
   10527        17667 :             align = dr_alignment (vect_dr_behavior (vinfo, first_dr_info));
   10528              :           /* Alignment is at most the access size if we do multiple loads.  */
   10529        17681 :           if (nloads > 1)
   10530        15395 :             align = MIN (tree_to_uhwi (TYPE_SIZE_UNIT (ltype)), align);
   10531        17681 :           ltype = build_aligned_type (ltype, align * BITS_PER_UNIT);
   10532              :         }
   10533              : 
   10534        24775 :       if (costing_p)
   10535              :         {
   10536              :           /* Record the composition type for target access during costing.  */
   10537        21108 :           ls.ls_type = lvectype;
   10538        21108 :           ls.ls_eltype = ltype;
   10539              :         }
   10540              :       else
   10541         3667 :         gcc_assert (ls.ls_type == lvectype && ls.ls_eltype == ltype);
   10542              : 
   10543              :       /* For SLP permutation support we need to load the whole group,
   10544              :          not only the number of vector stmts the permutation result
   10545              :          fits in.  */
   10546        24775 :       int ncopies;
   10547        24775 :       if (ls.slp_perm)
   10548              :         {
   10549         2894 :           gcc_assert (memory_access_type != VMAT_ELEMENTWISE);
   10550              :           /* We don't yet generate SLP_TREE_LOAD_PERMUTATIONs for
   10551              :              variable VF.  */
   10552         2894 :           unsigned int const_vf = vf.to_constant ();
   10553         2894 :           ncopies = CEIL (group_size * const_vf, const_nunits);
   10554         2894 :           dr_chain.create (ncopies);
   10555              :         }
   10556              :       else
   10557              :         ncopies = vec_num;
   10558              : 
   10559        24775 :       unsigned int group_el = 0;
   10560        24775 :       unsigned HOST_WIDE_INT
   10561        24775 :         elsz = tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (vectype)));
   10562        24775 :       unsigned int n_groups = 0;
   10563              :       /* For costing some adjacent vector loads, we'd like to cost with
   10564              :          the total number of them once instead of cost each one by one. */
   10565        24775 :       unsigned int n_adjacent_loads = 0;
   10566        59018 :       for (j = 0; j < ncopies; j++)
   10567              :         {
   10568        34243 :           if (nloads > 1 && !costing_p)
   10569         3370 :             vec_alloc (v, nloads);
   10570        34243 :           gimple *new_stmt = NULL;
   10571       143535 :           for (i = 0; i < nloads; i++)
   10572              :             {
   10573       109292 :               if (costing_p)
   10574              :                 {
   10575              :                   /* For VMAT_ELEMENTWISE, just cost it as scalar_load to
   10576              :                      avoid ICE, see PR110776.  */
   10577        98671 :                   if (VECTOR_TYPE_P (ltype)
   10578         6021 :                       && memory_access_type != VMAT_ELEMENTWISE)
   10579         6021 :                     n_adjacent_loads++;
   10580              :                   else
   10581        92650 :                     inside_cost += record_stmt_cost (cost_vec, 1, scalar_load,
   10582              :                                                      slp_node, 0, vect_body);
   10583        98671 :                   continue;
   10584              :                 }
   10585        10621 :               unsigned int load_el = group_el;
   10586              :               /* For elementwise accesses apply a load permutation directly.  */
   10587        10621 :               if (memory_access_type == VMAT_ELEMENTWISE
   10588        10621 :                   && SLP_TREE_LOAD_PERMUTATION (slp_node).exists ())
   10589         2486 :                 load_el = SLP_TREE_LOAD_PERMUTATION (slp_node)[group_el];
   10590        10621 :               tree this_off = build_int_cst (TREE_TYPE (alias_off),
   10591        10621 :                                              load_el * elsz + cst_offset);
   10592        10621 :               tree data_ref = build2 (MEM_REF, ltype, running_off, this_off);
   10593        10621 :               vect_copy_ref_info (data_ref, first_stmt_info);
   10594        10621 :               new_temp = make_ssa_name (ltype);
   10595        10621 :               new_stmt = gimple_build_assign (new_temp, data_ref);
   10596        10621 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
   10597        10621 :               if (nloads > 1)
   10598         9002 :                 CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, new_temp);
   10599              : 
   10600        10621 :               group_el += lnel;
   10601        10621 :               if (group_el == group_size)
   10602              :                 {
   10603        10252 :                   n_groups++;
   10604              :                   /* When doing SLP make sure to not load elements from
   10605              :                      the next vector iteration, those will not be accessed
   10606              :                      so just use the last element again.  See PR107451.  */
   10607        10252 :                   if (known_lt (n_groups, vf))
   10608              :                     {
   10609         6566 :                       tree newoff = copy_ssa_name (running_off);
   10610         6566 :                       gimple *incr
   10611         6566 :                         = gimple_build_assign (newoff, POINTER_PLUS_EXPR,
   10612              :                                                running_off, stride_step);
   10613         6566 :                       vect_finish_stmt_generation (vinfo, stmt_info, incr, gsi);
   10614         6566 :                       running_off = newoff;
   10615              :                     }
   10616              :                   group_el = 0;
   10617              :                 }
   10618              :             }
   10619              : 
   10620        34243 :           if (nloads > 1)
   10621              :             {
   10622        25355 :               if (costing_p)
   10623        21985 :                 inside_cost += record_stmt_cost (cost_vec, 1, vec_construct,
   10624              :                                                  slp_node, 0, vect_body);
   10625              :               else
   10626              :                 {
   10627         3370 :                   tree vec_inv = build_constructor (lvectype, v);
   10628         3370 :                   new_temp = vect_init_vector (vinfo, stmt_info, vec_inv,
   10629              :                                                lvectype, gsi);
   10630         3370 :                   new_stmt = SSA_NAME_DEF_STMT (new_temp);
   10631         3370 :                   if (lvectype != vectype)
   10632              :                     {
   10633          398 :                       new_stmt
   10634          398 :                         = gimple_build_assign (make_ssa_name (vectype),
   10635              :                                                VIEW_CONVERT_EXPR,
   10636              :                                                build1 (VIEW_CONVERT_EXPR,
   10637              :                                                        vectype, new_temp));
   10638          398 :                       vect_finish_stmt_generation (vinfo, stmt_info, new_stmt,
   10639              :                                                    gsi);
   10640              :                     }
   10641              :                 }
   10642              :             }
   10643         8888 :           else if (!costing_p && ltype != vectype)
   10644              :             {
   10645         1602 :               new_stmt = gimple_build_assign (make_ssa_name (vectype),
   10646              :                                               VIEW_CONVERT_EXPR,
   10647              :                                               build1 (VIEW_CONVERT_EXPR,
   10648              :                                                       vectype, new_temp));
   10649         1602 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt,
   10650              :                                            gsi);
   10651              :             }
   10652              : 
   10653        34243 :           if (!costing_p)
   10654              :             {
   10655         4989 :               if (ls.slp_perm)
   10656         1683 :                 dr_chain.quick_push (gimple_assign_lhs (new_stmt));
   10657              :               else
   10658         3306 :                 slp_node->push_vec_def (new_stmt);
   10659              :             }
   10660              :         }
   10661        24775 :       if (ls.slp_perm)
   10662              :         {
   10663         2894 :           if (costing_p)
   10664              :             {
   10665         2100 :               gcc_assert (ls.n_perms != -1U);
   10666         2100 :               inside_cost += record_stmt_cost (cost_vec, ls.n_perms, vec_perm,
   10667              :                                                slp_node, 0, vect_body);
   10668              :             }
   10669              :           else
   10670              :             {
   10671          794 :               unsigned n_perms2;
   10672          794 :               vect_transform_slp_perm_load (vinfo, slp_node, dr_chain, gsi, vf,
   10673              :                                             false, &ls, &n_perms2);
   10674          794 :               gcc_assert (ls.n_perms == n_perms2);
   10675              :             }
   10676              :         }
   10677              : 
   10678        24775 :       if (costing_p)
   10679              :         {
   10680        21108 :           if (n_adjacent_loads > 0)
   10681         2207 :             vect_get_load_cost (vinfo, stmt_info, slp_node, n_adjacent_loads,
   10682              :                                 alignment_support_scheme, misalignment, false,
   10683              :                                 &inside_cost, nullptr, cost_vec, cost_vec,
   10684              :                                 true);
   10685        21108 :           if (dump_enabled_p ())
   10686          531 :             dump_printf_loc (MSG_NOTE, vect_location,
   10687              :                              "vect_model_load_cost: inside_cost = %u, "
   10688              :                              "prologue_cost = 0 .\n",
   10689              :                              inside_cost);
   10690        21108 :           SLP_TREE_TYPE (slp_node) = load_vec_info_type;
   10691        21108 :           slp_node->data = new vect_load_store_data (std::move (ls));
   10692              :         }
   10693              : 
   10694        24775 :       return true;
   10695        24775 :     }
   10696              : 
   10697       601724 :   if (mat_gather_scatter_p (memory_access_type)
   10698       601724 :       && !ls.ls_type)
   10699              :     grouped_load = false;
   10700              : 
   10701       598546 :   if (grouped_load
   10702       601724 :       || SLP_TREE_LOAD_PERMUTATION (slp_node).exists ())
   10703              :     {
   10704       266976 :       if (grouped_load)
   10705              :         {
   10706       266507 :           first_stmt_info = DR_GROUP_FIRST_ELEMENT (stmt_info);
   10707       266507 :           group_size = DR_GROUP_SIZE (first_stmt_info);
   10708              :         }
   10709              :       else
   10710              :         {
   10711              :           first_stmt_info = stmt_info;
   10712              :           group_size = 1;
   10713              :         }
   10714              :       /* For SLP vectorization we directly vectorize a subchain
   10715              :          without permutation.  */
   10716       266976 :       if (! SLP_TREE_LOAD_PERMUTATION (slp_node).exists ())
   10717       207715 :         first_stmt_info = SLP_TREE_SCALAR_STMTS (slp_node)[0];
   10718              :       /* For BB vectorization always use the first stmt to base
   10719              :          the data ref pointer on.  */
   10720       266976 :       if (bb_vinfo)
   10721       214471 :         first_stmt_info_for_drptr
   10722       214471 :           = vect_find_first_scalar_stmt_in_slp (slp_node);
   10723              : 
   10724       266976 :       first_dr_info = STMT_VINFO_DR_INFO (first_stmt_info);
   10725       266976 :       group_gap_adj = 0;
   10726              : 
   10727              :       /* VEC_NUM is the number of vect stmts to be created for this group.  */
   10728       266976 :       grouped_load = false;
   10729              :       /* If an SLP permutation is from N elements to N elements,
   10730              :          and if one vector holds a whole number of N, we can load
   10731              :          the inputs to the permutation in the same way as an
   10732              :          unpermuted sequence.  In other cases we need to load the
   10733              :          whole group, not only the number of vector stmts the
   10734              :          permutation result fits in.  */
   10735       266976 :       unsigned scalar_lanes = SLP_TREE_LANES (slp_node);
   10736       266976 :       if (nested_in_vect_loop)
   10737              :         /* We do not support grouped accesses in a nested loop,
   10738              :            instead the access is contiguous but it might be
   10739              :            permuted.  No gap adjustment is needed though.  */
   10740              :         ;
   10741       266974 :       else if (ls.slp_perm
   10742       266974 :                && (group_size != scalar_lanes
   10743        10092 :                    || !multiple_p (nunits, group_size)))
   10744              :         {
   10745              :           /* We don't yet generate such SLP_TREE_LOAD_PERMUTATIONs for
   10746              :              variable VF; see vect_transform_slp_perm_load.  */
   10747        50348 :           unsigned int const_vf = vf.to_constant ();
   10748        50348 :           unsigned int const_nunits = nunits.to_constant ();
   10749        50348 :           vec_num = CEIL (group_size * const_vf, const_nunits);
   10750        50348 :           group_gap_adj = vf * group_size - nunits * vec_num;
   10751              :         }
   10752              :       else
   10753              :         {
   10754       216626 :           group_gap_adj = group_size - scalar_lanes;
   10755              :         }
   10756              : 
   10757       266976 :       ref_type = get_group_alias_ptr_type (first_stmt_info);
   10758              :     }
   10759              :   else
   10760              :     {
   10761       334748 :       first_stmt_info = stmt_info;
   10762       334748 :       first_dr_info = dr_info;
   10763       334748 :       group_size = 1;
   10764       334748 :       group_gap_adj = 0;
   10765       334748 :       ref_type = reference_alias_ptr_type (DR_REF (first_dr_info->dr));
   10766              :     }
   10767              : 
   10768       601724 :   bool masks_p = loop_vinfo && LOOP_VINFO_FULLY_MASKED_P (loop_vinfo);
   10769       387253 :   bool lens_p = loop_vinfo && LOOP_VINFO_FULLY_WITH_LENGTH_P (loop_vinfo);
   10770              : 
   10771              :   /* The vect_transform_stmt and vect_analyze_stmt will go here but there
   10772              :      are some difference here.  We cannot enable both the lens and masks
   10773              :      during transform but it is allowed during analysis.
   10774              :      Shouldn't go with length-based approach if fully masked.  */
   10775       601724 :   if (cost_vec == NULL)
   10776              :     /* The cost_vec is NULL during transform.  */
   10777       155754 :     gcc_assert ((!lens_p || !masks_p));
   10778              : 
   10779              :   /* Targets with store-lane instructions must not require explicit
   10780              :      realignment.  vect_supportable_dr_alignment always returns either
   10781              :      dr_aligned or dr_unaligned_supported for (non-length) masked
   10782              :      operations.  */
   10783       601724 :   gcc_assert ((memory_access_type != VMAT_LOAD_STORE_LANES
   10784              :                && !mask_node
   10785              :                && !masks_p)
   10786              :               || mat_gather_scatter_p (memory_access_type)
   10787              :               || alignment_support_scheme == dr_aligned
   10788              :               || alignment_support_scheme == dr_unaligned_supported);
   10789              : 
   10790              :   /* In case the vectorization factor (VF) is bigger than the number
   10791              :      of elements that we can fit in a vectype (nunits), we have to generate
   10792              :      more than one vector stmt - i.e - we need to "unroll" the
   10793              :      vector stmt by a factor VF/nunits.  In doing so, we record a pointer
   10794              :      from one copy of the vector stmt to the next, in the field
   10795              :      STMT_VINFO_RELATED_STMT.  This is necessary in order to allow following
   10796              :      stages to find the correct vector defs to be used when vectorizing
   10797              :      stmts that use the defs of the current stmt.  The example below
   10798              :      illustrates the vectorization process when VF=16 and nunits=4 (i.e., we
   10799              :      need to create 4 vectorized stmts):
   10800              : 
   10801              :      before vectorization:
   10802              :                                 RELATED_STMT    VEC_STMT
   10803              :         S1:     x = memref      -               -
   10804              :         S2:     z = x + 1       -               -
   10805              : 
   10806              :      step 1: vectorize stmt S1:
   10807              :         We first create the vector stmt VS1_0, and, as usual, record a
   10808              :         pointer to it in the STMT_VINFO_VEC_STMT of the scalar stmt S1.
   10809              :         Next, we create the vector stmt VS1_1, and record a pointer to
   10810              :         it in the STMT_VINFO_RELATED_STMT of the vector stmt VS1_0.
   10811              :         Similarly, for VS1_2 and VS1_3.  This is the resulting chain of
   10812              :         stmts and pointers:
   10813              :                                 RELATED_STMT    VEC_STMT
   10814              :         VS1_0:  vx0 = memref0   VS1_1           -
   10815              :         VS1_1:  vx1 = memref1   VS1_2           -
   10816              :         VS1_2:  vx2 = memref2   VS1_3           -
   10817              :         VS1_3:  vx3 = memref3   -               -
   10818              :         S1:     x = load        -               VS1_0
   10819              :         S2:     z = x + 1       -               -
   10820              :   */
   10821              : 
   10822              :   /* If the data reference is aligned (dr_aligned) or potentially unaligned
   10823              :      on a target that supports unaligned accesses (dr_unaligned_supported)
   10824              :      we generate the following code:
   10825              :          p = initial_addr;
   10826              :          indx = 0;
   10827              :          loop {
   10828              :            p = p + indx * vectype_size;
   10829              :            vec_dest = *(p);
   10830              :            indx = indx + 1;
   10831              :          }
   10832              : 
   10833              :      Otherwise, the data reference is potentially unaligned on a target that
   10834              :      does not support unaligned accesses (dr_explicit_realign_optimized) -
   10835              :      then generate the following code, in which the data in each iteration is
   10836              :      obtained by two vector loads, one from the previous iteration, and one
   10837              :      from the current iteration:
   10838              :          p1 = initial_addr;
   10839              :          msq_init = *(floor(p1))
   10840              :          p2 = initial_addr + VS - 1;
   10841              :          realignment_token = call target_builtin;
   10842              :          indx = 0;
   10843              :          loop {
   10844              :            p2 = p2 + indx * vectype_size
   10845              :            lsq = *(floor(p2))
   10846              :            vec_dest = realign_load (msq, lsq, realignment_token)
   10847              :            indx = indx + 1;
   10848              :            msq = lsq;
   10849              :          }   */
   10850              : 
   10851              :   /* If the misalignment remains the same throughout the execution of the
   10852              :      loop, we can create the init_addr and permutation mask at the loop
   10853              :      preheader.  Otherwise, it needs to be created inside the loop.
   10854              :      This can only occur when vectorizing memory accesses in the inner-loop
   10855              :      nested within an outer-loop that is being vectorized.  */
   10856              : 
   10857       601724 :   if (nested_in_vect_loop
   10858       601724 :       && !multiple_p (DR_STEP_ALIGNMENT (dr_info->dr),
   10859         1240 :                       GET_MODE_SIZE (TYPE_MODE (vectype))))
   10860              :     {
   10861          195 :       gcc_assert (alignment_support_scheme != dr_explicit_realign_optimized);
   10862              :       compute_in_loop = true;
   10863              :     }
   10864              : 
   10865       601724 :   bool diff_first_stmt_info
   10866       601724 :     = first_stmt_info_for_drptr && first_stmt_info != first_stmt_info_for_drptr;
   10867              : 
   10868       601724 :   tree offset = NULL_TREE;
   10869       601724 :   if ((alignment_support_scheme == dr_explicit_realign_optimized
   10870       601724 :        || alignment_support_scheme == dr_explicit_realign)
   10871            0 :       && !compute_in_loop)
   10872              :     {
   10873              :       /* If we have different first_stmt_info, we can't set up realignment
   10874              :          here, since we can't guarantee first_stmt_info DR has been
   10875              :          initialized yet, use first_stmt_info_for_drptr DR by bumping the
   10876              :          distance from first_stmt_info DR instead as below.  */
   10877            0 :       if (!costing_p)
   10878              :         {
   10879            0 :           if (!diff_first_stmt_info)
   10880            0 :             msq = vect_setup_realignment (vinfo, first_stmt_info, vectype, gsi,
   10881              :                                           &realignment_token,
   10882              :                                           alignment_support_scheme, NULL_TREE,
   10883              :                                           &at_loop);
   10884            0 :           if (alignment_support_scheme == dr_explicit_realign_optimized)
   10885              :             {
   10886            0 :               phi = as_a<gphi *> (SSA_NAME_DEF_STMT (msq));
   10887            0 :               offset = size_binop (MINUS_EXPR, TYPE_SIZE_UNIT (vectype),
   10888              :                                    size_one_node);
   10889            0 :               gcc_assert (!first_stmt_info_for_drptr);
   10890              :             }
   10891              :         }
   10892              :     }
   10893              :   else
   10894       601724 :     at_loop = loop;
   10895              : 
   10896       601724 :   if (!known_eq (poffset, 0))
   10897         4911 :     offset = (offset
   10898         4911 :               ? size_binop (PLUS_EXPR, offset, size_int (poffset))
   10899         4911 :               : size_int (poffset));
   10900              : 
   10901       601724 :   tree dr_increment;
   10902       601724 :   tree dr_bump;
   10903       601724 :   tree vec_offset = NULL_TREE;
   10904              : 
   10905       601724 :   auto_vec<tree> vec_offsets;
   10906       601724 :   auto_vec<tree> vec_masks;
   10907       601724 :   if (mask_node && !costing_p)
   10908          644 :     vect_get_slp_defs (SLP_TREE_CHILDREN (slp_node)[mask_index],
   10909              :                        &vec_masks);
   10910              : 
   10911       601724 :   tree vec_mask = NULL_TREE;
   10912       601724 :   tree vec_els = NULL_TREE;
   10913       601724 :   if (memory_access_type == VMAT_LOAD_STORE_LANES)
   10914              :     {
   10915            0 :       const internal_fn lanes_ifn = ls.lanes_ifn;
   10916              : 
   10917            0 :       gcc_assert (alignment_support_scheme == dr_aligned
   10918              :                   || alignment_support_scheme == dr_unaligned_supported);
   10919              : 
   10920            0 :       aggr_type = build_array_type_nelts (elem_type, group_size * nunits);
   10921            0 :       if (!costing_p)
   10922              :         {
   10923            0 :           dr_increment = vect_get_data_ptr_step (vinfo, dr_info,
   10924              :                                                       memory_access_type);
   10925            0 :           dr_bump = vect_get_data_ptr_bump (vinfo, dr_info, aggr_type,
   10926              :                                             memory_access_type);
   10927              :         }
   10928              : 
   10929            0 :       unsigned int inside_cost = 0, prologue_cost = 0;
   10930              :       /* For costing some adjacent vector loads, we'd like to cost with
   10931              :          the total number of them once instead of cost each one by one. */
   10932            0 :       unsigned int n_adjacent_loads = 0;
   10933            0 :       int ncopies = vec_num / group_size;
   10934            0 :       for (j = 0; j < ncopies; j++)
   10935              :         {
   10936            0 :           if (costing_p)
   10937              :             {
   10938              :               /* An IFN_LOAD_LANES will load all its vector results,
   10939              :                  regardless of which ones we actually need.  Account
   10940              :                  for the cost of unused results.  */
   10941            0 :               if (first_stmt_info == stmt_info)
   10942              :                 {
   10943            0 :                   unsigned int gaps = DR_GROUP_SIZE (first_stmt_info);
   10944            0 :                   stmt_vec_info next_stmt_info = first_stmt_info;
   10945            0 :                   do
   10946              :                     {
   10947            0 :                       gaps -= 1;
   10948            0 :                       next_stmt_info = DR_GROUP_NEXT_ELEMENT (next_stmt_info);
   10949              :                     }
   10950            0 :                   while (next_stmt_info);
   10951            0 :                   if (gaps)
   10952              :                     {
   10953            0 :                       if (dump_enabled_p ())
   10954            0 :                         dump_printf_loc (MSG_NOTE, vect_location,
   10955              :                                          "vect_model_load_cost: %d "
   10956              :                                          "unused vectors.\n",
   10957              :                                          gaps);
   10958            0 :                       vect_get_load_cost (vinfo, stmt_info, slp_node, gaps,
   10959              :                                           alignment_support_scheme,
   10960              :                                           misalignment, false, &inside_cost,
   10961              :                                           &prologue_cost, cost_vec, cost_vec,
   10962              :                                           true);
   10963              :                     }
   10964              :                 }
   10965            0 :               n_adjacent_loads++;
   10966            0 :               continue;
   10967            0 :             }
   10968              : 
   10969              :           /* 1. Create the vector or array pointer update chain.  */
   10970            0 :           if (j == 0)
   10971            0 :             dataref_ptr
   10972            0 :               = vect_create_data_ref_ptr (vinfo, first_stmt_info, aggr_type,
   10973              :                                           at_loop, offset, &dummy, gsi,
   10974              :                                           NULL, false, dr_increment);
   10975              :           else
   10976              :             {
   10977            0 :               gcc_assert (!LOOP_VINFO_USING_SELECT_VL_P (loop_vinfo));
   10978            0 :               dataref_ptr = bump_vector_ptr (vinfo, dataref_ptr, gsi,
   10979              :                                              stmt_info, dr_bump);
   10980              :             }
   10981            0 :           if (mask_node)
   10982            0 :             vec_mask = vec_masks[j];
   10983              : 
   10984            0 :           tree vec_array = create_vector_array (vectype, group_size);
   10985              : 
   10986            0 :           tree final_mask = NULL_TREE;
   10987            0 :           tree final_len = NULL_TREE;
   10988            0 :           tree bias = NULL_TREE;
   10989            0 :           if (masks_p)
   10990            0 :             final_mask
   10991            0 :               = vect_get_mask (loop_vinfo, gsi, ncopies, vectype, j);
   10992            0 :           if (vec_mask)
   10993            0 :             final_mask = prepare_vec_mask (loop_vinfo, mask_vectype, final_mask,
   10994              :                                            vec_mask, gsi);
   10995              : 
   10996            0 :           if (lanes_ifn == IFN_MASK_LEN_LOAD_LANES)
   10997              :             {
   10998            0 :               if (lens_p)
   10999            0 :                 final_len
   11000            0 :                   = vect_get_len (loop_vinfo, gsi, ncopies, vectype, j, 1, true);
   11001              :               else
   11002            0 :                 final_len = size_int (TYPE_VECTOR_SUBPARTS (vectype));
   11003            0 :               signed char biasval
   11004            0 :                 = LOOP_VINFO_PARTIAL_LOAD_STORE_BIAS (loop_vinfo);
   11005            0 :               bias = build_int_cst (intQI_type_node, biasval);
   11006            0 :               if (!final_mask)
   11007              :                 {
   11008            0 :                   mask_vectype = truth_type_for (vectype);
   11009            0 :                   final_mask = build_minus_one_cst (mask_vectype);
   11010              :                 }
   11011              :             }
   11012              : 
   11013            0 :           if (final_mask)
   11014              :             {
   11015            0 :               vec_els = vect_get_mask_load_else (maskload_elsval, vectype);
   11016            0 :               if (type_mode_padding_p
   11017            0 :                   && maskload_elsval != MASK_LOAD_ELSE_ZERO)
   11018            0 :                 need_zeroing = true;
   11019              :             }
   11020              : 
   11021            0 :           gcall *call;
   11022            0 :           if (final_len && final_mask)
   11023              :             {
   11024              :               /* Emit:
   11025              :                    VEC_ARRAY = MASK_LEN_LOAD_LANES (DATAREF_PTR, ALIAS_PTR,
   11026              :                                                     VEC_MASK, LEN, BIAS).  */
   11027            0 :               unsigned int align = TYPE_ALIGN (TREE_TYPE (vectype));
   11028            0 :               tree alias_ptr = build_int_cst (ref_type, align);
   11029            0 :               call = gimple_build_call_internal (IFN_MASK_LEN_LOAD_LANES, 6,
   11030              :                                                  dataref_ptr, alias_ptr,
   11031              :                                                  final_mask, vec_els,
   11032              :                                                  final_len, bias);
   11033              :             }
   11034            0 :           else if (final_mask)
   11035              :             {
   11036              :               /* Emit:
   11037              :                    VEC_ARRAY = MASK_LOAD_LANES (DATAREF_PTR, ALIAS_PTR,
   11038              :                                                 VEC_MASK).  */
   11039            0 :               unsigned int align = TYPE_ALIGN (TREE_TYPE (vectype));
   11040            0 :               tree alias_ptr = build_int_cst (ref_type, align);
   11041            0 :               call = gimple_build_call_internal (IFN_MASK_LOAD_LANES, 4,
   11042              :                                                  dataref_ptr, alias_ptr,
   11043              :                                                  final_mask, vec_els);
   11044              :             }
   11045              :           else
   11046              :             {
   11047              :               /* Emit:
   11048              :                    VEC_ARRAY = LOAD_LANES (MEM_REF[...all elements...]).  */
   11049            0 :               data_ref = create_array_ref (aggr_type, dataref_ptr, ref_type);
   11050            0 :               call = gimple_build_call_internal (IFN_LOAD_LANES, 1, data_ref);
   11051              :             }
   11052            0 :           gimple_call_set_lhs (call, vec_array);
   11053            0 :           gimple_call_set_nothrow (call, true);
   11054            0 :           vect_finish_stmt_generation (vinfo, stmt_info, call, gsi);
   11055              : 
   11056              :           /* Extract each vector into an SSA_NAME.  */
   11057            0 :           for (unsigned i = 0; i < group_size; i++)
   11058              :             {
   11059            0 :               new_temp = read_vector_array (vinfo, stmt_info, gsi, scalar_dest,
   11060              :                                             vec_array, i, need_zeroing,
   11061              :                                             final_mask);
   11062            0 :               slp_node->push_vec_def (new_temp);
   11063              :             }
   11064              : 
   11065              :           /* Record that VEC_ARRAY is now dead.  */
   11066            0 :           vect_clobber_variable (vinfo, stmt_info, gsi, vec_array);
   11067              :         }
   11068              : 
   11069            0 :       if (costing_p)
   11070              :         {
   11071            0 :           if (n_adjacent_loads > 0)
   11072            0 :             vect_get_load_cost (vinfo, stmt_info, slp_node, n_adjacent_loads,
   11073              :                                 alignment_support_scheme, misalignment, false,
   11074              :                                 &inside_cost, &prologue_cost, cost_vec,
   11075              :                                 cost_vec, true);
   11076            0 :           if (dump_enabled_p ())
   11077            0 :             dump_printf_loc (MSG_NOTE, vect_location,
   11078              :                              "vect_model_load_cost: inside_cost = %u, "
   11079              :                              "prologue_cost = %u .\n",
   11080              :                              inside_cost, prologue_cost);
   11081            0 :           SLP_TREE_TYPE (slp_node) = load_vec_info_type;
   11082            0 :           slp_node->data = new vect_load_store_data (std::move (ls));
   11083              :         }
   11084              : 
   11085            0 :       return true;
   11086              :     }
   11087              : 
   11088       601724 :   if (mat_gather_scatter_p (memory_access_type))
   11089              :     {
   11090         3178 :       gcc_assert ((!grouped_load && !ls.slp_perm) || ls.ls_type);
   11091              : 
   11092         3178 :       auto_vec<tree> dr_chain (vec_num);
   11093              : 
   11094              :       /* If we pun the original vectype the loads as well as costing, length,
   11095              :          etc. is performed with the new type.  After loading we VIEW_CONVERT
   11096              :          the data to the original vectype.  */
   11097         3178 :       tree original_vectype = vectype;
   11098         3178 :       if (ls.ls_type)
   11099            0 :         vectype = ls.ls_type;
   11100              : 
   11101              :       /* 1. Create the vector or array pointer update chain.  */
   11102         3178 :       if (STMT_VINFO_GATHER_SCATTER_P (stmt_info))
   11103              :         {
   11104         3178 :           aggr_type = NULL_TREE;
   11105         3178 :           dr_increment = NULL_TREE;
   11106         3178 :           if (!costing_p)
   11107          882 :             vect_get_gather_scatter_ops (loop, slp_node, &dataref_ptr,
   11108              :                                          &vec_offsets);
   11109              :         }
   11110              :       else
   11111              :         {
   11112            0 :           aggr_type = elem_type;
   11113            0 :           if (!costing_p)
   11114              :             {
   11115            0 :               vect_get_strided_load_store_ops (stmt_info, slp_node, vectype,
   11116              :                                                ls.strided_offset_vectype,
   11117              :                                                loop_vinfo, gsi,
   11118              :                                                &dr_increment, &dr_bump,
   11119              :                                                &vec_offset);
   11120            0 :               dataref_ptr
   11121            0 :                   = vect_create_data_ref_ptr (vinfo, first_stmt_info, aggr_type,
   11122              :                                               at_loop, offset, &dummy, gsi,
   11123              :                                               NULL, false, dr_increment);
   11124              :             }
   11125              :         }
   11126              : 
   11127         3178 :       unsigned int inside_cost = 0, prologue_cost = 0;
   11128              : 
   11129         3178 :       gimple *new_stmt = NULL;
   11130         7126 :       for (i = 0; i < vec_num; i++)
   11131              :         {
   11132         3948 :           tree final_mask = NULL_TREE;
   11133         3948 :           tree final_len = NULL_TREE;
   11134         3948 :           tree bias = NULL_TREE;
   11135         3948 :           if (!costing_p)
   11136              :             {
   11137         1089 :               if (mask_node)
   11138          148 :                 vec_mask = vec_masks[i];
   11139         1089 :               if (masks_p)
   11140            0 :                 final_mask
   11141            0 :                   = vect_get_mask (loop_vinfo, gsi, vec_num, vectype, i);
   11142         1089 :               if (vec_mask)
   11143          148 :                 final_mask = prepare_vec_mask (loop_vinfo, mask_vectype,
   11144              :                                                final_mask, vec_mask, gsi);
   11145              : 
   11146         1089 :               if (i > 0 && !STMT_VINFO_GATHER_SCATTER_P (stmt_info))
   11147            0 :                 dataref_ptr = bump_vector_ptr (vinfo, dataref_ptr, gsi,
   11148              :                                                stmt_info, dr_bump);
   11149              :             }
   11150              : 
   11151              :           /* 2. Create the vector-load in the loop.  */
   11152         3948 :           unsigned align = get_object_alignment (DR_REF (first_dr_info->dr));
   11153         3948 :           tree alias_align_ptr = build_int_cst (ref_type, align);
   11154         3948 :           if (memory_access_type == VMAT_GATHER_SCATTER_IFN)
   11155              :             {
   11156            0 :               if (costing_p)
   11157              :                 {
   11158            0 :                   if (ls.supported_offset_vectype
   11159            0 :                       && !tree_nop_conversion_p (ls.supported_offset_vectype,
   11160              :                                                  vec_offset))
   11161            0 :                     inside_cost
   11162            0 :                       += record_stmt_cost (cost_vec, 1, vector_stmt,
   11163              :                                            slp_node, 0, vect_body);
   11164            0 :                   if (ls.supported_scale)
   11165            0 :                     inside_cost
   11166            0 :                       += record_stmt_cost (cost_vec, 1, vector_stmt,
   11167              :                                            slp_node, 0, vect_body);
   11168              : 
   11169            0 :                   unsigned int cnunits = vect_nunits_for_cost (vectype);
   11170            0 :                   inside_cost
   11171            0 :                     = record_stmt_cost (cost_vec, cnunits, scalar_load,
   11172              :                                         slp_node, 0, vect_body);
   11173            0 :                   continue;
   11174            0 :                 }
   11175            0 :               if (STMT_VINFO_GATHER_SCATTER_P (stmt_info))
   11176            0 :                 vec_offset = vec_offsets[i];
   11177            0 :               tree zero = build_zero_cst (vectype);
   11178            0 :               tree scale = size_int (SLP_TREE_GS_SCALE (slp_node));
   11179            0 :               bool strided = !VECTOR_TYPE_P (TREE_TYPE (vec_offset));
   11180              : 
   11181              :               /* Perform the offset conversion and scaling if necessary.  */
   11182            0 :               if (!strided
   11183            0 :                   && (ls.supported_offset_vectype || ls.supported_scale))
   11184              :                 {
   11185            0 :                   gimple_seq stmts = NULL;
   11186            0 :                   if (ls.supported_offset_vectype)
   11187            0 :                     vec_offset = gimple_convert
   11188            0 :                       (&stmts, ls.supported_offset_vectype, vec_offset);
   11189            0 :                   if (ls.supported_scale)
   11190              :                     {
   11191              :                       /* Only scale the vec_offset if we haven't already.  */
   11192            0 :                       if (STMT_VINFO_GATHER_SCATTER_P (stmt_info)
   11193            0 :                           || i == 0)
   11194              :                         {
   11195            0 :                           tree mult_cst = build_int_cst
   11196            0 :                             (TREE_TYPE (TREE_TYPE (vec_offset)),
   11197            0 :                              SLP_TREE_GS_SCALE (slp_node) / ls.supported_scale);
   11198            0 :                           tree mult = build_vector_from_val
   11199            0 :                             (TREE_TYPE (vec_offset), mult_cst);
   11200            0 :                           vec_offset = gimple_build
   11201            0 :                             (&stmts, MULT_EXPR, TREE_TYPE (vec_offset),
   11202              :                              vec_offset, mult);
   11203              :                         }
   11204            0 :                       scale = size_int (ls.supported_scale);
   11205              :                     }
   11206            0 :                   gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
   11207              :                 }
   11208              : 
   11209            0 :               if (ls.gs.ifn == IFN_MASK_LEN_GATHER_LOAD)
   11210              :                 {
   11211            0 :                   if (lens_p)
   11212            0 :                     final_len = vect_get_len (loop_vinfo, gsi, vec_num, vectype,
   11213              :                                               i, 1, true);
   11214              :                   else
   11215            0 :                     final_len = build_int_cst (sizetype,
   11216            0 :                                                TYPE_VECTOR_SUBPARTS (vectype));
   11217            0 :                   signed char biasval
   11218            0 :                     = LOOP_VINFO_PARTIAL_LOAD_STORE_BIAS (loop_vinfo);
   11219            0 :                   bias = build_int_cst (intQI_type_node, biasval);
   11220            0 :                   if (!final_mask)
   11221              :                     {
   11222            0 :                       mask_vectype = truth_type_for (vectype);
   11223            0 :                       final_mask = build_minus_one_cst (mask_vectype);
   11224              :                     }
   11225              :                 }
   11226              : 
   11227            0 :               if (final_mask)
   11228              :                 {
   11229            0 :                   vec_els = vect_get_mask_load_else (maskload_elsval, vectype);
   11230            0 :                   if (type_mode_padding_p
   11231            0 :                       && maskload_elsval != MASK_LOAD_ELSE_ZERO)
   11232            0 :                     need_zeroing = true;
   11233              :                 }
   11234              : 
   11235            0 :               gcall *call;
   11236            0 :               if (final_len && final_mask)
   11237              :                 {
   11238            0 :                   if (VECTOR_TYPE_P (TREE_TYPE (vec_offset)))
   11239            0 :                     call = gimple_build_call_internal (IFN_MASK_LEN_GATHER_LOAD,
   11240              :                                                        9, dataref_ptr,
   11241              :                                                        alias_align_ptr,
   11242              :                                                        vec_offset, scale, zero,
   11243              :                                                        final_mask, vec_els,
   11244              :                                                        final_len, bias);
   11245              :                   else
   11246              :                     /* Non-vector offset indicates that prefer to take
   11247              :                        MASK_LEN_STRIDED_LOAD instead of the
   11248              :                        MASK_LEN_GATHER_LOAD with direct stride arg.  */
   11249            0 :                     call = gimple_build_call_internal
   11250            0 :                              (IFN_MASK_LEN_STRIDED_LOAD, 7, dataref_ptr,
   11251              :                               vec_offset, zero, final_mask, vec_els, final_len,
   11252              :                               bias);
   11253              :                 }
   11254            0 :               else if (final_mask)
   11255            0 :                 call = gimple_build_call_internal (IFN_MASK_GATHER_LOAD,
   11256              :                                                    7, dataref_ptr,
   11257              :                                                    alias_align_ptr,
   11258              :                                                    vec_offset, scale,
   11259              :                                                    zero, final_mask, vec_els);
   11260              :               else
   11261            0 :                 call = gimple_build_call_internal (IFN_GATHER_LOAD, 5,
   11262              :                                                    dataref_ptr,
   11263              :                                                    alias_align_ptr,
   11264              :                                                    vec_offset, scale, zero);
   11265            0 :               gimple_call_set_nothrow (call, true);
   11266            0 :               new_stmt = call;
   11267            0 :               data_ref = NULL_TREE;
   11268              :             }
   11269         3948 :           else if (memory_access_type == VMAT_GATHER_SCATTER_LEGACY)
   11270              :             {
   11271              :               /* The builtin decls path for gather is legacy, x86 only.  */
   11272          820 :               gcc_assert (!final_len && nunits.is_constant ());
   11273          820 :               if (costing_p)
   11274              :                 {
   11275          550 :                   unsigned int cnunits = vect_nunits_for_cost (vectype);
   11276          550 :                   inside_cost
   11277          550 :                     = record_stmt_cost (cost_vec, cnunits, scalar_load,
   11278              :                                         slp_node, 0, vect_body);
   11279          550 :                   continue;
   11280          550 :                 }
   11281          270 :               tree offset_vectype = TREE_TYPE (vec_offsets[0]);
   11282          270 :               poly_uint64 offset_nunits = TYPE_VECTOR_SUBPARTS (offset_vectype);
   11283          270 :               if (known_eq (nunits, offset_nunits))
   11284              :                 {
   11285          133 :                   new_stmt = vect_build_one_gather_load_call
   11286          133 :                                (vinfo, stmt_info, slp_node, vectype, gsi,
   11287          133 :                                 ls.gs.decl, dataref_ptr, vec_offsets[i],
   11288              :                                 final_mask);
   11289          133 :                   data_ref = NULL_TREE;
   11290              :                 }
   11291          137 :               else if (known_eq (nunits, offset_nunits * 2))
   11292              :                 {
   11293              :                   /* We have a offset vector with half the number of
   11294              :                      lanes but the builtins will produce full vectype
   11295              :                      data with just the lower lanes filled.  */
   11296           59 :                   new_stmt = vect_build_one_gather_load_call
   11297          118 :                                (vinfo, stmt_info, slp_node, vectype, gsi,
   11298           59 :                                 ls.gs.decl, dataref_ptr, vec_offsets[2 * i],
   11299              :                                 final_mask);
   11300           59 :                   tree low = make_ssa_name (vectype);
   11301           59 :                   gimple_set_lhs (new_stmt, low);
   11302           59 :                   vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
   11303              : 
   11304              :                   /* now put upper half of final_mask in final_mask low. */
   11305           59 :                   if (final_mask
   11306           59 :                       && !SCALAR_INT_MODE_P (TYPE_MODE (TREE_TYPE (final_mask))))
   11307              :                     {
   11308           11 :                       int count = nunits.to_constant ();
   11309           11 :                       vec_perm_builder sel (count, count, 1);
   11310           11 :                       sel.quick_grow (count);
   11311           98 :                       for (int i = 0; i < count; ++i)
   11312           76 :                         sel[i] = i | (count / 2);
   11313           11 :                       vec_perm_indices indices (sel, 2, count);
   11314           11 :                       tree perm_mask = vect_gen_perm_mask_checked
   11315           11 :                                          (TREE_TYPE (final_mask), indices);
   11316           11 :                       new_stmt = gimple_build_assign (NULL_TREE, VEC_PERM_EXPR,
   11317              :                                                       final_mask, final_mask,
   11318              :                                                       perm_mask);
   11319           11 :                       final_mask = make_ssa_name (TREE_TYPE (final_mask));
   11320           11 :                       gimple_set_lhs (new_stmt, final_mask);
   11321           11 :                       vect_finish_stmt_generation (vinfo, stmt_info,
   11322              :                                                    new_stmt, gsi);
   11323           11 :                     }
   11324           48 :                   else if (final_mask)
   11325              :                     {
   11326           24 :                       new_stmt = gimple_build_assign (NULL_TREE,
   11327              :                                                       VEC_UNPACK_HI_EXPR,
   11328              :                                                       final_mask);
   11329           24 :                       final_mask = make_ssa_name
   11330           24 :                                     (truth_type_for (offset_vectype));
   11331           24 :                       gimple_set_lhs (new_stmt, final_mask);
   11332           24 :                       vect_finish_stmt_generation (vinfo, stmt_info,
   11333              :                                                    new_stmt, gsi);
   11334              :                     }
   11335              : 
   11336           59 :                   new_stmt = vect_build_one_gather_load_call
   11337          118 :                                (vinfo, stmt_info, slp_node, vectype, gsi,
   11338              :                                 ls.gs.decl, dataref_ptr,
   11339           59 :                                 vec_offsets[2 * i + 1], final_mask);
   11340           59 :                   tree high = make_ssa_name (vectype);
   11341           59 :                   gimple_set_lhs (new_stmt, high);
   11342           59 :                   vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
   11343              : 
   11344              :                   /* compose low + high.  */
   11345           59 :                   int count = nunits.to_constant ();
   11346           59 :                   vec_perm_builder sel (count, count, 1);
   11347           59 :                   sel.quick_grow (count);
   11348          686 :                   for (int i = 0; i < count; ++i)
   11349          568 :                     sel[i] = i < count / 2 ? i : i + count / 2;
   11350           59 :                   vec_perm_indices indices (sel, 2, count);
   11351           59 :                   tree perm_mask
   11352           59 :                     = vect_gen_perm_mask_checked (vectype, indices);
   11353           59 :                   new_stmt = gimple_build_assign (NULL_TREE, VEC_PERM_EXPR,
   11354              :                                                   low, high, perm_mask);
   11355           59 :                   data_ref = NULL_TREE;
   11356           59 :                 }
   11357           78 :               else if (known_eq (nunits * 2, offset_nunits))
   11358              :                 {
   11359              :                   /* We have a offset vector with double the number of
   11360              :                      lanes.  Select the low/high part accordingly.  */
   11361           78 :                   vec_offset = vec_offsets[i / 2];
   11362           78 :                   if (i & 1)
   11363              :                     {
   11364           39 :                       int count = offset_nunits.to_constant ();
   11365           39 :                       vec_perm_builder sel (count, count, 1);
   11366           39 :                       sel.quick_grow (count);
   11367          474 :                       for (int i = 0; i < count; ++i)
   11368          396 :                         sel[i] = i | (count / 2);
   11369           39 :                       vec_perm_indices indices (sel, 2, count);
   11370           39 :                       tree perm_mask = vect_gen_perm_mask_checked
   11371           39 :                                          (TREE_TYPE (vec_offset), indices);
   11372           39 :                       new_stmt = gimple_build_assign (NULL_TREE, VEC_PERM_EXPR,
   11373              :                                                       vec_offset, vec_offset,
   11374              :                                                       perm_mask);
   11375           39 :                       vec_offset = make_ssa_name (TREE_TYPE (vec_offset));
   11376           39 :                       gimple_set_lhs (new_stmt, vec_offset);
   11377           39 :                       vect_finish_stmt_generation (vinfo, stmt_info,
   11378              :                                                    new_stmt, gsi);
   11379           39 :                     }
   11380           78 :                   new_stmt = vect_build_one_gather_load_call
   11381           78 :                                (vinfo, stmt_info, slp_node, vectype, gsi,
   11382              :                                 ls.gs.decl,
   11383              :                                 dataref_ptr, vec_offset, final_mask);
   11384           78 :                   data_ref = NULL_TREE;
   11385              :                 }
   11386              :               else
   11387            0 :                 gcc_unreachable ();
   11388              :             }
   11389              :           else
   11390              :             {
   11391              :               /* Emulated gather-scatter.  */
   11392         3128 :               gcc_assert (!final_mask);
   11393         3128 :               unsigned HOST_WIDE_INT const_nunits = nunits.to_constant ();
   11394         3128 :               if (costing_p)
   11395              :                 {
   11396         2309 :                   if (ls.gs_offset_uniform_p)
   11397              :                     {
   11398           25 :                       if (dump_enabled_p ())
   11399           25 :                         dump_printf_loc (MSG_NOTE, vect_location,
   11400              :                                          "computing cost for broadcast\n");
   11401              :                       /* Broadcast optimization: 1 extract + 1 load
   11402              :                          + 1 broadcast.  */
   11403           25 :                       inside_cost = record_stmt_cost (cost_vec, 1,
   11404              :                                                       vec_to_scalar, slp_node,
   11405              :                                                       0, vect_body);
   11406           25 :                       inside_cost += record_stmt_cost (cost_vec, 1, scalar_load,
   11407              :                                                        slp_node, 0, vect_body);
   11408           25 :                       inside_cost += record_stmt_cost (cost_vec, 1,
   11409              :                                                        scalar_to_vec, slp_node,
   11410              :                                                        0, vect_body);
   11411              :                     }
   11412              :                   else
   11413              :                     {
   11414              :                       /* For emulated gathers N offset vector element
   11415              :                          offset add is consumed by the load).  */
   11416         2284 :                       inside_cost = record_stmt_cost (cost_vec, 1,
   11417              :                                                       vec_deconstruct, slp_node,
   11418              :                                                       0, vect_body);
   11419              :                       /* N scalar loads plus gathering them into a
   11420              :                          vector.  */
   11421         2284 :                       inside_cost
   11422         2284 :                         = record_stmt_cost (cost_vec, const_nunits, scalar_load,
   11423              :                                             slp_node, 0, vect_body);
   11424         2284 :                       inside_cost
   11425         2284 :                         = record_stmt_cost (cost_vec, 1, vec_construct,
   11426              :                                             slp_node, 0, vect_body);
   11427              :                     }
   11428         2309 :                   continue;
   11429              :                 }
   11430          819 :               tree offset_vectype = TREE_TYPE (vec_offsets[0]);
   11431          819 :               unsigned HOST_WIDE_INT const_offset_nunits
   11432          819 :                 = TYPE_VECTOR_SUBPARTS (offset_vectype).to_constant ();
   11433          819 :               vec<constructor_elt, va_gc> *ctor_elts;
   11434          819 :               vec_alloc (ctor_elts, const_nunits);
   11435          819 :               gimple_seq stmts = NULL;
   11436              :               /* We support offset vectors with more elements
   11437              :                  than the data vector for now.  */
   11438          819 :               unsigned HOST_WIDE_INT factor
   11439              :                 = const_offset_nunits / const_nunits;
   11440          819 :               vec_offset = vec_offsets[i / factor];
   11441          819 :               unsigned elt_offset = (i % factor) * const_nunits;
   11442          819 :               tree idx_type = TREE_TYPE (TREE_TYPE (vec_offset));
   11443          819 :               tree scale = size_int (SLP_TREE_GS_SCALE (slp_node));
   11444          819 :               tree ltype = build_aligned_type (TREE_TYPE (vectype), align);
   11445         4124 :               for (unsigned k = 0; k < const_nunits; ++k)
   11446              :                 {
   11447         2486 :                   tree elt;
   11448              :                   /* If all lanes are uniform then generate broadcast otherwise
   11449              :                      emulated gathers.  */
   11450         2486 :                   if (ls.gs_offset_uniform_p && k > 0)
   11451           63 :                     elt = (*ctor_elts)[0].value;
   11452              :                   else
   11453              :                     {
   11454         2423 :                       tree boff = size_binop (MULT_EXPR, TYPE_SIZE (idx_type),
   11455              :                                               bitsize_int (k + elt_offset));
   11456         7269 :                       tree idx = gimple_build (&stmts, BIT_FIELD_REF, idx_type,
   11457         2423 :                                                vec_offset, TYPE_SIZE (idx_type),
   11458              :                                                boff);
   11459         2423 :                       idx = gimple_convert (&stmts, sizetype, idx);
   11460         2423 :                       idx = gimple_build (&stmts, MULT_EXPR, sizetype, idx,
   11461              :                                           scale);
   11462         2423 :                       tree ptr = gimple_build (&stmts, PLUS_EXPR,
   11463         2423 :                                                TREE_TYPE (dataref_ptr),
   11464              :                                                dataref_ptr, idx);
   11465         2423 :                       ptr = gimple_convert (&stmts, ptr_type_node, ptr);
   11466         2423 :                       elt = make_ssa_name (TREE_TYPE (vectype));
   11467         2423 :                       tree ref = build2 (MEM_REF, ltype, ptr,
   11468              :                                          build_int_cst (ref_type, 0));
   11469         2423 :                       new_stmt = gimple_build_assign (elt, ref);
   11470         4846 :                       gimple_set_vuse (new_stmt, gimple_vuse (gsi_stmt (*gsi)));
   11471         2423 :                       gimple_seq_add_stmt (&stmts, new_stmt);
   11472              :                     }
   11473         2486 :                   CONSTRUCTOR_APPEND_ELT (ctor_elts, NULL_TREE, elt);
   11474              :                 }
   11475          819 :               gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
   11476          819 :               new_stmt = gimple_build_assign (NULL_TREE,
   11477              :                                               build_constructor (vectype,
   11478              :                                                                  ctor_elts));
   11479          819 :               data_ref = NULL_TREE;
   11480              :             }
   11481              : 
   11482         1089 :           vec_dest = vect_create_destination_var (scalar_dest, vectype);
   11483              :           /* DATA_REF is null if we've already built the statement.  */
   11484         1089 :           if (data_ref)
   11485              :             {
   11486              :               vect_copy_ref_info (data_ref, first_stmt_info);
   11487              :               new_stmt = gimple_build_assign (vec_dest, data_ref);
   11488              :             }
   11489         2178 :           new_temp = (need_zeroing
   11490         1089 :                       ? make_ssa_name (vectype)
   11491         1089 :                       : make_ssa_name (vec_dest, new_stmt));
   11492         1089 :           gimple_set_lhs (new_stmt, new_temp);
   11493         1089 :           vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
   11494              : 
   11495              :           /* If we need to explicitly zero inactive elements emit a
   11496              :              VEC_COND_EXPR that does so.  */
   11497         1089 :           if (need_zeroing)
   11498              :             {
   11499            0 :               vec_els = vect_get_mask_load_else (MASK_LOAD_ELSE_ZERO,
   11500              :                                                  vectype);
   11501              : 
   11502            0 :               tree new_temp2 = make_ssa_name (vec_dest, new_stmt);
   11503            0 :               new_stmt = gimple_build_assign (new_temp2, VEC_COND_EXPR,
   11504              :                                               final_mask, new_temp, vec_els);
   11505            0 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
   11506            0 :               new_temp = new_temp2;
   11507              :             }
   11508              : 
   11509         1089 :           if (ls.ls_type)
   11510              :             {
   11511            0 :               new_stmt = gimple_build_assign (make_ssa_name
   11512              :                                               (original_vectype),
   11513              :                                               VIEW_CONVERT_EXPR,
   11514              :                                               build1 (VIEW_CONVERT_EXPR,
   11515              :                                                       original_vectype,
   11516              :                                                       new_temp));
   11517            0 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
   11518              :             }
   11519              : 
   11520              :           /* Store vector loads in the corresponding SLP_NODE.  */
   11521         1089 :           if (!costing_p)
   11522              :             {
   11523         1089 :               if (ls.slp_perm)
   11524            0 :                 dr_chain.quick_push (gimple_assign_lhs (new_stmt));
   11525              :               else
   11526         1089 :                 slp_node->push_vec_def (new_stmt);
   11527              :             }
   11528              :         }
   11529              : 
   11530         3178 :       if (ls.slp_perm)
   11531              :         {
   11532            0 :           if (costing_p)
   11533              :             {
   11534            0 :               gcc_assert (ls.n_perms != -1U);
   11535            0 :               inside_cost += record_stmt_cost (cost_vec, ls.n_perms, vec_perm,
   11536              :                                                slp_node, 0, vect_body);
   11537              :             }
   11538              :           else
   11539              :             {
   11540            0 :               unsigned n_perms2;
   11541            0 :               vect_transform_slp_perm_load (vinfo, slp_node, dr_chain, gsi, vf,
   11542              :                                             false, &ls, &n_perms2);
   11543            0 :               gcc_assert (ls.n_perms == n_perms2);
   11544              :             }
   11545              :         }
   11546              : 
   11547         3178 :       if (costing_p)
   11548              :         {
   11549         2296 :           if (dump_enabled_p ())
   11550          419 :             dump_printf_loc (MSG_NOTE, vect_location,
   11551              :                              "vect_model_load_cost: inside_cost = %u, "
   11552              :                              "prologue_cost = %u .\n",
   11553              :                              inside_cost, prologue_cost);
   11554         2296 :           SLP_TREE_TYPE (slp_node) = load_vec_info_type;
   11555         2296 :           slp_node->data = new vect_load_store_data (std::move (ls));
   11556              :         }
   11557         3178 :       return true;
   11558         3178 :     }
   11559              : 
   11560       598546 :   gcc_assert (memory_access_type == VMAT_CONTIGUOUS
   11561              :               || memory_access_type == VMAT_CONTIGUOUS_REVERSE);
   11562              : 
   11563       598546 :   aggr_type = vectype;
   11564       598546 :   if (!costing_p)
   11565              :     {
   11566       154872 :       dr_increment = vect_get_data_ptr_step (vinfo, dr_info,
   11567              :                                                   memory_access_type);
   11568       154872 :       dr_bump = vect_get_data_ptr_bump (vinfo, dr_info, aggr_type,
   11569              :                                         memory_access_type);
   11570              :     }
   11571              : 
   11572       598546 :   poly_uint64 group_elt = 0;
   11573       598546 :   unsigned int inside_cost = 0, prologue_cost = 0;
   11574              :   /* For costing some adjacent vector loads, we'd like to cost with
   11575              :      the total number of them once instead of cost each one by one. */
   11576       598546 :   unsigned int n_adjacent_loads = 0;
   11577              : 
   11578              :   /* 1. Create the vector or array pointer update chain.  */
   11579       598546 :   if (!costing_p)
   11580              :     {
   11581       154872 :       bool simd_lane_access_p
   11582       154872 :           = STMT_VINFO_SIMD_LANE_ACCESS_P (stmt_info) != 0;
   11583       154872 :       if (simd_lane_access_p
   11584         1831 :           && TREE_CODE (DR_BASE_ADDRESS (first_dr_info->dr)) == ADDR_EXPR
   11585         1831 :           && VAR_P (TREE_OPERAND (DR_BASE_ADDRESS (first_dr_info->dr), 0))
   11586         1831 :           && integer_zerop (get_dr_vinfo_offset (vinfo, first_dr_info))
   11587         1831 :           && integer_zerop (DR_INIT (first_dr_info->dr))
   11588         1831 :           && alias_sets_conflict_p (get_alias_set (aggr_type),
   11589         1831 :                                     get_alias_set (TREE_TYPE (ref_type)))
   11590       154872 :           && (alignment_support_scheme == dr_aligned
   11591         1831 :               || alignment_support_scheme == dr_unaligned_supported))
   11592              :         {
   11593         1831 :           dataref_ptr = unshare_expr (DR_BASE_ADDRESS (first_dr_info->dr));
   11594         1831 :           dataref_offset = build_int_cst (ref_type, 0);
   11595              :         }
   11596       153041 :       else if (diff_first_stmt_info)
   11597              :         {
   11598         3383 :           dataref_ptr
   11599         3383 :             = vect_create_data_ref_ptr (vinfo, first_stmt_info_for_drptr,
   11600              :                                         aggr_type, at_loop, offset, &dummy,
   11601              :                                         gsi, NULL, simd_lane_access_p,
   11602              :                                         dr_increment);
   11603              :           /* Adjust the pointer by the difference to first_stmt.  */
   11604         3383 :           data_reference_p ptrdr
   11605              :             = STMT_VINFO_DATA_REF (first_stmt_info_for_drptr);
   11606         3383 :           tree diff = fold_convert (sizetype,
   11607              :                                     size_binop (MINUS_EXPR,
   11608              :                                                 DR_INIT (first_dr_info->dr),
   11609              :                                                 DR_INIT (ptrdr)));
   11610         3383 :           dataref_ptr = bump_vector_ptr (vinfo, dataref_ptr, gsi,
   11611              :                                          stmt_info, diff);
   11612         3383 :           if (alignment_support_scheme == dr_explicit_realign)
   11613              :             {
   11614            0 :               msq = vect_setup_realignment (vinfo, first_stmt_info_for_drptr,
   11615              :                                             vectype, gsi,
   11616              :                                             &realignment_token,
   11617              :                                             alignment_support_scheme,
   11618              :                                             dataref_ptr, &at_loop);
   11619            0 :               gcc_assert (!compute_in_loop);
   11620              :             }
   11621              :         }
   11622              :       else
   11623       149658 :         dataref_ptr
   11624       149658 :           = vect_create_data_ref_ptr (vinfo, first_stmt_info, aggr_type,
   11625              :                                       at_loop,
   11626              :                                       offset, &dummy, gsi, NULL,
   11627              :                                       simd_lane_access_p, dr_increment);
   11628              :     }
   11629              : 
   11630       598546 :   auto_vec<tree> dr_chain;
   11631       598546 :   if (grouped_load || ls.slp_perm)
   11632        59261 :     dr_chain.create (vec_num);
   11633              : 
   11634       598546 :   gimple *new_stmt = NULL;
   11635      1563765 :   for (i = 0; i < vec_num; i++)
   11636              :     {
   11637       965219 :       tree final_mask = NULL_TREE;
   11638       965219 :       tree final_len = NULL_TREE;
   11639       965219 :       tree bias = NULL_TREE;
   11640              : 
   11641       965219 :       if (!costing_p)
   11642              :         {
   11643       244608 :           if (mask_node)
   11644          695 :             vec_mask = vec_masks[i];
   11645       244608 :           if (masks_p)
   11646           58 :             final_mask
   11647           58 :               = vect_get_mask (loop_vinfo, gsi, vec_num, vectype, i);
   11648       244608 :           if (vec_mask)
   11649          695 :             final_mask = prepare_vec_mask (loop_vinfo, mask_vectype,
   11650              :                                            final_mask, vec_mask, gsi);
   11651              : 
   11652       244608 :           if (i > 0)
   11653        89736 :             dataref_ptr = bump_vector_ptr (vinfo, dataref_ptr, gsi, stmt_info,
   11654              :                                            dr_bump);
   11655              :         }
   11656              : 
   11657              :       /* 2. Create the vector-load in the loop.  */
   11658       965219 :       switch (alignment_support_scheme)
   11659              :         {
   11660       965219 :         case dr_aligned:
   11661       965219 :         case dr_unaligned_supported:
   11662       965219 :           {
   11663       965219 :             if (costing_p)
   11664              :               break;
   11665              : 
   11666       244608 :             unsigned int misalign;
   11667       244608 :             unsigned HOST_WIDE_INT align;
   11668       244608 :             align = known_alignment (DR_TARGET_ALIGNMENT (first_dr_info));
   11669       244608 :             if (alignment_support_scheme == dr_aligned)
   11670              :               {
   11671              :                 /* Aligning a whole speculative read window does not give
   11672              :                    each vector load that window's alignment.  */
   11673        85220 :                 if (dr_safe_speculative_read_required (stmt_info))
   11674         2760 :                   align = MIN (align, known_alignment (tree_to_poly_uint64
   11675              :                                               (TYPE_SIZE_UNIT (vectype))));
   11676              :                 misalign = 0;
   11677              :               }
   11678       159388 :             else if (misalignment == DR_MISALIGNMENT_UNKNOWN)
   11679              :               {
   11680       122007 :                 align = dr_alignment (vect_dr_behavior (vinfo, first_dr_info));
   11681       122007 :                 misalign = 0;
   11682              :               }
   11683              :             else
   11684        37381 :               misalign = misalignment;
   11685       244608 :             if (dataref_offset == NULL_TREE
   11686       242231 :                 && TREE_CODE (dataref_ptr) == SSA_NAME)
   11687       176388 :               set_ssa_name_alignment (dataref_ptr, align, misalign);
   11688       244608 :             align = least_bit_hwi (misalign | align);
   11689              : 
   11690              :             /* Compute IFN when LEN_LOOP_P or final_mask valid.  */
   11691       244608 :             machine_mode vmode = TYPE_MODE (vectype);
   11692       244608 :             machine_mode new_vmode = vmode;
   11693       244608 :             internal_fn partial_ifn = IFN_LAST;
   11694       244608 :             if (lens_p)
   11695              :               {
   11696            0 :                 opt_machine_mode new_ovmode
   11697            0 :                   = get_len_load_store_mode (vmode, true, &partial_ifn);
   11698            0 :                 new_vmode = new_ovmode.require ();
   11699            0 :                 unsigned factor
   11700            0 :                   = (new_ovmode == vmode) ? 1 : GET_MODE_UNIT_SIZE (vmode);
   11701            0 :                 final_len = vect_get_len (loop_vinfo, gsi, vec_num, vectype, i,
   11702              :                                           factor, true);
   11703              :               }
   11704       244608 :             else if (final_mask)
   11705              :               {
   11706          733 :                 if (!can_vec_mask_load_store_p (vmode,
   11707          733 :                                                 TYPE_MODE
   11708              :                                                   (TREE_TYPE (final_mask)),
   11709              :                                                 true, &partial_ifn))
   11710            0 :                   gcc_unreachable ();
   11711              :               }
   11712              : 
   11713       244608 :             if (partial_ifn == IFN_MASK_LEN_LOAD)
   11714              :               {
   11715            0 :                 if (!final_len)
   11716              :                   {
   11717              :                     /* Pass VF value to 'len' argument of
   11718              :                        MASK_LEN_LOAD if LEN_LOOP_P is false.  */
   11719            0 :                     final_len = size_int (TYPE_VECTOR_SUBPARTS (vectype));
   11720              :                   }
   11721            0 :                 if (!final_mask)
   11722              :                   {
   11723              :                     /* Pass all ones value to 'mask' argument of
   11724              :                        MASK_LEN_LOAD if final_mask is invalid.  */
   11725            0 :                     mask_vectype = truth_type_for (vectype);
   11726            0 :                     final_mask = build_minus_one_cst (mask_vectype);
   11727              :                   }
   11728              :               }
   11729       244608 :             if (final_len)
   11730              :               {
   11731            0 :                 signed char biasval
   11732            0 :                   = LOOP_VINFO_PARTIAL_LOAD_STORE_BIAS (loop_vinfo);
   11733            0 :                 bias = build_int_cst (intQI_type_node, biasval);
   11734              :               }
   11735              : 
   11736            0 :             tree vec_els;
   11737              : 
   11738            0 :             if (final_len)
   11739              :               {
   11740            0 :                 tree ptr = build_int_cst (ref_type, align * BITS_PER_UNIT);
   11741            0 :                 gcall *call;
   11742              : 
   11743              :                 /* Need conversion if the vectype is punned by VnQI.  */
   11744            0 :                 els_vectype = vectype;
   11745            0 :                 if (vmode != new_vmode)
   11746            0 :                   els_vectype
   11747            0 :                     = build_vector_type_for_mode (unsigned_intQI_type_node,
   11748              :                                                   new_vmode);
   11749            0 :                 vec_els = vect_get_mask_load_else (maskload_elsval,
   11750              :                                                    els_vectype);
   11751              : 
   11752            0 :                 if (partial_ifn == IFN_MASK_LEN_LOAD)
   11753              :                   {
   11754            0 :                     if (type_mode_padding_p
   11755            0 :                         && maskload_elsval != MASK_LOAD_ELSE_ZERO)
   11756            0 :                       need_zeroing = true;
   11757            0 :                     call = gimple_build_call_internal (IFN_MASK_LEN_LOAD,
   11758              :                                                        6, dataref_ptr, ptr,
   11759              :                                                        final_mask, vec_els,
   11760              :                                                        final_len, bias);
   11761              :                   }
   11762              :                 else
   11763            0 :                   call = gimple_build_call_internal (IFN_LEN_LOAD, 5,
   11764              :                                                      dataref_ptr, ptr,
   11765              :                                                      vec_els, final_len,
   11766              :                                                      bias);
   11767            0 :                 gimple_call_set_nothrow (call, true);
   11768            0 :                 new_stmt = call;
   11769            0 :                 data_ref = NULL_TREE;
   11770              : 
   11771              :                 /* Need conversion if it's wrapped with VnQI.  */
   11772            0 :                 if (vmode != new_vmode)
   11773              :                   {
   11774            0 :                     tree new_vtype
   11775            0 :                       = build_vector_type_for_mode (unsigned_intQI_type_node,
   11776              :                                                     new_vmode);
   11777            0 :                     tree var = vect_get_new_ssa_name (new_vtype,
   11778              :                                                       vect_simple_var);
   11779            0 :                     gimple_set_lhs (call, var);
   11780            0 :                     vect_finish_stmt_generation (vinfo, stmt_info, call,
   11781              :                                                  gsi);
   11782            0 :                     tree op = build1 (VIEW_CONVERT_EXPR, vectype, var);
   11783            0 :                     new_stmt = gimple_build_assign (vec_dest,
   11784              :                                                     VIEW_CONVERT_EXPR, op);
   11785              :                   }
   11786              :               }
   11787       244608 :             else if (final_mask)
   11788              :               {
   11789          733 :                 tree ptr = build_int_cst (ref_type, align * BITS_PER_UNIT);
   11790          733 :                 vec_els = vect_get_mask_load_else (maskload_elsval, vectype);
   11791          733 :                 if (type_mode_padding_p
   11792          733 :                     && maskload_elsval != MASK_LOAD_ELSE_ZERO)
   11793            0 :                   need_zeroing = true;
   11794          733 :                 gcall *call = gimple_build_call_internal (IFN_MASK_LOAD, 4,
   11795              :                                                           dataref_ptr, ptr,
   11796              :                                                           final_mask,
   11797              :                                                           vec_els);
   11798          733 :                 gimple_call_set_nothrow (call, true);
   11799          733 :                 new_stmt = call;
   11800          733 :                 data_ref = NULL_TREE;
   11801              :               }
   11802              :             else
   11803              :               {
   11804       243875 :                 tree ltype = vectype;
   11805       243875 :                 tree new_vtype = NULL_TREE;
   11806       243875 :                 unsigned HOST_WIDE_INT gap = DR_GROUP_GAP (first_stmt_info);
   11807       243875 :                 unsigned HOST_WIDE_INT dr_size
   11808       243875 :                   = vect_get_scalar_dr_size (first_dr_info);
   11809       243875 :                 poly_int64 off = 0;
   11810       243875 :                 if (memory_access_type == VMAT_CONTIGUOUS_REVERSE)
   11811         1594 :                   off = (TYPE_VECTOR_SUBPARTS (vectype) - 1) * -dr_size;
   11812       243875 :                 unsigned int vect_align
   11813       243875 :                   = vect_known_alignment_in_bytes (first_dr_info, vectype,
   11814       243875 :                                                    off);
   11815              :                 /* Try to use a single smaller load when we are about
   11816              :                    to load excess elements compared to the unrolled
   11817              :                    scalar loop.  */
   11818       243875 :                 if (known_gt ((i + 1) * nunits,
   11819              :                               (group_size * vf - gap)))
   11820              :                   {
   11821         7042 :                     poly_uint64 remain = ((group_size * vf - gap) - i * nunits);
   11822         7042 :                     if (known_ge ((i + 1) * nunits - (group_size * vf - gap),
   11823              :                                   nunits))
   11824              :                       /* DR will be unused.  */
   11825              :                       ltype = NULL_TREE;
   11826         2388 :                     else if (known_ge (vect_align,
   11827              :                                        tree_to_poly_uint64
   11828              :                                          (TYPE_SIZE_UNIT (vectype))))
   11829              :                       /* Aligned access to excess elements is OK if
   11830              :                          at least one element is accessed in the
   11831              :                          scalar loop.  */
   11832              :                       ;
   11833         1979 :                     else if (known_gt (vect_align,
   11834              :                                        ((nunits - remain) * dr_size)))
   11835              :                       /* Aligned access to the gap area when there's
   11836              :                          at least one element in it is OK.  */
   11837              :                       ;
   11838              :                     else
   11839              :                       {
   11840              :                         /* remain should now be > 0 and < nunits.  */
   11841         1974 :                         unsigned num;
   11842         1974 :                         if (known_ne (remain, 0u)
   11843         1974 :                             && constant_multiple_p (nunits, remain, &num))
   11844              :                           {
   11845         1485 :                             tree ptype;
   11846         1485 :                             new_vtype
   11847         1485 :                               = vector_vector_composition_type (vectype, num,
   11848              :                                                                 &ptype);
   11849         1485 :                             if (new_vtype)
   11850         1485 :                               ltype = ptype;
   11851              :                           }
   11852              :                         /* Else use multiple loads or a masked load?  */
   11853              :                         /* For loop vectorization we now should have
   11854              :                            an alternate type or LOOP_VINFO_PEELING_FOR_GAPS
   11855              :                            set.  */
   11856         1974 :                         if (loop_vinfo)
   11857         1729 :                           gcc_assert (new_vtype
   11858              :                                       || LOOP_VINFO_PEELING_FOR_GAPS
   11859              :                                            (loop_vinfo));
   11860              :                         /* But still reduce the access size to the next
   11861              :                            required power-of-two so peeling a single
   11862              :                            scalar iteration is sufficient.  */
   11863         1974 :                         unsigned HOST_WIDE_INT cremain;
   11864         1974 :                         if (remain.is_constant (&cremain))
   11865              :                           {
   11866         1974 :                             unsigned HOST_WIDE_INT cpart_size
   11867         1974 :                               = 1 << ceil_log2 (cremain);
   11868         1974 :                             if (known_gt (nunits, cpart_size)
   11869         1974 :                                 && constant_multiple_p (nunits, cpart_size,
   11870              :                                                         &num))
   11871              :                               {
   11872         1497 :                                 tree ptype;
   11873         1497 :                                 new_vtype
   11874         2994 :                                   = vector_vector_composition_type (vectype,
   11875         1497 :                                                                     num,
   11876              :                                                                     &ptype);
   11877         1497 :                                 if (new_vtype)
   11878         1497 :                                   ltype = ptype;
   11879              :                               }
   11880              :                           }
   11881              :                       }
   11882              :                   }
   11883       243875 :                 tree offset = (dataref_offset ? dataref_offset
   11884       241498 :                                : build_int_cst (ref_type, 0));
   11885       243875 :                 if (!ltype)
   11886              :                   ;
   11887       239221 :                 else if (ltype != vectype
   11888       239221 :                          && memory_access_type == VMAT_CONTIGUOUS_REVERSE)
   11889              :                   {
   11890           21 :                     poly_uint64 gap_offset
   11891           21 :                       = (tree_to_poly_uint64 (TYPE_SIZE_UNIT (vectype))
   11892           21 :                          - tree_to_poly_uint64 (TYPE_SIZE_UNIT (ltype)));
   11893           21 :                     tree gapcst = build_int_cstu (ref_type, gap_offset);
   11894           21 :                     offset = size_binop (PLUS_EXPR, offset, gapcst);
   11895              :                   }
   11896       239221 :                 if (ltype)
   11897              :                   {
   11898       239221 :                     data_ref = fold_build2 (MEM_REF, ltype,
   11899              :                                             dataref_ptr, offset);
   11900       239221 :                     if (alignment_support_scheme == dr_aligned
   11901       239221 :                         && align >= TYPE_ALIGN_UNIT (ltype))
   11902              :                       ;
   11903              :                     else
   11904       157668 :                       TREE_TYPE (data_ref)
   11905       315336 :                         = build_aligned_type (TREE_TYPE (data_ref),
   11906              :                                               align * BITS_PER_UNIT);
   11907              :                   }
   11908       239221 :                 if (!ltype)
   11909         4654 :                   data_ref = build_constructor (vectype, NULL);
   11910       239221 :                 else if (ltype != vectype)
   11911              :                   {
   11912         1497 :                     vect_copy_ref_info (data_ref, first_stmt_info);
   11913         1497 :                     tree tem = make_ssa_name (ltype);
   11914         1497 :                     new_stmt = gimple_build_assign (tem, data_ref);
   11915         1497 :                     vect_finish_stmt_generation (vinfo, stmt_info, new_stmt,
   11916              :                                                  gsi);
   11917         1497 :                     data_ref = NULL;
   11918         1497 :                     vec<constructor_elt, va_gc> *v;
   11919              :                     /* We've computed 'num' above to statically two
   11920              :                        or via constant_multiple_p.  */
   11921         1497 :                     unsigned num
   11922         1497 :                       = (exact_div (tree_to_poly_uint64
   11923         1497 :                                       (TYPE_SIZE_UNIT (vectype)),
   11924              :                                     tree_to_poly_uint64
   11925         1497 :                                       (TYPE_SIZE_UNIT (ltype)))
   11926         1497 :                          .to_constant ());
   11927         1497 :                     vec_alloc (v, num);
   11928         1497 :                     if (memory_access_type == VMAT_CONTIGUOUS_REVERSE)
   11929              :                       {
   11930           54 :                         while (--num)
   11931           54 :                           CONSTRUCTOR_APPEND_ELT (v, NULL_TREE,
   11932              :                                                   build_zero_cst (ltype));
   11933           21 :                         CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, tem);
   11934              :                       }
   11935              :                     else
   11936              :                       {
   11937         1476 :                         CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, tem);
   11938         1476 :                         while (--num)
   11939         3410 :                           CONSTRUCTOR_APPEND_ELT (v, NULL_TREE,
   11940              :                                                   build_zero_cst (ltype));
   11941              :                       }
   11942         1497 :                     gcc_assert (new_vtype != NULL_TREE);
   11943         1497 :                     if (new_vtype == vectype)
   11944         1465 :                       new_stmt
   11945         1465 :                         = gimple_build_assign (vec_dest,
   11946              :                                                build_constructor (vectype, v));
   11947              :                     else
   11948              :                       {
   11949           32 :                         tree new_vname = make_ssa_name (new_vtype);
   11950           32 :                         new_stmt
   11951           32 :                           = gimple_build_assign (new_vname,
   11952              :                                                  build_constructor (new_vtype,
   11953              :                                                                     v));
   11954           32 :                         vect_finish_stmt_generation (vinfo, stmt_info,
   11955              :                                                      new_stmt, gsi);
   11956           32 :                         new_stmt
   11957           32 :                           = gimple_build_assign (vec_dest,
   11958              :                                                  build1 (VIEW_CONVERT_EXPR,
   11959              :                                                          vectype, new_vname));
   11960              :                       }
   11961              :                   }
   11962              :               }
   11963              :             break;
   11964              :           }
   11965            0 :         case dr_explicit_realign:
   11966            0 :           {
   11967            0 :             if (costing_p)
   11968              :               break;
   11969            0 :             tree ptr, bump;
   11970              : 
   11971            0 :             tree vs = size_int (TYPE_VECTOR_SUBPARTS (vectype));
   11972              : 
   11973            0 :             if (compute_in_loop)
   11974            0 :               msq = vect_setup_realignment (vinfo, first_stmt_info, vectype,
   11975              :                                             gsi, &realignment_token,
   11976              :                                             dr_explicit_realign,
   11977              :                                             dataref_ptr, NULL);
   11978              : 
   11979            0 :             if (TREE_CODE (dataref_ptr) == SSA_NAME)
   11980            0 :               ptr = copy_ssa_name (dataref_ptr);
   11981              :             else
   11982            0 :               ptr = make_ssa_name (TREE_TYPE (dataref_ptr));
   11983              :             // For explicit realign the target alignment should be
   11984              :             // known at compile time.
   11985            0 :             unsigned HOST_WIDE_INT align
   11986            0 :               = DR_TARGET_ALIGNMENT (first_dr_info).to_constant ();
   11987            0 :             new_stmt = gimple_build_assign (ptr, BIT_AND_EXPR, dataref_ptr,
   11988              :                                             build_int_cst
   11989            0 :                                               (TREE_TYPE (dataref_ptr),
   11990            0 :                                                -(HOST_WIDE_INT) align));
   11991            0 :             vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
   11992            0 :             data_ref = build2 (MEM_REF, vectype,
   11993              :                                ptr, build_int_cst (ref_type, 0));
   11994            0 :             vect_copy_ref_info (data_ref, first_stmt_info);
   11995            0 :             vec_dest = vect_create_destination_var (scalar_dest, vectype);
   11996            0 :             new_stmt = gimple_build_assign (vec_dest, data_ref);
   11997            0 :             new_temp = make_ssa_name (vec_dest, new_stmt);
   11998            0 :             gimple_assign_set_lhs (new_stmt, new_temp);
   11999            0 :             gimple_move_vops (new_stmt, stmt_info->stmt);
   12000            0 :             vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
   12001            0 :             msq = new_temp;
   12002              : 
   12003            0 :             bump = size_binop (MULT_EXPR, vs, TYPE_SIZE_UNIT (elem_type));
   12004            0 :             bump = size_binop (MINUS_EXPR, bump, size_one_node);
   12005            0 :             ptr = bump_vector_ptr (vinfo, dataref_ptr, gsi, stmt_info, bump);
   12006            0 :             new_stmt = gimple_build_assign (NULL_TREE, BIT_AND_EXPR, ptr,
   12007            0 :                                             build_int_cst (TREE_TYPE (ptr),
   12008            0 :                                                            -(HOST_WIDE_INT) align));
   12009            0 :             if (TREE_CODE (ptr) == SSA_NAME)
   12010            0 :               ptr = copy_ssa_name (ptr, new_stmt);
   12011              :             else
   12012            0 :               ptr = make_ssa_name (TREE_TYPE (ptr), new_stmt);
   12013            0 :             gimple_assign_set_lhs (new_stmt, ptr);
   12014            0 :             vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
   12015            0 :             data_ref = build2 (MEM_REF, vectype,
   12016              :                                ptr, build_int_cst (ref_type, 0));
   12017            0 :             break;
   12018              :           }
   12019            0 :         case dr_explicit_realign_optimized:
   12020            0 :           {
   12021            0 :             if (costing_p)
   12022              :               break;
   12023            0 :             if (TREE_CODE (dataref_ptr) == SSA_NAME)
   12024            0 :               new_temp = copy_ssa_name (dataref_ptr);
   12025              :             else
   12026            0 :               new_temp = make_ssa_name (TREE_TYPE (dataref_ptr));
   12027              :             // We should only be doing this if we know the target
   12028              :             // alignment at compile time.
   12029            0 :             unsigned HOST_WIDE_INT align
   12030            0 :               = DR_TARGET_ALIGNMENT (first_dr_info).to_constant ();
   12031            0 :             new_stmt = gimple_build_assign (new_temp, BIT_AND_EXPR, dataref_ptr,
   12032            0 :                                             build_int_cst (TREE_TYPE (dataref_ptr),
   12033            0 :                                                            -(HOST_WIDE_INT) align));
   12034            0 :             vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
   12035            0 :             data_ref = build2 (MEM_REF, vectype, new_temp,
   12036              :                                build_int_cst (ref_type, 0));
   12037            0 :             break;
   12038              :           }
   12039            0 :         default:
   12040            0 :         gcc_unreachable ();
   12041              :         }
   12042              : 
   12043              :       /* One common place to cost the above vect load for different
   12044              :          alignment support schemes.  */
   12045       965219 :       if (costing_p)
   12046              :         {
   12047              :           /* For the prologue cost for realign,
   12048              :              we only need to count it once for the whole group.  */
   12049       720611 :           bool first_stmt_info_p = first_stmt_info == stmt_info;
   12050       720611 :           bool add_realign_cost = first_stmt_info_p && i == 0;
   12051       720611 :           if (memory_access_type == VMAT_CONTIGUOUS
   12052       720611 :               || memory_access_type == VMAT_CONTIGUOUS_REVERSE)
   12053              :             {
   12054              :               /* Leave realign cases alone to keep them simple.  */
   12055       720611 :               if (alignment_support_scheme == dr_explicit_realign_optimized
   12056              :                   || alignment_support_scheme == dr_explicit_realign)
   12057            0 :                 vect_get_load_cost (vinfo, stmt_info, slp_node, 1,
   12058              :                                     alignment_support_scheme, misalignment,
   12059              :                                     add_realign_cost, &inside_cost,
   12060              :                                     &prologue_cost, cost_vec, cost_vec,
   12061              :                                     true);
   12062              :               else
   12063       720611 :                 n_adjacent_loads++;
   12064              :             }
   12065              :         }
   12066              :       else
   12067              :         {
   12068       244608 :           vec_dest = vect_create_destination_var (scalar_dest, vectype);
   12069              :           /* DATA_REF is null if we've already built the statement.  */
   12070       244608 :           if (data_ref)
   12071              :             {
   12072       242378 :               vect_copy_ref_info (data_ref, first_stmt_info);
   12073       242378 :               new_stmt = gimple_build_assign (vec_dest, data_ref);
   12074              :             }
   12075              : 
   12076       489216 :           new_temp = (need_zeroing
   12077       244608 :                       ? make_ssa_name (vectype)
   12078       244608 :                       : make_ssa_name (vec_dest, new_stmt));
   12079       244608 :           gimple_set_lhs (new_stmt, new_temp);
   12080       244608 :           vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
   12081              : 
   12082              :           /* If we need to explicitly zero inactive elements emit a
   12083              :              VEC_COND_EXPR that does so.  */
   12084       244608 :           if (need_zeroing)
   12085              :             {
   12086            0 :               vec_els = vect_get_mask_load_else (MASK_LOAD_ELSE_ZERO,
   12087              :                                                  vectype);
   12088              : 
   12089            0 :               tree new_temp2 = make_ssa_name (vec_dest, new_stmt);
   12090            0 :               new_stmt = gimple_build_assign (new_temp2, VEC_COND_EXPR,
   12091              :                                               final_mask, new_temp, vec_els);
   12092            0 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt,
   12093              :                                            gsi);
   12094            0 :               new_temp = new_temp2;
   12095              :             }
   12096              :         }
   12097              : 
   12098              :       /* 3. Handle explicit realignment if necessary/supported.
   12099              :          Create in loop:
   12100              :          vec_dest = realign_load (msq, lsq, realignment_token)  */
   12101       965219 :       if (!costing_p
   12102       244608 :           && (alignment_support_scheme == dr_explicit_realign_optimized
   12103              :               || alignment_support_scheme == dr_explicit_realign))
   12104              :         {
   12105            0 :           lsq = gimple_assign_lhs (new_stmt);
   12106            0 :           if (!realignment_token)
   12107            0 :             realignment_token = dataref_ptr;
   12108            0 :           vec_dest = vect_create_destination_var (scalar_dest, vectype);
   12109            0 :           new_stmt = gimple_build_assign (vec_dest, REALIGN_LOAD_EXPR, msq,
   12110              :                                           lsq, realignment_token);
   12111            0 :           new_temp = make_ssa_name (vec_dest, new_stmt);
   12112            0 :           gimple_assign_set_lhs (new_stmt, new_temp);
   12113            0 :           vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
   12114              : 
   12115            0 :           if (alignment_support_scheme == dr_explicit_realign_optimized)
   12116              :             {
   12117            0 :               gcc_assert (phi);
   12118            0 :               if (i == vec_num - 1)
   12119            0 :                 add_phi_arg (phi, lsq, loop_latch_edge (containing_loop),
   12120              :                              UNKNOWN_LOCATION);
   12121              :               msq = lsq;
   12122              :             }
   12123              :         }
   12124              : 
   12125       965219 :       if (memory_access_type == VMAT_CONTIGUOUS_REVERSE)
   12126              :         {
   12127         6319 :           if (costing_p)
   12128              :             {
   12129         4725 :               tree perm_mask = perm_mask_for_reverse (vectype);
   12130         4725 :               ls.perms.safe_push ({perm_mask, 1, 1});
   12131         4725 :               inside_cost = record_stmt_cost (cost_vec, 1, vec_perm,
   12132              :                                               slp_node, 0, vect_body);
   12133              :             }
   12134              :           else
   12135              :             {
   12136         4782 :               new_temp = permute_vec_elements (vinfo, new_temp, new_temp,
   12137         1594 :                                                ls.perms.last ().mask,
   12138              :                                                stmt_info, gsi);
   12139         1594 :               new_stmt = SSA_NAME_DEF_STMT (new_temp);
   12140              :             }
   12141              :         }
   12142              : 
   12143              :       /* Collect vector loads and later create their permutation in
   12144              :          vect_transform_slp_perm_load.  */
   12145       965219 :       if (!costing_p && (grouped_load || ls.slp_perm))
   12146        75243 :         dr_chain.quick_push (new_temp);
   12147              : 
   12148              :       /* Store vector loads in the corresponding SLP_NODE.  */
   12149       244608 :       if (!costing_p && !ls.slp_perm)
   12150       169365 :         slp_node->push_vec_def (new_stmt);
   12151              : 
   12152              :       /* With SLP permutation we load the gaps as well, without
   12153              :          we need to skip the gaps after we manage to fully load
   12154              :          all elements.  group_gap_adj is DR_GROUP_SIZE here.  */
   12155       965219 :       group_elt += nunits;
   12156       965219 :       if (!costing_p
   12157       244608 :           && maybe_ne (group_gap_adj, 0U)
   12158        40213 :           && !ls.slp_perm
   12159       980414 :           && known_eq (group_elt, group_size - group_gap_adj))
   12160              :         {
   12161        12569 :           poly_wide_int bump_val
   12162        12569 :             = (wi::to_wide (TYPE_SIZE_UNIT (elem_type)) * group_gap_adj);
   12163        12569 :           if (tree_int_cst_sgn (vect_dr_behavior (vinfo, dr_info)->step) == -1)
   12164            0 :             bump_val = -bump_val;
   12165        12569 :           tree bump = wide_int_to_tree (sizetype, bump_val);
   12166        12569 :           dataref_ptr = bump_vector_ptr (vinfo, dataref_ptr, gsi, stmt_info,
   12167              :                                          bump);
   12168        12569 :           group_elt = 0;
   12169        12569 :         }
   12170              :     }
   12171              :   /* Bump the vector pointer to account for a gap or for excess
   12172              :      elements loaded for a permuted SLP load.  */
   12173       598546 :   if (!costing_p
   12174       154872 :       && maybe_ne (group_gap_adj, 0U)
   12175       611590 :       && ls.slp_perm)
   12176              :     {
   12177          475 :       poly_wide_int bump_val
   12178          475 :         = (wi::to_wide (TYPE_SIZE_UNIT (elem_type)) * group_gap_adj);
   12179          475 :       if (tree_int_cst_sgn (vect_dr_behavior (vinfo, dr_info)->step) == -1)
   12180            9 :         bump_val = -bump_val;
   12181          475 :       tree bump = wide_int_to_tree (sizetype, bump_val);
   12182          475 :       dataref_ptr = bump_vector_ptr (vinfo, dataref_ptr, gsi, stmt_info, bump);
   12183          475 :     }
   12184              : 
   12185       598546 :   if (ls.slp_perm)
   12186              :     {
   12187              :       /* For SLP we know we've seen all possible uses of dr_chain so
   12188              :          direct vect_transform_slp_perm_load to DCE the unused parts.
   12189              :          ???  This is a hack to prevent compile-time issues as seen
   12190              :          in PR101120 and friends.  */
   12191        59261 :       if (costing_p)
   12192              :         {
   12193        41662 :           gcc_assert (ls.n_perms != -1U && ls.n_loads != -1U);
   12194        41662 :           if (ls.n_perms != 0)
   12195        41133 :             inside_cost = record_stmt_cost (cost_vec, ls.n_perms, vec_perm,
   12196              :                                             slp_node, 0, vect_body);
   12197        41662 :           if (n_adjacent_loads > 0)
   12198        41662 :             n_adjacent_loads = ls.n_loads;
   12199              :         }
   12200              :       else
   12201              :         {
   12202        17599 :           unsigned n_perms2, n_loads2;
   12203        17599 :           bool ok = vect_transform_slp_perm_load (vinfo, slp_node, dr_chain,
   12204              :                                                   gsi, vf, false, &ls,
   12205              :                                                   &n_perms2, &n_loads2, true);
   12206        17599 :           gcc_assert (ok && ls.n_perms == n_perms2 && ls.n_loads == n_loads2);
   12207              :         }
   12208              :     }
   12209              : 
   12210       598546 :   if (costing_p)
   12211              :     {
   12212       443674 :       gcc_assert (memory_access_type == VMAT_CONTIGUOUS
   12213              :                   || memory_access_type == VMAT_CONTIGUOUS_REVERSE);
   12214       443674 :       if (n_adjacent_loads > 0)
   12215       443674 :         vect_get_load_cost (vinfo, stmt_info, slp_node, n_adjacent_loads,
   12216              :                             alignment_support_scheme, misalignment, false,
   12217              :                             &inside_cost, &prologue_cost, cost_vec, cost_vec,
   12218              :                             true);
   12219       443674 :       if (dump_enabled_p ())
   12220        26242 :         dump_printf_loc (MSG_NOTE, vect_location,
   12221              :                          "vect_model_load_cost: inside_cost = %u, "
   12222              :                          "prologue_cost = %u .\n",
   12223              :                          inside_cost, prologue_cost);
   12224       443674 :       SLP_TREE_TYPE (slp_node) = load_vec_info_type;
   12225       443674 :       slp_node->data = new vect_load_store_data (std::move (ls));
   12226              :     }
   12227              : 
   12228       598546 :   return true;
   12229      1346439 : }
   12230              : 
   12231              : /* vectorizable_condition.
   12232              : 
   12233              :    Check if STMT_INFO is conditional modify expression that can be vectorized.
   12234              :    If COST_VEC is passed, calculate costs but don't change anything,
   12235              :    otherwise, vectorize STMT_INFO: create a vectorized stmt using
   12236              :    VEC_COND_EXPR to replace it, and insert it at GSI.
   12237              : 
   12238              :    When STMT_INFO is vectorized as a nested cycle, for_reduction is true.
   12239              : 
   12240              :    Return true if STMT_INFO is vectorizable in this way.  */
   12241              : 
   12242              : static bool
   12243       734496 : vectorizable_condition (vec_info *vinfo,
   12244              :                         stmt_vec_info stmt_info, gimple_stmt_iterator *gsi,
   12245              :                         slp_tree slp_node, stmt_vector_for_cost *cost_vec)
   12246              : {
   12247       734496 :   tree scalar_dest = NULL_TREE;
   12248       734496 :   tree vec_dest = NULL_TREE;
   12249       734496 :   tree then_clause, else_clause;
   12250       734496 :   tree vec_cond_lhs = NULL_TREE;
   12251       734496 :   tree vec_then_clause = NULL_TREE, vec_else_clause = NULL_TREE;
   12252       734496 :   tree vec_compare;
   12253       734496 :   tree new_temp;
   12254       734496 :   loop_vec_info loop_vinfo = dyn_cast <loop_vec_info> (vinfo);
   12255       734496 :   enum vect_def_type dts[4]
   12256              :     = {vect_unknown_def_type, vect_unknown_def_type,
   12257              :        vect_unknown_def_type, vect_unknown_def_type};
   12258       734496 :   enum tree_code code;
   12259       734496 :   int i;
   12260       734496 :   bb_vec_info bb_vinfo = dyn_cast <bb_vec_info> (vinfo);
   12261       734496 :   vec<tree> vec_oprnds0 = vNULL;
   12262       734496 :   vec<tree> vec_oprnds2 = vNULL;
   12263       734496 :   vec<tree> vec_oprnds3 = vNULL;
   12264       734496 :   tree vec_cmp_type;
   12265              : 
   12266       734496 :   if (!STMT_VINFO_RELEVANT_P (stmt_info) && !bb_vinfo)
   12267              :     return false;
   12268              : 
   12269              :   /* Is vectorizable conditional operation?  */
   12270       734496 :   gassign *stmt = dyn_cast <gassign *> (stmt_info->stmt);
   12271       421903 :   if (!stmt)
   12272              :     return false;
   12273              : 
   12274       421903 :   code = gimple_assign_rhs_code (stmt);
   12275       421903 :   if (code != COND_EXPR)
   12276              :     return false;
   12277              : 
   12278        36916 :   int reduc_index = SLP_TREE_REDUC_IDX (slp_node);
   12279        36916 :   vect_reduction_type reduction_type = TREE_CODE_REDUCTION;
   12280        36916 :   bool nested_cycle_p = false;
   12281        36916 :   bool for_reduction = vect_is_reduction (stmt_info);
   12282        36916 :   if (for_reduction)
   12283              :     {
   12284          664 :       if (SLP_TREE_LANES (slp_node) > 1)
   12285              :         return false;
   12286              :       /* ???  With a reduction path we do not get at the reduction info from
   12287              :          every stmt, use the conservative default setting then.  */
   12288          745 :       if (STMT_VINFO_REDUC_DEF (vect_orig_stmt (stmt_info)))
   12289              :         {
   12290          646 :           vect_reduc_info reduc_info
   12291          646 :             = info_for_reduction (loop_vinfo, slp_node);
   12292          646 :           reduction_type = VECT_REDUC_INFO_TYPE (reduc_info);
   12293          646 :           nested_cycle_p = nested_in_vect_loop_p (LOOP_VINFO_LOOP (loop_vinfo),
   12294              :                                                   stmt_info);
   12295              :         }
   12296              :     }
   12297              :   else
   12298              :     {
   12299        36252 :       if (STMT_VINFO_DEF_TYPE (stmt_info) != vect_internal_def)
   12300              :         return false;
   12301              :     }
   12302              : 
   12303        36916 :   tree vectype = SLP_TREE_VECTYPE (slp_node);
   12304        36916 :   tree vectype1 = NULL_TREE, vectype2 = NULL_TREE;
   12305              : 
   12306        36916 :   int vec_num = vect_get_num_copies (vinfo, slp_node);
   12307              : 
   12308        36916 :   slp_tree slp_cond;
   12309        36916 :   tree cond_expr = gimple_assign_rhs1 (stmt);
   12310        36916 :   gcc_assert (! COMPARISON_CLASS_P (cond_expr));
   12311        36916 :   if (TREE_CODE (cond_expr) != SSA_NAME
   12312        36916 :       || !VECT_SCALAR_BOOLEAN_TYPE_P (TREE_TYPE (cond_expr))
   12313        36916 :       || !vect_is_simple_use (vinfo, slp_node, 0,
   12314              :                               &slp_cond, &dts[0], &vec_cmp_type)
   12315        36916 :       || !vec_cmp_type
   12316        73817 :       || !VECTOR_BOOLEAN_TYPE_P (vec_cmp_type))
   12317              :     return false;
   12318              : 
   12319        36901 :   slp_tree then_slp_node, else_slp_node;
   12320        36901 :   if (!vect_is_simple_use (vinfo, slp_node, 1,
   12321              :                            &then_clause, &then_slp_node, &dts[2], &vectype1))
   12322              :     return false;
   12323        36901 :   if (!vect_is_simple_use (vinfo, slp_node, 2,
   12324              :                            &else_clause, &else_slp_node, &dts[3], &vectype2))
   12325              :     return false;
   12326              : 
   12327        36901 :   if (vectype1 && !useless_type_conversion_p (vectype, vectype1))
   12328              :     return false;
   12329              : 
   12330        36893 :   if (vectype2 && !useless_type_conversion_p (vectype, vectype2))
   12331              :     return false;
   12332              : 
   12333        36881 :   if (maybe_ne (TYPE_VECTOR_SUBPARTS (vectype),
   12334        73762 :                 TYPE_VECTOR_SUBPARTS (vec_cmp_type)))
   12335              :     return false;
   12336              : 
   12337              :   /* For conditional reductions, the "then" value needs to be the candidate
   12338              :      value calculated by this iteration while the "else" value needs to be
   12339              :      the result carried over from previous iterations.  If the COND_EXPR
   12340              :      is the other way around, we need to swap it.  */
   12341        36881 :   bool must_invert_cmp_result = false;
   12342        36881 :   if (reduction_type == EXTRACT_LAST_REDUCTION && reduc_index == 1)
   12343              :     {
   12344       734496 :       must_invert_cmp_result = true;
   12345              :       /* ???  The vectorized operand query below doesn't allow swapping
   12346              :          this way for SLP.  */
   12347              :       return false;
   12348              :       /* std::swap (then_clause, else_clause); */
   12349              :     }
   12350              : 
   12351        36881 :   if (cost_vec)
   12352              :     {
   12353        27842 :       vect_cost_for_stmt kind = vector_stmt;
   12354        27842 :       if (reduction_type == EXTRACT_LAST_REDUCTION)
   12355              :         /* Count one reduction-like operation per vector.  */
   12356              :         kind = vec_to_scalar;
   12357        27842 :       else if (!expand_vec_cond_expr_p (vectype, vec_cmp_type))
   12358              :         return false;
   12359              : 
   12360        27812 :       if (!vect_maybe_update_slp_op_vectype (SLP_TREE_CHILDREN (slp_node)[0],
   12361              :                                              vec_cmp_type)
   12362        27812 :           || !vect_maybe_update_slp_op_vectype (then_slp_node, vectype)
   12363        55624 :           || !vect_maybe_update_slp_op_vectype (else_slp_node, vectype))
   12364              :         {
   12365            0 :           if (dump_enabled_p ())
   12366            0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
   12367              :                              "incompatible vector types for invariants\n");
   12368              :           return false;
   12369              :         }
   12370              : 
   12371        27812 :       if (loop_vinfo && for_reduction
   12372          488 :           && LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo))
   12373              :         {
   12374           81 :           if (reduction_type == EXTRACT_LAST_REDUCTION)
   12375              :             {
   12376            0 :               if (direct_internal_fn_supported_p (IFN_LEN_FOLD_EXTRACT_LAST,
   12377              :                                                   vectype, OPTIMIZE_FOR_SPEED))
   12378            0 :                 vect_record_len (loop_vinfo, vec_num, vectype, 1);
   12379              :               else
   12380            0 :                 vect_record_mask (loop_vinfo, vec_num, vectype, NULL_TREE);
   12381              :             }
   12382              :           /* Extra inactive lanes should be safe for vect_nested_cycle.  */
   12383           81 :           else if (!nested_cycle_p)
   12384              :             {
   12385           81 :               if (dump_enabled_p ())
   12386            8 :                 dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
   12387              :                                  "conditional reduction prevents the use"
   12388              :                                  " of partial vectors.\n");
   12389           81 :               LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo) = false;
   12390              :             }
   12391              :         }
   12392              : 
   12393        27812 :       SLP_TREE_TYPE (slp_node) = condition_vec_info_type;
   12394        27812 :       vect_model_simple_cost (vinfo, 1, slp_node, cost_vec, kind);
   12395        27812 :       return true;
   12396              :     }
   12397              : 
   12398              :   /* Transform.  */
   12399              : 
   12400              :   /* Handle def.  */
   12401         9039 :   scalar_dest = gimple_assign_lhs (stmt);
   12402         9039 :   if (reduction_type != EXTRACT_LAST_REDUCTION)
   12403         9039 :     vec_dest = vect_create_destination_var (scalar_dest, vectype);
   12404              : 
   12405         9039 :   bool swap_cond_operands = false;
   12406              : 
   12407              :   /* See whether another part of the vectorized code applies a loop
   12408              :      mask to the condition, or to its inverse.  */
   12409              : 
   12410         9039 :   bool masks_p = false;
   12411         9039 :   bool lens_p = false;
   12412         9039 :   if (loop_vinfo && LOOP_VINFO_FULLY_WITH_LENGTH_P (loop_vinfo))
   12413              :     {
   12414            0 :       if (reduction_type == EXTRACT_LAST_REDUCTION)
   12415         9039 :         lens_p = true;
   12416              :     }
   12417         9039 :   else if (loop_vinfo && LOOP_VINFO_FULLY_MASKED_P (loop_vinfo))
   12418              :     {
   12419            3 :       if (reduction_type == EXTRACT_LAST_REDUCTION)
   12420              :         masks_p = true;
   12421              :       else
   12422              :         {
   12423            3 :           scalar_cond_masked_key cond (cond_expr, 1);
   12424            3 :           if (loop_vinfo->scalar_cond_masked_set.contains (cond))
   12425              :             masks_p = true;
   12426              :           else
   12427              :             {
   12428            3 :               bool honor_nans = HONOR_NANS (TREE_TYPE (cond.op0));
   12429            3 :               tree_code orig_code = cond.code;
   12430            3 :               cond.code = invert_tree_comparison (cond.code, honor_nans);
   12431              :               /* Try the inverse of the current mask.  We check if the
   12432              :                  inverse mask is live and if so we generate a negate of
   12433              :                  the current mask such that we still honor NaNs.  */
   12434            3 :               cond.inverted_p = true;
   12435            3 :               cond.code = orig_code;
   12436            3 :               if (loop_vinfo->scalar_cond_masked_set.contains (cond))
   12437              :                 {
   12438            0 :                   masks_p = true;
   12439            0 :                   swap_cond_operands = true;
   12440            0 :                   must_invert_cmp_result = true;
   12441              :                 }
   12442              :             }
   12443              :         }
   12444              :     }
   12445              : 
   12446              :   /* Handle cond expr.  */
   12447         9039 :   vect_get_vec_defs (vinfo, slp_node, true, &vec_oprnds0, true, &vec_oprnds2,
   12448              :                      reduction_type != EXTRACT_LAST_REDUCTION, &vec_oprnds3);
   12449              : 
   12450         9039 :   if (reduction_type == EXTRACT_LAST_REDUCTION)
   12451            0 :     vec_else_clause = else_clause;
   12452              : 
   12453              :   /* Arguments are ready.  Create the new vector stmt.  */
   12454        20967 :   FOR_EACH_VEC_ELT (vec_oprnds0, i, vec_cond_lhs)
   12455              :     {
   12456        11928 :       vec_then_clause = vec_oprnds2[i];
   12457        11928 :       if (reduction_type != EXTRACT_LAST_REDUCTION)
   12458        11928 :         vec_else_clause = vec_oprnds3[i];
   12459              : 
   12460        11928 :       if (swap_cond_operands)
   12461            0 :         std::swap (vec_then_clause, vec_else_clause);
   12462              : 
   12463        11928 :       vec_compare = vec_cond_lhs;
   12464              : 
   12465              :       /* If we decided to apply a loop mask to the result of the vector
   12466              :          comparison, AND the comparison with the mask now.  Later passes
   12467              :          should then be able to reuse the AND results between multiple
   12468              :          vector statements.
   12469              : 
   12470              :          For example:
   12471              :          for (int i = 0; i < 100; ++i)
   12472              :          x[i] = y[i] ? z[i] : 10;
   12473              : 
   12474              :          results in following optimized GIMPLE:
   12475              : 
   12476              :          mask__35.8_43 = vect__4.7_41 != { 0, ... };
   12477              :          vec_mask_and_46 = loop_mask_40 & mask__35.8_43;
   12478              :          _19 = &MEM[base: z_12(D), index: ivtmp_56, step: 4, offset: 0B];
   12479              :          vect_iftmp.11_47 = .MASK_LOAD (_19, 4B, vec_mask_and_46);
   12480              :          vect_iftmp.12_52 = VEC_COND_EXPR <vec_mask_and_46,
   12481              :          vect_iftmp.11_47, { 10, ... }>;
   12482              : 
   12483              :          instead of using a masked and unmasked forms of
   12484              :          vec != { 0, ... } (masked in the MASK_LOAD,
   12485              :          unmasked in the VEC_COND_EXPR).  */
   12486              : 
   12487              :       /* Force vec_compare to be an SSA_NAME rather than a comparison,
   12488              :          in cases where that's necessary.  */
   12489              : 
   12490        11928 :       tree len = NULL_TREE, bias = NULL_TREE;
   12491        11928 :       if (masks_p || lens_p
   12492        11928 :           || reduction_type == EXTRACT_LAST_REDUCTION)
   12493              :         {
   12494            0 :           if (!is_gimple_val (vec_compare))
   12495              :             {
   12496            0 :               tree vec_compare_name = make_ssa_name (vec_cmp_type);
   12497            0 :               gassign *new_stmt = gimple_build_assign (vec_compare_name,
   12498              :                                                        vec_compare);
   12499            0 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
   12500            0 :               vec_compare = vec_compare_name;
   12501              :             }
   12502              : 
   12503            0 :           if (must_invert_cmp_result)
   12504              :             {
   12505            0 :               tree vec_compare_name = make_ssa_name (vec_cmp_type);
   12506            0 :               gassign *new_stmt = gimple_build_assign (vec_compare_name,
   12507              :                                                        BIT_NOT_EXPR,
   12508              :                                                        vec_compare);
   12509            0 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
   12510            0 :               vec_compare = vec_compare_name;
   12511              :             }
   12512              : 
   12513            0 :           if (direct_internal_fn_supported_p (IFN_LEN_FOLD_EXTRACT_LAST,
   12514              :                                               vectype, OPTIMIZE_FOR_SPEED))
   12515              :             {
   12516            0 :               if (lens_p)
   12517              :                 {
   12518              :                   /* ??? Do we really want the adjusted LEN here?  Isn't this
   12519              :                      based on number of elements?  */
   12520            0 :                   len = vect_get_len (loop_vinfo, gsi, vec_num, vectype, i, 1,
   12521              :                                       true);
   12522            0 :                   signed char biasval
   12523            0 :                     = LOOP_VINFO_PARTIAL_LOAD_STORE_BIAS (loop_vinfo);
   12524            0 :                   bias = build_int_cst (intQI_type_node, biasval);
   12525              :                 }
   12526              :               else
   12527              :                 {
   12528            0 :                   len = size_int (TYPE_VECTOR_SUBPARTS (vectype));
   12529            0 :                   bias = build_int_cst (intQI_type_node, 0);
   12530              :                 }
   12531              :             }
   12532            0 :           if (masks_p)
   12533              :             {
   12534            0 :               tree loop_mask
   12535            0 :                 = vect_get_mask (loop_vinfo, gsi, vec_num, vectype, i);
   12536            0 :               tree tmp2 = make_ssa_name (vec_cmp_type);
   12537            0 :               gassign *g
   12538            0 :                 = gimple_build_assign (tmp2, BIT_AND_EXPR, vec_compare,
   12539              :                                        loop_mask);
   12540            0 :               vect_finish_stmt_generation (vinfo, stmt_info, g, gsi);
   12541            0 :               vec_compare = tmp2;
   12542              :             }
   12543              :         }
   12544              : 
   12545            0 :       gimple *new_stmt;
   12546            0 :       if (reduction_type == EXTRACT_LAST_REDUCTION)
   12547              :         {
   12548            0 :           gimple *old_stmt = vect_orig_stmt (stmt_info)->stmt;
   12549            0 :           tree lhs = gimple_get_lhs (old_stmt);
   12550            0 :           if ((unsigned)i != vec_oprnds0.length () - 1)
   12551            0 :             lhs = copy_ssa_name (lhs);
   12552            0 :           if (len)
   12553            0 :             new_stmt = gimple_build_call_internal
   12554            0 :                 (IFN_LEN_FOLD_EXTRACT_LAST, 5, vec_else_clause, vec_compare,
   12555              :                  vec_then_clause, len, bias);
   12556              :           else
   12557            0 :             new_stmt = gimple_build_call_internal
   12558            0 :                 (IFN_FOLD_EXTRACT_LAST, 3, vec_else_clause, vec_compare,
   12559              :                  vec_then_clause);
   12560            0 :           gimple_call_set_lhs (new_stmt, lhs);
   12561            0 :           SSA_NAME_DEF_STMT (lhs) = new_stmt;
   12562            0 :           if ((unsigned)i != vec_oprnds0.length () - 1)
   12563              :             {
   12564            0 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
   12565            0 :               vec_else_clause = lhs;
   12566              :             }
   12567            0 :           else if (old_stmt == gsi_stmt (*gsi))
   12568            0 :             vect_finish_replace_stmt (vinfo, stmt_info, new_stmt);
   12569              :           else
   12570              :             {
   12571              :               /* In this case we're moving the definition to later in the
   12572              :                  block.  That doesn't matter because the only uses of the
   12573              :                  lhs are in phi statements.  */
   12574            0 :               gimple_stmt_iterator old_gsi = gsi_for_stmt (old_stmt);
   12575            0 :               gsi_remove (&old_gsi, true);
   12576            0 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
   12577              :             }
   12578              :         }
   12579              :       else
   12580              :         {
   12581        11928 :           new_temp = make_ssa_name (vec_dest);
   12582        11928 :           new_stmt = gimple_build_assign (new_temp, VEC_COND_EXPR, vec_compare,
   12583              :                                           vec_then_clause, vec_else_clause);
   12584        11928 :           vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
   12585              :         }
   12586        11928 :       slp_node->push_vec_def (new_stmt);
   12587              :     }
   12588              : 
   12589         9039 :   vec_oprnds0.release ();
   12590         9039 :   vec_oprnds2.release ();
   12591         9039 :   vec_oprnds3.release ();
   12592              : 
   12593         9039 :   return true;
   12594              : }
   12595              : 
   12596              : /* Helper of vectorizable_comparison.
   12597              : 
   12598              :    Check if STMT_INFO is comparison expression CODE that can be vectorized.
   12599              :    If COST_VEC is passed, calculate costs but don't change anything,
   12600              :    otherwise, vectorize STMT_INFO: create a vectorized comparison, and insert
   12601              :    it at GSI.
   12602              : 
   12603              :    Return true if STMT_INFO is vectorizable in this way.  */
   12604              : 
   12605              : static bool
   12606       393670 : vectorizable_comparison_1 (vec_info *vinfo, tree vectype,
   12607              :                            stmt_vec_info stmt_info, tree_code code,
   12608              :                            gimple_stmt_iterator *gsi,
   12609              :                            slp_tree slp_node, stmt_vector_for_cost *cost_vec)
   12610              : {
   12611       393670 :   tree lhs, rhs1, rhs2;
   12612       393670 :   tree vectype1 = NULL_TREE, vectype2 = NULL_TREE;
   12613       393670 :   tree vec_rhs1 = NULL_TREE, vec_rhs2 = NULL_TREE;
   12614       393670 :   tree new_temp;
   12615       393670 :   enum vect_def_type dts[2] = {vect_unknown_def_type, vect_unknown_def_type};
   12616       393670 :   poly_uint64 nunits;
   12617       393670 :   enum tree_code bitop1 = NOP_EXPR, bitop2 = NOP_EXPR;
   12618       393670 :   int i;
   12619       393670 :   bb_vec_info bb_vinfo = dyn_cast <bb_vec_info> (vinfo);
   12620       393670 :   vec<tree> vec_oprnds0 = vNULL;
   12621       393670 :   vec<tree> vec_oprnds1 = vNULL;
   12622       393670 :   tree mask_type;
   12623       393670 :   tree mask = NULL_TREE;
   12624              : 
   12625       393670 :   if (!STMT_VINFO_RELEVANT_P (stmt_info) && !bb_vinfo)
   12626              :     return false;
   12627              : 
   12628       393670 :   if (!vectype || !VECTOR_BOOLEAN_TYPE_P (vectype))
   12629              :     return false;
   12630              : 
   12631       174515 :   mask_type = vectype;
   12632       174515 :   nunits = TYPE_VECTOR_SUBPARTS (vectype);
   12633              : 
   12634       174515 :   if (TREE_CODE_CLASS (code) != tcc_comparison)
   12635              :     return false;
   12636              : 
   12637       172583 :   slp_tree slp_rhs1, slp_rhs2;
   12638       172583 :   if (!vect_is_simple_use (vinfo, slp_node,
   12639              :                            0, &rhs1, &slp_rhs1, &dts[0], &vectype1))
   12640              :     return false;
   12641              : 
   12642       172583 :   if (!vect_is_simple_use (vinfo, slp_node,
   12643              :                            1, &rhs2, &slp_rhs2, &dts[1], &vectype2))
   12644              :     return false;
   12645              : 
   12646       135036 :   if (vectype1 && vectype2
   12647       251990 :       && maybe_ne (TYPE_VECTOR_SUBPARTS (vectype1),
   12648        79407 :                    TYPE_VECTOR_SUBPARTS (vectype2)))
   12649           16 :     return false;
   12650              : 
   12651       172567 :   vectype = vectype1 ? vectype1 : vectype2;
   12652              : 
   12653              :   /* Invariant comparison.  */
   12654       172567 :   if (!vectype)
   12655              :     {
   12656        32948 :       vectype = get_vectype_for_scalar_type (vinfo, TREE_TYPE (rhs1), slp_node);
   12657        32948 :       if (!vectype || maybe_ne (TYPE_VECTOR_SUBPARTS (vectype), nunits))
   12658              :         return false;
   12659              :     }
   12660       139619 :   else if (maybe_ne (nunits, TYPE_VECTOR_SUBPARTS (vectype)))
   12661              :     return false;
   12662              : 
   12663              :   /* Can't compare mask and non-mask types.  */
   12664       135020 :   if (vectype1 && vectype2
   12665       410104 :       && (VECTOR_BOOLEAN_TYPE_P (vectype1) ^ VECTOR_BOOLEAN_TYPE_P (vectype2)))
   12666              :     return false;
   12667              : 
   12668              :   /* We cannot compare non-mode precision _BitInt types.  Unlike bool
   12669              :      or bit-precision INTEGER_TYPE the padding bit values are target
   12670              :      dependent and possibly undefined.  */
   12671       345020 :   if (BITINT_TYPE_P (TREE_TYPE (rhs1))
   12672       172555 :       && !type_has_mode_precision_p (TREE_TYPE (rhs1)))
   12673              :     return false;
   12674              : 
   12675              :   /* Boolean values may have another representation in vectors
   12676              :      and therefore we prefer bit operations over comparison for
   12677              :      them (which also works for scalar masks).  We store opcodes
   12678              :      to use in bitop1 and bitop2.  Statement is vectorized as
   12679              :        BITOP2 (rhs1 BITOP1 rhs2) or
   12680              :        rhs1 BITOP2 (BITOP1 rhs2)
   12681              :      depending on bitop1 and bitop2 arity.  */
   12682       172489 :   bool swap_p = false;
   12683       172489 :   if (VECTOR_BOOLEAN_TYPE_P (vectype))
   12684              :     {
   12685          751 :       if (code == GT_EXPR)
   12686              :         {
   12687              :           bitop1 = BIT_NOT_EXPR;
   12688              :           bitop2 = BIT_AND_EXPR;
   12689              :         }
   12690              :       else if (code == GE_EXPR)
   12691              :         {
   12692              :           bitop1 = BIT_NOT_EXPR;
   12693              :           bitop2 = BIT_IOR_EXPR;
   12694              :         }
   12695              :       else if (code == LT_EXPR)
   12696              :         {
   12697              :           bitop1 = BIT_NOT_EXPR;
   12698              :           bitop2 = BIT_AND_EXPR;
   12699              :           swap_p = true;
   12700              :         }
   12701              :       else if (code == LE_EXPR)
   12702              :         {
   12703              :           bitop1 = BIT_NOT_EXPR;
   12704              :           bitop2 = BIT_IOR_EXPR;
   12705              :           swap_p = true;
   12706              :         }
   12707              :       else
   12708              :         {
   12709              :           bitop1 = BIT_XOR_EXPR;
   12710              :           if (code == EQ_EXPR)
   12711              :             bitop2 = BIT_NOT_EXPR;
   12712              :         }
   12713              :     }
   12714              : 
   12715       172489 :   if (cost_vec)
   12716              :     {
   12717       159328 :       if (bitop1 == NOP_EXPR)
   12718              :         {
   12719       158726 :           if (!expand_vec_cmp_expr_p (vectype, mask_type, code))
   12720              :             return false;
   12721              :         }
   12722              :       else
   12723              :         {
   12724          602 :           machine_mode mode = TYPE_MODE (vectype);
   12725          602 :           optab optab;
   12726              : 
   12727          602 :           optab = optab_for_tree_code (bitop1, vectype, optab_default);
   12728          602 :           if (!optab || !can_implement_p (optab, mode))
   12729              :             return false;
   12730              : 
   12731          602 :           if (bitop2 != NOP_EXPR)
   12732              :             {
   12733           97 :               optab = optab_for_tree_code (bitop2, vectype, optab_default);
   12734           97 :               if (!optab || !can_implement_p (optab, mode))
   12735              :                 return false;
   12736              :             }
   12737              :         }
   12738              : 
   12739              :       /* Put types on constant and invariant SLP children.  */
   12740       151703 :       if (!vect_maybe_update_slp_op_vectype (slp_rhs1, vectype)
   12741       151703 :           || !vect_maybe_update_slp_op_vectype (slp_rhs2, vectype))
   12742              :         {
   12743            2 :           if (dump_enabled_p ())
   12744            2 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
   12745              :                              "incompatible vector types for invariants\n");
   12746              :           return false;
   12747              :         }
   12748              : 
   12749       151701 :       vect_model_simple_cost (vinfo, 1 + (bitop2 != NOP_EXPR),
   12750              :                               slp_node, cost_vec);
   12751       151701 :       return true;
   12752              :     }
   12753              : 
   12754              :   /* Transform.  */
   12755              : 
   12756              :   /* Handle def.  */
   12757        13161 :   lhs = gimple_get_lhs (STMT_VINFO_STMT (stmt_info));
   12758        13161 :   if (lhs)
   12759        13161 :     mask = vect_create_destination_var (lhs, mask_type);
   12760              : 
   12761        13161 :   vect_get_vec_defs (vinfo, slp_node, true, &vec_oprnds0, true, &vec_oprnds1);
   12762        13161 :   if (swap_p)
   12763           60 :     std::swap (vec_oprnds0, vec_oprnds1);
   12764              : 
   12765              :   /* Arguments are ready.  Create the new vector stmt.  */
   12766        32958 :   FOR_EACH_VEC_ELT (vec_oprnds0, i, vec_rhs1)
   12767              :     {
   12768        19797 :       gimple *new_stmt;
   12769        19797 :       vec_rhs2 = vec_oprnds1[i];
   12770              : 
   12771        19797 :       if (lhs)
   12772        19797 :         new_temp = make_ssa_name (mask);
   12773              :       else
   12774            0 :         new_temp = make_temp_ssa_name (mask_type, NULL, "cmp");
   12775        19797 :       if (bitop1 == NOP_EXPR)
   12776              :         {
   12777        19638 :           new_stmt = gimple_build_assign (new_temp, code,
   12778              :                                           vec_rhs1, vec_rhs2);
   12779        19638 :           vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
   12780              :         }
   12781              :       else
   12782              :         {
   12783          159 :           if (bitop1 == BIT_NOT_EXPR)
   12784           86 :             new_stmt = gimple_build_assign (new_temp, bitop1, vec_rhs2);
   12785              :           else
   12786           73 :             new_stmt = gimple_build_assign (new_temp, bitop1, vec_rhs1,
   12787              :                                             vec_rhs2);
   12788          159 :           vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
   12789          159 :           if (bitop2 != NOP_EXPR)
   12790              :             {
   12791           86 :               tree res = make_ssa_name (mask);
   12792           86 :               if (bitop2 == BIT_NOT_EXPR)
   12793            0 :                 new_stmt = gimple_build_assign (res, bitop2, new_temp);
   12794              :               else
   12795           86 :                 new_stmt = gimple_build_assign (res, bitop2, vec_rhs1,
   12796              :                                                 new_temp);
   12797           86 :               vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
   12798              :             }
   12799              :         }
   12800        19797 :       slp_node->push_vec_def (new_stmt);
   12801              :     }
   12802              : 
   12803        13161 :   vec_oprnds0.release ();
   12804        13161 :   vec_oprnds1.release ();
   12805              : 
   12806        13161 :   return true;
   12807              : }
   12808              : 
   12809              : /* vectorizable_comparison.
   12810              : 
   12811              :    Check if STMT_INFO is comparison expression that can be vectorized.
   12812              :    If COST_VEC is passed, calculate costs but don't change anything,
   12813              :    otherwise, vectorize STMT_INFO: create a vectorized comparison, and insert
   12814              :    it at GSI.
   12815              : 
   12816              :    Return true if STMT_INFO is vectorizable in this way.  */
   12817              : 
   12818              : static bool
   12819       710806 : vectorizable_comparison (vec_info *vinfo,
   12820              :                          stmt_vec_info stmt_info, gimple_stmt_iterator *gsi,
   12821              :                          slp_tree slp_node, stmt_vector_for_cost *cost_vec)
   12822              : {
   12823       710806 :   bb_vec_info bb_vinfo = dyn_cast <bb_vec_info> (vinfo);
   12824              : 
   12825       710806 :   if (!STMT_VINFO_RELEVANT_P (stmt_info) && !bb_vinfo)
   12826              :     return false;
   12827              : 
   12828       710806 :   if (STMT_VINFO_DEF_TYPE (stmt_info) != vect_internal_def)
   12829              :     return false;
   12830              : 
   12831       463989 :   gassign *stmt = dyn_cast <gassign *> (stmt_info->stmt);
   12832       390884 :   if (!stmt)
   12833              :     return false;
   12834              : 
   12835       390884 :   enum tree_code code = gimple_assign_rhs_code (stmt);
   12836       390884 :   tree vectype = SLP_TREE_VECTYPE (slp_node);
   12837       390884 :   if (!vectorizable_comparison_1 (vinfo, vectype, stmt_info, code, gsi,
   12838              :                                   slp_node, cost_vec))
   12839              :     return false;
   12840              : 
   12841       162076 :   if (cost_vec)
   12842       148915 :     SLP_TREE_TYPE (slp_node) = comparison_vec_info_type;
   12843              : 
   12844              :   return true;
   12845              : }
   12846              : 
   12847              : /* Check to see if the target supports any of the compare and branch optabs for
   12848              :    vectors with MODE as these would be required when expanding.  */
   12849              : static bool
   12850        67974 : supports_vector_compare_and_branch (loop_vec_info loop_vinfo, machine_mode mode)
   12851              : {
   12852        67974 :   bool masked_loop_p = LOOP_VINFO_FULLY_MASKED_P (loop_vinfo);
   12853        67974 :   bool len_loop_p = LOOP_VINFO_FULLY_WITH_LENGTH_P (loop_vinfo);
   12854              : 
   12855              :   /* The vectorizer only produces vec_cbranch_any_optab directly.  So only
   12856              :      check for support for that or vec_cbranch_any_optab when masked.
   12857              :      We can't produce vcond_cbranch_any directly from the vectorizer as we
   12858              :      want to keep gimple_cond as the GIMPLE representation.  But we'll fold
   12859              :      it in expand.  For that reason we require a backend to support the
   12860              :      unconditional vector cbranch optab if they support the conditional one,
   12861              :      which is just an optimization on the unconditional one.  */
   12862        67974 :   if (masked_loop_p
   12863        67974 :       && direct_optab_handler (cond_vec_cbranch_any_optab, mode)
   12864              :                 != CODE_FOR_nothing)
   12865              :     return true;
   12866        67974 :   else if (len_loop_p
   12867        67974 :            && direct_optab_handler (cond_len_vec_cbranch_any_optab, mode)
   12868              :                 != CODE_FOR_nothing)
   12869              :     return true;
   12870        67974 :   else if (!masked_loop_p && !len_loop_p
   12871       135948 :            && direct_optab_handler (vec_cbranch_any_optab, mode)
   12872              :                 != CODE_FOR_nothing)
   12873              :     return true;
   12874              : 
   12875              :   /* The target can implement cbranch to distinguish between boolean vector
   12876              :      types and data types if they don't have a different mode for both.  */
   12877        67974 :   return direct_optab_handler (cbranch_optab, mode) != CODE_FOR_nothing;
   12878              : }
   12879              : 
   12880              : /* Determine the type to use for early break vectorization's scalar IV.  If
   12881              :    no type is possible return false.  */
   12882              : 
   12883              : static bool
   12884         2786 : vect_compute_type_for_early_break_scalar_iv (loop_vec_info loop_vinfo)
   12885              : {
   12886              :   /* Check if we have a usable scalar IV type for vectorization.  */
   12887         2786 :   tree iters_vf_type = sizetype;
   12888         2786 :   if (!LOOP_VINFO_NITERS_UNCOUNTED_P (loop_vinfo))
   12889              :     {
   12890              :       /* Find the type with the minimum precision we can use
   12891              :          for the scalar IV.  */
   12892         2549 :       tree cand_type = TREE_TYPE (LOOP_VINFO_NITERS (loop_vinfo));
   12893              : 
   12894              :       /* Work out how many bits we need to represent the limit.  */
   12895         2549 :       unsigned int min_ni_width
   12896         2549 :         = vect_min_prec_for_max_niters (loop_vinfo, 1);
   12897              : 
   12898              :       /* Check if we're using PFA, if so we need a signed IV and an
   12899              :          extra bit for the sign.  */
   12900         2549 :       if (TYPE_UNSIGNED (cand_type)
   12901         2549 :           && LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo)
   12902         4124 :           && LOOP_VINFO_PEELING_FOR_ALIGNMENT (loop_vinfo))
   12903          159 :         min_ni_width += 1;
   12904              : 
   12905         2549 :       if (TYPE_PRECISION (cand_type) >= min_ni_width)
   12906         2472 :         iters_vf_type = unsigned_type_for (cand_type);
   12907              :       else
   12908              :         {
   12909           77 :           opt_scalar_int_mode cmp_mode_iter;
   12910           77 :           tree iv_type = NULL_TREE;
   12911          373 :           FOR_EACH_MODE_IN_CLASS (cmp_mode_iter, MODE_INT)
   12912              :             {
   12913          373 :               auto cmp_mode = cmp_mode_iter.require ();
   12914          373 :               unsigned int cmp_bits = GET_MODE_BITSIZE (cmp_mode);
   12915          373 :               if (cmp_bits >= min_ni_width
   12916          373 :                   && targetm.scalar_mode_supported_p (cmp_mode))
   12917              :                 {
   12918           77 :                   iv_type = build_nonstandard_integer_type (cmp_bits, true);
   12919           77 :                   if (iv_type)
   12920              :                     break;
   12921              :                 }
   12922              :             }
   12923              : 
   12924           77 :           if (!iv_type)
   12925              :             {
   12926            0 :               if (dump_enabled_p ())
   12927            0 :                 dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
   12928              :                        "can't vectorize early exit because the "
   12929              :                        "target doesn't support a scalar type wide "
   12930              :                        "wide enough to hold niters.\n");
   12931            0 :               return false;
   12932              :             }
   12933           77 :           iters_vf_type = iv_type;
   12934              :         }
   12935              :     }
   12936              : 
   12937         2786 :   LOOP_VINFO_EARLY_BRK_IV_TYPE (loop_vinfo) = iters_vf_type;
   12938         2786 :   return true;
   12939              : }
   12940              : 
   12941              : /* Check to see if the current early break given in STMT_INFO is valid for
   12942              :    vectorization.  */
   12943              : 
   12944              : bool
   12945       267265 : vectorizable_early_exit (loop_vec_info loop_vinfo, stmt_vec_info stmt_info,
   12946              :                          gimple_stmt_iterator *gsi,
   12947              :                          slp_tree slp_node, stmt_vector_for_cost *cost_vec)
   12948              : {
   12949       267265 :   if (!is_a <gcond *> (STMT_VINFO_STMT (stmt_info)))
   12950              :     return false;
   12951              : 
   12952        69656 :   if (STMT_VINFO_DEF_TYPE (stmt_info) != vect_condition_def)
   12953              :     return false;
   12954              : 
   12955        69656 :   if (!STMT_VINFO_RELEVANT_P (stmt_info))
   12956              :     return false;
   12957              : 
   12958        69656 :   DUMP_VECT_SCOPE ("vectorizable_early_exit");
   12959              : 
   12960        69656 :   auto code = gimple_cond_code (STMT_VINFO_STMT (stmt_info));
   12961              : 
   12962              :   /* For SLP we don't want to use the type of the operands of the SLP node, when
   12963              :      vectorizing using SLP slp_node will be the children of the gcond and we
   12964              :      want to use the type of the direct children which since the gcond is root
   12965              :      will be the current node, rather than a child node as vect_is_simple_use
   12966              :      assumes.  */
   12967        69656 :   tree vectype = SLP_TREE_VECTYPE (slp_node);
   12968        69656 :   if (!vectype)
   12969              :     return false;
   12970              : 
   12971        69656 :   machine_mode mode = TYPE_MODE (vectype);
   12972        69656 :   int vec_num = vect_get_num_copies (loop_vinfo, slp_node);
   12973              : 
   12974        69656 :   bool masked_loop_p = LOOP_VINFO_FULLY_MASKED_P (loop_vinfo);
   12975        69656 :   bool len_loop_p = LOOP_VINFO_FULLY_WITH_LENGTH_P (loop_vinfo);
   12976              : 
   12977              :   /* Now build the new conditional.  Pattern gimple_conds get dropped during
   12978              :      codegen so we must replace the original insn.  */
   12979        69656 :   gimple *orig_stmt = STMT_VINFO_STMT (vect_orig_stmt (stmt_info));
   12980        69656 :   gcond *cond_stmt = as_a <gcond *>(orig_stmt);
   12981              : 
   12982        69656 :   tree vectype_out = vectype;
   12983        69656 :   auto bb = gimple_bb (cond_stmt);
   12984        69656 :   edge exit_true_edge = EDGE_SUCC (bb, 0);
   12985        69656 :   if (exit_true_edge->flags & EDGE_FALSE_VALUE)
   12986          889 :     exit_true_edge = EDGE_SUCC (bb, 1);
   12987        69656 :   gcc_assert (exit_true_edge->flags & EDGE_TRUE_VALUE);
   12988              : 
   12989              :   /* When vectorizing we assume that if the branch edge is taken that we're
   12990              :      exiting the loop.  This is not however always the case as the compiler will
   12991              :      rewrite conditions to always be a comparison against 0.  To do this it
   12992              :      sometimes flips the edges.  This is fine for scalar,  but for vector we
   12993              :      then have to negate the result of the test, as we're still assuming that if
   12994              :      you take the branch edge that we found the exit condition.  i.e. we need to
   12995              :      know whether we are generating a `forall` or an `exist` condition.  */
   12996       139312 :   bool flipped = flow_bb_inside_loop_p (LOOP_VINFO_LOOP (loop_vinfo),
   12997        69656 :                                         exit_true_edge->dest);
   12998              : 
   12999              :   /* See if we support ADDHN and use that for the reduction.  */
   13000        69656 :   internal_fn ifn = IFN_VEC_TRUNC_ADD_HIGH;
   13001        69656 :   bool addhn_supported_p
   13002        69656 :     = direct_internal_fn_supported_p (ifn, vectype, OPTIMIZE_FOR_BOTH);
   13003        69656 :   tree narrow_type = NULL_TREE;
   13004        69656 :   if (addhn_supported_p)
   13005              :     {
   13006              :       /* Calculate the narrowing type for the result.  */
   13007            0 :       auto halfprec = TYPE_PRECISION (TREE_TYPE (vectype)) / 2;
   13008            0 :       auto unsignedp = TYPE_UNSIGNED (TREE_TYPE (vectype));
   13009            0 :       tree itype = build_nonstandard_integer_type (halfprec, unsignedp);
   13010            0 :       tree tmp_type = build_vector_type (itype, TYPE_VECTOR_SUBPARTS (vectype));
   13011            0 :       narrow_type = truth_type_for (tmp_type);
   13012              : 
   13013            0 :       if (!supports_vector_compare_and_branch (loop_vinfo,
   13014            0 :                                                TYPE_MODE (narrow_type)))
   13015              :         {
   13016            0 :           if (dump_enabled_p ())
   13017            0 :               dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
   13018              :                                "can't use ADDHN reduction because cbranch for "
   13019              :                                "the narrowed type is not supported by the "
   13020              :                                "target.\n");
   13021              :           addhn_supported_p = false;
   13022              :         }
   13023              :     }
   13024              : 
   13025              :   /* Analyze only.  */
   13026        69656 :   if (cost_vec)
   13027              :     {
   13028        67974 :       if (!addhn_supported_p
   13029        67974 :           && !supports_vector_compare_and_branch (loop_vinfo, mode))
   13030              :         {
   13031        65188 :           if (dump_enabled_p ())
   13032          801 :               dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
   13033              :                                "can't vectorize early exit because the "
   13034              :                                "target doesn't support flag setting vector "
   13035              :                                "comparisons.\n");
   13036              :           return false;
   13037              :         }
   13038              : 
   13039         2786 :       if (!vectorizable_comparison_1 (loop_vinfo, vectype, stmt_info, code, gsi,
   13040              :                                       slp_node, cost_vec))
   13041              :         return false;
   13042              : 
   13043         2786 :       if (LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo))
   13044              :         {
   13045         1575 :           if (direct_internal_fn_supported_p (IFN_VCOND_MASK_LEN, vectype,
   13046              :                                               OPTIMIZE_FOR_SPEED))
   13047            0 :             vect_record_len (loop_vinfo, vec_num, vectype, 1);
   13048              :           else
   13049         1575 :             vect_record_mask (loop_vinfo, vec_num, vectype, NULL_TREE);
   13050              :         }
   13051              : 
   13052         2786 :       if (!vect_compute_type_for_early_break_scalar_iv (loop_vinfo))
   13053              :         return false;
   13054              : 
   13055              :       return true;
   13056              :     }
   13057              : 
   13058              :   /* Transform.  */
   13059              : 
   13060         1682 :   tree new_temp = NULL_TREE;
   13061         1682 :   gimple *new_stmt = NULL;
   13062              : 
   13063         1682 :   if (dump_enabled_p ())
   13064          488 :     dump_printf_loc (MSG_NOTE, vect_location, "transform early-exit.\n");
   13065              : 
   13066              :   /* For SLP we don't do codegen of the body starting from the gcond, the gconds are
   13067              :      roots and so by the time we get to them we have already codegened the SLP tree
   13068              :      and so we shouldn't try to do so again.  The arguments have already been
   13069              :      vectorized.  It's not very clean to do this here, But the masking code below is
   13070              :      complex and this keeps it all in one place to ease fixes and backports.  Once we
   13071              :      drop the non-SLP loop vect or split vectorizable_* this can be simplified.  */
   13072              : 
   13073         1682 :   gimple *stmt = STMT_VINFO_STMT (stmt_info);
   13074         1682 :   basic_block cond_bb = gimple_bb (stmt);
   13075         1682 :   gimple_stmt_iterator  cond_gsi = gsi_last_bb (cond_bb);
   13076              : 
   13077         1682 :   auto_vec<tree> stmts;
   13078         1682 :   stmts.safe_splice (SLP_TREE_VEC_DEFS (slp_node));
   13079              : 
   13080              :   /* If we're comparing against a previous forall we need to negate the results
   13081              :      before we do the final comparison or reduction.  */
   13082         1682 :   if (flipped)
   13083              :     {
   13084              :       /* Rewrite the if(all(mask)) into if (!all(mask)) which is the same as
   13085              :          if (any(~mask)) by negating the masks and flipping the branches.
   13086              : 
   13087              :         1. For unmasked loops we simply reduce the ~mask.
   13088              :         2. For masked loops we reduce (~mask & loop_mask) which is the same as
   13089              :            doing (mask & loop_mask) ^ loop_mask.  */
   13090          398 :       for (unsigned i = 0; i < stmts.length (); i++)
   13091              :         {
   13092          253 :           tree inv_lhs = make_temp_ssa_name (vectype, NULL, "vexit_inv");
   13093          253 :           auto inv_stmt = gimple_build_assign (inv_lhs, BIT_NOT_EXPR, stmts[i]);
   13094          253 :           vect_finish_stmt_generation (loop_vinfo, stmt_info, inv_stmt,
   13095              :                                        &cond_gsi);
   13096          253 :           stmts[i] = inv_lhs;
   13097              :         }
   13098              : 
   13099          145 :       EDGE_SUCC (bb, 0)->flags ^= (EDGE_TRUE_VALUE|EDGE_FALSE_VALUE);
   13100          145 :       EDGE_SUCC (bb, 1)->flags ^= (EDGE_TRUE_VALUE|EDGE_FALSE_VALUE);
   13101              :     }
   13102              : 
   13103              :   /* Determine if we need to reduce the final value.  */
   13104         1682 :   if (stmts.length () > 1)
   13105              :     {
   13106              :       /* We build the reductions in a way to maintain as much parallelism as
   13107              :          possible.  */
   13108          169 :       auto_vec<tree> workset (stmts.length ());
   13109              : 
   13110              :       /* Mask the statements as we queue them up.  Normally we loop over
   13111              :          vec_num,  but since we inspect the exact results of vectorization
   13112              :          we don't need to and instead can just use the stmts themselves.  */
   13113          169 :       if (masked_loop_p)
   13114            0 :         for (unsigned i = 0; i < stmts.length (); i++)
   13115              :           {
   13116            0 :             tree stmt_mask
   13117            0 :               = vect_get_mask (loop_vinfo, gsi, vec_num, vectype, i);
   13118            0 :             stmt_mask = prepare_vec_mask (loop_vinfo, TREE_TYPE (stmt_mask),
   13119            0 :                                           stmt_mask, stmts[i], &cond_gsi);
   13120            0 :             workset.quick_push (stmt_mask);
   13121              :           }
   13122          169 :       else if (len_loop_p)
   13123          169 :         for (unsigned i = 0; i < stmts.length (); i++)
   13124              :           {
   13125            0 :             tree len_mask
   13126            0 :               = vect_gen_loop_len_mask (loop_vinfo, gsi, &cond_gsi, vec_num,
   13127            0 :                                         vectype, stmts[i], i, 1);
   13128              : 
   13129            0 :             workset.quick_push (len_mask);
   13130              :           }
   13131              :       else
   13132          169 :         workset.splice (stmts);
   13133              : 
   13134          520 :       while (workset.length () > 1)
   13135              :         {
   13136          351 :           tree arg0 = workset.pop ();
   13137          351 :           tree arg1 = workset.pop ();
   13138          351 :           if (addhn_supported_p && workset.length () == 0)
   13139              :             {
   13140            0 :               new_stmt = gimple_build_call_internal (ifn, 2, arg0, arg1);
   13141            0 :               vectype_out = narrow_type;
   13142            0 :               new_temp = make_temp_ssa_name (vectype_out, NULL, "vexit_reduc");
   13143            0 :               gimple_call_set_lhs (as_a <gcall *> (new_stmt), new_temp);
   13144            0 :               gimple_call_set_nothrow (as_a <gcall *> (new_stmt), true);
   13145              :             }
   13146              :           else
   13147              :             {
   13148          351 :               new_temp = make_temp_ssa_name (vectype_out, NULL, "vexit_reduc");
   13149          351 :               new_stmt
   13150          351 :                 = gimple_build_assign (new_temp, BIT_IOR_EXPR, arg0, arg1);
   13151              :             }
   13152          351 :           vect_finish_stmt_generation (loop_vinfo, stmt_info, new_stmt,
   13153              :                                        &cond_gsi);
   13154          351 :           workset.quick_insert (0, new_temp);
   13155              :         }
   13156          169 :     }
   13157              :   else
   13158              :     {
   13159         1513 :       new_temp = stmts[0];
   13160         1513 :       if (masked_loop_p)
   13161              :         {
   13162            2 :           tree mask = vect_get_mask (loop_vinfo, gsi, 1, vectype, 0);
   13163            2 :           new_temp = prepare_vec_mask (loop_vinfo, TREE_TYPE (mask), mask,
   13164              :                                        new_temp, &cond_gsi);
   13165              :         }
   13166         1511 :       else if (len_loop_p)
   13167            0 :         new_temp = vect_gen_loop_len_mask (loop_vinfo, gsi, &cond_gsi, 1,
   13168              :                                            vectype, new_temp, 0, 1);
   13169              :     }
   13170              : 
   13171         1682 :   gcc_assert (new_temp);
   13172              : 
   13173         1682 :   tree cst = build_zero_cst (vectype_out);
   13174         1682 :   gimple_cond_set_condition (cond_stmt, NE_EXPR, new_temp, cst);
   13175         1682 :   update_stmt (orig_stmt);
   13176              : 
   13177              :   /* ??? */
   13178         1682 :   SLP_TREE_VEC_DEFS (slp_node).truncate (0);
   13179              : 
   13180         1682 :   return true;
   13181         1682 : }
   13182              : 
   13183              : /* If SLP_NODE is nonnull, return true if vectorizable_live_operation
   13184              :    can handle all live statements in the node.  Otherwise return true
   13185              :    if STMT_INFO is not live or if vectorizable_live_operation can handle it.
   13186              :    VEC_STMT_P is as for vectorizable_live_operation.  */
   13187              : 
   13188              : static bool
   13189      1357380 : can_vectorize_live_stmts (vec_info *vinfo,
   13190              :                           slp_tree slp_node, slp_instance slp_node_instance,
   13191              :                           bool vec_stmt_p,
   13192              :                           stmt_vector_for_cost *cost_vec)
   13193              : {
   13194      1357380 :   stmt_vec_info slp_stmt_info;
   13195      1357380 :   unsigned int i;
   13196      2856240 :   FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_STMTS (slp_node), i, slp_stmt_info)
   13197              :     {
   13198      1498860 :       if (slp_stmt_info
   13199      1482277 :           && STMT_VINFO_LIVE_P (slp_stmt_info)
   13200      1634586 :           && !vectorizable_live_operation (vinfo, slp_stmt_info, slp_node,
   13201              :                                            slp_node_instance, i,
   13202              :                                            vec_stmt_p, cost_vec))
   13203              :         return false;
   13204              :     }
   13205              : 
   13206              :   return true;
   13207              : }
   13208              : 
   13209              : /* Make sure the statement is vectorizable.  */
   13210              : 
   13211              : opt_result
   13212      2677928 : vect_analyze_stmt (vec_info *vinfo,
   13213              :                    slp_tree node, slp_instance node_instance,
   13214              :                    stmt_vector_for_cost *cost_vec)
   13215              : {
   13216      2677928 :   stmt_vec_info stmt_info = SLP_TREE_REPRESENTATIVE (node);
   13217      2677928 :   bb_vec_info bb_vinfo = dyn_cast <bb_vec_info> (vinfo);
   13218      2677928 :   enum vect_relevant relevance = STMT_VINFO_RELEVANT (stmt_info);
   13219      2677928 :   bool ok;
   13220              : 
   13221      2677928 :   if (dump_enabled_p ())
   13222       110196 :     dump_printf_loc (MSG_NOTE, vect_location, "==> examining statement: %G",
   13223              :                      stmt_info->stmt);
   13224              : 
   13225      5056947 :   if (gimple_has_volatile_ops (stmt_info->stmt))
   13226              :     {
   13227              :       /* ???  This shouldn't really happen, volatile stmts should
   13228              :          not end up in the SLP graph.  */
   13229            0 :       return opt_result::failure_at (stmt_info->stmt,
   13230              :                                      "not vectorized:"
   13231              :                                      " stmt has volatile operands: %G\n",
   13232              :                                      stmt_info->stmt);
   13233              :     }
   13234              : 
   13235              :   /* Skip stmts that do not need to be vectorized.  */
   13236      2677928 :   if (!STMT_VINFO_RELEVANT_P (stmt_info)
   13237            0 :       && !STMT_VINFO_LIVE_P (stmt_info))
   13238              :     {
   13239            0 :       if (dump_enabled_p ())
   13240            0 :         dump_printf_loc (MSG_NOTE, vect_location, "irrelevant.\n");
   13241              : 
   13242              :       /* ???  This shouldn't really happen, irrelevant stmts should
   13243              :          not end up in the SLP graph.  */
   13244            0 :       return opt_result::failure_at (stmt_info->stmt,
   13245              :                                      "not vectorized:"
   13246              :                                      " irrelevant stmt as SLP node %p "
   13247              :                                      "representative.\n",
   13248              :                                      (void *)node);
   13249              :     }
   13250              : 
   13251      2677928 :   switch (STMT_VINFO_DEF_TYPE (stmt_info))
   13252              :     {
   13253              :       case vect_internal_def:
   13254              :       case vect_condition_def:
   13255              :         break;
   13256              : 
   13257        83588 :       case vect_reduction_def:
   13258        83588 :       case vect_nested_cycle:
   13259        83588 :          gcc_assert (!bb_vinfo
   13260              :                      && (relevance == vect_used_in_outer
   13261              :                          || relevance == vect_used_in_outer_by_reduction
   13262              :                          || relevance == vect_used_by_reduction
   13263              :                          || relevance == vect_unused_in_scope
   13264              :                          || relevance == vect_used_only_live));
   13265              :          break;
   13266              : 
   13267          322 :       case vect_double_reduction_def:
   13268          322 :         gcc_assert (!bb_vinfo && node);
   13269              :         break;
   13270              : 
   13271       162901 :       case vect_induction_def:
   13272       162901 :       case vect_first_order_recurrence:
   13273       162901 :         gcc_assert (!bb_vinfo);
   13274              :         break;
   13275              : 
   13276            0 :       case vect_constant_def:
   13277            0 :       case vect_external_def:
   13278            0 :       case vect_unknown_def_type:
   13279            0 :       default:
   13280            0 :         gcc_unreachable ();
   13281              :     }
   13282              : 
   13283      2677928 :   tree saved_vectype = STMT_VINFO_VECTYPE (stmt_info);
   13284      2677928 :   STMT_VINFO_VECTYPE (stmt_info) = NULL_TREE;
   13285              : 
   13286      2677928 :   if (STMT_VINFO_RELEVANT_P (stmt_info))
   13287              :     {
   13288      2677928 :       gcall *call = dyn_cast <gcall *> (stmt_info->stmt);
   13289      2677928 :       gcc_assert (SLP_TREE_VECTYPE (node)
   13290              :                   || gimple_code (stmt_info->stmt) == GIMPLE_COND
   13291              :                   || (call && gimple_call_lhs (call) == NULL_TREE));
   13292              :     }
   13293              : 
   13294      2677928 :   ok = true;
   13295      2677928 :   if (bb_vinfo
   13296      1554989 :       || (STMT_VINFO_RELEVANT_P (stmt_info)
   13297            0 :           || STMT_VINFO_DEF_TYPE (stmt_info) == vect_reduction_def))
   13298              :     /* Prefer vectorizable_call over vectorizable_simd_clone_call so
   13299              :        -mveclibabi= takes preference over library functions with
   13300              :        the simd attribute.  */
   13301      2677928 :     ok = (vectorizable_call (vinfo, stmt_info, NULL, node, cost_vec)
   13302      2669456 :           || vectorizable_simd_clone_call (vinfo, stmt_info, NULL, node,
   13303              :                                            cost_vec)
   13304      2668947 :           || vectorizable_conversion (vinfo, stmt_info, NULL, node, cost_vec)
   13305      2580616 :           || vectorizable_operation (vinfo, stmt_info, NULL, node, cost_vec)
   13306      2153286 :           || vectorizable_assignment (vinfo, stmt_info, NULL, node, cost_vec)
   13307      2079920 :           || vectorizable_load (vinfo, stmt_info, NULL, node, cost_vec)
   13308      1607690 :           || vectorizable_store (vinfo, stmt_info, NULL, node, cost_vec)
   13309       775516 :           || vectorizable_shift (vinfo, stmt_info, NULL, node, cost_vec)
   13310       725457 :           || vectorizable_condition (vinfo, stmt_info, NULL, node, cost_vec)
   13311       697645 :           || vectorizable_comparison (vinfo, stmt_info, NULL, node, cost_vec)
   13312       548730 :           || (bb_vinfo
   13313       140867 :               && vectorizable_phi (bb_vinfo, stmt_info, node, cost_vec))
   13314      3166913 :           || (is_a <loop_vec_info> (vinfo)
   13315       407863 :               && (vectorizable_lane_reducing (as_a <loop_vec_info> (vinfo),
   13316              :                                               stmt_info, node, cost_vec)
   13317       407075 :                   || vectorizable_reduction (as_a <loop_vec_info> (vinfo),
   13318              :                                              stmt_info,
   13319              :                                              node, node_instance, cost_vec)
   13320       326141 :                   || vectorizable_induction (as_a <loop_vec_info> (vinfo),
   13321              :                                              stmt_info, node, cost_vec)
   13322       198693 :                   || vectorizable_lc_phi (as_a <loop_vec_info> (vinfo),
   13323              :                                           stmt_info, node)
   13324       197878 :                   || vectorizable_recurr (as_a <loop_vec_info> (vinfo),
   13325              :                                           stmt_info, node, cost_vec)
   13326       197609 :                   || vectorizable_early_exit (as_a <loop_vec_info> (vinfo),
   13327              :                                               stmt_info, NULL, node,
   13328              :                                               cost_vec))));
   13329              : 
   13330      2677928 :   STMT_VINFO_VECTYPE (stmt_info) = saved_vectype;
   13331              : 
   13332      2399197 :   if (!ok)
   13333       278731 :     return opt_result::failure_at (stmt_info->stmt,
   13334              :                                    "not vectorized:"
   13335              :                                    " relevant stmt not supported: %G",
   13336              :                                    stmt_info->stmt);
   13337              : 
   13338              :   /* Stmts that are (also) "live" (i.e. - that are used out of the loop)
   13339              :       need extra handling, except for vectorizable reductions.  */
   13340      2399197 :   if (!bb_vinfo
   13341      1357380 :       && (SLP_TREE_TYPE (node) != lc_phi_info_type
   13342          815 :           || SLP_TREE_DEF_TYPE (node) == vect_internal_def)
   13343      1357380 :       && (!node->ldst_lanes || SLP_TREE_PERMUTE_P (node))
   13344      3756577 :       && !can_vectorize_live_stmts (as_a <loop_vec_info> (vinfo),
   13345              :                                     node, node_instance,
   13346              :                                     false, cost_vec))
   13347            0 :     return opt_result::failure_at (stmt_info->stmt,
   13348              :                                    "not vectorized:"
   13349              :                                    " live stmt not supported: %G",
   13350              :                                    stmt_info->stmt);
   13351              : 
   13352      2399197 :   return opt_result::success ();
   13353              : }
   13354              : 
   13355              : 
   13356              : /* Function vect_transform_stmt.
   13357              : 
   13358              :    Create a vectorized stmt to replace STMT_INFO, and insert it at GSI.  */
   13359              : 
   13360              : void
   13361       991427 : vect_transform_stmt (vec_info *vinfo,
   13362              :                      stmt_vec_info stmt_info, gimple_stmt_iterator *gsi,
   13363              :                      slp_tree slp_node, slp_instance slp_node_instance)
   13364              : {
   13365       991427 :   bool done;
   13366              : 
   13367       991427 :   gcc_assert (slp_node);
   13368              : 
   13369       991427 :   if (stmt_info)
   13370       974470 :     STMT_VINFO_VECTYPE (stmt_info) = NULL_TREE;
   13371              : 
   13372       991427 :   switch (SLP_TREE_TYPE (slp_node))
   13373              :     {
   13374        24054 :     case type_demotion_vec_info_type:
   13375        24054 :     case type_promotion_vec_info_type:
   13376        24054 :     case type_conversion_vec_info_type:
   13377        24054 :       done = vectorizable_conversion (vinfo, stmt_info, gsi, slp_node, NULL);
   13378        24054 :       gcc_assert (done);
   13379              :       break;
   13380              : 
   13381        18364 :     case induc_vec_info_type:
   13382        18364 :       done = vectorizable_induction (as_a <loop_vec_info> (vinfo),
   13383              :                                      stmt_info, slp_node, NULL);
   13384        18364 :       gcc_assert (done);
   13385              :       break;
   13386              : 
   13387         9583 :     case shift_vec_info_type:
   13388         9583 :       done = vectorizable_shift (vinfo, stmt_info, gsi, slp_node, NULL);
   13389         9583 :       gcc_assert (done);
   13390              :       break;
   13391              : 
   13392       122681 :     case op_vec_info_type:
   13393       122681 :       done = vectorizable_operation (vinfo, stmt_info, gsi, slp_node, NULL);
   13394       122681 :       gcc_assert (done);
   13395              :       break;
   13396              : 
   13397        17415 :     case assignment_vec_info_type:
   13398        17415 :       done = vectorizable_assignment (vinfo, stmt_info, gsi, slp_node, NULL);
   13399        17415 :       gcc_assert (done);
   13400              :       break;
   13401              : 
   13402       160249 :     case load_vec_info_type:
   13403       160249 :       done = vectorizable_load (vinfo, stmt_info, gsi, slp_node, NULL);
   13404       160249 :       gcc_assert (done);
   13405              :       break;
   13406              : 
   13407       554872 :     case store_vec_info_type:
   13408       554872 :       done = vectorizable_store (vinfo, stmt_info, gsi, slp_node, NULL);
   13409       554872 :       gcc_assert (done);
   13410              :       break;
   13411              : 
   13412         9039 :     case condition_vec_info_type:
   13413         9039 :       done = vectorizable_condition (vinfo, stmt_info, gsi, slp_node, NULL);
   13414         9039 :       gcc_assert (done);
   13415              :       break;
   13416              : 
   13417        13161 :     case comparison_vec_info_type:
   13418        13161 :       done = vectorizable_comparison (vinfo, stmt_info, gsi, slp_node, NULL);
   13419        13161 :       gcc_assert (done);
   13420              :       break;
   13421              : 
   13422         4920 :     case call_vec_info_type:
   13423         4920 :       done = vectorizable_call (vinfo, stmt_info, gsi, slp_node, NULL);
   13424         4920 :       break;
   13425              : 
   13426          390 :     case call_simd_clone_vec_info_type:
   13427          390 :       done = vectorizable_simd_clone_call (vinfo, stmt_info, gsi,
   13428              :                                            slp_node, NULL);
   13429          390 :       break;
   13430              : 
   13431         2773 :     case reduc_vec_info_type:
   13432         2773 :       done = vect_transform_reduction (as_a <loop_vec_info> (vinfo), stmt_info,
   13433              :                                        gsi, slp_node);
   13434         2773 :       gcc_assert (done);
   13435              :       break;
   13436              : 
   13437        23868 :     case cycle_phi_info_type:
   13438        23868 :       done = vect_transform_cycle_phi (as_a <loop_vec_info> (vinfo), stmt_info,
   13439              :                                        slp_node, slp_node_instance);
   13440        23868 :       gcc_assert (done);
   13441              :       break;
   13442              : 
   13443          494 :     case lc_phi_info_type:
   13444          494 :       done = vect_transform_lc_phi (as_a <loop_vec_info> (vinfo),
   13445              :                                     stmt_info, slp_node);
   13446          494 :       gcc_assert (done);
   13447              :       break;
   13448              : 
   13449           43 :     case recurr_info_type:
   13450           43 :       done = vectorizable_recurr (as_a <loop_vec_info> (vinfo),
   13451              :                                   stmt_info, slp_node, NULL);
   13452           43 :       gcc_assert (done);
   13453              :       break;
   13454              : 
   13455        12564 :     case phi_info_type:
   13456        12564 :       done = vectorizable_phi (as_a <bb_vec_info> (vinfo),
   13457              :                                stmt_info, slp_node, NULL);
   13458        12564 :       gcc_assert (done);
   13459              :       break;
   13460              : 
   13461            0 :     case loop_exit_ctrl_vec_info_type:
   13462            0 :       done = vectorizable_early_exit (as_a <loop_vec_info> (vinfo),
   13463              :                                       stmt_info, gsi, slp_node, NULL);
   13464            0 :       gcc_assert (done);
   13465              :       break;
   13466              : 
   13467        16957 :     case permute_info_type:
   13468        16957 :       done = vectorizable_slp_permutation (vinfo, gsi, slp_node, NULL);
   13469        16957 :       gcc_assert (done);
   13470              :       break;
   13471              : 
   13472            0 :     default:
   13473            0 :       if (!STMT_VINFO_LIVE_P (stmt_info))
   13474              :         {
   13475            0 :           if (dump_enabled_p ())
   13476            0 :             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
   13477              :                              "stmt not supported.\n");
   13478            0 :           gcc_unreachable ();
   13479              :         }
   13480       991427 :       done = true;
   13481              :     }
   13482              : 
   13483       991427 :   if (SLP_TREE_TYPE (slp_node) != store_vec_info_type
   13484       436555 :       && (!slp_node->ldst_lanes || SLP_TREE_PERMUTE_P (slp_node)))
   13485              :     {
   13486              :       /* Handle stmts whose DEF is used outside the loop-nest that is
   13487              :          being vectorized.  */
   13488       548633 :       for (unsigned lane : SLP_TREE_LIVE_LANES (slp_node))
   13489              :         {
   13490        41246 :           stmt_vec_info slp_stmt_info = SLP_TREE_SCALAR_STMTS (slp_node)[lane];
   13491        41246 :           done = vectorizable_live_operation (vinfo, slp_stmt_info, slp_node,
   13492              :                                               slp_node_instance, lane,
   13493              :                                               true, NULL);
   13494        41246 :           gcc_assert (done);
   13495              :         }
   13496              :     }
   13497       991427 : }
   13498              : 
   13499              : 
   13500              : /* Remove a group of stores (for SLP or interleaving), free their
   13501              :    stmt_vec_info.  */
   13502              : 
   13503              : void
   13504            0 : vect_remove_stores (vec_info *vinfo, stmt_vec_info first_stmt_info)
   13505              : {
   13506            0 :   stmt_vec_info next_stmt_info = first_stmt_info;
   13507              : 
   13508            0 :   while (next_stmt_info)
   13509              :     {
   13510            0 :       stmt_vec_info tmp = DR_GROUP_NEXT_ELEMENT (next_stmt_info);
   13511            0 :       next_stmt_info = vect_orig_stmt (next_stmt_info);
   13512              :       /* Free the attached stmt_vec_info and remove the stmt.  */
   13513            0 :       vinfo->remove_stmt (next_stmt_info);
   13514            0 :       next_stmt_info = tmp;
   13515              :     }
   13516            0 : }
   13517              : 
   13518              : /* If NUNITS is nonzero, return a vector type that contains NUNITS
   13519              :    elements of type SCALAR_TYPE, or null if the target doesn't support
   13520              :    such a type.
   13521              : 
   13522              :    If NUNITS is zero, return a vector type that contains elements of
   13523              :    type SCALAR_TYPE, choosing whichever vector size the target prefers.
   13524              : 
   13525              :    If PREVAILING_MODE is VOIDmode, we have not yet chosen a vector mode
   13526              :    for this vectorization region and want to "autodetect" the best choice.
   13527              :    Otherwise, PREVAILING_MODE is a previously-chosen vector TYPE_MODE
   13528              :    and we want the new type to be interoperable with it.   PREVAILING_MODE
   13529              :    in this case can be a scalar integer mode or a vector mode; when it
   13530              :    is a vector mode, the function acts like a tree-level version of
   13531              :    related_vector_mode.  */
   13532              : 
   13533              : tree
   13534     31013473 : get_related_vectype_for_scalar_type (machine_mode prevailing_mode,
   13535              :                                      tree scalar_type, poly_uint64 nunits)
   13536              : {
   13537     31013473 :   tree orig_scalar_type = scalar_type;
   13538     31013473 :   scalar_mode inner_mode;
   13539     31013473 :   machine_mode simd_mode;
   13540     31013473 :   tree vectype;
   13541              : 
   13542     31013473 :   if ((!INTEGRAL_TYPE_P (scalar_type)
   13543     10170889 :        && !POINTER_TYPE_P (scalar_type)
   13544      2191526 :        && !SCALAR_FLOAT_TYPE_P (scalar_type))
   13545     40612026 :       || (!is_int_mode (TYPE_MODE (scalar_type), &inner_mode)
   13546      1619344 :           && !is_float_mode (TYPE_MODE (scalar_type), &inner_mode)))
   13547              :     return NULL_TREE;
   13548              : 
   13549     30437763 :   unsigned int nbytes = GET_MODE_SIZE (inner_mode);
   13550              : 
   13551              :   /* Interoperability between modes requires one to be a constant multiple
   13552              :      of the other, so that the number of vectors required for each operation
   13553              :      is a compile-time constant.  */
   13554     30437763 :   if (prevailing_mode != VOIDmode
   13555     29264080 :       && !constant_multiple_p (nunits * nbytes,
   13556     29264080 :                                GET_MODE_SIZE (prevailing_mode))
   13557     31708365 :       && !constant_multiple_p (GET_MODE_SIZE (prevailing_mode),
   13558      1270602 :                                nunits * nbytes))
   13559              :     return NULL_TREE;
   13560              : 
   13561              :   /* For vector types of elements whose mode precision doesn't
   13562              :      match their types precision we use a element type of mode
   13563              :      precision.  The vectorization routines will have to make sure
   13564              :      they support the proper result truncation/extension.
   13565              :      We also make sure to build vector types with INTEGER_TYPE
   13566              :      component type only.  */
   13567     30437763 :   if (INTEGRAL_TYPE_P (scalar_type)
   13568     51280193 :       && (GET_MODE_BITSIZE (inner_mode) != TYPE_PRECISION (scalar_type)
   13569     19627032 :           || TREE_CODE (scalar_type) != INTEGER_TYPE))
   13570      1433706 :     scalar_type = build_nonstandard_integer_type (GET_MODE_BITSIZE (inner_mode),
   13571      1433706 :                                                   TYPE_UNSIGNED (scalar_type));
   13572              : 
   13573              :   /* We shouldn't end up building VECTOR_TYPEs of non-scalar components.
   13574              :      When the component mode passes the above test simply use a type
   13575              :      corresponding to that mode.  The theory is that any use that
   13576              :      would cause problems with this will disable vectorization anyway.  */
   13577     29004057 :   else if (!SCALAR_FLOAT_TYPE_P (scalar_type)
   13578              :            && !INTEGRAL_TYPE_P (scalar_type))
   13579      7979363 :     scalar_type = lang_hooks.types.type_for_mode (inner_mode, 1);
   13580              : 
   13581              :   /* We can't build a vector type of elements with alignment bigger than
   13582              :      their size.  */
   13583     21024694 :   else if (nbytes < TYPE_ALIGN_UNIT (scalar_type))
   13584       421186 :     scalar_type = lang_hooks.types.type_for_mode (inner_mode,
   13585       210593 :                                                   TYPE_UNSIGNED (scalar_type));
   13586              : 
   13587              :   /* If we felt back to using the mode fail if there was
   13588              :      no scalar type for it.  */
   13589     30437763 :   if (scalar_type == NULL_TREE)
   13590              :     return NULL_TREE;
   13591              : 
   13592              :   /* If no prevailing mode was supplied, use the mode the target prefers.
   13593              :      Otherwise lookup a vector mode based on the prevailing mode.  */
   13594     30437763 :   if (prevailing_mode == VOIDmode)
   13595              :     {
   13596      1173683 :       gcc_assert (known_eq (nunits, 0U));
   13597      1173683 :       simd_mode = targetm.vectorize.preferred_simd_mode (inner_mode);
   13598      1173683 :       if (SCALAR_INT_MODE_P (simd_mode))
   13599              :         {
   13600              :           /* Traditional behavior is not to take the integer mode
   13601              :              literally, but simply to use it as a way of determining
   13602              :              the vector size.  It is up to mode_for_vector to decide
   13603              :              what the TYPE_MODE should be.
   13604              : 
   13605              :              Note that nunits == 1 is allowed in order to support single
   13606              :              element vector types.  */
   13607        66786 :           if (!multiple_p (GET_MODE_SIZE (simd_mode), nbytes, &nunits)
   13608        33393 :               || !mode_for_vector (inner_mode, nunits).exists (&simd_mode))
   13609              :             return NULL_TREE;
   13610              :         }
   13611              :     }
   13612     29264080 :   else if (SCALAR_INT_MODE_P (prevailing_mode)
   13613     29264080 :            || !related_vector_mode (prevailing_mode,
   13614     29263423 :                                     inner_mode, nunits).exists (&simd_mode))
   13615              :     {
   13616              :       /* Fall back to using mode_for_vector, mostly in the hope of being
   13617              :          able to use an integer mode.  */
   13618      2401011 :       if (known_eq (nunits, 0U)
   13619      4796393 :           && !multiple_p (GET_MODE_SIZE (prevailing_mode), nbytes, &nunits))
   13620              :         return NULL_TREE;
   13621              : 
   13622       243598 :       if (!mode_for_vector (inner_mode, nunits).exists (&simd_mode))
   13623       228154 :         return NULL_TREE;
   13624              :     }
   13625              : 
   13626     28019558 :   vectype = build_vector_type_for_mode (scalar_type, simd_mode);
   13627              : 
   13628              :   /* In cases where the mode was chosen by mode_for_vector, check that
   13629              :      the target actually supports the chosen mode, or that it at least
   13630              :      allows the vector mode to be replaced by a like-sized integer.  */
   13631     56039116 :   if (!VECTOR_MODE_P (TYPE_MODE (vectype))
   13632     28035344 :       && !INTEGRAL_MODE_P (TYPE_MODE (vectype)))
   13633              :     return NULL_TREE;
   13634              : 
   13635              :   /* Re-attach the address-space qualifier if we canonicalized the scalar
   13636              :      type.  */
   13637     28011310 :   if (TYPE_ADDR_SPACE (orig_scalar_type) != TYPE_ADDR_SPACE (vectype))
   13638            3 :     return build_qualified_type
   13639            3 :       (vectype, qualifier_set {TYPE_UNQUALIFIED,
   13640            3 :                                TYPE_ADDR_SPACE (orig_scalar_type)});
   13641              : 
   13642              :   return vectype;
   13643              : }
   13644              : 
   13645              : /* Function get_vectype_for_scalar_type.
   13646              : 
   13647              :    Returns the vector type corresponding to SCALAR_TYPE as supported
   13648              :    by the target.  If GROUP_SIZE is nonzero and we're performing BB
   13649              :    vectorization, make sure that the number of elements in the vector
   13650              :    is no bigger than GROUP_SIZE.  */
   13651              : 
   13652              : tree
   13653     27032084 : get_vectype_for_scalar_type (vec_info *vinfo, tree scalar_type,
   13654              :                              unsigned int group_size)
   13655              : {
   13656              :   /* For BB vectorization, we should always have a group size once we've
   13657              :      constructed the SLP tree; the only valid uses of zero GROUP_SIZEs
   13658              :      are tentative requests during things like early data reference
   13659              :      analysis and pattern recognition.  */
   13660     27032084 :   if (is_a <bb_vec_info> (vinfo))
   13661     23980918 :     gcc_assert (vinfo->slp_instances.is_empty () || group_size != 0);
   13662              :   else
   13663              :     group_size = 0;
   13664              : 
   13665     27032084 :   tree vectype = get_related_vectype_for_scalar_type (vinfo->vector_mode,
   13666              :                                                       scalar_type);
   13667     27032084 :   if (vectype && vinfo->vector_mode == VOIDmode)
   13668      1088214 :     vinfo->vector_mode = TYPE_MODE (vectype);
   13669              : 
   13670              :   /* Register the natural choice of vector type, before the group size
   13671              :      has been applied.  */
   13672            0 :   if (vectype)
   13673     24205347 :     vinfo->shared->used_vector_modes.add (TYPE_MODE (vectype));
   13674              : 
   13675              :   /* If the natural choice of vector type doesn't satisfy GROUP_SIZE,
   13676              :      try again with an explicit number of elements.  */
   13677     24205347 :   if (vectype
   13678     24205347 :       && group_size
   13679     27032084 :       && maybe_ge (TYPE_VECTOR_SUBPARTS (vectype), group_size))
   13680              :     {
   13681              :       /* Start with the biggest number of units that fits within
   13682              :          GROUP_SIZE and halve it until we find a valid vector type.
   13683              :          Usually either the first attempt will succeed or all will
   13684              :          fail (in the latter case because GROUP_SIZE is too small
   13685              :          for the target), but it's possible that a target could have
   13686              :          a hole between supported vector types.
   13687              : 
   13688              :          If GROUP_SIZE is not a power of 2, this has the effect of
   13689              :          trying the largest power of 2 that fits within the group,
   13690              :          even though the group is not a multiple of that vector size.
   13691              :          The BB vectorizer will then try to carve up the group into
   13692              :          smaller pieces.  */
   13693      2604414 :       unsigned int nunits = 1 << floor_log2 (group_size);
   13694      2604414 :       do
   13695              :         {
   13696      2604414 :           vectype = get_related_vectype_for_scalar_type (vinfo->vector_mode,
   13697      2604414 :                                                          scalar_type, nunits);
   13698      2604414 :           nunits /= 2;
   13699              :         }
   13700      2604414 :       while (nunits > 1 && !vectype);
   13701              :     }
   13702              : 
   13703     27032084 :   return vectype;
   13704              : }
   13705              : 
   13706              : /* Return the vector type corresponding to SCALAR_TYPE as supported
   13707              :    by the target.  NODE, if nonnull, is the SLP tree node that will
   13708              :    use the returned vector type.  */
   13709              : 
   13710              : tree
   13711       188470 : get_vectype_for_scalar_type (vec_info *vinfo, tree scalar_type, slp_tree node)
   13712              : {
   13713       188470 :   unsigned int group_size = 0;
   13714       188470 :   if (node)
   13715       188470 :     group_size = SLP_TREE_LANES (node);
   13716       188470 :   return get_vectype_for_scalar_type (vinfo, scalar_type, group_size);
   13717              : }
   13718              : 
   13719              : /* Function get_mask_type_for_scalar_type.
   13720              : 
   13721              :    Returns the mask type corresponding to a result of comparison
   13722              :    of vectors of specified SCALAR_TYPE as supported by target.
   13723              :    If GROUP_SIZE is nonzero and we're performing BB vectorization,
   13724              :    make sure that the number of elements in the vector is no bigger
   13725              :    than GROUP_SIZE.  */
   13726              : 
   13727              : tree
   13728      1169067 : get_mask_type_for_scalar_type (vec_info *vinfo, tree scalar_type,
   13729              :                                unsigned int group_size)
   13730              : {
   13731      1169067 :   tree vectype = get_vectype_for_scalar_type (vinfo, scalar_type, group_size);
   13732              : 
   13733      1169067 :   if (!vectype)
   13734              :     return NULL;
   13735              : 
   13736      1147154 :   return truth_type_for (vectype);
   13737              : }
   13738              : 
   13739              : /* Function get_mask_type_for_scalar_type.
   13740              : 
   13741              :    Returns the mask type corresponding to a result of comparison
   13742              :    of vectors of specified SCALAR_TYPE as supported by target.
   13743              :    NODE, if nonnull, is the SLP tree node that will use the returned
   13744              :    vector type.  */
   13745              : 
   13746              : tree
   13747           19 : get_mask_type_for_scalar_type (vec_info *vinfo, tree scalar_type,
   13748              :                                slp_tree node)
   13749              : {
   13750           19 :   tree vectype = get_vectype_for_scalar_type (vinfo, scalar_type, node);
   13751              : 
   13752           19 :   if (!vectype)
   13753              :     return NULL;
   13754              : 
   13755           19 :   return truth_type_for (vectype);
   13756              : }
   13757              : 
   13758              : /* Function get_same_sized_vectype
   13759              : 
   13760              :    Returns a vector type corresponding to SCALAR_TYPE of size
   13761              :    VECTOR_TYPE if supported by the target.  */
   13762              : 
   13763              : tree
   13764         1188 : get_same_sized_vectype (tree scalar_type, tree vector_type)
   13765              : {
   13766         1188 :   if (VECT_SCALAR_BOOLEAN_TYPE_P (scalar_type))
   13767            0 :     return truth_type_for (vector_type);
   13768              : 
   13769         1188 :   poly_uint64 nunits;
   13770         2376 :   if (!multiple_p (GET_MODE_SIZE (TYPE_MODE (vector_type)),
   13771         2376 :                    GET_MODE_SIZE (TYPE_MODE (scalar_type)), &nunits))
   13772              :     return NULL_TREE;
   13773              : 
   13774         1188 :   return get_related_vectype_for_scalar_type (TYPE_MODE (vector_type),
   13775         1188 :                                               scalar_type, nunits);
   13776              : }
   13777              : 
   13778              : /* Return true if replacing VINFO->vector_mode with VECTOR_MODE
   13779              :    would not change the chosen vector modes.  */
   13780              : 
   13781              : bool
   13782      1511960 : vect_chooses_same_modes_p (vec_info *vinfo, machine_mode vector_mode)
   13783              : {
   13784      1511960 :   const vec_info_shared::mode_set &used_vector_modes
   13785      1511960 :     = vinfo->shared->used_vector_modes;
   13786              : 
   13787      1511960 :   for (vec_info_shared::mode_set::iterator i = used_vector_modes.begin ();
   13788      2600856 :        i != used_vector_modes.end (); ++i)
   13789      2000286 :     if (!VECTOR_MODE_P (*i)
   13790      6000588 :         || related_vector_mode (vector_mode, GET_MODE_INNER (*i), 0) != *i)
   13791       911390 :       return false;
   13792       600570 :   return true;
   13793              : }
   13794              : 
   13795              : /* Return true if replacing VECTOR_MODE with ALT_VECTOR_MODE would not
   13796              :    change the chosen vector modes for analysis of a loop.  */
   13797              : 
   13798              : bool
   13799       412001 : vect_chooses_same_modes_p (machine_mode vector_mode,
   13800              :                            machine_mode alt_vector_mode)
   13801              : {
   13802        66586 :   return (VECTOR_MODE_P (vector_mode)
   13803       412001 :           && VECTOR_MODE_P (alt_vector_mode)
   13804       824002 :           && (related_vector_mode (vector_mode,
   13805              :                                    GET_MODE_INNER (alt_vector_mode))
   13806       412001 :               == alt_vector_mode)
   13807       440811 :           && (related_vector_mode (alt_vector_mode,
   13808              :                                    GET_MODE_INNER (vector_mode))
   13809        14405 :               == vector_mode));
   13810              : }
   13811              : 
   13812              : /* Function vect_is_simple_use.
   13813              : 
   13814              :    Input:
   13815              :    VINFO - the vect info of the loop or basic block that is being vectorized.
   13816              :    OPERAND - operand in the loop or bb.
   13817              :    Output:
   13818              :    DEF_STMT_INFO_OUT (optional) - information about the defining stmt in
   13819              :      case OPERAND is an SSA_NAME that is defined in the vectorizable region
   13820              :    DEF_STMT_OUT (optional) - the defining stmt in case OPERAND is an SSA_NAME;
   13821              :      the definition could be anywhere in the function
   13822              :    DT - the type of definition
   13823              : 
   13824              :    Returns whether a stmt with OPERAND can be vectorized.
   13825              :    For loops, supportable operands are constants, loop invariants, and operands
   13826              :    that are defined by the current iteration of the loop.  Unsupportable
   13827              :    operands are those that are defined by a previous iteration of the loop (as
   13828              :    is the case in reduction/induction computations).
   13829              :    For basic blocks, supportable operands are constants and bb invariants.
   13830              :    For now, operands defined outside the basic block are not supported.  */
   13831              : 
   13832              : bool
   13833     44906439 : vect_is_simple_use (tree operand, vec_info *vinfo, enum vect_def_type *dt,
   13834              :                     stmt_vec_info *def_stmt_info_out, gimple **def_stmt_out)
   13835              : {
   13836     44906439 :   if (def_stmt_info_out)
   13837     42827652 :     *def_stmt_info_out = NULL;
   13838     44906439 :   if (def_stmt_out)
   13839     10540017 :     *def_stmt_out = NULL;
   13840     44906439 :   *dt = vect_unknown_def_type;
   13841              : 
   13842     44906439 :   if (dump_enabled_p ())
   13843              :     {
   13844       843200 :       dump_printf_loc (MSG_NOTE, vect_location,
   13845              :                        "vect_is_simple_use: operand ");
   13846       843200 :       if (TREE_CODE (operand) == SSA_NAME
   13847       843200 :           && !SSA_NAME_IS_DEFAULT_DEF (operand))
   13848       769558 :         dump_gimple_expr (MSG_NOTE, TDF_SLIM, SSA_NAME_DEF_STMT (operand), 0);
   13849              :       else
   13850        73642 :         dump_generic_expr (MSG_NOTE, TDF_SLIM, operand);
   13851              :     }
   13852              : 
   13853     44906439 :   if (CONSTANT_CLASS_P (operand))
   13854      3438169 :     *dt = vect_constant_def;
   13855     41468270 :   else if (is_gimple_min_invariant (operand))
   13856       404484 :     *dt = vect_external_def;
   13857     41063786 :   else if (TREE_CODE (operand) != SSA_NAME)
   13858         1262 :     *dt = vect_unknown_def_type;
   13859     41062524 :   else if (SSA_NAME_IS_DEFAULT_DEF (operand))
   13860       724802 :     *dt = vect_external_def;
   13861              :   else
   13862              :     {
   13863     40337722 :       gimple *def_stmt = SSA_NAME_DEF_STMT (operand);
   13864     40337722 :       stmt_vec_info stmt_vinfo = vinfo->lookup_def (operand);
   13865     40337722 :       if (!stmt_vinfo)
   13866       889539 :         *dt = vect_external_def;
   13867              :       else
   13868              :         {
   13869     39448183 :           stmt_vinfo = vect_stmt_to_vectorize (stmt_vinfo);
   13870     39448183 :           def_stmt = stmt_vinfo->stmt;
   13871     39448183 :           *dt = STMT_VINFO_DEF_TYPE (stmt_vinfo);
   13872     39448183 :           if (def_stmt_info_out)
   13873     37378541 :             *def_stmt_info_out = stmt_vinfo;
   13874              :         }
   13875     40337722 :       if (def_stmt_out)
   13876     10319682 :         *def_stmt_out = def_stmt;
   13877              :     }
   13878              : 
   13879     44906439 :   if (dump_enabled_p ())
   13880              :     {
   13881       843200 :       dump_printf (MSG_NOTE, ", type of def: ");
   13882       843200 :       switch (*dt)
   13883              :         {
   13884            0 :         case vect_uninitialized_def:
   13885            0 :           dump_printf (MSG_NOTE, "uninitialized\n");
   13886            0 :           break;
   13887        61715 :         case vect_constant_def:
   13888        61715 :           dump_printf (MSG_NOTE, "constant\n");
   13889        61715 :           break;
   13890        28321 :         case vect_external_def:
   13891        28321 :           dump_printf (MSG_NOTE, "external\n");
   13892        28321 :           break;
   13893       601144 :         case vect_internal_def:
   13894       601144 :           dump_printf (MSG_NOTE, "internal\n");
   13895       601144 :           break;
   13896       119134 :         case vect_induction_def:
   13897       119134 :           dump_printf (MSG_NOTE, "induction\n");
   13898       119134 :           break;
   13899        29465 :         case vect_reduction_def:
   13900        29465 :           dump_printf (MSG_NOTE, "reduction\n");
   13901        29465 :           break;
   13902          482 :         case vect_double_reduction_def:
   13903          482 :           dump_printf (MSG_NOTE, "double reduction\n");
   13904          482 :           break;
   13905         2193 :         case vect_nested_cycle:
   13906         2193 :           dump_printf (MSG_NOTE, "nested cycle\n");
   13907         2193 :           break;
   13908          277 :         case vect_first_order_recurrence:
   13909          277 :           dump_printf (MSG_NOTE, "first order recurrence\n");
   13910          277 :           break;
   13911            0 :         case vect_condition_def:
   13912            0 :           dump_printf (MSG_NOTE, "control flow\n");
   13913            0 :           break;
   13914          469 :         case vect_unknown_def_type:
   13915          469 :           dump_printf (MSG_NOTE, "unknown\n");
   13916          469 :           break;
   13917              :         }
   13918              :     }
   13919              : 
   13920     44906439 :   if (*dt == vect_unknown_def_type)
   13921              :     {
   13922        59140 :       if (dump_enabled_p ())
   13923          469 :         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
   13924              :                          "Unsupported pattern.\n");
   13925              :       return false;
   13926              :     }
   13927              : 
   13928              :   return true;
   13929              : }
   13930              : 
   13931              : /* Function vect_is_simple_use.
   13932              : 
   13933              :    Same as vect_is_simple_use but determines the operand by operand
   13934              :    position OPERAND from either STMT or SLP_NODE, filling in *OP
   13935              :    and *SLP_DEF (when SLP_NODE is not NULL).  */
   13936              : 
   13937              : bool
   13938      3765490 : vect_is_simple_use (vec_info *vinfo, slp_tree slp_node,
   13939              :                     unsigned operand, tree *op, slp_tree *slp_def,
   13940              :                     enum vect_def_type *dt,
   13941              :                     tree *vectype, stmt_vec_info *def_stmt_info_out)
   13942              : {
   13943      3765490 :   slp_tree child = SLP_TREE_CHILDREN (slp_node)[operand];
   13944      3765490 :   *slp_def = child;
   13945      3765490 :   *vectype = SLP_TREE_VECTYPE (child);
   13946      3765490 :   if (SLP_TREE_DEF_TYPE (child) == vect_internal_def)
   13947              :     {
   13948              :       /* ???  VEC_PERM nodes might be intermediate and their lane value
   13949              :          have no representative (nor do we build a VEC_PERM stmt for
   13950              :          the actual operation).  Note for two-operator nodes we set
   13951              :          a representative but leave scalar stmts empty as we'd only
   13952              :          have one for a subset of lanes.  Ideally no caller would
   13953              :          require *op for internal defs.  */
   13954      2056006 :       if (SLP_TREE_REPRESENTATIVE (child))
   13955              :         {
   13956      1998389 :           *op = gimple_get_lhs (SLP_TREE_REPRESENTATIVE (child)->stmt);
   13957      1998389 :           return vect_is_simple_use (*op, vinfo, dt, def_stmt_info_out);
   13958              :         }
   13959              :       else
   13960              :         {
   13961        57617 :           gcc_assert (SLP_TREE_PERMUTE_P (child));
   13962        57617 :           *op = error_mark_node;
   13963        57617 :           *dt = vect_internal_def;
   13964        57617 :           if (def_stmt_info_out)
   13965          155 :             *def_stmt_info_out = NULL;
   13966              :           return true;
   13967              :         }
   13968              :     }
   13969              :   else
   13970              :     {
   13971      1709484 :       if (def_stmt_info_out)
   13972        57033 :         *def_stmt_info_out = NULL;
   13973      1709484 :       *op = SLP_TREE_SCALAR_OPS (child)[0];
   13974      1709484 :       *dt = SLP_TREE_DEF_TYPE (child);
   13975      1709484 :       return true;
   13976              :     }
   13977              : }
   13978              : 
   13979              : /* Wrapper around vect_is_simple_use that elides the scalar op output.  */
   13980              : 
   13981              : bool
   13982       290526 : vect_is_simple_use (vec_info *vinfo, slp_tree slp_node,
   13983              :                     unsigned operand, slp_tree *slp_def,
   13984              :                     enum vect_def_type *dt, tree *vectype)
   13985              : {
   13986       290526 :   tree op;
   13987       290526 :   return vect_is_simple_use (vinfo, slp_node, operand, &op, slp_def, dt,
   13988       290526 :                              vectype);
   13989              : }
   13990              : 
   13991              : /* If OP is not NULL and is external or constant update its vector
   13992              :    type with VECTYPE.  Returns true if successful or false if not,
   13993              :    for example when conflicting vector types are present.  */
   13994              : 
   13995              : bool
   13996      3267328 : vect_maybe_update_slp_op_vectype (slp_tree op, tree vectype)
   13997              : {
   13998      3267328 :   if (!op || SLP_TREE_DEF_TYPE (op) == vect_internal_def)
   13999              :     return true;
   14000      1118441 :   if (SLP_TREE_VECTYPE (op))
   14001        24040 :     return types_compatible_p (SLP_TREE_VECTYPE (op), vectype);
   14002              :   /* For external defs refuse to produce VECTOR_BOOLEAN_TYPE_P, those
   14003              :      should be handled by patters.  Allow vect_constant_def for now
   14004              :      as well as the trivial single-lane uniform vect_external_def case
   14005              :      both of which we code-generate reasonably.  */
   14006      1094401 :   if (VECTOR_BOOLEAN_TYPE_P (vectype)
   14007         1757 :       && SLP_TREE_DEF_TYPE (op) == vect_external_def
   14008      1095705 :       && SLP_TREE_LANES (op) > 1)
   14009              :     return false;
   14010      1094211 :   SLP_TREE_VECTYPE (op) = vectype;
   14011      1094211 :   return true;
   14012              : }
   14013              : 
   14014              : /* Function supportable_widening_operation
   14015              : 
   14016              :    Check whether an operation represented by the code CODE is a
   14017              :    widening operation that is supported by the target platform in
   14018              :    vector form (i.e., when operating on arguments of type VECTYPE_IN
   14019              :    producing a result of type VECTYPE_OUT).
   14020              : 
   14021              :    Widening operations we currently support are NOP (CONVERT), FLOAT,
   14022              :    FIX_TRUNC and WIDEN_MULT.  This function checks if these operations
   14023              :    are supported by the target platform either directly (via vector
   14024              :    tree-codes), or via target builtins.
   14025              : 
   14026              :    When EVENODD_OK then also lane-swizzling operations are considered.
   14027              : 
   14028              :    Output:
   14029              :    - CODE1 and CODE2 are codes of vector operations to be used when
   14030              :    vectorizing the operation, if available.
   14031              :    - MULTI_STEP_CVT determines the number of required intermediate steps in
   14032              :    case of multi-step conversion (like char->short->int - in that case
   14033              :    MULTI_STEP_CVT will be 1).
   14034              :    - INTERM_TYPES contains the intermediate type required to perform the
   14035              :    widening operation (short in the above example).  */
   14036              : 
   14037              : bool
   14038       567175 : supportable_widening_operation (code_helper code,
   14039              :                                 tree vectype_out, tree vectype_in,
   14040              :                                 bool evenodd_ok,
   14041              :                                 code_helper *code1,
   14042              :                                 code_helper *code2,
   14043              :                                 int *multi_step_cvt,
   14044              :                                 vec<tree> *interm_types)
   14045              : {
   14046       567175 :   machine_mode vec_mode;
   14047       567175 :   enum insn_code icode1, icode2;
   14048       567175 :   optab optab1 = unknown_optab, optab2 = unknown_optab;
   14049       567175 :   tree vectype = vectype_in;
   14050       567175 :   tree wide_vectype = vectype_out;
   14051       567175 :   tree_code c1 = MAX_TREE_CODES, c2 = MAX_TREE_CODES;
   14052       567175 :   int i;
   14053       567175 :   tree prev_type, intermediate_type;
   14054       567175 :   machine_mode intermediate_mode, prev_mode;
   14055       567175 :   optab optab3, optab4;
   14056              : 
   14057       567175 :   *multi_step_cvt = 0;
   14058              : 
   14059       567175 :   switch (code.safe_as_tree_code ())
   14060              :     {
   14061              :     case MAX_TREE_CODES:
   14062              :       /* Don't set c1 and c2 if code is not a tree_code.  */
   14063              :       break;
   14064              : 
   14065       216068 :     case WIDEN_MULT_EXPR:
   14066              :       /* The result of a vectorized widening operation usually requires
   14067              :          two vectors (because the widened results do not fit into one vector).
   14068              :          The generated vector results would normally be expected to be
   14069              :          generated in the same order as in the original scalar computation,
   14070              :          i.e. if 8 results are generated in each vector iteration, they are
   14071              :          to be organized as follows:
   14072              :                 vect1: [res1,res2,res3,res4],
   14073              :                 vect2: [res5,res6,res7,res8].
   14074              : 
   14075              :          However, in the special case that the result of the widening
   14076              :          operation is used in a reduction computation only, the order doesn't
   14077              :          matter (because when vectorizing a reduction we change the order of
   14078              :          the computation).  Some targets can take advantage of this and
   14079              :          generate more efficient code.  For example, targets like Altivec,
   14080              :          that support widen_mult using a sequence of {mult_even,mult_odd}
   14081              :          generate the following vectors:
   14082              :                 vect1: [res1,res3,res5,res7],
   14083              :                 vect2: [res2,res4,res6,res8].
   14084              : 
   14085              :          When vectorizing outer-loops, we execute the inner-loop sequentially
   14086              :          (each vectorized inner-loop iteration contributes to VF outer-loop
   14087              :          iterations in parallel).  We therefore don't allow to change the
   14088              :          order of the computation in the inner-loop during outer-loop
   14089              :          vectorization.  */
   14090              :       /* TODO: Another case in which order doesn't *really* matter is when we
   14091              :          widen and then contract again, e.g. (short)((int)x * y >> 8).
   14092              :          Normally, pack_trunc performs an even/odd permute, whereas the
   14093              :          repack from an even/odd expansion would be an interleave, which
   14094              :          would be significantly simpler for e.g. AVX2.  */
   14095              :       /* In any case, in order to avoid duplicating the code below, recurse
   14096              :          on VEC_WIDEN_MULT_EVEN_EXPR.  If it succeeds, all the return values
   14097              :          are properly set up for the caller.  If we fail, we'll continue with
   14098              :          a VEC_WIDEN_MULT_LO/HI_EXPR check.  */
   14099       216068 :       if (evenodd_ok
   14100       216068 :           && supportable_widening_operation (VEC_WIDEN_MULT_EVEN_EXPR,
   14101              :                                              vectype_out, vectype_in,
   14102              :                                              evenodd_ok, code1,
   14103              :                                              code2, multi_step_cvt,
   14104              :                                              interm_types))
   14105       111010 :         return true;
   14106              :       c1 = VEC_WIDEN_MULT_LO_EXPR;
   14107              :       c2 = VEC_WIDEN_MULT_HI_EXPR;
   14108              :       break;
   14109              : 
   14110              :     case DOT_PROD_EXPR:
   14111       456165 :       c1 = DOT_PROD_EXPR;
   14112       456165 :       c2 = DOT_PROD_EXPR;
   14113              :       break;
   14114              : 
   14115            0 :     case SAD_EXPR:
   14116            0 :       c1 = SAD_EXPR;
   14117            0 :       c2 = SAD_EXPR;
   14118            0 :       break;
   14119              : 
   14120       213878 :     case VEC_WIDEN_MULT_EVEN_EXPR:
   14121              :       /* Support the recursion induced just above.  */
   14122       213878 :       c1 = VEC_WIDEN_MULT_EVEN_EXPR;
   14123       213878 :       c2 = VEC_WIDEN_MULT_ODD_EXPR;
   14124       213878 :       break;
   14125              : 
   14126         9840 :     case WIDEN_LSHIFT_EXPR:
   14127         9840 :       c1 = VEC_WIDEN_LSHIFT_LO_EXPR;
   14128         9840 :       c2 = VEC_WIDEN_LSHIFT_HI_EXPR;
   14129         9840 :       break;
   14130              : 
   14131        46020 :     CASE_CONVERT:
   14132        46020 :       c1 = VEC_UNPACK_LO_EXPR;
   14133        46020 :       c2 = VEC_UNPACK_HI_EXPR;
   14134        46020 :       break;
   14135              : 
   14136         9381 :     case FLOAT_EXPR:
   14137         9381 :       c1 = VEC_UNPACK_FLOAT_LO_EXPR;
   14138         9381 :       c2 = VEC_UNPACK_FLOAT_HI_EXPR;
   14139         9381 :       break;
   14140              : 
   14141          127 :     case FIX_TRUNC_EXPR:
   14142          127 :       c1 = VEC_UNPACK_FIX_TRUNC_LO_EXPR;
   14143          127 :       c2 = VEC_UNPACK_FIX_TRUNC_HI_EXPR;
   14144          127 :       break;
   14145              : 
   14146            0 :     default:
   14147            0 :       gcc_unreachable ();
   14148              :     }
   14149              : 
   14150       456165 :   if (BYTES_BIG_ENDIAN && c1 != VEC_WIDEN_MULT_EVEN_EXPR)
   14151              :     std::swap (c1, c2);
   14152              : 
   14153       456165 :   if (code == FIX_TRUNC_EXPR)
   14154              :     {
   14155              :       /* The signedness is determined from output operand.  */
   14156          127 :       optab1 = optab_for_tree_code (c1, vectype_out, optab_default);
   14157          127 :       optab2 = optab_for_tree_code (c2, vectype_out, optab_default);
   14158              :     }
   14159       802927 :   else if (CONVERT_EXPR_CODE_P (code.safe_as_tree_code ())
   14160        46020 :            && VECTOR_BOOLEAN_TYPE_P (wide_vectype)
   14161         8324 :            && VECTOR_BOOLEAN_TYPE_P (vectype)
   14162         8324 :            && TYPE_MODE (wide_vectype) == TYPE_MODE (vectype)
   14163       384641 :            && SCALAR_INT_MODE_P (TYPE_MODE (vectype)))
   14164              :     {
   14165              :       /* If the input and result modes are the same, a different optab
   14166              :          is needed where we pass in the number of units in vectype.  */
   14167              :       optab1 = vec_unpacks_sbool_lo_optab;
   14168              :       optab2 = vec_unpacks_sbool_hi_optab;
   14169              :     }
   14170              : 
   14171       456165 :   vec_mode = TYPE_MODE (vectype);
   14172       456165 :   if (widening_fn_p (code))
   14173              :      {
   14174              :        /* If this is an internal fn then we must check whether the target
   14175              :           supports either a low-high split or an even-odd split.  */
   14176        71861 :       internal_fn ifn = as_internal_fn ((combined_fn) code);
   14177              : 
   14178        71861 :       internal_fn lo, hi, even, odd;
   14179        71861 :       lookup_hilo_internal_fn (ifn, &lo, &hi);
   14180        71861 :       if (BYTES_BIG_ENDIAN)
   14181              :         std::swap (lo, hi);
   14182        71861 :       *code1 = as_combined_fn (lo);
   14183        71861 :       *code2 = as_combined_fn (hi);
   14184        71861 :       optab1 = direct_internal_fn_optab (lo, {vectype, vectype});
   14185        71861 :       optab2 = direct_internal_fn_optab (hi, {vectype, vectype});
   14186              : 
   14187              :       /* If we don't support low-high, then check for even-odd.  */
   14188        71861 :       if (!optab1
   14189        71861 :           || (icode1 = optab_handler (optab1, vec_mode)) == CODE_FOR_nothing
   14190            0 :           || !optab2
   14191        71861 :           || (icode2 = optab_handler (optab2, vec_mode)) == CODE_FOR_nothing)
   14192              :         {
   14193        71861 :           lookup_evenodd_internal_fn (ifn, &even, &odd);
   14194        71861 :           *code1 = as_combined_fn (even);
   14195        71861 :           *code2 = as_combined_fn (odd);
   14196        71861 :           optab1 = direct_internal_fn_optab (even, {vectype, vectype});
   14197        71861 :           optab2 = direct_internal_fn_optab (odd, {vectype, vectype});
   14198              :         }
   14199              :     }
   14200       384304 :   else if (code.is_tree_code ())
   14201              :     {
   14202       384304 :       if (code == FIX_TRUNC_EXPR)
   14203              :         {
   14204              :           /* The signedness is determined from output operand.  */
   14205          127 :           optab1 = optab_for_tree_code (c1, vectype_out, optab_default);
   14206          127 :           optab2 = optab_for_tree_code (c2, vectype_out, optab_default);
   14207              :         }
   14208       384177 :       else if (CONVERT_EXPR_CODE_P ((tree_code) code.safe_as_tree_code ())
   14209        46020 :                && VECTOR_BOOLEAN_TYPE_P (wide_vectype)
   14210         8324 :                && VECTOR_BOOLEAN_TYPE_P (vectype)
   14211         8324 :                && TYPE_MODE (wide_vectype) == TYPE_MODE (vectype)
   14212       384641 :                && SCALAR_INT_MODE_P (TYPE_MODE (vectype)))
   14213              :         {
   14214              :           /* If the input and result modes are the same, a different optab
   14215              :              is needed where we pass in the number of units in vectype.  */
   14216              :           optab1 = vec_unpacks_sbool_lo_optab;
   14217              :           optab2 = vec_unpacks_sbool_hi_optab;
   14218              :         }
   14219              :       else
   14220              :         {
   14221       383713 :           optab1 = optab_for_tree_code (c1, vectype, optab_default);
   14222       383713 :           optab2 = optab_for_tree_code (c2, vectype, optab_default);
   14223              :         }
   14224       384304 :       *code1 = c1;
   14225       384304 :       *code2 = c2;
   14226              :     }
   14227              : 
   14228       456165 :   if (!optab1 || !optab2)
   14229              :     return false;
   14230              : 
   14231       456165 :   if ((icode1 = optab_handler (optab1, vec_mode)) == CODE_FOR_nothing
   14232       456165 :        || (icode2 = optab_handler (optab2, vec_mode)) == CODE_FOR_nothing)
   14233              :     return false;
   14234              : 
   14235              : 
   14236       171744 :   if (insn_data[icode1].operand[0].mode == TYPE_MODE (wide_vectype)
   14237       171744 :       && insn_data[icode2].operand[0].mode == TYPE_MODE (wide_vectype))
   14238              :     {
   14239       159890 :       if (!VECTOR_BOOLEAN_TYPE_P (vectype))
   14240              :         return true;
   14241              :       /* For scalar masks we may have different boolean
   14242              :          vector types having the same QImode.  Thus we
   14243              :          add additional check for elements number.  */
   14244         4514 :       if (known_eq (TYPE_VECTOR_SUBPARTS (vectype),
   14245              :                     TYPE_VECTOR_SUBPARTS (wide_vectype) * 2))
   14246              :         return true;
   14247              :     }
   14248              : 
   14249              :   /* Check if it's a multi-step conversion that can be done using intermediate
   14250              :      types.  */
   14251              : 
   14252        12083 :   prev_type = vectype;
   14253        12083 :   prev_mode = vec_mode;
   14254              : 
   14255        12083 :   if (!CONVERT_EXPR_CODE_P (code.safe_as_tree_code ()))
   14256              :     return false;
   14257              : 
   14258              :   /* We assume here that there will not be more than MAX_INTERM_CVT_STEPS
   14259              :      intermediate steps in promotion sequence.  We try
   14260              :      MAX_INTERM_CVT_STEPS to get to NARROW_VECTYPE, and fail if we do
   14261              :      not.  */
   14262        12031 :   interm_types->create (MAX_INTERM_CVT_STEPS);
   14263        25394 :   for (i = 0; i < MAX_INTERM_CVT_STEPS; i++)
   14264              :     {
   14265        13363 :       intermediate_mode = insn_data[icode1].operand[0].mode;
   14266        13363 :       if (VECTOR_BOOLEAN_TYPE_P (prev_type))
   14267         4719 :         intermediate_type
   14268         4719 :           = vect_halve_mask_nunits (prev_type, intermediate_mode);
   14269         8644 :       else if (VECTOR_MODE_P (intermediate_mode))
   14270              :         {
   14271         8644 :           tree intermediate_element_type
   14272         8644 :             = lang_hooks.types.type_for_mode (GET_MODE_INNER (intermediate_mode),
   14273         8644 :                                               TYPE_UNSIGNED (prev_type));
   14274         8644 :           intermediate_type
   14275         8644 :             = build_vector_type_for_mode (intermediate_element_type,
   14276              :                                           intermediate_mode);
   14277         8644 :         }
   14278              :       else
   14279            0 :         intermediate_type
   14280            0 :           = lang_hooks.types.type_for_mode (intermediate_mode,
   14281            0 :                                             TYPE_UNSIGNED (prev_type));
   14282              : 
   14283        13363 :       if (VECTOR_BOOLEAN_TYPE_P (intermediate_type)
   14284         4719 :           && VECTOR_BOOLEAN_TYPE_P (wide_vectype)
   14285         4719 :           && intermediate_mode == TYPE_MODE (wide_vectype)
   14286        13674 :           && SCALAR_INT_MODE_P (intermediate_mode))
   14287              :         {
   14288              :           /* If the input and result modes are the same, a different optab
   14289              :              is needed where we pass in the number of units in vectype.  */
   14290              :           optab3 = vec_unpacks_sbool_lo_optab;
   14291              :           optab4 = vec_unpacks_sbool_hi_optab;
   14292              :         }
   14293              :       else
   14294              :         {
   14295        13052 :           optab3 = optab_for_tree_code (c1, intermediate_type, optab_default);
   14296        13052 :           optab4 = optab_for_tree_code (c2, intermediate_type, optab_default);
   14297              :         }
   14298              : 
   14299        13363 :       if (!optab3 || !optab4
   14300        13363 :           || (icode1 = optab_handler (optab1, prev_mode)) == CODE_FOR_nothing
   14301        13323 :           || insn_data[icode1].operand[0].mode != intermediate_mode
   14302        13323 :           || (icode2 = optab_handler (optab2, prev_mode)) == CODE_FOR_nothing
   14303        13323 :           || insn_data[icode2].operand[0].mode != intermediate_mode
   14304        13323 :           || ((icode1 = optab_handler (optab3, intermediate_mode))
   14305              :               == CODE_FOR_nothing)
   14306        26292 :           || ((icode2 = optab_handler (optab4, intermediate_mode))
   14307              :               == CODE_FOR_nothing))
   14308              :         break;
   14309              : 
   14310        12929 :       interm_types->quick_push (intermediate_type);
   14311        12929 :       (*multi_step_cvt)++;
   14312              : 
   14313        12929 :       if (insn_data[icode1].operand[0].mode == TYPE_MODE (wide_vectype)
   14314        12929 :           && insn_data[icode2].operand[0].mode == TYPE_MODE (wide_vectype))
   14315              :         {
   14316        11679 :           if (!VECTOR_BOOLEAN_TYPE_P (vectype))
   14317              :             return true;
   14318         3790 :           if (known_eq (TYPE_VECTOR_SUBPARTS (intermediate_type),
   14319              :                         TYPE_VECTOR_SUBPARTS (wide_vectype) * 2))
   14320              :             return true;
   14321              :         }
   14322              : 
   14323         1332 :       prev_type = intermediate_type;
   14324         1332 :       prev_mode = intermediate_mode;
   14325              :     }
   14326              : 
   14327          434 :   interm_types->release ();
   14328          434 :   return false;
   14329              : }
   14330              : 
   14331              : 
   14332              : /* Function supportable_narrowing_operation
   14333              : 
   14334              :    Check whether an operation represented by the code CODE is a
   14335              :    narrowing operation that is supported by the target platform in
   14336              :    vector form (i.e., when operating on arguments of type VECTYPE_IN
   14337              :    and producing a result of type VECTYPE_OUT).
   14338              : 
   14339              :    Narrowing operations we currently support are NOP (CONVERT), FIX_TRUNC
   14340              :    and FLOAT.  This function checks if these operations are supported by
   14341              :    the target platform directly via vector tree-codes.
   14342              : 
   14343              :    Output:
   14344              :    - CODE1 is the code of a vector operation to be used when
   14345              :    vectorizing the operation, if available.
   14346              :    - MULTI_STEP_CVT determines the number of required intermediate steps in
   14347              :    case of multi-step conversion (like int->short->char - in that case
   14348              :    MULTI_STEP_CVT will be 1).
   14349              :    - INTERM_TYPES contains the intermediate type required to perform the
   14350              :    narrowing operation (short in the above example).   */
   14351              : 
   14352              : bool
   14353        45610 : supportable_narrowing_operation (code_helper code,
   14354              :                                  tree vectype_out, tree vectype_in,
   14355              :                                  code_helper *code1, int *multi_step_cvt,
   14356              :                                  vec<tree> *interm_types)
   14357              : {
   14358        45610 :   machine_mode vec_mode;
   14359        45610 :   enum insn_code icode1;
   14360        45610 :   optab optab1, interm_optab;
   14361        45610 :   tree vectype = vectype_in;
   14362        45610 :   tree narrow_vectype = vectype_out;
   14363        45610 :   enum tree_code c1;
   14364        45610 :   tree intermediate_type, prev_type;
   14365        45610 :   machine_mode intermediate_mode, prev_mode;
   14366        45610 :   int i;
   14367        45610 :   unsigned HOST_WIDE_INT n_elts;
   14368        45610 :   bool uns;
   14369              : 
   14370        45610 :   if (!code.is_tree_code ())
   14371              :     return false;
   14372              : 
   14373        45610 :   *multi_step_cvt = 0;
   14374        45610 :   switch ((tree_code) code)
   14375              :     {
   14376        44100 :     CASE_CONVERT:
   14377        44100 :       c1 = VEC_PACK_TRUNC_EXPR;
   14378        44100 :       if (VECTOR_BOOLEAN_TYPE_P (narrow_vectype)
   14379        11697 :           && VECTOR_BOOLEAN_TYPE_P (vectype)
   14380        11697 :           && SCALAR_INT_MODE_P (TYPE_MODE (vectype))
   14381         5271 :           && TYPE_VECTOR_SUBPARTS (vectype).is_constant (&n_elts)
   14382        49371 :           && n_elts < BITS_PER_UNIT)
   14383              :         optab1 = vec_pack_sbool_trunc_optab;
   14384              :       else
   14385        41613 :         optab1 = optab_for_tree_code (c1, vectype, optab_default);
   14386              :       break;
   14387              : 
   14388          572 :     case FIX_TRUNC_EXPR:
   14389          572 :       c1 = VEC_PACK_FIX_TRUNC_EXPR;
   14390              :       /* The signedness is determined from output operand.  */
   14391          572 :       optab1 = optab_for_tree_code (c1, vectype_out, optab_default);
   14392          572 :       break;
   14393              : 
   14394          938 :     case FLOAT_EXPR:
   14395          938 :       c1 = VEC_PACK_FLOAT_EXPR;
   14396          938 :       optab1 = optab_for_tree_code (c1, vectype, optab_default);
   14397          938 :       break;
   14398              : 
   14399            0 :     default:
   14400            0 :       gcc_unreachable ();
   14401              :     }
   14402              : 
   14403        45610 :   if (!optab1)
   14404              :     return false;
   14405              : 
   14406        45610 :   vec_mode = TYPE_MODE (vectype);
   14407        45610 :   if ((icode1 = optab_handler (optab1, vec_mode)) == CODE_FOR_nothing)
   14408              :     return false;
   14409              : 
   14410        39979 :   *code1 = c1;
   14411              : 
   14412        39979 :   if (insn_data[icode1].operand[0].mode == TYPE_MODE (narrow_vectype))
   14413              :     {
   14414        25394 :       if (!VECTOR_BOOLEAN_TYPE_P (vectype))
   14415              :         return true;
   14416              :       /* For scalar masks we may have different boolean
   14417              :          vector types having the same QImode.  Thus we
   14418              :          add additional check for elements number.  */
   14419         5885 :       if (known_eq (TYPE_VECTOR_SUBPARTS (vectype) * 2,
   14420              :                     TYPE_VECTOR_SUBPARTS (narrow_vectype)))
   14421              :         return true;
   14422              :     }
   14423              : 
   14424        14736 :   if (code == FLOAT_EXPR)
   14425              :     return false;
   14426              : 
   14427              :   /* Check if it's a multi-step conversion that can be done using intermediate
   14428              :      types.  */
   14429        14736 :   prev_mode = vec_mode;
   14430        14736 :   prev_type = vectype;
   14431        14736 :   if (code == FIX_TRUNC_EXPR)
   14432           94 :     uns = TYPE_UNSIGNED (vectype_out);
   14433              :   else
   14434        14642 :     uns = TYPE_UNSIGNED (vectype);
   14435              : 
   14436              :   /* For multi-step FIX_TRUNC_EXPR prefer signed floating to integer
   14437              :      conversion over unsigned, as unsigned FIX_TRUNC_EXPR is often more
   14438              :      costly than signed.  */
   14439        14736 :   if (code == FIX_TRUNC_EXPR && uns)
   14440              :     {
   14441           28 :       enum insn_code icode2;
   14442              : 
   14443           28 :       intermediate_type
   14444           28 :         = lang_hooks.types.type_for_mode (TYPE_MODE (vectype_out), 0);
   14445           28 :       interm_optab
   14446           28 :         = optab_for_tree_code (c1, intermediate_type, optab_default);
   14447           28 :       if (interm_optab != unknown_optab
   14448           28 :           && (icode2 = optab_handler (optab1, vec_mode)) != CODE_FOR_nothing
   14449           28 :           && insn_data[icode1].operand[0].mode
   14450           28 :              == insn_data[icode2].operand[0].mode)
   14451              :         {
   14452              :           uns = false;
   14453              :           optab1 = interm_optab;
   14454              :           icode1 = icode2;
   14455              :         }
   14456              :     }
   14457              : 
   14458              :   /* We assume here that there will not be more than MAX_INTERM_CVT_STEPS
   14459              :      intermediate steps in promotion sequence.  We try
   14460              :      MAX_INTERM_CVT_STEPS to get to NARROW_VECTYPE, and fail if we do not.  */
   14461        14736 :   interm_types->create (MAX_INTERM_CVT_STEPS);
   14462        31496 :   for (i = 0; i < MAX_INTERM_CVT_STEPS; i++)
   14463              :     {
   14464        16760 :       intermediate_mode = insn_data[icode1].operand[0].mode;
   14465        16760 :       if (VECTOR_BOOLEAN_TYPE_P (prev_type))
   14466         7050 :         intermediate_type
   14467         7050 :           = vect_double_mask_nunits (prev_type, intermediate_mode);
   14468              :       else
   14469         9710 :         intermediate_type
   14470         9710 :           = lang_hooks.types.type_for_mode (intermediate_mode, uns);
   14471        16760 :       if (VECTOR_BOOLEAN_TYPE_P (intermediate_type)
   14472         7050 :           && VECTOR_BOOLEAN_TYPE_P (prev_type)
   14473         7050 :           && SCALAR_INT_MODE_P (prev_mode)
   14474         3144 :           && TYPE_VECTOR_SUBPARTS (intermediate_type).is_constant (&n_elts)
   14475        19904 :           && n_elts < BITS_PER_UNIT)
   14476              :         interm_optab = vec_pack_sbool_trunc_optab;
   14477              :       else
   14478        16408 :         interm_optab
   14479        16408 :           = optab_for_tree_code (VEC_PACK_TRUNC_EXPR, intermediate_type,
   14480              :                                  optab_default);
   14481          352 :       if (!interm_optab
   14482        16760 :           || ((icode1 = optab_handler (optab1, prev_mode)) == CODE_FOR_nothing)
   14483        16760 :           || insn_data[icode1].operand[0].mode != intermediate_mode
   14484        33168 :           || ((icode1 = optab_handler (interm_optab, intermediate_mode))
   14485              :               == CODE_FOR_nothing))
   14486              :         break;
   14487              : 
   14488        15892 :       interm_types->quick_push (intermediate_type);
   14489        15892 :       (*multi_step_cvt)++;
   14490              : 
   14491        15892 :       if (insn_data[icode1].operand[0].mode == TYPE_MODE (narrow_vectype))
   14492              :         {
   14493        13868 :           if (!VECTOR_BOOLEAN_TYPE_P (vectype))
   14494              :             return true;
   14495         4976 :           if (known_eq (TYPE_VECTOR_SUBPARTS (intermediate_type) * 2,
   14496              :                         TYPE_VECTOR_SUBPARTS (narrow_vectype)))
   14497              :             return true;
   14498              :         }
   14499              : 
   14500         2024 :       prev_mode = intermediate_mode;
   14501         2024 :       prev_type = intermediate_type;
   14502         2024 :       optab1 = interm_optab;
   14503              :     }
   14504              : 
   14505          868 :   interm_types->release ();
   14506          868 :   return false;
   14507              : }
   14508              : 
   14509              : /* Function supportable_indirect_convert_operation
   14510              : 
   14511              :    Check whether an operation represented by the code CODE is single or multi
   14512              :    operations that are supported by the target platform in
   14513              :    vector form (i.e., when operating on arguments of type VECTYPE_IN
   14514              :    producing a result of type VECTYPE_OUT).
   14515              : 
   14516              :    Convert operations we currently support directly are FIX_TRUNC and FLOAT.
   14517              :    This function checks if these operations are supported
   14518              :    by the target platform directly (via vector tree-codes).
   14519              : 
   14520              :    Output:
   14521              :    - converts contains some pairs to perform the convert operation,
   14522              :    the pair's first is the intermediate type, and its second is the code of
   14523              :    a vector operation to be used when converting the operation from the
   14524              :    previous type to the intermediate type. */
   14525              : bool
   14526        97257 : supportable_indirect_convert_operation (code_helper code,
   14527              :                                         tree vectype_out,
   14528              :                                         tree vectype_in,
   14529              :                                         vec<std::pair<tree, tree_code> > &converts,
   14530              :                                         slp_tree slp_op0)
   14531              : {
   14532        97257 :   bool found_mode = false;
   14533        97257 :   scalar_mode lhs_mode = GET_MODE_INNER (TYPE_MODE (vectype_out));
   14534        97257 :   scalar_mode rhs_mode = GET_MODE_INNER (TYPE_MODE (vectype_in));
   14535        97257 :   tree_code code1, code2;
   14536              : 
   14537        97257 :   tree cvt_type = NULL_TREE;
   14538        97257 :   poly_uint64 nelts = TYPE_VECTOR_SUBPARTS (vectype_in);
   14539              : 
   14540        97257 :   if (supportable_convert_operation ((tree_code) code,
   14541              :                                      vectype_out,
   14542              :                                      vectype_in))
   14543              :     {
   14544        88898 :       converts.safe_push (std::make_pair (vectype_out, (tree_code) code));
   14545        88898 :       return true;
   14546              :     }
   14547              : 
   14548              :   /* For conversions between mask types where the destination has
   14549              :      a data mode attempt a vcond_mask conversion.  */
   14550         8359 :   if (VECTOR_BOOLEAN_TYPE_P (vectype_in)
   14551          138 :       && VECTOR_BOOLEAN_TYPE_P (vectype_out)
   14552         8497 :       && GET_MODE_CLASS (TYPE_MODE (vectype_out)) == MODE_VECTOR_INT)
   14553              :     {
   14554          137 :       tree scalar_datatype
   14555          137 :         = build_nonstandard_integer_type (element_precision (vectype_out), 0);
   14556          137 :       tree datatype_out = build_vector_type_for_mode (scalar_datatype,
   14557          137 :                                                       TYPE_MODE (vectype_out));
   14558          137 :       if (expand_vec_cond_expr_p (datatype_out, vectype_in))
   14559              :         {
   14560            2 :           converts.safe_push (std::make_pair (datatype_out, COND_EXPR));
   14561            2 :           return true;
   14562              :         }
   14563              :     }
   14564              : 
   14565              :   /* For conversions between float and integer types try whether
   14566              :      we can use intermediate signed integer types to support the
   14567              :      conversion.  */
   14568        16714 :   if (GET_MODE_SIZE (lhs_mode) != GET_MODE_SIZE (rhs_mode)
   14569         8357 :       && (code == FLOAT_EXPR
   14570         5740 :           || (code == FIX_TRUNC_EXPR && !flag_trapping_math)))
   14571              :     {
   14572         1568 :       bool demotion = GET_MODE_SIZE (rhs_mode) > GET_MODE_SIZE (lhs_mode);
   14573          784 :       bool float_expr_p = code == FLOAT_EXPR;
   14574          784 :       unsigned short target_size;
   14575          784 :       scalar_mode intermediate_mode;
   14576          784 :       if (demotion)
   14577              :         {
   14578           97 :           intermediate_mode = lhs_mode;
   14579           97 :           target_size = GET_MODE_SIZE (rhs_mode);
   14580              :         }
   14581              :       else
   14582              :         {
   14583          687 :           target_size = GET_MODE_SIZE (lhs_mode);
   14584          687 :           if (!int_mode_for_size
   14585          687 :               (GET_MODE_BITSIZE (rhs_mode), 0).exists (&intermediate_mode))
   14586          142 :             return false;
   14587              :         }
   14588          784 :       code1 = float_expr_p ? (tree_code) code : NOP_EXPR;
   14589          721 :       code2 = float_expr_p ? NOP_EXPR : (tree_code) code;
   14590          784 :       opt_scalar_mode mode_iter;
   14591         2449 :       FOR_EACH_2XWIDER_MODE (mode_iter, intermediate_mode)
   14592              :         {
   14593         2449 :           intermediate_mode = mode_iter.require ();
   14594              : 
   14595         4898 :           if (GET_MODE_SIZE (intermediate_mode) > target_size)
   14596              :             break;
   14597              : 
   14598         1860 :           scalar_mode cvt_mode;
   14599         1860 :           if (!int_mode_for_size
   14600         1860 :               (GET_MODE_BITSIZE (intermediate_mode), 0).exists (&cvt_mode))
   14601              :             break;
   14602              : 
   14603         1830 :           cvt_type = build_nonstandard_integer_type
   14604         1830 :             (GET_MODE_BITSIZE (cvt_mode), 0);
   14605              : 
   14606              :           /* Check if the intermediate type can hold OP0's range.
   14607              :              When converting from float to integer this is not necessary
   14608              :              because values that do not fit the (smaller) target type are
   14609              :              unspecified anyway.  */
   14610         1830 :           if (demotion && float_expr_p)
   14611              :             {
   14612           23 :               wide_int op_min_value, op_max_value;
   14613              :               /* For vector form, it looks like slp_op0 doesn't have RANGE_INFO.
   14614              :                  In the future, if it is supported, changes may need to be made
   14615              :                  to this part, such as checking the RANGE of each element
   14616              :                  in the vector.  */
   14617           23 :               if (slp_op0)
   14618              :                 {
   14619           13 :                   tree def;
   14620              :                   /* ???  Merge ranges in case of more than one lane.  */
   14621           13 :                   if (SLP_TREE_LANES (slp_op0) != 1
   14622            0 :                       || !(def = vect_get_slp_scalar_def (slp_op0, 0))
   14623           13 :                       || !vect_get_range_info (def,
   14624              :                                                &op_min_value, &op_max_value))
   14625              :                     break;
   14626              :                 }
   14627              :               else
   14628              :                 break;
   14629              : 
   14630            0 :               if (cvt_type == NULL_TREE
   14631            0 :                   || (wi::min_precision (op_max_value, SIGNED)
   14632            0 :                       > TYPE_PRECISION (cvt_type))
   14633            0 :                   || (wi::min_precision (op_min_value, SIGNED)
   14634            0 :                       > TYPE_PRECISION (cvt_type)))
   14635            0 :                 continue;
   14636           23 :             }
   14637              : 
   14638         1807 :           cvt_type = get_related_vectype_for_scalar_type (TYPE_MODE (vectype_in),
   14639              :                                                           cvt_type,
   14640              :                                                           nelts);
   14641              :           /* This should only happened for SLP as long as loop vectorizer
   14642              :              only supports same-sized vector.  */
   14643         3472 :           if (cvt_type == NULL_TREE
   14644         3614 :               || maybe_ne (TYPE_VECTOR_SUBPARTS (cvt_type), nelts)
   14645         1807 :               || !supportable_convert_operation ((tree_code) code1,
   14646              :                                                  vectype_out, cvt_type)
   14647         2532 :               || !supportable_convert_operation ((tree_code) code2,
   14648              :                                                  cvt_type, vectype_in))
   14649         1665 :             continue;
   14650              : 
   14651              :           found_mode = true;
   14652              :           break;
   14653              :         }
   14654              : 
   14655          784 :       if (found_mode)
   14656              :         {
   14657          142 :           converts.safe_push (std::make_pair (cvt_type, code2));
   14658          142 :           if (TYPE_MODE (cvt_type) != TYPE_MODE (vectype_out))
   14659          142 :             converts.safe_push (std::make_pair (vectype_out, code1));
   14660              :           return true;
   14661              :         }
   14662              :     }
   14663              :   return false;
   14664              : }
   14665              : 
   14666              : /* Generate and return a vector mask of MASK_TYPE such that
   14667              :    mask[I] is true iff J + START_INDEX < END_INDEX for all J <= I.
   14668              :    Add the statements to SEQ.  */
   14669              : 
   14670              : tree
   14671            0 : vect_gen_while (gimple_seq *seq, tree mask_type, tree start_index,
   14672              :                 tree end_index, const char *name)
   14673              : {
   14674            0 :   tree cmp_type = TREE_TYPE (start_index);
   14675            0 :   gcc_checking_assert (direct_internal_fn_supported_p (IFN_WHILE_ULT,
   14676              :                                                        cmp_type, mask_type,
   14677              :                                                        OPTIMIZE_FOR_SPEED));
   14678            0 :   gcall *call = gimple_build_call_internal (IFN_WHILE_ULT, 3,
   14679              :                                             start_index, end_index,
   14680              :                                             build_zero_cst (mask_type));
   14681            0 :   tree tmp;
   14682            0 :   if (name)
   14683            0 :     tmp = make_temp_ssa_name (mask_type, NULL, name);
   14684              :   else
   14685            0 :     tmp = make_ssa_name (mask_type);
   14686            0 :   gimple_call_set_lhs (call, tmp);
   14687            0 :   gimple_seq_add_stmt (seq, call);
   14688            0 :   return tmp;
   14689              : }
   14690              : 
   14691              : /* Generate a vector mask of type MASK_TYPE for which index I is false iff
   14692              :    J + START_INDEX < END_INDEX for all J <= I.  Add the statements to SEQ.  */
   14693              : 
   14694              : tree
   14695            0 : vect_gen_while_not (gimple_seq *seq, tree mask_type, tree start_index,
   14696              :                     tree end_index)
   14697              : {
   14698            0 :   tree tmp = vect_gen_while (seq, mask_type, start_index, end_index);
   14699            0 :   return gimple_build (seq, BIT_NOT_EXPR, mask_type, tmp);
   14700              : }
   14701              : 
   14702              : /* Try to compute the vector types required to vectorize STMT_INFO,
   14703              :    returning true on success and false if vectorization isn't possible.
   14704              :    If GROUP_SIZE is nonzero and we're performing BB vectorization,
   14705              :    take sure that the number of elements in the vectors is no bigger
   14706              :    than GROUP_SIZE.
   14707              : 
   14708              :    On success:
   14709              : 
   14710              :    - Set *STMT_VECTYPE_OUT to:
   14711              :      - NULL_TREE if the statement doesn't need to be vectorized;
   14712              :      - the equivalent of STMT_VINFO_VECTYPE otherwise.  */
   14713              : 
   14714              : opt_result
   14715      6300742 : vect_get_vector_types_for_stmt (vec_info *vinfo, stmt_vec_info stmt_info,
   14716              :                                 tree *stmt_vectype_out,
   14717              :                                 unsigned int group_size)
   14718              : {
   14719      6300742 :   gimple *stmt = stmt_info->stmt;
   14720              : 
   14721              :   /* For BB vectorization, we should always have a group size once we've
   14722              :      constructed the SLP tree; the only valid uses of zero GROUP_SIZEs
   14723              :      are tentative requests during things like early data reference
   14724              :      analysis and pattern recognition.  */
   14725      6300742 :   if (is_a <bb_vec_info> (vinfo))
   14726      5043652 :     gcc_assert (vinfo->slp_instances.is_empty () || group_size != 0);
   14727              :   else
   14728              :     group_size = 0;
   14729              : 
   14730      6300742 :   *stmt_vectype_out = NULL_TREE;
   14731              : 
   14732      6300742 :   if (gimple_get_lhs (stmt) == NULL_TREE
   14733              :       /* Allow vector conditionals through here.  */
   14734         2723 :       && !is_a <gcond *> (stmt)
   14735              :       /* MASK_STORE and friends have no lhs, but are ok.  */
   14736      6306158 :       && !(is_gimple_call (stmt)
   14737         2723 :            && gimple_call_internal_p (stmt)
   14738         2693 :            && internal_store_fn_p (gimple_call_internal_fn (stmt))))
   14739              :     {
   14740           30 :       if (is_a <gcall *> (stmt))
   14741              :         {
   14742              :           /* Ignore calls with no lhs.  These must be calls to
   14743              :              #pragma omp simd functions, and what vectorization factor
   14744              :              it really needs can't be determined until
   14745              :              vectorizable_simd_clone_call.  */
   14746           30 :           if (dump_enabled_p ())
   14747           28 :             dump_printf_loc (MSG_NOTE, vect_location,
   14748              :                              "defer to SIMD clone analysis.\n");
   14749           30 :           return opt_result::success ();
   14750              :         }
   14751              : 
   14752            0 :       return opt_result::failure_at (stmt,
   14753              :                                      "not vectorized: irregular stmt: %G", stmt);
   14754              :     }
   14755              : 
   14756      6300712 :   tree vectype;
   14757      6300712 :   tree scalar_type = NULL_TREE;
   14758      6300712 :   if (group_size == 0 && STMT_VINFO_VECTYPE (stmt_info))
   14759              :     {
   14760      1699789 :       vectype = STMT_VINFO_VECTYPE (stmt_info);
   14761      1699789 :       if (dump_enabled_p ())
   14762        86816 :         dump_printf_loc (MSG_NOTE, vect_location,
   14763              :                          "precomputed vectype: %T\n", vectype);
   14764              :     }
   14765      4600923 :   else if (vect_use_mask_type_p (stmt_info))
   14766              :     {
   14767       232097 :       unsigned int precision = stmt_info->mask_precision;
   14768       232097 :       scalar_type = build_nonstandard_integer_type (precision, 1);
   14769       232097 :       vectype = get_mask_type_for_scalar_type (vinfo, scalar_type, group_size);
   14770       232097 :       if (!vectype)
   14771            0 :         return opt_result::failure_at (stmt, "not vectorized: unsupported"
   14772              :                                        " data-type %T\n", scalar_type);
   14773       232097 :       if (dump_enabled_p ())
   14774         5302 :         dump_printf_loc (MSG_NOTE, vect_location, "vectype: %T\n", vectype);
   14775              :     }
   14776              :   else
   14777              :     {
   14778              :       /* If we got here with a gcond it means that the target had no available vector
   14779              :          mode for the scalar type.  We can't vectorize so abort.  */
   14780      4368826 :       if (is_a <gcond *> (stmt))
   14781            0 :         return opt_result::failure_at (stmt,
   14782              :                                        "not vectorized:"
   14783              :                                        " unsupported data-type for gcond %T\n",
   14784              :                                        scalar_type);
   14785              : 
   14786      4368826 :       if (data_reference *dr = STMT_VINFO_DATA_REF (stmt_info))
   14787      1546432 :         scalar_type = TREE_TYPE (DR_REF (dr));
   14788              :       else
   14789      2822394 :         scalar_type = TREE_TYPE (gimple_get_lhs (stmt));
   14790              : 
   14791      4368826 :       if (dump_enabled_p ())
   14792              :         {
   14793        71748 :           if (group_size)
   14794         9675 :             dump_printf_loc (MSG_NOTE, vect_location,
   14795              :                              "get vectype for scalar type (group size %d):"
   14796              :                              " %T\n", group_size, scalar_type);
   14797              :           else
   14798        62073 :             dump_printf_loc (MSG_NOTE, vect_location,
   14799              :                              "get vectype for scalar type: %T\n", scalar_type);
   14800              :         }
   14801      4368826 :       vectype = get_vectype_for_scalar_type (vinfo, scalar_type, group_size);
   14802      4368826 :       if (!vectype)
   14803       258478 :         return opt_result::failure_at (stmt,
   14804              :                                        "not vectorized:"
   14805              :                                        " unsupported data-type %T\n",
   14806              :                                        scalar_type);
   14807              : 
   14808      4110348 :       if (dump_enabled_p ())
   14809        71457 :         dump_printf_loc (MSG_NOTE, vect_location, "vectype: %T\n", vectype);
   14810              :     }
   14811              : 
   14812      4429261 :   if (scalar_type && VECTOR_MODE_P (TYPE_MODE (scalar_type)))
   14813            0 :     return opt_result::failure_at (stmt,
   14814              :                                    "not vectorized: vector stmt in loop:%G",
   14815              :                                    stmt);
   14816              : 
   14817      6042234 :   *stmt_vectype_out = vectype;
   14818      6042234 :   return opt_result::success ();
   14819              : }
   14820              : 
   14821              : /* Generate and return statement sequence that sets vector length LEN that is:
   14822              : 
   14823              :    min_of_start_and_end = min (START_INDEX, END_INDEX);
   14824              :    left_len = END_INDEX - min_of_start_and_end;
   14825              :    rhs = min (left_len, LEN_LIMIT);
   14826              :    LEN = rhs;
   14827              : 
   14828              :    Note: the cost of the code generated by this function is modeled
   14829              :    by vect_estimate_min_profitable_iters, so changes here may need
   14830              :    corresponding changes there.  */
   14831              : 
   14832              : gimple_seq
   14833            0 : vect_gen_len (tree len, tree start_index, tree end_index, tree len_limit)
   14834              : {
   14835            0 :   gimple_seq stmts = NULL;
   14836            0 :   tree len_type = TREE_TYPE (len);
   14837            0 :   gcc_assert (TREE_TYPE (start_index) == len_type);
   14838              : 
   14839            0 :   tree min = gimple_build (&stmts, MIN_EXPR, len_type, start_index, end_index);
   14840            0 :   tree left_len = gimple_build (&stmts, MINUS_EXPR, len_type, end_index, min);
   14841            0 :   tree rhs = gimple_build (&stmts, MIN_EXPR, len_type, left_len, len_limit);
   14842            0 :   gimple* stmt = gimple_build_assign (len, rhs);
   14843            0 :   gimple_seq_add_stmt (&stmts, stmt);
   14844              : 
   14845            0 :   return stmts;
   14846              : }
   14847              : 
        

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