public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "rsandifo at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/106081] missed vectorization
Date: Wed, 26 Jul 2023 10:01:10 +0000	[thread overview]
Message-ID: <bug-106081-4-ZUs1Ej3QuF@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-106081-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106081

--- Comment #10 from rsandifo at gcc dot gnu.org <rsandifo at gcc dot gnu.org> ---
(In reply to Richard Biener from comment #9)
> So I can adjust change_layout_cost in a bit awkward way, but it seems that
> internal_node_cost would already work out that a permute can be merged into
> an existing permute.
Right.

> It seems that existing permutes are not recorded in the "layout".
They should be if they're bijective, via:

      else if (SLP_TREE_CODE (node) == VEC_PERM_EXPR
               && SLP_TREE_CHILDREN (node).length () == 1
               && (child = SLP_TREE_CHILDREN (node)[0])
               && (TYPE_VECTOR_SUBPARTS (SLP_TREE_VECTYPE (child))
                   .is_constant (&imin)))
        {
          /* If the child has the same vector size as this node,
             reversing the permutation can make the permutation a no-op.
             In other cases it can change a true permutation into a
             full-vector extract.  */
          tmp_perm.reserve (SLP_TREE_LANES (node));
          for (unsigned j = 0; j < SLP_TREE_LANES (node); ++j)
            tmp_perm.quick_push (SLP_TREE_LANE_PERMUTATION (node)[j].second);
        }

> Also vectorizable_slp_permutation_1 doesn't try to elide permutes that
> are noop based on knowledge of the layout of 'node', say a permute
> { 1 0 3 2 } of a { _1, _1, _2, _2 } node would be noop.
To do that in general, I think we'd need to value-number each
element of each node (which sounds doable).  But I guess doing
it at leaves would be better than nothing.

> But change_layout_cost does MAX (count, 1) on its result anyway.
At the moment, yes, because having from_layout_i != to_layout_i
for identical layouts would be a consistency failure.

> The following elides the unnecessary permutation for this special case
> (but not the general case):
> 
> diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc
> index e4430248ab5..e9048a61891 100644
> --- a/gcc/tree-vect-slp.cc
> +++ b/gcc/tree-vect-slp.cc
> @@ -4389,6 +4389,19 @@ vect_optimize_slp_pass::change_layout_cost (slp_tree
> node,
>    if (from_layout_i == to_layout_i)
>      return 0;
>  
> +  /* When there's a uniform load permutation permutating that in any
> +     way is free.  */
> +  if (SLP_TREE_LOAD_PERMUTATION (node).exists ())
> +    {
> +      unsigned l = SLP_TREE_LOAD_PERMUTATION (node)[0];
> +      unsigned i;
> +      for (i = 1; i < SLP_TREE_LOAD_PERMUTATION (node).length (); ++i)
> +       if (SLP_TREE_LOAD_PERMUTATION (node)[i] != l)
> +         break;
> +      if (i == SLP_TREE_LOAD_PERMUTATION (node).length ())
> +       return 0;
> +    }
> +
>    auto_vec<slp_tree, 1> children (1);
>    children.quick_push (node);
>    auto_lane_permutation_t perm (SLP_TREE_LANES (node));
> 
> I'm not sure this is the correct place to factor in cost savings
> materialization would give.  Is it?
Yeah, I think so.  The patch LGTM.  I don't know if it's worth
caching the “all the same element” result, but probably not.

> Are explicit VEC_PERM nodes also still there in the optimization
> process or are they turned into sth implicit?
They're still there.  The current algorithm inherits the old
restriction that candidate layouts must be bijective, and not
all VEC_PERM_EXPRs are.  So some VEC_PERM_EXPRs would have to
be explicit whatever happens.  Same for non-bijective load
permutations.

  parent reply	other threads:[~2023-07-26 10:01 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-24 15:56 [Bug middle-end/106081] New: " hubicka at gcc dot gnu.org
2022-06-24 16:14 ` [Bug middle-end/106081] " hubicka at gcc dot gnu.org
2022-06-26  8:08 ` crazylht at gmail dot com
2022-06-27  9:01 ` marxin at gcc dot gnu.org
2022-06-27 10:38 ` rguenth at gcc dot gnu.org
2022-06-27 14:26 ` hubicka at gcc dot gnu.org
2022-10-24  0:14 ` pinskia at gcc dot gnu.org
2023-06-21 13:45 ` rguenth at gcc dot gnu.org
2023-06-27  7:49 ` rguenth at gcc dot gnu.org
2023-06-27  8:13 ` rguenth at gcc dot gnu.org
2023-06-27  9:10 ` rsandifo at gcc dot gnu.org
2023-06-28 12:15 ` hubicka at gcc dot gnu.org
2023-07-26  9:34 ` rguenth at gcc dot gnu.org
2023-07-26  9:35 ` rguenth at gcc dot gnu.org
2023-07-26 10:01 ` rsandifo at gcc dot gnu.org [this message]
2023-07-26 10:32 ` rguenth at gcc dot gnu.org
2023-07-26 10:52 ` rguenth at gcc dot gnu.org
2023-07-26 11:00 ` rsandifo at gcc dot gnu.org
2023-07-26 11:15 ` rsandifo at gcc dot gnu.org
2023-07-26 12:15 ` rguenther at suse dot de
2023-07-26 13:28 ` cvs-commit at gcc dot gnu.org
2023-07-26 13:28 ` rguenth at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-106081-4-ZUs1Ej3QuF@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).