public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "amacleod at redhat dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/114086] Boolean switches could have a lot better codegen, possibly utilizing bit-vectors Date: Mon, 26 Feb 2024 14:58:37 +0000 [thread overview] Message-ID: <bug-114086-4-xTYMHBLVVU@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-114086-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114086 --- Comment #9 from Andrew Macleod <amacleod at redhat dot com> --- (In reply to Jakub Jelinek from comment #8) > Unfortunately doing the ((682 >> x) & 1) to x & 1 optimization in match.pd > isn't possible, we can only use global ranges there and we need path > specific range here. > Can it be done in VRP pass? Though, I'm afraid I'm quite lost where it > actually has > the statement optimizations (rather than mere computing of ranges), > Aldy/Andrew, any hints? I mean like what old tree-vrp.c was doing in > simplify_stmt_using_ranges. I don't think much has changed there... We still call into all the code in vr-values.cc to do simplifications. I think Aldy changed it all to be contained in class 'simplify_using_ranges'.. but those routines are all still in vr-values.cc. tree-vrp calls into the top level simplfy() routine. bool fold_stmt (gimple_stmt_iterator *gsi) override { bool ret = m_simplifier.simplify (gsi); if (!ret) ret = ::fold_stmt (gsi, follow_single_use_edges); return ret; } If that fails, then rangers fold_stmt() is invoked. That is merely a contextual wrapper around a call to gimple-fold::fold_stmt to see if normal folding can find anything. Under the covers I believe that invokes match.pd which, if it was using the current range_query, would get contextual info. > Guess we could duplicate that in match.pd for the case which can use global > range or > doesn't need any range at all. > I mean > unsigned int > foo (int x) > { > return (0xaaaaaaaaU >> x) & 1; > } > > unsigned int > bar (int x) > { > return (0x55555555U >> x) & 1; > } > > unsigned int > baz (int x) > { > if (x >= 22) __builtin_unreachable (); > return (0x5aaaaaU >> x) & 1; > } > can be optimized even with global ranges (or the first one with no ranges). > foo and baz equivalent is x & 1, while bar is (~x) & 1 or (x & 1) ^ 1, dunno > what is more canonical.
prev parent reply other threads:[~2024-02-26 14:58 UTC|newest] Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-02-24 9:58 [Bug middle-end/114086] New: " janschultke at googlemail dot com 2024-02-24 10:14 ` [Bug middle-end/114086] " jakub at gcc dot gnu.org 2024-02-24 10:49 ` janschultke at googlemail dot com 2024-02-24 11:02 ` jakub at gcc dot gnu.org 2024-02-24 11:22 ` jakub at gcc dot gnu.org 2024-02-24 11:27 ` janschultke at googlemail dot com 2024-02-24 11:52 ` [Bug tree-optimization/114086] " jakub at gcc dot gnu.org 2024-02-24 12:13 ` jakub at gcc dot gnu.org 2024-02-26 8:38 ` rguenth at gcc dot gnu.org 2024-02-26 12:04 ` jakub at gcc dot gnu.org 2024-02-26 14:58 ` amacleod at redhat dot com [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-114086-4-xTYMHBLVVU@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).