| 1 |
/* { dg-do run { target { riscv_v } } } */ |
| 2 |
/* { dg-additional-options "-mrvv-vector-bits=scalable -fdump-tree-vect-details" } */ |
| 3 |
|
| 4 |
double |
| 5 |
__attribute__ ((noipa)) |
| 6 |
foo2 (double *__restrict a, double init, int *__restrict cond, int n) |
| 7 |
{ |
| 8 |
for (int i = 0; i < n; i++) |
| 9 |
if (cond[i]) |
| 10 |
init += a[i]; |
| 11 |
return init; |
| 12 |
} |
| 13 |
|
| 14 |
double |
| 15 |
__attribute__ ((noipa)) |
| 16 |
foo3 (double *__restrict a, double init, int *__restrict cond, int n) |
| 17 |
{ |
| 18 |
for (int i = 0; i < n; i++) |
| 19 |
if (cond[i]) |
| 20 |
init -= a[i]; |
| 21 |
return init; |
| 22 |
} |
| 23 |
|
| 24 |
double |
| 25 |
__attribute__ ((noipa)) |
| 26 |
foo4 (double *__restrict a, double init, int *__restrict cond, int n) |
| 27 |
{ |
| 28 |
for (int i = 0; i < n; i++) |
| 29 |
if (cond[i]) |
| 30 |
init *= a[i]; |
| 31 |
return init; |
| 32 |
} |
| 33 |
|
| 34 |
int |
| 35 |
__attribute__ ((noipa)) |
| 36 |
foo5 (int *__restrict a, int init, int *__restrict cond, int n) |
| 37 |
{ |
| 38 |
for (int i = 0; i < n; i++) |
| 39 |
if (cond[i]) |
| 40 |
init &= a[i]; |
| 41 |
return init; |
| 42 |
} |
| 43 |
|
| 44 |
int |
| 45 |
__attribute__ ((noipa)) |
| 46 |
foo6 (int *__restrict a, int init, int *__restrict cond, int n) |
| 47 |
{ |
| 48 |
for (int i = 0; i < n; i++) |
| 49 |
if (cond[i]) |
| 50 |
init |= a[i]; |
| 51 |
return init; |
| 52 |
} |
| 53 |
|
| 54 |
int |
| 55 |
__attribute__ ((noipa)) |
| 56 |
foo7 (int *__restrict a, int init, int *__restrict cond, int n) |
| 57 |
{ |
| 58 |
for (int i = 0; i < n; i++) |
| 59 |
if (cond[i]) |
| 60 |
init ^= a[i]; |
| 61 |
return init; |
| 62 |
} |
| 63 |
|
| 64 |
#define SZ 125 |
| 65 |
|
| 66 |
int |
| 67 |
main () |
| 68 |
{ |
| 69 |
double res1 = 0, res2 = 0, res3 = 0; |
| 70 |
double a1[SZ], a2[SZ], a3[SZ]; |
| 71 |
int c1[SZ], c2[SZ], c3[SZ]; |
| 72 |
|
| 73 |
int a4[SZ], a5[SZ], a6[SZ]; |
| 74 |
int res4 = 0, res5 = 0, res6 = 0; |
| 75 |
int c4[SZ], c5[SZ], c6[SZ]; |
| 76 |
|
| 77 |
for (int i = 0; i < SZ; i++) |
| 78 |
{ |
| 79 |
a1[i] = i * 3 + (i & 4) - (i & 7); |
| 80 |
a2[i] = i * 3 + (i & 4) - (i & 7); |
| 81 |
a3[i] = i * 0.05 + (i & 4) - (i & 7); |
| 82 |
a4[i] = i * 3 + (i & 4) - (i & 7); |
| 83 |
a5[i] = i * 3 + (i & 4) - (i & 7); |
| 84 |
a6[i] = i * 3 + (i & 4) - (i & 7); |
| 85 |
c1[i] = i & 1; |
| 86 |
c2[i] = i & 2; |
| 87 |
c3[i] = i & 3; |
| 88 |
c4[i] = i & 4; |
| 89 |
c5[i] = i & 5; |
| 90 |
c6[i] = i & 6; |
| 91 |
__asm__ volatile ("" : : : "memory"); |
| 92 |
} |
| 93 |
|
| 94 |
double init1 = 2.7, init2 = 8.2, init3 = 0.1; |
| 95 |
double ref1 = init1, ref2 = init2, ref3 = init3; |
| 96 |
|
| 97 |
int init4 = 87, init5 = 11, init6 = -123894344; |
| 98 |
int ref4 = init4, ref5 = init5, ref6 = init6; |
| 99 |
|
| 100 |
#pragma GCC novector |
| 101 |
for (int i = 0; i < SZ; i++) |
| 102 |
{ |
| 103 |
if (c1[i]) |
| 104 |
ref1 += a1[i]; |
| 105 |
if (c2[i]) |
| 106 |
ref2 -= a2[i]; |
| 107 |
if (c3[i]) |
| 108 |
ref3 *= a3[i]; |
| 109 |
if (c4[i]) |
| 110 |
ref4 &= a4[i]; |
| 111 |
if (c5[i]) |
| 112 |
ref5 |= a5[i]; |
| 113 |
if (c6[i]) |
| 114 |
ref6 ^= a6[i]; |
| 115 |
} |
| 116 |
|
| 117 |
res1 = foo2 (a1, init1, c1, SZ); |
| 118 |
res2 = foo3 (a2, init2, c2, SZ); |
| 119 |
res3 = foo4 (a3, init3, c3, SZ); |
| 120 |
res4 = foo5 (a4, init4, c4, SZ); |
| 121 |
res5 = foo6 (a5, init5, c5, SZ); |
| 122 |
res6 = foo7 (a6, init6, c6, SZ); |
| 123 |
|
| 124 |
if (res1 != ref1) |
| 125 |
__builtin_abort (); |
| 126 |
if (res2 != ref2) |
| 127 |
__builtin_abort (); |
| 128 |
if (res3 != ref3) |
| 129 |
__builtin_abort (); |
| 130 |
if (res4 != ref4) |
| 131 |
__builtin_abort (); |
| 132 |
if (res5 != ref5) |
| 133 |
__builtin_abort (); |
| 134 |
if (res6 != ref6) |
| 135 |
__builtin_abort (); |
| 136 |
} |
| 137 |
|
| 138 |
/* { dg-final { scan-tree-dump-times "vectorized 1 loop" 5 "vect" } } */ |
| 139 |
/* { dg-final { scan-tree-dump-not "VCOND_MASK" "vect" } } */ |