From 6c5b3c5401563ffbdae0ad8a62c59e3ebebe8352 Mon Sep 17 00:00:00 2001 From: marxin Date: Tue, 24 Nov 2015 18:14:10 +0100 Subject: [PATCH 4/6] HSA: fix CMP instruction emission gcc/ChangeLog: 2015-11-24 Martin Liska * hsa-gen.c (gen_hsa_cmp_insn_from_gimple): If dest type of a CMP instruction is an integer type, use B1 as intermediate destination register. (hsa_insn_basic::set_output_in_type): Fix case where the type of an instruction is equal to the type of an argument. --- gcc/hsa-gen.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/gcc/hsa-gen.c b/gcc/hsa-gen.c index 75facec..b7e649d 100644 --- a/gcc/hsa-gen.c +++ b/gcc/hsa-gen.c @@ -2748,11 +2748,18 @@ gen_hsa_cmp_insn_from_gimple (enum tree_code code, tree lhs, tree rhs, return; } - hsa_insn_cmp *cmp = new hsa_insn_cmp (compare, dest->m_type); - cmp->set_op (0, dest); + /* CMP instruction returns e.g. 0xffffffff (for a 32-bit with integer) + as a result of comparison. */ + + BrigType16_t dest_type = hsa_type_integer_p (dest->m_type) + ? (BrigType16_t) BRIG_TYPE_B1 : dest->m_type; + + hsa_insn_cmp *cmp = new hsa_insn_cmp (compare, dest_type); cmp->set_op (1, hsa_reg_or_immed_for_gimple_op (lhs, hbb)); cmp->set_op (2, hsa_reg_or_immed_for_gimple_op (rhs, hbb)); + hbb->append_insn (cmp); + cmp->set_output_in_type (dest, 0, hbb); } /* Generate an unary instruction with OPCODE and append it to a basic block @@ -3424,7 +3431,10 @@ hsa_insn_basic::set_output_in_type (hsa_op_reg *dest, unsigned op_index, gcc_checking_assert (op_output_p (op_index)); if (dest->m_type == m_type) - set_op (op_index, dest); + { + set_op (op_index, dest); + return; + } hsa_op_reg *tmp = new hsa_op_reg (m_type); set_op (op_index, tmp); -- 2.6.3