On Fri, Dec 05, 2014 at 11:27:50AM +0100, Marek Polacek wrote:
> My recent change to shift operand promotion caused a regression in
> loop unrolling. Fixed as Richi suggested in the PR audit trail.
>
> Bootstrapped/regtested on ppc64-linux and x86_64-linux, ok for trunk?
>
> 2014-12-05 Marek Polacek <[email protected]>
>
> PR tree-optimization/64183
> * c-gimplify.c (c_gimplify_expr): Don't convert the RHS of a
> shift-expression if it is integer_type_node.
>
> * gcc.dg/tree-ssa/pr64183.c: New test.
This is for middle-end, so I think it would be better to use
the middle-end type equality in the checks, so !types_compatible_p
instead of != ?
> diff --git gcc/c-family/c-gimplify.c gcc/c-family/c-gimplify.c
> index 2cfa5d9..41a928c 100644
> --- gcc/c-family/c-gimplify.c
> +++ gcc/c-family/c-gimplify.c
> @@ -255,7 +255,8 @@ c_gimplify_expr (tree *expr_p, gimple_seq *pre_p
> ATTRIBUTE_UNUSED,
> type demotion/promotion pass. */
> tree *op1_p = &TREE_OPERAND (*expr_p, 1);
> if (TREE_CODE (TREE_TYPE (*op1_p)) != VECTOR_TYPE
> - && TYPE_MAIN_VARIANT (TREE_TYPE (*op1_p)) != unsigned_type_node)
> + && TYPE_MAIN_VARIANT (TREE_TYPE (*op1_p)) != unsigned_type_node
> + && TYPE_MAIN_VARIANT (TREE_TYPE (*op1_p)) != integer_type_node)
> *op1_p = convert (unsigned_type_node, *op1_p);
> break;
> }
> diff --git gcc/testsuite/gcc.dg/tree-ssa/pr64183.c
> gcc/testsuite/gcc.dg/tree-ssa/pr64183.c
> index e69de29..0563739 100644
> --- gcc/testsuite/gcc.dg/tree-ssa/pr64183.c
> +++ gcc/testsuite/gcc.dg/tree-ssa/pr64183.c
> @@ -0,0 +1,21 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O3 -fdump-tree-cunroll-details" } */
> +
> +int bits;
> +unsigned int size;
> +int max_code;
> +
> +void
> +test ()
> +{
> + int code = 0;
> +
> + while (code < max_code)
> + code |= ((unsigned int) (size >> (--bits)));
> +
> + while (bits < (unsigned int)25)
> + bits += 8;
> +}
> +
> +/* { dg-final { scan-tree-dump "Loop 2 iterates at most 4 times" "cunroll"}
> } */
> +/* { dg-final { cleanup-tree-dump "cunroll" } } */
Jakub