diff mbox

[hsa] Satisfy conditional move operand type constrains

Message ID 20160226155745.GD3094@virgil.suse.cz
State New
Headers show

Commit Message

Martin Jambor Feb. 26, 2016, 3:57 p.m. UTC
Hi,

It turned out that we got the types of conditional move operands and
their immediate operands wrong in, partly because we missed a detail
in the specs, partly because the finalizer/verifier is even stricter
in one aspect.  I'll commit the bootstrapped and tested fix below
shortly.

Thanks,

Martin

2016-02-17  Martin Jambor  <mjambor@suse.cz>

	* 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.
---
 gcc/hsa-gen.c | 28 +++++++++++-----------------
 gcc/hsa.c     |  8 ++++++++
 gcc/hsa.h     | 12 ++++++++++++
 3 files changed, 31 insertions(+), 17 deletions(-)
diff mbox

Patch

diff --git a/gcc/hsa-gen.c b/gcc/hsa-gen.c
index 717e755..a7dc220 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 <hsa_op_immed *> (op2))
     {
       hsa_op_immed *i = dyn_cast <hsa_op_immed *> (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 <hsa_op_immed *> (op2))
+	  op2->m_type = utype;
+	if (is_a <hsa_op_immed *> (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 f0b3205..9537e29 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 f0436f3..275a954 100644
--- a/gcc/hsa.h
+++ b/gcc/hsa.h
@@ -199,6 +199,17 @@  is_a_helper <hsa_op_immed *>::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 <hsa_op_immed *>::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);