[Bug tree-optimization/95923] Failure to optimize bool checks into and

2023-07-17 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95923

Andrew Pinski  changed:

   What|Removed |Added

   Target Milestone|--- |14.0
 Status|ASSIGNED|RESOLVED
 Resolution|--- |FIXED

--- Comment #10 from Andrew Pinski  ---
Fixed.

[Bug tree-optimization/95923] Failure to optimize bool checks into and

2023-07-17 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95923

--- Comment #9 from CVS Commits  ---
The trunk branch has been updated by Andrew Pinski :

https://gcc.gnu.org/g:0407ae8a7732d90622a65ddf1798c9d51d450e9d

commit r14-2556-g0407ae8a7732d90622a65ddf1798c9d51d450e9d
Author: Andrew Pinski 
Date:   Sun Jul 16 22:31:59 2023 +

PR 95923: More (boolean) bitop simplifications in match.pd

This adds the boolean version of some of the simplifications
that were added with r8-4395-ge268a77b59cb78.

That are the following:
(a | b) & (a == b) --> a & b
a | (a == b)   --> a | (b ^ 1)
(a & b) | (a == b) --> a == b

OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.

gcc/ChangeLog:

PR tree-optimization/95923
* match.pd ((a|b)&(a==b),a|(a==b),(a)|(a==b)): New
transformation.

gcc/testsuite/ChangeLog:

PR tree-optimization/95923
* gcc.dg/tree-ssa/bitops-2.c: New test.
* gcc.dg/tree-ssa/bool-checks-1.c: New test.

[Bug tree-optimization/95923] Failure to optimize bool checks into and

2023-07-16 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95923

Andrew Pinski  changed:

   What|Removed |Added

   Keywords||patch
URL||https://gcc.gnu.org/piperma
   ||il/gcc-patches/2023-July/62
   ||4594.html

--- Comment #8 from Andrew Pinski  ---
Patch posted:
https://gcc.gnu.org/pipermail/gcc-patches/2023-July/624594.html

[Bug tree-optimization/95923] Failure to optimize bool checks into and

2023-07-16 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95923

--- Comment #7 from Andrew Pinski  ---
I will fix the phiopt issue later ...

[Bug tree-optimization/95923] Failure to optimize bool checks into and

2023-07-16 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95923

--- Comment #6 from Andrew Pinski  ---
Created attachment 8
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=8=edit
Patch which I am testing

[Bug tree-optimization/95923] Failure to optimize bool checks into and

2023-07-15 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95923

--- Comment #5 from Andrew Pinski  ---
(In reply to Andrew Pinski from comment #4)
> So there are some patterns for non boolean as for boolean values ~(a^b) is
> converted to a==b so we need to support the == case for these:
The non-boolean ones were originally added by 
r8-4395-ge268a77b59cb78

[Bug tree-optimization/95923] Failure to optimize bool checks into and

2023-07-15 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95923

--- Comment #4 from Andrew Pinski  ---
So there are some patterns for non boolean as for boolean values ~(a^b) is
converted to a==b so we need to support the == case for these:
```
/* (a | b) & ~(a ^ b)  -->  a & b  */
(simplify
 (bit_and:c (bit_ior @0 @1) (bit_not (bit_xor:c @0 @1)))
 (bit_and @0 @1))

/* a | ~(a ^ b)  -->  a | ~b  */
(simplify
 (bit_ior:c @0 (bit_not:s (bit_xor:c @0 @1)))
 (bit_ior @0 (bit_not @1)))

/* (a & b) | ~(a ^ b)  -->  ~(a ^ b)  */
(simplify
 (bit_ior:c (bit_and:c @0 @1) (bit_not@2 (bit_xor @0 @1)))
 @2)
```

So mine.

[Bug tree-optimization/95923] Failure to optimize bool checks into and

2023-06-11 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95923

--- Comment #3 from Andrew Pinski  ---
After r14-1597-g64d90d06d2db, we now have:
  _8 = a_6(D) | b_7(D);
  _10 = a_6(D) == b_7(D);
  _1 = _8 & _10;

(a == b) & (a | b)

I am no longer working on this right now. That is a job for reassociate I
think.

Note I noticed that we don't remove some "dead" statements during phiopt3 too:
```
  if (_8 != 0)
goto ; [66.00%]
  else
goto ; [34.00%]

   [local count: 708669601]:
  _1 = ~a_6(D);
  _2 = _1 & b_7(D);
  _10 = a_6(D) == b_7(D);

   [local count: 1073741824]:
  # _5 = PHI <_10(3), 0(2)>
```

I will fix that before unassigning. The problem there is:
We had:
  _1 = ~a_6(D);
  _2 = _1 & b_7(D);
  if (_2 != 0)

But we don't mark _2 as possible unused even though match will produce without
it:
Folded into the sequence:
_3 = ~b_7(D);
_4 = _3 | a_6(D);
_11 = a_6(D) ^ b_7(D);
_10 = a_6(D) == b_7(D);
statement un-sinked:
_12 = _1 | b_7(D);

[Bug tree-optimization/95923] Failure to optimize bool checks into and

2021-08-07 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95923

Andrew Pinski  changed:

   What|Removed |Added

   Last reconfirmed||2021-08-07
 Ever confirmed|0   |1
   Assignee|unassigned at gcc dot gnu.org  |pinskia at gcc dot 
gnu.org
 Status|UNCONFIRMED |ASSIGNED

--- Comment #2 from Andrew Pinski  ---
Mine.
  _1 = ~a_6(D);
  _3 = _1 & b_7(D);
  if (_3 != 0)
goto ; [34.00%]
  else
goto ; [66.00%]

   [local count: 467721933]:
  _10 = _1 | b_7(D);

   [local count: 1073741824]:
  # _5 = PHI <0(3), _10(4), 0(2)>

This is _3 ? 0 : _10 -> (_10 & ~3)

And then this simplifies more.

[Bug tree-optimization/95923] Failure to optimize bool checks into and

2021-04-25 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95923

Andrew Pinski  changed:

   What|Removed |Added

   Severity|normal  |enhancement

[Bug tree-optimization/95923] Failure to optimize bool checks into and

2020-06-27 Thread glisse at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95923

--- Comment #1 from Marc Glisse  ---
(With one variant I ended up with (a|b)&(a==b), which we don't optimize to a)

We don't optimize !(!a && !b) && !(!a && b) && !(a && !b) (we keep several
branches), but we do optimize if I manually replace enough && with &.