eacb76a7c37f3ee050dcb77fd7a915d139f15e71
[oota-llvm.git] / test / LLC / bigstack.c
1 /*===- test/Regression/Transforms/Scalar/DecomposeMultiDimRefs.cpp     -----=*
2  * 
3  * This is a feature test that checks for correct code generation
4  * of the SAVE instruction when the stack size does not fit in the
5  * immediate field of the SAVE instruction.  This happens in main().
6  *===---------------------------------------------------------------------===*/
7
8 #include <stdlib.h>
9 #include <stdio.h>
10
11 typedef struct Flat_struct {
12   char   c;
13   float  x;
14 } Flat_t;
15
16 typedef struct Mixed_struct {
17   int    N;
18   double A[10];
19   double B[10][10];
20   Flat_t F[10];
21 } Mixed_t;
22
23
24 double
25 AddMixed(Mixed_t* M)
26 {
27   double sum = 0;
28   int i, j;
29   
30   for (i=0; i < 10; ++i)
31     sum += M->A[i];
32   
33   for (i=0; i < 10; ++i)
34     for (j=0; j < 10; ++j)
35       sum += M->B[i][j];
36   
37   for (i=0; i < 10; ++i) {
38     sum += (double) M->F[i].c;
39     sum += M->F[i].x;
40   }
41   
42   return sum;
43 }
44
45 void
46 InitializeMixed(Mixed_t* M, int base)
47 {
48   int i, j;
49   
50   for (i=0; i < 10; ++i)
51     M->A[i] = i + base;
52     
53   for (i=0; i < 10; ++i)
54     for (j=0; j < 10; ++j)
55       M->B[i][j] = i*10 + j + base;
56   
57   for (i=0; i < 10; ++i) {
58     M->F[i].c = 'Q';
59     M->F[i].x = i / 10 + base;
60   }
61 }
62
63 int
64 main(int argc, char** argv)
65 {
66   Mixed_t M;
67   Mixed_t MA[4];
68   int i;
69   
70   InitializeMixed(&M, 100);
71   printf("Sum(M)  = %.2f\n", AddMixed(&M));
72   
73   for (i=0; i < 4; i++) {
74     InitializeMixed(&MA[i], 100 * (i+2));
75     printf("Sum(MA[%d]) = %.2f\n", i, AddMixed(&MA[i]));
76   }
77
78   return 0;
79 }