This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: [Bug c/47980] Inefficient code for local const char arrays
- From: Jan Hubicka <hubicka at ucw dot cz>
- To: "jakub at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- Cc: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 4 Mar 2011 17:25:33 +0100
- Subject: Re: [Bug c/47980] Inefficient code for local const char arrays
- References: <bug-47980-4@http.gcc.gnu.org/bugzilla/> <bug-47980-4-hmAur3HAPr@http.gcc.gnu.org/bugzilla/>
> I believe f could do:
> assert (arg != "aoeuaoeuaeouaeouaoeuaoeaoxbxod");
> which would then fail with the proposed optimization. It is unspecified if
> two string literals with the same content are distinct objects, but foo must be
> a distinct object (ok, with static const char foo[] =
> "aoeuaoeuaeouaeouaoeuaoeaoxbxod"; and -fmerge-all-constants which ignores some
> C requirements it doesn't have to).
Hmm, I was not aware of this.
I've seen quite few cases of real world code where such local arrays was used only
for direct references. It is valid to do the transform in all cases when address
is not escaping and it is not used for inequality tests. We do not track the second,
but we could.
It is however bit tricky to do the actual promotion of automatic scalar var to
static as gimplification lower initializers very early and thus we will have to
reconstruct it from gimple code.
Worthwhile optimization however I think.
Honza