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

--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Pavel M from comment #7)
> May be useful: https://devblogs.microsoft.com/cppblog/new-code-optimizer.
> Search for "Bit Estimator" section containing "Folding comparisons and
> branches".

All of the infrastructure for the above referenced is already done really. This
is what with_possible_nonzero_bits/get_nonzero_bits is used for inside
match.pd. My original example match.pd used a constant but does not need to.

In fact GCC already handles:
bool f(int x)
{
    if (x == 4)
      if (x & 0x3)
        return true;
    return false;
}
It is the & case where GCC does not handle (&& in the original code is
converted into & early on as both sides do NOT have side effects and such).

Reply via email to