From patchwork Thu Nov 5 15:48:02 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 540490 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 AEABA1406AA for ; Fri, 6 Nov 2015 02:48:21 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=kVFx6gBz; 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 :subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=bF2Vw5LChzz2lRWLm dXZbjWUlEM8jQbcMKPoJClhOFS8FrBWLtnTwuowuQ0uN0CxPqdjPskZAQKjSYNS5 2UAlSnKxoxIp9eqZAmFzDX4gx0/IefYkYu55CY1zcD8SJTuGm8y6ynWXhLZeaCnX FZWtJvs3XYtnO6p8Ewk2rU7SAI= 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 :subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=+DO8yT+vPf0pVIv2UiS+8Wf BN2c=; b=kVFx6gBzXP6IXREq9YBeWDztqqHvSZb4dy5nt3Iv7RiMDYLxf3lzzwE qin2wmjqCI0vy0DAupm1H7Jd/OhcbAMFtvBX3Bg9iEbAPQDoPYVcpVNB0m+2XI60 FrSJma2LgdjJ+p9fL0oeHQoXVCvKOg/6qW4Ps72/Kt/QLmYkRBio= Received: (qmail 76097 invoked by alias); 5 Nov 2015 15:48:12 -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 76065 invoked by uid 89); 5 Nov 2015 15:48:07 -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-yk0-f180.google.com Received: from mail-yk0-f180.google.com (HELO mail-yk0-f180.google.com) (209.85.160.180) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Thu, 05 Nov 2015 15:48:06 +0000 Received: by ykdv3 with SMTP id v3so47793017ykd.0 for ; Thu, 05 Nov 2015 07:48:04 -0800 (PST) X-Received: by 10.31.54.71 with SMTP id d68mr7639186vka.50.1446738484308; Thu, 05 Nov 2015 07:48:04 -0800 (PST) Received: from ?IPv6:2601:181:c000:c497:a2a8:cdff:fe3e:b48? ([2601:181:c000:c497:a2a8:cdff:fe3e:b48]) by smtp.googlemail.com with ESMTPSA id a21sm5023159vke.10.2015.11.05.07.48.03 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Nov 2015 07:48:03 -0800 (PST) Subject: Re: [OpenACC] internal fn folding To: Bernd Schmidt , GCC Patches , Richard Guenther References: <563116AC.3010108@acm.org> <56376B79.5010100@acm.org> <5639D79B.8040200@redhat.com> From: Nathan Sidwell Message-ID: <563B7A32.7010209@acm.org> Date: Thu, 5 Nov 2015 10:48:02 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 In-Reply-To: <5639D79B.8040200@redhat.com> On 11/04/15 05:02, Bernd Schmidt wrote: > On 11/02/2015 02:56 PM, Nathan Sidwell wrote: >> On 10/28/15 14:40, Nathan Sidwell wrote: >>> 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? This is what I committed, using the helpers I recently added. (I realized we can only get here for functions with the oacc attribute already set) nathan 2015-11-05 Nathan Sidwell * gimple-fold.c: Include omp-low.h. (fold_internal_goacc_dim): New. (gimple_fold_call): Call it. Index: gimple-fold.c =================================================================== --- gimple-fold.c (revision 229809) +++ gimple-fold.c (working copy) @@ -52,6 +52,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. @@ -2906,6 +2907,28 @@ 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 (const gimple *call) +{ + int axis = get_oacc_ifn_dim_arg (call); + int size = get_oacc_fn_dim_size (current_function_decl, axis); + bool is_pos = gimple_call_internal_fn (call) == IFN_GOACC_DIM_POS; + tree result = NULL_TREE; + + /* If the size is 1, or we only want the size and it is not dynamic, + we know the answer. */ + if (size == 1 || (!is_pos && size)) + { + tree type = TREE_TYPE (gimple_call_lhs (call)); + result = build_int_cst (type, size - is_pos); + } + + 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. */ @@ -3106,6 +3129,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;