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 AFE523858D39 for ; Tue, 28 Mar 2023 22:46:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AFE523858D39 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=kernel.crashing.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=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 32SMjkCl027749; Tue, 28 Mar 2023 17:45:46 -0500 Received: (from segher@localhost) by gate.crashing.org (8.14.1/8.14.1/Submit) id 32SMjjAS027748; Tue, 28 Mar 2023 17:45:45 -0500 X-Authentication-Warning: gate.crashing.org: segher set sender to segher@kernel.crashing.org using -f Date: Tue, 28 Mar 2023 17:45:45 -0500 From: Segher Boessenkool To: Kalamatee Cc: gcc-help@gcc.gnu.org Subject: Re: Problem understand optimization with inline asm Message-ID: <20230328224545.GN25951@gate.crashing.org> References: 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=-2.8 required=5.0 tests=BAYES_00,JMQ_SPF_NEUTRAL,KAM_DMARC_STATUS,SPF_HELO_PASS,SPF_PASS,TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hi! On Tue, Mar 28, 2023 at 12:15:37PM +0100, Kalamatee via Gcc-help wrote: > Now, I can work around this by using "+" (even though I don't read the > variable), or initializing the value a second time in the asm block - but > should I have to? This sounds like the compiler is doing the wrong thing > based on the assertion/assumption "=" means I will 100% change some > variable, Yes, that is what an output contraint means. From the manual: '=' Means that this operand is written to by this instruction: the previous value is discarded and replaced by new data. If you use "+" it will mean exactly what you want. "+" means "both an input and an output operand". '+' Means that this operand is both read and written by the instruction. If you want the asm to have semantics like if (cond) x = y; this can be equivalently written as if (cond) x = y; else x = x; or maybe even x = (cond) ? y : x; and written that way it is clear you really want an in/out constraint here :-) HtH, Segher