public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] tree-optimization/101159 - fix missing NULL check in popcount pattern
@ 2021-06-22  9:00 Richard Biener
  2021-06-22 13:04 ` [PATCH] testsuite: Add testcase for recently fixed PR [PR101159] Jakub Jelinek
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Biener @ 2021-06-22  9:00 UTC (permalink / raw)
  To: gcc-patches

This fixes a missing check for a NULL vectype in the new popcount
pattern.

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

2021-06-22  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/101159
	* tree-vect-patterns.c (vect_recog_popcount_pattern): Add
	missing NULL vectype check.
---
 gcc/tree-vect-patterns.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/gcc/tree-vect-patterns.c b/gcc/tree-vect-patterns.c
index 59727056dc7..d0a5c71dbe4 100644
--- a/gcc/tree-vect-patterns.c
+++ b/gcc/tree-vect-patterns.c
@@ -1385,9 +1385,9 @@ vect_recog_popcount_pattern (vec_info *vinfo,
   vect_pattern_detected ("vec_regcog_popcount_pattern", popcount_stmt);
   vec_type = get_vectype_for_scalar_type (vinfo, lhs_type);
   /* Do it only the backend existed popcount<vector_mode>2.  */
-  if (!direct_internal_fn_supported_p (IFN_POPCOUNT,
-				       vec_type,
-				       OPTIMIZE_FOR_SPEED))
+  if (!vec_type
+      || !direct_internal_fn_supported_p (IFN_POPCOUNT, vec_type,
+					  OPTIMIZE_FOR_SPEED))
     return NULL;
 
   /* Create B = .POPCOUNT (A).  */
-- 
2.26.2

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

* [PATCH] testsuite: Add testcase for recently fixed PR [PR101159]
  2021-06-22  9:00 [PATCH] tree-optimization/101159 - fix missing NULL check in popcount pattern Richard Biener
@ 2021-06-22 13:04 ` Jakub Jelinek
  2021-06-22 13:15   ` Richard Biener
  0 siblings, 1 reply; 3+ messages in thread
From: Jakub Jelinek @ 2021-06-22 13:04 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc-patches

On Tue, Jun 22, 2021 at 11:00:51AM +0200, Richard Biener wrote:
> 2021-06-22  Richard Biener  <rguenther@suse.de>
> 
> 	PR tree-optimization/101159
> 	* tree-vect-patterns.c (vect_recog_popcount_pattern): Add
> 	missing NULL vectype check.

The following patch adds the testcase for it, IMHO it can't hurt and
from my experience testcases often trigger other bugs later on (rather
than the original bugs reappearing, though even that happens),
and also fixes a couple of typos in the new function.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2021-06-22  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/101159
	* tree-vect-patterns.c (vect_recog_widen_minus_pattern): Fix some
	comment typos.

	* gcc.c-torture/compile/pr101159.c: New test.

--- gcc/tree-vect-patterns.c.jj	2021-06-22 12:19:09.168846556 +0200
+++ gcc/tree-vect-patterns.c	2021-06-22 12:41:35.334932438 +0200
@@ -1300,7 +1300,7 @@ vect_recog_widen_minus_pattern (vec_info
    TYPE1 B;
    UTYPE2 temp_in;
    TYPE3 temp_out;
-   temp_in = (TYPE2)A;
+   temp_in = (UTYPE2)A;
 
    temp_out = __builtin_popcount{,l,ll} (temp_in);
    B = (TYPE1) temp_out;
@@ -1372,8 +1372,8 @@ vect_recog_popcount_pattern (vec_info *v
   if (!rhs_origin)
     return NULL;
 
-  /* Input and outout of .POPCOUNT should be same-precision integer.
-     Also A should be unsigned or same presion as temp_in,
+  /* Input and output of .POPCOUNT should be same-precision integer.
+     Also A should be unsigned or same precision as temp_in,
      otherwise there would be sign_extend from A to temp_in.  */
   if (TYPE_PRECISION (unprom_diff.type) != TYPE_PRECISION (lhs_type)
       || (!TYPE_UNSIGNED (unprom_diff.type)
@@ -1384,7 +1384,7 @@ vect_recog_popcount_pattern (vec_info *v
 
   vect_pattern_detected ("vec_regcog_popcount_pattern", popcount_stmt);
   vec_type = get_vectype_for_scalar_type (vinfo, lhs_type);
-  /* Do it only the backend existed popcount<vector_mode>2.  */
+  /* Do it only if the backend has popcount<vector_mode>2 pattern.  */
   if (!vec_type
       || !direct_internal_fn_supported_p (IFN_POPCOUNT, vec_type,
 					  OPTIMIZE_FOR_SPEED))
--- gcc/testsuite/gcc.c-torture/compile/pr101159.c.jj	2021-06-22 12:41:54.742665843 +0200
+++ gcc/testsuite/gcc.c-torture/compile/pr101159.c	2021-06-22 12:38:15.267680653 +0200
@@ -0,0 +1,10 @@
+/* PR tree-optimization/101159 */
+
+unsigned long a;
+long b;
+
+void
+foo (void)
+{
+  a += __builtin_popcountl (b);
+}


	Jakub


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

* Re: [PATCH] testsuite: Add testcase for recently fixed PR [PR101159]
  2021-06-22 13:04 ` [PATCH] testsuite: Add testcase for recently fixed PR [PR101159] Jakub Jelinek
