Pick three bugfixes from next branch to trunk for inclusion in 4.5.0 RC2, as discusse...
[sdcc.git] / sdcc / support / regression / tests / gcc-torture-execute-pr28982a.c
blob2d93116377843c42edd34fb222a52d4e4588d266
1 /*
2 pr28982.c from the execute part of the gcc torture tests.
3 */
5 #include <testfwk.h>
7 #ifdef __SDCC
8 #pragma std_c99
9 #endif
11 // Lack of memory
12 #if defined(__SDCC_MODEL_SMALL) || defined(__SDCC_MODEL_MEDIUM) || \
13 (defined(__SDCC_mcs51) && defined(__SDCC_STACK_AUTO)) || defined (__SDCC_pdk14) || defined (__SDCC_pdk15) || defined (__SDCC_pic14)
14 #define SKIP
15 #endif
17 /* PR rtl-optimization/28982. Function foo() does the equivalent of:
19 float tmp_results[NVARS];
20 for (int i = 0; i < NVARS; i++)
22 int inc = incs[i];
23 float *ptr = ptrs[i], result = 0;
24 for (int j = 0; j < n; j++)
25 result += *ptr, ptr += inc;
26 tmp_results[i] = result;
28 memcpy (results, tmp_results, sizeof (results));
30 but without the outermost loop. The idea is to create high register
31 pressure and ensure that some INC and PTR variables are spilled.
33 On ARM targets, sequences like "result += *ptr, ptr += inc" can
34 usually be implemented using (mem (post_modify ...)), and we do
35 indeed create such MEMs before reload for this testcase. However,
36 (post_modify ...) is not a valid address for coprocessor loads, so
37 for -mfloat-abi=softfp, reload reloads the POST_MODIFY into a base
38 register. GCC did not deal correctly with cases where the base and
39 index of the POST_MODIFY are themselves reloaded. */
40 #define NITER 4
41 #define NVARS 20
42 #define MULTI(X) \
43 X( 0), X( 1), X( 2), X( 3), X( 4), X( 5), X( 6), X( 7), X( 8), X( 9), \
44 X(10), X(11), X(12), X(13), X(14), X(15), X(16), X(17), X(18), X(19)
46 #define DECLAREI(INDEX) inc##INDEX = incs[INDEX]
47 #define DECLAREF(INDEX) *ptr##INDEX = ptrs[INDEX], result##INDEX = 0
48 #define LOOP(INDEX) result##INDEX += *ptr##INDEX, ptr##INDEX += inc##INDEX
49 #define COPYOUT(INDEX) results[INDEX] = result##INDEX
51 #ifndef SKIP
52 float *ptrs[NVARS];
53 float results[NVARS];
54 int incs[NVARS];
56 void
57 foo (int n)
59 int MULTI (DECLAREI);
60 float MULTI (DECLAREF);
61 while (n--)
62 MULTI (LOOP);
63 MULTI (COPYOUT);
66 float input[NITER * NVARS];
67 #endif
69 void
70 testTortureExecute (void)
72 #ifndef SKIP
73 int i;
75 for (i = 0; i < NVARS; i++)
76 ptrs[i] = input + i, incs[i] = i;
77 for (i = 0; i < NITER * NVARS; i++)
78 input[i] = i;
79 foo (NITER);
80 for (i = 0; i < NVARS; i++)
81 if (results[i] != i * NITER * (NITER + 1) / 2)
82 ASSERT (0);
83 return;
84 #endif