tree-optimization/114760 - check variants of >> and << in loop-niter
[official-gcc.git] / gcc / testsuite / gcc.dg / tree-ssa / pr114760-1.c
blob9f10ccc3b5107d8dc39ac1da20db178c692e2146
1 /* PR tree-optimization/114760 */
2 /* { dg-do compile } */
3 /* { dg-require-effective-target clz } */
4 /* { dg-require-effective-target ctz } */
5 /* { dg-options "-O3 -fdump-tree-optimized" } */
7 unsigned
8 ntz32_1 (unsigned x)
10 int n = 32;
11 while (x != 0)
13 n = n - 1;
14 x = x * 2;
16 return n;
19 unsigned
20 ntz32_2 (unsigned x)
22 int n = 32;
23 while (x != 0)
25 n = n - 1;
26 x = x + x;
28 return n;
31 unsigned
32 ntz32_3 (unsigned x)
34 int n = 32;
35 while (x != 0)
37 n = n - 1;
38 x = x << 1;
40 return n;
43 #define PREC (__CHAR_BIT__ * __SIZEOF_INT__)
44 int
45 nlz32_1 (unsigned int b) {
46 int c = PREC;
48 while (b != 0) {
49 b >>= 1;
50 c --;
53 return c;
56 int
57 nlz32_2 (unsigned int b) {
58 int c = PREC;
60 while (b != 0) {
61 b /= 2;
62 c --;
65 return c;
68 /* { dg-final { scan-tree-dump-times "__builtin_ctz|\\.CTZ" 3 "optimized" } } */
69 /* { dg-final { scan-tree-dump-times "__builtin_clz|\\.CLZ" 2 "optimized" } } */