This is the mail archive of the gcc-bugs@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]

[Bug tree-optimization/33344] New: if(!z) {a.b = x->b + 1; z = &a; } else if (!x) { a.b = z->b+1; x = &a; } use z->b and x->b; is not optimized


Testcase:
struct f { int a; };
int g(struct f *b, struct f *c)
{
  struct f g;
  if (!b) {
    b = &g;
    b->a = c->a + 1;
  }
  else if (!c) {
    c = &g;
    c->a = b->a + 1;
  }
  return c->a + b->a;
}

The best way to optimize this is:
struct f { int a; };
int g(struct f *b, struct f *c)
{
  int ba, ca;
  if (!b) {
    ca = c->a;
    ba = ca + 1;
  }
  else if (!c) {
    ba = b->a;
    ca = ba + 1;
  }
  else {
    ca = c->a;
    ba = b->a;
  }
  return ca + ba;
}

Which avoids the LHS (load-hit-store hazzard) issue on the Cell.


-- 
           Summary: if(!z) {a.b = x->b + 1; z = &a; } else if (!x) { a.b =
                    z->b+1; x = &a; } use z->b and x->b; is not optimized
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: pinskia at gcc dot gnu dot org


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


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