[PATCH] c++, dyninit: Optimize C++ dynamic initialization by constants into DECL_INITIAL adjustment [PR102876]

Jakub Jelinek jakub@redhat.com
Sat Nov 6 10:04:30 GMT 2021

On Fri, Nov 05, 2021 at 11:06:44AM -0600, Martin Sebor wrote:
> In my work-in-progress patch to diagnose stores into constant
> objects (and subobjects) I deal with the same problem.  I had
> considered a pair of markers like those above (David Malcolm
> suggested a smilar approach as well), but decided to go
> a different route, not trusting they could be kept together,
> or that they wouldn't be viewed as overly intrusive.  With
> it, I have been able to distinguish dynamic initialization
> from overwriting stores even at the end of compilation, but
> I'd be fine changing that and running the detection earlier.
> So if the markers are added for the purpose of optimizing
> the dynamic initialization at file scope, could they be added
> for those of locals as well?  That way I wouldn't need to add
> a separate solution.

I'm afraid not.  The ifns by pretending to read the corresponding
variables (and maybe they should be pretending to read from all
namespace scope global variables defined in the TU) prevent code motion of
stores across them and various other optimizations.
I'd hope it is acceptable for the global constructor functions because
those happen just once per process, never happen inside loops etc.
But for automatic or static block scope variables that would be way too
expensive.  We can't affort that.


More information about the Gcc-patches mailing list