public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/98322] New: optimizes to false instead true
@ 2020-12-16 17:09 sucicf1 at outlook dot com
  2020-12-16 17:16 ` [Bug c++/98322] " ktkachov at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: sucicf1 at outlook dot com @ 2020-12-16 17:09 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 98322
           Summary: optimizes to false instead true
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sucicf1 at outlook dot com
  Target Milestone: ---

bool always_true (bool a, bool b)
{
        return (a == b) == (~a ^ b);
} 

is optimized to 

xorl    %eax, %eax
        ret

instead return 1.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/98322] optimizes to false instead true
  2020-12-16 17:09 [Bug c++/98322] New: optimizes to false instead true sucicf1 at outlook dot com
@ 2020-12-16 17:16 ` ktkachov at gcc dot gnu.org
  2020-12-16 17:41 ` jakub at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: ktkachov at gcc dot gnu.org @ 2020-12-16 17:16 UTC (permalink / raw)
  To: gcc-bugs

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

ktkachov at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
                 CC|                            |ktkachov at gcc dot gnu.org
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #1 from ktkachov at gcc dot gnu.org ---
I don't think that's true.
Note, that with -Wall you get the warning:
true.c: In function 'always_true':
true.c:3:29: warning: '~' on a boolean expression [-Wbool-operation]
    3 |         return (a == b) == (~a ^ b);
      |                             ^
true.c:3:29: note: did you mean to use logical not?
    3 |         return (a == b) == (~a ^ b);
      |                             ^
      |

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/98322] optimizes to false instead true
  2020-12-16 17:09 [Bug c++/98322] New: optimizes to false instead true sucicf1 at outlook dot com
  2020-12-16 17:16 ` [Bug c++/98322] " ktkachov at gcc dot gnu.org
@ 2020-12-16 17:41 ` jakub at gcc dot gnu.org
  2020-12-16 17:46 ` sucicf1 at outlook dot com
  2020-12-16 17:48 ` jakub at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-12-16 17:41 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Yeah, folding it to return false; is the right thing.
~a ^ b is ~(int) (a ^ b) in C++, so if a == b, it is ~0 (on two's complement
-1),
and if a != b, then it is ~1 (on two's complement -2).
1 != -1
and
0 != -2
so it is always false.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/98322] optimizes to false instead true
  2020-12-16 17:09 [Bug c++/98322] New: optimizes to false instead true sucicf1 at outlook dot com
  2020-12-16 17:16 ` [Bug c++/98322] " ktkachov at gcc dot gnu.org
  2020-12-16 17:41 ` jakub at gcc dot gnu.org
@ 2020-12-16 17:46 ` sucicf1 at outlook dot com
  2020-12-16 17:48 ` jakub at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: sucicf1 at outlook dot com @ 2020-12-16 17:46 UTC (permalink / raw)
  To: gcc-bugs

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

Ivan Sučić <sucicf1 at outlook dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|INVALID                     |FIXED

--- Comment #3 from Ivan Sučić <sucicf1 at outlook dot com> ---
Sorry for false report.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/98322] optimizes to false instead true
  2020-12-16 17:09 [Bug c++/98322] New: optimizes to false instead true sucicf1 at outlook dot com
                   ` (2 preceding siblings ...)
  2020-12-16 17:46 ` sucicf1 at outlook dot com
@ 2020-12-16 17:48 ` jakub at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-12-16 17:48 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|FIXED                       |INVALID

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-12-16 17:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-16 17:09 [Bug c++/98322] New: optimizes to false instead true sucicf1 at outlook dot com
2020-12-16 17:16 ` [Bug c++/98322] " ktkachov at gcc dot gnu.org
2020-12-16 17:41 ` jakub at gcc dot gnu.org
2020-12-16 17:46 ` sucicf1 at outlook dot com
2020-12-16 17:48 ` jakub at gcc dot gnu.org

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).