[Bug tree-optimization/110293] Some `A CMP (A NEEQ 0)` is not simplified in some cases

2024-03-08 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110293

--- Comment #10 from Andrew Pinski  ---
Here is some more optimizations where the inner CMP is not EQ/NE:
signed:
x == (x <= CST) -> CST == 0 ? false : CST < 0 ? x == 0 : x == 1
x == (x  < CST) -> CST == 1 ? false : CST <= 0 ? x == 0 : x == 1

unsigned:
x == (x u<= CST) -> CST == 0 ? false : x == 1 (note 0 should already be
handled)
x == (x u<= CST) -> CST == 0 ? x == 0 : CST == 1 ? false : x == 1 (note 0/1
should be handled already)

[Bug tree-optimization/110293] Some `A CMP (A NEEQ 0)` is not simplified in some cases

2023-09-12 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110293

--- Comment #9 from Andrew Pinski  ---
Actually here is the rest for the non-zero comparisons.

Note for the below case, s can be swapped around with unsigned and the CST
comparisons become unsigned comparisons too.

s < (s == CST) ->  CST == 0 ? s <= 0 : CST < 0
s >= (s == CST) -> CST == 0 ? s > 0  : CST > 0
s > (s == CST) ->  CST == 0 ? s <= 0 : CST > 1
s <= (s == CST) -> CST == 0 ? s > 0  : CST <= 1

s <  (s != CST) -> CST == 0 ? s < 0  : (CST > 0 ? s < 1 : (s < 1 & s != CST))
s >= (s != CST) -> CST == 0 ? s >= 0 : (CST == 1 ? s > 1 : (CST > 1 ? s != CST
& s >= 1 : s >= 1))
s >  (s != CST) -> CST == 0 ? s <= 1 : 
s <= (s != CST) -> CST == 0 ? s >  1 :

[Bug tree-optimization/110293] Some `A CMP (A NEEQ 0)` is not simplified in some cases

2023-09-12 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110293

--- Comment #8 from Andrew Pinski  ---
Created attachment 55889
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55889=edit
Runtime test

[Bug tree-optimization/110293] Some `A CMP (A NEEQ 0)` is not simplified in some cases

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

--- Comment #7 from Andrew Pinski  ---
Half of this is fixed now.

[Bug tree-optimization/110293] Some `A CMP (A NEEQ 0)` is not simplified in some cases

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

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

https://gcc.gnu.org/g:285c9d042e90a7425b37697edc9ec93a1b03b486

commit r14-2501-g285c9d042e90a7425b37697edc9ec93a1b03b486
Author: Andrew Pinski 
Date:   Wed Jul 12 00:33:14 2023 -0700

Fix part of PR 110293: `A NEEQ (A NEEQ CST)` part

This fixes part of PR 110293, for the outer comparison case
being `!=` or `==`.  In turn PR 110539 is able to be optimized
again as the if statement for `(a&1) == ((a & 1) != 0)` gets optimized
to `false` early enough to allow FRE/DOM to do a CSE for memory store/load.

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

gcc/ChangeLog:

PR tree-optimization/110293
PR tree-optimization/110539
* match.pd: Expand the `x != (typeof x)(x == 0)`
pattern to handle where the inner and outer comparsions
are either `!=` or `==` and handle other constants
than 0.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/pr110293-1.c: New test.
* gcc.dg/tree-ssa/pr110539-1.c: New test.
* gcc.dg/tree-ssa/pr110539-2.c: New test.
* gcc.dg/tree-ssa/pr110539-3.c: New test.
* gcc.dg/tree-ssa/pr110539-4.c: New test.

[Bug tree-optimization/110293] Some `A CMP (A NEEQ 0)` is not simplified in some cases

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

--- Comment #5 from Andrew Pinski  ---
Part 1 of the patch to fix this:
https://gcc.gnu.org/pipermail/gcc-patches/2023-July/624293.html

This weekend I will handle the outer != NE/EQ cases.

[Bug tree-optimization/110293] Some `A CMP (A NEEQ 0)` is not simplified in some cases

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

--- Comment #4 from Andrew Pinski  ---
Created attachment 55527
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55527=edit
the eq/ne based functions

[Bug tree-optimization/110293] Some `A CMP (A NEEQ 0)` is not simplified in some cases

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

Andrew Pinski  changed:

   What|Removed |Added

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

--- Comment #3 from Andrew Pinski  ---
MIne, going to fix this ...

[Bug tree-optimization/110293] Some `A CMP (A NEEQ 0)` is not simplified in some cases

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

--- Comment #2 from Andrew Pinski  ---
Some more generally for the ==/!= cases for CSTs:
x == (x == CST) -> CST == 0 ? 0 : (CST == 1 ? (x==0||x==1) : x != 0)
x == (x != CST) -> CST == 1 ? 0 : (CST == 0 ? (x==0||x==1) : x != 1)
x != (x == CST) -> CST == 0 ? 1 : (CST == 1 ? (x!=0&!=1) : x != 0)
x != (x != CST) -> CST == 1 ? 1 : (CST == 0 ? (x!=0&!=1) : x != 1)

[Bug tree-optimization/110293] Some `A CMP (A NEEQ 0)` is not simplified in some cases

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

--- Comment #1 from Andrew Pinski  ---
Here are the signed versions of />=:
`s <  (s != 0)` is `s <  0`
`s <= (s != 0)` is `s <= 1`
`s >  (s != 0)` is `s >  1`
`s >= (s != 0)` is `s >= 0`

`s <  (s == 0)` is `s <= 0`
`s <= (s == 0)` is `s <= 0`
`s >  (s == 0)` is `s >  0`
`s >= (s == 0)` is `s >  0`


Here are the unsigned versions with `uns == 0` since I had missed those before:

`uns <  (uns == 0)` is `uns == 0`
`uns <= (uns == 0)` is `uns == 0`
`uns >= (uns == 0)` is `uns != 0`
`uns >  (uns == 0)` is `uns != 0`

I noticed LLVM does not catch these either.