]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-ssa-math-opts.c (do_shift_rotate): Zero bits out of type precision after operation.
authorKai Tietz <ktietz@redhat.com>
Mon, 27 Jun 2011 13:44:52 +0000 (15:44 +0200)
committerKai Tietz <ktietz@gcc.gnu.org>
Mon, 27 Jun 2011 13:44:52 +0000 (15:44 +0200)
2011-06-27  Kai Tietz  <ktietz@redhat.com>

        * tree-ssa-math-opts.c (do_shift_rotate): Zero bits
        out of type precision after operation.
        (find_bswap): Take for limit value the integer auto-
        promotion into account.

ChangeLog

2011-06-27  Kai Tietz  <ktietz@redhat.com>

        * gcc.dg/optimize-bswapdi-2.c: New test.

From-SVN: r175528

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/optimize-bswapdi-2.c [new file with mode: 0644]
gcc/tree-ssa-math-opts.c

index ff7fe68d6790a29983d84a9ba3536d3e9a534ec2..c107dfd225d0a0b1b3e8c6e7d1e9062f742cdce4 100644 (file)
@@ -1,3 +1,10 @@
+2011-06-27  Kai Tietz  <ktietz@redhat.com>
+
+       * tree-ssa-math-opts.c (do_shift_rotate): Zero bits
+       out of type precision after operation.
+       (find_bswap): Take for limit value the integer auto-
+       promotion into account.
+
 2011-06-27  Eric Botcazou  <ebotcazou@adacore.com>
 
        * reorg.c (fill_simple_delay_slots): Use stop_search_p to stop the
index c833b41a6209ddebd66a3386608d3157a942ee89..975409ec860277e3180c382a02c718b6cc673abf 100644 (file)
@@ -1,3 +1,7 @@
+2011-06-27  Kai Tietz  <ktietz@redhat.com>
+
+       * gcc.dg/optimize-bswapdi-2.c: New test.
+
 2011-06-27  Michael Hope  <michael.hope@linaro.org>
            Richard Sandiford  <richard.sandiford@linaro.org>
 
diff --git a/gcc/testsuite/gcc.dg/optimize-bswapdi-2.c b/gcc/testsuite/gcc.dg/optimize-bswapdi-2.c
new file mode 100644 (file)
index 0000000..6e2821d
--- /dev/null
@@ -0,0 +1,26 @@
+/* { dg-do compile { target arm*-*-* alpha*-*-* ia64*-*-* x86_64-*-* s390x-*-* powerpc*-*-* rs6000-*-* } } */
+/* { dg-require-effective-target stdint_types } */
+/* { dg-require-effective-target lp64 } */
+/* { dg-options "-O2 -fdump-tree-bswap" } */
+
+#include <stdint.h>
+
+/* A variant via unsigned short.  */
+
+uint64_t
+swap64_c (uint64_t x)
+{
+  uint16_t a0 = x >> 48;
+  uint16_t a1 = x >> 32;
+  uint16_t a2 = x >> 16;
+  uint16_t a3 = x;
+
+  return ((uint64_t) (((a0 >> 8) & 0xff) | ((a0 << 8) & 0xff00)))
+       | ((uint64_t) (((a1 >> 8) & 0xff) | ((a1 << 8) & 0xff00)) << 16)
+       | ((uint64_t) (((a2 >> 8) & 0xff) | ((a2 << 8) & 0xff00)) << 32)
+       | ((uint64_t) (((a3 >> 8) & 0xff) | ((a3 << 8) & 0xff00)) << 48);
+}
+
+
+/* { dg-final { scan-tree-dump-times "64 bit bswap implementation found at" 1 "bswap" } } */
+/* { dg-final { cleanup-tree-dump "bswap" } } */
index bc7919a39ad3f71c380f6ad5bf8667f019091c72..4da401827f4f38b0fc6875dd3879218a74dce110 100644 (file)
@@ -1543,6 +1543,9 @@ do_shift_rotate (enum tree_code code,
     default:
       return false;
     }
+  /* Zero unused bits for size.  */
+  if (n->size < (int)sizeof (HOST_WIDEST_INT))
+    n->n &= ((unsigned HOST_WIDEST_INT)1 << (n->size * BITS_PER_UNIT)) - 1;
   return true;
 }
 
@@ -1740,15 +1743,16 @@ find_bswap (gimple stmt)
 
   struct symbolic_number n;
   tree source_expr;
+  int limit;
 
   /* The last parameter determines the depth search limit.  It usually
      correlates directly to the number of bytes to be touched.  We
-     increase that number by one here in order to also cover signed ->
-     unsigned conversions of the src operand as can be seen in
-     libgcc.  */
-  source_expr =  find_bswap_1 (stmt, &n,
-                              TREE_INT_CST_LOW (
-                                TYPE_SIZE_UNIT (gimple_expr_type (stmt))) + 1);
+     increase that number by three  here in order to also
+     cover signed -> unsigned converions of the src operand as can be seen
+     in libgcc, and for initial shift/and operation of the src operand.  */
+  limit = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (gimple_expr_type (stmt)));
+  limit += 1 + (int) ceil_log2 ((unsigned HOST_WIDE_INT) limit);
+  source_expr =  find_bswap_1 (stmt, &n, limit);
 
   if (!source_expr)
     return NULL_TREE;