The types can differ through nop conversions. */
static inline bool
-bitwise_inverted_equal_p (tree expr1, tree expr2)
+bitwise_inverted_equal_p (tree expr1, tree expr2, bool &wascmp)
{
STRIP_NOPS (expr1);
STRIP_NOPS (expr2);
+ wascmp = false;
if (expr1 == expr2)
return false;
if (!tree_nop_conversion_p (TREE_TYPE (expr1), TREE_TYPE (expr2)))
{
tree op10 = TREE_OPERAND (expr1, 0);
tree op20 = TREE_OPERAND (expr2, 0);
+ wascmp = true;
if (!operand_equal_p (op10, op20))
return false;
tree op11 = TREE_OPERAND (expr1, 1);
/* Return true if EXPR1 and EXPR2 have the bitwise opposite value,
but not necessarily same type.
The types can differ through nop conversions. */
-#define bitwise_inverted_equal_p(expr1, expr2) \
- gimple_bitwise_inverted_equal_p (expr1, expr2, valueize)
+#define bitwise_inverted_equal_p(expr1, expr2, wascmp) \
+ gimple_bitwise_inverted_equal_p (expr1, expr2, wascmp, valueize)
bool gimple_bit_not_with_nop (tree, tree *, tree (*) (tree));
/* Helper function for bitwise_equal_p macro. */
static inline bool
-gimple_bitwise_inverted_equal_p (tree expr1, tree expr2, tree (*valueize) (tree))
+gimple_bitwise_inverted_equal_p (tree expr1, tree expr2, bool &wascmp, tree (*valueize) (tree))
{
+ wascmp = false;
if (expr1 == expr2)
return false;
if (!tree_nop_conversion_p (TREE_TYPE (expr1), TREE_TYPE (expr2)))
tree op21 = do_valueize (valueize, gimple_assign_rhs2 (a2));
if (!operand_equal_p (op11, op21))
return false;
+ wascmp = true;
if (invert_tree_comparison (gimple_assign_rhs_code (a1),
HONOR_NANS (op10))
== gimple_assign_rhs_code (a2))
/* Simplify ~X & X as zero. */
(simplify
(bit_and (convert? @0) (convert? @1))
- (if (types_match (TREE_TYPE (@0), TREE_TYPE (@1))
- && bitwise_inverted_equal_p (@0, @1))
- { build_zero_cst (type); }))
+ (with { bool wascmp; }
+ (if (types_match (TREE_TYPE (@0), TREE_TYPE (@1))
+ && bitwise_inverted_equal_p (@0, @1, wascmp))
+ { wascmp ? constant_boolean_node (false, type) : build_zero_cst (type); })))
/* PR71636: Transform x & ((1U << b) - 1) -> x & ~(~0U << b); */
(simplify
(for op (bit_ior bit_xor)
(simplify
(op (convert? @0) (convert? @1))
- (if (types_match (TREE_TYPE (@0), TREE_TYPE (@1))
- && bitwise_inverted_equal_p (@0, @1))
- (convert { build_all_ones_cst (TREE_TYPE (@0)); }))))
+ (with { bool wascmp; }
+ (if (types_match (TREE_TYPE (@0), TREE_TYPE (@1))
+ && bitwise_inverted_equal_p (@0, @1, wascmp))
+ (convert
+ { wascmp
+ ? constant_boolean_node (true, type)
+ : build_all_ones_cst (TREE_TYPE (@0)); })))))
/* x ^ x -> 0 */
(simplify
/* (~x & y) | x -> x | y */
(simplify
(bitop:c (rbitop:c @2 @1) @0)
- (if (bitwise_inverted_equal_p (@0, @2))
- (bitop @0 @1))))
+ (with { bool wascmp; }
+ (if (bitwise_inverted_equal_p (@0, @2, wascmp)
+ && (!wascmp || element_precision (type) == 1))
+ (bitop @0 @1)))))
/* ((x | y) & z) | x -> (z & y) | x */
(simplify
/* a?~t:t -> (-(a))^t */
(simplify
(cond @0 @1 @2)
- (if (INTEGRAL_TYPE_P (type)
- && bitwise_inverted_equal_p (@1, @2))
- (with {
- auto prec = TYPE_PRECISION (type);
- auto unsign = TYPE_UNSIGNED (type);
- tree inttype = build_nonstandard_integer_type (prec, unsign);
- }
- (convert (bit_xor (negate (convert:inttype @0)) (convert:inttype @2))))))
+ (with { bool wascmp; }
+ (if (INTEGRAL_TYPE_P (type)
+ && bitwise_inverted_equal_p (@1, @2, wascmp)
+ && (!wascmp || element_precision (type) == 1))
+ (with {
+ auto prec = TYPE_PRECISION (type);
+ auto unsign = TYPE_UNSIGNED (type);
+ tree inttype = build_nonstandard_integer_type (prec, unsign);
+ }
+ (convert (bit_xor (negate (convert:inttype @0)) (convert:inttype @2)))))))
#endif
/* Simplify pointer equality compares using PTA. */