public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "cvs-commit at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug target/103611] GCC generates suboptimal code for SSE2/SSE4.1 64-bit integer element extraction on 32-bit x86 targets Date: Sat, 18 Dec 2021 13:53:13 +0000 [thread overview] Message-ID: <bug-103611-4-acQkyraBAE@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-103611-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103611 --- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Roger Sayle <sayle@gcc.gnu.org>: https://gcc.gnu.org/g:31048012db98f5ec9c2ba537bfd850374bdd771f commit r12-6058-g31048012db98f5ec9c2ba537bfd850374bdd771f Author: Roger Sayle <roger@nextmovesoftware.com> Date: Sat Dec 18 13:51:56 2021 +0000 x86: PR target/103611: Splitter for DST:DI = (HI:SI<<32)|LO:SI. A common idiom is to create a DImode value from the "concat" of two SImode values, using "(long long)hi << 32 | (long long)lo", where the operation may be ior, xor or plus. On x86, with -m32, the high and low parts of a DImode register are actually different SImode registers (typically %edx and %eax) so ideally this idiom should reduce to two move instructions (or optimally, just clever register allocation). Unfortunately, GCC currently performs the IOR operation above on -m32, and worse allocates DImode registers (split to SImode register pairs) for both the zero extended HI and LO values. Hence, for test1 from the new test case below: typedef int __v4si __attribute__ ((__vector_size__ (16))); long long test1(__v4si v) { unsigned int loVal = (unsigned int)v[0]; unsigned int hiVal = (unsigned int)v[1]; return (long long)(loVal) | ((long long)(hiVal) << 32); } we currently generate (with -m32 -O2 -msse4.1): test1: subl $28, %esp pextrd $1, %xmm0, %eax pmovzxdq %xmm0, %xmm1 movq %xmm1, 8(%esp) movl %eax, %edx movl 8(%esp), %eax orl 12(%esp), %edx addl $28, %esp orb $0, %ah ret with this patch we now generate: test1: pextrd $1, %xmm0, %edx movd %xmm0, %eax ret The fix is to recognize and split the idiom (hi<<32)|zext(lo) prior to register allocation on !TARGET_64BIT, simplifying this sequence to "highpart(dst) = hi; lowpart(dst) = lo". The one minor complication is that sse.md's define_insn for *vec_extractv4si_0_zext_sse4 can sometimes interfere with this optimization. It turns out that on !TARGET_64BIT, the zero_extend:DI following vec_select:SI isn't free, and this insn gets split back into multiple instructions during later passes, but too late to be optimized away by this patch/reload. Hence the last hunk of this patch is to restrict *vec_extractv4si_0_zext_sse4 to TARGET_64BIT. Checking PR target/80286, where *vec_extractv4si_0_zext_sse4 was first added, this seems reasonable. 2021-12-18 Roger Sayle <roger@nextmovesoftware.com> Uroš Bizjak <ubizjak@gmail.com> gcc/ChangeLog PR target/103611 * config/i386/i386.md (any_or_plus): New code iterator. (define_split): Split (HI<<32)|zext(LO) into piece-wise move instructions on !TARGET_64BIT. * config/i386/sse.md (*vec_extractv4si_0_zext_sse4): Restrict to TARGET_64BIT. gcc/testsuite/ChangeLog PR target/103611 * gcc.target/i386/pr103611-2.c: New test case.
next prev parent reply other threads:[~2021-12-18 13:53 UTC|newest] Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-12-08 0:55 [Bug target/103611] New: " john_platts at hotmail dot com 2021-12-08 1:04 ` [Bug target/103611] " john_platts at hotmail dot com 2021-12-08 1:10 ` john_platts at hotmail dot com 2021-12-08 1:28 ` pinskia at gcc dot gnu.org 2021-12-08 1:36 ` john_platts at hotmail dot com 2021-12-13 18:52 ` cvs-commit at gcc dot gnu.org 2021-12-18 13:53 ` cvs-commit at gcc dot gnu.org [this message] 2021-12-21 21:30 ` roger at nextmovesoftware 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-103611-4-acQkyraBAE@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).