1 /* { dg-do compile } */
2 /* { dg-options "-O2 -ftree-vectorize -fno-trapping-math" } */
3 
4 #include <stdint.h>
5 
6 #define DEF_LOOP(FLOAT_TYPE, INT_TYPE)				\
7   void __attribute__ ((noipa))					\
8   test_##INT_TYPE (FLOAT_TYPE *__restrict r,			\
9 		   INT_TYPE *__restrict a,			\
10 		   INT_TYPE *__restrict pred, int n)		\
11   {								\
12     for (int i = 0; i < n; ++i)					\
13       r[i] = pred[i] ? (FLOAT_TYPE) a[i] : 0.0;			\
14   }
15 
16 #define TEST_ALL(T) \
17   T (_Float16, int16_t) \
18   T (_Float16, uint16_t) \
19   T (float, int32_t) \
20   T (float, uint32_t) \
21   T (double, int64_t) \
22   T (double, uint64_t)
23 
24 TEST_ALL (DEF_LOOP)
25 
26 /* { dg-final { scan-assembler-times {\tscvtf\tz[0-9]+\.h, p[0-7]/m,} 1 } } */
27 /* { dg-final { scan-assembler-times {\tucvtf\tz[0-9]+\.h, p[0-7]/m,} 1 } } */
28 /* { dg-final { scan-assembler-times {\tscvtf\tz[0-9]+\.s, p[0-7]/m,} 1 } } */
29 /* { dg-final { scan-assembler-times {\tucvtf\tz[0-9]+\.s, p[0-7]/m,} 1 } } */
30 /* { dg-final { scan-assembler-times {\tscvtf\tz[0-9]+\.d, p[0-7]/m,} 1 } } */
31 /* { dg-final { scan-assembler-times {\tucvtf\tz[0-9]+\.d, p[0-7]/m,} 1 } } */
32 
33 /* Really we should be able to use MOVPRFX /z here, but at the moment
34    we're relying on combine to merge a SEL and an arithmetic operation,
35    and the SEL doesn't allow the "false" value to be zero when the "true"
36    value is a register.  */
37 /* { dg-final { scan-assembler-times {\tmovprfx\tz[0-9]+, z[0-9]+\n} 6 } } */
38 
39 /* { dg-final { scan-assembler-not {\tmov\tz[^\n]*z} } } */
40 /* { dg-final { scan-assembler-not {\tsel\t} } } */
41