OSDN Git Service

2005-11-25 Andrew Pinski <pinskia@physics.uc.edu>
authorpinskia <pinskia@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 25 Nov 2005 04:54:59 +0000 (04:54 +0000)
committerpinskia <pinskia@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 25 Nov 2005 04:54:59 +0000 (04:54 +0000)
        PR middle-end/24990
        * fold-const.c (fold_binary): Fold (~a) == C to a == ~C
        for C being INTEGER_CST.  Likewise for !=.
2005-11-24  Andrew Pinski  <pinskia@physics.uc.edu>

        PR middle-end/24990
        * tree-ssa/pr24990-1.c: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@107487 138bc75d-0d04-0410-961f-82ee72b054a4

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

index 2d5eed2..aeb45fd 100644 (file)
@@ -1,3 +1,9 @@
+2005-11-25  Andrew Pinski  <pinskia@physics.uc.edu>
+
+       PR middle-end/24990
+       * fold-const.c (fold_binary): Fold (~a) == C to a == ~C
+       for C being INTEGER_CST.  Likewise for !=.
+
 2005-11-25  Joseph S. Myers  <joseph@codesourcery.com>
 
        PR middle-end/24998
index 2d750f6..962ebd3 100644 (file)
@@ -8839,6 +8839,13 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1)
       /* If one arg is a real or integer constant, put it last.  */
       if (tree_swap_operands_p (arg0, arg1, true))
        return fold_build2 (swap_tree_comparison (code), type, op1, op0);
+
+      /*  ~a != C becomes a != ~C where C is a constant.  Likewise for ==.  */
+      if (TREE_CODE (arg0) == BIT_NOT_EXPR && TREE_CODE (arg1) == INTEGER_CST
+         && (code == NE_EXPR || code == EQ_EXPR))
+       return fold_build2 (code, type, TREE_OPERAND (arg0, 0),
+                           fold_build1 (BIT_NOT_EXPR, TREE_TYPE (arg1), 
+                                        arg1));
        
       /* bool_var != 0 becomes bool_var. */
       if (TREE_CODE (TREE_TYPE (arg0)) == BOOLEAN_TYPE && integer_zerop (arg1)
index d2bc993..cb611dc 100644 (file)
@@ -1,3 +1,8 @@
+2005-11-24  Andrew Pinski  <pinskia@physics.uc.edu>
+
+       PR middle-end/24990
+       * tree-ssa/pr24990-1.c: New test.
+
 2005-11-24  Richard Guenther  <rguenther@suse.de>
        Dirk Mueller <dmueller@suse.de>
 
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr24990-1.c b/gcc/testsuite/gcc.dg/tree-ssa/pr24990-1.c
new file mode 100644 (file)
index 0000000..a518df0
--- /dev/null
@@ -0,0 +1,21 @@
+/* { dg-do compile } */
+/* { dg-options "-O1 -fdump-tree-optimized" } */
+
+int f(int x)
+{
+  return ((~x) != 0);
+}
+int f1(int x)
+{
+  return ((~x) == 0);
+}
+
+/* There should be no != 0 which is produced by the front-end as
+   ~x != 0 is the same as x != -1 (or ~0).   Likewise for ==. */
+/* { dg-final { scan-tree-dump-times "!= 0" 0 "optimized"} } */
+/* { dg-final { scan-tree-dump-times "!= -1" 1 "optimized"} } */
+/* { dg-final { scan-tree-dump-times "== 0" 0 "optimized"} } */
+/* { dg-final { scan-tree-dump-times "== -1" 1 "optimized"} } */
+
+/* { dg-final { cleanup-tree-dump "optimized" } } */
+