[Bug tree-optimization/91882] boolean XOR tautology missed optimisation

SztfG at yandex dot ru gcc-bugzilla@gcc.gnu.org
Tue Sep 24 14:35:00 GMT 2019


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

--- Comment #1 from SztfG at yandex dot ru ---
Similar problem with other tautology:

unsigned int impl_bit(unsigned int a, unsigned int b) // bitwise implication
{
  return (~a | b);
}

unsigned int eq_bit(unsigned int a, unsigned int b) // bitwise equivalence
{
  return (~a ^ b);
}

// good optimisation - "return 1;"
unsigned int always_true(unsigned int a, unsigned int b)
{
  return eq_bit(impl_bit(a,b), impl_bit(b,a)) == eq_bit(a, b); // ( (a -> b) =
(b -> a) ) = (a = b) tautology
}



bool impl_bool(bool a, bool b
{
    return (!a || b);
}

// bad optimisation
bool always_true(bool a, bool b)
{
    return (impl(a,b) == impl(b,a)) == (a == b); // ( (a -> b) = (b -> a) ) =
(a = b) tautology
}


More information about the Gcc-bugs mailing list