From a3cdf7c0cadca64ff0efa9c56ff1ed50fee70575 Mon Sep 17 00:00:00 2001
From: Thomas Preud'homme <thomas.preudhomme@arm.com>
Date: Wed, 29 Oct 2014 10:33:46 +0000
Subject: [PATCH] optimize-bswapsi-1.c (swap32_e): New bswap test.

2014-10-29  Thomas Preud'homme  <thomas.preudhomme@arm.com>

    gcc/testsuite/
    * gcc.dg/optimize-bswapsi-1.c (swap32_e): New bswap test.
    * gcc.dg/optimize-bswapsi-3.c: New test.

From-SVN: r216830
---
 gcc/testsuite/ChangeLog                   |  5 +++++
 gcc/testsuite/gcc.dg/optimize-bswapsi-1.c | 16 ++++++++++++++-
 gcc/testsuite/gcc.dg/optimize-bswapsi-3.c | 24 +++++++++++++++++++++++
 3 files changed, 44 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/optimize-bswapsi-3.c

diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index e8ec94a97d7b..52a9e5490751 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2014-10-29  Thomas Preud'homme  <thomas.preudhomme@arm.com>
+
+	* gcc.dg/optimize-bswapsi-1.c (swap32_e): New bswap test.
+	* gcc.dg/optimize-bswapsi-3.c: New test.
+
 2014-10-20  Alexander Ivchenko  <alexander.ivchenko@intel.com>
 	    Maxim Kuznetsov  <maxim.kuznetsov@intel.com>
 	    Anna Tikhonova  <anna.tikhonova@intel.com>
diff --git a/gcc/testsuite/gcc.dg/optimize-bswapsi-1.c b/gcc/testsuite/gcc.dg/optimize-bswapsi-1.c
index 580e6e0fee2c..cfde2182e4cb 100644
--- a/gcc/testsuite/gcc.dg/optimize-bswapsi-1.c
+++ b/gcc/testsuite/gcc.dg/optimize-bswapsi-1.c
@@ -64,5 +64,19 @@ swap32_d (SItype in)
 	 | (((in >> 24) & 0xFF) << 0);
 }
 
-/* { dg-final { scan-tree-dump-times "32 bit bswap implementation found at" 4 "bswap" } } */
+/* This variant is adapted from swap32_d above.  It detects missing cast of
+   MARKER_BYTE_UNKNOWN to uint64_t for the CASE_CONVERT case for host
+   architecture where a left shift with too big an operand mask its high
+   bits.  */
+
+SItype
+swap32_e (SItype in)
+{
+  return (((in >> 0) & 0xFF) << 24)
+	 | (((in >> 8) & 0xFF) << 16)
+	 | (((((int64_t) in) & 0xFF0000FF0000) >> 16) << 8)
+	 | (((in >> 24) & 0xFF) << 0);
+}
+
+/* { dg-final { scan-tree-dump-times "32 bit bswap implementation found at" 5 "bswap" } } */
 /* { dg-final { cleanup-tree-dump "bswap" } } */
diff --git a/gcc/testsuite/gcc.dg/optimize-bswapsi-3.c b/gcc/testsuite/gcc.dg/optimize-bswapsi-3.c
new file mode 100644
index 000000000000..79f2147e3a29
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/optimize-bswapsi-3.c
@@ -0,0 +1,24 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target bswap32 } */
+/* { dg-require-effective-target stdint_types } */
+/* { dg-options "-O2 -fdump-tree-bswap" } */
+/* { dg-additional-options "-march=z900" { target s390-*-* } } */
+
+typedef int SItype __attribute__ ((mode (SI)));
+typedef int DItype __attribute__ ((mode (DI)));
+
+/* This variant comes from optimize-bswapsi-1.c swap32_d.  It detects a missing
+   cast of MARKER_BYTE_UNKNOWN to uint64_t for the CASE_CONVERT case for host
+   architecture where a left shift with too big an operand gives zero.  */
+
+SItype
+swap32 (SItype in)
+{
+  return (((in >> 0) & 0xFF) << 24)
+	 | (((in >> 8) & 0xFF) << 16)
+	 | (((((DItype) in) & 0xFF00FF0000llu) >> 16) << 8)
+	 | (((in >> 24) & 0xFF) << 0);
+}
+
+/* { dg-final { scan-tree-dump-not "32 bit bswap implementation found at" "bswap" } } */
+/* { dg-final { cleanup-tree-dump "bswap" } } */
-- 
GitLab