This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Fold {2, 3, 4, 5} >> 31
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Marc Glisse <marc dot glisse at inria dot fr>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Thu, 11 Apr 2013 18:29:53 +0200
- Subject: Re: Fold {2, 3, 4, 5} >> 31
- References: <alpine dot DEB dot 2 dot 02 dot 1304111812580 dot 27055 at stedding dot saclay dot inria dot fr>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Thu, Apr 11, 2013 at 06:24:02PM +0200, Marc Glisse wrote:
> here is a patch to handle constant folding of mixed vector-integer
> operations. I could have shared the loop with the vector-vector
> case, but that would have meant re-testing if arg2 was a vector at
> every iteration (I can go back to that version if you prefer).
Yeah, that is the kind of thinking I had too.
> + /* Shifts allow a scalar offset for a vector. */
> + if (TREE_CODE (arg1) == VECTOR_CST)
I'd prefer && TREE_CODE (arg2) == INTEGER_CST added to the condition
here.
> + {
> + tree type = TREE_TYPE (arg1);
> + int count = TYPE_VECTOR_SUBPARTS (type), i;
> + tree *elts = XALLOCAVEC (tree, count);
Please use just one space.
> +
> + for (i = 0; i < count; i++)
> + {
> + tree elem1 = VECTOR_CST_ELT (arg1, i);
> +
> + elts[i] = const_binop (code, elem1, arg2);
> +
> + /* It is possible that const_binop cannot handle the given
> + code and return NULL_TREE */
> + if (elts[i] == NULL_TREE)
> return NULL_TREE;
And please use tabs where possible, instead of 8 spaces.
> --- gcc/testsuite/gcc.dg/fold-cstvecshift.c (revision 0)
> +++ gcc/testsuite/gcc.dg/fold-cstvecshift.c (revision 0)
> @@ -0,0 +1,13 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O -fdump-tree-ccp1" } */
> +
> +typedef int vec __attribute__ ((vector_size (4 * sizeof (int))));
> +
> +void f (vec *r)
> +{
> + vec a = { 2, 3, 4, 5 };
> + *r = (a << 2) >> 1;
> +}
> +
> +/* { dg-final { scan-tree-dump "{ 4, 6, 8, 10 }" "ccp1"} } */
> +/* { dg-final { cleanup-tree-dump "ccp1" } } */
Have you tested the testcase say for -m32 -mno-sse too, to see
if it doesn't fail without HW vector support?
If so, the patch is ok with the above mentioned changes.
Jakub