Jakub Jelinek | 4eb4a25 | 2014-10-17 12:50:16 +0200 | [diff] [blame] | 1 | /* PR tree-optimization/63302 */ |
| 2 | |
| 3 | #ifdef __SIZEOF_INT128__ |
| 4 | #if __SIZEOF_INT128__ * __CHAR_BIT__ == 128 |
| 5 | #define USE_INT128 |
| 6 | #endif |
| 7 | #endif |
| 8 | #if __SIZEOF_LONG_LONG__ * __CHAR_BIT__ == 64 |
| 9 | #define USE_LLONG |
| 10 | #endif |
| 11 | |
| 12 | #ifdef USE_INT128 |
| 13 | __attribute__((noinline, noclone)) int |
| 14 | foo (__int128 x) |
| 15 | { |
| 16 | __int128 v = x & (((__int128) -1 << 63) | 0x7ff); |
| 17 | |
| 18 | return v == 0 || v == ((__int128) -1 << 63); |
| 19 | } |
| 20 | #endif |
| 21 | |
| 22 | #ifdef USE_LLONG |
| 23 | __attribute__((noinline, noclone)) int |
| 24 | bar (long long x) |
| 25 | { |
| 26 | long long v = x & (((long long) -1 << 31) | 0x7ff); |
| 27 | |
| 28 | return v == 0 || v == ((long long) -1 << 31); |
| 29 | } |
| 30 | #endif |
| 31 | |
| 32 | int |
| 33 | main () |
| 34 | { |
| 35 | #ifdef USE_INT128 |
| 36 | if (foo (0) != 1 |
| 37 | || foo (1) != 0 |
| 38 | || foo (0x800) != 1 |
| 39 | || foo (0x801) != 0 |
| 40 | || foo ((__int128) 1 << 63) != 0 |
| 41 | || foo ((__int128) -1 << 63) != 1 |
| 42 | || foo (((__int128) -1 << 63) | 1) != 0 |
| 43 | || foo (((__int128) -1 << 63) | 0x800) != 1 |
| 44 | || foo (((__int128) -1 << 63) | 0x801) != 0) |
| 45 | __builtin_abort (); |
| 46 | #endif |
| 47 | #ifdef USE_LLONG |
| 48 | if (bar (0) != 1 |
| 49 | || bar (1) != 0 |
| 50 | || bar (0x800) != 1 |
| 51 | || bar (0x801) != 0 |
| 52 | || bar (1LL << 31) != 0 |
| 53 | || bar (-1LL << 31) != 1 |
| 54 | || bar ((-1LL << 31) | 1) != 0 |
| 55 | || bar ((-1LL << 31) | 0x800) != 1 |
| 56 | || bar ((-1LL << 31) | 0x801) != 0) |
| 57 | __builtin_abort (); |
| 58 | #endif |
| 59 | return 0; |
| 60 | } |