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 rtl-optimization/110717] Double-word sign-extension missed-optimization Date: Fri, 04 Aug 2023 15:26:50 +0000 [thread overview] Message-ID: <bug-110717-4-rI8yrKaIxr@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-110717-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110717 --- Comment #15 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:c572f09a751cbd365e2285b30527de5ab9025972 commit r14-2998-gc572f09a751cbd365e2285b30527de5ab9025972 Author: Roger Sayle <roger@nextmovesoftware.com> Date: Fri Aug 4 16:26:06 2023 +0100 Specify signed/unsigned/dontcare in calls to extract_bit_field_1. This patch is inspired by Jakub's work on PR rtl-optimization/110717. The bitfield example described in comment #2, looks like: struct S { __int128 a : 69; }; unsigned type bar (struct S *p) { return p->a; } which on x86_64 with -O2 currently generates: bar: movzbl 8(%rdi), %ecx movq (%rdi), %rax andl $31, %ecx movq %rcx, %rdx salq $59, %rdx sarq $59, %rdx ret The ANDL $31 is interesting... we first extract an unsigned 69-bit bitfield by masking/clearing the top bits of the most significant word, and then it gets sign-extended, by left shifting and arithmetic right shifting. Obviously, this bit-wise AND is redundant, for signed bit-fields, we don't require these bits to be cleared, if we're about to set them appropriately. This patch eliminates this redundancy in the middle-end, during RTL expansion, but extending the extract_bit_field APIs so that the integer UNSIGNEDP argument takes a special value; 0 indicates the field should be sign extended, 1 (any non-zero value) indicates the field should be zero extended, but -1 indicates a third option, that we don't care how or whether the field is extended. By passing and checking this sentinel value at the appropriate places we avoid the useless bit masking (on all targets). For the test case above, with this patch we now generate: bar: movzbl 8(%rdi), %ecx movq (%rdi), %rax movq %rcx, %rdx salq $59, %rdx sarq $59, %rdx ret 2023-08-04 Roger Sayle <roger@nextmovesoftware.com> gcc/ChangeLog * expmed.cc (extract_bit_field_1): Document that an UNSIGNEDP value of -1 is equivalent to don't care. (extract_integral_bit_field): Indicate that we don't require the most significant word to be zero extended, if we're about to sign extend it. (extract_fixed_bit_field_1): Document that an UNSIGNEDP value of -1 is equivalent to don't care. Don't clear the most significant bits with AND mask when UNSIGNEDP is -1. gcc/testsuite/ChangeLog * gcc.target/i386/pr110717-2.c: New test case.
next prev parent reply other threads:[~2023-08-04 15:26 UTC|newest] Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-07-18 14:32 [Bug rtl-optimization/110717] New: " jakub at gcc dot gnu.org 2023-07-18 14:33 ` [Bug rtl-optimization/110717] " jakub at gcc dot gnu.org 2023-07-18 14:54 ` jakub at gcc dot gnu.org 2023-07-19 6:38 ` rguenth at gcc dot gnu.org 2023-07-19 8:55 ` ubizjak at gmail dot com 2023-07-19 9:00 ` jakub at gcc dot gnu.org 2023-07-19 9:30 ` ubizjak at gmail dot com 2023-07-20 18:56 ` cvs-commit at gcc dot gnu.org 2023-07-20 19:03 ` ubizjak at gmail dot com 2023-07-20 19:19 ` jakub at gcc dot gnu.org 2023-07-20 19:21 ` jakub at gcc dot gnu.org 2023-07-21 9:06 ` jakub at gcc dot gnu.org 2023-07-21 10:53 ` segher at gcc dot gnu.org 2023-07-21 16:28 ` segher at gcc dot gnu.org 2023-07-21 16:46 ` pinskia at gcc dot gnu.org 2023-08-04 15:26 ` cvs-commit at gcc dot gnu.org [this message] 2023-10-30 16:18 ` cvs-commit at gcc dot gnu.org 2023-12-13 13:37 ` cvs-commit at gcc dot gnu.org 2024-05-07 7:41 ` rguenth at gcc dot gnu.org
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-110717-4-rI8yrKaIxr@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).