aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/fold-popcount-6.c
blob: 7e67c6e6ab2c9abb50270abd8f775aeacde09411 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/* { dg-do compile } */
/* { dg-options "-O2 -fdump-tree-optimized" } */

int foo(unsigned int x)
{
#if __SIZEOF_INT__ == 4
  return __builtin_popcount (__builtin_bswap32(x));
#elif __SIZEOF_INT__ == 2
  return __builtin_popcount (__builtin_bswap16(x));
#else
  return x;
#endif
}

int bar(unsigned long x)
{
#if __SIZEOF_LONG__ == 8
  return __builtin_popcountl (__builtin_bswap64(x));
#elif __SIZEOF_LONG__ == 4
  return __builtin_popcountl (__builtin_bswap32(x));
#else
  return x;
#endif
}

int baz(unsigned long long x)
{
#if __SIZEOF_LONG_LONG__ == 8
  return __builtin_popcountll (__builtin_bswap64(x));
#elif __SIZEOF_LONG_LONG__ == 4
  return __builtin_popcountll (__builtin_bswap32(x));
#else
  return x;
#endif
}

/* { dg-final { scan-tree-dump-not "bswap" "optimized" } } */