1 /* PR middle-end/21137  */
2 /* { dg-do compile } */
3 /* { dg-options "-O2 -fdump-tree-original" } */
4 extern void foo();
5 
test1(int a)6 void test1(int a)
7 {
8   if ((a >> 3) & 1)
9     foo ();
10 }
11 
test2(int b)12 void test2(int b)
13 {
14   if ((b >> 3) & 4)
15     foo ();
16 }
17 
test3(int c)18 int test3(int c)
19 {
20   return (c >> 3) & 1;
21 }
22 
test4(int d)23 int test4(int d)
24 {
25   return (d >> 3) & 4;
26 }
27 
28 #if __INT_MAX__ == 32767
29 #define INT_BITS 16
30 #elif __INT_MAX__ == 2147483647
31 #define INT_BITS 32
32 #elif __INT_MAX__ == 9223372036854775807
33 #define INT_BITS 64
34 #else
35 #error Please add support for your target here.
36 #endif
37 
test5(int e)38 void test5(int e)
39 {
40   if ((e >> (INT_BITS - 1)) & 64)
41     foo();
42 }
43 
test6(unsigned int f)44 void test6(unsigned int f)
45 {
46   if ((f >> (INT_BITS - 1)) & 64)
47     foo();
48 }
49 
50 /* { dg-final { scan-tree-dump-times "\\(a \& 8\\) != 0" 1 "original" } } */
51 /* { dg-final { scan-tree-dump-times "\\(b \& 32\\) != 0" 1 "original" } } */
52 /* { dg-final { scan-tree-dump-times "c >> 3 \& 1" 1 "original" } } */
53 /* { dg-final { scan-tree-dump-times "d >> 3 \& 4" 1 "original" } } */
54 /* { dg-final { scan-tree-dump-times "e < 0" 1 "original" } } */
55 /* { dg-final { scan-tree-dump-times "if \\(0\\)" 1 "original" } } */
56