diff --git a/gcc/match.pd b/gcc/match.pd
index 8a2de136e..4a2f9a784 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -6660,6 +6660,15 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
  (simplify
   (bitop (neeql @0 @1) (neeqr (bit_ior @0 @1) integer_zerop))
   { constant_boolean_node (bitop == BIT_IOR_EXPR, type); }))
+
+/* (a == 0) | ((a | b) == 0) -> (a == 0) -- PR125442
+   (a != 0) & ((a | b) != 0) -> (a != 0) -- PR125442 */
+
+(for bitop (bit_and bit_ior)
+     neeq  (ne      eq)
+(simplify
+  (bitop:c (neeq@2 @0 integer_zerop) (neeq (bit_ior:c @0 @1) integer_zerop))
+  @2))
 #endif
 
 /* These was part of minmax phiopt.  */
