public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/111282] New: `a & (b ^ ~a)` (or `a & ~(a ^ b)`) not optimized to `a & b` in gimple
@ 2023-09-04  6:03 pinskia at gcc dot gnu.org
  2023-09-04  6:04 ` [Bug tree-optimization/111282] " pinskia at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-04  6:03 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 111282
           Summary: `a & (b ^ ~a)` (or `a & ~(a ^ b)`) not optimized to `a
                    & b` in gimple
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
          Assignee: pinskia at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---

Take:
```
int f(int a, int b)
{
        return a & (b ^ ~a);
}
``
This should be optimized to `a & b` which it is on the RTL.

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

* [Bug tree-optimization/111282] `a & (b ^ ~a)` (or `a & ~(a ^ b)`) not optimized to `a & b` in gimple
  2023-09-04  6:03 [Bug tree-optimization/111282] New: `a & (b ^ ~a)` (or `a & ~(a ^ b)`) not optimized to `a & b` in gimple pinskia at gcc dot gnu.org
@ 2023-09-04  6:04 ` pinskia at gcc dot gnu.org
  2023-09-04  6:09 ` pinskia at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-04  6:04 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2023-09-04
     Ever confirmed|0                           |1

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

* [Bug tree-optimization/111282] `a & (b ^ ~a)` (or `a & ~(a ^ b)`) not optimized to `a & b` in gimple
  2023-09-04  6:03 [Bug tree-optimization/111282] New: `a & (b ^ ~a)` (or `a & ~(a ^ b)`) not optimized to `a & b` in gimple pinskia at gcc dot gnu.org
  2023-09-04  6:04 ` [Bug tree-optimization/111282] " pinskia at gcc dot gnu.org
@ 2023-09-04  6:09 ` pinskia at gcc dot gnu.org
  2023-09-04  7:26 ` pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-04  6:09 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note we will need to detect both `a & (b ^ ~a)` and `a & ~(a ^ b)` since a
might be comparison too.

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

* [Bug tree-optimization/111282] `a & (b ^ ~a)` (or `a & ~(a ^ b)`) not optimized to `a & b` in gimple
  2023-09-04  6:03 [Bug tree-optimization/111282] New: `a & (b ^ ~a)` (or `a & ~(a ^ b)`) not optimized to `a & b` in gimple pinskia at gcc dot gnu.org
  2023-09-04  6:04 ` [Bug tree-optimization/111282] " pinskia at gcc dot gnu.org
  2023-09-04  6:09 ` pinskia at gcc dot gnu.org
@ 2023-09-04  7:26 ` pinskia at gcc dot gnu.org
  2023-10-03  3:12 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-04  7:26 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note `|` case already handled by r8-4395:
/* a | ~(a ^ b)  -->  a | ~b  */
(simplify
 (bit_ior:c @0 (bit_not:s (bit_xor:c @0 @1)))
 (bit_ior @0 (bit_not @1)))

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

* [Bug tree-optimization/111282] `a & (b ^ ~a)` (or `a & ~(a ^ b)`) not optimized to `a & b` in gimple
  2023-09-04  6:03 [Bug tree-optimization/111282] New: `a & (b ^ ~a)` (or `a & ~(a ^ b)`) not optimized to `a & b` in gimple pinskia at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2023-09-04  7:26 ` pinskia at gcc dot gnu.org
@ 2023-10-03  3:12 ` pinskia at gcc dot gnu.org
  2023-10-10 20:03 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-10-03  3:12 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #1)
> Note we will need to detect both `a & (b ^ ~a)` and `a & ~(a ^ b)` since a
> might be comparison too.

Well and that will handle:
```
int f0(int a, int b)
{
        return (~a) & (b ^ a); // ~a & b
}
```
Which we don't currently.

on the RTL level, we currently simplify that to:
(a | b) ^ a


The interesting thing is we do simplify the above in tree via the following
pattern:
/* (X | Y) ^ X -> Y & ~ X */

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

