[PATCH] tree-optimization/103514 Missing XOR-EQ-AND Optimization
Marc Glisse
marc.glisse@inria.fr
Sat Dec 4 21:22:14 GMT 2021
+/* (a & b) ^ (a == b) -> !(a | b) */
+/* (a & b) == (a ^ b) -> !(a | b) */
+(for first_op (bit_xor eq)
+ second_op (eq bit_xor)
+ (simplify
+ (first_op:c (bit_and:c @0 @1) (second_op:c @0 @1))
+ (if (INTEGRAL_TYPE_P (TREE_TYPE (@0))
+ && types_match (TREE_TYPE (@0), TREE_TYPE (@1)))
+ (convert (bit_not (bit_ior @0 @1))))))
I don't think you need types_match, if both are operands of bit_and, their
types must already match.
It isn't clear what the INTEGRAL_TYPE_P test is for. Your 2
transformations don't seem that similar to me. The first one requires that
a and b have the same type as the result of ==, so they are boolean-like.
The second one makes sense for more general integers, but then it looks
like it should produce (a|b)==0.
It doesn't look like we have a canonical representation between a^b and
a!=b for booleans :-(
(sorry for the broken thread, I was automatically unsubscribed because
mailman doesn't like greylisting)
--
Marc Glisse
More information about the Gcc-patches
mailing list