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

            Bug ID: 121492
           Summary: union/struct copy should be able to optimized without
                    SRA when it comes to a loop
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: pinskia at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
                CC: unassigned at gcc dot gnu.org
            Blocks: 121364
  Target Milestone: ---

Testcase from PR 32964 (note PR 25500 has the same pattern):
```
union A
{
 float a;
};
float t(float a)
{
  union A a1, a2, a3;
  a1.a = a;
  for(int i =0;i<100;i++)
  {
  a2 = a1;
  a2.a += a;
  a1 = a2;
  }
  a3 = a1;
  return a3.a;
}
```

We should be able to optimize away the 3 unions even with SRA turned off.

Currently we have this in the inner loop:
```
  a2 = a1;
  _1 = a2.a;
  _2 = _1 + a_6(D);
  a2.a = _2;
  a1 = a2;
```

So the load from a2.a could become a load from a1.a. That will get rid of one
copy.
And then the copy `a1 = a2` could become just a store `a1.a = _2` That will get
rid of another copy.
And then LIM will be able to do the rest.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121364
[Bug 121364] [meta-bug] copy prop for aggregates

Reply via email to