gcc/ChangeLog:
[official-gcc.git] / gcc / testsuite / gcc.target / powerpc / swaps-p8-34.c
blob8ee9795b9a5045052fef9ea741156f17852d509e
1 /* { dg-do run { target { powerpc*-*-* } } } */
2 /* { dg-require-effective-target p8vector_hw } */
3 /* { dg-skip-if "do not override -mcpu" { powerpc*-*-* } { "-mcpu=*" } { "-mcpu=power8" } } */
4 /* { dg-options "-mcpu=power8 -O3 " } */
6 #include <altivec.h>
8 extern void abort (void);
10 vector int x;
11 vector int y = { 0, 1, 2, 3 };
12 vector int z;
14 vector int
15 foo (void)
17 return y; /* Remove 1 swap and use lvx. */
20 vector int
21 foo1 (void)
23 x = y; /* Remove 2 redundant swaps here. */
24 return x; /* Remove 1 swap and use lvx. */
27 void __attribute__ ((noinline))
28 fill_local (vector int *vp)
30 *vp = x; /* Remove 2 redundant swaps here. */
33 /* Test aligned load from local. */
34 vector int
35 foo2 (void)
37 vector int v;
39 /* Need to be clever here because v will normally reside in a
40 register rather than memory. */
41 fill_local (&v);
42 return v; /* Remove 1 swap and use lvx. */
46 /* Test aligned load from pointer. */
47 vector int
48 foo3 (vector int *arg)
50 return *arg; /* Remove 1 swap and use lvx. */
53 /* In this structure, the compiler should insert padding to assure
54 that a_vector is properly aligned. */
55 struct bar {
56 short a_field;
57 vector int a_vector;
60 vector int
61 foo4 (struct bar *bp)
63 return bp->a_vector; /* Remove 1 swap and use lvx. */
66 /* Test aligned store to global. */
67 void
68 baz (vector int arg)
70 x = arg; /* Remove 1 swap and use stvx. */
73 void __attribute__ ((noinline))
74 copy_local (vector int *arg)
76 x = *arg; /* Remove 2 redundant swaps. */
80 /* Test aligned store to local. */
81 void
82 baz1 (vector int arg)
84 vector int v;
86 /* Need cleverness, because v will normally reside in a register
87 rather than memory. */
88 v = arg; /* Aligned store to local: remove 1
89 swap and use stvx. */
90 copy_local (&v);
93 /* Test aligned store to pointer. */
94 void
95 baz2 (vector int *arg1, vector int arg2)
97 /* Assume arg2 resides in register. */
98 *arg1 = arg2; /* Remove 1 swap and use stvx. */
101 void
102 baz3 (struct bar *bp, vector int v)
104 /* Assume v resides in register. */
105 bp->a_vector = v; /* Remove 1 swap and use stvx. */
109 main (int argc, int *argv[])
111 vector int fetched_value = foo ();
112 if (fetched_value[0] != 0 || fetched_value[3] != 3)
113 abort ();
115 fetched_value = foo1 ();
116 if (fetched_value[1] != 1 || fetched_value[2] != 2)
117 abort ();
119 fetched_value = foo2 ();
120 if (fetched_value[2] != 2 || fetched_value[1] != 1)
121 abort ();
123 fetched_value = foo3 (&x);
124 if (fetched_value[3] != 3 || fetched_value[0] != 0)
125 abort ();
127 struct bar a_struct;
128 a_struct.a_vector = x; /* Remove 2 redundant swaps. */
129 fetched_value = foo4 (&a_struct);
130 if (fetched_value[2] != 2 || fetched_value[3] != 3)
131 abort ();
133 z[0] = 7;
134 z[1] = 6;
135 z[2] = 5;
136 z[3] = 4;
138 baz (z);
139 if (x[0] != 7 || x[3] != 4)
140 abort ();
142 vector int source = { 8, 7, 6, 5 };
144 baz1 (source);
145 if (x[2] != 6 || x[1] != 7)
146 abort ();
148 vector int dest;
149 baz2 (&dest, source);
150 if (dest[0] != 8 || dest[1] != 7)
151 abort ();
153 baz3 (&a_struct, source);
154 if (a_struct.a_vector[3] != 5 || a_struct.a_vector[0] != 8)
155 abort ();
157 return 0;