[13/n] PR85694: Try to avoid vectorising casts of invariants
authorRichard Sandiford <richard.sandiford@arm.com>
Sat, 30 Jun 2018 13:56:34 +0000 (13:56 +0000)
committerRichard Sandiford <rsandifo@gcc.gnu.org>
Sat, 30 Jun 2018 13:56:34 +0000 (13:56 +0000)
commit3330053ecaafe8bca82cc3845be9b2d01a614eb1
tree9ced16ed568b3208366e3c98d23fc84ffd77cacb
parent003479340f5ae6b7407b5c92e3e1915101552377
[13/n] PR85694: Try to avoid vectorising casts of invariants

vect_recog_rotate_pattern had code to prevent operations
on invariants being vectorised unnecessarily:

  if (dt == vect_external_def
      && TREE_CODE (oprnd1) == SSA_NAME
      && is_a <loop_vec_info> (vinfo))
    {
      struct loop *loop = as_a <loop_vec_info> (vinfo)->loop;
      ext_def = loop_preheader_edge (loop);
      if (!SSA_NAME_IS_DEFAULT_DEF (oprnd1))
        {
          basic_block bb = gimple_bb (SSA_NAME_DEF_STMT (oprnd1));
          if (bb == NULL
              || !dominated_by_p (CDI_DOMINATORS, ext_def->dest, bb))
            ext_def = NULL;
        }
    }
  [..]
      if (ext_def)
        {
          basic_block new_bb
            = gsi_insert_on_edge_immediate (ext_def, def_stmt);
          gcc_assert (!new_bb);
        }

This patch reuses the same idea for casts of invariants created
during widening optimisations.

One hitch was that vect_loop_versioning asserted that the vector loop
preheader was still empty, although the cfg transformation it's doing
should be correct either way.

2018-06-30  Richard Sandiford  <richard.sandiford@arm.com>

gcc/
* tree-vect-patterns.c (vect_get_external_def_edge): New function,
split out from...
(vect_recog_rotate_pattern): ...here.
(vect_convert_input): Try to insert casts of invariants in the
preheader.
* tree-vect-loop-manip.c (vect_loop_versioning): Don't require the
preheader to be empty.

gcc/testsuite/
* gcc.dg/vect/vect-widen-mult-extern-1.c: New test.

From-SVN: r262277
gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/vect/vect-widen-mult-extern-1.c [new file with mode: 0644]
gcc/tree-vect-loop-manip.c
gcc/tree-vect-patterns.c