public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH]middle-end slp: check that the operation we're combing is a boolean operation [PR103741]
@ 2021-12-17 10:04 Tamar Christina
  2021-12-17 10:54 ` Richard Sandiford
  0 siblings, 1 reply; 2+ messages in thread
From: Tamar Christina @ 2021-12-17 10:04 UTC (permalink / raw)
  To: gcc-patches; +Cc: nd, richard.sandiford

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

Hi All,

It seems I forgot to check that the operation we're combing when masking the
predicated together are actually predicates types.

Without it we end up accidentally trying to combine a value and a mask.

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

Ok for master?

Thanks,
Tamar

gcc/ChangeLog:

	PR tree-optimization/103741
	* tree-vect-stmts.c (vectorizable_operation): Check for boolean.

gcc/testsuite/ChangeLog:

	PR tree-optimization/103741
	* gcc.target/aarch64/pr103741.c: New test.

--- inline copy of patch -- 
diff --git a/gcc/testsuite/gcc.target/aarch64/pr103741.c b/gcc/testsuite/gcc.target/aarch64/pr103741.c
new file mode 100644
index 0000000000000000000000000000000000000000..ef3ae66ebe5e5a44e7bea7be22b6378bc23cc538
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/pr103741.c
@@ -0,0 +1,26 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-march=armv8-a+sve -O1" } */
+
+long int m, n;
+
+int
+qux (int z)
+{
+  return 4 >> z ? z : 0;
+}
+
+int
+bar (long int y)
+{
+  return y ? 3 : 2;
+}
+
+__attribute__ ((simd)) int
+foo (int x)
+{
+  long int a = x & m;
+  int b = bar (x) / n;
+
+  return qux (b) == a;
+}
+
diff --git a/gcc/tree-vect-stmts.c b/gcc/tree-vect-stmts.c
index 8c427174b37e6c03c2f914c90332bcc4eac54130..ad90cdb0473a337207d6ba54c1dd0a2ecc50ab8d 100644
--- a/gcc/tree-vect-stmts.c
+++ b/gcc/tree-vect-stmts.c
@@ -6361,7 +6361,9 @@ vectorizable_operation (vec_info *vinfo,
 	  /* When combining two masks check if either of them is elsewhere
 	     combined with a loop mask, if that's the case we can mark that the
 	     new combined mask doesn't need to be combined with a loop mask.  */
-	  if (masked_loop_p && code == BIT_AND_EXPR)
+	  if (masked_loop_p
+	      && code == BIT_AND_EXPR
+	      && VECTOR_BOOLEAN_TYPE_P (vectype))
 	    {
 	      if (loop_vinfo->scalar_cond_masked_set.contains ({ op0,
 								 ncopies}))


-- 

[-- Attachment #2: rb15162.patch --]
[-- Type: text/x-diff, Size: 1354 bytes --]

diff --git a/gcc/testsuite/gcc.target/aarch64/pr103741.c b/gcc/testsuite/gcc.target/aarch64/pr103741.c
new file mode 100644
index 0000000000000000000000000000000000000000..ef3ae66ebe5e5a44e7bea7be22b6378bc23cc538
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/pr103741.c
@@ -0,0 +1,26 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-march=armv8-a+sve -O1" } */
+
+long int m, n;
+
+int
+qux (int z)
+{
+  return 4 >> z ? z : 0;
+}
+
+int
+bar (long int y)
+{
+  return y ? 3 : 2;
+}
+
+__attribute__ ((simd)) int
+foo (int x)
+{
+  long int a = x & m;
+  int b = bar (x) / n;
+
+  return qux (b) == a;
+}
+
diff --git a/gcc/tree-vect-stmts.c b/gcc/tree-vect-stmts.c
index 8c427174b37e6c03c2f914c90332bcc4eac54130..ad90cdb0473a337207d6ba54c1dd0a2ecc50ab8d 100644
--- a/gcc/tree-vect-stmts.c
+++ b/gcc/tree-vect-stmts.c
@@ -6361,7 +6361,9 @@ vectorizable_operation (vec_info *vinfo,
 	  /* When combining two masks check if either of them is elsewhere
 	     combined with a loop mask, if that's the case we can mark that the
 	     new combined mask doesn't need to be combined with a loop mask.  */
-	  if (masked_loop_p && code == BIT_AND_EXPR)
+	  if (masked_loop_p
+	      && code == BIT_AND_EXPR
+	      && VECTOR_BOOLEAN_TYPE_P (vectype))
 	    {
 	      if (loop_vinfo->scalar_cond_masked_set.contains ({ op0,
 								 ncopies}))


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

* Re: [PATCH]middle-end slp: check that the operation we're combing is a boolean operation [PR103741]
  2021-12-17 10:04 [PATCH]middle-end slp: check that the operation we're combing is a boolean operation [PR103741] Tamar Christina
@ 2021-12-17 10:54 ` Richard Sandiford
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Sandiford @ 2021-12-17 10:54 UTC (permalink / raw)
  To: Tamar Christina; +Cc: gcc-patches, nd

