case CFN_FNMS:
return 0;
+ case CFN_COND_ADD:
+ case CFN_COND_MUL:
+ case CFN_COND_MIN:
+ case CFN_COND_MAX:
+ case CFN_COND_FMIN:
+ case CFN_COND_FMAX:
+ case CFN_COND_AND:
+ case CFN_COND_IOR:
+ case CFN_COND_XOR:
+ case CFN_COND_FMA:
+ case CFN_COND_FMS:
+ case CFN_COND_FNMA:
+ case CFN_COND_FNMS:
+ return 1;
+
default:
return -1;
}
(if (REAL_VALUE_NEGATIVE (TREE_REAL_CST (@0)))
(COPYSIGN_ALL (negate @0) @1)))
+/* Transform c ? x * copysign (1, y) : z to c ? x ^ signs(y) : z.
+ tree-ssa-math-opts.cc does the corresponding optimization for
+ unconditional multiplications (via xorsign). */
+(simplify
+ (IFN_COND_MUL:c @0 @1 (IFN_COPYSIGN real_onep @2) @3)
+ (with { tree signs = sign_mask_for (type); }
+ (if (signs)
+ (with { tree inttype = TREE_TYPE (signs); }
+ (view_convert:type
+ (IFN_COND_XOR:inttype @0
+ (view_convert:inttype @1)
+ (bit_and (view_convert:inttype @2) { signs; })
+ (view_convert:inttype @3)))))))
+
/* (x >= 0 ? x : 0) + (x <= 0 ? -x : 0) -> abs x. */
(simplify
(plus:c (max @0 integer_zerop) (max (negate @0) integer_zerop))
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+#define xorsign(A, B, SUFFIX) ((A) * __builtin_copysign##SUFFIX (1.0, B))
+
+#define DEF_LOOP(TYPE, SUFFIX) \
+ void __attribute__ ((noinline, noclone)) \
+ test_##TYPE (TYPE *__restrict r, TYPE *__restrict a, \
+ TYPE *__restrict b, TYPE *__restrict c, \
+ int n) \
+ { \
+ for (int i = 0; i < n; ++i) \
+ r[i] = a[i] < 20 ? xorsign(b[i], c[i], SUFFIX) : b[i]; \
+ }
+
+#define TEST_ALL(T) \
+ T (_Float16, f16) \
+ T (float, f) \
+ T (double, )
+
+TEST_ALL (DEF_LOOP)
+
+/* { dg-final { scan-assembler-times {\tand\tz[0-9]+\.h, z[0-9]+\.h,} 1 } } */
+/* { dg-final { scan-assembler-times {\tand\tz[0-9]+\.s, z[0-9]+\.s,} 1 } } */
+/* { dg-final { scan-assembler-times {\tand\tz[0-9]+\.d, z[0-9]+\.d,} 1 } } */
+
+/* { dg-final { scan-assembler-times {\teor\tz[0-9]+\.h, p[0-7]/m,} 1 } } */
+/* { dg-final { scan-assembler-times {\teor\tz[0-9]+\.s, p[0-7]/m,} 1 } } */
+/* { dg-final { scan-assembler-times {\teor\tz[0-9]+\.d, p[0-7]/m,} 1 } } */
+
+/* { dg-final { scan-assembler-not {\tfmul} } } */
+/* { dg-final { scan-assembler-not {\tmov\tz[^,]*z} } } */
+/* { dg-final { scan-assembler-not {\tmovprfx\t} } } */
+/* { dg-final { scan-assembler-not {\tsel\t} } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -msve-vector-bits=128 --param aarch64-autovec-preference=2" } */
+
+#include "cond_xorsign_1.c"
+
+/* { dg-final { scan-assembler-times {\tand\tz[0-9]+\.h, z[0-9]+\.h,} 1 } } */
+/* { dg-final { scan-assembler-times {\tand\tz[0-9]+\.s, z[0-9]+\.s,} 1 } } */
+/* { dg-final { scan-assembler-times {\tand\tz[0-9]+\.d, z[0-9]+\.d,} 1 } } */
+
+/* { dg-final { scan-assembler-times {\teor\tz[0-9]+\.h, p[0-7]/m,} 1 } } */
+/* { dg-final { scan-assembler-times {\teor\tz[0-9]+\.s, p[0-7]/m,} 1 } } */
+/* { dg-final { scan-assembler-times {\teor\tz[0-9]+\.d, p[0-7]/m,} 1 } } */
+
+/* { dg-final { scan-assembler-not {\tfmul} } } */
+/* { dg-final { scan-assembler-not {\tmov\tz[^,]*z} } } */
+/* { dg-final { scan-assembler-not {\tmovprfx\t} } } */
+/* { dg-final { scan-assembler-not {\tsel\t} } } */
}
}
+/* If floating-point type TYPE has an IEEE-style sign bit, return an
+ unsigned constant in which only the sign bit is set. Return null
+ otherwise. */
+
+tree
+sign_mask_for (tree type)
+{
+ /* Avoid having to choose between a real-only sign and a pair of signs.
+ This could be relaxed if the choice becomes obvious later. */
+ if (TREE_CODE (type) == COMPLEX_TYPE)
+ return NULL_TREE;
+
+ auto eltmode = as_a<scalar_float_mode> (element_mode (type));
+ auto bits = REAL_MODE_FORMAT (eltmode)->ieee_bits;
+ if (!bits || !pow2p_hwi (bits))
+ return NULL_TREE;
+
+ tree inttype = unsigned_type_for (type);
+ if (!inttype)
+ return NULL_TREE;
+
+ auto mask = wi::set_bit_in_zero (bits - 1, bits);
+ if (TREE_CODE (inttype) == VECTOR_TYPE)
+ {
+ tree elt = wide_int_to_tree (TREE_TYPE (inttype), mask);
+ return build_vector_from_val (inttype, elt);
+ }
+ return wide_int_to_tree (inttype, mask);
+}
/* Build a BINFO with LEN language slots. */
return NULL_TREE;
if (inner == inner2)
return type;
+ machine_mode new_mode;
+ if (VECTOR_MODE_P (TYPE_MODE (type))
+ && related_int_vector_mode (TYPE_MODE (type)).exists (&new_mode))
+ return build_vector_type_for_mode (inner2, new_mode);
return build_vector_type (inner2, TYPE_VECTOR_SUBPARTS (type));
}
extern tree build_minus_one_cst (tree);
extern tree build_all_ones_cst (tree);
extern tree build_zero_cst (tree);
+extern tree sign_mask_for (tree);
extern tree build_string (unsigned, const char * = NULL);
extern tree build_poly_int_cst (tree, const poly_wide_int_ref &);
extern tree build_tree_list (tree, tree CXX_MEM_STAT_INFO);