From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id EC3C4386F81E; Sun, 7 Jun 2020 10:01:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EC3C4386F81E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1591524107; bh=wB6ZUZI84rIwFct96JSKpPp4gBd5silEm5ntKf/DvTo=; h=From:To:Subject:Date:From; b=NtzXkO8InYslMjv1nXGGKmoopC7F324ahMTS/2AngvxgliH/Wnq2x+WfP5mqa1tFS 1dQc0rMJxmTh5SaQ5XgMEx7yvGZLXLlMqZKBHbcJp/3Rde9SBRnuf6Sa9WBkzi+Zow taSNHDB8osb6nTzM52i4BLLxeokgKpOLThXHh/N0= From: "zero at smallinteger dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/95566] New: x86 instruction selection --- some REX prefixes unnecessary Date: Sun, 07 Jun 2020 10:01: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: 10.1.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, 07 Jun 2020 10:01:48 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D95566 Bug ID: 95566 Summary: x86 instruction selection --- some REX prefixes unnecessary Product: gcc Version: 10.1.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 48696 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D48696&action=3Dedit sample code Consider the code attached, compiled with gcc -O3 sample.c -o sample Gcc produces unrolled loop code that follows the pattern below. movzx ecx, WORD PTR [rsp-62] cmp rdx, rcx Here, rdx has the value of k >> 48. The top 32 bits of rdx are zero after = the shift, so the entirety of k >> 48 is in edx. Thus, the cmp instructions co= uld be cmp edx, ecx instead. This difference avoids the REX prefix, and thus the instructions = are shorter. After sufficient unrolling (or with e.g. more complex comparisons that depend on k >> 48), shorter instructions without the REX prefix will be better even accounting for the partial register dependency (or an instructi= on to break the dependency). The Intel optimization manual says shorter instructions are better. The attachment is the entirety of sample.c. I did not include other files because this attachment appears to qualify for that exemption due to excuse (ii): the attached test case is small and does not include any other file. I originally found this behavior looking at the disassembly of gcc (Gentoo 9.2.0-r2 p3) 9.2.0. I verified the same behavior with gcc 10.1 and gcc tru= nk at godbolt.=