public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/111541] New: missing optimization x & ~c | (y | c) -> x | (y | c)
@ 2023-09-22 16:37 vanyacpp at gmail dot com
2023-09-22 18:12 ` [Bug middle-end/111541] " pinskia at gcc dot gnu.org
2023-09-22 18:12 ` pinskia at gcc dot gnu.org
0 siblings, 2 replies; 3+ messages in thread
From: vanyacpp at gmail dot com @ 2023-09-22 16:37 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111541
Bug ID: 111541
Summary: missing optimization x & ~c | (y | c) -> x | (y | c)
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: vanyacpp at gmail dot com
Target Milestone: ---
On this function clang generates shorter code:
unsigned foo(unsigned x, unsigned y, unsigned c)
{
return x & ~c | (y | c);
}
Clang notices that the expression can be simplified to x | (y | c). It would be
great if GCC can do the same.
https://gcc.godbolt.org/z/dMo4nEjrs
This issue is symmetric to the one described in PR 98710. The idea behind this
simplification is the following: when we are working with bitsets, "|" can be
read as adding bits and "&~" as removing. Therefore the expression "x & ~c | (y
| c)" can be read as removing "c" from "x" and then adding "y | c".
So the simplification
x & ~c | (y | c) -> x | (y | c)
means there is no need to remove "c" if later we add something containing "c".
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug middle-end/111541] missing optimization x & ~c | (y | c) -> x | (y | c)
2023-09-22 16:37 [Bug middle-end/111541] New: missing optimization x & ~c | (y | c) -> x | (y | c) vanyacpp at gmail dot com
@ 2023-09-22 18:12 ` pinskia at gcc dot gnu.org
2023-09-22 18:12 ` pinskia at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-22 18:12 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111541
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|normal |enhancement
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.
Note this also should be optimized:
```
_Bool foo1(_Bool x, _Bool y, unsigned a)
{
_Bool c = a != 0;
return x & !c | (y | c);
}
```
Down to:
```
_Bool foo1_(_Bool x, _Bool y, unsigned a)
{
_Bool c = a != 0;
return x | (y | c);
}
```
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug middle-end/111541] missing optimization x & ~c | (y | c) -> x | (y | c)
2023-09-22 16:37 [Bug middle-end/111541] New: missing optimization x & ~c | (y | c) -> x | (y | c) vanyacpp at gmail dot com
2023-09-22 18:12 ` [Bug middle-end/111541] " pinskia at gcc dot gnu.org
@ 2023-09-22 18:12 ` pinskia at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-22 18:12 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111541
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2023-09-22
Ever confirmed|0 |1
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-09-22 18:12 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-22 16:37 [Bug middle-end/111541] New: missing optimization x & ~c | (y | c) -> x | (y | c) vanyacpp at gmail dot com
2023-09-22 18:12 ` [Bug middle-end/111541] " pinskia at gcc dot gnu.org
2023-09-22 18:12 ` 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).