Debian Codegraph @

gcc/testsuite/gcc.dg/vect/vect-simd-clone-20.c

raw
1 /* { dg-do-if compile { target { sse2_runtime && { ! sse4_runtime } } } } */
2 /* { dg-require-effective-target vect_simd_clones } */
3 /* { dg-additional-options "-fopenmp-simd --param vect-epilogues-nomask=0" } */
4 /* { dg-additional-options "-msse4" { target sse4 } } */
5 /* { dg-additional-options "-mavx" { target avx_runtime } } */
6
7 /* Test that simd inbranch clones work correctly. */
8
9 #ifndef TYPE
10 #define TYPE int
11 #endif
12
13 /* A simple function that will be cloned. */
14 #pragma omp declare simd inbranch
15 TYPE __attribute__((noinline))
16 foo (TYPE a)
17 {
18 return a + 1;
19 }
20
21 /* Check that "inbranch" clones are called correctly. */
22
23 void __attribute__((noipa))
24 masked (TYPE * __restrict a, TYPE * __restrict b, int size)
25 {
26 #pragma omp simd
27 for (int i = 0; i < size; i++)
28 b[i] = foo(a[i]);
29 }
30
31 /* Check that "inbranch" works when there might be unrolling. */
32
33 void __attribute__((noipa))
34 masked_fixed (TYPE * __restrict a, TYPE * __restrict b)
35 {
36 #pragma omp simd
37 for (int i = 0; i < 128; i++)
38 b[i] = foo(a[i]);
39 }
40
41 /* Validate the outputs. */
42
43 void
44 check_masked (TYPE *b, int size)
45 {
46 for (int i = 0; i < size; i++)
47 if (b[i] != (TYPE)(i + 1))
48 {
49 __builtin_printf ("error at %d\n", i);
50 __builtin_exit (1);
51 }
52 }
53
54 int
55 main ()
56 {
57 TYPE a[1024];
58 TYPE b[1024];
59
60 for (int i = 0; i < 1024; i++)
61 a[i] = i;
62
63 masked_fixed (a, b);
64 check_masked (b, 128);
65
66 /* Test various sizes to cover machines with different vectorization
67 factors. */
68 for (int size = 8; size <= 1024; size *= 2)
69 {
70 masked (a, b, size);
71 check_masked (b, size);
72 }
73
74 /* Test sizes that might exercise the partial vector code-path. */
75 for (int size = 8; size <= 1024; size *= 2)
76 {
77 masked (a, b, size-4);
78 check_masked (b, size-4);
79 }
80
81 return 0;
82 }
83
84 /* Ensure the the in-branch simd clones are used on targets that support them. */
85 /* { dg-final { scan-tree-dump-times {[\n\r] [^\n]* = foo\.simdclone} 2 "vect" { target { aarch64*-*-* || { sse4 && { ! avx_runtime } } } } } } */
86 /* { dg-final { scan-tree-dump-times {[\n\r] [^\n]* = foo\.simdclone} 4 "vect" { target { avx_runtime } } } } */
87
88 /* The LTO test produces two dump files and we scan the wrong one. */
89 /* { dg-skip-if "" { *-*-* } { "-flto" } { "" } } */