From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate.crashing.org (gate.crashing.org [63.228.1.57]) by sourceware.org (Postfix) with ESMTP id B2503397A02D for ; Fri, 4 Dec 2020 18:34:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org B2503397A02D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=kernel.crashing.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=segher@kernel.crashing.org Received: from gate.crashing.org (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.14.1) with ESMTP id 0B4IXIVY020545; Fri, 4 Dec 2020 12:33:18 -0600 Received: (from segher@localhost) by gate.crashing.org (8.14.1/8.14.1/Submit) id 0B4IXH6u020544; Fri, 4 Dec 2020 12:33:17 -0600 X-Authentication-Warning: gate.crashing.org: segher set sender to segher@kernel.crashing.org using -f Date: Fri, 4 Dec 2020 12:33:17 -0600 From: Segher Boessenkool To: Andrea Corallo Cc: stefan@franke.ms, gcc-help@gcc.gnu.org Subject: Re: Correct way to express to the compiler "this does not get clobbered"? Message-ID: <20201204183317.GO2672@gate.crashing.org> References: <32b3c0a3-9917-2b92-de59-1d6a14ecd8f8@hesbynett.no> <20201204172721.GM2672@gate.crashing.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.3i X-Spam-Status: No, score=-6.3 required=5.0 tests=BAYES_00, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, TXREP, T_SPF_HELO_PERMERROR, T_SPF_PERMERROR autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-help@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-help mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 04 Dec 2020 18:34:30 -0000 On Fri, Dec 04, 2020 at 07:16:45PM +0100, Andrea Corallo via Gcc-help wrote: > Segher Boessenkool writes: > > > On Fri, Dec 04, 2020 at 10:52:17AM +0100, Andrea Corallo via Gcc-help wrote: > >> stefan@franke.ms writes: > >> I might open a bug but my understanding is that const is generally > >> not used for optimizations. Am I wrong? > > > > extern const int x = 42; > > int f(void) { return x; } > > > > The code generated for f does not load the value for x from memory: it > > returns 42 always. > Are you suggesting we should treat this as a bug? Huh? No, I am just saying that const *is* used for optimisation, with a dumb simple example. Remove const from this code and you get different generated machine code (that does load x from memory always). If you think you have found a missing optimisation, please make a self-contained demonstrator for that, and a file a PR? Segher