if (TREE_CODE (expr2) == BIT_NOT_EXPR
&& bitwise_equal_p (expr1, TREE_OPERAND (expr2, 0)))
return true;
+
+ /* `X ^ CST` and `X ^ ~CST` match for ~. */
+ if (TREE_CODE (expr1) == BIT_XOR_EXPR && TREE_CODE (expr2) == BIT_XOR_EXPR
+ && bitwise_equal_p (TREE_OPERAND (expr1, 0), TREE_OPERAND (expr2, 0)))
+ {
+ tree cst1 = uniform_integer_cst_p (TREE_OPERAND (expr1, 1));
+ tree cst2 = uniform_integer_cst_p (TREE_OPERAND (expr2, 1));
+ if (cst1 && cst2 && wi::to_wide (cst1) == ~wi::to_wide (cst2))
+ return true;
+ }
if (COMPARISON_CLASS_P (expr1)
&& COMPARISON_CLASS_P (expr2))
{
bool gimple_bit_not_with_nop (tree, tree *, tree (*) (tree));
bool gimple_maybe_cmp (tree, tree *, tree (*) (tree));
+bool gimple_bit_xor_cst (tree, tree *, tree (*) (tree));
/* Helper function for bitwise_inverted_equal_p macro. */
if (operand_equal_p (expr1, expr2, 0))
return false;
+ tree xor1[2];
+ tree xor2[2];
+ /* `X ^ CST` and `X ^ ~CST` match for ~. */
+ if (gimple_bit_xor_cst (expr1, xor1, valueize)
+ && gimple_bit_xor_cst (expr2, xor2, valueize))
+ {
+ if (operand_equal_p (xor1[0], xor2[0], 0)
+ && (wi::to_wide (uniform_integer_cst_p (xor1[1]))
+ == ~wi::to_wide (uniform_integer_cst_p (xor2[1]))))
+ return true;
+ }
+
tree other;
/* Try if EXPR1 was defined as ~EXPR2. */
if (gimple_bit_not_with_nop (expr1, &other, valueize))
(match (bit_not_with_nop @0)
(convert (bit_not @0))
(if (tree_nop_conversion_p (type, TREE_TYPE (@0)))))
+(match (bit_xor_cst @0 @1)
+ (bit_xor @0 uniform_integer_cst_p@1))
(for cmp (tcc_comparison)
(match (maybe_cmp @0)
(cmp@0 @1 @2))
(INTEGER_CST@0))
(match (maybe_bit_not @0)
(maybe_cmp@0 @1))
+(match (maybe_bit_not @0)
+ (bit_xor_cst@0 @1 @2))
/* Transform likes of (char) ABS_EXPR <(int) x> into (char) ABSU_EXPR <x>
ABSU_EXPR returns unsigned absolute value of the operand and the operand
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized-raw" } */
+/* PR tree-optimization/115224 */
+
+int f1(int a, int b)
+{
+ a = a ^ 1;
+ int c = ~a;
+ return c | (a ^ b);
+ // ~((a ^ 1) & b) or (a ^ -2) | ~b
+}
+/* { dg-final { scan-tree-dump-times "bit_xor_expr, " 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "bit_ior_expr, " 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "bit_not_expr, " 1 "optimized" } } */
+