public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "juzhe.zhong at rivai dot ai" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/111751] RISC-V: RVV unexpected vectorization
Date: Tue, 10 Oct 2023 04:00:45 +0000	[thread overview]
Message-ID: <bug-111751-4-hFGiS0W06E@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-111751-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #7 from JuzheZhong <juzhe.zhong at rivai dot ai> ---
(In reply to Andrew Pinski from comment #6)
> (In reply to JuzheZhong from comment #5)
> > (In reply to Andrew Pinski from comment #4)
> > > The issue for aarch64 with SVE is that MASK_LOAD is not optimized:
> > > 
> > >   ic = "\x00\x03\x06\t\f\x0f\x12\x15\x18\x1b\x1e!$\'*-";
> > >   ib = "\x00\x03\x06\t\f\x0f\x12\x15\x18\x1b\x1e!$\'*-";
> > >   vect__1.7_9 = .MASK_LOAD (&ib, 8B, { -1, -1, -1, -1, -1, -1, -1, -1, -1,
> > > -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
> > > ... });
> > >   vect__2.10_35 = .MASK_LOAD (&ic, 8B, { -1, -1, -1, -1, -1, -1, -1, -1, -1,
> > > -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
> > > ... });
> > 
> > I don't ARM SVE has issues ...
> 
> It does as I mentioned if you use -fno-vect-cost-model, you get the above
> issue which should be optimized really to a constant vector ...

After investigation:

I found it failed to recognize its CONST_VECTOR value in FRE

/* Visit a load from a reference operator RHS, part of STMT, value number it,
   and return true if the value number of the LHS has changed as a result.  */

static bool
visit_reference_op_load (tree lhs, tree op, gimple *stmt)
{
  bool changed = false;
  tree result;
  vn_reference_t res;

  tree vuse = gimple_vuse (stmt);
  tree last_vuse = vuse;
  result = vn_reference_lookup (op, vuse, default_vn_walk_kind, &res, true,
&last_vuse);

  /* We handle type-punning through unions by value-numbering based
     on offset and size of the access.  Be prepared to handle a
     type-mismatch here via creating a VIEW_CONVERT_EXPR.  */
  if (result
      && !useless_type_conversion_p (TREE_TYPE (result), TREE_TYPE (op)))
    {
      /* Avoid the type punning in case the result mode has padding where
         the op we lookup has not.  */
      if (maybe_lt (GET_MODE_PRECISION (TYPE_MODE (TREE_TYPE (result))),
                    GET_MODE_PRECISION (TYPE_MODE (TREE_TYPE (op)))))
        result = NULL_TREE;

....


The result is BLKmode, op is V16QImode

Then reach
      /* Avoid the type punning in case the result mode has padding where
         the op we lookup has not.  */
      if (maybe_lt (GET_MODE_PRECISION (TYPE_MODE (TREE_TYPE (result))),
                    GET_MODE_PRECISION (TYPE_MODE (TREE_TYPE (op)))))
        result = NULL_TREE;

If I delete this code, RVV can optimize it.

Do you have any suggestion ?

This is my observation:

Breakpoint 6, visit_reference_op_load (lhs=0x7ffff68364c8, op=0x7ffff6874410,
stmt=0x7ffff6872640) at ../../../../gcc/gcc/tree-ssa-sccvn.cc:5740
5740      result = vn_reference_lookup (op, vuse, default_vn_walk_kind, &res,
true, &last_vuse);
(gdb) c
Continuing.

Breakpoint 6, visit_reference_op_load (lhs=0x7ffff68364c8, op=0x7ffff6874410,
stmt=0x7ffff6872640) at ../../../../gcc/gcc/tree-ssa-sccvn.cc:5740
5740      result = vn_reference_lookup (op, vuse, default_vn_walk_kind, &res,
true, &last_vuse);
(gdb) n
5746          && !useless_type_conversion_p (TREE_TYPE (result), TREE_TYPE
(op)))
(gdb) p debug (result)
"\x00\x03\x06\t\f\x0f\x12\x15\x18\x1b\x1e!$\'*-"
$9 = void
(gdb) p op->typed.type->type_common.mode
$10 = E_V16QImode

  parent reply	other threads:[~2023-10-10  4:00 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-10  3:19 [Bug c/111751] New: " juzhe.zhong at rivai dot ai
2023-10-10  3:35 ` [Bug tree-optimization/111751] " pinskia at gcc dot gnu.org
2023-10-10  3:35 ` pinskia at gcc dot gnu.org
2023-10-10  3:36 ` pinskia at gcc dot gnu.org
2023-10-10  3:41 ` pinskia at gcc dot gnu.org
2023-10-10  3:51 ` juzhe.zhong at rivai dot ai
2023-10-10  3:55 ` pinskia at gcc dot gnu.org
2023-10-10  4:00 ` juzhe.zhong at rivai dot ai [this message]
2023-10-10  9:09 ` rguenth at gcc dot gnu.org
2023-10-10  9:24 ` juzhe.zhong at rivai dot ai
2023-10-10  9:32 ` rguenther at suse dot de
2023-10-10 10:38 ` cvs-commit at gcc dot gnu.org
2023-10-10 10:50 ` rguenth at gcc dot gnu.org
2023-10-10 11:17 ` juzhe.zhong at rivai dot ai
2023-10-10 11:23 ` juzhe.zhong at rivai dot ai
2023-10-10 11:40 ` juzhe.zhong at rivai dot ai
2023-10-10 11:49 ` rguenth at gcc dot gnu.org
2023-10-10 11:50 ` cvs-commit at gcc dot gnu.org
2023-10-10 11:56 ` juzhe.zhong at rivai dot ai
2023-10-10 12:20 ` cvs-commit at gcc dot gnu.org
2023-10-10 12:22 ` cvs-commit at gcc dot gnu.org
2023-10-10 12:47 ` juzhe.zhong at rivai dot ai

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-111751-4-hFGiS0W06E@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).