Tighten condition in vect/pr85586.c (PR 85654)
[official-gcc.git] / gcc / testsuite / gcc.dg / range-test-1.c
blob93a90ac7187b5849351d64c1a101472e23d9cc0c
1 /* Test fold-const.c (fold_range_test) optimizations. */
2 /* { dg-do run } */
3 /* { dg-options "-O2" } */
5 #include <stdlib.h>
6 #include <stdio.h>
7 #include <limits.h>
9 #if (INT_MAX == 2147483647) && (INT_MIN == -2147483648) \
10 && (SCHAR_MIN == -128) && (SCHAR_MAX == 127) \
11 && (UCHAR_MIN == 0) && (UCHAR_MAX == 255)
13 #ifndef T
15 enum integers
17 int_smallest = INT_MIN,
18 int_2ndsmallest = INT_MIN + 1,
19 int_3rdsmallest = INT_MIN + 2,
20 int_minus2 = -2,
21 int_minus1 = -1,
22 int_zero = 0,
23 int_one = 1,
24 int_two = 2,
25 int_3rdlargest = INT_MAX - 2,
26 int_2ndlargest = INT_MAX - 1,
27 int_largest = INT_MAX
30 int var;
31 void
32 check (void)
34 ++var;
37 #define T(IDX, TYPE, TEST, YESARR, NOARR) \
38 void __attribute__((noinline)) \
39 test##IDX (TYPE x) \
40 { \
41 if (TEST) \
42 check (); \
44 #include "range-test-1.c"
45 #undef T
47 int
48 main (void)
50 int i, fails = 0;
52 #define C ,
53 #define T(IDX, TYPE, TEST, YESARR, NOARR) \
54 { \
55 static TYPE yesarr##IDX [] = YESARR; \
56 static TYPE noarr##IDX [] = NOARR; \
57 for (i = 0; i < (int) (sizeof (yesarr##IDX) / sizeof (TYPE)); ++i) \
58 { \
59 var = 0; \
60 test##IDX (yesarr##IDX [i]); \
61 if (var != 1) \
62 printf ("test" #IDX " failed for yesarr [%u]\n", i), ++fails; \
63 } \
64 var = 0; \
65 for (i = 0; i < (int) (sizeof (noarr##IDX) / sizeof (TYPE)); ++i) \
66 { \
67 test##IDX (noarr##IDX [i]); \
68 if (var != 0) \
69 printf ("test" #IDX " failed for noarr [%u]\n", i), ++fails; \
70 } \
72 #include "range-test-1.c"
73 #undef T
75 if (fails)
76 abort ();
78 exit (0);
81 #else
83 /* Use `C' instead of `,' below to separate array entries. */
85 /* These ought to be all optimized into single comparison. */
86 T(1, unsigned int, x == 0 || x == 1,
87 { 0 C 1 }, { -1U C 2 C 12 C 35 C 0x7fffffff C 0x80000000 })
88 T(2, unsigned int, x == 0 || x == -1U || x == -2U,
89 { 0 C -1U C -2U }, { -3U C -6U C 1 C 2 C 12 C 35 C 0x7fffffff C 0x80000000 })
90 T(3, unsigned int, x == 0 || x == 1 || x == 2,
91 { 0 C 1 C 2 }, { -3U C -6U C -1U C -2U C 12 C 35 C 0x7fffffff C 0x80000000 })
92 T(4, unsigned int, x == 3 || x == 4 || x == 5 || x == 6,
93 { 3 C 4 C 5 C 6 }, { -3U C 0 C 1 C 2 C 7 C 8 C 12 C 0x7fffffff C 0x80000000 })
94 T(5, unsigned int, x == -3U || x == -4U || x == -5U || x == -6U,
95 { -3U C -4U C -5U C -6U }, { -7U C -8U C -2U C -1U C 1 C 2 C 0x7fffffff C 0x80000000 })
96 T(6, unsigned int, x == -3U || x == -4U || x == -5U,
97 { -3U C -4U C -5U }, { -6U C -7U C -8U C -2U C -1U C 1 C 2 C 0x7fffffff C 0x80000000 })
98 T(7, char *, x == (char *) -3UL || x == (char *) -4UL || x == (char *) -5UL,
99 { (char *) -3UL C (char *) -4UL C (char *) -5UL },
100 { (char *) -6UL C (char *) -20UL C (char *) -2UL C (char *) -1UL C (char *) 0
101 C (char *) 1UL C (char *) 35UL C (char *) 0x7fffffffUL C (char *) 0x80000000UL })
102 T(8, unsigned long, x == -2UL || x == -1UL || x == 0,
103 { 0 C -1UL C -2UL }, { -3UL C -6UL C 1 C 2 C 12 C 35 C 0x7fffffff C 0x80000000 })
104 T(9, unsigned long, x >= -4UL || x <= 8,
105 { -4UL C -3UL C -2UL C -1UL C 0 C 1 C 2 C 3 C 4 C 5 C 6 C 7 C 8 },
106 { -7UL C -5UL C 9 C 10 C 61 C 127 C 0x7fffffff C 0x80000000 })
107 T(10, signed char, x == 0 || x == -1 || x == -2 || x == -3,
108 { 0 C -1 C -2 C -3 }, { -4 C -5 C 1 C 2 C 3 C 35 C -24 })
109 T(11, int, x == 0 || x == 1,
110 { 0 C 1 }, { -1 C 2 C 12 C 35 C INT_MAX C INT_MIN })
111 T(12, int, x == 0 || x == -1 || x == -2,
112 { 0 C -1 C -2 }, { -3 C -6 C 1 C 2 C 12 C 35 C INT_MAX C INT_MIN })
113 T(13, int, x == 0 || x == 1 || x == 2,
114 { 0 C 1 C 2 }, { -3 C -6 C -1 C -2 C 12 C 35 C INT_MAX C INT_MIN })
115 T(14, int, x == 3 || x == 4 || x == 5 || x == 6,
116 { 3 C 4 C 5 C 6 }, { -3 C 0 C 1 C 2 C 7 C 8 C 12 C INT_MAX C INT_MIN })
117 T(15, int, x == -3 || x == -4 || x == -5 || x == -6,
118 { -3 C -4 C -5 C -6 }, { -7 C -8 C -2 C -1 C 1 C 2 C INT_MAX C INT_MIN })
119 T(16, int, x == -3 || x == -4 || x == -5,
120 { -3 C -4 C -5 }, { -6 C -7 C -8 C -2 C -1 C 1 C 2 C INT_MAX C INT_MIN })
121 T(17, unsigned int, (x >= -8U && x <= -3U) || x == -2U || x == -1U || x == 0 || x == 1 || x == 2,
122 { -8U C -7U C -6U C -5U C -4U C -3U C -2U C -1U C 0 C 1 C 2 },
123 { -9U C -10U C 3 C 4 C 12 C -54U C INT_MAX C INT_MIN })
124 T(18, int, (x >= -8 && x <= -3) || x == -2 || x == -1 || x == 0 || x == 1 || x == 2,
125 { -8 C -7 C -6 C -5 C -4 C -3 C -2 C -1 C 0 C 1 C 2 },
126 { -9 C -10 C 3 C 4 C 12 C -54 C INT_MAX C INT_MIN })
127 T(19, unsigned long, (x >= 0 && x <= 16) || (x >= 18 && x <= -1UL),
128 { -3UL C -6UL C -1UL C 0 C 1 C 2 C 12 C 15 C 16 C 18 C 19 C 35 C 0x7fffffff
129 C 0x80000000 }, { 17 })
130 T(20, char *, x == (char *) -1UL || x == 0,
131 { (char *) -1UL C 0 }, { (char *) -6UL C (char *) -20UL C (char *) -2UL
132 C (char *) 1UL C (char *) 35UL C (char *) 0x7fffffffUL C (char *) 0x80000000UL })
133 T(21, enum integers, x == int_zero || x == int_one,
134 { int_zero C int_one }, { int_minus1 C int_two C 12 C 35 C int_largest C int_smallest })
135 T(22, int, x == INT_MIN || x == INT_MAX,
136 { INT_MIN C INT_MAX },
137 { -1 C 0 C 1 C INT_MAX - 1 C INT_MAX - 2 C INT_MIN + 1 C INT_MIN + 2 })
138 T(23, int, x == INT_MIN + 1 || x == INT_MIN + 2 || x == INT_MIN || x == INT_MAX,
139 { INT_MIN + 1 C INT_MIN + 2 C INT_MIN C INT_MAX },
140 { -1 C 0 C 1 C INT_MAX - 1 C INT_MAX - 2 C INT_MIN + 3 C INT_MIN + 4 })
141 T(24, signed char, x == SCHAR_MIN || x == SCHAR_MAX,
142 { SCHAR_MIN C SCHAR_MAX },
143 { -1 C 0 C 1 C SCHAR_MAX - 1 C SCHAR_MAX - 2 C SCHAR_MIN + 1 C SCHAR_MIN + 2 })
144 T(25, enum integers, x == int_smallest || x == int_largest,
145 { int_smallest C int_largest }, { int_minus1 C int_zero C int_one
146 C int_2ndsmallest C int_2ndlargest C int_3rdsmallest C int_3rdlargest })
148 /* This should be optimized into unconditional jump. */
149 T(o1, unsigned long, (x >= 0 && x <= 16) || (x >= 17 && x <= -1UL),
150 { -3UL C -6UL C -1UL C 0 C 1 C 2 C 12 C 15 C 16 C 17 C 18 C 19 C 35 C 0x7fffffff
151 C 0x80000000 }, { })
152 T(o2, unsigned long, (x >= 0 && x <= -3UL) || (x == -2UL || x == -1UL),
153 { -3UL C -6UL C -1UL C 0 C 1 C 2 C 12 C 15 C 16 C 17 C 18 C 19 C 35 C 0x7fffffff
154 C 0x80000000 }, { })
156 /* This should be eventually optimized into a single comparison. */
157 T(td1, unsigned char, x == 0 || x == 4 || x == 1 || x == 5 || x == 2 || x == 6 || x == 3,
158 { 0 C 1 C 2 C 3 C 4 C 5 C 6 }, { 7 C 8 C 127 C 128 C 254 C 255 })
160 #endif
162 #else
164 main (void)
166 return 0;
168 #endif