Tamar Christina <tamar.christina@arm.com> writes:
> Hi All,
>
> It seems I forgot to check that the operation we're combing when masking the
> predicated together are actually predicates types.
>
> Without it we end up accidentally trying to combine a value and a mask.
>
> Bootstrapped Regtested on aarch64-none-linux-gnu and no issues.
>
> Ok for master?
>
> Thanks,
> Tamar
>
> gcc/ChangeLog:
>
> 	PR tree-optimization/103741
> 	* tree-vect-stmts.c (vectorizable_operation): Check for boolean.
>
> gcc/testsuite/ChangeLog:
>
> 	PR tree-optimization/103741
> 	* gcc.target/aarch64/pr103741.c: New test.
>
> --- inline copy of patch -- 
> diff --git a/gcc/testsuite/gcc.target/aarch64/pr103741.c b/gcc/testsuite/gcc.target/aarch64/pr103741.c
> new file mode 100644
> index 0000000000000000000000000000000000000000..ef3ae66ebe5e5a44e7bea7be22b6378bc23cc538
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/aarch64/pr103741.c
> @@ -0,0 +1,26 @@
> +/* { dg-do compile } */
> +/* { dg-additional-options "-march=armv8-a+sve -O1" } */
> +
> +long int m, n;
> +
> +int
> +qux (int z)
> +{
> +  return 4 >> z ? z : 0;
> +}
> +
> +int
> +bar (long int y)
> +{
> +  return y ? 3 : 2;
> +}
> +
> +__attribute__ ((simd)) int
> +foo (int x)
> +{
> +  long int a = x & m;
> +  int b = bar (x) / n;
> +
> +  return qux (b) == a;
> +}
> +
> diff --git a/gcc/tree-vect-stmts.c b/gcc/tree-vect-stmts.c
> index 8c427174b37e6c03c2f914c90332bcc4eac54130..ad90cdb0473a337207d6ba54c1dd0a2ecc50ab8d 100644
> --- a/gcc/tree-vect-stmts.c
> +++ b/gcc/tree-vect-stmts.c
> @@ -6361,7 +6361,9 @@ vectorizable_operation (vec_info *vinfo,
>  	  /* When combining two masks check if either of them is elsewhere
>  	     combined with a loop mask, if that's the case we can mark that the
>  	     new combined mask doesn't need to be combined with a loop mask.  */
> -	  if (masked_loop_p && code == BIT_AND_EXPR)
> +	  if (masked_loop_p
> +	      && code == BIT_AND_EXPR
> +	      && VECTOR_BOOLEAN_TYPE_P (vectype))
>  	    {
>  	      if (loop_vinfo->scalar_cond_masked_set.contains ({ op0,
>  								 ncopies}))

Ah, so the reason that scalar_cond_masked_set.contains is not robust
against non-boolean op0 (despite looking like it might be) is that
we previously entered:

  cmp = X != 0

into the set as <X, !=, 0>.  Then looking up X implicitly becomes
<X, !=, 0> too.

So yeah, the patch is OK, thanks.

Richard

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

end of thread, other threads:[~2021-12-17 10:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-17 10:04 [PATCH]middle-end slp: check that the operation we're combing is a boolean operation [PR103741] Tamar Christina
2021-12-17 10:54 ` Richard Sandiford

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