OSDN Git Service

* fold-const.c (fold) [EQ_EXPR]: When seeing if D & ~C != 0 to
authorkazu <kazu@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 3 Oct 2004 15:31:54 +0000 (15:31 +0000)
committerkazu <kazu@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 3 Oct 2004 15:31:54 +0000 (15:31 +0000)
fold (A & C) == D into 0, fold ~C.  Similarly, for the case
where | is used instead of &.

* testsuite/gcc.dg/tree-ssa/20041002-1.c: New.

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

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

index ae9c59b..8cb2906 100644 (file)
@@ -1,5 +1,11 @@
 2004-10-03  Kazu Hirata  <kazu@cs.umass.edu>
 
+       * fold-const.c (fold) [EQ_EXPR]: When seeing if D & ~C != 0 to
+       fold (A & C) == D into 0, fold ~C.  Similarly, for the case
+       where | is used instead of &.
+
+2004-10-03  Kazu Hirata  <kazu@cs.umass.edu>
+
        * ginclude/stddef.h: Fix a comment typo.
 
 2004-10-03  Eric Botcazou  <ebotcazou@libertysurf.fr>
index 595d8c1..7de102f 100644 (file)
@@ -8400,11 +8400,11 @@ fold (tree expr)
          && TREE_CODE (arg1) == INTEGER_CST
          && TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST)
        {
-         tree dandnotc
-           = fold (build2 (BIT_AND_EXPR, TREE_TYPE (arg0),
-                           arg1, build1 (BIT_NOT_EXPR,
-                                         TREE_TYPE (TREE_OPERAND (arg0, 1)),
-                                         TREE_OPERAND (arg0, 1))));
+         tree notc = fold (build1 (BIT_NOT_EXPR,
+                                   TREE_TYPE (TREE_OPERAND (arg0, 1)),
+                                   TREE_OPERAND (arg0, 1)));
+         tree dandnotc = fold (build2 (BIT_AND_EXPR, TREE_TYPE (arg0),
+                                       arg1, notc));
          tree rslt = code == EQ_EXPR ? integer_zero_node : integer_one_node;
          if (integer_nonzerop (dandnotc))
            return omit_one_operand (type, rslt, arg0);
@@ -8417,10 +8417,9 @@ fold (tree expr)
          && TREE_CODE (arg1) == INTEGER_CST
          && TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST)
        {
-         tree candnotd
-           = fold (build2 (BIT_AND_EXPR, TREE_TYPE (arg0),
-                           TREE_OPERAND (arg0, 1),
-                           build1 (BIT_NOT_EXPR, TREE_TYPE (arg1), arg1)));
+         tree notd = fold (build1 (BIT_NOT_EXPR, TREE_TYPE (arg1), arg1));
+         tree candnotd = fold (build2 (BIT_AND_EXPR, TREE_TYPE (arg0),
+                                       TREE_OPERAND (arg0, 1), notd));
          tree rslt = code == EQ_EXPR ? integer_zero_node : integer_one_node;
          if (integer_nonzerop (candnotd))
            return omit_one_operand (type, rslt, arg0);
index 7c6f445..3e32305 100644 (file)
@@ -1,3 +1,7 @@
+2004-10-03  Kazu Hirata  <kazu@cs.umass.edu>
+
+       * gcc.dg/tree-ssa/20041002-1.c: New.
+
 2004-10-03  Paul Brook  <paul@codesourcery.com>
 
        * gfortran.dg/pr17286.f90: Add dg-do line.  Explicitly test bug,
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/20041002-1.c b/gcc/testsuite/gcc.dg/tree-ssa/20041002-1.c
new file mode 100644 (file)
index 0000000..7f38f80
--- /dev/null
@@ -0,0 +1,23 @@
+/* PR tree-optimization/16632
+   fold() failed to see the following "if" statements never trigger.  */
+
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-ssa" } */
+
+int
+foo (int i)
+{
+  if ((i | 3) == 1)
+    return 1;
+  return 0;
+}
+
+int
+bar (int i)
+{
+  if ((i & 4) == 2)
+    return 1;
+  return 0;
+}
+
+/* { dg-final { scan-tree-dump-times "if" 0 "ssa" } } */