(simplify
(bitop:c (rbitop:c @0 @1) @0)
@0)
- /* (~x | y) & x -> x & y */
- /* (~x & y) | x -> x | y */
- (simplify
- (bitop:c (rbitop:c @2 @1) @0)
- (with { bool wascmp; }
- (if (bitwise_inverted_equal_p (@0, @2, wascmp)
- && (!wascmp || element_precision (type) == 1))
- (bitop @0 @1))))
/* (x | y) & (x & z) -> (x & z) */
/* (x & y) | (x | z) -> (x | z) */
(simplify
{ build_zero_cst (type); }
{ build_minus_one_cst (type); })))
+/* (~x | y) & x -> x & y
+ (~x & y) | x -> x | y
+ (~x & y) ^ x -> x | y */
+(for bitop (bit_and bit_ior bit_xor)
+ rbitop (bit_ior bit_and bit_and)
+ resbitop (bit_and bit_ior bit_ior)
+ (simplify
+ (bitop:c (rbitop:c @2 @1) @0)
+ (with { bool wascmp; }
+ (if (bitwise_inverted_equal_p (@0, @2, wascmp)
+ && (!wascmp || element_precision (type) == 1))
+ (resbitop @0 @1)))))
+
/* ((x | y) & z) | x -> (z & y) | x
((x ^ y) & z) | x -> (z & y) | x */
(for op (bit_ior bit_xor)
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O1 -fdump-tree-gimple-raw -fdump-tree-forwprop1-raw" } */
+/* PR tree-optimization/125104 */
+
+int f(int a, int b)
+{
+ a &= ~1;
+ a ^= 1;
+ return a; // a | 1
+}
+
+/* { dg-final { scan-tree-dump "bit_xor_expr" "gimple" } } */
+/* { dg-final { scan-tree-dump "bit_ior_expr" "forwprop1" } } */