~X & Y to X ^ Y in some cases
authorMarc Glisse <marc.glisse@inria.fr>
Tue, 17 May 2016 17:54:28 +0000 (19:54 +0200)
committerMarc Glisse <glisse@gcc.gnu.org>
Tue, 17 May 2016 17:54:28 +0000 (17:54 +0000)
2016-05-17  Marc Glisse  <marc.glisse@inria.fr>

gcc/
* match.pd (~X & Y): New transformation.

gcc/testsuite/
* gcc.dg/tree-ssa/pr69270.c: Adjust.
* gcc.dg/tree-ssa/andnot-1.c: New testcase.

From-SVN: r236337

gcc/ChangeLog
gcc/match.pd
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-ssa/andnot-1.c [new file with mode: 0644]

index 93c1a2d22a1f8a8f4ae27a07b79e2006f154e989..9ec5a9e688af5ec4e460bf3874a73674efbe0a80 100644 (file)
@@ -1,3 +1,7 @@
+2016-05-17  Marc Glisse  <marc.glisse@inria.fr>
+
+       * match.pd (~X & Y): New transformation.
+
 2016-05-17  Marc Glisse  <marc.glisse@inria.fr>
 
        * tree-vrp.c (simplify_truth_ops_using_ranges): Set range
index 5b3cb3bfd5e86dce2708c909b76d37da09855ca9..acc41be5a8d96e17dd0176b7bdc49977f54621c0 100644 (file)
@@ -503,6 +503,14 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
  (bit_ior:c (bit_and @0 INTEGER_CST@2) (bit_and (bit_not @0) INTEGER_CST@1))
  (if (wi::bit_not (@2) == @1)
   (bit_xor @0 @1)))
+/* Simplify (~X & Y) to X ^ Y if we know that (X & ~Y) is 0.  */
+#if GIMPLE
+(simplify
+ (bit_and (bit_not SSA_NAME@0) INTEGER_CST@1)
+ (if (INTEGRAL_TYPE_P (TREE_TYPE (@0))
+      && (get_nonzero_bits (@0) & wi::bit_not (@1)) == 0)
+  (bit_xor @0 @1)))
+#endif
 
 /* X % Y is smaller than Y.  */
 (for cmp (lt ge)
index ca093a185271de9a9bcde64ccd6522f772f00620..61b6a2290c0d22d72e9235b1866534a4021f6b3a 100644 (file)
@@ -1,3 +1,8 @@
+2016-05-17  Marc Glisse  <marc.glisse@inria.fr>
+
+       * gcc.dg/tree-ssa/pr69270.c: Adjust.
+       * gcc.dg/tree-ssa/andnot-1.c: New testcase.
+
 2016-05-17  Marc Glisse  <marc.glisse@inria.fr>
 
        * gcc.dg/tree-ssa/pr69270.c: Adjust.
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/andnot-1.c b/gcc/testsuite/gcc.dg/tree-ssa/andnot-1.c
new file mode 100644 (file)
index 0000000..7f161b6
--- /dev/null
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-optimized-raw" } */
+
+unsigned f(unsigned i){
+  i >>= __SIZEOF_INT__ * __CHAR_BIT__ - 3;
+  i = ~i;
+  return i & 7;
+}
+
+/* { dg-final { scan-tree-dump "bit_xor_expr" "optimized" } } */
+/* { dg-final { scan-tree-dump-not "bit_not_expr" "optimized" } } */
+/* { dg-final { scan-tree-dump-not "bit_and_expr" "optimized" } } */