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/110932] [14 Regression] Dead Code Elimination Regression since r14-2230-g7e904d6c7f2
Date: Sat, 19 Aug 2023 13:59:44 +0000	[thread overview]
Message-ID: <bug-110932-4-u2RbukVFG5@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-110932-4@http.gcc.gnu.org/bugzilla/>

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2023-08-19

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
  _41 = _43 <= 0;
  # RANGE [irange] unsigned short [0, 1] NONZERO 0x1
  _40 = (unsigned short) _41;
  # RANGE [irange] unsigned short [65534, +INF]
  _36 = ~_40;
  # RANGE [irange] short int [-2, -1]
  _19 = (short intD.17) _36;
  # RANGE [irange] unsigned int [4294967294, +INF]
  _17 = (unsigned intD.9) _19; // ~(unsigned)_41
   // rather _41 ? 4294967294 : 4294967295
  i.1_14 = (unsigned intD.9) pretmp_60;
  _13 = i.1_14 < _17;
  # RANGE [irange] int [0, 1] NONZERO 0x1
  _12 = (intD.6) _13;
  if (_12 == pretmp_60)


pretmp_60 == (((unsigned intD.9) pretmp_60) < _17)

Which is:
(pretmp_60  == 1 && ((unsigned intD.9) pretmp_60) < _17))
| (pretmp_60  == 0 && ((unsigned intD.9) pretmp_60) >= _17))
Though ((unsigned intD.9) pretmp_60) >= _17) is always false because _17's
range does not include 0.

So we are left with:
(pretmp_60  == 1 && 1 < _17)
But _17's range is always bigger than 0 so we are just left with:
pretmp_60 == 1


So the general rule is:
(simplify
 (eq:c @0 (convert (cmp @1 @2)))
 (if (bitwise_equal_p (@0, @1))
 (with {
    bool zeroalwaystrue = ...
    bool zeroalwaysfalse = ...
    bool onealwaystrue = ...
    bool onealwaysfalse = ...
  }
  (switch
   (if (zeroalwaystrue && onealwaystrue)
    (le @0:unsigned { one(unsigned); } )) // @0 == 0 | @0 == 1
   (if (zeroalwaysfalse && onealwaysfalse )
    { false_bool; }) // false
   (if (zeroalwaystrue && onealwaysfalse)
    (eq @0 { zero(TREE_TYPE(@0)); })) // @0 == 0
   (if (onealwaystrue && onealwaysfalse)
    (eq @0 { one(TREE_TYPE(@0)); })) // @0 == 1

Later on instead of `if (_12 == _50)` we would have `if (_50 == 1)`
```
  if (_50 == 1)
    goto <bb 4>; [51.12%]
  else
    goto <bb 3>; [48.88%]
...
  <bb 4> [local count: 278223726]:
  if (_50 != 0)
    goto <bb 5>; [33.00%]
  else
    goto <bb 15>; [67.00%]
```
Which is an obvious case where we know _50 is 1 in bb 4 and therefore !=0.
etc.

  parent reply	other threads:[~2023-08-19 13:59 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-07 10:42 [Bug tree-optimization/110932] New: " theodort at inf dot ethz.ch
2023-08-07 12:08 ` [Bug tree-optimization/110932] " rguenth at gcc dot gnu.org
2023-08-19 13:59 ` pinskia at gcc dot gnu.org [this message]
2023-08-19 14:01 ` pinskia at gcc dot gnu.org
2024-03-07 23:25 ` law at gcc dot gnu.org
2024-05-07  7:41 ` [Bug tree-optimization/110932] [14/15 " rguenth 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-110932-4-u2RbukVFG5@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).