From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 95931 invoked by alias); 11 Nov 2015 14:01:24 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 95912 invoked by uid 89); 11 Nov 2015 14:01:22 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.0 required=5.0 tests=AWL,BAYES_00,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx2.suse.de Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (CAMELLIA256-SHA encrypted) ESMTPS; Wed, 11 Nov 2015 14:01:21 +0000 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 279CBAC1D for ; Wed, 11 Nov 2015 14:00:57 +0000 (UTC) To: GCC Patches From: =?UTF-8?Q?Martin_Li=c5=a1ka?= Subject: [PATCH, HSA] fix emission of HSAIL for builtins Message-ID: <56434A2D.7030301@suse.cz> Date: Wed, 11 Nov 2015 14:01:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------010909090106080404060909" X-IsSubscribed: yes X-SW-Source: 2015-11/txt/msg01374.txt.bz2 This is a multi-part message in MIME format. --------------010909090106080404060909 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Content-length: 385 Hello. Following patch has been just applied to HSA branch and is responsible for correct emission of builtins. As HSAIL can support approximation for builtins like 'sin', we emit these if unsafe_math_optimization flag is enabled. Otherwise direct call instructions are emitted. I would like to install the patch to trunk as soon as initial patch set will be merged. Thanks, Martin --------------010909090106080404060909 Content-Type: text/x-patch; name="0002-HSA-fix-emission-of-HSAIL-for-builtins.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0002-HSA-fix-emission-of-HSAIL-for-builtins.patch" Content-length: 4098 >From 110a6e64af6c5ad7c925e7ef3837f3685e07fe12 Mon Sep 17 00:00:00 2001 From: marxin Date: Thu, 5 Nov 2015 16:59:07 +0100 Subject: [PATCH 2/2] HSA: fix emission of HSAIL for builtins gcc/ChangeLog: 2015-11-05 Martin Liska * hsa-gen.c (gen_hsa_unaryop_builtin_call): New function. (gen_hsa_unaryop_or_call_for_builtin): Likewise. (gen_hsa_insns_for_call): Use these aforementioned functions to correctly dispatch between creation of a function call and direct usage of an HSAIL instruction. --- gcc/hsa-gen.c | 57 +++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 16 deletions(-) diff --git a/gcc/hsa-gen.c b/gcc/hsa-gen.c index 48c4254..300bee6 100644 --- a/gcc/hsa-gen.c +++ b/gcc/hsa-gen.c @@ -4073,6 +4073,36 @@ gen_hsa_unaryop_for_builtin (int opcode, gimple *stmt, hsa_bb *hbb) gen_hsa_unary_operation (opcode, dest, op, hbb); } +/* Helper functions to create a call to standard library if LHS of the + STMT is used. HBB is the HSA BB to which the instruction should be + added. */ + +static void +gen_hsa_unaryop_builtin_call (gimple *stmt, hsa_bb *hbb) +{ + tree lhs = gimple_call_lhs (stmt); + if (!lhs) + return; + + gen_hsa_insns_for_direct_call (stmt, hbb); +} + +/* Helper functions to create a single unary HSA operations out of calls to + builtins (if unsafe math optimizations are enable). Otherwise, create + a call to standard library function. + OPCODE is the HSA operation to be generated. STMT is a gimple + call to a builtin. HBB is the HSA BB to which the instruction should be + added. Note that nothing will be created if STMT does not have a LHS. */ + +static void +gen_hsa_unaryop_or_call_for_builtin (int opcode, gimple *stmt, hsa_bb *hbb) +{ + if (flag_unsafe_math_optimizations) + gen_hsa_unaryop_for_builtin (opcode, stmt, hbb); + else + gen_hsa_unaryop_builtin_call (stmt, hbb); +} + /* Generate HSA address corresponding to a value VAL (as opposed to a memory reference tree), for example an SSA_NAME or an ADDR_EXPR. HBB is the HSA BB to which the instruction should be added. */ @@ -4345,7 +4375,6 @@ gen_hsa_insns_for_call (gimple *stmt, hsa_bb *hbb) case BUILT_IN_SQRT: case BUILT_IN_SQRTF: - /* TODO: Perhaps produce BRIG_OPCODE_NSQRT with -ffast-math? */ gen_hsa_unaryop_for_builtin (BRIG_OPCODE_SQRT, stmt, hbb); break; @@ -4355,31 +4384,27 @@ gen_hsa_insns_for_call (gimple *stmt, hsa_bb *hbb) break; case BUILT_IN_COS: + case BUILT_IN_SIN: + case BUILT_IN_EXP2: + case BUILT_IN_LOG2: + /* HSAIL does not provide an instruction for double argument type. */ + gen_hsa_unaryop_builtin_call (stmt, hbb); + break; + case BUILT_IN_COSF: - /* FIXME: Using the native instruction may not be precise enough. - Perhaps only allow if using -ffast-math? */ - gen_hsa_unaryop_for_builtin (BRIG_OPCODE_NCOS, stmt, hbb); + gen_hsa_unaryop_or_call_for_builtin (BRIG_OPCODE_NCOS, stmt, hbb); break; - case BUILT_IN_EXP2: case BUILT_IN_EXP2F: - /* FIXME: Using the native instruction may not be precise enough. - Perhaps only allow if using -ffast-math? */ - gen_hsa_unaryop_for_builtin (BRIG_OPCODE_NEXP2, stmt, hbb); + gen_hsa_unaryop_or_call_for_builtin (BRIG_OPCODE_NEXP2, stmt, hbb); break; - case BUILT_IN_LOG2: case BUILT_IN_LOG2F: - /* FIXME: Using the native instruction may not be precise enough. - Perhaps only allow if using -ffast-math? */ - gen_hsa_unaryop_for_builtin (BRIG_OPCODE_NLOG2, stmt, hbb); + gen_hsa_unaryop_or_call_for_builtin (BRIG_OPCODE_NLOG2, stmt, hbb); break; - case BUILT_IN_SIN: case BUILT_IN_SINF: - /* FIXME: Using the native instruction may not be precise enough. - Perhaps only allow if using -ffast-math? */ - gen_hsa_unaryop_for_builtin (BRIG_OPCODE_NSIN, stmt, hbb); + gen_hsa_unaryop_or_call_for_builtin (BRIG_OPCODE_NSIN, stmt, hbb); break; case BUILT_IN_ATOMIC_LOAD_1: -- 2.6.2 --------------010909090106080404060909--