public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/98709] New: gcc optimizes bitwise operations, but doesn't optimize logical ones
@ 2021-01-17 1:31 vanyacpp at gmail dot com
2021-01-17 17:34 ` [Bug middle-end/98709] " glisse at gcc dot gnu.org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: vanyacpp at gmail dot com @ 2021-01-17 1:31 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98709
Bug ID: 98709
Summary: gcc optimizes bitwise operations, but doesn't optimize
logical ones
Product: gcc
Version: 10.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: vanyacpp at gmail dot com
Target Milestone: ---
GCC 10.2 produces very good code for this function noticing that both sides of
conjuntion are the same:
unsigned foo_bitwise(unsigned a, unsigned b)
{
return (~a ^ b) & ~(a ^ b);
}
foo_bitwise(unsigned int, unsigned int):
xor edi, esi
mov eax, edi
not eax
ret
But when I write a similar function with logical operations it doesn't notice
that:
bool foo_logical(bool a, bool b)
{
return (!a ^ b) & !(a ^ b);
}
foo_logical(bool, bool):
mov eax, esi
xor eax, edi
xor eax, 1
cmp dil, sil
sete dl
and eax, edx
ret
I believe that in a similar manner it can be optimized to something like this:
foo_logical(bool, bool):
xor edi, esi
mov eax, edi
xor eax, 1
ret
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug middle-end/98709] gcc optimizes bitwise operations, but doesn't optimize logical ones
2021-01-17 1:31 [Bug middle-end/98709] New: gcc optimizes bitwise operations, but doesn't optimize logical ones vanyacpp at gmail dot com
@ 2021-01-17 17:34 ` glisse at gcc dot gnu.org
2021-08-01 18:17 ` [Bug tree-optimization/98709] " pinskia at gcc dot gnu.org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: glisse at gcc dot gnu.org @ 2021-01-17 17:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98709
--- Comment #1 from Marc Glisse <glisse at gcc dot gnu.org> ---
At the end of gimple, we have
_6 = a_3(D) ^ b_4(D);
_1 = ~_6;
_2 = a_3(D) == b_4(D);
_7 = _1 & _2;
I guess we are missing a simplification of ~(a^b) to a==b for bool (similar to
~(a!=b) be we canonicalize != to ^).
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/98709] gcc optimizes bitwise operations, but doesn't optimize logical ones
2021-01-17 1:31 [Bug middle-end/98709] New: gcc optimizes bitwise operations, but doesn't optimize logical ones vanyacpp at gmail dot com
2021-01-17 17:34 ` [Bug middle-end/98709] " glisse at gcc dot gnu.org
@ 2021-08-01 18:17 ` pinskia at gcc dot gnu.org
2022-08-10 11:46 ` vanyacpp at gmail dot com
2022-10-22 2:13 ` pinskia at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-01 18:17 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98709
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Depends on| |101706
Last reconfirmed| |2021-08-01
Component|middle-end |tree-optimization
Status|UNCONFIRMED |NEW
Severity|normal |enhancement
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.
I noticed the ~(a^b) issue the other day (not even knowing about this bug) and
filed PR 101706 for that :)
Referenced Bugs:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101706
[Bug 101706] bool0^bool1^1 -> bool0 == bool1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/98709] gcc optimizes bitwise operations, but doesn't optimize logical ones
2021-01-17 1:31 [Bug middle-end/98709] New: gcc optimizes bitwise operations, but doesn't optimize logical ones vanyacpp at gmail dot com
2021-01-17 17:34 ` [Bug middle-end/98709] " glisse at gcc dot gnu.org
2021-08-01 18:17 ` [Bug tree-optimization/98709] " pinskia at gcc dot gnu.org
@ 2022-08-10 11:46 ` vanyacpp at gmail dot com
2022-10-22 2:13 ` pinskia at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: vanyacpp at gmail dot com @ 2022-08-10 11:46 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98709
Ivan Sorokin <vanyacpp at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution|--- |FIXED
--- Comment #3 from Ivan Sorokin <vanyacpp at gmail dot com> ---
This issue was fixed in PR106379 by Richard Biener.
https://gcc.gnu.org/g:375668e0508fbe173af1ed519d8ae2b79f388d94
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/98709] gcc optimizes bitwise operations, but doesn't optimize logical ones
2021-01-17 1:31 [Bug middle-end/98709] New: gcc optimizes bitwise operations, but doesn't optimize logical ones vanyacpp at gmail dot com
` (2 preceding siblings ...)
2022-08-10 11:46 ` vanyacpp at gmail dot com
@ 2022-10-22 2:13 ` pinskia at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-10-22 2:13 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98709
Bug 98709 depends on bug 101706, which changed state.
Bug 101706 Summary: bool0^bool1^1 -> bool0 == bool1
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101706
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-10-22 2:13 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-17 1:31 [Bug middle-end/98709] New: gcc optimizes bitwise operations, but doesn't optimize logical ones vanyacpp at gmail dot com
2021-01-17 17:34 ` [Bug middle-end/98709] " glisse at gcc dot gnu.org
2021-08-01 18:17 ` [Bug tree-optimization/98709] " pinskia at gcc dot gnu.org
2022-08-10 11:46 ` vanyacpp at gmail dot com
2022-10-22 2:13 ` pinskia 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).