extern bool loongarch_const_vector_shuffle_set_p (rtx, machine_mode);
extern bool loongarch_const_vector_bitimm_set_p (rtx, machine_mode);
extern bool loongarch_const_vector_bitimm_clr_p (rtx, machine_mode);
+extern rtx loongarch_const_vector_vrepli (rtx, machine_mode);
extern rtx loongarch_lsx_vec_parallel_const_half (machine_mode, bool);
extern rtx loongarch_gen_const_int_vector (machine_mode, HOST_WIDE_INT);
extern enum reg_class loongarch_secondary_reload_class (enum reg_class,
return true;
}
+rtx
+loongarch_const_vector_vrepli (rtx x, machine_mode mode)
+{
+ int size = GET_MODE_SIZE (mode);
+
+ if (GET_CODE (x) != CONST_VECTOR
+ || GET_MODE_CLASS (mode) != MODE_VECTOR_INT)
+ return NULL_RTX;
+
+ for (scalar_int_mode elem_mode: {QImode, HImode, SImode, DImode})
+ {
+ machine_mode new_mode =
+ mode_for_vector (elem_mode, size / GET_MODE_SIZE (elem_mode))
+ .require ();
+ rtx op = lowpart_subreg (new_mode, x, mode);
+ if (loongarch_const_vector_same_int_p (op, new_mode, -512, 511))
+ return op;
+ }
+
+ return NULL_RTX;
+}
+
/* Return true if rtx constants of mode MODE should be put into a small
data section. */
case CONST_VECTOR:
if ((LSX_SUPPORTED_MODE_P (GET_MODE (x))
|| LASX_SUPPORTED_MODE_P (GET_MODE (x)))
- && loongarch_const_vector_same_int_p (x, GET_MODE (x), -512, 511))
+ && loongarch_const_vector_vrepli (x, GET_MODE (x)))
return 1;
/* Fall through. */
case CONST_DOUBLE:
/* Check for vector set to an immediate const vector with valid replicated
element. */
if (FP_REG_RTX_P (dest)
- && loongarch_const_vector_same_int_p (src, GET_MODE (src), -512, 511))
+ && loongarch_const_vector_vrepli (src, GET_MODE (src)))
return false;
/* Check for vector load zero immediate. */
&& src_code == CONST_VECTOR
&& CONST_INT_P (CONST_VECTOR_ELT (src, 0)))
{
- gcc_assert (loongarch_const_vector_same_int_p (src, mode, -512, 511));
+ operands[1] = loongarch_const_vector_vrepli (src, mode);
+ gcc_assert (operands[1]);
+
switch (GET_MODE_SIZE (mode))
{
case 16:
- return "vrepli.%v0\t%w0,%E1";
+ return "vrepli.%v1\t%w0,%E1";
case 32:
- return "xvrepli.%v0\t%u0,%E1";
+ return "xvrepli.%v1\t%u0,%E1";
default: gcc_unreachable ();
}
}
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -mlasx" } */
+/* { dg-final { scan-assembler "\tvrepli\\.b\t\\\$vr\[0-9\]+,-35" } } */
+/* { dg-final { scan-assembler "\txvrepli\\.b\t\\\$xr\[0-9\]+,-35" } } */
+
+int f __attribute__((vector_size (16)));
+int g __attribute__((vector_size (32)));
+
+void
+test (void)
+{
+ constexpr int x = (int) 0xdddddddd;
+ f = (typeof(f)){x, x, x, x};
+ g = (typeof(g)){x, x, x, x, x, x, x, x};
+}