[Bug tree-optimization/111456] [14 Regression] Dead Code Elimination Regression since r14-3719-gb34f3736356

2023-09-26 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111456

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

https://gcc.gnu.org/g:c3c6f30496d945b77dcb7f4ad8c3f8094f5a64a4

commit r14-4280-gc3c6f30496d945b77dcb7f4ad8c3f8094f5a64a4
Author: Andrew Pinski 
Date:   Wed Sep 20 14:54:31 2023 -0700

MATCH: Simplify `(A ==/!= B) &/| (((cast)A) CMP C)`

This patch adds support to the pattern for `(A == B) &/| (A CMP C)`
where the second A could be casted to a different type.
Some were handled correctly if using seperate `if` statements
but not if combined with BIT_AND/BIT_IOR.
In the case of pr111456-1.c, the testcase would pass if
`--param=logical-op-non-short-circuit=0` was used but now
can be optimized always.

OK? Bootstrapped and tested on x86_64-linux-gnu.

PR tree-optimization/106164
PR tree-optimization/111456

gcc/ChangeLog:

* match.pd (`(A ==/!= B) & (A CMP C)`):
Support an optional cast on the second A.
(`(A ==/!= B) | (A CMP C)`): Likewise.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/cmpbit-6.c: New test.
* gcc.dg/tree-ssa/cmpbit-7.c: New test.
* gcc.dg/tree-ssa/pr111456-1.c: New test.

[Bug tree-optimization/111456] [14 Regression] Dead Code Elimination Regression since r14-3719-gb34f3736356

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

Andrew Pinski  changed:

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
 Resolution|--- |FIXED

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

[Bug tree-optimization/111456] [14 Regression] Dead Code Elimination Regression since r14-3719-gb34f3736356

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

Andrew Pinski  changed:

   What|Removed |Added

URL||https://gcc.gnu.org/piperma
   ||il/gcc-patches/2023-Septemb
   ||er/631065.html
   Keywords||patch

--- Comment #6 from Andrew Pinski  ---
Patch posted:
https://gcc.gnu.org/pipermail/gcc-patches/2023-September/631065.html

[Bug tree-optimization/111456] [14 Regression] Dead Code Elimination Regression since r14-3719-gb34f3736356

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

--- Comment #5 from Andrew Pinski  ---
Just a quick note, --param=logical-op-non-short-circuit=0 also allows the
missed optimization to no longer to be missed.

[Bug tree-optimization/111456] [14 Regression] Dead Code Elimination Regression since r14-3719-gb34f3736356

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

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

I still need to add testcases.

[Bug tree-optimization/111456] [14 Regression] Dead Code Elimination Regression since r14-3719-gb34f3736356

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

--- Comment #3 from Andrew Pinski  ---
here is another missed optimization:
```
_Bool f2(int a, int b)
{
_Bool t = a == b;
unsigned t1 = a;
unsigned t2 = b;
_Bool b2 = t1 >= t2;
return t & b2;
}
```
This should just be optimized to `return a == b;`.

[Bug tree-optimization/111456] [14 Regression] Dead Code Elimination Regression since r14-3719-gb34f3736356

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

--- Comment #2 from Andrew Pinski  ---
Reduced testcase for the missed optimization before and after the patch:
```
_Bool f(int a)
{
_Bool t = a == 0;
short t1 = a;
_Bool t2 = t1 >= 0;
return t & t2;
}
```

This really should just reduce to `return a == 0;`

[Bug tree-optimization/111456] [14 Regression] Dead Code Elimination Regression since r14-3719-gb34f3736356

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

Andrew Pinski  changed:

   What|Removed |Added

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

--- Comment #1 from Andrew Pinski  ---
I noticed a few missed optimizations:
   [local count: 1073741824]:
  i.0_1 = i;
  _2 = (short int) i.0_1;
  _14 = _2 >= 0;
  _15 = i.0_1 == 0;
  _16 = _14 & _15;
  if (_16 != 0)
goto ; [50.00%]
  else
goto ; [50.00%]

   [local count: 805306368]:
  _21 = (int) _2;
  _20 = _21 == 0;
  _29 = _21 > 1;
  _30 = _20 | _29;
  if (_30 != 0)
goto ; [72.67%]
  else
goto ; [27.33%]

Here this should have been just 
  if (i.0_1 == 0)
goto ; [50.00%]
  else
goto ; [50.00%]

And that would fix the rest.

I suspect if we extend:
/* Convert (X == CST1) && (X OP2 CST2) to a known value
   based on CST1 OP2 CST2.  Similarly for (X != CST1).  */
/* Convert (X == Y) && (X OP2 Y) to a known value if X is an integral type.
   Similarly for (X != Y).  */

to handle a cast for the second part. This will be fixed ...
Will handle that this weekend or earlier.

[Bug tree-optimization/111456] [14 Regression] Dead Code Elimination Regression since r14-3719-gb34f3736356

2023-09-18 Thread rguenth at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111456

Richard Biener  changed:

   What|Removed |Added

   Target Milestone|--- |14.0