This is the mail archive of the gcc@gcc.gnu.org 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: [tree-ssa] Optimizing if statements



On Mon, 2 Jun 2003, Steven Bosscher wrote:

> Consider this simple function,
>
> void
> foo (int bar)
> {
>   int boz = 0;
>
>   if (bar > 0)
>     boz = bar;
>
>   if (boz > 0)
>     printf ("Yup!\n");
> }
>
> Compiled with -O2, t.c.t14.optimized looks like this:
>
> ;; Function foo (foo)
>
> foo (bar)
> {
>   int s;
>   extern  printf;
>
>   s = 0 ;
>   if (bar > 0)
>     {
>       s = bar
>     };
>   if (s > 0)
>     {
>       printf ((const char *)(char *)"Yup!\n")
>     }
> }
>
>
> Shouldn't tree-ssa be able to optimize away one of the
> "if" statements here (since (s > 0) iff (bar > 0))?
If copy prop was working, it would.

Also, the neat Sparse Predicated GVN algorithm i mentioned a while back
would
take care of this.

Without copy-prop working, you'd need a predicated CCP
algorithm (predicated in that it tracks assertions about the predicates in
branch statements).
> Eventually, one of the RTL optimizers takes care of it,
> but it would be nice if it could be done at the tree
> level.
>
> Gr.
> Steven
>
>
>


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