1 /* { dg-require-effective-target vect_float } */
2 
3 #include <stdarg.h>
4 #include "tree-vect.h"
5 
6 #define N 256
7 
8 float pa[N] __attribute__ ((__aligned__(__BIGGEST_ALIGNMENT__)));
9 float pb[N] __attribute__ ((__aligned__(__BIGGEST_ALIGNMENT__))) = {0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54,57};
10 float pc[N] __attribute__ ((__aligned__(__BIGGEST_ALIGNMENT__))) = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19};
11 
12 /* Check handling of unaligned accesses when the misalignment is
13    known at compile time and different accesses have the same
14    misalignment (e.g. peeling to align one access will align all
15    accesses with the same misalignment.  Also, the number of
16    peeled iterations is known in this case, and the vectorizer
17    can use this information (generate prolog and epilog loops
18    with known number of iterations, and only if needed).  */
19 
20 __attribute__ ((noinline)) int
main1()21 main1 ()
22 {
23   int i;
24 
25   for (i = 0; i < 10; i++)
26     {
27       pa[i+1] = pb[i+1] * pc[i+1];
28     }
29 
30   /* check results:  */
31   for (i = 0; i < 10; i++)
32     {
33       if (pa[i+1] != (pb[i+1] * pc[i+1]))
34 	abort ();
35     }
36 
37   return 0;
38 }
39 
40 __attribute__ ((noinline)) int
main2()41 main2 ()
42 {
43   int i;
44 
45   for (i = 0; i < 12; i++)
46     {
47       pa[i+1] = pb[i+1] * pc[i+1];
48     }
49 
50   /* check results:  */
51   for (i = 0; i < 12; i++)
52     {
53       if (pa[i+1] != (pb[i+1] * pc[i+1]))
54 	abort ();
55     }
56 
57   return 0;
58 }
59 
60 __attribute__ ((noinline)) int
main3(int n)61 main3 (int n)
62 {
63   int i;
64 
65   for (i = 0; i < n; i++)
66     {
67       pa[i+1] = pb[i+1] * pc[i+1];
68     }
69 
70   /* check results:  */
71   for (i = 0; i < n; i++)
72     {
73       if (pa[i+1] != (pb[i+1] * pc[i+1]))
74 	abort ();
75     }
76 
77   return 0;
78 }
79 
main(void)80 int main (void)
81 {
82   int i;
83 
84   check_vect ();
85 
86   main1 ();
87   main2 ();
88   main3 (N-1);
89 
90   return 0;
91 }
92 
93 /* { dg-final { scan-tree-dump-times "vectorized 1 loops" 3 "vect" } } */
94 /* { dg-final { scan-tree-dump-times "Vectorizing an unaligned access" 0 "vect" } } */
95 /* { dg-final { scan-tree-dump-times "Alignment of access forced using peeling" 3 "vect" } } */
96