[Bug tree-optimization/112659] missed-optimization: if (exp) return exp; else return 0;

pinskia at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Nov 21 22:05:25 GMT 2023


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112659

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
           Severity|normal                      |enhancement
           Assignee|unassigned at gcc dot gnu.org      |pinskia at gcc dot gnu.org
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2023-11-21

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Mine.

We get in phiopt1:
        v_2(D) == -8 ? 0 : _4
where _4 is defined as:
  _4 = v_2(D) + 8;

So maybe
```
(simplify
 (cond (eq @0 INTEGER_CST@1) zero_p (plus@3 @0 INTEGER_CST@2))
 @3
)
```


Note GCC handles already on the trunk:
```
int optb(int v, int b) {
    if (v -b)
        return v - b;
    else
        return 0;
}
int optc(int v, int b) {
    if (v + b)
        return v + b;
    else
        return 0;
}
```


More information about the Gcc-bugs mailing list