public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/111543] New: `(a & b) & ~a` could be optimized before reassociation
@ 2023-09-22 18:52 pinskia at gcc dot gnu.org
  2023-09-22 18:56 ` [Bug tree-optimization/111543] " pinskia at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-22 18:52 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 111543
           Summary: `(a & b) & ~a` could be optimized before reassociation
           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:
```
_Bool fb(int x,int y)
{
  _Bool a = x == 1;
  _Bool b = y == 2;
  _Bool t = a & b;
  return t & !a;
}
int fi(int a,int b)
{
  int t = a & b;
  return t & ~a;
}

```
We should optimize both of these to `return 0` in ccp1.

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

* [Bug tree-optimization/111543] `(a & b) & ~a` could be optimized before reassociation
  2023-09-22 18:52 [Bug tree-optimization/111543] New: `(a & b) & ~a` could be optimized before reassociation pinskia at gcc dot gnu.org
@ 2023-09-22 18:56 ` pinskia at gcc dot gnu.org
  2023-09-22 18:56 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-22 18:56 UTC (permalink / raw)
  To: gcc-bugs

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

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|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2023-09-22

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

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

* [Bug tree-optimization/111543] `(a & b) & ~a` could be optimized before reassociation
  2023-09-22 18:52 [Bug tree-optimization/111543] New: `(a & b) & ~a` could be optimized before reassociation pinskia at gcc dot gnu.org
  2023-09-22 18:56 ` [Bug tree-optimization/111543] " pinskia at gcc dot gnu.org
@ 2023-09-22 18:56 ` pinskia at gcc dot gnu.org
  2023-09-23  4:26 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-22 18:56 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED

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

* [Bug tree-optimization/111543] `(a & b) & ~a` could be optimized before reassociation
  2023-09-22 18:52 [Bug tree-optimization/111543] New: `(a & b) & ~a` could be optimized before reassociation pinskia at gcc dot gnu.org
  2023-09-22 18:56 ` [Bug tree-optimization/111543] " pinskia at gcc dot gnu.org
  2023-09-22 18:56 ` pinskia at gcc dot gnu.org
@ 2023-09-23  4:26 ` pinskia at gcc dot gnu.org
  2023-09-23 19:55 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-23  4:26 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
/* (X & ~Y) & Y -> 0 */
(simplify
 (bit_and:c (bit_and @0 @1) @2)
 (with { bool wascmp; }
  (if (bitwise_inverted_equal_p (@0, @2, wascmp)
       || bitwise_inverted_equal_p (@1, @2, wascmp))
   { wascmp ? constant_boolean_node (false, type) : build_zero_cst (type); })))
/* (X | ~Y) | Y -> -1 */
(simplify
 (bit_ior:c (bit_ior @0 @1) @2)
 (with { bool wascmp; }
  (if ((bitwise_inverted_equal_p (@0, @2, wascmp)
        || bitwise_inverted_equal_p (@1, @2, wascmp))
       && (!wascmp || element_precision (type) == 1))
   { build_all_ones_cst (TREE_TYPE (@0)); })))

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

* [Bug tree-optimization/111543] `(a & b) & ~a` could be optimized before reassociation
  2023-09-22 18:52 [Bug tree-optimization/111543] New: `(a & b) & ~a` could be optimized before reassociation pinskia at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2023-09-23  4:26 ` pinskia at gcc dot gnu.org
@ 2023-09-23 19:55 ` pinskia at gcc dot gnu.org
  2023-09-24  6:48 ` cvs-commit at gcc dot gnu.org
  2023-09-24  6:49 ` pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-23 19:55 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch
                URL|                            |https://gcc.gnu.org/piperma
                   |                            |il/gcc-patches/2023-Septemb
                   |                            |er/631235.html

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Patch posted:
https://gcc.gnu.org/pipermail/gcc-patches/2023-September/631235.html

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

* [Bug tree-optimization/111543] `(a & b) & ~a` could be optimized before reassociation
  2023-09-22 18:52 [Bug tree-optimization/111543] New: `(a & b) & ~a` could be optimized before reassociation pinskia at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2023-09-23 19:55 ` pinskia at gcc dot gnu.org
@ 2023-09-24  6:48 ` cvs-commit at gcc dot gnu.org
  2023-09-24  6:49 ` pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-09-24  6:48 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 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:1bf0cd05cb30889cae4b6cf06e80b7f3a13c40c1

commit r14-4241-g1bf0cd05cb30889cae4b6cf06e80b7f3a13c40c1
Author: Andrew Pinski <apinski@marvell.com>
Date:   Sat Sep 23 04:38:02 2023 +0000

    MATCH: Add `(X & ~Y) & Y` and `(X | ~Y) | Y`

    Even though this gets optimized by reassociation, catching it more often
    will always be better.

    Note the reason why I didn't add `(X ^ ~Y) ^ Y` is that it gets caught
    by prefering `~(X ^ Y)` to `(X ^ ~Y)` which then it is caught by the
    the pattern for `(X ^ Y) ^ Y` already.

            PR tree-optimization/111543

    gcc/ChangeLog:

            * match.pd (`(X & ~Y) & Y`, `(X | ~Y) | Y`): New patterns.

    gcc/testsuite/ChangeLog:

            * gcc.dg/tree-ssa/bitops-4.c: New test.

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

* [Bug tree-optimization/111543] `(a & b) & ~a` could be optimized before reassociation
  2023-09-22 18:52 [Bug tree-optimization/111543] New: `(a & b) & ~a` could be optimized before reassociation pinskia at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2023-09-24  6:48 ` cvs-commit at gcc dot gnu.org
@ 2023-09-24  6:49 ` pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-24  6:49 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
   Target Milestone|---                         |14.0
             Status|ASSIGNED                    |RESOLVED

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

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

end of thread, other threads:[~2023-09-24  6:49 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-22 18:52 [Bug tree-optimization/111543] New: `(a & b) & ~a` could be optimized before reassociation pinskia at gcc dot gnu.org
2023-09-22 18:56 ` [Bug tree-optimization/111543] " pinskia at gcc dot gnu.org
2023-09-22 18:56 ` pinskia at gcc dot gnu.org
2023-09-23  4:26 ` pinskia at gcc dot gnu.org
2023-09-23 19:55 ` pinskia at gcc dot gnu.org
2023-09-24  6:48 ` cvs-commit at gcc dot gnu.org
2023-09-24  6:49 ` 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).