]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR tree-optimization/60454 (Code mistakenly detected as doing bswap)
authorJoey Ye <joey.ye@arm.com>
Thu, 13 Mar 2014 07:00:05 +0000 (07:00 +0000)
committerJoey Ye <jye2@gcc.gnu.org>
Thu, 13 Mar 2014 07:00:05 +0000 (07:00 +0000)
2014-03-13  Joey Ye  <joey.ye@arm.com>

        Backport from mainline
        2014-03-12  Thomas Preud'homme  <thomas.preudhomme@arm.com>

        PR tree-optimization/60454
        * tree-ssa-math-opts.c (find_bswap_1): Fix bswap detection.

testsuite:
        * gcc.c-torture/execute/pr60454.c: New test.

From-SVN: r208529

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/pr60454.c [new file with mode: 0644]
gcc/tree-ssa-math-opts.c

index 0c4dc21a52d27fec2faaeea174fdc5d6b30c7d85..0f643817c1800a1612477da3929f7fde93f07e5e 100644 (file)
@@ -1,3 +1,11 @@
+2014-03-13  Joey Ye  <joey.ye@arm.com>
+
+       Backport from mainline
+       2014-03-12  Thomas Preud'homme  <thomas.preudhomme@arm.com>
+
+       PR tree-optimization/60454
+       * tree-ssa-math-opts.c (find_bswap_1): Fix bswap detection.
+
 2014-03-06  Matthias Klose  <doko@ubuntu.com>
 
        * Makefile.in (s-mlib): Only pass MULTIARCH_DIRNAME if
index f5f0edfca6377792a3669a848bde7b44b6755cd2..a736c0791018a2060c7bbaced8f89cdd7cd67949 100644 (file)
@@ -1,3 +1,11 @@
+2014-03-13  Joey Ye  <joey.ye@arm.com>
+
+       Backport from mainline
+       2014-03-12  Thomas Preud'homme  <thomas.preudhomme@arm.com>
+
+       PR tree-optimization/60454
+       * gcc.c-torture/execute/pr60454.c: New test.
+
 2014-03-08  Janus Weil  <janus@gcc.gnu.org>
 
        PR fortran/60450
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr60454.c b/gcc/testsuite/gcc.c-torture/execute/pr60454.c
new file mode 100644 (file)
index 0000000..ceec45e
--- /dev/null
@@ -0,0 +1,31 @@
+#ifdef __UINT32_TYPE__
+typedef __UINT32_TYPE__ uint32_t;
+#else
+typedef unsigned uint32_t;
+#endif
+
+#define __fake_const_swab32(x) ((uint32_t)(                          \
+        (((uint32_t)(x) & (uint32_t)0x000000ffUL) << 24) |            \
+        (((uint32_t)(x) & (uint32_t)0x0000ff00UL) <<  8) |            \
+        (((uint32_t)(x) & (uint32_t)0x000000ffUL) <<  8) |            \
+        (((uint32_t)(x) & (uint32_t)0x0000ff00UL)      ) |            \
+        (((uint32_t)(x) & (uint32_t)0xff000000UL) >> 24)))
+
+/* Previous version of bswap optimization would detect byte swap when none
+   happen. This test aims at catching such wrong detection to avoid
+   regressions.  */
+
+__attribute__ ((noinline, noclone)) uint32_t
+fake_swap32 (uint32_t in)
+{
+  return __fake_const_swab32 (in);
+}
+
+int main(void)
+{
+  if (sizeof (uint32_t) * __CHAR_BIT__ != 32)
+    return 0;
+  if (fake_swap32 (0x12345678UL) != 0x78567E12UL)
+    __builtin_abort ();
+  return 0;
+}
index 2140ced495b8cf4f5b2971b31b083c62430070b2..508a240bf89e4f61b9aedc1d6d8808a1edc20b90 100644 (file)
@@ -1718,7 +1718,9 @@ find_bswap_1 (gimple stmt, struct symbolic_number *n, int limit)
 
   if (rhs_class == GIMPLE_BINARY_RHS)
     {
+      int i;
       struct symbolic_number n1, n2;
+      unsigned HOST_WIDEST_INT mask;
       tree source_expr2;
 
       if (code != BIT_IOR_EXPR)
@@ -1744,6 +1746,15 @@ find_bswap_1 (gimple stmt, struct symbolic_number *n, int limit)
            return NULL_TREE;
 
          n->size = n1.size;
+         for (i = 0, mask = 0xff; i < n->size; i++, mask <<= BITS_PER_UNIT)
+           {
+             unsigned HOST_WIDEST_INT masked1, masked2;
+
+             masked1 = n1.n & mask;
+             masked2 = n2.n & mask;
+             if (masked1 && masked2 && masked1 != masked2)
+               return NULL_TREE;
+           }
          n->n = n1.n | n2.n;
 
          if (!verify_symbolic_number_p (n, stmt))