[tree-ssa] Optimizing if statements

Steven Bosscher s.bosscher@student.tudelft.nl
Mon Jun 2 16:48:00 GMT 2003


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))?
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




More information about the Gcc mailing list