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/97690] (cond ? 2 : 0) is not optimized to int(cond) << 1
Date: Wed, 04 Nov 2020 11:15:45 +0000	[thread overview]
Message-ID: <bug-97690-4-P1YfABggl5@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-97690-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:3e190757fa332d327bee27495f37beb01155cfab

commit r11-4717-g3e190757fa332d327bee27495f37beb01155cfab
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Wed Nov 4 11:55:29 2020 +0100

    phiopt: Optimize x ? 1024 : 0 to (int) x << 10 [PR97690]

    The following patch generalizes the x ? 1 : 0 -> (int) x optimization
    to handle also left shifts by constant.

    During x86_64-linux and i686-linux bootstraps + regtests it triggered
    in 1514 unique non-LTO -m64 cases (sort -u on log mentioning
    filename, function name and shift count) and 1866 -m32 cases.

    Unfortunately, the patch regresses (before the tests have been adjusted):
    +FAIL: gcc.dg/tree-ssa/ssa-ccp-11.c scan-tree-dump-times optimized "if " 0
    +FAIL: gcc.dg/vect/bb-slp-pattern-2.c -flto -ffat-lto-objects 
scan-tree-dump-times slp1 "optimized: basic block" 1
    +FAIL: gcc.dg/vect/bb-slp-pattern-2.c scan-tree-dump-times slp1 "optimized:
basic block" 1
    and in both cases it actually results in worse code.

    > > We'd need some optimization that would go through all PHI edges and
    > > compute if some use of the phi results don't actually compute a
constant
    > > across all the PHI edges - 1 & 0 and 0 & 1 is always 0.

    > PRE should do this, IMHO only optimizing it at -O2 is fine.

    > > Similarly, in the slp vectorization test there is:
    > >      a[0] = b[0] ? 1 : 7;

    > note this, carefully avoiding the already "optimized" b[0] ? 1 : 0 ...

    > So the option is to put : 7 in the 2, 4 an 8 case as well.  The testcase
    > wasn't added for any real-world case but is artificial I guess for
    > COND_EXPR handling of invariants.

    > But yeah, for things like SLP it means we eventually have to
    > implement reverse transforms for all of this to make the lanes
    > matching.  But that's true anyway for things like x + 1 vs. x + 0
    > or x / 3 vs. x / 2 or other simplifications we do.

    2020-11-04  Jakub Jelinek  <jakub@redhat.com>

            PR tree-optimization/97690
            * tree-ssa-phiopt.c (conditional_replacement): Also optimize
            cond ? pow2p_cst : 0 as ((type) cond) << cst.

            * gcc.dg/tree-ssa/phi-opt-22.c: New test.
            * gcc.dg/tree-ssa/ssa-ccp-11.c: Use -O2 instead of -O1.
            * gcc.dg/vect/bb-slp-pattern-2.c (foo): Use ? 2 : 7, ? 4 : 7 and
            ? 8 : 7 instead of ? 2 : 0, ? 4 : 0, ? 8 : 0.

  parent reply	other threads:[~2020-11-04 11:15 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-03 10:28 [Bug tree-optimization/97690] New: " redi at gcc dot gnu.org
2020-11-03 10:30 ` [Bug tree-optimization/97690] " redi at gcc dot gnu.org
2020-11-03 10:37 ` redi at gcc dot gnu.org
2020-11-03 12:55 ` rguenth at gcc dot gnu.org
2020-11-03 17:32 ` jakub at gcc dot gnu.org
2020-11-04 11:15 ` cvs-commit at gcc dot gnu.org [this message]
2021-05-24  7:12 ` pinskia at gcc dot gnu.org
2021-06-01 20:50 ` pinskia 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-97690-4-P1YfABggl5@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).