From 0eeb34b29937338a8087216c49d3837b69107238 Mon Sep 17 00:00:00 2001 From: Dmitrij Pochepko Date: Tue, 8 Oct 2019 21:53:03 +0000 Subject: [PATCH] re PR tree-optimization/90836 (Missing popcount pattern matching) 2019-10-08 Dmitrij Pochepko PR tree-optimization/90836 * lib/target-supports.exp (check_effective_target_popcount) (check_effective_target_popcountll): New effective targets. * gcc.dg/tree-ssa/popcount4.c: New test. * gcc.dg/tree-ssa/popcount4l.c: New test. * gcc.dg/tree-ssa/popcount4ll.c: New test. From-SVN: r276722 --- gcc/testsuite/ChangeLog | 9 +++++++++ gcc/testsuite/gcc.dg/tree-ssa/popcount4.c | 22 +++++++++++++++++++++ gcc/testsuite/gcc.dg/tree-ssa/popcount4l.c | 30 +++++++++++++++++++++++++++++ gcc/testsuite/gcc.dg/tree-ssa/popcount4ll.c | 19 ++++++++++++++++++ gcc/testsuite/lib/target-supports.exp | 23 ++++++++++++++++++++++ 5 files changed, 103 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/popcount4.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/popcount4l.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/popcount4ll.c diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 1b6c04a..d9d73db 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,12 @@ +2019-10-08 Dmitrij Pochepko + + PR tree-optimization/90836 + * lib/target-supports.exp (check_effective_target_popcount) + (check_effective_target_popcountll): New effective targets. + * gcc.dg/tree-ssa/popcount4.c: New test. + * gcc.dg/tree-ssa/popcount4l.c: New test. + * gcc.dg/tree-ssa/popcount4ll.c: New test. + 2019-10-08 Martin Sebor PR middle-end/92014 diff --git a/gcc/testsuite/gcc.dg/tree-ssa/popcount4.c b/gcc/testsuite/gcc.dg/tree-ssa/popcount4.c new file mode 100644 index 0000000..bfb563b --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/popcount4.c @@ -0,0 +1,22 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target popcount } */ +/* { dg-require-effective-target int32plus } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +const unsigned m1 = 0x55555555UL; +const unsigned m2 = 0x33333333UL; +const unsigned m4 = 0x0F0F0F0FUL; +const unsigned h01 = 0x01010101UL; +const int shift = 24; + +int popcount64c(unsigned x) +{ + x -= (x >> 1) & m1; + x = (x & m2) + ((x >> 2) & m2); + x = (x + (x >> 4)) & m4; + return (x * h01) >> shift; +} + +/* { dg-final { scan-tree-dump-times "\.POPCOUNT" 1 "optimized" } } */ + + diff --git a/gcc/testsuite/gcc.dg/tree-ssa/popcount4l.c b/gcc/testsuite/gcc.dg/tree-ssa/popcount4l.c new file mode 100644 index 0000000..69fb2d1 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/popcount4l.c @@ -0,0 +1,30 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target popcountl } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +#if __SIZEOF_LONG__ == 4 +const unsigned long m1 = 0x55555555UL; +const unsigned long m2 = 0x33333333UL; +const unsigned long m4 = 0x0F0F0F0FUL; +const unsigned long h01 = 0x01010101UL; +const int shift = 24; +#else +const unsigned long m1 = 0x5555555555555555UL; +const unsigned long m2 = 0x3333333333333333UL; +const unsigned long m4 = 0x0f0f0f0f0f0f0f0fUL; +const unsigned long h01 = 0x0101010101010101UL; +const int shift = 56; +#endif + + +int popcount64c(unsigned long x) +{ + x -= (x >> 1) & m1; + x = (x & m2) + ((x >> 2) & m2); + x = (x + (x >> 4)) & m4; + return (x * h01) >> shift; +} + +/* { dg-final { scan-tree-dump-times "\.POPCOUNT" 1 "optimized" } } */ + + diff --git a/gcc/testsuite/gcc.dg/tree-ssa/popcount4ll.c b/gcc/testsuite/gcc.dg/tree-ssa/popcount4ll.c new file mode 100644 index 0000000..191d957 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/popcount4ll.c @@ -0,0 +1,19 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target popcountll } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +const unsigned long long m1 = 0x5555555555555555ULL; +const unsigned long long m2 = 0x3333333333333333ULL; +const unsigned long long m4 = 0x0F0F0F0F0F0F0F0FULL; +const unsigned long long h01 = 0x0101010101010101ULL; +const int shift = 56; + +int popcount64c(unsigned long long x) +{ + x -= (x >> 1) & m1; + x = (x & m2) + ((x >> 2) & m2); + x = (x + (x >> 4)) & m4; + return (x * h01) >> shift; +} + +/* { dg-final { scan-tree-dump-times "\.POPCOUNT" 1 "optimized" } } */ diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp index a7b76b6..179202f 100644 --- a/gcc/testsuite/lib/target-supports.exp +++ b/gcc/testsuite/lib/target-supports.exp @@ -6933,6 +6933,29 @@ proc check_effective_target_popcountl { } { } "" ] } +# Return 1 if the target supports popcount on long long. + +proc check_effective_target_popcountll { } { + return [check_no_messages_and_pattern popcountll "!\\(call" rtl-expand { + int foo (long long b) + { + return __builtin_popcountll (b); + } + } "" ] +} + + +# Return 1 if the target supports popcount on int. + +proc check_effective_target_popcount { } { + return [check_no_messages_and_pattern popcount "!\\(call" rtl-expand { + int foo (int b) + { + return __builtin_popcount (b); + } + } "" ] +} + # Return 1 if the target supports atomic operations on "long long" # and can execute them. # -- 2.7.4