From b15e4689e6b6c582c89d57eeb79fedc8b6081aeb Mon Sep 17 00:00:00 2001 From: Martin Jambor Date: Fri, 26 Feb 2016 18:42:06 +0100 Subject: [PATCH] [hsa] Satisfy conditional move operand type constrains 2016-02-26 Martin Jambor * hsa.h (is_a_helper): New overload for hsa_op_immed for hsa_op_with_type operands. (hsa_unsigned_type_for_type): Declare. * hsa.c (hsa_unsigned_type_for_type): New function. * hsa-gen.c (gen_hsa_binary_operation): Use hsa_unsigned_type_for_type. (gen_hsa_insns_for_operation_assignment): Satisfy constrains of the finalizer. Do not emit extra move. From-SVN: r233749 --- gcc/ChangeLog | 10 ++++++++++ gcc/hsa-gen.c | 28 +++++++++++----------------- gcc/hsa.c | 8 ++++++++ gcc/hsa.h | 12 ++++++++++++ 4 files changed, 41 insertions(+), 17 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index de2189a84078..bf03f181b164 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,13 @@ +2016-02-26 Martin Jambor + + * hsa.h (is_a_helper): New overload for hsa_op_immed for + hsa_op_with_type operands. + (hsa_unsigned_type_for_type): Declare. + * hsa.c (hsa_unsigned_type_for_type): New function. + * hsa-gen.c (gen_hsa_binary_operation): Use hsa_unsigned_type_for_type. + (gen_hsa_insns_for_operation_assignment): Satisfy constrains of + the finalizer. Do not emit extra move. + 2016-02-26 Martin Jambor * hsa-gen.c (gen_hsa_ternary_atomic_for_builtin): Fail in presence of diff --git a/gcc/hsa-gen.c b/gcc/hsa-gen.c index 7a7ec41ab801..be402ddda71e 100644 --- a/gcc/hsa-gen.c +++ b/gcc/hsa-gen.c @@ -3022,7 +3022,7 @@ gen_hsa_binary_operation (int opcode, hsa_op_reg *dest, && is_a (op2)) { hsa_op_immed *i = dyn_cast (op2); - i->set_type (hsa_uint_for_bitsize (hsa_type_bit_size (i->m_type))); + i->set_type (hsa_unsigned_type_for_type (i->m_type)); } hsa_insn_basic *insn = new hsa_insn_basic (3, opcode, dest->m_type, dest, @@ -3233,27 +3233,21 @@ gen_hsa_insns_for_operation_assignment (gimple *assign, hsa_bb *hbb) ctrl = r; } - hsa_op_with_type *rhs2_reg = hsa_reg_or_immed_for_gimple_op (rhs2, hbb); - hsa_op_with_type *rhs3_reg = hsa_reg_or_immed_for_gimple_op (rhs3, hbb); - - BrigType16_t btype = hsa_bittype_for_type (dest->m_type); - hsa_op_reg *tmp = new hsa_op_reg (btype); + hsa_op_with_type *op2 = hsa_reg_or_immed_for_gimple_op (rhs2, hbb); + hsa_op_with_type *op3 = hsa_reg_or_immed_for_gimple_op (rhs3, hbb); - rhs2_reg->m_type = btype; - rhs3_reg->m_type = btype; + BrigType16_t utype = hsa_unsigned_type_for_type (dest->m_type); + if (is_a (op2)) + op2->m_type = utype; + if (is_a (op3)) + op3->m_type = utype; hsa_insn_basic *insn - = new hsa_insn_basic (4, BRIG_OPCODE_CMOV, tmp->m_type, tmp, ctrl, - rhs2_reg, rhs3_reg); + = new hsa_insn_basic (4, BRIG_OPCODE_CMOV, + hsa_bittype_for_type (dest->m_type), + dest, ctrl, op2, op3); hbb->append_insn (insn); - - /* As operands of a CMOV insn must be Bx types, we have to emit - a conversion insn. */ - hsa_insn_basic *mov = new hsa_insn_basic (2, BRIG_OPCODE_MOV, - dest->m_type, dest, tmp); - hbb->append_insn (mov); - return; } case COMPLEX_EXPR: diff --git a/gcc/hsa.c b/gcc/hsa.c index f0b320573bff..9537e295cb52 100644 --- a/gcc/hsa.c +++ b/gcc/hsa.c @@ -472,6 +472,14 @@ hsa_bittype_for_type (BrigType16_t t) return hsa_bittype_for_bitsize (hsa_type_bit_size (t)); } +/* Return HSA unsigned integer type with the same size as the type T. */ + +BrigType16_t +hsa_unsigned_type_for_type (BrigType16_t t) +{ + return hsa_uint_for_bitsize (hsa_type_bit_size (t)); +} + /* Return true if and only if TYPE is a floating point number type. */ bool diff --git a/gcc/hsa.h b/gcc/hsa.h index f0436f3cf691..275a954f88de 100644 --- a/gcc/hsa.h +++ b/gcc/hsa.h @@ -199,6 +199,17 @@ is_a_helper ::test (hsa_op_base *p) return p->m_kind == BRIG_KIND_OPERAND_CONSTANT_BYTES; } +/* Likewise, but for a more specified base. */ + +template <> +template <> +inline bool +is_a_helper ::test (hsa_op_with_type *p) +{ + return p->m_kind == BRIG_KIND_OPERAND_CONSTANT_BYTES; +} + + /* HSA register operand. */ class hsa_op_reg : public hsa_op_with_type @@ -1326,6 +1337,7 @@ BrigType16_t hsa_bittype_for_bitsize (unsigned bitsize); BrigType16_t hsa_uint_for_bitsize (unsigned bitsize); BrigType16_t hsa_float_for_bitsize (unsigned bitsize); BrigType16_t hsa_bittype_for_type (BrigType16_t t); +BrigType16_t hsa_unsigned_type_for_type (BrigType16_t t); bool hsa_type_float_p (BrigType16_t type); bool hsa_type_integer_p (BrigType16_t type); bool hsa_btype_p (BrigType16_t type); -- 2.47.2