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/94026] combine missed opportunity to simplify comparisons with zero
Date: Tue, 09 Aug 2022 17:57:28 +0000	[thread overview]
Message-ID: <bug-94026-4-C0RV58Hcqb@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-94026-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #14 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:6fc14f1963dfefead588a4cd8902d641ed69255c

commit r13-2005-g6fc14f1963dfefead588a4cd8902d641ed69255c
Author: Roger Sayle <roger@nextmovesoftware.com>
Date:   Tue Aug 9 18:54:43 2022 +0100

    middle-end: Optimize ((X >> C1) & C2) != C3 for more cases.

    Following my middle-end patch for PR tree-optimization/94026, I'd promised
    Jeff Law that I'd clean up the dead-code in fold-const.cc now that these
    optimizations are handled in match.pd.  Alas, I discovered things aren't
    quite that simple, as the transformations I'd added avoided cases where
    C2 overlapped with the new bits introduced by the shift, but the original
    code handled any value of C2 provided that it had a single-bit set (under
    the condition that C3 was always zero).

    This patch upgrades the transformations supported by match.pd to cover
    any values of C2 and C3, provided that C1 is a valid bit shift constant,
    for all three shift types (logical right, arithmetic right and left).
    This then makes the code in fold-const.cc fully redundant, and adds
    support for some new (corner) cases not previously handled.  If the
    constant C1 is valid for the type's precision, the shift is now always
    eliminated (with C2 and C3 possibly updated to test the sign bit).

    Interestingly, the fold-const.cc code that I'm now deleting was originally
    added by me back in 2006 to resolve PR middle-end/21137.  I've confirmed
    that those testcase(s) remain resolved with this patch (and I'll close
    21137 in Bugzilla).  This patch also implements most (but not all) of the
    examples mentioned in PR tree-optimization/98954, for which I have some
    follow-up patches.

    2022-08-09  Roger Sayle  <roger@nextmovesoftware.com>
                Richard Biener  <rguenther@suse.de>

    gcc/ChangeLog
            PR middle-end/21137
            PR tree-optimization/98954
            * fold-const.cc (fold_binary_loc): Remove optimizations to
            optimize ((X >> C1) & C2) ==/!= 0.
            * match.pd (cmp (bit_and (lshift @0 @1) @2) @3): Remove wi::ctz
            check, and handle all values of INTEGER_CSTs @2 and @3.
            (cmp (bit_and (rshift @0 @1) @2) @3): Likewise, remove wi::clz
            checks, and handle all values of INTEGER_CSTs @2 and @3.

    gcc/testsuite/ChangeLog
            PR middle-end/21137
            PR tree-optimization/98954
            * gcc.dg/fold-eqandshift-4.c: New test case.

      parent reply	other threads:[~2022-08-09 17:57 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bug-94026-4@http.gcc.gnu.org/bugzilla/>
2020-03-13  3:09 ` [Bug rtl-optimization/94026] " felix.yang at huawei dot com
2020-03-13  5:00 ` pinskia at gcc dot gnu.org
2020-03-16  3:34 ` felix.yang at huawei dot com
2020-03-20 14:23 ` wdijkstr at arm dot com
2021-07-25  1:14 ` [Bug tree-optimization/94026] " pinskia at gcc dot gnu.org
2022-06-24 15:48 ` segher at gcc dot gnu.org
2022-06-24 16:30 ` law at gcc dot gnu.org
2022-06-24 17:30 ` segher at gcc dot gnu.org
2022-06-24 18:07 ` segher at gcc dot gnu.org
2022-06-24 20:06 ` segher at gcc dot gnu.org
2022-06-27  6:45 ` cvs-commit at gcc dot gnu.org
2022-07-03 20:55 ` roger at nextmovesoftware dot com
2022-08-09 17:57 ` cvs-commit at gcc dot gnu.org [this message]

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-94026-4-C0RV58Hcqb@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).