public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "linkw at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/106365] Miss to handle ifn .LEN_STORE in FRE
Date: Thu, 21 Jul 2022 07:30:19 +0000	[thread overview]
Message-ID: <bug-106365-4-OqnSpUHRr4@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-106365-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #10 from Kewen Lin <linkw at gcc dot gnu.org> ---
(In reply to Richard Biener from comment #7)
> Created attachment 53323 [details]
> prototype
> 
> I'm testing this - for .LEN_STORE you mainly have to compute pd.rhs_off,
> pd.offset, pd.size and do a single
> 
>   return data->push_partial_def (pd, set, set, offseti, maxsizei);

Thanks!  Added the below diff and confirm it can make most of code optimized
away and generate "return 285;".

diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc
index 0a16984d2ca..ea5b7c54f82 100644
--- a/gcc/tree-ssa-sccvn.cc
+++ b/gcc/tree-ssa-sccvn.cc
@@ -3228,6 +3228,7 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void
*data_,
        return (void *)-1;

       tree mask = NULL_TREE;
+      tree len = NULL_TREE;
       switch (fn)
        {
        case IFN_MASK_STORE:
@@ -3236,6 +3237,19 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void
*data_,
          if (TREE_CODE (mask) != VECTOR_CST)
            return (void *)-1;
          break;
+       case IFN_LEN_STORE:
+         {
+           /* Extract the length without bias.  */
+           tree len0 = gimple_call_arg (call, 2);
+           len0 = vn_valueize (len0);
+           if (TREE_CODE (len0) != INTEGER_CST)
+             return (void *) -1;
+           tree bias = gimple_call_arg (call, 4);
+           len = fold_build2 (MINUS_EXPR, TREE_TYPE (len0), len0, bias);
+           /* Bias is either 0 or -1, biased length should be constant.  */
+           gcc_assert (TREE_CODE (len) == INTEGER_CST);
+           break;
+         }
        default:
          return (void *)-1;
        }
@@ -3311,6 +3325,16 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void
*data_,
                                                       offseti, maxsizei);
                    }
                }
+             else if (len)
+               {
+                 pd.rhs_off = 0;
+                 pd.offset = offset2i;
+                 pd.size = tree_to_uhwi (len) * elsz;
+                 if (ranges_known_overlap_p (offset, maxsize, pd.offset,
+                                             pd.size))
+                   return data->push_partial_def (pd, set, set, offseti,
+                                                  maxsizei);
+               }
              else
                gcc_unreachable ();
              return NULL;

But it still keeps the .LEN_STORE there:

int foo ()
{
  int a[10];

  <bb 2> [local count: 97603129]:
  .LEN_STORE (&MEM <int[10]> [(void *)&a + 32B], 128B, 8, { 64, 0, 0, 0, 81, 0,
0, 0, 100, 0, 0, 0, 121, 0, 0, 0 }, 0);
  a ={v} {CLOBBER(eol)};
  return 285;

}

btw, the latest commit "Add alias disambiguation for vectorizer load/store
IFNs" has been applied.

  parent reply	other threads:[~2022-07-21  7:30 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-20  5:25 [Bug tree-optimization/106365] New: " linkw at gcc dot gnu.org
2022-07-20  7:35 ` [Bug tree-optimization/106365] " linkw at gcc dot gnu.org
2022-07-20  8:25 ` rguenth at gcc dot gnu.org
2022-07-20  8:53 ` linkw at gcc dot gnu.org
2022-07-20  9:01 ` rguenth at gcc dot gnu.org
2022-07-20  9:07 ` rguenth at gcc dot gnu.org
2022-07-20  9:11 ` linkw at gcc dot gnu.org
2022-07-20 10:34 ` rguenth at gcc dot gnu.org
2022-07-20 12:07 ` rguenth at gcc dot gnu.org
2022-07-21  7:26 ` rguenth at gcc dot gnu.org
2022-07-21  7:30 ` linkw at gcc dot gnu.org [this message]
2022-07-21  7:31 ` rguenth at gcc dot gnu.org
2022-07-21  7:37 ` linkw at gcc dot gnu.org
2022-07-21  7:39 ` rguenth at gcc dot gnu.org
2022-07-21  7:57 ` linkw at gcc dot gnu.org
2022-07-21 11:06 ` cvs-commit at gcc dot gnu.org
2022-07-21 11:24 ` 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-106365-4-OqnSpUHRr4@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).