]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR tree-optimization/15458 (Combine ~ and ^.)
authorRoger Sayle <roger@eyesopen.com>
Sun, 29 Oct 2006 17:51:07 +0000 (17:51 +0000)
committerRoger Sayle <sayle@gcc.gnu.org>
Sun, 29 Oct 2006 17:51:07 +0000 (17:51 +0000)
PR tree-optimization/15458
* fold-const.c (fold_binary): Optimize ~X ^ C as X ^ ~C, where C
is a constant.

* gcc.dg/fold-xornot-1.c: New test case.

From-SVN: r118152

gcc/ChangeLog
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/fold-xornot-1.c [new file with mode: 0644]

index c4bd38882353161a7a9a34dc954e564c15dae74e..fbdec1aff0755ef8e4d3a47a4962c5e8d131b828 100644 (file)
@@ -1,3 +1,9 @@
+2006-10-29  Roger Sayle  <roger@eyesopen.com>
+
+       PR tree-optimization/15458
+       * fold-const.c (fold_binary): Optimize ~X ^ C as X ^ ~C, where C
+       is a constant.
+
 2006-10-29  Richard Guenther  <rguenther@suse.de>
 
        * config/i386/i386-protos.h (ix86_expand_trunc): Declare.
index 8e3c97ae91e3766174945b017c225ffcdf1216e7..1c3c752ceb4fa5d3ff00e64442758a8026978a2b 100644 (file)
@@ -9506,6 +9506,13 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1)
                            fold_convert (type, TREE_OPERAND (arg0, 0)),
                            fold_convert (type, TREE_OPERAND (arg1, 0)));
 
+      /* Convert ~X ^ C to X ^ ~C.  */
+      if (TREE_CODE (arg0) == BIT_NOT_EXPR
+         && TREE_CODE (arg1) == INTEGER_CST)
+       return fold_build2 (code, type,
+                           fold_convert (type, TREE_OPERAND (arg0, 0)),
+                           fold_build1 (BIT_NOT_EXPR, type, arg1));
+
       /* Fold (X & 1) ^ 1 as (X & 1) == 0.  */
       if (TREE_CODE (arg0) == BIT_AND_EXPR
          && integer_onep (TREE_OPERAND (arg0, 1))
index 067d97e9481df2e5b8cdf11f11666426ebbfc390..de569bb604fd723fb1701f2bd3cc9fa7e5e806ea 100644 (file)
@@ -1,3 +1,8 @@
+2006-10-29  Roger Sayle  <roger@eyesopen.com>
+
+       PR tree-optimization/15458
+       * gcc.dg/fold-xornot-1.c: New test case.
+
 2006-10-29  Richard Guenther  <rguenther@suse.de>
 
        * gcc.target/i386/math-torture/trunc.c: New testcase.
diff --git a/gcc/testsuite/gcc.dg/fold-xornot-1.c b/gcc/testsuite/gcc.dg/fold-xornot-1.c
new file mode 100644 (file)
index 0000000..c92095d
--- /dev/null
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-original" } */
+
+int foo(int x)
+{
+  return ~(x ^ 4);
+}
+
+int bar(int y)
+{
+  return ~y ^ 4;
+}
+
+/* { dg-final { scan-tree-dump-times "x \\^ -5" 1 "original" } } */
+/* { dg-final { scan-tree-dump-times "y \\^ -5" 1 "original" } } */
+/* { dg-final { cleanup-tree-dump "original" } } */