public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "rguenth at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/30267] folding (~ -x) >= (-2147483647-1) to x != -2147483648
Date: Wed, 27 Dec 2006 16:48:00 -0000	[thread overview]
Message-ID: <20061227164837.5261.qmail@sourceware.org> (raw)
In-Reply-To: <bug-30267-128@http.gcc.gnu.org/bugzilla/>



------- Comment #1 from rguenth at gcc dot gnu dot org  2006-12-27 16:48 -------
This is folded to

;; Function notneg (notneg)
;; enabled by -tree-original


{
  return x != -2147483648;
}



;; Function negnot (negnot)
;; enabled by -tree-original

{
  return x != 2147483647;
}

via

      /* Convert - (~A) to A + 1.  */
      if (INTEGRAL_TYPE_P (type) && TREE_CODE (arg0) == BIT_NOT_EXPR)
        return fold_build2 (PLUS_EXPR, type, TREE_OPERAND (arg0, 0),
                            build_int_cst (type, 1));

and

      /* Convert ~ (-A) to A - 1.  */
      else if (INTEGRAL_TYPE_P (type) && TREE_CODE (arg0) == NEGATE_EXPR)
        return fold_build2 (MINUS_EXPR, type, TREE_OPERAND (arg0, 0),
                            build_int_cst (type, 1));

and

      /* Transform comparisons of the form X +- C1 CMP C2 to X CMP C2 +- C1. 
*/      if ((TREE_CODE (arg0) == PLUS_EXPR || TREE_CODE (arg0) == MINUS_EXPR)
          && (TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST
              && !TREE_OVERFLOW (TREE_OPERAND (arg0, 1))
              && !TYPE_UNSIGNED (TREE_TYPE (arg1))
              && !(flag_wrapv || flag_trapv))
          && (TREE_CODE (arg1) == INTEGER_CST
              && !TREE_OVERFLOW (arg1)))
        {
          tree const1 = TREE_OPERAND (arg0, 1);
          tree const2 = arg1;
          tree variable = TREE_OPERAND (arg0, 0);
          tree lhs;
          int lhs_add;
          lhs_add = TREE_CODE (arg0) != PLUS_EXPR;

          lhs = fold_build2 (lhs_add ? PLUS_EXPR : MINUS_EXPR,
                             TREE_TYPE (arg1), const2, const1);
          if (TREE_CODE (lhs) == TREE_CODE (arg1)
              && (TREE_CODE (lhs) != INTEGER_CST
                  || !TREE_OVERFLOW (lhs)))
            return fold_build2 (code, type, variable, lhs);
        }

(citing from the 4.1 branch)

Note this is actually wrong-code.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rguenth at gcc dot gnu dot
                   |                            |org
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
           Keywords|                            |wrong-code
      Known to fail|                            |4.1.2 4.3.0
      Known to work|                            |4.0.3
   Last reconfirmed|0000-00-00 00:00:00         |2006-12-27 16:48:37
               date|                            |
            Summary|missed optimization due to  |folding (~ -x) >= (-
                   |bad range propagation       |2147483647-1) to x != -
                   |without -fwrapv             |2147483648


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30267


  reply	other threads:[~2006-12-27 16:48 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-20 14:35 [Bug c/30267] New: missed optimization due to bad range propagation without -fwrapv bruno at clisp dot org
2006-12-27 16:48 ` rguenth at gcc dot gnu dot org [this message]
2006-12-27 17:01 ` [Bug middle-end/30267] folding (~ -x) >= (-2147483647-1) to x != -2147483648 pinskia at gcc dot gnu dot org
     [not found] <bug-30267-4@http.gcc.gnu.org/bugzilla/>
2021-06-08  8:47 ` pinskia at gcc dot gnu.org
2021-06-08 11:09 ` bruno at clisp dot 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=20061227164837.5261.qmail@sourceware.org \
    --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).