PR middle-end/77357 - strlen of constant strings not folded
[official-gcc.git] / gcc / testsuite / gcc.dg / unroll-and-jam.c
blob70910d318cbc703986ede1adf62a6a16645db6fc
1 /* { dg-do run } */
2 /* { dg-options "-O3 -floop-unroll-and-jam --param unroll-jam-min-percent=0 -fdump-tree-unrolljam-details" } */
3 /* { dg-require-effective-target int32plus } */
5 #include <stdio.h>
6 extern unsigned int a[];
7 extern unsigned int b[];
8 extern unsigned int aa[][1024];
9 unsigned int checksum;
10 void checkaa(void)
12 unsigned sum = 1;
13 unsigned long i, j;
14 for (i = 0; i < 1024; i++) {
15 for (j = 0; j < 16; j++) {
16 sum += aa[j][i]*31+47;
19 checksum = checksum * 27 + sum;
20 //printf(" %d\n", sum);
23 void checkb(void)
25 unsigned sum = 1;
26 unsigned long i, j;
27 for (i = 0; i < 1024; i++) {
28 sum += b[i]*31+47;
30 checksum = checksum * 27 + sum;
31 //printf(" %d\n", sum);
34 #define TEST(name, body, test) \
35 static void __attribute__((noinline,noclone)) name (unsigned long n, unsigned long m) \
36 { \
37 unsigned long i, j; \
38 for (i = 1; i < m; i++) { \
39 for (j = 1; j < n; j++) { \
40 body; \
41 } \
42 } \
43 test; \
44 } \
45 static void __attribute__((noinline,noclone,optimize("O1"))) name ## noopt (unsigned long n, unsigned long m) \
46 { \
47 unsigned long i, j; \
48 for (i = 1; i < m; i++) { \
49 for (j = 1; j < n; j++) { \
50 body; \
51 } \
52 } \
53 test; \
55 TEST(foo1, aa[i+1][j+1]=aa[i][j] * aa[i][j] / 2, checkaa()) //ok, -1,-1
56 TEST(foo2, aa[i][j+1]=3*aa[i+1][j], checkaa()) //notok, 1,-1
57 TEST(foo3, aa[i+1][j-1]=aa[i][j] * aa[i][j] / 2, checkaa()) //notok, -1,1
58 TEST(foo4, aa[i][j] = aa[i-1][j+1] * aa[i-1][j+1] / 2, checkaa()) //notok, -1,1
59 TEST(foo5, aa[i][j] = aa[i+1][j+1] * aa[i+1][j+1] / 2, checkaa()) //ok, 1,1
60 TEST(foo6, aa[i][j] = aa[i+1][j] * aa[i+1][j] / 2, checkaa()) //ok, -1,0
61 TEST(foo7, aa[i+1][j] = aa[i][j] * aa[i][j] / 2, checkaa()) //ok, 1,0
62 TEST(foo9, b[j] = 3*b[j+1] + 1, checkb()) //notok, 0,-1
63 TEST(foo10, b[j] = 3*b[j] + 1, checkb()) //ok, 0,0
65 /* foo8 should work as well, but currently doesn't because the distance
66 vectors we compute are too pessimistic. We compute
67 (0,1), (1,1) and (1,-1)
68 and the last one causes us to lose. */
69 TEST(foo8, b[j+1] = 3*b[j] + 1, checkb()) //ok, 0,1
71 unsigned int a[1024];
72 unsigned int b[1024];
73 unsigned int aa[16][1024];
74 void init(void)
76 unsigned long i,j;
77 for (i = 0; i < 1024; i++) {
78 for (j = 0; j < 16; j++) {
79 aa[j][i] = ((j+1)*2+i+1) % 17;
81 a[i] = ((i+1)*31) % 19;
82 b[i] = ((i+1)*47) % 23;
84 checksum = 1;
87 #define RUN(name) \
88 printf(" %s\n", #name); \
89 init();for(i=0;i<4;i++)name##noopt(32,8); checka = checksum; \
90 init();for(i=0;i<4;i++)name(32,8); \
91 printf("%sok %s\n", checka != checksum ? "NOT " : "", #name);
93 int main()
95 int i;
96 unsigned checka;
97 RUN(foo1);
98 RUN(foo2);
99 RUN(foo3);
100 RUN(foo4);
101 RUN(foo5);
102 RUN(foo6);
103 RUN(foo7);
104 RUN(foo8);
105 RUN(foo9);
106 RUN(foo10);
107 return 0;
110 /* Five loops should be unroll-jammed (actually six, but see above). */
111 /* { dg-final { scan-tree-dump-times "applying unroll and jam" 5 "unrolljam" } } */