summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/tree-ssa/predcom-dse-1.c
blob: d3a2339e55e550831f481aa9b8743b165d0e485f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/* { dg-do run } */
/* { dg-options "-O2 -fno-inline -fpredictive-commoning -fdump-tree-pcom-details" } */

int arr[105] = {2, 3, 5, 7, 11};
int result0[10] = {2, 3, 5, 7, 11};
int result1[10] = {0, -1, 5, -2, 11, 0};
int result2[10] = {0, 0, -1, -2, -2, 0};
int result3[10] = {0, 0, 0, -1, -2, -2, 0};
int result4[10] = {0, 0, 0, 0, -1, -2, -2, 0};
int result100[105] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
		      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
		      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
		      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
		      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
		      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
		      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -2, -2, 0};

extern void abort (void);

void __attribute__((noinline)) foo (int *a, int len)
{
  int i;
  for (i = 0; i < len; i++)
    {
      a[i] = 0;
      a[i + 1] = -1;
      a[i + 3] = -2;
    }
}

void check (int *a, int *res, int len)
{
  int i;

  for (i = 0; i < len; i++)
    if (a[i] != res[i])
      abort ();
}

int main (void)
{
  foo (arr, 0);
  check (arr, result0, 10);

  foo (arr, 1);
  check (arr, result1, 10);

  foo (arr, 2);
  check (arr, result2, 10);

  foo (arr, 3);
  check (arr, result3, 10);

  foo (arr, 4);
  check (arr, result4, 10);

  foo (arr, 100);
  check (arr, result100, 105);

  return 0;
}
/* { dg-final { scan-tree-dump "Store-stores chain" "pcom"} } */