This adds the boolean version of some of the simplifications
that were added with
r8-4395-ge268a77b59cb78.
That are the following:
(a | b) & (a == b) --> a & b
a | (a == b) --> a | (b ^ 1)
(a & b) | (a == b) --> a == b
OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.
gcc/ChangeLog:
PR tree-optimization/95923
* match.pd ((a|b)&(a==b),a|(a==b),(a&b)|(a==b)): New transformation.
gcc/testsuite/ChangeLog:
PR tree-optimization/95923
* gcc.dg/tree-ssa/bitops-2.c: New test.
* gcc.dg/tree-ssa/bool-checks-1.c: New test.
(bit_and:c (bit_ior @0 @1) (bit_not (bit_xor:c @0 @1)))
(bit_and @0 @1))
+/* (a | b) & (a == b) --> a & b (boolean version of the above). */
+(simplify
+ (bit_and:c (bit_ior @0 @1) (nop_convert? (eq:c @0 @1)))
+ (bit_and @0 @1))
+
/* a | ~(a ^ b) --> a | ~b */
(simplify
(bit_ior:c @0 (bit_not:s (bit_xor:c @0 @1)))
(bit_ior @0 (bit_not @1)))
+/* a | (a == b) --> a | (b^1) (boolean version of the above). */
+(simplify
+ (bit_ior:c @0 (nop_convert? (eq:c @0 @1)))
+ (bit_ior @0 (bit_xor @1 { build_one_cst (type); })))
+
/* (a | b) | (a &^ b) --> a | b */
(for op (bit_and bit_xor)
(simplify
(bit_ior:c (bit_and:c @0 @1) (bit_not@2 (bit_xor @0 @1)))
@2)
+/* (a & b) | (a == b) --> a == b */
+(simplify
+ (bit_ior:c (bit_and:c @0 @1) (nop_convert?@2 (eq @0 @1)))
+ @2)
+
/* ~(~a & b) --> a | ~b */
(simplify
(bit_not (bit_and:cs (bit_not @0) @1))
--- /dev/null
+/* { dg-do run } */
+/* { dg-options "-O -fdump-tree-optimized-raw" } */
+
+#define DECLS(n,VOL) \
+__attribute__((noinline,noclone)) \
+_Bool h##n(_Bool A,_Bool B){ \
+ VOL _Bool C = A | B; \
+ VOL _Bool D = A == B; \
+ return C & D; \
+} \
+__attribute__((noinline,noclone)) \
+_Bool i##n(_Bool A,_Bool B){ \
+ VOL _Bool C = A == B; \
+ return A | C; \
+} \
+__attribute__((noinline,noclone)) \
+_Bool k##n(_Bool A,_Bool B){ \
+ VOL _Bool C = A & B; \
+ VOL _Bool D = A == B; \
+ return C | D; \
+} \
+
+DECLS(0,)
+DECLS(1,volatile)
+
+int main(){
+ for(int A = 0; A <= 1; ++A)
+ for(int B = 0; B <= 1; ++B)
+ {
+ if (h0 (A, B) != h1 (A, B)) __builtin_abort();
+ if (i0 (A, B) != i1 (A, B)) __builtin_abort();
+ if (k0 (A, B) != k1 (A, B)) __builtin_abort();
+ }
+}
+
+/* { dg-final { scan-tree-dump-times "bit_not_expr," 1 "optimized"} } */
+/* { dg-final { scan-tree-dump-times "bit_and_expr," 3 "optimized"} } */
+/* { dg-final { scan-tree-dump-times "bit_ior_expr," 4 "optimized"} } */
+/* { dg-final { scan-tree-dump-times "eq_expr," 4 "optimized"} } */
+/* { dg-final { scan-tree-dump-times "ne_expr," 7 "optimized"} } */
+/* { dg-final { scan-tree-dump-not "bit_xor_expr," "optimized"} } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O1 -fdump-tree-optimized-raw" } */
+/* PR tree-optimization/95923 */
+
+_Bool f(_Bool a, _Bool b)
+{
+ if (!a && !b)
+ return 0;
+ if (!a && b)
+ return 0;
+ if (a && !b)
+ return 0;
+ return 1;
+}
+
+/* { dg-final { scan-tree-dump-times "bit_and_expr," 1 "optimized"} } */
+/* { dg-final { scan-tree-dump-not "bit_not_expr," "optimized"} } */
+/* { dg-final { scan-tree-dump-not "bit_ior_expr," "optimized"} } */
+/* { dg-final { scan-tree-dump-not "bit_xor_expr," "optimized"} } */
+/* { dg-final { scan-tree-dump-not "eq_expr," "optimized"} } */
+/* { dg-final { scan-tree-dump-not "ne_expr," "optimized"} } */
+/* { dg-final { scan-tree-dump-not "gimple_cond" "optimized"} } */