From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by sourceware.org (Postfix) with ESMTPS id 7B0513858D35 for ; Thu, 28 Oct 2021 09:55:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7B0513858D35 Received: by mail-wm1-x329.google.com with SMTP id j128-20020a1c2386000000b003301a98dd62so428048wmj.5 for ; Thu, 28 Oct 2021 02:55:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=vxu3L80lzB/k/x/eCcA4U9OjpQYotorRk/wS1fpsJ6I=; b=u7uxMDKVx3cn0VbTVsLvWB0r/+wuXpteEOwP9f7PqqVnnON4TIEcRHPtLLGVYUrqUz EwFVFhylzrBpcJm9YWpVop/SR1J4OCnJNItZRrX7DHBmLajsA4Epy0qvxibVt3dhd3j8 YhDtyfUuEEBgz0e7iejuOqvOIQKaBr8VWzENBhj9xiNwTdiZW/KTFatU0WIvKbEPRGph GPol7ifqB0HYs/oVqu5QW/uNAIkM8zdriGig+XZ9Mq2VlyQmkkXSLFXcicBojLQjr0YY okdpw4iF4GPgIJ+vnj7pi8sp/Flh458qn1M4KQSkh3J6qeBI8vMaGwaF9aC9dwAld4N+ KPTQ== X-Gm-Message-State: AOAM531ZZZkWa9PqRppl0hYKD6OP9FqgiHF2TRzT8R3o+7lFsle0vNyd 7lgU97NCasEpjglpYpad0bup7c6vssXRee6T1Xg= X-Google-Smtp-Source: ABdhPJyV4biyfgSg4tl1MdIZPtmU8Gxv1dGxCukErixlYcfddydNuFrWPfj/4L7cV1weoXHleNFSR5KrtCPNnSLgBmQ= X-Received: by 2002:a1c:f213:: with SMTP id s19mr11355617wmc.169.1635414922628; Thu, 28 Oct 2021 02:55:22 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Jonathan Wakely Date: Thu, 28 Oct 2021 10:55:11 +0100 Message-ID: Subject: Re: Generated assembly code for returning std::optional To: =?UTF-8?B?4piCSm9zaCBDaGlhICjorJ3ku7vkuK0p?= Cc: gcc-help Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=0.5 required=5.0 tests=BAYES_00, BODY_8BITS, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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 Oct 2021 09:55:25 -0000 On Thu, 28 Oct 2021 at 08:11, =E2=98=82Josh Chia (=E8=AC=9D=E4=BB=BB=E4=B8= =AD) via Gcc-help wrote: > > Under -O3 -std=3Dc++17, the assembly code generated by gcc 11.2 for some > std::optional C++ code seems less optimal than I expect; it is writing th= e > content of optional return values to both the stack and to the > RAX register. What am I missing? I was under the impression that return > values are put in RAX if they can fit. Why does gcc have to write the > return value to both the stack and RAX instead of just one of them? Can t= he > writing to the stack be avoided? Is this https://gcc.gnu.org/PR101326 ?