public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "rdapp at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug target/106701] Compiler does not take into account number range limitation to avoid subtract from immediate Date: Wed, 24 Aug 2022 07:57:01 +0000 [thread overview] Message-ID: <bug-106701-4-fKSSKc1TJ0@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-106701-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106701 rdapp at gcc dot gnu.org changed: What |Removed |Added ---------------------------------------------------------------------------- Target|s390 |s390 x86_64-linux-gnu CC| |glisse at gcc dot gnu.org, | |rdapp at gcc dot gnu.org, | |rguenth at gcc dot gnu.org Summary|s390: Compiler does not |Compiler does not take into |take into account number |account number range |range limitation to avoid |limitation to avoid |subtract from immediate |subtract from immediate --- Comment #1 from rdapp at gcc dot gnu.org --- Added x86 to targets because we don't seem to optimize this there either (at least I didn't see it on my recent-ish GCC). The following (not regtested) helps on s390 diff --git a/gcc/match.pd b/gcc/match.pd index e486b4be282c..2ebbf68010f9 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -7992,3 +7992,27 @@ and, (match (bitwise_induction_p @0 @2 @3) (bit_not (nop_convert1? (bit_xor@0 (convert2? (lshift integer_onep@1 @2)) @3)))) + +/* cst - a -> cst ^ a if 0 >= a <= cst and integer_pow2p (cst + 1). */ +#if GIMPLE +(simplify + (minus INTEGER_CST@0 @1) + (with { + wide_int w = wi::to_wide (@0) + 1; + value_range vr; + wide_int wmin = w; + wide_int wmax = w; + if (get_global_range_query ()->range_of_expr (vr, @1) + && vr.kind () == VR_RANGE) + { + wmin = vr.lower_bound (); + wmax = vr.upper_bound (); + } + } + (if (wi::exact_log2 (w) != -1 + && wi::geu_p (wmin, 0) + && wi::leu_p (wmax, w)) + (bit_xor @0 @1)) + ) +) +#endif but it can surely be improved by some match.pd magic still. A second question would be, do we unconditionally want to simplify this or should it rather be backend dependent?
next parent reply other threads:[~2022-08-24 7:57 UTC|newest] Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top [not found] <bug-106701-4@http.gcc.gnu.org/bugzilla/> 2022-08-24 7:57 ` rdapp at gcc dot gnu.org [this message] 2022-08-24 10:02 ` rguenth at gcc dot gnu.org 2022-08-24 12:02 ` rdapp at gcc dot gnu.org 2022-08-24 13:45 ` rguenther at suse dot de 2022-08-24 15:02 ` 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-106701-4-fKSSKc1TJ0@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).