public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "zero at smallinteger dot com" <gcc-bugzilla@gcc.gnu.org> 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 [thread overview] Message-ID: <bug-95566-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95566 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=48696&action=edit 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 could 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 instruction 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 trunk at godbolt.
next reply other threads:[~2020-06-07 10:01 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-06-07 10:01 zero at smallinteger dot com [this message] 2021-08-20 5:13 ` [Bug target/95566] " pinskia at gcc dot gnu.org 2021-08-20 8:09 ` crazylht at gmail dot com
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-95566-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).