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

--- Comment #30 from fiesh at zefix dot tv ---
Sorry for not having gotten back to this sooner.

The way I see this now is that:

* This is not a regression.  In fact, the new patch just makes GCC's behavior
consistent across these two code samples:

a.cpp:

struct H {
  unsigned char p[3]{0, 1, 2};
};
void q(H &r) { r = {}; }

vs

b.cpp:

struct h {
  int g;
  constexpr h() : g(0) {}
};
struct H {
  unsigned char p[3]{0, 1, 2};
  h o{};
};
void q(H &r) { r = {}; }


The behavior:

a.cpp:
  -O2 compiles to text size 16 and data size 0 both with gcc 14 and 15
  -Os compiles to text size 48 and data size 4 both with gcc 14 and 15

b.cpp:
  -O2 compiles to sizes 20 / 0 and 44 / 6 with gcc 14 and gcc 15 respectively
  -Os compiles to sizes 20 / 0 and 44 / 6 with gcc 14 and gcc 15 respectively


This difference is just because of the missed "optimization" of gcc 14.

My code has a lot of three-byte constexpr objects.  This is because they
reference objects in program memory by pointer (2 bytes) plus length (one
byte).  These used to fall into the gcc 14 bug and didn't get "optimized."  Now
they don't, and this leads to the increase in data size since they all occupy
space in .data now.

So I suppose the issue's title is incorrect, but I do believe that this is the
wrong optimization.

Reply via email to