OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gcc-4.2.2/] [gcc/] [testsuite/] [g++.dg/] [opt/] [range-test-1.C] - Blame information for rev 816

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 149 jeremybenn
// Test fold-const.c (fold_range_test) optimizations.
2
// { dg-do run } */
3
// { dg-options "-O2" } */
4
 
5
#ifndef __RANGE_TEST_HDR_INCL
6
#define __RANGE_TEST_HDR_INCL
7
/* Protect against fix-header weakness */
8
#include 
9
#include 
10
#include 
11
#endif
12
 
13
#if (INT_MAX == 2147483647) && (INT_MIN == -2147483648) \
14
    && (SCHAR_MIN == -128) && (SCHAR_MAX == 127) \
15
    && (UCHAR_MIN == 0) && (UCHAR_MAX == 255)
16
 
17
#ifndef T
18
 
19
enum integers
20
{
21
  int_smallest = INT_MIN,
22
  int_2ndsmallest = INT_MIN + 1,
23
  int_3rdsmallest = INT_MIN + 2,
24
  int_minus2 = -2,
25
  int_minus1 = -1,
26
  int_zero = 0,
27
  int_one = 1,
28
  int_two = 2,
29
  int_3rdlargest = INT_MAX - 2,
30
  int_2ndlargest = INT_MAX - 1,
31
  int_largest = INT_MAX
32
};
33
 
34
enum smallenum
35
{
36
  smalle_minus4 = -4,
37
  smalle_minus3 = -3,
38
  smalle_minus2 = -2,
39
  smalle_minus1 = -1,
40
  smalle_zero = 0,
41
  smalle_one = 1,
42
  smalle_two = 2,
43
  smalle_three = 3
44
};
45
 
46
enum enum2
47
{
48
  enum2_two = 2,
49
  enum2_three = 3,
50
  enum2_four = 4,
51
  enum2_five = 5
52
};
53
 
54
enum enum3
55
{
56
  enum3_zero,
57
  enum3_one,
58
  enum3_two,
59
  enum3_three,
60
  enum3_four,
61
  enum3_five,
62
  enum3_six,
63
  enum3_seven
64
};
65
 
66
int var;
67
void
68
check ()
69
{
70
  ++var;
71
}
72
 
73
#define T(IDX, TYPE, TEST, YESARR, NOARR)                               \
74
void __attribute__((noinline))                                          \
75
test##IDX (TYPE x)                                                      \
76
{                                                                       \
77
  if (TEST)                                                             \
78
    check ();                                                           \
79
}
80
#include "range-test-1.C"
81
#undef T
82
 
