public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "jakub at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/98865] Missed transform of (a >> 63) * b Date: Thu, 28 Jan 2021 14:26:10 +0000 [thread overview] Message-ID: <bug-98865-4-A0uaNN0DzS@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-98865-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98865 Jakub Jelinek <jakub at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jakub at gcc dot gnu.org --- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> --- PR middle-end/98865 * match.pd (a * (b >> (prec-1)) to ((signed)b >> (prec-1)) & a): New simplification. --- gcc/match.pd.jj 2021-01-22 11:50:09.882909120 +0100 +++ gcc/match.pd 2021-01-28 15:20:20.536238614 +0100 @@ -793,6 +793,16 @@ (define_operator_list COND_TERNARY && tree_nop_conversion_p (type, TREE_TYPE (@1))) (lshift @0 @2))) +/* Fold (a * (b >> (prec-1))) with logical shift into + ((signed)b >> (prec-1)) & a. */ +(simplify + (mult:c @0 (nop_convert? (rshift @1 INTEGER_CST@2))) + (if (INTEGRAL_TYPE_P (TREE_TYPE (@1)) + && TYPE_UNSIGNED (TREE_TYPE (@1)) + && wi::to_widest (@2) + 1 == TYPE_PRECISION (TREE_TYPE (@1))) + (with { tree stype = signed_type_for (TREE_TYPE (@1)); } + (bit_and (convert:type (rshift (convert:stype @1) @2)) @0)))) + /* Fold (1 << (C - x)) where C = precision(type) - 1 into ((1 << C) >> x). */ (simplify (completely untested) does that. It doesn't handle vector types, whether that is a good idea or not depends on how do we deal with the match.pd simplifications after last veclower pass issue. And, given: unsigned long long foo (unsigned long long a, unsigned long long b) { return (a >> 63) * b; } long long bar (long long a, long long b) { return -(a >> 63) * b; } long long baz (long long a, long long b) { long long c = a >> 63; long long d = -c; return d * b; } we optimize with it for and bar but not baz, apparently the -(a >> 63) arithmetic to (a >> 63) logical shift is done only in GENERIC folding and not later.
next prev parent reply other threads:[~2021-01-28 14:26 UTC|newest] Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-01-28 13:38 [Bug middle-end/98865] New: " rguenth at gcc dot gnu.org 2021-01-28 13:40 ` [Bug middle-end/98865] " rguenth at gcc dot gnu.org 2021-01-28 14:26 ` jakub at gcc dot gnu.org [this message] 2021-03-07 2:46 ` pinskia at gcc dot gnu.org 2021-07-20 22:19 ` pinskia at gcc dot gnu.org 2021-09-22 18:19 ` cvs-commit at gcc dot gnu.org 2022-01-11 11:19 ` rguenth at gcc dot gnu.org 2022-05-18 15:24 ` cvs-commit at gcc dot gnu.org 2022-05-19 16:55 ` cvs-commit at gcc dot gnu.org 2022-05-27 8:02 ` cvs-commit at gcc dot gnu.org 2022-05-28 9:18 ` roger at nextmovesoftware dot com
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-98865-4-A0uaNN0DzS@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).