From patchwork Wed Oct 28 18:40:44 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 537530 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id D29CF1402B2 for ; Thu, 29 Oct 2015 05:40:57 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=o+e86ITp; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=nPOKOgVPgmKWkOPxoUUeKjZItt6wIgfeg9yf88ZI5bE07/iNgf IlWurXwHaeKYRZhYNcYtMDdczLFeie3Yq1yWIGuFlasb+Z8wR1Cxp/l5jnnm78dM qUUi3Wbu/ua8rYvAT5BX2rM1eyeP+PmulL0uVt1QO05tLAYv4kn+GwQ9s= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=ocGDlQzeQYNjiiioRpi9+DF06gQ=; b=o+e86ITpRGOUl8ACHvg5 7NxxqHFzXbz71lPOEDNaF3Savvd+S9hGSsBeM55OZZrL9tjB+HxoFO7KCOscx1dB te3Ksw8DX8uOuvKrRxCw7gkWhozOI3YoucxICqLiFIbe98yt7Zh1O+/nUeFI3BF8 rinFw99pK3Q0qpOwtWSDmB8= Received: (qmail 57298 invoked by alias); 28 Oct 2015 18:40:49 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 57285 invoked by uid 89); 28 Oct 2015 18:40:49 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pa0-f41.google.com Received: from mail-pa0-f41.google.com (HELO mail-pa0-f41.google.com) (209.85.220.41) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Wed, 28 Oct 2015 18:40:47 +0000 Received: by pasz6 with SMTP id z6so14443854pas.2 for ; Wed, 28 Oct 2015 11:40:46 -0700 (PDT) X-Received: by 10.66.102.97 with SMTP id fn1mr35305204pab.77.1446057646156; Wed, 28 Oct 2015 11:40:46 -0700 (PDT) Received: from ?IPv6:2600:1012:b115:101e:a2a8:cdff:fe3e:b48? ([2600:1012:b115:101e:a2a8:cdff:fe3e:b48]) by smtp.googlemail.com with ESMTPSA id w8sm46726383pbs.87.2015.10.28.11.40.45 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 28 Oct 2015 11:40:45 -0700 (PDT) To: GCC Patches , Richard Guenther From: Nathan Sidwell Subject: [OpenACC] internal fn folding Message-ID: <563116AC.3010108@acm.org> Date: Wed, 28 Oct 2015 11:40:44 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 Richard, this patch adds folding for the new GOACC_DIM_POS and GOACC_DIM_SIZE internal functions. IIUC gimple_fold_call is the right place to add this. The size of a compute dimension is very often a compile-time constant. On the host, in particular it's 1, which means we can deduce the POS must be zero. ok? nathan 2015-10-28 Nathan Sidwell * gimple-fold.c: Include omp-low.h. (fold_internal_goacc_dim): New. (gimple_fold_call): Call it. Index: gcc/gimple-fold.c =================================================================== --- gcc/gimple-fold.c (revision 229488) +++ gcc/gimple-fold.c (working copy) @@ -64,6 +64,7 @@ along with GCC; see the file COPYING3. #include "gimple-match.h" #include "gomp-constants.h" #include "optabs-query.h" +#include "omp-low.h" /* Return true when DECL can be referenced from current unit. @@ -2925,6 +2926,40 @@ gimple_fold_builtin (gimple_stmt_iterato return false; } +/* Transform IFN_GOACC_DIM_SIZE and IFN_GOACC_DIM_POS internal + function calls to constants, where possible. */ + +static tree +fold_internal_goacc_dim (gimple *call) +{ + tree size = integer_one_node; + + if (tree attrs = get_oacc_fn_attrib (current_function_decl)) + { + tree arg = gimple_call_arg (call, 0); + tree pos = TREE_VALUE (attrs); + + for (unsigned axis = (unsigned) TREE_INT_CST_LOW (arg); axis--;) + pos = TREE_CHAIN (pos); + size = TREE_VALUE (pos); + } + + tree result; + if (integer_zerop (size)) + /* Dimension size is dynamic. */ + result = NULL_TREE; + else if (gimple_call_internal_fn (call) == IFN_GOACC_DIM_SIZE) + result = size; + else if (integer_onep (size)) + /* Size is one, so pos must be zero. */ + result = integer_zero_node; + else + /* Size is more than 1, so POS might be non-zero. */ + result = NULL_TREE; + + return result; +} + /* Return true if ARG0 CODE ARG1 in infinite signed precision operation doesn't fit into TYPE. The test for overflow should be regardless of -fwrapv, and even for unsigned types. */ @@ -3125,6 +3160,10 @@ gimple_fold_call (gimple_stmt_iterator * return true; } break; + case IFN_GOACC_DIM_SIZE: + case IFN_GOACC_DIM_POS: + result = fold_internal_goacc_dim (stmt); + break; case IFN_UBSAN_CHECK_ADD: subcode = PLUS_EXPR; break;