public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <richard.guenther@gmail.com>
To: luoxhu <luoxhu@linux.ibm.com>
Cc: Segher Boessenkool <segher@kernel.crashing.org>,
	GCC Patches <gcc-patches@gcc.gnu.org>,
	 David Edelsohn <dje.gcc@gmail.com>,
	Bill Schmidt <wschmidt@linux.ibm.com>,
	linkw@gcc.gnu.org
Subject: Re: [PATCH v2] rs6000: Expand vec_insert in expander instead of gimple [PR79251]
Date: Mon, 7 Sep 2020 13:57:31 +0200	[thread overview]
Message-ID: <CAFiYyc17PyP++95TWjyOJQd52+EbSN+95f7R+ZZS1T_aNfxy_w@mail.gmail.com> (raw)
In-Reply-To: <e36e8ff4-cb88-dc95-2588-d62ce36c4b77@linux.ibm.com>

On Mon, Sep 7, 2020 at 7:44 AM luoxhu <luoxhu@linux.ibm.com> wrote:
>
> Hi,
>
> On 2020/9/4 18:23, Segher Boessenkool wrote:
> >> diff --git a/gcc/config/rs6000/rs6000-c.c b/gcc/config/rs6000/rs6000-c.c
> >> index 03b00738a5e..00c65311f76 100644
> >> --- a/gcc/config/rs6000/rs6000-c.c
> >> +++ b/gcc/config/rs6000/rs6000-c.c
> >>         /* Build *(((arg1_inner_type*)&(vector type){arg1})+arg2) = arg0. */
> >> @@ -1654,15 +1656,8 @@ altivec_resolve_overloaded_builtin (location_t loc, tree fndecl,
> >>            SET_EXPR_LOCATION (stmt, loc);
> >>            stmt = build1 (COMPOUND_LITERAL_EXPR, arg1_type, stmt);
> >>          }
> >> -
> >> -      innerptrtype = build_pointer_type (arg1_inner_type);
> >> -
> >> -      stmt = build_unary_op (loc, ADDR_EXPR, stmt, 0);
> >> -      stmt = convert (innerptrtype, stmt);
> >> -      stmt = build_binary_op (loc, PLUS_EXPR, stmt, arg2, 1);
> >> -      stmt = build_indirect_ref (loc, stmt, RO_NULL);
> >> -      stmt = build2 (MODIFY_EXPR, TREE_TYPE (stmt), stmt,
> >> -                    convert (TREE_TYPE (stmt), arg0));
> >> +      stmt = build_array_ref (loc, stmt, arg2);
> >> +      stmt = fold_build2 (MODIFY_EXPR, TREE_TYPE (arg0), stmt, arg0);
> >>         stmt = build2 (COMPOUND_EXPR, arg1_type, stmt, decl);
> >>         return stmt;
> >>       }
> > You should make a copy of the vector, not modify the original one in
> > place?  (If I read that correctly, heh.)  Looks good otherwise.
> >
>
> Segher, there  is already existed code to make a copy of vector as we
> discussed offline.  Thanks for the reminder.
>
> cat pr79251.c.006t.gimple
> __attribute__((noinline))
> test (__vector signed int v, int i, size_t n)
> {
>   __vector signed int D.3192;
>   __vector signed int D.3194;
>   __vector signed int v1;
>   v1 = v;
>   D.3192 = v1;
>   _1 = n & 3;
>   VIEW_CONVERT_EXPR<int[4]>(D.3192)[_1] = i;
>   v1 = D.3192;
>   D.3194 = v1;
>   return D.3194;
> }
>
> Attached the v2 patch which does:
> 1) Build VIEW_CONVERT_EXPR for vec_insert (i, v, n) like v[n%4] = i to
> unify the gimple code, then expander could use vec_set_optab to expand.
> 2) Recognize the pattern in expander and use optabs to expand
> VIEW_CONVERT_EXPR to vec_insert with variable index to fast instructions:
> lvsl+xxperm+xxsel.

Looking at the RTL expander side I see several issues.


@@ -5237,6 +5288,16 @@ expand_assignment (tree to, tree from, bool nontemporal)

       to_rtx = expand_expr (tem, NULL_RTX, VOIDmode, EXPAND_WRITE);

