From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id E4BF9384A87E; Sat, 20 Jun 2020 06:34:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E4BF9384A87E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1592634896; bh=eDQDlyCQ7YBjekuch7dpRzORkqh28Jwhh2o841orKyA=; h=From:To:Subject:Date:From; b=lUMQ2yLfO87Xx467lhMvk4x9h8xgk1yv/2ImzmFo5beHYnFDLisq53Luj3KHHfqbW LTCEgevfpWR9YV2aBTJ3gztT/G3YUWbzA1ZdUnsXHmmXTy7vpiRJymZebogBVgz9r6 pAzApCSCDlYyGpcx96K1nJ1YKS5DAgPAn2knBqP8= From: "josephcsible at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/95783] New: Inefficient use of the stack when a function takes the address of its argument Date: Sat, 20 Jun 2020 06:34:56 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 10.1.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: josephcsible at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status keywords bug_severity priority component assigned_to reporter target_milestone cf_gcctarget Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 20 Jun 2020 06:34:57 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D95783 Bug ID: 95783 Summary: Inefficient use of the stack when a function takes the address of its argument Product: gcc Version: 10.1.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: josephcsible at gmail dot com Target Milestone: --- Target: x86_64-linux-gnu Consider this C code: void g(long *); long f(long x) { g(&x); return x; } At either "-O3" or "-Os", it results in this assembly: f: subq $24, %rsp movq %rdi, 8(%rsp) leaq 8(%rsp), %rdi call g movq 8(%rsp), %rax addq $24, %rsp ret There are two problems with this: it's unnecessarily complicated with extra instructions, and it wastes 16 bytes of stack space. I'd rather see this assembly instead: f: pushq %rdi movq %rsp, %rdi call g popq %rax ret https://godbolt.org/z/PuNB6Y=