public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/111432] New: `bool & (a|1)` is not optimized to just `bool`
@ 2023-09-16 4:11 pinskia at gcc dot gnu.org
2023-10-10 21:47 ` [Bug tree-optimization/111432] " pinskia at gcc dot gnu.org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-16 4:11 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111432
Bug ID: 111432
Summary: `bool & (a|1)` is not optimized to just `bool`
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: enhancement
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: pinskia at gcc dot gnu.org
Target Milestone: ---
take:
```
int
foo3(int c, int bb)
{
if ((bb & ~3)!=0) __builtin_unreachable();
return (bb & (c|3));
}
int
foo_bool(int c, _Bool bb)
{
return (bb & (c|7));
}
```
foo3 should be optimized to just `return bb`, likewise for foo_bool.
Note LLVM does this.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/111432] `bool & (a|1)` is not optimized to just `bool`
2023-09-16 4:11 [Bug tree-optimization/111432] New: `bool & (a|1)` is not optimized to just `bool` pinskia at gcc dot gnu.org
@ 2023-10-10 21:47 ` pinskia at gcc dot gnu.org
2023-10-14 0:57 ` pinskia at gcc dot gnu.org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-10-10 21:47 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111432
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
Last reconfirmed| |2023-10-10
Ever confirmed|0 |1
Status|UNCONFIRMED |ASSIGNED
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The reason why this is correct is:
a & (x | CST) -> (a & x) | (a & CST) -> // due to `a & CST -> a`
(a & x) | a -> a
So:
```
/* `a & (x | CST)` -> a if we know that (a & ~CST) == 0 */
(simplify
(bit_and:c SSA_NAME@0 (bit_ior @1 INTEGER_CST@2))
(if (INTEGRAL_TYPE_P (TREE_TYPE (@0))
&& wi::bit_and_not (get_nonzero_bits (@0), wi::to_wide (@2)) == 0)
@0))
```
// a | (x & CST) simplifies down to `(a | x) & CST` but I don't see if that is
an improvement here as we still have 2 operations.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/111432] `bool & (a|1)` is not optimized to just `bool`
2023-09-16 4:11 [Bug tree-optimization/111432] New: `bool & (a|1)` is not optimized to just `bool` pinskia at gcc dot gnu.org
2023-10-10 21:47 ` [Bug tree-optimization/111432] " pinskia at gcc dot gnu.org
@ 2023-10-14 0:57 ` pinskia at gcc dot gnu.org
2023-10-17 16:04 ` cvs-commit at gcc dot gnu.org
2023-10-17 16:04 ` pinskia at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-10-14 0:57 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111432
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
URL| |https://gcc.gnu.org/piperma
| |il/gcc-patches/2023-October
| |/632988.html
Keywords| |patch
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Patch posted:
https://gcc.gnu.org/pipermail/gcc-patches/2023-October/632988.html
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/111432] `bool & (a|1)` is not optimized to just `bool`
2023-09-16 4:11 [Bug tree-optimization/111432] New: `bool & (a|1)` is not optimized to just `bool` pinskia at gcc dot gnu.org
2023-10-10 21:47 ` [Bug tree-optimization/111432] " pinskia at gcc dot gnu.org
2023-10-14 0:57 ` pinskia at gcc dot gnu.org
@ 2023-10-17 16:04 ` cvs-commit at gcc dot gnu.org
2023-10-17 16:04 ` pinskia at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-10-17 16:04 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111432
--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Andrew Pinski <pinskia@gcc.gnu.org>:
https://gcc.gnu.org/g:b18d1cabe2f9cccc0cad697e1e0bfd2abebb85f9
commit r14-4686-gb18d1cabe2f9cccc0cad697e1e0bfd2abebb85f9
Author: Andrew Pinski <pinskia@gmail.com>
Date: Fri Oct 13 13:27:18 2023 -0700
MATCH: [PR111432] Simplify `a & (x | CST)` to a when we know that (a &
~CST) == 0
This adds the simplification `a & (x | CST)` to a when we know that
`(a & ~CST) == 0`. In a similar fashion as `a & CST` is handle.
I looked into handling `a | (x & CST)` but that I don't see any decent
simplifications happening.
OK? Bootstrapped and tested on x86_linux-gnu with no regressions.
PR tree-optimization/111432
gcc/ChangeLog:
* match.pd (`a & (x | CST)`): New pattern.
gcc/testsuite/ChangeLog:
* gcc.dg/tree-ssa/bitops-7.c: New test.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/111432] `bool & (a|1)` is not optimized to just `bool`
2023-09-16 4:11 [Bug tree-optimization/111432] New: `bool & (a|1)` is not optimized to just `bool` pinskia at gcc dot gnu.org
` (2 preceding siblings ...)
2023-10-17 16:04 ` cvs-commit at gcc dot gnu.org
@ 2023-10-17 16:04 ` pinskia at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-10-17 16:04 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111432
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Target Milestone|--- |14.0
Status|ASSIGNED |RESOLVED
--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Fixed.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-10-17 16:04 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-16 4:11 [Bug tree-optimization/111432] New: `bool & (a|1)` is not optimized to just `bool` pinskia at gcc dot gnu.org
2023-10-10 21:47 ` [Bug tree-optimization/111432] " pinskia at gcc dot gnu.org
2023-10-14 0:57 ` pinskia at gcc dot gnu.org
2023-10-17 16:04 ` cvs-commit at gcc dot gnu.org
2023-10-17 16:04 ` 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).