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/114666] [14 Regression] Signed single bit comparison miscompile at -O2
Date: Tue, 09 Apr 2024 20:35:35 +0000	[thread overview]
Message-ID: <bug-114666-4-636acHGvKH@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-114666-4@http.gcc.gnu.org/bugzilla/>

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |pinskia at gcc dot gnu.org
             Status|NEW                         |ASSIGNED

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---

Folding statement: _3 = _2 ^ 1;
Matching expression match.pd:2835, gimple-match-2.cc:35
Matching expression match.pd:2838, gimple-match-1.cc:66
Matching expression match.pd:2845, gimple-match-2.cc:96
Matching expression match.pd:2243, gimple-match-5.cc:20
Matching expression match.pd:2835, gimple-match-2.cc:35
Matching expression match.pd:2838, gimple-match-1.cc:66
Matching expression match.pd:2845, gimple-match-2.cc:96
Applying pattern match.pd:6795, gimple-match-4.cc:1721
Matching expression match.pd:2243, gimple-match-5.cc:20
Matching expression match.pd:2286, gimple-match-3.cc:23
Matching expression match.pd:2255, gimple-match-4.cc:67
Matching expression match.pd:2243, gimple-match-5.cc:20
Applying pattern match.pd:7103, gimple-match-8.cc:47279
Applying pattern match.pd:5898, gimple-match-8.cc:47191
gimple_simplified to _7 = (long unsigned int) _1;
_8 = -_7;
_3 = _8 ^ 1;

That is wrong.

I can't figure out how we got there though. 
match.pd:6795 is the pattern which does `(convert)a CMP b` into `a CMP
(convert)b` which I assume VRP does `_3 == 0 ? 1 : -2u` which then we get `_1
== 0 ? 1 : -2u` (which seems reasonable) and then we apply match.pd:5898 which
gets us to `_1 ? -2u : 1` which seems wrong as not a boolean  type nor an one
bit unsigned integer.

So the problem is with:
 /* !A ? B : C -> A ? C : B.  */
 (simplify
  (cnd (logical_inverted_value truth_valued_p@0) @1 @2)
  (cnd @0 @2 @1)))

which does not check the types correctly for gimple. Note this pattern has been
there since 2014.
Just been exposed the issue when I added match.pd:7103 in
r14-3110-g7fb65f10285124.

Let me try to figure out what to do here to fix the issue.

  parent reply	other threads:[~2024-04-09 20:35 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-09 20:10 [Bug middle-end/114666] New: " patrick at rivosinc dot com
2024-04-09 20:11 ` [Bug middle-end/114666] " pinskia at gcc dot gnu.org
2024-04-09 20:16 ` pinskia at gcc dot gnu.org
2024-04-09 20:35 ` pinskia at gcc dot gnu.org [this message]
2024-04-09 20:49 ` [Bug tree-optimization/114666] " pinskia at gcc dot gnu.org
2024-04-09 21:03 ` pinskia at gcc dot gnu.org
2024-04-09 21:11 ` pinskia at gcc dot gnu.org
2024-04-09 22:58 ` pinskia at gcc dot gnu.org
2024-04-10 22:04 ` pinskia at gcc dot gnu.org
2024-04-11  1:10 ` pinskia at gcc dot gnu.org
2024-04-12 17:57 ` cvs-commit at gcc dot gnu.org
2024-04-12 17:57 ` 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-114666-4-636acHGvKH@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).