http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57650

            Bug ID: 57650
           Summary: Suboptimal code after TRUTH_AND_EXPR is changed into
                    BIT_AND_EXPR
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jakub at gcc dot gnu.org

On:

int baz (int);

int
foo (char *x, int y, int z)
{
  if (y > z && x)
    return baz (1);
  if (x)
    baz (2);
  return 0;
}

int
bar (char *x, int y, int z)
{
  if (x && y > z)
    return baz (1);
  if (x)
    baz (2);
  return 0;
}

one of the functions (depending on reassoc decission to keep or swap the
BIT_AND_EXPR arguments) ends up with really bad generated code, will do
testq %rdi, %rdi
setne %al
...
compare y with z, jump based on that, then test %al (separately in both
branches).  Would be much better if tree optimizers could figure out that if
one of the BIT_AND_EXPR operands is also used as condition for a conditional
jump nearby, that it perhaps could jump thread this (essentially generate the
same code as
if (x)
  {
    if (y > z)
      return bar (1);
    bar (2);
  }
would).

Reply via email to