OSDN Git Service

gcc/
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.dg / pr48616.c
1 /* PR tree-optimization/48616 */
2 /* { dg-do run } */
3 /* { dg-options "-O2 -ftree-vectorize" } */
4 /* { dg-options "-O2 -ftree-vectorize -fno-common" { target alpha*-dec-osf* hppa*-*-hpux* } } */
5
6 extern void abort (void);
7 int a[4] __attribute__((aligned (32)));
8 int b[4] __attribute__((aligned (32)));
9 int c[4] __attribute__((aligned (32)));
10 int d[4] __attribute__((aligned (32)));
11 int e[4] __attribute__((aligned (32)));
12
13 __attribute__((noinline, noclone))
14 int
15 foo (int x)
16 {
17   asm ("" : "+r" (x));
18   return x;
19 }
20
21 __attribute__((noinline, noclone))
22 void
23 fn1 (int i)
24 {
25   a[0] = b[0] << c[0];
26   a[1] = b[1] << c[1];
27   a[2] = b[2] << c[2];
28   a[3] = b[3] << c[3];
29   if (i)
30     {
31       d[0] = e[0] >> c[0];
32       d[1] = e[1] >> c[1];
33       d[2] = e[2] >> c[2];
34       d[3] = e[3] >> c[3];
35     }
36 }
37
38 __attribute__((noinline, noclone))
39 void
40 fn2 (int i)
41 {
42   a[0] = b[0] << 1;
43   a[1] = b[1] << 2;
44   a[2] = b[2] << 3;
45   a[3] = b[3] << 4;
46   if (i)
47     {
48       d[0] = e[0] >> 1;
49       d[1] = e[1] >> 2;
50       d[2] = e[2] >> 3;
51       d[3] = e[3] >> 4;
52     }
53 }
54
55 __attribute__((noinline, noclone))
56 void
57 fn3 (int i, int j)
58 {
59   int x = foo (j);
60   a[0] = b[0] << x;
61   a[1] = b[1] << x;
62   a[2] = b[2] << x;
63   a[3] = b[3] << x;
64   if (i)
65     {
66       d[0] = e[0] >> x;
67       d[1] = e[1] >> x;
68       d[2] = e[2] >> x;
69       d[3] = e[3] >> x;
70     }
71 }
72
73 __attribute__((noinline, noclone))
74 void
75 fn4 (int i)
76 {
77   a[0] = b[0] << 1;
78   a[1] = b[1] << 1;
79   a[2] = b[2] << 1;
80   a[3] = b[3] << 1;
81   if (i)
82     {
83       d[0] = e[0] >> 1;
84       d[1] = e[1] >> 1;
85       d[2] = e[2] >> 1;
86       d[3] = e[3] >> 1;
87     }
88 }
89
90 int
91 main ()
92 {
93   int i;
94   int *t;
95   for (i = 0; i < 4; i++)
96     {
97       b[i] = 32;
98       c[i] = i + 1;
99       e[i] = 32;
100     }
101   asm volatile ("" : : "r" (b) : "memory");
102   asm volatile ("" : : "r" (c) : "memory");
103   asm volatile ("" : "=r" (t) : "0" (d) : "memory");
104   fn1 (t != 0);
105   for (i = 0; i < 4; i++)
106     {
107       if (a[i] != (32 << (i + 1)) || d[i] != (32 >> (i + 1)))
108         abort ();
109       a[i] = 0;
110       d[i] = 0;
111     }
112   fn2 (t != 0);
113   for (i = 0; i < 4; i++)
114     {
115       if (a[i] != (32 << (i + 1)) || d[i] != (32 >> (i + 1)))
116         abort ();
117       a[i] = 0;
118       d[i] = 0;
119     }
120   fn3 (t != 0, t != 0);
121   for (i = 0; i < 4; i++)
122     {
123       if (a[i] != (32 << 1) || d[i] != (32 >> 1))
124         abort ();
125       a[i] = 0;
126       d[i] = 0;
127     }
128   fn4 (t != 0);
129   for (i = 0; i < 4; i++)
130     {
131       if (a[i] != (32 << 1) || d[i] != (32 >> 1))
132         abort ();
133     }
134   return 0;
135 }