" a valid %qT value", actual, argno + 1, fndecl, enumtype);
}
+/* Try to fold constant arguments ARG1 and ARG2 using the given tree_code.
+ Operations are not treated as overflowing. */
+static tree
+aarch64_const_binop (enum tree_code code, tree arg1, tree arg2)
+{
+ if (poly_int_tree_p (arg1) && poly_int_tree_p (arg2))
+ {
+ poly_wide_int poly_res;
+ tree type = TREE_TYPE (arg1);
+ signop sign = TYPE_SIGN (type);
+ wi::overflow_type overflow = wi::OVF_NONE;
+
+ /* Return 0 for division by 0, like SDIV and UDIV do. */
+ if (code == TRUNC_DIV_EXPR && integer_zerop (arg2))
+ return arg2;
+
+ if (!poly_int_binop (poly_res, code, arg1, arg2, sign, &overflow))
+ return NULL_TREE;
+ return force_fit_type (type, poly_res, false,
+ TREE_OVERFLOW (arg1) | TREE_OVERFLOW (arg2));
+ }
+ return NULL_TREE;
+}
+
/* Return a hash code for a function_instance. */
hashval_t
function_instance::hash () const
return gimple_build_assign (lhs, builder.build ());
}
+/* Try to fold the call to a constant, given that, for integers, the call
+ is roughly equivalent to binary operation CODE. aarch64_const_binop
+ handles any differences between CODE and the intrinsic. */
+gimple *
+gimple_folder::fold_const_binary (enum tree_code code)
+{
+ gcc_assert (gimple_call_num_args (call) == 3);
+ tree pg = gimple_call_arg (call, 0);
+ tree op1 = gimple_call_arg (call, 1);
+ tree op2 = gimple_call_arg (call, 2);
+
+ if (type_suffix (0).integer_p
+ && (pred == PRED_x || is_ptrue (pg, type_suffix (0).element_bytes)))
+ if (tree res = vector_const_binop (code, op1, op2, aarch64_const_binop))
+ return gimple_build_assign (lhs, res);
+
+ return NULL;
+}
+
/* Try to fold the call. Return the new statement on success and null
on failure. */
gimple *
--- /dev/null
+/* { dg-final { check-function-bodies "**" "" } } */
+/* { dg-options "-O2" } */
+
+#include "arm_sve.h"
+
+/*
+** s64_x_pg:
+** mov z[0-9]+\.d, #1
+** ret
+*/
+svint64_t s64_x_pg (svbool_t pg)
+{
+ return svdiv_x (pg, svdup_s64 (5), svdup_s64 (3));
+}
+
+/*
+** s64_x_pg_0:
+** mov z[0-9]+\.b, #0
+** ret
+*/
+svint64_t s64_x_pg_0 (svbool_t pg)
+{
+ return svdiv_x (pg, svdup_s64 (0), svdup_s64 (3));
+}
+
+/*
+** s64_x_pg_by0:
+** mov z[0-9]+\.b, #0
+** ret
+*/
+svint64_t s64_x_pg_by0 (svbool_t pg)
+{
+ return svdiv_x (pg, svdup_s64 (5), svdup_s64 (0));
+}
+
+/*
+** s64_z_pg:
+** mov z[0-9]+\.d, p[0-7]/z, #1
+** ret
+*/
+svint64_t s64_z_pg (svbool_t pg)
+{
+ return svdiv_z (pg, svdup_s64 (5), svdup_s64 (3));
+}
+
+/*
+** s64_z_pg_0:
+** mov z[0-9]+\.d, p[0-7]/z, #0
+** ret
+*/
+svint64_t s64_z_pg_0 (svbool_t pg)
+{
+ return svdiv_z (pg, svdup_s64 (0), svdup_s64 (3));
+}
+
+/*
+** s64_z_pg_by0:
+** mov (z[0-9]+\.d), #5
+** mov (z[0-9]+)\.b, #0
+** sdivr \2\.d, p[0-7]/m, \2\.d, \1
+** ret
+*/
+svint64_t s64_z_pg_by0 (svbool_t pg)
+{
+ return svdiv_z (pg, svdup_s64 (5), svdup_s64 (0));
+}
+
+/*
+** s64_m_pg:
+** mov (z[0-9]+\.d), #3
+** mov (z[0-9]+\.d), #5
+** sdiv \2, p[0-7]/m, \2, \1
+** ret
+*/
+svint64_t s64_m_pg (svbool_t pg)
+{
+ return svdiv_m (pg, svdup_s64 (5), svdup_s64 (3));
+}
+
+/*
+** s64_x_ptrue:
+** mov z[0-9]+\.d, #1
+** ret
+*/
+svint64_t s64_x_ptrue ()
+{
+ return svdiv_x (svptrue_b64 (), svdup_s64 (5), svdup_s64 (3));
+}
+
+/*
+** s64_z_ptrue:
+** mov z[0-9]+\.d, #1
+** ret
+*/
+svint64_t s64_z_ptrue ()
+{
+ return svdiv_z (svptrue_b64 (), svdup_s64 (5), svdup_s64 (3));
+}
+
+/*
+** s64_m_ptrue:
+** mov z[0-9]+\.d, #1
+** ret
+*/
+svint64_t s64_m_ptrue ()
+{
+ return svdiv_m (svptrue_b64 (), svdup_s64 (5), svdup_s64 (3));
+}
+
+/*
+** s64_x_pg_n:
+** mov z[0-9]+\.d, #1
+** ret
+*/
+svint64_t s64_x_pg_n (svbool_t pg)
+{
+ return svdiv_n_s64_x (pg, svdup_s64 (5), 3);
+}
+
+/*
+** s64_x_pg_n_s64_0:
+** mov z[0-9]+\.b, #0
+** ret
+*/
+svint64_t s64_x_pg_n_s64_0 (svbool_t pg)
+{
+ return svdiv_n_s64_x (pg, svdup_s64 (0), 3);
+}
+
+/*
+** s64_x_pg_n_s64_by0:
+** mov z[0-9]+\.b, #0
+** ret
+*/
+svint64_t s64_x_pg_n_s64_by0 (svbool_t pg)
+{
+ return svdiv_n_s64_x (pg, svdup_s64 (5), 0);
+}
+
+/*
+** s64_z_pg_n:
+** mov z[0-9]+\.d, p[0-7]/z, #1
+** ret
+*/
+svint64_t s64_z_pg_n (svbool_t pg)
+{
+ return svdiv_n_s64_z (pg, svdup_s64 (5), 3);
+}
+
+/*
+** s64_z_pg_n_s64_0:
+** mov z[0-9]+\.d, p[0-7]/z, #0
+** ret
+*/
+svint64_t s64_z_pg_n_s64_0 (svbool_t pg)
+{
+ return svdiv_n_s64_z (pg, svdup_s64 (0), 3);
+}
+
+/*
+** s64_z_pg_n_s64_by0:
+** mov (z[0-9]+\.d), #5
+** mov (z[0-9]+)\.b, #0
+** sdivr \2\.d, p[0-7]/m, \2\.d, \1
+** ret
+*/
+svint64_t s64_z_pg_n_s64_by0 (svbool_t pg)
+{
+ return svdiv_n_s64_z (pg, svdup_s64 (5), 0);
+}
+
+/*
+** s64_m_pg_n:
+** mov (z[0-9]+\.d), #3
+** mov (z[0-9]+\.d), #5
+** sdiv \2, p[0-7]/m, \2, \1
+** ret
+*/
+svint64_t s64_m_pg_n (svbool_t pg)
+{
+ return svdiv_n_s64_m (pg, svdup_s64 (5), 3);
+}
+
+/*
+** s64_x_ptrue_n:
+** mov z[0-9]+\.d, #1
+** ret
+*/
+svint64_t s64_x_ptrue_n ()
+{
+ return svdiv_n_s64_x (svptrue_b64 (), svdup_s64 (5), 3);
+}
+
+/*
+** s64_z_ptrue_n:
+** mov z[0-9]+\.d, #1
+** ret
+*/
+svint64_t s64_z_ptrue_n ()
+{
+ return svdiv_n_s64_z (svptrue_b64 (), svdup_s64 (5), 3);
+}
+
+/*
+** s64_m_ptrue_n:
+** mov z[0-9]+\.d, #1
+** ret
+*/
+svint64_t s64_m_ptrue_n ()
+{
+ return svdiv_n_s64_m (svptrue_b64 (), svdup_s64 (5), 3);
+}
+
+/*
+** s32_m_ptrue_dupq:
+** mov z[0-9]+\.b, #0
+** ret
+*/
+svint32_t s32_m_ptrue_dupq ()
+{
+ return svdiv_s32_m (svptrue_b32 (), svdupq_s32 (3, 0, -5, 11),
+ svdupq_s32 (4, 1, -6, 0));
+}
+
+/*
+** s32_z_ptrue_dupq:
+** mov z[0-9]+\.s, #-2
+** ret
+*/
+svint32_t s32_z_ptrue_dupq ()
+{
+ return svdiv_s32_z (svptrue_b32 (), svdupq_s32 (6, -30, 100, -4),
+ svdupq_s32 (-3, 15, -50, 2));
+}
+
+/*
+** u64_x_pg:
+** mov z[0-9]+\.d, #1
+** ret
+*/
+svuint64_t u64_x_pg (svbool_t pg)
+{
+ return svdiv_x (pg, svdup_u64 (5), svdup_u64 (3));
+}
+
+/*
+** u64_z_pg:
+** mov z[0-9]+\.d, p[0-7]/z, #1
+** ret
+*/
+svuint64_t u64_z_pg (svbool_t pg)
+{
+ return svdiv_z (pg, svdup_u64 (5), svdup_u64 (3));
+}
+
+/*
+** u64_m_pg:
+** mov (z[0-9]+\.d), #3
+** mov (z[0-9]+\.d), #5
+** udiv \2, p[0-7]/m, \2, \1
+** ret
+*/
+svuint64_t u64_m_pg (svbool_t pg)
+{
+ return svdiv_m (pg, svdup_u64 (5), svdup_u64 (3));
+}
+
+/*
+** u64_x_ptrue:
+** mov z[0-9]+\.d, #1
+** ret
+*/
+svuint64_t u64_x_ptrue ()
+{
+ return svdiv_x (svptrue_b64 (), svdup_u64 (5), svdup_u64 (3));
+}
+
+/*
+** u64_z_ptrue:
+** mov z[0-9]+\.d, #1
+** ret
+*/
+svuint64_t u64_z_ptrue ()
+{
+ return svdiv_z (svptrue_b64 (), svdup_u64 (5), svdup_u64 (3));
+}
+
+/*
+** u64_m_ptrue:
+** mov z[0-9]+\.d, #1
+** ret
+*/
+svuint64_t u64_m_ptrue ()
+{
+ return svdiv_m (svptrue_b64 (), svdup_u64 (5), svdup_u64 (3));
+}
+
+/*
+** u64_x_pg_n:
+** mov z[0-9]+\.d, #1
+** ret
+*/
+svuint64_t u64_x_pg_n (svbool_t pg)
+{
+ return svdiv_n_u64_x (pg, svdup_u64 (5), 3);
+}
+
+/*
+** u64_z_pg_n:
+** mov z[0-9]+\.d, p[0-7]/z, #1
+** ret
+*/
+svuint64_t u64_z_pg_n (svbool_t pg)
+{
+ return svdiv_n_u64_z (pg, svdup_u64 (5), 3);
+}
+
+/*
+** u64_m_pg_n:
+** mov (z[0-9]+\.d), #3
+** mov (z[0-9]+\.d), #5
+** udiv \2, p[0-7]/m, \2, \1
+** ret
+*/
+svuint64_t u64_m_pg_n (svbool_t pg)
+{
+ return svdiv_n_u64_m (pg, svdup_u64 (5), 3);
+}
+
+/*
+** u64_x_ptrue_n:
+** mov z[0-9]+\.d, #1
+** ret
+*/
+svuint64_t u64_x_ptrue_n ()
+{
+ return svdiv_n_u64_x (svptrue_b64 (), svdup_u64 (5), 3);
+}
+
+/*
+** u64_z_ptrue_n:
+** mov z[0-9]+\.d, #1
+** ret
+*/
+svuint64_t u64_z_ptrue_n ()
+{
+ return svdiv_n_u64_z (svptrue_b64 (), svdup_u64 (5), 3);
+}
+
+/*
+** u64_m_ptrue_n:
+** mov z[0-9]+\.d, #1
+** ret
+*/
+svuint64_t u64_m_ptrue_n ()
+{
+ return svdiv_n_u64_m (svptrue_b64 (), svdup_u64 (5), 3);
+}