[Bug tree-optimization/100864] (a&!b) | b is not opimized to a | b for comparisons
pinskia at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Mon Jun 14 22:04:39 GMT 2021
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100864
--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
So what is done for A && !B (and A || !B), is the following:
/* Simple range test simplifications. */
/* A < B || A >= B -> true. */
(for test1 (lt le le le ne ge)
test2 (ge gt ge ne eq ne)
(simplify
(bit_ior:c (test1 @0 @1) (test2 @0 @1))
(if (INTEGRAL_TYPE_P (TREE_TYPE (@0))
|| VECTOR_INTEGER_TYPE_P (TREE_TYPE (@0)))
{ constant_boolean_node (true, type); })))
/* A < B && A >= B -> false. */
(for test1 (lt lt lt le ne eq)
test2 (ge gt eq gt eq gt)
(simplify
(bit_and:c (test1 @0 @1) (test2 @0 @1))
(if (INTEGRAL_TYPE_P (TREE_TYPE (@0))
|| VECTOR_INTEGER_TYPE_P (TREE_TYPE (@0)))
{ constant_boolean_node (false, type); })))
But this could be expanded to other non-integer types.
For float types e.g (with -ffast-math):
int f(float a, float b)
{
int c = a == b;
int d = a != b;
return c & d;
}
Is not optimized until reassoc1. I will change that to be similar what I Have
too.
More information about the Gcc-bugs
mailing list