libcpp, c, middle-end: Optimize initializers using #embed in C
[official-gcc.git] / gcc / testsuite / gcc.dg / tree-ssa / predcom-dse-11.c
blobed2b96a0d1a4e0c90bf52a83b5f21e2fd1c5a5c5
1 /* { dg-do run } */
2 /* { dg-options "-O2 -fno-inline -fpredictive-commoning -fdump-tree-pcom-details-blocks" } */
4 int arr[105] = {2, 3, 5, 7, 11};
5 int x[105] = {2, 3, 5, 7, 11};
6 int result0[10] = {2, 3, 5, 7, 11};
7 int result1[10] = {0, 0, 0, 0, 0, 0, -1, -2, -2};
9 extern void abort (void);
11 int __attribute__((noinline)) foo (int * __restrict__ a, int * __restrict__ b, int len, int flag)
13 int i, sum = 0;
14 for (i = 0; i < len; i++)
16 a[i] = 0;
17 b[i + 2] = i;
18 a[i + 1] = -1;
19 sum += b[i];
20 a[i + 3] = -2;
22 return sum;
25 void check (int *a, int *res, int len, int sum, int val)
27 int i;
29 if (sum != val)
30 abort ();
32 for (i = 0; i < len; i++)
33 if (a[i] != res[i])
34 abort ();
37 int main (void)
39 int i, sum;
41 sum = foo (arr, x, 0, 0);
42 check (arr, result0, 10, sum, 0);
44 sum = foo (arr, x, 6, 0);
45 check (arr, result1, 10, sum, 11);
47 return 0;
49 /* { dg-final { scan-tree-dump "Store-stores chain" "pcom"} } */
50 /* { dg-final { scan-tree-dump "Store-loads chain" "pcom"} } */
51 /* { dg-final { scan-tree-dump-not "Invalid sum" "pcom" } } */