[PATCH] Fix middle-end/15618, bool_var != 0 (== 1) -> bool_var

Paul Schlie schlie@comcast.net
Tue May 3 01:49:00 GMT 2005


> Andrew Pinski writes:
> Right now we don't optimize if a bool variable is compared not equal
> to zero or equal to one.  This implements that folding of those two
> and treats BOOLEAN_TYPE like INTEGER_TYPE in fold_widened_comparison
> so we get the folding of "(int)bool_var != 0" into "bool_var != 0".

Might these also be worth while? (or are they handled elsewhere):

bool_var == 0 => ! bool_var // as a logical ! (not) it's likely more
bool_var != 1 => ! bool_var // easily folded with other logical ops.

bool_var == (N other than 0 or 1) => false // as constant results are
bool_var != (N other than 0 or 1) => true  // always likely a good thing.





More information about the Gcc-patches mailing list