public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH]middle-end: don't lower past veclower [PR106063]
@ 2022-07-05 15:00 Tamar Christina
  2022-07-06 13:14 ` Jeff Law
  2022-07-07  7:18 ` Richard Biener
  0 siblings, 2 replies; 7+ messages in thread
From: Tamar Christina @ 2022-07-05 15:00 UTC (permalink / raw)
  To: gcc-patches; +Cc: nd, rguenther

[-- Attachment #1: Type: text/plain, Size: 1743 bytes --]

Hi All,

My previous patch can cause a problem if the pattern matches after veclower
as it may replace the construct with a vector sequence which the target may not
directly support.

As such don't perform the rewriting if after veclower.

Bootstrapped Regtested on aarch64-none-linux-gnu, x86_64-pc-linux-gnu
and no issues.

Ok for master? and backport to GCC 12?

Thanks,
Tamar


gcc/ChangeLog:

	PR tree-optimization/106063
	* match.pd: Do not apply pattern after veclower.

gcc/testsuite/ChangeLog:

	PR tree-optimization/106063
	* gcc.dg/pr106063.c: New test.

--- inline copy of patch -- 
diff --git a/gcc/match.pd b/gcc/match.pd
index 40c09bedadb89dabb6622559a8f69df5384e61fd..ba161892a98756c0278dc40fc377d7d0deaacbcf 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -6040,7 +6040,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
   (simplify
    (cmp (bit_and:c@2 @0 cst@1) integer_zerop)
     (with { tree csts = bitmask_inv_cst_vector_p (@1); }
-     (if (csts && (VECTOR_TYPE_P (TREE_TYPE (@1)) || single_use (@2)))
+     (if (csts && (VECTOR_TYPE_P (TREE_TYPE (@1)) || single_use (@2))
+	  && optimize_vectors_before_lowering_p ())
       (if (TYPE_UNSIGNED (TREE_TYPE (@1)))
        (icmp @0 { csts; })
        (with { tree utype = unsigned_type_for (TREE_TYPE (@1)); }
diff --git a/gcc/testsuite/gcc.dg/pr106063.c b/gcc/testsuite/gcc.dg/pr106063.c
new file mode 100644
index 0000000000000000000000000000000000000000..b23596724f6bb98c53af2dce77d31509bab10378
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr106063.c
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fno-tree-forwprop --disable-tree-evrp" } */
+typedef __int128 __attribute__((__vector_size__ (16))) V;
+
+V
+foo (V v)
+{
+  return (v & (V){15}) == v;
+}




-- 

[-- Attachment #2: rb15911.patch --]
[-- Type: text/plain, Size: 1143 bytes --]

diff --git a/gcc/match.pd b/gcc/match.pd
index 40c09bedadb89dabb6622559a8f69df5384e61fd..ba161892a98756c0278dc40fc377d7d0deaacbcf 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -6040,7 +6040,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
   (simplify
    (cmp (bit_and:c@2 @0 cst@1) integer_zerop)
     (with { tree csts = bitmask_inv_cst_vector_p (@1); }
-     (if (csts && (VECTOR_TYPE_P (TREE_TYPE (@1)) || single_use (@2)))
+     (if (csts && (VECTOR_TYPE_P (TREE_TYPE (@1)) || single_use (@2))
+	  && optimize_vectors_before_lowering_p ())
       (if (TYPE_UNSIGNED (TREE_TYPE (@1)))
        (icmp @0 { csts; })
        (with { tree utype = unsigned_type_for (TREE_TYPE (@1)); }
diff --git a/gcc/testsuite/gcc.dg/pr106063.c b/gcc/testsuite/gcc.dg/pr106063.c
new file mode 100644
index 0000000000000000000000000000000000000000..b23596724f6bb98c53af2dce77d31509bab10378
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr106063.c
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fno-tree-forwprop --disable-tree-evrp" } */
+typedef __int128 __attribute__((__vector_size__ (16))) V;
+
+V
+foo (V v)
+{
+  return (v & (V){15}) == v;
+}




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH]middle-end: don't lower past veclower [PR106063]
  2022-07-05 15:00 [PATCH]middle-end: don't lower past veclower [PR106063] Tamar Christina
@ 2022-07-06 13:14 ` Jeff Law
  2022-07-07  7:18 ` Richard Biener
  1 sibling, 0 replies; 7+ messages in thread
From: Jeff Law @ 2022-07-06 13:14 UTC (permalink / raw)
  To: gcc-patches



On 7/5/2022 9:00 AM, Tamar Christina via Gcc-patches wrote:
> Hi All,
>
> My previous patch can cause a problem if the pattern matches after veclower
> as it may replace the construct with a vector sequence which the target may not
> directly support.
>
> As such don't perform the rewriting if after veclower.
>
> Bootstrapped Regtested on aarch64-none-linux-gnu, x86_64-pc-linux-gnu
> and no issues.
>
> Ok for master? and backport to GCC 12?
>
> Thanks,
> Tamar
>
>
> gcc/ChangeLog:
>
> 	PR tree-optimization/106063
> 	* match.pd: Do not apply pattern after veclower.
>
> gcc/testsuite/ChangeLog:
>
> 	PR tree-optimization/106063
> 	* gcc.dg/pr106063.c: New test.
OK for both the trunk and gcc-12.
jeff


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH]middle-end: don't lower past veclower [PR106063]
  2022-07-05 15:00 [PATCH]middle-end: don't lower past veclower [PR106063] Tamar Christina
  2022-07-06 13:14 ` Jeff Law
@ 2022-07-07  7:18 ` Richard Biener
  2022-07-07  7:41   ` Tamar Christina
  1 sibling, 1 reply; 7+ messages in thread
From: Richard Biener @ 2022-07-07  7:18 UTC (permalink / raw)
  To: Tamar Christina; +Cc: gcc-patches, nd

On Tue, 5 Jul 2022, Tamar Christina wrote:

> Hi All,
> 
> My previous patch can cause a problem if the pattern matches after veclower
> as it may replace the construct with a vector sequence which the target may not
> directly support.
> 
> As such don't perform the rewriting if after veclower.

Note that when doing the rewriting before veclower to a variant
not supported by the target can cause veclower to generate absymal
code.  In some cases we are very careful and try to at least preserve
code supported by the target over transforming that into a variant
not supported.

That said, a better fix would be to check whether the target
can perform the new comparison.  Before veclower it would be
OK to do the transform nevertheless in case it cannot do the
original transform.

Richard.

> Bootstrapped Regtested on aarch64-none-linux-gnu, x86_64-pc-linux-gnu
> and no issues.
> 
> Ok for master? and backport to GCC 12?
> 
> Thanks,
> Tamar
> 
> 
> gcc/ChangeLog:
> 
> 	PR tree-optimization/106063
> 	* match.pd: Do not apply pattern after veclower.
> 
> gcc/testsuite/ChangeLog:
> 
> 	PR tree-optimization/106063
> 	* gcc.dg/pr106063.c: New test.
> 
> --- inline copy of patch -- 
> diff --git a/gcc/match.pd b/gcc/match.pd
> index 40c09bedadb89dabb6622559a8f69df5384e61fd..ba161892a98756c0278dc40fc377d7d0deaacbcf 100644
> --- a/gcc/match.pd
> +++ b/gcc/match.pd
> @@ -6040,7 +6040,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
>    (simplify
>     (cmp (bit_and:c@2 @0 cst@1) integer_zerop)
>      (with { tree csts = bitmask_inv_cst_vector_p (@1); }
> -     (if (csts && (VECTOR_TYPE_P (TREE_TYPE (@1)) || single_use (@2)))
> +     (if (csts && (VECTOR_TYPE_P (TREE_TYPE (@1)) || single_use (@2))
> +	  && optimize_vectors_before_lowering_p ())
>        (if (TYPE_UNSIGNED (TREE_TYPE (@1)))
>         (icmp @0 { csts; })
>         (with { tree utype = unsigned_type_for (TREE_TYPE (@1)); }
> diff --git a/gcc/testsuite/gcc.dg/pr106063.c b/gcc/testsuite/gcc.dg/pr106063.c
> new file mode 100644
> index 0000000000000000000000000000000000000000..b23596724f6bb98c53af2dce77d31509bab10378
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/pr106063.c
> @@ -0,0 +1,9 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -fno-tree-forwprop --disable-tree-evrp" } */
> +typedef __int128 __attribute__((__vector_size__ (16))) V;
> +
> +V
> +foo (V v)
> +{
> +  return (v & (V){15}) == v;
> +}
> 
> 
> 
> 
> 

-- 
Richard Biener <rguenther@suse.de>
SUSE Software Solutions Germany GmbH, Frankenstra

^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: [PATCH]middle-end: don't lower past veclower [PR106063]
  2022-07-07  7:18 ` Richard Biener
@ 2022-07-07  7:41   ` Tamar Christina
  2022-07-07  7:47     ` Richard Biener
  0 siblings, 1 reply; 7+ messages in thread
From: Tamar Christina @ 2022-07-07  7:41 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc-patches, nd

> -----Original Message-----
> From: Richard Biener <rguenther@suse.de>
> Sent: Thursday, July 7, 2022 8:19 AM
> To: Tamar Christina <Tamar.Christina@arm.com>
> Cc: gcc-patches@gcc.gnu.org; nd <nd@arm.com>
> Subject: Re: [PATCH]middle-end: don't lower past veclower [PR106063]
> 
> On Tue, 5 Jul 2022, Tamar Christina wrote:
> 
> > Hi All,
> >
> > My previous patch can cause a problem if the pattern matches after
> > veclower as it may replace the construct with a vector sequence which
> > the target may not directly support.
> >
> > As such don't perform the rewriting if after veclower.
> 
> Note that when doing the rewriting before veclower to a variant not
> supported by the target can cause veclower to generate absymal code.  In
> some cases we are very careful and try to at least preserve code supported
> by the target over transforming that into a variant not supported.
> 
> That said, a better fix would be to check whether the target can perform the
> new comparison.  Before veclower it would be OK to do the transform
> nevertheless in case it cannot do the original transform.

This last statement is somewhat confusing. Did you want me to change it such that
before veclower the rewrite is always done and after veclowering only if the target
supports it?

Or did you want me to never do the rewrite if the target doesn't support it?

Thanks,
Tamar

> 
> Richard.
> 
> > Bootstrapped Regtested on aarch64-none-linux-gnu, x86_64-pc-linux-gnu
> > and no issues.
> >
> > Ok for master? and backport to GCC 12?
> >
> > Thanks,
> > Tamar
> >
> >
> > gcc/ChangeLog:
> >
> > 	PR tree-optimization/106063
> > 	* match.pd: Do not apply pattern after veclower.
> >
> > gcc/testsuite/ChangeLog:
> >
> > 	PR tree-optimization/106063
> > 	* gcc.dg/pr106063.c: New test.
> >
> > --- inline copy of patch --
> > diff --git a/gcc/match.pd b/gcc/match.pd index
> >
> 40c09bedadb89dabb6622559a8f69df5384e61fd..ba161892a98756c0278dc40fc
> 377
> > d7d0deaacbcf 100644
> > --- a/gcc/match.pd
> > +++ b/gcc/match.pd
> > @@ -6040,7 +6040,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
> >    (simplify
> >     (cmp (bit_and:c@2 @0 cst@1) integer_zerop)
> >      (with { tree csts = bitmask_inv_cst_vector_p (@1); }
> > -     (if (csts && (VECTOR_TYPE_P (TREE_TYPE (@1)) || single_use (@2)))
> > +     (if (csts && (VECTOR_TYPE_P (TREE_TYPE (@1)) || single_use (@2))
> > +	  && optimize_vectors_before_lowering_p ())
> >        (if (TYPE_UNSIGNED (TREE_TYPE (@1)))
> >         (icmp @0 { csts; })
> >         (with { tree utype = unsigned_type_for (TREE_TYPE (@1)); }
> > diff --git a/gcc/testsuite/gcc.dg/pr106063.c
> > b/gcc/testsuite/gcc.dg/pr106063.c new file mode 100644 index
> >
> 0000000000000000000000000000000000000000..b23596724f6bb98c53af2dce77
> d3
> > 1509bab10378
> > --- /dev/null
> > +++ b/gcc/testsuite/gcc.dg/pr106063.c
> > @@ -0,0 +1,9 @@
> > +/* { dg-do compile } */
> > +/* { dg-options "-O2 -fno-tree-forwprop --disable-tree-evrp" } */
> > +typedef __int128 __attribute__((__vector_size__ (16))) V;
> > +
> > +V
> > +foo (V v)
> > +{
> > +  return (v & (V){15}) == v;
> > +}
> >
> >
> >
> >
> >
> 
> --
> Richard Biener <rguenther@suse.de>
> SUSE Software Solutions Germany GmbH, Frankenstra

^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: [PATCH]middle-end: don't lower past veclower [PR106063]
  2022-07-07  7:41   ` Tamar Christina
@ 2022-07-07  7:47     ` Richard Biener
  2022-07-08  6:26       ` Tamar Christina
  0 siblings, 1 reply; 7+ messages in thread
From: Richard Biener @ 2022-07-07  7:47 UTC (permalink / raw)
  To: Tamar Christina; +Cc: gcc-patches, nd

On Thu, 7 Jul 2022, Tamar Christina wrote:

> > -----Original Message-----
> > From: Richard Biener <rguenther@suse.de>
> > Sent: Thursday, July 7, 2022 8:19 AM
> > To: Tamar Christina <Tamar.Christina@arm.com>
> > Cc: gcc-patches@gcc.gnu.org; nd <nd@arm.com>
> > Subject: Re: [PATCH]middle-end: don't lower past veclower [PR106063]
> > 
> > On Tue, 5 Jul 2022, Tamar Christina wrote:
> > 
> > > Hi All,
> > >
> > > My previous patch can cause a problem if the pattern matches after
> > > veclower as it may replace the construct with a vector sequence which
> > > the target may not directly support.
> > >
> > > As such don't perform the rewriting if after veclower.
> > 
> > Note that when doing the rewriting before veclower to a variant not
> > supported by the target can cause veclower to generate absymal code.  In
> > some cases we are very careful and try to at least preserve code supported
> > by the target over transforming that into a variant not supported.
> > 
> > That said, a better fix would be to check whether the target can perform the
> > new comparison.  Before veclower it would be OK to do the transform
> > nevertheless in case it cannot do the original transform.
> 
> This last statement is somewhat confusing. Did you want me to change it such that
> before veclower the rewrite is always done and after veclowering only if the target
> supports it?
> 
> Or did you want me to never do the rewrite if the target doesn't support it?

I meant before veclower you can do the rewrite if either the rewriting
result is supported by the target OR if the original expression is
_not_ supported by the target.  The latter case might be not too
important to worry doing (it would still canonicalize for those
targets then).  After veclower you can only rewrite under the former
condition.

Richard.

> Thanks,
> Tamar
> 
> > 
> > Richard.
> > 
> > > Bootstrapped Regtested on aarch64-none-linux-gnu, x86_64-pc-linux-gnu
> > > and no issues.
> > >
> > > Ok for master? and backport to GCC 12?
> > >
> > > Thanks,
> > > Tamar
> > >
> > >
> > > gcc/ChangeLog:
> > >
> > > 	PR tree-optimization/106063
> > > 	* match.pd: Do not apply pattern after veclower.
> > >
> > > gcc/testsuite/ChangeLog:
> > >
> > > 	PR tree-optimization/106063
> > > 	* gcc.dg/pr106063.c: New test.
> > >
> > > --- inline copy of patch --
> > > diff --git a/gcc/match.pd b/gcc/match.pd index
> > >
> > 40c09bedadb89dabb6622559a8f69df5384e61fd..ba161892a98756c0278dc40fc
> > 377
> > > d7d0deaacbcf 100644
> > > --- a/gcc/match.pd
> > > +++ b/gcc/match.pd
> > > @@ -6040,7 +6040,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
> > >    (simplify
> > >     (cmp (bit_and:c@2 @0 cst@1) integer_zerop)
> > >      (with { tree csts = bitmask_inv_cst_vector_p (@1); }
> > > -     (if (csts && (VECTOR_TYPE_P (TREE_TYPE (@1)) || single_use (@2)))
> > > +     (if (csts && (VECTOR_TYPE_P (TREE_TYPE (@1)) || single_use (@2))
> > > +	  && optimize_vectors_before_lowering_p ())
> > >        (if (TYPE_UNSIGNED (TREE_TYPE (@1)))
> > >         (icmp @0 { csts; })
> > >         (with { tree utype = unsigned_type_for (TREE_TYPE (@1)); }
> > > diff --git a/gcc/testsuite/gcc.dg/pr106063.c
> > > b/gcc/testsuite/gcc.dg/pr106063.c new file mode 100644 index
> > >
> > 0000000000000000000000000000000000000000..b23596724f6bb98c53af2dce77
> > d3
> > > 1509bab10378
> > > --- /dev/null
> > > +++ b/gcc/testsuite/gcc.dg/pr106063.c
> > > @@ -0,0 +1,9 @@
> > > +/* { dg-do compile } */
> > > +/* { dg-options "-O2 -fno-tree-forwprop --disable-tree-evrp" } */
> > > +typedef __int128 __attribute__((__vector_size__ (16))) V;
> > > +
> > > +V
> > > +foo (V v)
> > > +{
> > > +  return (v & (V){15}) == v;
> > > +}
> > >
> > >
> > >
> > >
> > >
> > 
> > --
> > Richard Biener <rguenther@suse.de>
> > SUSE Software Solutions Germany GmbH, Frankenstra
> 

-- 
Richard Biener <rguenther@suse.de>
SUSE Software Solutions Germany GmbH, Frankenstra

^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: [PATCH]middle-end: don't lower past veclower [PR106063]
  2022-07-07  7:47     ` Richard Biener
@ 2022-07-08  6:26       ` Tamar Christina
  2022-07-08  7:16         ` Richard Biener
  0 siblings, 1 reply; 7+ messages in thread
From: Tamar Christina @ 2022-07-08  6:26 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc-patches, nd

[-- Attachment #1: Type: text/plain, Size: 4337 bytes --]

> -----Original Message-----
> From: Richard Biener <rguenther@suse.de>
> Sent: Thursday, July 7, 2022 8:47 AM
> To: Tamar Christina <Tamar.Christina@arm.com>
> Cc: gcc-patches@gcc.gnu.org; nd <nd@arm.com>
> Subject: RE: [PATCH]middle-end: don't lower past veclower [PR106063]
> 
> On Thu, 7 Jul 2022, Tamar Christina wrote:
> 
> > > -----Original Message-----
> > > From: Richard Biener <rguenther@suse.de>
> > > Sent: Thursday, July 7, 2022 8:19 AM
> > > To: Tamar Christina <Tamar.Christina@arm.com>
> > > Cc: gcc-patches@gcc.gnu.org; nd <nd@arm.com>
> > > Subject: Re: [PATCH]middle-end: don't lower past veclower [PR106063]
> > >
> > > On Tue, 5 Jul 2022, Tamar Christina wrote:
> > >
> > > > Hi All,
> > > >
> > > > My previous patch can cause a problem if the pattern matches after
> > > > veclower as it may replace the construct with a vector sequence
> > > > which the target may not directly support.
> > > >
> > > > As such don't perform the rewriting if after veclower.
> > >
> > > Note that when doing the rewriting before veclower to a variant not
> > > supported by the target can cause veclower to generate absymal code.
> > > In some cases we are very careful and try to at least preserve code
> > > supported by the target over transforming that into a variant not
> supported.
> > >
> > > That said, a better fix would be to check whether the target can
> > > perform the new comparison.  Before veclower it would be OK to do
> > > the transform nevertheless in case it cannot do the original transform.
> >
> > This last statement is somewhat confusing. Did you want me to change
> > it such that before veclower the rewrite is always done and after
> > veclowering only if the target supports it?
> >
> > Or did you want me to never do the rewrite if the target doesn't support it?
> 
> I meant before veclower you can do the rewrite if either the rewriting result
> is supported by the target OR if the original expression is _not_ supported by
> the target.  The latter case might be not too important to worry doing (it
> would still canonicalize for those targets then).  After veclower you can only
> rewrite under the former condition.
> 

Bootstrapped Regtested on aarch64-none-linux-gnu, x86_64-pc-linux-gnu
and no issues.

Ok for master? and backport to GCC 12?

Thanks,
Tamar


gcc/ChangeLog:

    PR tree-optimization/106063
	* match.pd: Only rewrite if target support it.

gcc/testsuite/ChangeLog:

    PR tree-optimization/106063
	* gcc.dg/pr106063.c: New test.

--- inline copy of patch ---

diff --git a/gcc/match.pd b/gcc/match.pd
index 40c09bedadb89dabb6622559a8f69df5384e61fd..5800a105c3cdada9d5e1d8019176ebbe5969ccb0 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -6041,10 +6041,16 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
    (cmp (bit_and:c@2 @0 cst@1) integer_zerop)
     (with { tree csts = bitmask_inv_cst_vector_p (@1); }
      (if (csts && (VECTOR_TYPE_P (TREE_TYPE (@1)) || single_use (@2)))
-      (if (TYPE_UNSIGNED (TREE_TYPE (@1)))
-       (icmp @0 { csts; })
-       (with { tree utype = unsigned_type_for (TREE_TYPE (@1)); }
-	 (icmp (view_convert:utype @0) { csts; }))))))))
+      (with { auto optab = VECTOR_TYPE_P (TREE_TYPE (@1))
+			 ? optab_vector : optab_default;
+	      tree utype = unsigned_type_for (TREE_TYPE (@1)); }
+       (if (target_supports_op_p (utype, icmp, optab)
+	    || (optimize_vectors_before_lowering_p ()
+		&& (!target_supports_op_p (type, cmp, optab)
+		    || !target_supports_op_p (type, BIT_AND_EXPR, optab))))
+	(if (TYPE_UNSIGNED (TREE_TYPE (@1)))
+	 (icmp @0 { csts; })
+	 (icmp (view_convert:utype @0) { csts; })))))))))
 
 /* When one argument is a constant, overflow detection can be simplified.
    Currently restricted to single use so as not to interfere too much with
diff --git a/gcc/testsuite/gcc.dg/pr106063.c b/gcc/testsuite/gcc.dg/pr106063.c
new file mode 100644
index 0000000000000000000000000000000000000000..b23596724f6bb98c53af2dce77d31509bab10378
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr106063.c
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fno-tree-forwprop --disable-tree-evrp" } */
+typedef __int128 __attribute__((__vector_size__ (16))) V;
+
+V
+foo (V v)
+{
+  return (v & (V){15}) == v;
+}

[-- Attachment #2: rb15911.patch --]
[-- Type: application/octet-stream, Size: 1699 bytes --]

diff --git a/gcc/match.pd b/gcc/match.pd
index 40c09bedadb89dabb6622559a8f69df5384e61fd..5800a105c3cdada9d5e1d8019176ebbe5969ccb0 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -6041,10 +6041,16 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
    (cmp (bit_and:c@2 @0 cst@1) integer_zerop)
     (with { tree csts = bitmask_inv_cst_vector_p (@1); }
      (if (csts && (VECTOR_TYPE_P (TREE_TYPE (@1)) || single_use (@2)))
-      (if (TYPE_UNSIGNED (TREE_TYPE (@1)))
-       (icmp @0 { csts; })
-       (with { tree utype = unsigned_type_for (TREE_TYPE (@1)); }
-	 (icmp (view_convert:utype @0) { csts; }))))))))
+      (with { auto optab = VECTOR_TYPE_P (TREE_TYPE (@1))
+			 ? optab_vector : optab_default;
+	      tree utype = unsigned_type_for (TREE_TYPE (@1)); }
+       (if (target_supports_op_p (utype, icmp, optab)
+	    || (optimize_vectors_before_lowering_p ()
+		&& (!target_supports_op_p (type, cmp, optab)
+		    || !target_supports_op_p (type, BIT_AND_EXPR, optab))))
+	(if (TYPE_UNSIGNED (TREE_TYPE (@1)))
+	 (icmp @0 { csts; })
+	 (icmp (view_convert:utype @0) { csts; })))))))))
 
 /* When one argument is a constant, overflow detection can be simplified.
    Currently restricted to single use so as not to interfere too much with
diff --git a/gcc/testsuite/gcc.dg/pr106063.c b/gcc/testsuite/gcc.dg/pr106063.c
new file mode 100644
index 0000000000000000000000000000000000000000..b23596724f6bb98c53af2dce77d31509bab10378
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr106063.c
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fno-tree-forwprop --disable-tree-evrp" } */
+typedef __int128 __attribute__((__vector_size__ (16))) V;
+
+V
+foo (V v)
+{
+  return (v & (V){15}) == v;
+}

^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: [PATCH]middle-end: don't lower past veclower [PR106063]
  2022-07-08  6:26       ` Tamar Christina
@ 2022-07-08  7:16         ` Richard Biener
  0 siblings, 0 replies; 7+ messages in thread
From: Richard Biener @ 2022-07-08  7:16 UTC (permalink / raw)
  To: Tamar Christina; +Cc: gcc-patches, nd

On Fri, 8 Jul 2022, Tamar Christina wrote:

> > -----Original Message-----
> > From: Richard Biener <rguenther@suse.de>
> > Sent: Thursday, July 7, 2022 8:47 AM
> > To: Tamar Christina <Tamar.Christina@arm.com>
> > Cc: gcc-patches@gcc.gnu.org; nd <nd@arm.com>
> > Subject: RE: [PATCH]middle-end: don't lower past veclower [PR106063]
> > 
> > On Thu, 7 Jul 2022, Tamar Christina wrote:
> > 
> > > > -----Original Message-----
> > > > From: Richard Biener <rguenther@suse.de>
> > > > Sent: Thursday, July 7, 2022 8:19 AM
> > > > To: Tamar Christina <Tamar.Christina@arm.com>
> > > > Cc: gcc-patches@gcc.gnu.org; nd <nd@arm.com>
> > > > Subject: Re: [PATCH]middle-end: don't lower past veclower [PR106063]
> > > >
> > > > On Tue, 5 Jul 2022, Tamar Christina wrote:
> > > >
> > > > > Hi All,
> > > > >
> > > > > My previous patch can cause a problem if the pattern matches after
> > > > > veclower as it may replace the construct with a vector sequence
> > > > > which the target may not directly support.
> > > > >
> > > > > As such don't perform the rewriting if after veclower.
> > > >
> > > > Note that when doing the rewriting before veclower to a variant not
> > > > supported by the target can cause veclower to generate absymal code.
> > > > In some cases we are very careful and try to at least preserve code
> > > > supported by the target over transforming that into a variant not
> > supported.
> > > >
> > > > That said, a better fix would be to check whether the target can
> > > > perform the new comparison.  Before veclower it would be OK to do
> > > > the transform nevertheless in case it cannot do the original transform.
> > >
> > > This last statement is somewhat confusing. Did you want me to change
> > > it such that before veclower the rewrite is always done and after
> > > veclowering only if the target supports it?
> > >
> > > Or did you want me to never do the rewrite if the target doesn't support it?
> > 
> > I meant before veclower you can do the rewrite if either the rewriting result
> > is supported by the target OR if the original expression is _not_ supported by
> > the target.  The latter case might be not too important to worry doing (it
> > would still canonicalize for those targets then).  After veclower you can only
> > rewrite under the former condition.
> > 
> 
> Bootstrapped Regtested on aarch64-none-linux-gnu, x86_64-pc-linux-gnu
> and no issues.
> 
> Ok for master? and backport to GCC 12?

OK for master, backport to GCC 12 after a few days of soaking.

Thanks,
Richard.

> Thanks,
> Tamar
> 
> 
> gcc/ChangeLog:
> 
>     PR tree-optimization/106063
> 	* match.pd: Only rewrite if target support it.
> 
> gcc/testsuite/ChangeLog:
> 
>     PR tree-optimization/106063
> 	* gcc.dg/pr106063.c: New test.
> 
> --- inline copy of patch ---
> 
> diff --git a/gcc/match.pd b/gcc/match.pd
> index 40c09bedadb89dabb6622559a8f69df5384e61fd..5800a105c3cdada9d5e1d8019176ebbe5969ccb0 100644
> --- a/gcc/match.pd
> +++ b/gcc/match.pd
> @@ -6041,10 +6041,16 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
>     (cmp (bit_and:c@2 @0 cst@1) integer_zerop)
>      (with { tree csts = bitmask_inv_cst_vector_p (@1); }
>       (if (csts && (VECTOR_TYPE_P (TREE_TYPE (@1)) || single_use (@2)))
> -      (if (TYPE_UNSIGNED (TREE_TYPE (@1)))
> -       (icmp @0 { csts; })
> -       (with { tree utype = unsigned_type_for (TREE_TYPE (@1)); }
> -	 (icmp (view_convert:utype @0) { csts; }))))))))
> +      (with { auto optab = VECTOR_TYPE_P (TREE_TYPE (@1))
> +			 ? optab_vector : optab_default;
> +	      tree utype = unsigned_type_for (TREE_TYPE (@1)); }
> +       (if (target_supports_op_p (utype, icmp, optab)
> +	    || (optimize_vectors_before_lowering_p ()
> +		&& (!target_supports_op_p (type, cmp, optab)
> +		    || !target_supports_op_p (type, BIT_AND_EXPR, optab))))
> +	(if (TYPE_UNSIGNED (TREE_TYPE (@1)))
> +	 (icmp @0 { csts; })
> +	 (icmp (view_convert:utype @0) { csts; })))))))))
>  
>  /* When one argument is a constant, overflow detection can be simplified.
>     Currently restricted to single use so as not to interfere too much with
> diff --git a/gcc/testsuite/gcc.dg/pr106063.c b/gcc/testsuite/gcc.dg/pr106063.c
> new file mode 100644
> index 0000000000000000000000000000000000000000..b23596724f6bb98c53af2dce77d31509bab10378
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/pr106063.c
> @@ -0,0 +1,9 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -fno-tree-forwprop --disable-tree-evrp" } */
> +typedef __int128 __attribute__((__vector_size__ (16))) V;
> +
> +V
> +foo (V v)
> +{
> +  return (v & (V){15}) == v;
> +}
> 

-- 
Richard Biener <rguenther@suse.de>
SUSE Software Solutions Germany GmbH, Frankenstra

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-07-08  7:16 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-05 15:00 [PATCH]middle-end: don't lower past veclower [PR106063] Tamar Christina
2022-07-06 13:14 ` Jeff Law
2022-07-07  7:18 ` Richard Biener
2022-07-07  7:41   ` Tamar Christina
2022-07-07  7:47     ` Richard Biener
2022-07-08  6:26       ` Tamar Christina
2022-07-08  7:16         ` Richard Biener

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).