* [PATCH] Canonicalize vec_perm index to make the first index come from the first vector.
@ 2022-10-18 23:23 liuhongt
2022-10-18 23:49 ` H.J. Lu
2022-10-19 5:58 ` Uros Bizjak
0 siblings, 2 replies; 4+ messages in thread
From: liuhongt @ 2022-10-18 23:23 UTC (permalink / raw)
To: gcc-patches; +Cc: crazylht, hjl.tools, ubizjak
Fix unexpected non-canon form from gimple vector selector.
Bootstrapped and regtested on x86_64-pc-linux-gnu{-m32,}.
Ok for trunk?
gcc/ChangeLog:
PR target/107271
* config/i386/i386-expand.cc (ix86_vec_perm_index_canon): New.
(expand_vec_perm_shufps_shufps): Call
ix86_vec_perm_index_canon
gcc/testsuite/ChangeLog:
* gcc.target/i386/pr107271.c: New test.
---
gcc/config/i386/i386-expand.cc | 17 +++++++++++++++++
gcc/testsuite/gcc.target/i386/pr107271.c | 16 ++++++++++++++++
2 files changed, 33 insertions(+)
create mode 100644 gcc/testsuite/gcc.target/i386/pr107271.c
diff --git a/gcc/config/i386/i386-expand.cc b/gcc/config/i386/i386-expand.cc
index 6baff6d0e61..4f121516091 100644
--- a/gcc/config/i386/i386-expand.cc
+++ b/gcc/config/i386/i386-expand.cc
@@ -19604,6 +19604,22 @@ expand_vec_perm_1 (struct expand_vec_perm_d *d)
return false;
}
+/* Canonicalize vec_perm index to make the first index
+ always comes from the first index. */
+static void
+ix86_vec_perm_index_canon (struct expand_vec_perm_d *d)
+{
+ unsigned nelt = d->nelt;
+ if (d->perm[0] < nelt)
+ return;
+
+ for (unsigned i = 0; i != nelt; i++)
+ d->perm[i] = (d->perm[i] + nelt) % (2 * nelt);
+
+ std::swap (d->op0, d->op1);
+ return;
+}
+
/* A subroutine of ix86_expand_vec_perm_const_1. Try to implement D
in terms of a pair of shufps+ shufps/pshufd instructions. */
static bool
@@ -19621,6 +19637,7 @@ expand_vec_perm_shufps_shufps (struct expand_vec_perm_d *d)
if (d->testing_p)
return true;
+ ix86_vec_perm_index_canon (d);
for (i = 0; i < 4; ++i)
count += d->perm[i] > 3 ? 1 : 0;
diff --git a/gcc/testsuite/gcc.target/i386/pr107271.c b/gcc/testsuite/gcc.target/i386/pr107271.c
new file mode 100644
index 00000000000..fe89c9a5bef
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr107271.c
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-options "-O0" } */
+
+typedef int __attribute__((__vector_size__ (16))) V;
+
+static inline __attribute__((__always_inline__)) V
+bar (V v128u32_0)
+{
+ return __builtin_shuffle ((V){}, v128u32_0, v128u32_0);
+}
+
+V
+foo (void)
+{
+ return bar ((V){7, 4, 4});
+}
--
2.27.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Canonicalize vec_perm index to make the first index come from the first vector.
2022-10-18 23:23 [PATCH] Canonicalize vec_perm index to make the first index come from the first vector liuhongt
@ 2022-10-18 23:49 ` H.J. Lu
2022-10-18 23:51 ` Hongtao Liu
2022-10-19 5:58 ` Uros Bizjak
1 sibling, 1 reply; 4+ messages in thread
From: H.J. Lu @ 2022-10-18 23:49 UTC (permalink / raw)
To: liuhongt; +Cc: gcc-patches, crazylht, ubizjak
On Tue, Oct 18, 2022 at 4:25 PM liuhongt <hongtao.liu@intel.com> wrote:
>
> Fix unexpected non-canon form from gimple vector selector.
>
> Bootstrapped and regtested on x86_64-pc-linux-gnu{-m32,}.
> Ok for trunk?
>
> gcc/ChangeLog:
>
> PR target/107271
> * config/i386/i386-expand.cc (ix86_vec_perm_index_canon): New.
> (expand_vec_perm_shufps_shufps): Call
> ix86_vec_perm_index_canon
>
> gcc/testsuite/ChangeLog:
>
> * gcc.target/i386/pr107271.c: New test.
> ---
> gcc/config/i386/i386-expand.cc | 17 +++++++++++++++++
> gcc/testsuite/gcc.target/i386/pr107271.c | 16 ++++++++++++++++
> 2 files changed, 33 insertions(+)
> create mode 100644 gcc/testsuite/gcc.target/i386/pr107271.c
>
> diff --git a/gcc/config/i386/i386-expand.cc b/gcc/config/i386/i386-expand.cc
> index 6baff6d0e61..4f121516091 100644
> --- a/gcc/config/i386/i386-expand.cc
> +++ b/gcc/config/i386/i386-expand.cc
> @@ -19604,6 +19604,22 @@ expand_vec_perm_1 (struct expand_vec_perm_d *d)
> return false;
> }
>
> +/* Canonicalize vec_perm index to make the first index
> + always comes from the first index. */
vector?
> +static void
> +ix86_vec_perm_index_canon (struct expand_vec_perm_d *d)
> +{
> + unsigned nelt = d->nelt;
> + if (d->perm[0] < nelt)
> + return;
> +
> + for (unsigned i = 0; i != nelt; i++)
> + d->perm[i] = (d->perm[i] + nelt) % (2 * nelt);
> +
> + std::swap (d->op0, d->op1);
> + return;
> +}
> +
> /* A subroutine of ix86_expand_vec_perm_const_1. Try to implement D
> in terms of a pair of shufps+ shufps/pshufd instructions. */
> static bool
> @@ -19621,6 +19637,7 @@ expand_vec_perm_shufps_shufps (struct expand_vec_perm_d *d)
> if (d->testing_p)
> return true;
>
> + ix86_vec_perm_index_canon (d);
> for (i = 0; i < 4; ++i)
> count += d->perm[i] > 3 ? 1 : 0;
>
> diff --git a/gcc/testsuite/gcc.target/i386/pr107271.c b/gcc/testsuite/gcc.target/i386/pr107271.c
> new file mode 100644
> index 00000000000..fe89c9a5bef
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/i386/pr107271.c
> @@ -0,0 +1,16 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O0" } */
> +
> +typedef int __attribute__((__vector_size__ (16))) V;
> +
> +static inline __attribute__((__always_inline__)) V
> +bar (V v128u32_0)
> +{
> + return __builtin_shuffle ((V){}, v128u32_0, v128u32_0);
> +}
> +
> +V
> +foo (void)
> +{
> + return bar ((V){7, 4, 4});
> +}
> --
> 2.27.0
>
--
H.J.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Canonicalize vec_perm index to make the first index come from the first vector.
2022-10-18 23:49 ` H.J. Lu
@ 2022-10-18 23:51 ` Hongtao Liu
0 siblings, 0 replies; 4+ messages in thread
From: Hongtao Liu @ 2022-10-18 23:51 UTC (permalink / raw)
To: H.J. Lu; +Cc: liuhongt, gcc-patches, ubizjak
On Wed, Oct 19, 2022 at 7:49 AM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> On Tue, Oct 18, 2022 at 4:25 PM liuhongt <hongtao.liu@intel.com> wrote:
> >
> > Fix unexpected non-canon form from gimple vector selector.
> >
> > Bootstrapped and regtested on x86_64-pc-linux-gnu{-m32,}.
> > Ok for trunk?
> >
> > gcc/ChangeLog:
> >
> > PR target/107271
> > * config/i386/i386-expand.cc (ix86_vec_perm_index_canon): New.
> > (expand_vec_perm_shufps_shufps): Call
> > ix86_vec_perm_index_canon
> >
> > gcc/testsuite/ChangeLog:
> >
> > * gcc.target/i386/pr107271.c: New test.
> > ---
> > gcc/config/i386/i386-expand.cc | 17 +++++++++++++++++
> > gcc/testsuite/gcc.target/i386/pr107271.c | 16 ++++++++++++++++
> > 2 files changed, 33 insertions(+)
> > create mode 100644 gcc/testsuite/gcc.target/i386/pr107271.c
> >
> > diff --git a/gcc/config/i386/i386-expand.cc b/gcc/config/i386/i386-expand.cc
> > index 6baff6d0e61..4f121516091 100644
> > --- a/gcc/config/i386/i386-expand.cc
> > +++ b/gcc/config/i386/i386-expand.cc
> > @@ -19604,6 +19604,22 @@ expand_vec_perm_1 (struct expand_vec_perm_d *d)
> > return false;
> > }
> >
> > +/* Canonicalize vec_perm index to make the first index
> > + always comes from the first index. */
> vector?
Yes.
> > +static void
> > +ix86_vec_perm_index_canon (struct expand_vec_perm_d *d)
> > +{
> > + unsigned nelt = d->nelt;
> > + if (d->perm[0] < nelt)
> > + return;
> > +
> > + for (unsigned i = 0; i != nelt; i++)
> > + d->perm[i] = (d->perm[i] + nelt) % (2 * nelt);
> > +
> > + std::swap (d->op0, d->op1);
> > + return;
> > +}
> > +
> > /* A subroutine of ix86_expand_vec_perm_const_1. Try to implement D
> > in terms of a pair of shufps+ shufps/pshufd instructions. */
> > static bool
> > @@ -19621,6 +19637,7 @@ expand_vec_perm_shufps_shufps (struct expand_vec_perm_d *d)
> > if (d->testing_p)
> > return true;
> >
> > + ix86_vec_perm_index_canon (d);
> > for (i = 0; i < 4; ++i)
> > count += d->perm[i] > 3 ? 1 : 0;
> >
> > diff --git a/gcc/testsuite/gcc.target/i386/pr107271.c b/gcc/testsuite/gcc.target/i386/pr107271.c
> > new file mode 100644
> > index 00000000000..fe89c9a5bef
> > --- /dev/null
> > +++ b/gcc/testsuite/gcc.target/i386/pr107271.c
> > @@ -0,0 +1,16 @@
> > +/* { dg-do compile } */
> > +/* { dg-options "-O0" } */
> > +
> > +typedef int __attribute__((__vector_size__ (16))) V;
> > +
> > +static inline __attribute__((__always_inline__)) V
> > +bar (V v128u32_0)
> > +{
> > + return __builtin_shuffle ((V){}, v128u32_0, v128u32_0);
> > +}
> > +
> > +V
> > +foo (void)
> > +{
> > + return bar ((V){7, 4, 4});
> > +}
> > --
> > 2.27.0
> >
>
>
> --
> H.J.
--
BR,
Hongtao
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Canonicalize vec_perm index to make the first index come from the first vector.
2022-10-18 23:23 [PATCH] Canonicalize vec_perm index to make the first index come from the first vector liuhongt
2022-10-18 23:49 ` H.J. Lu
@ 2022-10-19 5:58 ` Uros Bizjak
1 sibling, 0 replies; 4+ messages in thread
From: Uros Bizjak @ 2022-10-19 5:58 UTC (permalink / raw)
To: liuhongt; +Cc: gcc-patches, crazylht, hjl.tools
On Wed, Oct 19, 2022 at 1:25 AM liuhongt <hongtao.liu@intel.com> wrote:
>
> Fix unexpected non-canon form from gimple vector selector.
>
> Bootstrapped and regtested on x86_64-pc-linux-gnu{-m32,}.
> Ok for trunk?
>
> gcc/ChangeLog:
>
> PR target/107271
> * config/i386/i386-expand.cc (ix86_vec_perm_index_canon): New.
> (expand_vec_perm_shufps_shufps): Call
> ix86_vec_perm_index_canon
>
> gcc/testsuite/ChangeLog:
>
> * gcc.target/i386/pr107271.c: New test.
OK.
Thanks,
Uros.
> ---
> gcc/config/i386/i386-expand.cc | 17 +++++++++++++++++
> gcc/testsuite/gcc.target/i386/pr107271.c | 16 ++++++++++++++++
> 2 files changed, 33 insertions(+)
> create mode 100644 gcc/testsuite/gcc.target/i386/pr107271.c
>
> diff --git a/gcc/config/i386/i386-expand.cc b/gcc/config/i386/i386-expand.cc
> index 6baff6d0e61..4f121516091 100644
> --- a/gcc/config/i386/i386-expand.cc
> +++ b/gcc/config/i386/i386-expand.cc
> @@ -19604,6 +19604,22 @@ expand_vec_perm_1 (struct expand_vec_perm_d *d)
> return false;
> }
>
> +/* Canonicalize vec_perm index to make the first index
> + always comes from the first index. */
> +static void
> +ix86_vec_perm_index_canon (struct expand_vec_perm_d *d)
> +{
> + unsigned nelt = d->nelt;
> + if (d->perm[0] < nelt)
> + return;
> +
> + for (unsigned i = 0; i != nelt; i++)
> + d->perm[i] = (d->perm[i] + nelt) % (2 * nelt);
> +
> + std::swap (d->op0, d->op1);
> + return;
> +}
> +
> /* A subroutine of ix86_expand_vec_perm_const_1. Try to implement D
> in terms of a pair of shufps+ shufps/pshufd instructions. */
> static bool
> @@ -19621,6 +19637,7 @@ expand_vec_perm_shufps_shufps (struct expand_vec_perm_d *d)
> if (d->testing_p)
> return true;
>
> + ix86_vec_perm_index_canon (d);
> for (i = 0; i < 4; ++i)
> count += d->perm[i] > 3 ? 1 : 0;
>
> diff --git a/gcc/testsuite/gcc.target/i386/pr107271.c b/gcc/testsuite/gcc.target/i386/pr107271.c
> new file mode 100644
> index 00000000000..fe89c9a5bef
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/i386/pr107271.c
> @@ -0,0 +1,16 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O0" } */
> +
> +typedef int __attribute__((__vector_size__ (16))) V;
> +
> +static inline __attribute__((__always_inline__)) V
> +bar (V v128u32_0)
> +{
> + return __builtin_shuffle ((V){}, v128u32_0, v128u32_0);
> +}
> +
> +V
> +foo (void)
> +{
> + return bar ((V){7, 4, 4});
> +}
> --
> 2.27.0
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-10-19 5:58 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-18 23:23 [PATCH] Canonicalize vec_perm index to make the first index come from the first vector liuhongt
2022-10-18 23:49 ` H.J. Lu
2022-10-18 23:51 ` Hongtao Liu
2022-10-19 5:58 ` Uros Bizjak
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).