https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118804
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
CC| |pinskia at gcc dot gnu.org
Last reconfirmed| |2025-02-09
Status|UNCONFIRMED |NEW
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed. A slightly different testcase that should be optimized for the same
reason (might be easier to optimize as sometimes `x == CST && y == CST` turn
into `(x == CST) & (y == CST)` removing the short cut):
```
bool f(int , int );
bool bar (int x, int y) {
if (x == y)
return true;
if (x == 999)
if (y == 999)
return true;
return f(x,y);
}
```
=========== BB 3 ============
Imports: x_3(D)
Exports: x_3(D)
x_3(D) [irange] int VARYING
Relational : (x_3(D) != y_4(D))
<bb 3> [local count: 848578158]:
if (x_3(D) == 999)
goto <bb 4>; [51.12%]
else
goto <bb 5>; [48.88%]
3->4 (T) x_3(D) : [irange] int [999, 999]
3->5 (F) x_3(D) : [irange] int [-INF, 998][1000, +INF]
Notice due to the relational one we should also register 3->4 for y_4 [-INF,
998][1000, +INF] and 3->5 for y_5: [999, 999].
Which means importing for BB 4:
Imports: y_4(D)
Exports: y_4(D)
y_4(D) [irange] int VARYING
<bb 4> [local count: 433793157]:
if (y_4(D) == 999)
goto <bb 6>; [20.97%]
else
goto <bb 5>; [79.03%]
The above conditional will be optimized away.
Now for the original case (on specific targets) is similar to:
```
bool bar2 (int x, int y, int z) {
bool t = x != y;
bool t1 = x == z & y == z;
return t & t1;
}
```
Which can be patterned matched in match.
Like:
```
(simplify
(bit_and:c (ne @0 @1) (bit_and:c (eq:c @0 @2) (eq:c @1 @2)))
{ constant_boolean_node (false, type); })
```
And I think that would solve the issue there.