diff --git a/gcc/match.pd b/gcc/match.pd index acd2a964917..d5c731e86d0 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -4704,6 +4704,14 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (op (vec_cond:s @0 @1 @2)) (vec_cond @0 (op! @1) (op! @2)))) +/* Sink unary conversions to branches, but only if we do fold both + and the target's truth type is the same as we already have. */ +(simplify + (convert (vec_cond:s @0 @1 @2)) + (if (VECTOR_TYPE_P (type) + && types_match (TREE_TYPE (@0), truth_type_for (type))) + (vec_cond @0 (convert! @1) (convert! @2)))) + /* Sink binary operation to branches, but only if we can fold it. */ (for op (tcc_comparison plus minus mult bit_and bit_ior bit_xor lshift rshift rdiv trunc_div ceil_div floor_div round_div diff --git a/gcc/testsuite/gcc.target/aarch64/sve/cond_convert_7.c b/gcc/testsuite/gcc.target/aarch64/sve/cond_convert_7.c new file mode 100644 index 00000000000..4bb95b92195 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/cond_convert_7.c @@ -0,0 +1,23 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -ftree-vectorize -moverride=sve_width=256 -fdump-tree-optimized" } */ + +/* This is a modified reduced version of cond_unary_5.c */ + +void __attribute__ ((noipa)) +f0 (unsigned short *__restrict r, + int *__restrict a, + int *__restrict pred) +{ + for (int i = 0; i < 1024; ++i) + { + int p = pred[i]?-1:0; + r[i] = p ; + } +} + +/* { dg-final { scan-assembler-times {\tmov\tz[0-9]+\.h, p[0-7]+/z, #-1} 1 } } */ +/* { dg-final { scan-assembler-not {\tmov\tz[0-9]+\.[hs], p[0-7]+/z, #1} } } */ + +/* { dg-final { scan-tree-dump-not "VIEW_CONVERT_EXPR " "optimized" } } */ +/* { dg-final { scan-tree-dump-not " = -" "optimized" } } */ +/* { dg-final { scan-tree-dump-not " = \\\(vector" "optimized" } } */