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 b,			\
13 		      TYPE *__restrict pred, int n)		\
14   {								\
15     for (int i = 0; i < n; ++i)					\
16       {								\
17 	TYPE bi = b[i];						\
18 	r[i] = pred[i] ? OP (a[i]) : bi;			\
19       }								\
20   }
21 
22 #define TEST_INT_TYPE(T, TYPE) \
23   T (TYPE, abs) \
24   T (TYPE, neg)
25 
26 #define TEST_FLOAT_TYPE(T, TYPE, SUFFIX) \
27   T (TYPE, __builtin_fabs##SUFFIX) \
28   T (TYPE, neg)
29 
30 #define TEST_ALL(T) \
31   TEST_INT_TYPE (T, int8_t) \
32   TEST_INT_TYPE (T, int16_t) \
33   TEST_INT_TYPE (T, int32_t) \
34   TEST_INT_TYPE (T, int64_t) \
35   TEST_FLOAT_TYPE (T, _Float16, f16) \
36   TEST_FLOAT_TYPE (T, float, f) \
37   TEST_FLOAT_TYPE (T, double, )
38 
39 TEST_ALL (DEF_LOOP)
40 
41 /* { dg-final { scan-assembler-times {\tabs\tz[0-9]+\.b, p[0-7]/m,} 1 } } */
42 /* { dg-final { scan-assembler-times {\tabs\tz[0-9]+\.h, p[0-7]/m,} 1 } } */
43 /* { dg-final { scan-assembler-times {\tabs\tz[0-9]+\.s, p[0-7]/m,} 1 } } */
44 /* { dg-final { scan-assembler-times {\tabs\tz[0-9]+\.d, p[0-7]/m,} 1 } } */
45 
46 /* { dg-final { scan-assembler-times {\tneg\tz[0-9]+\.b, p[0-7]/m,} 1 } } */
47 /* { dg-final { scan-assembler-times {\tneg\tz[0-9]+\.h, p[0-7]/m,} 1 } } */
48 /* { dg-final { scan-assembler-times {\tneg\tz[0-9]+\.s, p[0-7]/m,} 1 } } */
49 /* { dg-final { scan-assembler-times {\tneg\tz[0-9]+\.d, p[0-7]/m,} 1 } } */
50 
51 /* { dg-final { scan-assembler-times {\tfabs\tz[0-9]+\.h, p[0-7]/m,} 1 } } */
52 /* { dg-final { scan-assembler-times {\tfabs\tz[0-9]+\.s, p[0-7]/m,} 1 } } */
53 /* { dg-final { scan-assembler-times {\tfabs\tz[0-9]+\.d, p[0-7]/m,} 1 } } */
54 
55 /* { dg-final { scan-assembler-times {\tfneg\tz[0-9]+\.h, p[0-7]/m,} 1 } } */
56 /* { dg-final { scan-assembler-times {\tfneg\tz[0-9]+\.s, p[0-7]/m,} 1 } } */
57 /* { dg-final { scan-assembler-times {\tfneg\tz[0-9]+\.d, p[0-7]/m,} 1 } } */
58 
59 /* { dg-final { scan-assembler-not {\tmov\tz} } } */
60 /* { dg-final { scan-assembler-not {\tmovprfx\t} } } */
61 /* { dg-final { scan-assembler-not {\tsel\t} } } */
62