(gimple) Allow integer return type from vector compares

Message ID 1507838577.26707.176.camel@brimstone.rchland.ibm.com
State New
Headers show
Series
  • (gimple) Allow integer return type from vector compares
Related show

Commit Message

Will Schmidt Oct. 12, 2017, 8:02 p.m.
Hi, 
    
Update the logic in verify_gimple_comparision to allow a vector integer result
from a vector comparison, where it previously was limited to only allowing
compares with boolean results.  This allows powerpc intrinsics such as this
one to build (after gimple folding):
   vector bool int vec_cmpeq (vector signed int, vector signed int);

This has been tested in conjunction with the "rs6000 GIMPLE folding for vector
compares" patch (posted separately) on p6 and newer.

OK for trunk?
    
Thanks,
-Will
    
[gcc]

2017-10-12  Will Schmidt  <will_schmidt@vnet.ibm.com>

	* gcc/tree-cfg.c: (@ verify_gimple_comparison ): allow boolean result
	from vector compares.

Comments

Richard Biener Oct. 13, 2017, 9:21 a.m. | #1
On Thu, Oct 12, 2017 at 10:02 PM, Will Schmidt
<will_schmidt@vnet.ibm.com> wrote:
> Hi,
>
> Update the logic in verify_gimple_comparision to allow a vector integer result
> from a vector comparison, where it previously was limited to only allowing
> compares with boolean results.  This allows powerpc intrinsics such as this
> one to build (after gimple folding):
>    vector bool int vec_cmpeq (vector signed int, vector signed int);
>
> This has been tested in conjunction with the "rs6000 GIMPLE folding for vector
> compares" patch (posted separately) on p6 and newer.
>
> OK for trunk?

Well.  It was this way before AVX512 introduced those vector boolean
types.  There
we decided to have comparisons always return a boolean vector.  Previously
there was an additional restriction in that the vector elements of the
boolean result
had to be the same size as the elements of the comparison operands.

You are now supposed to use the "canonical"

 _1 = _2 != _3 ? { your true value vector } : { your false value vector};

with a VEC_COND_EXPR.

Richard.

> Thanks,
> -Will
>
> [gcc]
>
> 2017-10-12  Will Schmidt  <will_schmidt@vnet.ibm.com>
>
>         * gcc/tree-cfg.c: (@ verify_gimple_comparison ): allow boolean result
>         from vector compares.
>
> diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c
> index b5e0460..adf3607 100644
> --- a/gcc/tree-cfg.c
> +++ b/gcc/tree-cfg.c
> @@ -3624,14 +3624,16 @@ verify_gimple_comparison (tree type, tree op0, tree op1, enum tree_code code)
>           debug_generic_expr (op0_type);
>           debug_generic_expr (op1_type);
>           return true;
>          }
>      }
> -  /* Or a boolean vector type with the same element count
> -     as the comparison operand types.  */
> +  /* Or a vector type with the same element count
> +     as the comparison operand types.  The vector type may
> +     be boolean or integer.  */
>    else if (TREE_CODE (type) == VECTOR_TYPE
> -          && TREE_CODE (TREE_TYPE (type)) == BOOLEAN_TYPE)
> +          && (( TREE_CODE (TREE_TYPE (type)) == BOOLEAN_TYPE)
> +          || ( TREE_CODE (TREE_TYPE (type)) == INTEGER_TYPE)))
>      {
>        if (TREE_CODE (op0_type) != VECTOR_TYPE
>           || TREE_CODE (op1_type) != VECTOR_TYPE)
>          {
>            error ("non-vector operands in vector comparison");
>
>

Patch

diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c
index b5e0460..adf3607 100644
--- a/gcc/tree-cfg.c
+++ b/gcc/tree-cfg.c
@@ -3624,14 +3624,16 @@  verify_gimple_comparison (tree type, tree op0, tree op1, enum tree_code code)
 	  debug_generic_expr (op0_type);
 	  debug_generic_expr (op1_type);
 	  return true;
         }
     }
-  /* Or a boolean vector type with the same element count
-     as the comparison operand types.  */
+  /* Or a vector type with the same element count
+     as the comparison operand types.  The vector type may
+     be boolean or integer.  */
   else if (TREE_CODE (type) == VECTOR_TYPE
-	   && TREE_CODE (TREE_TYPE (type)) == BOOLEAN_TYPE)
+	   && (( TREE_CODE (TREE_TYPE (type)) == BOOLEAN_TYPE)
+	   || ( TREE_CODE (TREE_TYPE (type)) == INTEGER_TYPE)))
     {
       if (TREE_CODE (op0_type) != VECTOR_TYPE
 	  || TREE_CODE (op1_type) != VECTOR_TYPE)
         {
           error ("non-vector operands in vector comparison");