Add documentation for musttail attribute
[official-gcc.git] / gcc / testsuite / gcc.target / powerpc / swaps-p8-33.c
blobba623662b5f1246297d1d2a7cadf49350794e37d
1 /* { dg-do compile } */
2 /* { dg-options "-mdejagnu-cpu=power8 -mvsx -O3 " } */
3 /* { dg-require-effective-target powerpc_vsx } */
5 /* Previous versions of this test required that the assembler does not
6 contain xxpermdi or xxswapd. However, with the more sophisticated
7 code generation used today, it is now possible that xxpermdi (aka
8 xxswapd) show up without being part of a lxvd2x or stxvd2x
9 sequence. */
11 #include <altivec.h>
13 extern void abort (void);
15 vector short x;
16 const vector short y = { 0, 1, 2, 3, 4, 5, 6, 7 };
17 vector short z;
19 vector short
20 foo (void)
22 return y; /* Remove 1 swap and use lvx. */
25 vector short
26 foo1 (void)
28 x = y; /* Remove 2 redundant swaps here. */
29 return x; /* Remove 1 swap and use lvx. */
32 void __attribute__ ((noinline))
33 fill_local (vector short *vp)
35 *vp = x; /* Remove 2 redundant swaps here. */
38 /* Test aligned load from local. */
39 vector short
40 foo2 (void)
42 vector short v;
44 /* Need to be clever here because v will normally reside in a
45 register rather than memory. */
46 fill_local (&v);
47 return v; /* Remove 1 swap and use lvx. */
51 /* Test aligned load from pointer. */
52 vector short
53 foo3 (vector short *arg)
55 return *arg; /* Remove 1 swap and use lvx. */
58 /* In this structure, the compiler should insert padding to assure
59 that a_vector is properly aligned. */
60 struct bar {
61 short a_field;
62 vector short a_vector;
65 vector short
66 foo4 (struct bar *bp)
68 return bp->a_vector; /* Remove 1 swap and use lvx. */
71 /* Test aligned store to global. */
72 void
73 baz (vector short arg)
75 x = arg; /* Remove 1 swap and use stvx. */
78 void __attribute__ ((noinline))
79 copy_local (vector short *arg)
81 x = *arg; /* Remove 2 redundant swaps. */
85 /* Test aligned store to local. */
86 void
87 baz1 (vector short arg)
89 vector short v;
91 /* Need cleverness, because v will normally reside in a register
92 rather than memory. */
93 v = arg; /* Aligned store to local: remove 1
94 swap and use stvx. */
95 copy_local (&v);
98 /* Test aligned store to pointer. */
99 void
100 baz2 (vector short *arg1, vector short arg2)
102 /* Assume arg2 resides in register. */
103 *arg1 = arg2; /* Remove 1 swap and use stvx. */
106 void
107 baz3 (struct bar *bp, vector short v)
109 /* Assume v resides in register. */
110 bp->a_vector = v; /* Remove 1 swap and use stvx. */
114 main (int argc, short *argv[])
116 vector short fetched_value = foo ();
117 if (fetched_value[0] != 0 || fetched_value[7] != 7)
118 abort ();
120 fetched_value = foo1 ();
121 if (fetched_value[1] != 1 || fetched_value[6] != 6)
122 abort ();
124 fetched_value = foo2 ();
125 if (fetched_value[2] != 2 || fetched_value[5] != 5)
126 abort ();
128 fetched_value = foo3 (&x);
129 if (fetched_value[3] != 3 || fetched_value[4] != 4)
130 abort ();
132 struct bar a_struct;
133 a_struct.a_vector = x; /* Remove 2 redundant swaps. */
134 fetched_value = foo4 (&a_struct);
135 if (fetched_value[4] != 4 || fetched_value[3] != 3)
136 abort ();
138 for (int i = 0; i < 8; i++)
139 z[i] = 7 - i;
141 baz (z);
142 if (x[0] != 7 || x[7] != 0)
143 abort ();
145 vector short source = { 8, 7, 6, 5, 4, 3, 2, 1 };
147 baz1 (source);
148 if (x[3] != 5 || x[7] != 1)
149 abort ();
151 vector short dest;
152 baz2 (&dest, source);
153 if (dest[4] != 4 || dest[1] != 7)
154 abort ();
156 baz3 (&a_struct, source);
157 if (a_struct.a_vector[7] != 1 || a_struct.a_vector[5] != 3)
158 abort ();
160 return 0;