1 /* { dg-do run } */
2 /* { dg-require-effective-target vect_double } */
3 /* { dg-require-effective-target vsx_hw { target { powerpc*-*-* } } } */
4 /* { dg-require-effective-target sse2_runtime { target { i?86-*-* x86_64-*-* } } } */
5 /* { dg-options "-O2 -ffast-math -fdump-tree-reassoc1" } */
6 /* { dg-additional-options "-mvsx" { target { powerpc*-*-* } } } */
7 /* { dg-additional-options "-msse2" { target { i?86-*-* x86_64-*-* } } } */
8
9 /* To test reassoc can undistribute vector bit_field_ref summation.
10
11 arg1 and arg2 are two arrays whose elements of type vector double.
12 Assuming:
13 A0 = arg1[0], A1 = arg1[1], A2 = arg1[2], A3 = arg1[3],
14 B0 = arg2[0], B1 = arg2[1], B2 = arg2[2], B3 = arg2[3],
15
16 Then:
17 V0 = A0 * B0, V1 = A1 * B1, V2 = A2 * B2, V3 = A3 * B3,
18
19 reassoc transforms
20
21 accumulator += V0[0] + V0[1] + V1[0] + V1[1] + V2[0] + V2[1]
22 + V3[0] + V3[1];
23
24 into:
25
26 T = V0 + V1 + V2 + V3
27 accumulator += T[0] + T[1];
28
29 Fewer bit_field_refs, only two for 128 or more bits vector. */
30
31 typedef double v2df __attribute__ ((vector_size (16)));
32 __attribute__ ((noinline)) double
33 test (double accumulator, v2df arg1[], v2df arg2[])
34 {
35 v2df temp;
36 temp = arg1[0] * arg2[0];
37 accumulator += temp[0] + temp[1];
38 temp = arg1[1] * arg2[1];
39 accumulator += temp[0] + temp[1];
40 temp = arg1[2] * arg2[2];
41 accumulator += temp[0] + temp[1];
42 temp = arg1[3] * arg2[3];
43 accumulator += temp[0] + temp[1];
44 return accumulator;
45 }
46
47 extern void abort (void);
48
49 int
50 main ()
51 {
52 v2df v2[4] = {{1.0, 2.0}, {4.0, 8.0}, {1.0, 3.0}, {9.0, 27.0}};
53 v2df v3[4] = {{1.0, 4.0}, {16.0, 64.0}, {1.0, 2.0}, {3.0, 4.0}};
54 double acc = 100.0;
55 double res = test (acc, v2, v3);
56 if (res != 827.0)
57 abort ();
58 return 0;
59 }
60 /* { dg-final { scan-tree-dump-times "BIT_FIELD_REF" 2 "reassoc1" { target { powerpc*-*-* i?86-*-* x86_64-*-* } } } } */