OSDN Git Service

2011-07-20 Richard Guenther <rguenther@suse.de>
authorrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 20 Jul 2011 13:35:20 +0000 (13:35 +0000)
committerrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 20 Jul 2011 13:35:20 +0000 (13:35 +0000)
PR middle-end/18908
* tree.c (integer_all_onesp): Use TYPE_PRECISION, not mode precision.
* tree-ssa-forwprop.c (simplify_bitwise_binary): Remove bogus
ADDR_EXPR folding.  Canonicalize X ^ ~0 as ~X.

* gcc.dg/tree-ssa/pr18908.c: New testcase.
* gcc.dg/tree-ssa/bitwise-sink.c: Adjust.

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

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-ssa/bitwise-sink.c
gcc/testsuite/gcc.dg/tree-ssa/pr18908.c [new file with mode: 0644]
gcc/tree-ssa-forwprop.c

index de9172a..6a9b143 100644 (file)
@@ -1,3 +1,10 @@
+2011-07-20  Richard Guenther  <rguenther@suse.de>
+
+       PR middle-end/18908
+       * tree.c (integer_all_onesp): Use TYPE_PRECISION, not mode precision.
+       * tree-ssa-forwprop.c (simplify_bitwise_binary): Remove bogus
+       ADDR_EXPR folding.  Canonicalize X ^ ~0 as ~X.
+
 2011-07-20  Vladimir Makarov  <vmakarov@redhat.com>
 
        * config/frv/frv.c (frv_register_move_cost): Define explicitly
index 9138237..1e2bc1c 100644 (file)
@@ -1,3 +1,9 @@
+2011-07-20  Richard Guenther  <rguenther@suse.de>
+
+       PR middle-end/18908
+       * gcc.dg/tree-ssa/pr18908.c: New testcase.
+       * gcc.dg/tree-ssa/bitwise-sink.c: Adjust.
+
 2011-07-20  Chung-Lin Tang  <cltang@codesourcery.com>
 
        * gcc.target/arm/combine-movs.c: New.
index f445299..1de04bc 100644 (file)
@@ -7,5 +7,5 @@ foo (_Bool x)
   return (x ^ 1);
 }
 
-/* { dg-final { scan-tree-dump-times "x\[^ \]* \\^ 1" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "~x" 1 "optimized" } } */
 /* { dg-final { cleanup-tree-dump "optimized" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr18908.c b/gcc/testsuite/gcc.dg/tree-ssa/pr18908.c
new file mode 100644 (file)
index 0000000..cfc92fe
--- /dev/null
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-forwprop1" } */
+
+_Bool f3(_Bool *p) { *p ^= 1; }
+
+/* We should be able to canonicalize the above to use bitwise not.  */
+/* { dg-final { scan-tree-dump "~D" "forwprop1" } } */
+/* { dg-final { scan-tree-dump-not "\\\^ 1" "forwprop1" } } */
+/* { dg-final { cleanup-tree-dump "forwprop1" } } */
index 5a40f5e..577609b 100644 (file)
@@ -1710,37 +1710,6 @@ simplify_bitwise_binary (gimple_stmt_iterator *gsi)
   tree def1_arg1, def2_arg1;
   enum tree_code def1_code, def2_code;
 
-  /* If the first argument is an SSA name that is itself a result of a
-     typecast of an ADDR_EXPR to an integer, feed the ADDR_EXPR to the
-     folder rather than the ssa name.  */
-  if (code == BIT_AND_EXPR
-      && TREE_CODE (arg2) == INTEGER_CST
-      && TREE_CODE (arg1) == SSA_NAME)
-    {
-      gimple def = SSA_NAME_DEF_STMT (arg1);
-      tree op = arg1;
-
-      /* ???  This looks bogus - the conversion could be truncating.  */
-      if (is_gimple_assign (def)
-         && CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (def))
-         && INTEGRAL_TYPE_P (TREE_TYPE (arg1)))
-       {
-         tree opp = gimple_assign_rhs1 (def);
-         if (TREE_CODE (opp) == ADDR_EXPR)
-           op = opp;
-       }
-
-      res = fold_binary_loc (gimple_location (stmt),
-                            BIT_AND_EXPR, TREE_TYPE (gimple_assign_lhs (stmt)),
-                            op, arg2);
-      if (res && is_gimple_min_invariant (res))
-       {
-         gimple_assign_set_rhs_from_tree (gsi, res);
-         update_stmt (stmt);
-         return true;
-       }
-    }
-
   def1_code = TREE_CODE (arg1);
   def1_arg1 = arg1;
   if (TREE_CODE (arg1) == SSA_NAME)
@@ -1862,6 +1831,17 @@ simplify_bitwise_binary (gimple_stmt_iterator *gsi)
       return true;
     }
 
+  /* Canonicalize X ^ ~0 to ~X.  */
+  if (code == BIT_XOR_EXPR
+      && TREE_CODE (arg2) == INTEGER_CST
+      && integer_all_onesp (arg2))
+    {
+      gimple_assign_set_rhs_with_ops (gsi, BIT_NOT_EXPR, arg1, NULL_TREE);
+      gcc_assert (gsi_stmt (*gsi) == stmt);
+      update_stmt (stmt);
+      return true;
+    }
+
   /* Try simple folding for X op !X, and X op X.  */
   res = simplify_bitwise_binary_1 (code, TREE_TYPE (arg1), arg1, arg2);
   if (res != NULL_TREE)