[Bug middle-end/78947] sub-optimal code for (bool)(int ? int : int)

pinskia at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Dec 29 03:44:00 GMT 2016


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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2016-12-29
     Ever confirmed|0                           |1

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed, this is fold-cost folding:
(bool)(a?b:c)
into a ? (bool) b : (bool)c;
early.

Rewriting the code slightly gets the code you wanted:
bool condSet(int cond, int a, int b) {
    int c;
    c = cond ? a : b;
    return c;
}


More information about the Gcc-bugs mailing list