https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116873

            Bug ID: 116873
           Summary: esra does not remove unused store sometimes
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---

Take:
```
struct Foo {
  int t;
  int x;
};


int f(struct Foo a, struct Foo b, int c)
{
  struct Foo d;
  struct Foo e;
  struct Foo *l;
  if (c) l = &a; else l = &b;
  d = *l;
  e = *l;
  return d.t + e.x;
}
```

After esra we get:
```
  # l_3 = PHI <&a(2), &b(3)>
  d = MEM[(const struct Foo &)l_3];
  d$t_6 = MEM[(const struct Foo &)l_3].t;
  e = MEM[(const struct Foo &)l_3];
  e$x_5 = MEM[(const struct Foo &)l_3].x;
  _1 = d$t_6;
  _2 = e$x_5;
  _10 = _1 + _2;
  d ={v} {CLOBBER(eos)};
  e ={v} {CLOBBER(eos)};
  return _10;
```

BUT the store to d and e are dea. If we full scalarize d and e, the stores are
removed (that is use d.x and e.t).

Shouldn't we just mark d and e to be removed too?

Yes DSE does remove them later on but I don't see why SRA could not handle them
if fields are unused.

Reply via email to