libcpp, c, middle-end: Optimize initializers using #embed in C
[official-gcc.git] / gcc / testsuite / gcc.dg / tree-ssa / bitcmp-6.c
blobcea377489eb3a8c59b3a75d309042917855f44fa
1 /* { dg-do compile } */
2 /* { dg-options "-O2 -fdump-tree-optimized" } */
3 /* PR tree-optimization/101590 */
5 /* These are the signed integer versions
6 of `(a & b) CMP a` and `(a | b) CMP a`
7 which can be optimized to 0. */
9 #if __SIZEOF_INT__ < 4
10 #define int __INT32_TYPE__
11 #endif
13 /* For `&`, the non-negativeness of b is not taken into account. */
14 int f_and_gt(int len) {
15 len &= 0xfffff;
16 const int N = 4;
17 int newlen = len & -N;
18 return newlen > len; // return 0
20 int f_and_gt_(int len, int N) {
21 len &= 0xfffff;
22 int newlen = len & -N;
23 return newlen > len; // return 0
26 /* For `|`, to get a known value, b either needs to be non-negative
27 or a constant. For the negative constant case, we swap around the comparison. */
28 int f_or_lt_(int len, int N) {
29 len &= 0xfffff;
30 N &= 0xffff;
31 int newlen = len | N;
32 return newlen < len; // return 0
34 int f_or_ge(int len) {
35 len &= 0xfffff;
36 const int N = 4;
37 int newlen = len | -N;
38 return newlen >= len; // return 0
41 /* { dg-final { scan-tree-dump-not " > " "optimized" } } */
42 /* { dg-final { scan-tree-dump-not " < " "optimized" } } */
43 /* { dg-final { scan-tree-dump-not " & " "optimized" } } */
44 /* { dg-final { scan-tree-dump-not " \\\| " "optimized" } } */
45 /* { dg-final { scan-tree-dump-times "return 0;" 4 "optimized" } } */