1 /* { dg-do run } */
2 /* { dg-options "-O2 -ftree-pre -fno-tree-loop-im -fgcse-sm -fdump-rtl-store_motion" } */
3
4 /* tree-pre moves the *sum load out of the loop. ftree-loop-im moves the *sum
5 store out of the loop, so we disable it, to allow fgcse-sm to do it
6 instead. */
7
8 #include <stdlib.h>
9
10 void __attribute__((noinline))
11 f (unsigned int *__restrict__ a, unsigned int *__restrict__ sum, unsigned int n)
12 {
13 unsigned int i;
14 for (i = 0; i < n; ++i)
15 *sum += a[i];
16 }
17
18 int
19 main ()
20 {
21 unsigned int a[] = { 1, 10, 100 };
22 unsigned sum = 1000;
23
24 f (a, &sum, 3);
25 if (sum != 1111)
26 abort ();
27
28 return 0;
29 }
30
31 /* Check that -fgcse-sm did something for f. */
32 /* { dg-final { scan-rtl-dump "STORE_MOTION of f, .* basic blocks, 1 insns deleted, 1 insns created" "store_motion" } } */
33