struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / gcc-torture-execute-pr51581-2.c
blob0e035fd40ec0188f12f3de76c3f15db0e898b636
1 /*
2 pr51581-2.c from the execute part of the gcc torture tests.
3 */
5 #include <testfwk.h>
7 #ifdef __SDCC
8 #pragma std_c99
9 #endif
11 #include <limits.h>
13 /* PR tree-optimization/51581 */
14 /* { dg-require-effective-target int32plus } */
16 #ifndef __SDCC_pdk14 // Lack of memory
18 #define N 4
19 int a[N], c[N];
20 unsigned int b[N], d[N];
22 void
23 f1 (void)
25 int i;
26 for (i = 0; i < N; i++)
27 c[i] = a[i] % 3;
30 void
31 f2 (void)
33 int i;
34 for (i = 0; i < N; i++)
35 d[i] = b[i] % 3;
38 void
39 f3 (void)
41 int i;
42 for (i = 0; i < N; i++)
43 c[i] = a[i] % 18;
46 void
47 f4 (void)
49 int i;
50 for (i = 0; i < N; i++)
51 d[i] = b[i] % 18;
54 void
55 f5 (void)
57 int i;
58 for (i = 0; i < N; i++)
59 c[i] = a[i] % 19;
62 void
63 f6 (void)
65 int i;
66 for (i = 0; i < N; i++)
67 d[i] = b[i] % 19;
70 #if __SIZEOF_INT__ == 4 && __SIZEOF_LONG_LONG__ == 8
71 void
72 f7 (void)
74 int i;
75 for (i = 0; i < N; i++)
77 int x = (int) ((unsigned long long) (a[i] * 0x55555556LL) >> 32) - (a[i] >> 31);
78 c[i] = a[i] - x * 3;
82 void
83 f8 (void)
85 int i;
86 for (i = 0; i < N; i++)
88 unsigned int x = ((unsigned int) ((b[i] * 0xaaaaaaabULL) >> 32) >> 1);
89 d[i] = b[i] - x * 3;
93 void
94 f9 (void)
96 int i;
97 for (i = 0; i < N; i++)
99 int x = (((int) ((unsigned long long) (a[i] * 0x38e38e39LL) >> 32)) >> 2) - (a[i] >> 31);
100 c[i] = a[i] - x * 18;
104 void
105 f10 (void)
107 int i;
108 for (i = 0; i < N; i++)
110 unsigned int x = (unsigned int) ((b[i] * 0x38e38e39ULL) >> 32) >> 2;
111 d[i] = b[i] - x * 18;
115 void
116 f11 (void)
118 int i;
119 for (i = 0; i < N; i++)
121 int x = (((int) ((unsigned long long) (a[i] * 0x6bca1af3LL) >> 32)) >> 3) - (a[i] >> 31);
122 c[i] = a[i] - x * 19;
126 void
127 f12 (void)
129 int i;
130 for (i = 0; i < N; i++)
132 unsigned int tmp = (b[i] * 0xaf286bcbULL) >> 32;
133 unsigned int x = (((b[i] - tmp) >> 1) + tmp) >> 4;
134 d[i] = b[i] - x * 19;
137 #endif
138 #endif
140 void
141 testTortureExecute (void)
143 #ifndef __SDCC_pdk14 // Lack of memory
144 int i;
145 for (i = 0; i < N; i++)
147 #ifndef PORT_HOST
148 __asm;
149 __endasm;
150 #endif
151 a[i] = i - N / 2;
152 b[i] = i;
154 a[0] = -INT_MAX - 1;
155 a[1] = -INT_MAX;
156 a[N - 1] = INT_MAX;
157 b[N - 1] = ~0;
158 f1 ();
159 f2 ();
160 for (i = 0; i < N; i++)
161 if (c[i] != a[i] % 3 || d[i] != b[i] % 3)
162 ASSERT (0);
163 f3 ();
164 f4 ();
165 for (i = 0; i < N; i++)
166 if (c[i] != a[i] % 18 || d[i] != b[i] % 18)
167 ASSERT (0);
168 f5 ();
169 f6 ();
170 for (i = 0; i < N; i++)
171 if (c[i] != a[i] % 19 || d[i] != b[i] % 19)
172 ASSERT (0);
173 #if __SIZEOF_INT__ == 4 && __SIZEOF_LONG_LONG__ == 8
174 f7 ();
175 f8 ();
176 for (i = 0; i < N; i++)
177 if (c[i] != a[i] % 3 || d[i] != b[i] % 3)
178 ASSERT (0);
179 f9 ();
180 f10 ();
181 for (i = 0; i < N; i++)
182 if (c[i] != a[i] % 18 || d[i] != b[i] % 18)
183 ASSERT (0);
184 f11 ();
185 f12 ();
186 for (i = 0; i < N; i++)
187 if (c[i] != a[i] % 19 || d[i] != b[i] % 19)
188 ASSERT (0);
189 #endif
190 #endif