diff mbox

Don't try to perform conditional_replacement on vectors (PR tree-optimization/53748)

Message ID 20120625144459.GE20264@tucnak.redhat.com
State New
Headers show

Commit Message

Jakub Jelinek June 25, 2012, 2:44 p.m. UTC
Hi!

On vectors, even when they satisfy
integer_zerop/integer_onep/integer_all_onesp, the routine doesn't
handle vector types and it is questionable if it would be a good
optimization for them anyway.  We don't handle complex there either,
so this patch limits it to integral/pointer types.

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

2012-06-25  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/53748
	* tree-ssa-phiopt.c (conditional_replacement): Only optimize
	if arg0/arg1 have integral or pointer types.

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


	Jakub

Comments

Richard Biener June 26, 2012, 7:56 a.m. UTC | #1
On Mon, 25 Jun 2012, Jakub Jelinek wrote:

> Hi!
> 
> On vectors, even when they satisfy
> integer_zerop/integer_onep/integer_all_onesp, the routine doesn't
> handle vector types and it is questionable if it would be a good
> optimization for them anyway.  We don't handle complex there either,
> so this patch limits it to integral/pointer types.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

Ok.

Thanks,
Richard.

> 2012-06-25  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR tree-optimization/53748
> 	* tree-ssa-phiopt.c (conditional_replacement): Only optimize
> 	if arg0/arg1 have integral or pointer types.
> 
> 	* gcc.c-torture/compile/pr53748.c: New test.
> 
> --- gcc/tree-ssa-phiopt.c.jj	2012-06-25 08:38:26.000000000 +0200
> +++ gcc/tree-ssa-phiopt.c	2012-06-25 12:10:23.473357828 +0200
> @@ -615,8 +615,12 @@ conditional_replacement (basic_block con
>    bool neg;
>  
>    /* FIXME: Gimplification of complex type is too hard for now.  */
> -  if (TREE_CODE (TREE_TYPE (arg0)) == COMPLEX_TYPE
> -      || TREE_CODE (TREE_TYPE (arg1)) == COMPLEX_TYPE)
> +  /* We aren't prepared to handle vectors either (and it is a question
> +     if it would be worthwhile anyway).  */
> +  if (!(INTEGRAL_TYPE_P (TREE_TYPE (arg0))
> +	|| POINTER_TYPE_P (TREE_TYPE (arg0)))
> +      || !(INTEGRAL_TYPE_P (TREE_TYPE (arg1))
> +	   || POINTER_TYPE_P (TREE_TYPE (arg1))))
>      return false;
>  
>    /* The PHI arguments have the constants 0 and 1, or 0 and -1, then
> --- gcc/testsuite/gcc.c-torture/compile/pr53748.c.jj	2012-06-25 11:54:15.959820372 +0200
> +++ gcc/testsuite/gcc.c-torture/compile/pr53748.c	2012-06-25 11:43:35.000000000 +0200
> @@ -0,0 +1,9 @@
> +/* PR tree-optimization/53748 */
> +
> +typedef unsigned int V __attribute__ ((__vector_size__ (sizeof (int) * 4)));
> +
> +void
> +foo (int x, V *y)
> +{
> +  *y = x ? ((V) { ~0U, ~0U, ~0U, ~0U }) : ((V) { 0, 0, 0, 0 });
> +}
> 
> 	Jakub
> 
>
Paolo Bonzini July 1, 2012, 1:54 p.m. UTC | #2
Il 25/06/2012 16:44, Jakub Jelinek ha scritto:
> Hi!
> 
> On vectors, even when they satisfy
> integer_zerop/integer_onep/integer_all_onesp, the routine doesn't
> handle vector types and it is questionable if it would be a good
> optimization for them anyway.

I think it's not questionable at all, since creating such masks is
exactly what vector comparison instructions do.  But anyway that would
be a separate patch.  Thanks for the fix!

Paolo
diff mbox

Patch

--- gcc/tree-ssa-phiopt.c.jj	2012-06-25 08:38:26.000000000 +0200
+++ gcc/tree-ssa-phiopt.c	2012-06-25 12:10:23.473357828 +0200
@@ -615,8 +615,12 @@  conditional_replacement (basic_block con
   bool neg;
 
   /* FIXME: Gimplification of complex type is too hard for now.  */
-  if (TREE_CODE (TREE_TYPE (arg0)) == COMPLEX_TYPE
-      || TREE_CODE (TREE_TYPE (arg1)) == COMPLEX_TYPE)
+  /* We aren't prepared to handle vectors either (and it is a question
+     if it would be worthwhile anyway).  */
+  if (!(INTEGRAL_TYPE_P (TREE_TYPE (arg0))
+	|| POINTER_TYPE_P (TREE_TYPE (arg0)))
+      || !(INTEGRAL_TYPE_P (TREE_TYPE (arg1))
+	   || POINTER_TYPE_P (TREE_TYPE (arg1))))
     return false;
 
   /* The PHI arguments have the constants 0 and 1, or 0 and -1, then
--- gcc/testsuite/gcc.c-torture/compile/pr53748.c.jj	2012-06-25 11:54:15.959820372 +0200
+++ gcc/testsuite/gcc.c-torture/compile/pr53748.c	2012-06-25 11:43:35.000000000 +0200
@@ -0,0 +1,9 @@ 
+/* PR tree-optimization/53748 */
+
+typedef unsigned int V __attribute__ ((__vector_size__ (sizeof (int) * 4)));
+
+void
+foo (int x, V *y)
+{
+  *y = x ? ((V) { ~0U, ~0U, ~0U, ~0U }) : ((V) { 0, 0, 0, 0 });
+}