@ 2021-06-22 13:15   ` Richard Biener
  0 siblings, 0 replies; 3+ messages in thread
From: Richard Biener @ 2021-06-22 13:15 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches

On Tue, 22 Jun 2021, Jakub Jelinek wrote:

> On Tue, Jun 22, 2021 at 11:00:51AM +0200, Richard Biener wrote:
> > 2021-06-22  Richard Biener  <rguenther@suse.de>
> > 
> > 	PR tree-optimization/101159
> > 	* tree-vect-patterns.c (vect_recog_popcount_pattern): Add
> > 	missing NULL vectype check.
> 
> The following patch adds the testcase for it, IMHO it can't hurt and
> from my experience testcases often trigger other bugs later on (rather
> than the original bugs reappearing, though even that happens),
> and also fixes a couple of typos in the new function.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

OK.

> 2021-06-22  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR tree-optimization/101159
> 	* tree-vect-patterns.c (vect_recog_widen_minus_pattern): Fix some
> 	comment typos.
> 
> 	* gcc.c-torture/compile/pr101159.c: New test.
> 
> --- gcc/tree-vect-patterns.c.jj	2021-06-22 12:19:09.168846556 +0200
> +++ gcc/tree-vect-patterns.c	2021-06-22 12:41:35.334932438 +0200
> @@ -1300,7 +1300,7 @@ vect_recog_widen_minus_pattern (vec_info
>     TYPE1 B;
>     UTYPE2 temp_in;
>     TYPE3 temp_out;
> -   temp_in = (TYPE2)A;
> +   temp_in = (UTYPE2)A;
>  
>     temp_out = __builtin_popcount{,l,ll} (temp_in);
>     B = (TYPE1) temp_out;
> @@ -1372,8 +1372,8 @@ vect_recog_popcount_pattern (vec_info *v
>    if (!rhs_origin)
>      return NULL;
>  
> -  /* Input and outout of .POPCOUNT should be same-precision integer.
> -     Also A should be unsigned or same presion as temp_in,
> +  /* Input and output of .POPCOUNT should be same-precision integer.
> +     Also A should be unsigned or same precision as temp_in,
>       otherwise there would be sign_extend from A to temp_in.  */
>    if (TYPE_PRECISION (unprom_diff.type) != TYPE_PRECISION (lhs_type)
>        || (!TYPE_UNSIGNED (unprom_diff.type)
> @@ -1384,7 +1384,7 @@ vect_recog_popcount_pattern (vec_info *v
>  
>    vect_pattern_detected ("vec_regcog_popcount_pattern", popcount_stmt);
>    vec_type = get_vectype_for_scalar_type (vinfo, lhs_type);
> -  /* Do it only the backend existed popcount<vector_mode>2.  */
> +  /* Do it only if the backend has popcount<vector_mode>2 pattern.  */
>    if (!vec_type
>        || !direct_internal_fn_supported_p (IFN_POPCOUNT, vec_type,
>  					  OPTIMIZE_FOR_SPEED))
> --- gcc/testsuite/gcc.c-torture/compile/pr101159.c.jj	2021-06-22 12:41:54.742665843 +0200
> +++ gcc/testsuite/gcc.c-torture/compile/pr101159.c	2021-06-22 12:38:15.267680653 +0200
> @@ -0,0 +1,10 @@
> +/* PR tree-optimization/101159 */
> +
> +unsigned long a;
> +long b;
> +
> +void
> +foo (void)
> +{
> +  a += __builtin_popcountl (b);
> +}
> 
> 
> 	Jakub
> 
> 

-- 
Richard Biener <rguenther@suse.de>
SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 Nuernberg,
Germany; GF: Felix Imendörffer; HRB 36809 (AG Nuernberg)

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

end of thread, other threads:[~2021-06-22 13:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-22  9:00 [PATCH] tree-optimization/101159 - fix missing NULL check in popcount pattern Richard Biener
2021-06-22 13:04 ` [PATCH] testsuite: Add testcase for recently fixed PR [PR101159] Jakub Jelinek
2021-06-22 13:15   ` 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).