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 tree-optimization/106245] Failure to optimize (u8)(a << 7) >> 7 pattern to a & 1
Date: Wed, 11 Oct 2023 07:09:06 +0000	[thread overview]
Message-ID: <bug-106245-4-RpHlIcrD0Z@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-106245-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106245

--- Comment #2 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:c41492423140e1573df68d1c98e825ae7593741f

commit r14-4551-gc41492423140e1573df68d1c98e825ae7593741f
Author: Roger Sayle <roger@nextmovesoftware.com>
Date:   Wed Oct 11 08:08:04 2023 +0100

    Optimize (ne:SI (subreg:QI (ashift:SI x 7) 0) 0) as (and:SI x 1).

    This patch is the middle-end piece of an improvement to PRs 101955 and
    106245, that adds a missing simplification to the RTL optimizers.
    This transformation is to simplify (char)(x << 7) != 0 as x & 1.
    Technically, the cast can be any truncation, where shift is by one
    less than the narrower type's precision, setting the most significant
    (only) bit from the least significant bit.

    This transformation applies to any target, but it's easy to see
    (and add a new test case) on x86, where the following function:

    int f(int a) { return (a << 31) >> 31; }

    currently gets compiled with -O2 to:

    foo:    movl    %edi, %eax
            sall    $7, %eax
            sarb    $7, %al
            movsbl  %al, %eax
            ret

    but with this patch, we now generate the slightly simpler.

    foo:    movl    %edi, %eax
            sall    $31, %eax
            sarl    $31, %eax
            ret

    2023-10-11  Roger Sayle  <roger@nextmovesoftware.com>

    gcc/ChangeLog
            PR middle-end/101955
            PR tree-optimization/106245
            * simplify-rtx.cc (simplify_relational_operation_1): Simplify
            the RTL (ne:SI (subreg:QI (ashift:SI x 7) 0) 0) to (and:SI x 1).

    gcc/testsuite/ChangeLog
            * gcc.target/i386/pr106245-1.c: New test case.

  parent reply	other threads:[~2023-10-11  7:09 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-10  9:30 [Bug tree-optimization/106245] New: " gabravier at gmail dot com
2022-07-10 19:46 ` [Bug tree-optimization/106245] " pinskia at gcc dot gnu.org
2023-10-11  7:09 ` cvs-commit at gcc dot gnu.org [this message]
2023-10-20 23:08 ` cvs-commit 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-106245-4-RpHlIcrD0Z@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: link
Be 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).