rtx tmp = NULL_RTX;
if (operands[2] != const0_rtx)
{
- /* Emit the slide down to index 0 in a new vector. */
- tmp = gen_reg_rtx (<MODE>mode);
- operands[2] = gen_lowpart (Pmode, operands[2]);
- rtx ops[] = {tmp, operands[1], operands[2]};
- riscv_vector::emit_vlmax_insn
- (code_for_pred_slide (UNSPEC_VSLIDEDOWN, <MODE>mode), riscv_vector::BINARY_OP, ops);
+ /* Properly convert a poly_int value and put the result into a
+ register. */
+ if (CONST_POLY_INT_P (operands[2]))
+ {
+ rtx pos = gen_reg_rtx (Pmode);
+ riscv_legitimize_poly_move (Pmode, pos, gen_reg_rtx (Pmode),
+ operands[2]);
+ operands[2] = pos;
+ }
+
+ /* Emit the slide down to index 0 in a new vector. */
+ tmp = gen_reg_rtx (<MODE>mode);
+ operands[2] = gen_lowpart (Pmode, operands[2]);
+ rtx ops[] = {tmp, operands[1], operands[2]};
+ riscv_vector::emit_vlmax_insn
+ (code_for_pred_slide (UNSPEC_VSLIDEDOWN, <MODE>mode),
+ riscv_vector::BINARY_OP, ops);
}
/* Emit v(f)mv.[xf].s. */
riscv_vector::emit_vlmax_insn (code_for_pred_merge (qimode),
riscv_vector::MERGE_OP, ops1);
- /* Slide down the requested byte element. */
- rtx tmp2 = gen_reg_rtx (qimode);
-
- rtx ops2[] = {tmp2, tmp1, operands[2]};
- riscv_vector::emit_vlmax_insn
- (code_for_pred_slide (UNSPEC_VSLIDEDOWN, qimode),
- riscv_vector::BINARY_OP, ops2);
+ /* Extract from it. */
+ riscv_vector::emit_vec_extract (operands[0], tmp1, operands[2]);
+ DONE;
+})
- /* Extract it. */
- emit_insn (gen_pred_extract_first (qimode, operands[0], tmp2));
+;; Same for a BImode but still return a QImode.
+(define_expand "vec_extract<mode>bi"
+ [(set (match_operand:QI 0 "register_operand")
+ (vec_select:QI
+ (match_operand:VB 1 "register_operand")
+ (parallel
+ [(match_operand 2 "nonmemory_operand")])))]
+ "TARGET_VECTOR"
+{
+ emit_insn (gen_vec_extract<mode>qi (operands[0], operands[1], operands[2]));
DONE;
})
extern void riscv_asm_output_external (FILE *, const tree, const char *);
extern bool
riscv_zcmp_valid_stack_adj_bytes_p (HOST_WIDE_INT, int);
+extern void riscv_legitimize_poly_move (machine_mode, rtx, rtx, rtx);
#ifdef RTX_CODE
extern void riscv_expand_int_scc (rtx, enum rtx_code, rtx, rtx, bool *invert_ptr = 0);
void expand_popcount (rtx *);
void expand_rawmemchr (machine_mode, rtx, rtx, rtx, bool = false);
bool expand_strcmp (rtx, rtx, rtx, rtx, unsigned HOST_WIDE_INT, bool);
-void emit_vec_extract (rtx, rtx, poly_int64);
+void emit_vec_extract (rtx, rtx, rtx);
/* Rounding mode bitfield for fixed point VXRM. */
enum fixed_point_rounding_mode
/* Extract the last element of the first vector. */
scalar_mode smode = GET_MODE_INNER (d->vmode);
rtx tmp = gen_reg_rtx (smode);
- emit_vec_extract (tmp, d->op0, nunits - 1);
+ emit_vec_extract (tmp, d->op0, gen_int_mode (nunits - 1, Pmode));
/* Insert the scalar into element 0. */
unsigned int unspec
return can_create_pseudo_p () && nonmemory_operand (op, mode);
}
-/* Helper function to emit vec_extract_optab. */
void
-emit_vec_extract (rtx target, rtx src, poly_int64 index)
+emit_vec_extract (rtx target, rtx src, rtx index)
{
machine_mode vmode = GET_MODE (src);
machine_mode smode = GET_MODE (target);
create_output_operand (&ops[0], target, smode);
ops[0].target = 1;
create_input_operand (&ops[1], src, vmode);
- if (index.is_constant ())
- create_integer_operand (&ops[2], index);
+
+ poly_int64 val;
+ if (poly_int_rtx_p (index, &val))
+ create_integer_operand (&ops[2], val);
else
- create_input_operand (&ops[2], gen_int_mode (index, Pmode), Pmode);
+ create_input_operand (&ops[2], index, Pmode);
+
expand_insn (icode, 3, ops);
if (ops[0].value != target)
emit_move_insn (target, ops[0].value);
static bool riscv_avoid_shrink_wrapping_separate ();
static tree riscv_handle_fndecl_attribute (tree *, tree, tree, int, bool *);
static tree riscv_handle_type_attribute (tree *, tree, tree, int, bool *);
-static void riscv_legitimize_poly_move (machine_mode, rtx, rtx, rtx);
/* Defining target-specific uses of __attribute__. */
TARGET_GNU_ATTRIBUTES (riscv_attribute_table,
/* Analyze src and emit const_poly_int mov sequence. */
-static void
+void
riscv_legitimize_poly_move (machine_mode mode, rtx dest, rtx tmp, rtx src)
{
poly_int64 value = rtx_to_poly_int64 (src);
else
result = gen_reg_rtx (smode);
- riscv_vector::emit_vec_extract (result, v, index + i);
+ riscv_vector::emit_vec_extract (result, v,
+ gen_int_mode (index + i, Pmode));
if (i == 1)
{
#include "expr.h"
#include "langhooks.h"
#include "tree-vector-builder.h"
+#include "recog.h"
struct target_expmed default_target_expmed;
#if SWITCHABLE_TARGET
&& !MEM_P (op0)
&& optab_handler (vec_set_optab, outermode) != CODE_FOR_nothing
&& fieldmode == innermode
- && known_eq (bitsize, GET_MODE_BITSIZE (innermode))
- && multiple_p (bitnum, GET_MODE_BITSIZE (innermode), &pos))
+ && known_eq (bitsize, GET_MODE_PRECISION (innermode))
+ && multiple_p (bitnum, GET_MODE_PRECISION (innermode), &pos))
{
class expand_operand ops[3];
enum insn_code icode = optab_handler (vec_set_optab, outermode);
if (VECTOR_MODE_P (GET_MODE (op0))
&& !MEM_P (op0)
&& VECTOR_MODE_P (tmode)
- && known_eq (bitsize, GET_MODE_BITSIZE (tmode))
+ && known_eq (bitsize, GET_MODE_PRECISION (tmode))
&& maybe_gt (GET_MODE_SIZE (GET_MODE (op0)), GET_MODE_SIZE (tmode)))
{
machine_mode new_mode = GET_MODE (op0);
if (VECTOR_MODE_P (outermode) && !MEM_P (op0))
{
scalar_mode innermode = GET_MODE_INNER (outermode);
+
enum insn_code icode
= convert_optab_handler (vec_extract_optab, outermode, innermode);
+
poly_uint64 pos;
if (icode != CODE_FOR_nothing
- && known_eq (bitsize, GET_MODE_BITSIZE (innermode))
- && multiple_p (bitnum, GET_MODE_BITSIZE (innermode), &pos))
+ && known_eq (bitsize, GET_MODE_PRECISION (innermode))
+ && multiple_p (bitnum, GET_MODE_PRECISION (innermode), &pos))
{
class expand_operand ops[3];
- create_output_operand (&ops[0], target, innermode);
+ create_output_operand (&ops[0], target,
+ insn_data[icode].operand[0].mode);
ops[0].target = 1;
create_input_operand (&ops[1], op0, outermode);
create_integer_operand (&ops[2], pos);
--- /dev/null
+/* { dg-do compile } */
+/* { dg-additional-options "-march=rv32gcv_zvl256b -mabi=ilp32d -O3" } */
+
+long long a;
+int b, c;
+int *d;
+void e(unsigned f) {
+ for (;; ++c)
+ if (f) {
+ a = 0;
+ for (; a <= 3; a++) {
+ f = 0;
+ for (; f <= 0; f++)
+ if ((long)a)
+ break;
+ }
+ if (b)
+ *d = f;
+ }
+}