Merge from mainline (167278:168000).
[official-gcc/graphite-test-results.git] / gcc / testsuite / gcc.target / ia64 / 20040709-2.c
blob585ab06f00e0013cd983ee7baaf9cdfedb63ad9b
1 /* Check for ia64 data speculation failure with '-O2 -funroll-loops'. */
3 /* { dg-do compile } */
4 /* { dg-options "-O2 -funroll-loops -Wno-overflow" } */
6 extern void abort (void);
7 extern void exit (int);
9 unsigned int
10 myrnd (void)
12 static unsigned int s = 1388815473;
13 s *= 1103515245;
14 s += 12345;
15 return (s / 65536) % 2048;
18 #define T(S) \
19 struct S s##S; \
20 struct S retme##S (struct S x) \
21 { \
22 return x; \
23 } \
25 unsigned int fn1##S (unsigned int x) \
26 { \
27 struct S y = s##S; \
28 y.k += x; \
29 y = retme##S (y); \
30 return y.k; \
31 } \
33 unsigned int fn2##S (unsigned int x) \
34 { \
35 struct S y = s##S; \
36 y.k += x; \
37 y.k %= 15; \
38 return y.k; \
39 } \
41 unsigned int retit##S (void) \
42 { \
43 return s##S.k; \
44 } \
46 unsigned int fn3##S (unsigned int x) \
47 { \
48 s##S.k += x; \
49 return retit##S (); \
50 } \
52 void test##S (void) \
53 { \
54 int i; \
55 unsigned int mask, v, a, r; \
56 struct S x; \
57 char *p = (char *) &s##S; \
58 for (i = 0; i < sizeof (s##S); ++i) \
59 *p++ = myrnd (); \
60 if (__builtin_classify_type (s##S.l) == 8) \
61 s##S.l = 5.25; \
62 s##S.k = -1; \
63 mask = s##S.k; \
64 v = myrnd (); \
65 a = myrnd (); \
66 s##S.k = v; \
67 x = s##S; \
68 r = fn1##S (a); \
69 if (x.i != s##S.i || x.j != s##S.j \
70 || x.k != s##S.k || x.l != s##S.l \
71 || ((v + a) & mask) != r) \
72 abort (); \
73 v = myrnd (); \
74 a = myrnd (); \
75 s##S.k = v; \
76 x = s##S; \
77 r = fn2##S (a); \
78 if (x.i != s##S.i || x.j != s##S.j \
79 || x.k != s##S.k || x.l != s##S.l \
80 || ((((v + a) & mask) % 15) & mask) != r) \
81 abort (); \
82 v = myrnd (); \
83 a = myrnd (); \
84 s##S.k = v; \
85 x = s##S; \
86 r = fn3##S (a); \
87 if (x.i != s##S.i || x.j != s##S.j \
88 || s##S.k != r || x.l != s##S.l \
89 || ((v + a) & mask) != r) \
90 abort (); \
93 #define pck __attribute__((packed))
94 struct pck A { unsigned short i : 1, l : 1, j : 3, k : 11; }; T(A)
95 struct pck B { unsigned short i : 4, j : 1, k : 11; unsigned int l; }; T(B)
96 struct pck C { unsigned int l; unsigned short i : 4, j : 1, k : 11; }; T(C)
97 struct pck D { unsigned long long l : 6, i : 6, j : 23, k : 29; }; T(D)
98 struct pck E { unsigned long long l, i : 12, j : 23, k : 29; }; T(E)
99 struct pck F { unsigned long long i : 12, j : 23, k : 29, l; }; T(F)
100 struct pck G { unsigned short i : 1, j : 1, k : 6; unsigned long long l; }; T(G)
101 struct pck H { unsigned short i : 6, j : 2, k : 8; unsigned long long l; }; T(H)
102 struct pck I { unsigned short i : 1, j : 6, k : 1; unsigned long long l; }; T(I)
103 struct pck J { unsigned short i : 1, j : 8, k : 7; unsigned short l; }; T(J)
104 struct pck K { unsigned int k : 6, l : 1, j : 10, i : 15; }; T(K)
105 struct pck L { unsigned int k : 6, j : 11, i : 15; unsigned int l; }; T(L)
106 struct pck M { unsigned int l; unsigned short k : 6, j : 11, i : 15; }; T(M)
107 struct pck N { unsigned long long l : 6, k : 6, j : 23, i : 29; }; T(N)
108 struct pck O { unsigned long long l, k : 12, j : 23, i : 29; }; T(O)
109 struct pck P { unsigned long long k : 12, j : 23, i : 29, l; }; T(P)
110 struct pck Q { unsigned short k : 12, j : 1, i : 3; unsigned long long l; }; T(Q)
111 struct pck R { unsigned short k : 2, j : 11, i : 3; unsigned long long l; }; T(R)
112 struct pck S { unsigned short k : 1, j : 6, i : 9; unsigned long long l; }; T(S)
113 struct pck T { unsigned short k : 1, j : 8, i : 7; unsigned short l; }; T(T)
114 struct pck U { unsigned short j : 6, k : 1, i : 9; unsigned long long l; }; T(U)
115 struct pck V { unsigned short j : 8, k : 1, i : 7; unsigned short l; }; T(V)
116 struct pck W { long double l; unsigned int k : 12, j : 13, i : 7; }; T(W)
117 struct pck X { unsigned int k : 12, j : 13, i : 7; long double l; }; T(X)
118 struct pck Y { unsigned int k : 12, j : 11, i : 9; long double l; }; T(Y)
119 struct pck Z { long double l; unsigned int j : 13, i : 7, k : 12; }; T(Z)
122 main (void)
124 testA ();
125 testB ();
126 testC ();
127 testD ();
128 testE ();
129 testF ();
130 testG ();
131 testH ();
132 testI ();
133 testJ ();
134 testK ();
135 testL ();
136 testM ();
137 testN ();
138 testO ();
139 testP ();
140 testQ ();
141 testR ();
142 testS ();
143 testT ();
144 testU ();
145 testV ();
146 testW ();
147 testX ();
148 testY ();
149 testZ ();
150 exit (0);