+/* Fold X + (X / CST) * -CST to X % CST. */
This one is still wrong. It is extremely similar to X-(X/CST)*CST, and the
current version of that one in match.pd is broken, we should fix that one
first.
+/* Fold (A & ~B) - (A & B) into (A ^ B) - B. */
+(simplify
+ (minus (bit_and:s @0 (bit_not @1)) (bit_and:s @0 @1))
+ (if (! FLOAT_TYPE_P (type))
+ (minus (bit_xor @0 @1) @1)))
I don't understand the point of the FLOAT_TYPE_P check.
Will we also simplify (A & B) - (A & ~B) into B - (A ^ B) ?
+(simplify
+ (minus (bit_and:s @0 INTEGER_CST@2) (bit_and:s @0 INTEGER_CST@1))
+ (if (! FLOAT_TYPE_P (type)
+ && wi::eq_p (const_unop (BIT_NOT_EXPR, TREE_TYPE (type), @2), @1))
TREE_TYPE (type) ???
+ (minus (bit_xor @0 @1) @1)))
(just a random comment, not for your patch)
When we generalize this to vector, should that be:
operand_equal_p (const_unop (BIT_NOT_EXPR, type, @2), @1, OEP_ONLY_CONST)
or maybe
integer_all_onesp (const_binop (BIT_XOR_EXPR, type, @2, @1))
?
+/* Simplify (X & ~Y) | (~X & Y) -> X ^ Y. */
+(simplify
+ (bit_ior (bit_and:c @0 (bit_not @1)) (bit_and:c (bit_not @0) @1))
+ (bit_xor @0 @1))
:c on bit_ior? It should also allow you to merge the 2 CST versions into
one.
+ (bit_ior (bit_and:c INTEGER_CST@0 (bit_not @1)) (bit_and:c (bit_not
INTEGER_CST@2) @1))
gcc always puts the constant last in bit_and, so
(bit_and (bit_not @1) INTEGER_CST@0)
You still have a (bit_not INTEGER_CST@2)...
-/* X & !X -> 0. */
+/* X & !X or X & ~X -> 0. */
(simplify
(bit_and:c @0 (logical_inverted_value @0))
- { build_zero_cst (type); })
+ { build_zero_cst (type); })
/* X | !X and X ^ !X -> 1, , if X is truth-valued. */
(for op (bit_ior bit_xor)
(simplify
I think that was already in your other patch, and I am not really in favor
of the indentation change (or the comment).
--
Marc Glisse