83
int
84
main ()
85
{
86
  int i, fails = 0;
87
 
88
#define C ,
89
#define T(IDX, TYPE, TEST, YESARR, NOARR)                               \
90
  {                                                                     \
91
    static TYPE yesarr##IDX [] = YESARR;                                \
92
    static TYPE noarr##IDX [] = NOARR;                                  \
93
    for (i = 0; i < (int) (sizeof (yesarr##IDX) / sizeof (TYPE)); ++i)  \
94
      {                                                                 \
95
        var = 0;                                                        \
96
        test##IDX (yesarr##IDX [i]);                                    \
97
        if (var != 1)                                                   \
98
          printf ("test" #IDX " failed for yesarr [%u]\n", i), ++fails; \
99
      }                                                                 \
100
    var = 0;                                                            \
101
    for (i = 0; i < (int) (sizeof (noarr##IDX) / sizeof (TYPE)); ++i)   \
102
      {                                                                 \
103
        test##IDX (noarr##IDX [i]);                                     \
104
        if (var != 0)                                                   \
105
          printf ("test" #IDX " failed for noarr [%u]\n", i), ++fails;  \
106
      }                                                                 \
107
  }
108
#include "range-test-1.C"
109
#undef T
110
 
111
  if (fails)
112
    abort ();
113
 
114
  exit (0);
115
}
116
 
117
#else
118
 
119
/* Use `C' instead of `,' below to separate array entries.  */
120
 
121
/* These ought to be all optimized into single comparison.  */
122
T(1, unsigned int, x == 0 || x == 1,
123
  { 0 C 1 }, { -1U C 2 C 12 C 35 C 0x7fffffff C 0x80000000 })
124
T(2, unsigned int, x == 0 || x == -1U || x == -2U,
125
  { 0 C -1U C -2U }, { -3U C -6U C 1 C 2 C 12 C 35 C 0x7fffffff C 0x80000000 })
126
T(3, unsigned int, x == 0 || x == 1 || x == 2,
127
  { 0 C 1 C 2 }, { -3U C -6U C -1U C -2U C 12 C 35 C 0x7fffffff C 0x80000000 })
128
T(4, unsigned int, x == 3 || x == 4 || x == 5 || x == 6,
129
  { 3 C 4 C 5 C 6 }, { -3U C 0 C 1 C 2 C 7 C 8 C 12 C 0x7fffffff C 0x80000000 })
130
T(5, unsigned int, x == -3U || x == -4U || x == -5U || x == -6U,
131
  { -3U C -4U C -5U C -6U }, { -7U C -8U C -2U C -1U C 1 C 2 C 0x7fffffff C 0x80000000 })
132
T(6, unsigned int, x == -3U || x == -4U || x == -5U,
133
  { -3U C -4U C -5U }, { -6U C -7U C -8U C -2U C -1U C 1 C 2 C 0x7fffffff C 0x80000000 })
134
T(7, char *, x == (char *) -3UL || x == (char *) -4UL || x == (char *) -5UL,
135
  { (char *) -3UL C (char *) -4UL C (char *) -5UL },
136
  { (char *) -6UL C (char *) -20UL C (char *) -2UL C (char *) -1UL C (char *) 0
137
    C (char *) 1UL C (char *) 35UL C (char *) 0x7fffffffUL C (char *) 0x80000000UL })
138
T(8, unsigned long, x == -2UL || x == -1UL || x == 0,
139
  { 0 C -1UL C -2UL }, { -3UL C -6UL C 1 C 2 C 12 C 35 C 0x7fffffff C 0x80000000 })
140
T(9, unsigned long, x >= -4UL || x <= 8,
141
  { -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 },
142
  { -7UL C -5UL C 9 C 10 C 61 C 127 C 0x7fffffff C 0x80000000 })
143
T(10, signed char, x == 0 || x == -1 || x == -2 || x == -3,
144
  { 0 C -1 C -2 C -3 }, { -4 C -5 C 1 C 2 C 3 C 35 C -24 })
145
T(11, int, x == 0 || x == 1,
146
  { 0 C 1 }, { -1 C 2 C 12 C 35 C INT_MAX C INT_MIN })
147
T(12, int, x == 0 || x == -1 || x == -2,
148
  { 0 C -1 C -2 }, { -3 C -6 C 1 C 2 C 12 C 35 C INT_MAX C INT_MIN })
149
T(13, int, x == 0 || x == 1 || x == 2,
150
  { 0 C 1 C 2 }, { -3 C -6 C -1 C -2 C 12 C 35 C INT_MAX C INT_MIN })
151
T(14, int, x == 3 || x == 4 || x == 5 || x == 6,
152
  { 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 })
153
T(15, int, x == -3 || x == -4 || x == -5 || x == -6,
154
  { -3 C -4 C -5 C -6 }, { -7 C -8 C -2 C -1 C 1 C 2 C INT_MAX C INT_MIN })
155
T(16, int, x == -3 || x == -4 || x == -5,
156
  { -3 C -4 C -5 }, { -6 C -7 C -8 C -2 C -1 C 1 C 2 C INT_MAX C INT_MIN })
157
T(17, unsigned int, (x >= -8U && x <= -3U) || x == -2U || x == -1U || x == 0 || x == 1 || x == 2,
158
  { -8U C -7U C -6U C -5U C -4U C -3U C -2U C -1U C 0 C 1 C 2 },
159
  { -9U C -10U C 3 C 4 C 12 C -54U C INT_MAX C INT_MIN })
160
T(18, int, (x >= -8 && x <= -3) || x == -2 || x == -1 || x == 0 || x == 1 || x == 2,
161
  { -8 C -7 C -6 C -5 C -4 C -3 C -2 C -1 C 0 C 1 C 2 },
162
  { -9 C -10 C 3 C 4 C 12 C -54 C INT_MAX C INT_MIN })
163
T(19, unsigned long, x <= 16 || (x >= 18 && x <= -1UL),
164
  { -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
165
    C 0x80000000 }, { 17 })
166
T(20, char *, x == (char *) -1UL || x == 0,
167
  { (char *) -1UL C 0 }, { (char *) -6UL C (char *) -20UL C (char *) -2UL
168
    C (char *) 1UL C (char *) 35UL C (char *) 0x7fffffffUL C (char *) 0x80000000UL })
169
T(21, integers, x == int_zero || x == int_one,
170
  { int_zero C int_one }, { int_minus1 C int_two C int_largest C int_smallest })
171
T(22, int, x == INT_MIN || x == INT_MAX,
172
  { INT_MIN C INT_MAX },
173
  { -1 C 0 C 1 C INT_MAX - 1 C INT_MAX - 2 C INT_MIN + 1 C INT_MIN + 2 })
174
T(23, int, x == INT_MIN + 1 || x == INT_MIN + 2 || x == INT_MIN || x == INT_MAX,
175
  { INT_MIN + 1 C INT_MIN + 2 C INT_MIN C INT_MAX },
176
  { -1 C 0 C 1 C INT_MAX - 1 C INT_MAX - 2 C INT_MIN + 3 C INT_MIN + 4 })
177
T(24, signed char, x == SCHAR_MIN || x == SCHAR_MAX,
178
  { SCHAR_MIN C SCHAR_MAX },
179
  { -1 C 0 C 1 C SCHAR_MAX - 1 C SCHAR_MAX - 2 C SCHAR_MIN + 1 C SCHAR_MIN + 2 })
180
T(25, integers, x == int_smallest || x == int_largest,
181
  { int_smallest C int_largest }, { int_minus1 C int_zero C int_one
182
    C int_2ndsmallest C int_2ndlargest C int_3rdsmallest C int_3rdlargest })
183
 
184
/* These should be optimized into unconditional jumps.  */
185
T(o1, unsigned long, x <= 16 || (x >= 17 && x <= -1UL),
186
  { -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
187
    C 0x80000000 }, { })
188
T(o2, unsigned long, x <= -3UL || (x == -2UL || x == -1UL),
189
  { -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
190
    C 0x80000000 }, { })
191
 
192
/* These should be eventually optimized into a single comparison.  */
193
T(td1, unsigned char, x == 0 || x == 4 || x == 1 || x == 5 || x == 2 || x == 6 || x == 3,
194
  { 0 C 1 C 2 C 3 C 4 C 5 C 6 }, { 7 C 8 C 127 C 128 C 254 C 255 })
195
 
196
/* These should not be optimized into a single comparison.  */
197
T(n1, smallenum, x == smalle_minus4 || x == smalle_three,
198
  { smalle_minus4 C smalle_three }, { smalle_minus3 C smalle_minus2 C smalle_minus1
199
    C smalle_zero C smalle_one C smalle_two })
200
T(n2, enum2, x == enum2_two || x == enum2_five,
201
  { enum2_two C enum2_five }, { enum2_three C enum2_four })
202
T(n3, enum3, x == enum3_zero || x == enum3_seven,
203
  { enum3_zero C enum3_seven }, { enum3_one C enum3_two C enum3_three C enum3_four
204
    C enum3_five C enum3_six })
205
 
206
#endif
207
 
208
#else
209
 
210
int
211
main (void)
212
{
213
  return 0;
214
}
215
 
216
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.