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 <sa...@gcc.gnu.org>:

https://gcc.gnu.org/g:c41492423140e1573df68d1c98e825ae7593741f

commit r14-4551-gc41492423140e1573df68d1c98e825ae7593741f
Author: Roger Sayle <ro...@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  <ro...@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.
  • [Bug tree-optimization/106245] ... cvs-commit at gcc dot gnu.org via Gcc-bugs

Reply via email to