* [Bug tree-optimization/111282] `a & (b ^ ~a)` (or `a & ~(a ^ b)`) not optimized to `a & b` in gimple
  2023-09-04  6:03 [Bug tree-optimization/111282] New: `a & (b ^ ~a)` (or `a & ~(a ^ b)`) not optimized to `a & b` in gimple pinskia at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2023-10-03  3:12 ` pinskia at gcc dot gnu.org
@ 2023-10-10 20:03 ` pinskia at gcc dot gnu.org
  2023-10-11  0:48 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-10-10 20:03 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Created attachment 56090
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=56090&action=edit
Patch under testing

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

* [Bug tree-optimization/111282] `a & (b ^ ~a)` (or `a & ~(a ^ b)`) not optimized to `a & b` in gimple
  2023-09-04  6:03 [Bug tree-optimization/111282] New: `a & (b ^ ~a)` (or `a & ~(a ^ b)`) not optimized to `a & b` in gimple pinskia at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2023-10-10 20:03 ` pinskia at gcc dot gnu.org
@ 2023-10-11  0:48 ` pinskia at gcc dot gnu.org
  2023-10-11 16:46 ` cvs-commit at gcc dot gnu.org
  2023-10-11 16:47 ` pinskia at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-10-11  0:48 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

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

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

* [Bug tree-optimization/111282] `a & (b ^ ~a)` (or `a & ~(a ^ b)`) not optimized to `a & b` in gimple
  2023-09-04  6:03 [Bug tree-optimization/111282] New: `a & (b ^ ~a)` (or `a & ~(a ^ b)`) not optimized to `a & b` in gimple pinskia at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2023-10-11  0:48 ` pinskia at gcc dot gnu.org
@ 2023-10-11 16:46 ` cvs-commit at gcc dot gnu.org
  2023-10-11 16:47 ` pinskia at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-10-11 16:46 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 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:e8d418df3dc609f27487deece796d4aa69004b8c

commit r14-4561-ge8d418df3dc609f27487deece796d4aa69004b8c
Author: Andrew Pinski <pinskia@gmail.com>
Date:   Tue Oct 10 12:45:56 2023 -0700

    MATCH: [PR111282] Simplify `a & (b ^ ~a)` to `a & b`

    While `a & (b ^ ~a)` is optimized to `a & b` on the rtl level,
    it is always good to optimize this at the gimple level and allows
    us to match a few extra things including where a is a comparison.

    Note I had to update/change the testcase and-1.c to avoid matching
    this case as we can match -2 and 1 as bitwise inversions.

            PR tree-optimization/111282

    gcc/ChangeLog:

            * match.pd (`a & ~(a ^ b)`, `a & (a == b)`,
            `a & ((~a) ^ b)`): New patterns.

    gcc/testsuite/ChangeLog:

            * gcc.dg/tree-ssa/and-1.c: Update testcase to avoid
            matching `~1 & (a ^ 1)` simplification.
            * gcc.dg/tree-ssa/bitops-6.c: New test.

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

* [Bug tree-optimization/111282] `a & (b ^ ~a)` (or `a & ~(a ^ b)`) not optimized to `a & b` in gimple
  2023-09-04  6:03 [Bug tree-optimization/111282] New: `a & (b ^ ~a)` (or `a & ~(a ^ b)`) not optimized to `a & b` in gimple pinskia at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2023-10-11 16:46 ` cvs-commit at gcc dot gnu.org
@ 2023-10-11 16:47 ` pinskia at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-10-11 16:47 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

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

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

end of thread, other threads:[~2023-10-11 16:47 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-04  6:03 [Bug tree-optimization/111282] New: `a & (b ^ ~a)` (or `a & ~(a ^ b)`) not optimized to `a & b` in gimple pinskia at gcc dot gnu.org
2023-09-04  6:04 ` [Bug tree-optimization/111282] " pinskia at gcc dot gnu.org
2023-09-04  6:09 ` pinskia at gcc dot gnu.org
2023-09-04  7:26 ` pinskia at gcc dot gnu.org
2023-10-03  3:12 ` pinskia at gcc dot gnu.org
2023-10-10 20:03 ` pinskia at gcc dot gnu.org
2023-10-11  0:48 ` pinskia at gcc dot gnu.org
2023-10-11 16:46 ` cvs-commit at gcc dot gnu.org
2023-10-11 16:47 ` 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).