From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6919 invoked by alias); 4 Mar 2011 16:26:03 -0000 Received: (qmail 6890 invoked by uid 22791); 4 Mar 2011 16:26:00 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from ksp.mff.cuni.cz (HELO atrey.karlin.mff.cuni.cz) (195.113.26.206) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 04 Mar 2011 16:25:56 +0000 Received: by atrey.karlin.mff.cuni.cz (Postfix, from userid 4018) id 8ECF2F0B76; Fri, 4 Mar 2011 17:25:33 +0100 (CET) Date: Fri, 04 Mar 2011 16:26:00 -0000 From: Jan Hubicka To: "jakub at gcc dot gnu.org" Cc: gcc-bugs@gcc.gnu.org Subject: Re: [Bug c/47980] Inefficient code for local const char arrays Message-ID: <20110304162533.GH12469@atrey.karlin.mff.cuni.cz> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.18 (2008-05-17) X-IsSubscribed: yes Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2011-03/txt/msg00421.txt.bz2 > 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