[Bug tree-optimization/107888] New: [12/13 Regression] Missed min/max transformation in phiopt due to VRP
pinskia at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Sun Nov 27 19:28:54 GMT 2022
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107888
Bug ID: 107888
Summary: [12/13 Regression] Missed min/max transformation in
phiopt due to VRP
Product: gcc
Version: 13.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
Target Milestone: ---
Take:
```
#define bool _Bool
int maxbool(bool ab, bool bb)
{
int a = ab;
int b = bb;
int c;
if (a > b)
c = a;
else
c = b;
return c;
}
```
We miss that c is max of a and b because VRP decides to change the phi.
We get out of VRP:
```
if (a_3 > b_5)
goto <bb 4>; [INV]
else
goto <bb 3>; [INV]
<bb 3> :
<bb 4> :
# c_1 = PHI <1(2), b_5(3)>
```
What VRP is doing is correct just is harder to optimize to a max (and then a |
).
In the above case we could optimize `bool0 ? 1 : bool1` to `bool0 | bool1` But
then we end up with PR 107887 too.
You can also end up with the above issue where you know the only overlap
between the two arguments is [5,6] :
```
int max(int ab, int bb)
{
if (ab < 5) __builtin_trap();
if (bb > 6) __builtin_trap();
int a = ab;
int b = bb;
int c;
if (a >= b)
c = a;
else
c = b;
return c;
}
```
Which we cannot optimize based on zero/one any more. (note this version of max
has been an issue since at least GCC 4.1, I suspect since VRP was added).
More information about the Gcc-bugs
mailing list