From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mxex1.tik.uni-stuttgart.de (mxex1.tik.uni-stuttgart.de [IPv6:2001:7c0:2041:24::a:1]) by sourceware.org (Postfix) with ESMTPS id F127C3858D34 for ; Tue, 26 May 2020 13:07:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org F127C3858D34 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=ipvs.uni-stuttgart.de Authentication-Results: sourceware.org; spf=none smtp.mailfrom=steffen.hirschmann@ipvs.uni-stuttgart.de Received: from localhost (localhost [127.0.0.1]) by mxex1.tik.uni-stuttgart.de (Postfix) with ESMTP id B1836608AB for ; Tue, 26 May 2020 15:07:12 +0200 (CEST) Authentication-Results: mxex1.tik.uni-stuttgart.de (amavisd-new); dkim=pass (2048-bit key) reason="pass (just generated, assumed good)" header.d=uni-stuttgart.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=uni-stuttgart.de; h=content-disposition:content-type:content-type:mime-version :message-id:subject:subject:from:from:date:date:received :received; s=dkim; i=@ipvs.uni-stuttgart.de; t=1590498430; x= 1592237231; bh=XkQpFU+3Tyd2movJj0zI7FgLB0hCb2WGnCrqLv+5zW4=; b=b R2Se3rB9v9WSU+7yXSwf1EbDAMMp7wjgaKuNSgFJE7OVB919CETwOhy/rXUCHxrp bCLz7LLxdUgUudMzE0DhzetMgikO6OQcrFSegrFSHMVSJfXE696PZZ0xmR8vZqHx tp2k7apKnn/6WEP90wrHZXIhXway6CJ4OC2TdMvAXyJEjqInXZafv2qzYbSfOTRV LZn1DY0zOg5bxuLHOima2g4rSCzrRyJW07HPMPVwAYuXR4Np9dqZw8j3yNjOg9Yo B/6sYpuQ9IeQfjk46BwqulktDFC+y/3YAgvGL49sOVaWgUjCx+9aKPWN7ajbuOlN 6ZtoUj9HfL7vKPjOeey3A== X-Virus-Scanned: USTUTT mailrelay AV services at mxex1.tik.uni-stuttgart.de Received: from mxex1.tik.uni-stuttgart.de ([127.0.0.1]) by localhost (mxex1.tik.uni-stuttgart.de [127.0.0.1]) (amavisd-new, port 10031) with ESMTP id OBI7zFCL_5Jb; Tue, 26 May 2020 15:07:10 +0200 (CEST) Received: from localhost (lapsgs17.informatik.uni-stuttgart.de [129.69.213.160]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mxex1.tik.uni-stuttgart.de (Postfix) with ESMTPSA; Tue, 26 May 2020 15:07:10 +0200 (CEST) Date: Tue, 26 May 2020 15:07:10 +0200 From: Steffen Hirschmann To: gcc-help@gcc.gnu.org Subject: Unnecessary stores with std::optional? Message-ID: <20200526130710.GB362962@lapsgs17> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham 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: Tue, 26 May 2020 13:07:15 -0000 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? Greetings, Steffen