public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] tree-optimization/108888 - call if-conversion
@ 2023-02-23 10:10 Richard Biener
  2023-04-05  9:07 ` Andre Vieira (lists)
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Biener @ 2023-02-23 10:10 UTC (permalink / raw)
  To: gcc-patches; +Cc: ams

The following makes sure to only predicate calls necessary.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

	PR tree-optimization/108888
	* tree-if-conv.cc (if_convertible_stmt_p): Set PLF_2 on
	calls to predicate.
	(predicate_statements): Only predicate calls with PLF_2.

	* g++.dg/torture/pr108888.C: New testcase.
---
 gcc/testsuite/g++.dg/torture/pr108888.C | 18 ++++++++++++++++++
 gcc/tree-if-conv.cc                     | 17 ++++++++++-------
 2 files changed, 28 insertions(+), 7 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/torture/pr108888.C

diff --git a/gcc/testsuite/g++.dg/torture/pr108888.C b/gcc/testsuite/g++.dg/torture/pr108888.C
new file mode 100644
index 00000000000..29a22e21102
--- /dev/null
+++ b/gcc/testsuite/g++.dg/torture/pr108888.C
@@ -0,0 +1,18 @@
+// { dg-do compile }
+
+int scaleValueSaturate_scalefactor, scaleValueSaturate___trans_tmp_2,
+    scaleValuesSaturate_i;
+int scaleValueSaturate(int value) {
+  int result = __builtin_clz(value);
+  if (value)
+    if (-result <= scaleValueSaturate_scalefactor)
+      return 0;
+  return scaleValueSaturate___trans_tmp_2;
+}
+short scaleValuesSaturate_dst;
+short *scaleValuesSaturate_src;
+void scaleValuesSaturate() {
+  for (; scaleValuesSaturate_i; scaleValuesSaturate_i++)
+    scaleValuesSaturate_dst =
+        scaleValueSaturate(scaleValuesSaturate_src[scaleValuesSaturate_i]);
+}
diff --git a/gcc/tree-if-conv.cc b/gcc/tree-if-conv.cc
index a7a8406374d..0e384e36394 100644
--- a/gcc/tree-if-conv.cc
+++ b/gcc/tree-if-conv.cc
@@ -1099,6 +1099,7 @@ if_convertible_stmt_p (gimple *stmt, vec<data_reference_p> refs)
 		   n = n->simdclone->next_clone)
 		if (n->simdclone->inbranch)
 		  {
+		    gimple_set_plf (stmt, GF_PLF_2, true);
 		    need_to_predicate = true;
 		    return true;
 		  }
@@ -2541,7 +2542,8 @@ predicate_statements (loop_p loop)
 	      release_defs (stmt);
 	      continue;
 	    }
-	  else if (gimple_plf (stmt, GF_PLF_2))
+	  else if (gimple_plf (stmt, GF_PLF_2)
+		   && is_gimple_assign (stmt))
 	    {
 	      tree lhs = gimple_assign_lhs (stmt);
 	      tree mask;
@@ -2625,13 +2627,14 @@ predicate_statements (loop_p loop)
 	      gimple_assign_set_rhs1 (stmt, ifc_temp_var (type, rhs, &gsi));
 	      update_stmt (stmt);
 	    }
-
-	  /* Convert functions that have a SIMD clone to IFN_MASK_CALL.  This
-	     will cause the vectorizer to match the "in branch" clone variants,
-	     and serves to build the mask vector in a natural way.  */
-	  gcall *call = dyn_cast <gcall *> (gsi_stmt (gsi));
-	  if (call && !gimple_call_internal_p (call))
+	  else if (gimple_plf (stmt, GF_PLF_2)
+		   && is_gimple_call (stmt))
 	    {
+	      /* Convert functions that have a SIMD clone to IFN_MASK_CALL.
+		 This will cause the vectorizer to match the "in branch"
+		 clone variants, and serves to build the mask vector
+		 in a natural way.  */
+	      gcall *call = dyn_cast <gcall *> (gsi_stmt (gsi));
 	      tree orig_fn = gimple_call_fn (call);
 	      int orig_nargs = gimple_call_num_args (call);
 	      auto_vec<tree> args;
-- 
2.35.3

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

* Re: [PATCH] tree-optimization/108888 - call if-conversion
  2023-02-23 10:10 [PATCH] tree-optimization/108888 - call if-conversion Richard Biener
@ 2023-04-05  9:07 ` Andre Vieira (lists)
  2023-04-11  8:48   ` Richard Biener
  0 siblings, 1 reply; 3+ messages in thread
From: Andre Vieira (lists) @ 2023-04-05  9:07 UTC (permalink / raw)
  To: Richard Biener, gcc-patches; +Cc: ams

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

Hi,

The original patch to fix this PR broke the if-conversion of calls into 
IFN_MASK_CALL.  This patch restores that original behaviour and makes 
sure the tests added earlier specifically test inbranch SIMD clones.

Bootstrapped and regression tested on aarch64-none-linux-gnu and 
x86_64-pc-linux-gnu.

Is this OK for trunk?

gcc/ChangeLog:

	PR tree-optimization/108888
	* tree-if-conv.cc (predicate_statements): Fix gimple call check.

gcc/testsuite/ChangeLog:

	* gcc.dg/vect/vect-simd-clone-16.c: Make simd clone inbranch only.
	* gcc.dg/vect/vect-simd-clone-17.c: Likewise.
	* gcc.dg/vect/vect-simd-clone-18.c: Likewise.

On 23/02/2023 10:10, Richard Biener via Gcc-patches wrote:
> The following makes sure to only predicate calls necessary.
> 
> Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.
> 
> 	PR tree-optimization/108888
> 	* tree-if-conv.cc (if_convertible_stmt_p): Set PLF_2 on
> 	calls to predicate.
> 	(predicate_statements): Only predicate calls with PLF_2.
> 
> 	* g++.dg/torture/pr108888.C: New testcase.
> ---
>   gcc/testsuite/g++.dg/torture/pr108888.C | 18 ++++++++++++++++++
>   gcc/tree-if-conv.cc                     | 17 ++++++++++-------
>   2 files changed, 28 insertions(+), 7 deletions(-)
>   create mode 100644 gcc/testsuite/g++.dg/torture/pr108888.C
> 
> diff --git a/gcc/testsuite/g++.dg/torture/pr108888.C b/gcc/testsuite/g++.dg/torture/pr108888.C
> new file mode 100644
> index 00000000000..29a22e21102
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/torture/pr108888.C
> @@ -0,0 +1,18 @@
> +// { dg-do compile }
> +
> +int scaleValueSaturate_scalefactor, scaleValueSaturate___trans_tmp_2,
> +    scaleValuesSaturate_i;
> +int scaleValueSaturate(int value) {
> +  int result = __builtin_clz(value);
> +  if (value)
> +    if (-result <= scaleValueSaturate_scalefactor)
> +      return 0;
> +  return scaleValueSaturate___trans_tmp_2;
> +}
> +short scaleValuesSaturate_dst;
> +short *scaleValuesSaturate_src;
> +void scaleValuesSaturate() {
> +  for (; scaleValuesSaturate_i; scaleValuesSaturate_i++)
> +    scaleValuesSaturate_dst =
> +        scaleValueSaturate(scaleValuesSaturate_src[scaleValuesSaturate_i]);
> +}
> diff --git a/gcc/tree-if-conv.cc b/gcc/tree-if-conv.cc
> index a7a8406374d..0e384e36394 100644
> --- a/gcc/tree-if-conv.cc
> +++ b/gcc/tree-if-conv.cc
> @@ -1099,6 +1099,7 @@ if_convertible_stmt_p (gimple *stmt, vec<data_reference_p> refs)
>   		   n = n->simdclone->next_clone)
>   		if (n->simdclone->inbranch)
>   		  {
> +		    gimple_set_plf (stmt, GF_PLF_2, true);
>   		    need_to_predicate = true;
>   		    return true;
>   		  }
> @@ -2541,7 +2542,8 @@ predicate_statements (loop_p loop)
>   	      release_defs (stmt);
>   	      continue;
>   	    }
> -	  else if (gimple_plf (stmt, GF_PLF_2))
> +	  else if (gimple_plf (stmt, GF_PLF_2)
> +		   && is_gimple_assign (stmt))
>   	    {
>   	      tree lhs = gimple_assign_lhs (stmt);
>   	      tree mask;
> @@ -2625,13 +2627,14 @@ predicate_statements (loop_p loop)
>   	      gimple_assign_set_rhs1 (stmt, ifc_temp_var (type, rhs, &gsi));
>   	      update_stmt (stmt);
>   	    }
> -
> -	  /* Convert functions that have a SIMD clone to IFN_MASK_CALL.  This
> -	     will cause the vectorizer to match the "in branch" clone variants,
> -	     and serves to build the mask vector in a natural way.  */
> -	  gcall *call = dyn_cast <gcall *> (gsi_stmt (gsi));
> -	  if (call && !gimple_call_internal_p (call))
> +	  else if (gimple_plf (stmt, GF_PLF_2)
> +		   && is_gimple_call (stmt))
>   	    {
> +	      /* Convert functions that have a SIMD clone to IFN_MASK_CALL.
> +		 This will cause the vectorizer to match the "in branch"
> +		 clone variants, and serves to build the mask vector
> +		 in a natural way.  */
> +	      gcall *call = dyn_cast <gcall *> (gsi_stmt (gsi));
>   	      tree orig_fn = gimple_call_fn (call);
>   	      int orig_nargs = gimple_call_num_args (call);
>   	      auto_vec<tree> args;

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

diff --git a/gcc/testsuite/gcc.dg/vect/vect-simd-clone-16.c b/gcc/testsuite/gcc.dg/vect/vect-simd-clone-16.c
index 3ff1cfee05951609d8ca93291d5d7c47cb07ec0d..125ff4f6c8d7df5e289187e523d32e0d12db9769 100644
--- a/gcc/testsuite/gcc.dg/vect/vect-simd-clone-16.c
+++ b/gcc/testsuite/gcc.dg/vect/vect-simd-clone-16.c
@@ -9,7 +9,7 @@
 #endif
 
 /* A simple function that will be cloned.  */
-#pragma omp declare simd
+#pragma omp declare simd inbranch
 TYPE __attribute__((noinline))
 foo (TYPE a)
 {
diff --git a/gcc/testsuite/gcc.dg/vect/vect-simd-clone-17.c b/gcc/testsuite/gcc.dg/vect/vect-simd-clone-17.c
index 803e0f25d45c1069633486c7b7d805638db83482..3430d6f5aa4f3ae3ed8bdfda80ef99d5517f15c6 100644
--- a/gcc/testsuite/gcc.dg/vect/vect-simd-clone-17.c
+++ b/gcc/testsuite/gcc.dg/vect/vect-simd-clone-17.c
@@ -9,7 +9,7 @@
 #endif
 
 /* A simple function that will be cloned.  */
-#pragma omp declare simd uniform(b)
+#pragma omp declare simd inbranch uniform(b)
 TYPE __attribute__((noinline))
 foo (TYPE a, TYPE b)
 {
diff --git a/gcc/testsuite/gcc.dg/vect/vect-simd-clone-18.c b/gcc/testsuite/gcc.dg/vect/vect-simd-clone-18.c
index 81b478c0206b6c74d59de8c51fd728428a9d8098..5324aee29c3173826057288d1604b5fe6de83c1e 100644
--- a/gcc/testsuite/gcc.dg/vect/vect-simd-clone-18.c
+++ b/gcc/testsuite/gcc.dg/vect/vect-simd-clone-18.c
@@ -9,7 +9,7 @@
 #endif
 
 /* A simple function that will be cloned.  */
-#pragma omp declare simd uniform(b)
+#pragma omp declare simd inbranch uniform(b)
 TYPE __attribute__((noinline))
 foo (TYPE b, TYPE a)
 {
diff --git a/gcc/tree-if-conv.cc b/gcc/tree-if-conv.cc
index 3494dccfe624a2cfb453db55a2de0616a134544a..7b21b16ff484f01caa7eefca0d74c54b8abba244 100644
--- a/gcc/tree-if-conv.cc
+++ b/gcc/tree-if-conv.cc
@@ -2641,8 +2641,9 @@ predicate_statements (loop_p loop)
 	      gimple_assign_set_rhs1 (stmt, ifc_temp_var (type, rhs, &gsi));
 	      update_stmt (stmt);
 	    }
-	  else if (gimple_plf (stmt, GF_PLF_2)
-		   && is_gimple_call (stmt))
+
+	  if (gimple_plf (gsi_stmt (gsi), GF_PLF_2)
+	      && is_gimple_call (gsi_stmt (gsi)))
 	    {
 	      /* Convert functions that have a SIMD clone to IFN_MASK_CALL.
 		 This will cause the vectorizer to match the "in branch"

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

* Re: [PATCH] tree-optimization/108888 - call if-conversion
  2023-04-05  9:07 ` Andre Vieira (lists)
