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