https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127292
Bug ID: 127292
Summary: `(a > 1) != a` should be optimized to `a != 0`
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: pinskia at gcc dot gnu.org
Blocks: 126043
Target Milestone: ---
Reduced from testsuite/gcc.dg/tree-ssa/pr108357.c after a phiopt change but
can be shown without it.
Take:
```
int f23(int a)
{
int t = a > 1;
return t != a;
}
int f23_1(int a)
{
int t;
if (a > 1)
t = 1;
else
t = 0;
return t != a;
}
int f23_2(int a)
{
int t;
if (a > 1)
t = 1;
else
t = 0;
if (t != a)
t = 1;
else
t = 0;
return t;
}
```
These all three should produce the same code.
Currently only f23_2 produces the best at `a!=0`.
Note LLVM is able to handle f23_1 and f23_2 but not f23.
This is related to PR 110293 but slightly different.
Referenced Bugs:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126043
[Bug 126043] early phiopt should allow CMP, (cast)CMP, -(cast)CMP