From 7a81fec3e13a6da5f7804c2cfd8bef8bb55927dc Mon Sep 17 00:00:00 2001 From: Andrew Stubbs Date: Mon, 29 Jun 2020 15:20:09 +0100 Subject: [PATCH] amdgcn: Add vec_extract for partial vectors Add vec_extract expanders for all valid pairs of vector types. gcc/ChangeLog: * config/gcn/gcn-protos.h (get_exec): Add prototypes for two variants. * config/gcn/gcn-valu.md (vec_extract): New define_expand. * config/gcn/gcn.cc (get_exec): Export the existing function. Add a new overload variant. --- gcc/ChangeLog.omp | 11 +++++++++++ gcc/config/gcn/gcn-protos.h | 2 ++ gcc/config/gcn/gcn-valu.md | 34 ++++++++++++++++++++++++++++++++++ gcc/config/gcn/gcn.cc | 9 ++++++++- 4 files changed, 55 insertions(+), 1 deletion(-) diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp index 24dff91a9aaa..e52be6315ebc 100644 --- a/gcc/ChangeLog.omp +++ b/gcc/ChangeLog.omp @@ -1,3 +1,14 @@ +2022-10-12 Andrew Stubbs + + Backport from mainline: + 2022-10-11 Andrew Stubbs + + * config/gcn/gcn-protos.h (get_exec): Add prototypes for two variants. + * config/gcn/gcn-valu.md + (vec_extract): New define_expand. + * config/gcn/gcn.cc (get_exec): Export the existing function. Add a + new overload variant. + 2022-10-12 Andrew Stubbs Backport from mainline: diff --git a/gcc/config/gcn/gcn-protos.h b/gcc/config/gcn/gcn-protos.h index 6300c1cbd366..f9a1fc00b4f0 100644 --- a/gcc/config/gcn/gcn-protos.h +++ b/gcc/config/gcn/gcn-protos.h @@ -24,6 +24,8 @@ extern bool gcn_constant64_p (rtx); extern bool gcn_constant_p (rtx); extern rtx gcn_convert_mask_mode (rtx reg); extern unsigned int gcn_dwarf_register_number (unsigned int regno); +extern rtx get_exec (int64_t); +extern rtx get_exec (machine_mode mode); extern char * gcn_expand_dpp_shr_insn (machine_mode, const char *, int, int); extern void gcn_expand_epilogue (); extern rtx gcn_expand_scaled_offsets (addr_space_t as, rtx base, rtx offsets, diff --git a/gcc/config/gcn/gcn-valu.md b/gcc/config/gcn/gcn-valu.md index cecaa1c0ff72..0b0055e3402b 100644 --- a/gcc/config/gcn/gcn-valu.md +++ b/gcc/config/gcn/gcn-valu.md @@ -808,6 +808,40 @@ (set_attr "exec" "none") (set_attr "laneselect" "yes")]) +(define_expand "vec_extract" + [(set (match_operand:V_ALL_ALT 0 "register_operand") + (vec_select:V_ALL_ALT + (match_operand:V_ALL 1 "register_operand") + (parallel [(match_operand 2 "immediate_operand")])))] + "MODE_VF (mode) < MODE_VF (mode) + && mode == mode" + { + int numlanes = GET_MODE_NUNITS (mode); + int firstlane = INTVAL (operands[2]) * numlanes; + rtx tmp; + + if (firstlane == 0) + { + /* A plain move will do. */ + tmp = operands[1]; + } else { + /* FIXME: optimize this by using DPP where available. */ + + rtx permutation = gen_reg_rtx (mode); + emit_insn (gen_vec_series (permutation, + GEN_INT (firstlane*4), + GEN_INT (4))); + + tmp = gen_reg_rtx (mode); + emit_insn (gen_ds_bpermute (tmp, permutation, operands[1], + get_exec (mode))); + } + + emit_move_insn (operands[0], + gen_rtx_SUBREG (mode, tmp, 0)); + DONE; + }) + (define_expand "extract_last_" [(match_operand: 0 "register_operand") (match_operand:DI 1 "gcn_alu_operand") diff --git a/gcc/config/gcn/gcn.cc b/gcc/config/gcn/gcn.cc index 3525ac00df7b..9c0c44dfa512 100644 --- a/gcc/config/gcn/gcn.cc +++ b/gcc/config/gcn/gcn.cc @@ -856,7 +856,7 @@ gcn_ira_change_pseudo_allocno_class (int regno, reg_class_t cl, /* Create a new DImode pseudo reg and emit an instruction to initialize it to VAL. */ -static rtx +rtx get_exec (int64_t val) { rtx reg = gen_reg_rtx (DImode); @@ -864,6 +864,13 @@ get_exec (int64_t val) return reg; } +rtx +get_exec (machine_mode mode) +{ + int vf = (VECTOR_MODE_P (mode) ? GET_MODE_NUNITS (mode) : 1); + return get_exec (0xffffffffffffffffUL >> (64-vf)); +} + /* }}} */ /* {{{ Immediate constants. */ -- 2.47.2