[PATCH] Avoid creating invalid gimple in eliminate_redundant_comparison (PR tree-optimization/45059)

Richard Guenther richard.guenther@gmail.com
Wed Aug 25 09:58:00 GMT 2010


On Tue, Aug 24, 2010 at 9:19 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> Hi!
>
> In some cases the operands of the comparison won't have the desired type,
> e.g. if there were any (useless) differences in types of the operands.
> Having a NOP_EXPR as gimple comparison's operand is invalid though.
>
> Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux.
> Ok for trunk?

Ok.

Thanks,
Richard.

> 2010-08-24  Jakub Jelinek  <jakub@redhat.com>
>
>        PR tree-optimization/45059
>        * tree-ssa-reassoc.c (eliminate_redundant_comparison): Strip useless
>        type conversions from newop{1,2}.  Assert t is a comparison and
>        newop{1,2} after the stripping are gimple vals.
>
>        * gcc.c-torture/compile/pr45059.c: New test.
>
> --- gcc/tree-ssa-reassoc.c.jj   2010-08-20 16:05:41.000000000 +0200
> +++ gcc/tree-ssa-reassoc.c      2010-08-24 19:16:57.000000000 +0200
> @@ -1314,9 +1314,14 @@ eliminate_redundant_comparison (enum tre
>          enum tree_code subcode;
>          tree newop1;
>          tree newop2;
> +         gcc_assert (COMPARISON_CLASS_P (t));
>          tmpvar = create_tmp_var (TREE_TYPE (t), NULL);
>          add_referenced_var (tmpvar);
>          extract_ops_from_tree (t, &subcode, &newop1, &newop2);
> +         STRIP_USELESS_TYPE_CONVERSION (newop1);
> +         STRIP_USELESS_TYPE_CONVERSION (newop2);
> +         gcc_checking_assert (is_gimple_val (newop1)
> +                              && is_gimple_val (newop2));
>          sum = build_and_add_sum (tmpvar, newop1, newop2, subcode);
>          curr->op = gimple_get_lhs (sum);
>        }
> --- gcc/testsuite/gcc.c-torture/compile/pr45059.c.jj    2010-08-24 19:05:44.000000000 +0200
> +++ gcc/testsuite/gcc.c-torture/compile/pr45059.c       2010-08-24 19:05:25.000000000 +0200
> @@ -0,0 +1,23 @@
> +/* PR tree-optimization/45059 */
> +
> +typedef unsigned int T;
> +extern void foo (signed char *, int);
> +
> +static signed char a;
> +static T b[1] = { -1 };
> +static unsigned char c;
> +
> +static inline short int
> +bar (short v)
> +{
> +  c |= a < b[0];
> +  return 0;
> +}
> +
> +int
> +main ()
> +{
> +  signed char *e = &a;
> +  foo (e, bar (bar (c)));
> +  return 0;
> +}
>
>        Jakub
>



More information about the Gcc-patches mailing list