+      if (TREE_CODE (to) == ARRAY_REF)
+       {
+         tree op0 = TREE_OPERAND (to, 0);
+         if (TREE_CODE (op0) == VIEW_CONVERT_EXPR
+             && expand_view_convert_to_vec_set (to, from, to_rtx))
+           {
+             pop_temp_slots ();
+             return;
+           }
+       }

you're placing this at an awkward spot IMHO, after to_rtx expansion
but disregading parts of  it and compensating just with 'to' matching.
Is the pieces (offset, bitpos) really too awkward to work with for
matching?

Because as written you'll miscompile

struct X { _vector signed int v; _vector singed int u; } x;

test(int i, int a)
{
  x.u[i] = a;
}

as I think you'll end up assigning to x.v.

Are we just interested in the case were we store to a
pseudo or also when the destination is memory?  I guess
only when it's a pseudo - correct?  In that case
handling this all in optimize_bitfield_assignment_op
is probably the best thing to try.

Note we possibly refrain from assigning a pseudo to
such vector because we see a variable array-ref to it.

Richard.

> Thanks,
> Xionghu

  reply	other threads:[~2020-09-07 11:57 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-31  9:06 [PATCH] " Xiong Hu Luo
2020-08-31 12:43 ` Richard Biener
2020-08-31 16:47 ` will schmidt
2020-09-01 11:43   ` luoxhu
2020-08-31 17:04 ` Segher Boessenkool
2020-09-01  8:09   ` luoxhu
2020-09-01 13:07     ` Richard Biener
2020-09-02  9:26       ` luoxhu
2020-09-02  9:30         ` Richard Biener
2020-09-03  9:20           ` luoxhu
2020-09-03 10:29             ` Richard Biener
2020-09-04  6:16               ` luoxhu
2020-09-04  6:38                 ` luoxhu
2020-09-04  7:19                   ` Richard Biener
2020-09-04  7:23                     ` Richard Biener
2020-09-04  9:18                       ` luoxhu
2020-09-04 10:23                         ` Segher Boessenkool
2020-09-07  5:43                           ` [PATCH v2] " luoxhu
2020-09-07 11:57                             ` Richard Biener [this message]
2020-09-08  8:11                               ` luoxhu
2020-09-08  8:26                                 ` Richard Biener
2020-09-09  1:47                                   ` luoxhu
2020-09-09  7:30                                     ` Richard Biener
2020-09-09 13:47                                   ` Segher Boessenkool
2020-09-09 14:28                                     ` Richard Biener
2020-09-09 16:00                                       ` Segher Boessenkool
2020-09-10 10:08                                         ` Richard Biener
2020-09-14  8:05                                           ` luoxhu
2020-09-14  9:47                                             ` Richard Biener
2020-09-14 10:47                                               ` Richard Sandiford
2020-09-14 11:22                                                 ` Richard Biener
2020-09-14 11:49                                                   ` Richard Sandiford
2020-09-14 21:06                                                 ` Segher Boessenkool
2020-09-14 20:59                                               ` Segher Boessenkool
2020-09-15  3:56                                               ` luoxhu
2020-09-15  6:51                                                 ` Richard Biener
2020-09-15 16:16                                                   ` Segher Boessenkool
2020-09-16  8:31                                                     ` Richard Biener
2020-09-16 11:11                                                       ` Segher Boessenkool
2020-09-16  6:15                                                   ` luoxhu
2020-09-16  8:41                                                     ` Richard Biener
2020-09-14 20:21                                           ` Segher Boessenkool
2020-09-01 14:02     ` [PATCH] " Segher Boessenkool

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=CAFiYyc17PyP++95TWjyOJQd52+EbSN+95f7R+ZZS1T_aNfxy_w@mail.gmail.com \
    --to=richard.guenther@gmail.com \
    --cc=dje.gcc@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=linkw@gcc.gnu.org \
    --cc=luoxhu@linux.ibm.com \
    --cc=segher@kernel.crashing.org \
    --cc=wschmidt@linux.ibm.com \
    /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).