This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH 2/3]Improve induction variable elimination

On Thu, Jul 17, 2014 at 11:08 AM, Bin Cheng <> wrote:
> Hi,
> As quoted from the function difference_cannot_overflow_p,
>   /* TODO: deeper inspection may be necessary to prove the equality.  */
>   switch (code)
>     {
>     case PLUS_EXPR:
>       return expr_equal_p (e1, offset) || expr_equal_p (e2, offset);
>       return expr_equal_p (e2, offset);
>     default:
>       return false;
>     }
> The overflow check can be improved by using deeper inspection to prove the
> equality.  This patch deals with that by making below two improvements:
>   a) Handles constant cases.
>   b) Uses affine expansion as deeper inspection to check the equality.
> As a result, functions strip_wrap_conserving_type_conversions and
> expr_equal_p can be removed now.  A test case is also added to illustrate iv
> elimination opportunity captured by this patch.
> Thanks,
> bin

You add special casing for constants but I don't see any testcases for that.

+  /* No overflow if offset is zero.  */
+  if (offset == integer_zero_node)
     return true;

is a bogus check (use integer_zerop).  Apart from the special-casing of
constants the patch looks good to me.


> 2014-07-17  Bin Cheng  <>
>         * tree-ssa-loop-ivopts.c (ivopts_data): New field name_expansion.
>         (tree_ssa_iv_optimize_init): Initialize name_expansion.
>         (tree_ssa_iv_optimize_finalize): Free name_expansion.
>         (strip_wrap_conserving_type_conversions, expr_equal_p): Delete.
>         (difference_cannot_overflow_p): New parameter.  Handle constant
>         cases.  Use affine expansion for equality check.
>         (iv_elimination_compare_lt): Pass new argument.
> gcc/testsuite/ChangeLog
> 2014-07-17  Bin Cheng  <>
>         * gcc.dg/tree-ssa/ivopts-lt-2.c: New test.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]