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 c/110430] New: Fail to CSE for LEN_MASK_STORE
Date: Tue, 27 Jun 2023 09:18:57 +0000	[thread overview]
Message-ID: <bug-110430-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 110430
           Summary: Fail to CSE for LEN_MASK_STORE
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: juzhe.zhong at rivai dot ai
  Target Milestone: ---

Consider this following case:

void __attribute__((noinline,noclone))
foo (int *out, int *res)
{
  int mask[] = { 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 };
  int i;
  for (i = 0; i < 16; ++i)
    {
      if (mask[i])
        out[i] = i;
    }
  int o0 = out[0];
  int o7 = out[7];
  int o14 = out[14];
  int o15 = out[15];
  res[0] = o0;
  res[2] = o7;
  res[4] = o14;
  res[6] = o15;
}

-O3 -march=rv64gcv_zvl512b --param riscv-autovec-preference=fixed-vlmax
Current RVV auto-vectorization codegen:

foo:
        lui     a5,%hi(.LANCHOR0)
        vsetivli        zero,16,e32,m1,ta,ma
        addi    a5,a5,%lo(.LANCHOR0)
        vid.v   v1
        vlm.v   v0,0(a5)
        vsetvli a5,zero,e32,m1,ta,ma
        vse32.v v1,0(a0),v0.t
        lw      a2,0(a0)
        lw      a3,28(a0)
        lw      a4,56(a0)
        lw      a5,60(a0)
        sw      a2,0(a1)
        sw      a3,8(a1)
        sw      a4,16(a1)
        sw      a5,24(a1)
        ret

However, with this patch:
https://patchwork.sourceware.org/project/gcc/patch/20230627064737.16257-1-juzhe.zhong@rivai.ai/

We will end up with better codegen with CSE:

foo:
        lui     a5,%hi(.LANCHOR0)
        vsetivli        zero,16,e32,m1,ta,ma
        addi    a5,a5,%lo(.LANCHOR0)
        vid.v   v1
        vlm.v   v0,0(a5)
        vsetvli a5,zero,e32,m1,ta,ma
        vse32.v v1,0(a0),v0.t
        lw      a4,0(a0)
        lw      a5,56(a0)
        sw      a4,0(a1)
        sw      a5,16(a1)
        li      a4,7
        li      a5,15
        sw      a4,8(a1)
        sw      a5,24(a1)
        ret

2 "lw" should be CSE into 2 "li" instructions, gimple IR:

.LEN_MASK_STORE (out_10(D), 32B, 16, { 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0,
-1, 0, -1, 0, -1 }, { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
0);
  o0_11 = *out_10(D);
  o14_13 = MEM[(int *)out_10(D) + 56B];
  *res_15(D) = o0_11;
  MEM[(int *)res_15(D) + 8B] = 7;
  MEM[(int *)res_15(D) + 16B] = o14_13;
  MEM[(int *)res_15(D) + 24B] = 15;
  mask ={v} {CLOBBER(eol)};

Since after discussion with Richi, 
this current possible fix patch can only hanlde VLS (fixed-length) vectors,
can not handle VLA (variable-length) vectors.

It's hard for us to create a C code testcase to produce CSE opportunity for
VL vectors.

So, open a BUG for now to make me won't forget such issue.
Will enhance LEN_MASK_STORE in CSE after I finished all RVV auto-vectorization
support.

             reply	other threads:[~2023-06-27  9:18 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-27  9:18 juzhe.zhong at rivai dot ai [this message]
2023-06-27 10:12 ` [Bug c/110430] " rguenth at gcc dot gnu.org
2023-06-27 20:14 ` [Bug middle-end/110430] " pinskia at gcc dot gnu.org
2023-06-27 20:14 ` pinskia 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-110430-4@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).