aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/testsuite')
-rw-r--r--gcc/testsuite/ChangeLog7
-rw-r--r--gcc/testsuite/gcc.dg/fold-popcount-1.c35
-rw-r--r--gcc/testsuite/gcc.dg/fold-popcount-2.c35
-rw-r--r--gcc/testsuite/gcc.dg/fold-popcount-3.c10
-rw-r--r--gcc/testsuite/gcc.dg/fold-popcount-4.c50
5 files changed, 137 insertions, 0 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 8a6fe20..f7d0c3a 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,10 @@
+2018-05-24 Roger Sayle <roger@nextmovesoftware.com>
+
+ * gcc.dg/fold-popcount-1.c: New testcase.
+ * gcc.dg/fold-popcount-2.c: New testcase.
+ * gcc.dg/fold-popcount-3.c: New testcase.
+ * gcc.dg/fold-popcount-4.c: New testcase.
+
2018-05-24 Marek Polacek <polacek@redhat.com>
PR c++/85847
diff --git a/gcc/testsuite/gcc.dg/fold-popcount-1.c b/gcc/testsuite/gcc.dg/fold-popcount-1.c
new file mode 100644
index 0000000..32bb7e2
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/fold-popcount-1.c
@@ -0,0 +1,35 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-original" } */
+
+int test_eqzero(unsigned int a)
+{
+ return __builtin_popcount(a) == 0;
+}
+
+int test_eqzerol(unsigned long b)
+{
+ return __builtin_popcountl(b) == 0;
+}
+
+int test_eqzeroll(unsigned long long c)
+{
+ return __builtin_popcountll(c) == 0;
+}
+
+int test_nezero(unsigned int d)
+{
+ return __builtin_popcount(d) != 0;
+}
+
+int test_nezerol(unsigned long e)
+{
+ return __builtin_popcountl(e) != 0;
+}
+
+int test_nezeroll(unsigned long long f)
+{
+ return __builtin_popcountll(f) != 0;
+}
+
+/* { dg-final { scan-tree-dump-times "popcount" 0 "original" } } */
+
diff --git a/gcc/testsuite/gcc.dg/fold-popcount-2.c b/gcc/testsuite/gcc.dg/fold-popcount-2.c
new file mode 100644
index 0000000..27557da
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/fold-popcount-2.c
@@ -0,0 +1,35 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-cddce1" } */
+
+int test_andone(unsigned int a)
+{
+ return __builtin_popcount(a&1);
+}
+
+int test_andonel(unsigned long b)
+{
+ return __builtin_popcountl(b&1);
+}
+
+int test_andonell(unsigned long long c)
+{
+ return __builtin_popcountll(c&1);
+}
+
+int test_oneand(unsigned int d)
+{
+ return __builtin_popcount(1&d);
+}
+
+int test_oneandl(unsigned long e)
+{
+ return __builtin_popcountl(1&e);
+}
+
+int test_oneandll(unsigned long long f)
+{
+ return __builtin_popcountll(1&f);
+}
+
+/* { dg-final { scan-tree-dump-times "popcount" 0 "cddce1" } } */
+
diff --git a/gcc/testsuite/gcc.dg/fold-popcount-3.c b/gcc/testsuite/gcc.dg/fold-popcount-3.c
new file mode 100644
index 0000000..eda0077
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/fold-popcount-3.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-cddce1" } */
+
+int test_combine(unsigned int a, unsigned int b)
+{
+ return __builtin_popcount(a&8) + __builtin_popcount(b&2);
+}
+
+/* { dg-final { scan-tree-dump-times "popcount" 1 "cddce1" } } */
+
diff --git a/gcc/testsuite/gcc.dg/fold-popcount-4.c b/gcc/testsuite/gcc.dg/fold-popcount-4.c
new file mode 100644
index 0000000..424c3d8
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/fold-popcount-4.c
@@ -0,0 +1,50 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-cddce1" } */
+
+int test_shiftmax(unsigned int a)
+{
+ return __builtin_popcount(a>>(8*sizeof(a)-1));
+}
+
+int test_shiftmaxl(unsigned long b)
+{
+ return __builtin_popcountl(b>>(8*sizeof(b)-1));
+}
+
+int test_shiftmaxll(unsigned long long c)
+{
+ return __builtin_popcountll(c>>(8*sizeof(c)-1));
+}
+
+int test_shift7(unsigned char d)
+{
+ return __builtin_popcount(d>>7);
+}
+
+int test_shift7l(unsigned char e)
+{
+ return __builtin_popcountl(e>>7);
+}
+
+int test_shift7ll(unsigned char f)
+{
+ return __builtin_popcountll(f>>7);
+}
+
+int test_shift15(unsigned short g)
+{
+ return __builtin_popcount(g>>15);
+}
+
+int test_shift15l(unsigned short h)
+{
+ return __builtin_popcountl(h>>15);
+}
+
+int test_shift15ll(unsigned short i)
+{
+ return __builtin_popcountll(i>>15);
+}
+
+/* { dg-final { scan-tree-dump-times "popcount" 0 "cddce1" } } */
+