This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [patch] for PR 34244
- From: "Richard Guenther" <richard dot guenther at gmail dot com>
- To: "Zdenek Dvorak" <rakdver at kam dot mff dot cuni dot cz>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Thu, 29 Nov 2007 13:34:22 +0100
- Subject: Re: [patch] for PR 34244
- References: <20071129042834.GB28974@kam.mff.cuni.cz>
On Nov 29, 2007 5:28 AM, Zdenek Dvorak <rakdver@kam.mff.cuni.cz> wrote:
> Hi,
>
> we have a code like
>
> if (something)
> offset = 100;
> else
> offset = -100;
>
> while (offset > 0)
> offset--;
>
> if (offset == 0)
> launch_nuclear_rockets ();
>
> VRP starts simulating the code, first executing the true branch of the if
> (something) condition, getting offset = 100. It then proceeds with the loop,
> determining that number of iterations is equal to offset (since we just now
> believe that offset==100, this is correct, without any assumptions), thus the
> final value of offset is 0 and launch_nuclear_rockets is considered to be
> always executed.
>
> Later, VRP evaluates the false branch of the if (something) condition, setting
> the value range of offset to [-100,100], and proceeds to re-evaluate the
> effects of the loop. However, scev caches the number of iterations of the
> loop, so it is not re-evaluated, and we keep believing that the final value of
> offset is always zero.
>
> Forcing scev to recompute the number of iterations every time some value range
> changes would probably lead to compile time problems (computing number of iterations
> is fairly expensive, and we used to have compile time problems with that in other
> passes). Instead, the patch forces scev to compute and cache the number of iterations
> of each loop before vrp analysis starts, and cache these values (that do not use
> the partial results of VRP).
>
> Bootstrapped & regtested on amd64-linux.
This is ok.
Thanks,
Richard.
> Zdenek
>
> PR tree-optimization/34244
> * tree-vrp.c (adjust_range_with_scev): Clear scev cache.
> (record_numbers_of_iterations): New function.
> (execute_vrp): Cache the numbers of iterations of loops.
> * tree-scalar-evolution.c (scev_reset_except_niters):
> New function.
> (scev_reset): Use scev_reset_except_niters.
> * tree-scalar-evolution.h (scev_reset_except_niters): Declare.
>
> * gcc.dg/tree-ssa/pr34244.c: New test.