From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id D497C3851C2F; Sun, 21 Jun 2020 07:16:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D497C3851C2F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1592723807; bh=xcqYEDspvEVe02GkCqjTgLEJ6teY4EbxCG0m6HQu3JM=; h=From:To:Subject:Date:From; b=EodtuNZLCjZ0PC8JNqKo1LbSXBbiFZSTwrbaG30fDLYyYeqeo2LWOcxyf79CPDlUm izm3MDrrBQGaJQTDWhHS1tIh1QeI4EVLRH8SZNVIns7dtb/zCcP4aBVviZMouwhUFX 42+WZmTC9Hl+zw92wc7l3NEK7UbKHYYZiGQDl2pg= From: "zero at smallinteger dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/95798] New: Initialization code --- suboptimal Date: Sun, 21 Jun 2020 07:16:47 +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: 9.3.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: zero at smallinteger 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 bug_severity priority component assigned_to reporter target_milestone attachments.created 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: Sun, 21 Jun 2020 07:16:47 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D95798 Bug ID: 95798 Summary: Initialization code --- suboptimal Product: gcc Version: 9.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: zero at smallinteger dot com Target Milestone: --- Created attachment 48764 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D48764&action=3Dedit sample code This is similar to (but not the same as) bug 87223 for structs. Further, t= his bug expands on this issue for gcc 10.x. Originally, this was noted in gcc (Ubuntu 9.3.0-10ubuntu2) 9.3.0, compiling with -O3. First, note the initialization code that trivially sets values to zero in an array, mov eax, edi sub rsp, 8080 xor edx, edx and eax, 127 mov QWORD PTR [rsp-120+rax*8], 0 mov QWORD PTR [rsp-112+rax*8], 0 mov QWORD PTR [rsp-104+rax*8], 0 mov QWORD PTR [rsp-96+rax*8], 0 mov QWORD PTR [rsp-88+rax*8], 0 mov QWORD PTR [rsp-80+rax*8], 0 mov QWORD PTR [rsp-72+rax*8], 0 mov QWORD PTR [rsp-64+rax*8], 0 xor eax, eax would be better by first setting a register to zero, then writing the value= of the register. Further, note that there is already a zero register available (edx), but it is not used. This is similar to 87223 for structs, and here = the issue manifests for arrays. Second, using gcc 10 versions and -O3 at godbolt.org results in this code: mov eax, edi mov edx, edi sub rsp, 8072 and eax, 127 and edx, 127 mov QWORD PTR [rsp-120+rdx*8], 0 lea edx, [rax+1] movsx rdx, edx mov QWORD PTR [rsp-120+rdx*8], 0 lea edx, [rax+2] movsx rdx, edx mov QWORD PTR [rsp-120+rdx*8], 0 lea edx, [rax+3] movsx rdx, edx mov QWORD PTR [rsp-120+rdx*8], 0 lea edx, [rax+4] movsx rdx, edx mov QWORD PTR [rsp-120+rdx*8], 0 lea edx, [rax+5] movsx rdx, edx mov QWORD PTR [rsp-120+rdx*8], 0 lea edx, [rax+6] add eax, 7 movsx rdx, edx cdqe mov QWORD PTR [rsp-120+rdx*8], 0 xor edx, edx mov QWORD PTR [rsp-120+rax*8], 0 xor eax, eax This is much, much more verbose than in gcc 9.3, for no apparent gain.=