public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "pinskia at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/100958] two_value_replacement should move to match.pd
Date: Sun, 09 Apr 2023 17:21:58 +0000	[thread overview]
Message-ID: <bug-100958-4-cjaCFwuPwR@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-100958-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Here is the start of the conversion to match.pd, there must be an easier way to
see the range too:
#if GIMPLE
/* Optimize
   x in range [cst1, cst2] where cst2 = cst1 + 1
   (x op CSTN) ? CST3 : CST4
   # where op is == or != and N is 1 or 2
   # where cst3 == cst4 + 1 or cst4 == cst3 + 1
   to x + (min (cst3, cst4) - cst1) or
  (min (cst3, cst4) + cst1) - x depending on op, N and which
   of cst3 and cst4 is smaller.  */
(for eqne (eq ne)
 (simplify
  (cond (eqne @0 INTEGER_CST@1) INTEGER_CST@2 INTEGER_CST@3)
  (if (tree_int_cst_lt (@2, @3)
       ? wi::to_widest (@2) + 1 != wi::to_widest (@3)
       : wi::to_widest (@3) + 1 != wi::to_widest (@2))
   (with { wide_int min, max;
           value_range r;
           get_range_query (cfun)->range_of_expr (r, lhs);

           if (r.kind () == VR_RANGE)
             {
               min = r.lower_bound ();
               max = r.upper_bound ();
             }
           else
             {
               int prec = TYPE_PRECISION (TREE_TYPE (lhs));
               signop sgn = TYPE_SIGN (TREE_TYPE (lhs));
               min = wi::min_value (prec, sgn);
               max = wi::max_value (prec, sgn);
             }
         }
    (if (min + 1 == max
         && (wi::to_wide (@1) == min
             || wi::to_wide (@1) == max))

#endif

  parent reply	other threads:[~2023-04-09 17:21 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-08  6:42 [Bug tree-optimization/100958] New: " pinskia at gcc dot gnu.org
2021-06-08  6:42 ` [Bug tree-optimization/100958] " pinskia at gcc dot gnu.org
2023-04-09 17:21 ` pinskia at gcc dot gnu.org [this message]
2023-04-26  3:01 ` pinskia at gcc dot gnu.org
2023-04-28 14:27 ` cvs-commit at gcc dot gnu.org
2023-04-28 14: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-100958-4-cjaCFwuPwR@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).