@ 2023-04-11  8:48   ` Richard Biener
  0 siblings, 0 replies; 3+ messages in thread
From: Richard Biener @ 2023-04-11  8:48 UTC (permalink / raw)
  To: Andre Vieira (lists); +Cc: gcc-patches, ams

On Wed, 5 Apr 2023, Andre Vieira (lists) wrote:

> Hi,
> 
> The original patch to fix this PR broke the if-conversion of calls into
> IFN_MASK_CALL.  This patch restores that original behaviour and makes sure the
> tests added earlier specifically test inbranch SIMD clones.

OOps.

> Bootstrapped and regression tested on aarch64-none-linux-gnu and
> x86_64-pc-linux-gnu.
> 
> Is this OK for trunk?

OK.

Thanks,
Richard.

> gcc/ChangeLog:
> 
> 	PR tree-optimization/108888
> 	* tree-if-conv.cc (predicate_statements): Fix gimple call check.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* gcc.dg/vect/vect-simd-clone-16.c: Make simd clone inbranch only.
> 	* gcc.dg/vect/vect-simd-clone-17.c: Likewise.
> 	* gcc.dg/vect/vect-simd-clone-18.c: Likewise.
> 
> On 23/02/2023 10:10, Richard Biener via Gcc-patches wrote:
> > The following makes sure to only predicate calls necessary.
> > 
> > Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.
> > 
> >  PR tree-optimization/108888
> >  * tree-if-conv.cc (if_convertible_stmt_p): Set PLF_2 on
> >  calls to predicate.
> >  (predicate_statements): Only predicate calls with PLF_2.
> > 
> > 	* g++.dg/torture/pr108888.C: New testcase.
> > ---
> >   gcc/testsuite/g++.dg/torture/pr108888.C | 18 ++++++++++++++++++
> >   gcc/tree-if-conv.cc                     | 17 ++++++++++-------
> >   2 files changed, 28 insertions(+), 7 deletions(-)
> >   create mode 100644 gcc/testsuite/g++.dg/torture/pr108888.C
> > 
> > diff --git a/gcc/testsuite/g++.dg/torture/pr108888.C
> > b/gcc/testsuite/g++.dg/torture/pr108888.C
> > new file mode 100644
> > index 00000000000..29a22e21102
> > --- /dev/null
> > +++ b/gcc/testsuite/g++.dg/torture/pr108888.C
> > @@ -0,0 +1,18 @@
> > +// { dg-do compile }
> > +
> > +int scaleValueSaturate_scalefactor, scaleValueSaturate___trans_tmp_2,
> > +    scaleValuesSaturate_i;
> > +int scaleValueSaturate(int value) {
> > +  int result = __builtin_clz(value);
> > +  if (value)
> > +    if (-result <= scaleValueSaturate_scalefactor)
> > +      return 0;
> > +  return scaleValueSaturate___trans_tmp_2;
> > +}
> > +short scaleValuesSaturate_dst;
> > +short *scaleValuesSaturate_src;
> > +void scaleValuesSaturate() {
> > +  for (; scaleValuesSaturate_i; scaleValuesSaturate_i++)
> > +    scaleValuesSaturate_dst =
> > +        scaleValueSaturate(scaleValuesSaturate_src[scaleValuesSaturate_i]);
> > +}
> > diff --git a/gcc/tree-if-conv.cc b/gcc/tree-if-conv.cc
> > index a7a8406374d..0e384e36394 100644
> > --- a/gcc/tree-if-conv.cc
> > +++ b/gcc/tree-if-conv.cc
> > @@ -1099,6 +1099,7 @@ if_convertible_stmt_p (gimple *stmt,
> > vec<data_reference_p> refs)
> >        n = n->simdclone->next_clone)
> >     if (n->simdclone->inbranch)
> >   		  {
> > +		    gimple_set_plf (stmt, GF_PLF_2, true);
> >         need_to_predicate = true;
> >         return true;
> >   		  }
> > @@ -2541,7 +2542,8 @@ predicate_statements (loop_p loop)
> >          release_defs (stmt);
> >          continue;
> >   	    }
> > -	  else if (gimple_plf (stmt, GF_PLF_2))
> > +	  else if (gimple_plf (stmt, GF_PLF_2)
> > +		   && is_gimple_assign (stmt))
> >        {
> >          tree lhs = gimple_assign_lhs (stmt);
> >          tree mask;
> > @@ -2625,13 +2627,14 @@ predicate_statements (loop_p loop)
> >          gimple_assign_set_rhs1 (stmt, ifc_temp_var (type, rhs, &gsi));
> >          update_stmt (stmt);
> >   	    }
> > -
> > -	  /* Convert functions that have a SIMD clone to IFN_MASK_CALL.  This
> > -	     will cause the vectorizer to match the "in branch" clone
> > variants,
> > -	     and serves to build the mask vector in a natural way.  */
> > -	  gcall *call = dyn_cast <gcall *> (gsi_stmt (gsi));
> > -	  if (call && !gimple_call_internal_p (call))
> > +	  else if (gimple_plf (stmt, GF_PLF_2)
> > +		   && is_gimple_call (stmt))
> >   	    {
> > +	      /* Convert functions that have a SIMD clone to IFN_MASK_CALL.
> > +		 This will cause the vectorizer to match the "in branch"
> > +		 clone variants, and serves to build the mask vector
> > +		 in a natural way.  */
> > +	      gcall *call = dyn_cast <gcall *> (gsi_stmt (gsi));
> >          tree orig_fn = gimple_call_fn (call);
> >          int orig_nargs = gimple_call_num_args (call);
> >          auto_vec<tree> args;
> 

-- 
Richard Biener <rguenther@suse.de>
SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg,
Germany; GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman;
HRB 36809 (AG Nuernberg)

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

end of thread, other threads:[~2023-04-11  8:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-23 10:10 [PATCH] tree-optimization/108888 - call if-conversion Richard Biener
2023-04-05  9:07 ` Andre Vieira (lists)
2023-04-11  8:48   ` 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).