From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sourceware.org (Postfix) with ESMTPS id 1AFE33870842 for ; Thu, 28 May 2020 15:00:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 1AFE33870842 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=inria.fr Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=marc.glisse@inria.fr X-IronPort-AV: E=Sophos;i="5.73,445,1583190000"; d="scan'208";a="349905596" Received: from 225.95.12.109.rev.sfr.net (HELO stedding) ([109.12.95.225]) by mail3-relais-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 May 2020 17:00:18 +0200 Date: Thu, 28 May 2020 17:00:18 +0200 (CEST) From: Marc Glisse X-X-Sender: glisse@stedding.saclay.inria.fr Reply-To: gcc-help@gcc.gnu.org To: Steffen Hirschmann cc: gcc-help@gcc.gnu.org Subject: Re: Unnecessary stores with std::optional? In-Reply-To: <20200526130710.GB362962@lapsgs17> Message-ID: References: <20200526130710.GB362962@lapsgs17> User-Agent: Alpine 2.22 (DEB 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP 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: Thu, 28 May 2020 15:00:25 -0000 On Tue, 26 May 2020, Steffen Hirschmann wrote: > Dear GCC community, > > I was testing std::optional when I noticed that gcc produces stores that > don't seem to be required. > > Code: > -------- > #include > std::optional foo(); > long bar() > { > auto r = foo(); > if (r) > return *r; > else > return 0L; > } > -------- > > What gcc 10.1 with -std=c++17 -O3 produces is: > bar(): > sub rsp, 24 > call foo() > mov QWORD PTR [rsp+8], rdx > cmp BYTE PTR [rsp+8], 0 > mov QWORD PTR [rsp], rax > mov rax, QWORD PTR [rsp] > jne .L1 > xor eax, eax > .L1: > add rsp, 24 > ret > > (see: https://godbolt.org/z/uHE6QB) > > I don't understand the stores (and loads) after the call to foo. They > don't seem necessary to me. Can anyone explain them to me? One of them seems to be a tuning choice (it disappears with some -march/-mtune flags), but not the other. Could you file an issue in gcc's bugzilla please? -- Marc Glisse