1 /* { dg-do compile } */
2 /* { dg-options "-O2 -ftree-vectorize" } */
3 
4 #include <stdint.h>
5 
6 #define abs(A) ((A) < 0 ? -(A) : (A))
7 #define neg(A) (-(A))
8 
9 #define DEF_LOOP(TYPE, OP)					\
10   void __attribute__ ((noipa))					\
11   test_##TYPE##_##OP (TYPE *__restrict r, TYPE *__restrict a,	\
12 		      TYPE *__restrict pred, int n)		\
13   {								\
14     for (int i = 0; i < n; ++i)					\
15       r[i] = pred[i] ? OP (a[i]) : 0;				\
16   }
17 
18 #define TEST_INT_TYPE(T, TYPE) \
19   T (TYPE, abs) \
20   T (TYPE, neg)
21 
22 #define TEST_FLOAT_TYPE(T, TYPE, SUFFIX) \
23   T (TYPE, __builtin_fabs##SUFFIX) \
24   T (TYPE, neg)
25 
26 #define TEST_ALL(T) \
27   TEST_INT_TYPE (T, int8_t) \
28   TEST_INT_TYPE (T, int16_t) \
29   TEST_INT_TYPE (T, int32_t) \
30   TEST_INT_TYPE (T, int64_t) \
31   TEST_FLOAT_TYPE (T, _Float16, f16) \
32   TEST_FLOAT_TYPE (T, float, f) \
33   TEST_FLOAT_TYPE (T, double, )
34 
35 TEST_ALL (DEF_LOOP)
36 
37 /* { dg-final { scan-assembler-times {\tabs\tz[0-9]+\.b, p[0-7]/m,} 1 } } */
38 /* { dg-final { scan-assembler-times {\tabs\tz[0-9]+\.h, p[0-7]/m,} 1 } } */
39 /* { dg-final { scan-assembler-times {\tabs\tz[0-9]+\.s, p[0-7]/m,} 1 } } */
40 /* { dg-final { scan-assembler-times {\tabs\tz[0-9]+\.d, p[0-7]/m,} 1 } } */
41 
42 /* { dg-final { scan-assembler-times {\tneg\tz[0-9]+\.b, p[0-7]/m,} 1 } } */
43 /* { dg-final { scan-assembler-times {\tneg\tz[0-9]+\.h, p[0-7]/m,} 1 } } */
44 /* { dg-final { scan-assembler-times {\tneg\tz[0-9]+\.s, p[0-7]/m,} 1 } } */
45 /* { dg-final { scan-assembler-times {\tneg\tz[0-9]+\.d, p[0-7]/m,} 1 } } */
46 
47 /* { dg-final { scan-assembler-times {\tfabs\tz[0-9]+\.h, p[0-7]/m,} 1 } } */
48 /* { dg-final { scan-assembler-times {\tfabs\tz[0-9]+\.s, p[0-7]/m,} 1 } } */
49 /* { dg-final { scan-assembler-times {\tfabs\tz[0-9]+\.d, p[0-7]/m,} 1 } } */
50 
51 /* { dg-final { scan-assembler-times {\tfneg\tz[0-9]+\.h, p[0-7]/m,} 1 } } */
52 /* { dg-final { scan-assembler-times {\tfneg\tz[0-9]+\.s, p[0-7]/m,} 1 } } */
53 /* { dg-final { scan-assembler-times {\tfneg\tz[0-9]+\.d, p[0-7]/m,} 1 } } */
54 
55 /* Really we should be able to use MOVPRFX /z here, but at the moment
56    we're relying on combine to merge a SEL and an arithmetic operation,
57    and the SEL doesn't allow the "false" value to be zero when the "true"
58    value is a register.  */
59 /* { dg-final { scan-assembler-times {\tmovprfx\tz[0-9]+, z[0-9]+\n} 14 } } */
60 
61 /* { dg-final { scan-assembler-not {\tmov\tz[^\n]*z} } } */
62 /* { dg-final { scan-assembler-not {\tsel\t} } } */
63