This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: [tree-ssa] Optimizing if statements
- From: Daniel Berlin <dberlin at dberlin dot org>
- To: Steven Bosscher <s dot bosscher at student dot tudelft dot nl>
- Cc: gcc at gcc dot gnu dot org
- Date: Mon, 2 Jun 2003 17:40:57 -0400 (EDT)
- Subject: Re: [tree-ssa] Optimizing if statements
- References: <3EDB7FB3.6070108@student.tudelft.nl>
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
>
>
>