From patchwork Wed Aug 12 18:11:03 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 506724 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 32BFC140338 for ; Thu, 13 Aug 2015 04:11:33 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=yCy67H4Q; 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:cc :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=Z0l9zb1ZwyI4P2w5AOtfI+Jzr79pJe6BXvyqvsw6eqMfq1N8w1 GOr80RGAoizMYsOZVMSS/TCLtxt0olwNomyKe+Ljq+OK3g862V5pW7xE8cA2UBeY NIqohz3FysUhzC3ukKaWed7dGlNDfiYewXQLkQ20w4XIR/4IU+4bja5oE= 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:cc :from:subject:message-id:date:mime-version:content-type; s= default; bh=x1vcWasR0QmZzmpgVKlWTE8oIYM=; b=yCy67H4Q34w1C9lqnVzz 2H7OtDWZODpsTTiymxNGQ45n6FQ1OIuxFj7A09PNIXpGT1OJ4dwOFqrpkt8+rZ4h Cro8ly9UrqRAQxE6g3dUWn55SHdSdL+BDeUQKa01mVUrCuH5hCnziuzxafjFD3X2 NXbMfcfm99DWH844UwCNLYM= Received: (qmail 54492 invoked by alias); 12 Aug 2015 18:11:15 -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 54384 invoked by uid 89); 12 Aug 2015 18:11:15 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.9 required=5.0 tests=BAYES_50, FREEMAIL_FROM, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=no version=3.3.2 X-HELO: mail-qg0-f44.google.com Received: from mail-qg0-f44.google.com (HELO mail-qg0-f44.google.com) (209.85.192.44) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Wed, 12 Aug 2015 18:11:11 +0000 Received: by qgj62 with SMTP id 62so16017172qgj.2 for ; Wed, 12 Aug 2015 11:11:08 -0700 (PDT) X-Received: by 10.140.235.14 with SMTP id g14mr27679081qhc.5.1439403068404; Wed, 12 Aug 2015 11:11:08 -0700 (PDT) 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 c109sm3594491qga.16.2015.08.12.11.11.06 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Aug 2015 11:11:07 -0700 (PDT) To: GCC Patches Cc: Cesar Philippidis From: Nathan Sidwell Subject: [gomp4] Fix dim api breakage, optimize fns Message-ID: <55CB8C37.7000304@acm.org> Date: Wed, 12 Aug 2015 14:11:03 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.1.0 MIME-Version: 1.0 I've committed this patch to a) fix the breakage I caused this morning, sorry b) Add a ptx-specific implementation of the fork_join hook. We only need to keep worker & vector-level forks & joins, and then only when the dimension size is not unity. This showed an awkwardness in that hook's API, so I tweaked it to pass the dimension array that oacc-xform has handy. c) Add smarts to VRP to know the range of the result of the DIM_POS and DIM_SIZE functions. This allows the new min/max optimizer to remove some MIN_EXPRs that get inserted. nathan 2015-08-12 Nathan Sidwell * target.def (fork_join): Adjustt prototype. * targhooks.h (default_foacc_fork_join): Adjust. * omp-low.c (oacc_xform_dim): Constify DIMS arg. (execute_oacc_transform): Defer setting defaulted unknown dimensions to 0. Adjust fork_join hook call. (default_goacc_fork_join): Adjust. * config/nvptx/nvptx.c: Include gimple.h (nvptx_xform_fork_join): New. (TARGET_GOACC_FORK_JOIN): Override. * doc/tm.texi: Rebuilt. Index: config/nvptx/nvptx.c =================================================================== --- config/nvptx/nvptx.c (revision 226813) +++ config/nvptx/nvptx.c (working copy) @@ -61,6 +61,7 @@ #include "cfg.h" #include "omp-low.h" #include "gomp-constants.h" +#include "gimple.h" /* This file should be included last. */ #include "target-def.h" @@ -3598,6 +3599,25 @@ nvptx_dim_limit (unsigned axis) return 0; } +/* Determine whether fork & joins are needed. */ + +static bool +nvptx_xform_fork_join (gimple_stmt_iterator *ARG_UNUSED (gsi), gimple stmt, + const int dims[], bool ARG_UNUSED (is_fork)) +{ + tree arg = gimple_call_arg (stmt, 0); + unsigned axis = TREE_INT_CST_LOW (arg); + + /* We only care about worker and vector partitioning. */ + if (axis < GOMP_DIM_WORKER) + return true; + + /* If the size is 1, there's no partitioning. */ + if (dims[axis] == 1) + return true; + + return false; +} #undef TARGET_OPTION_OVERRIDE #define TARGET_OPTION_OVERRIDE nvptx_option_override @@ -3699,6 +3719,9 @@ nvptx_dim_limit (unsigned axis) #undef TARGET_GOACC_DIM_LIMIT #define TARGET_GOACC_DIM_LIMIT nvptx_dim_limit +#undef TARGET_GOACC_FORK_JOIN +#define TARGET_GOACC_FORK_JOIN nvptx_xform_fork_join + struct gcc_target targetm = TARGET_INITIALIZER; #include "gt-nvptx.h" Index: doc/tm.texi =================================================================== --- doc/tm.texi (revision 226813) +++ doc/tm.texi (working copy) @@ -5753,7 +5753,7 @@ This hook should return the maximum size or zero if unbounded. @end deftypefn -@deftypefn {Target Hook} bool TARGET_GOACC_FORK_JOIN (bool, gimple_stmt_iterator *@var{}, @var{gimple}) +@deftypefn {Target Hook} bool TARGET_GOACC_FORK_JOIN (gimple_stmt_iterator *@var{}, @var{gimple}, const @var{int[]}, @var{bool}) This hook should convert IFN_GOACC_FORK and IFN_GOACC_JOIN function calls to target-specific gimple. It is executed during the oacc_xform pass. It should return true, if the functions should be deleted. The Index: omp-low.c =================================================================== --- omp-low.c (revision 226813) +++ omp-low.c (working copy) @@ -14589,7 +14589,7 @@ oacc_xform_on_device (gimple_stmt_iterat static void oacc_xform_dim (gimple_stmt_iterator *gsi, gimple stmt, - int dims[], bool is_pos) + const int dims[], bool is_pos) { tree arg = gimple_call_arg (stmt, 0); unsigned axis = (unsigned)TREE_INT_CST_LOW (arg); @@ -14636,12 +14636,12 @@ execute_oacc_transform () for (ix = 0; ix != GOMP_DIM_MAX; ix++) { if (!pos) - dims[ix] = 0; + dims[ix] = -1; else { tree val = TREE_VALUE (pos); - dims[ix] = val ? TREE_INT_CST_LOW (val) : -1; + dims[ix] = val ? TREE_INT_CST_LOW (val) : -2; pos = TREE_CHAIN (pos); } } @@ -14652,7 +14652,7 @@ execute_oacc_transform () for (ix = 0; ix != GOMP_DIM_MAX; ix++) if (dims[ix] < 0) { - dims[ix] = 1; + dims[ix] = (int)(dims[ix] < -1); changed = true; } @@ -14699,7 +14699,7 @@ execute_oacc_transform () case IFN_GOACC_FORK: case IFN_GOACC_JOIN: if (targetm.goacc.fork_join - (ifn_code == IFN_GOACC_FORK, &gsi, stmt)) + (&gsi, stmt, dims, ifn_code == IFN_GOACC_FORK)) { replace_uses_by (gimple_vdef (stmt), gimple_vuse (stmt)); @@ -14754,24 +14754,25 @@ default_goacc_dim_limit (unsigned ARG_UN there is no RTL expander. */ bool -default_goacc_fork_join (bool is_fork, gimple_stmt_iterator *ARG_UNUSED (gsi), - gimple ARG_UNUSED (stmt)) +default_goacc_fork_join (gimple_stmt_iterator *ARG_UNUSED (gsi), + gimple ARG_UNUSED (stmt), + const int *ARG_UNUSED (dims), bool is_fork) { + /* If there is no expander, we can delete the functions. */ if (is_fork) { -#ifdef HAVE_oacc_fork - return false; +#ifndef HAVE_oacc_fork + return true; #endif } else { -#ifdef HAVE_oacc_join - return false; +#ifndef HAVE_oacc_join + return true; #endif } - /* We have no expander, so delete the functions now. */ - return true; + return false; } namespace { Index: target.def =================================================================== --- target.def (revision 226813) +++ target.def (working copy) @@ -1667,7 +1667,7 @@ DEFHOOK calls to target-specific gimple. It is executed during the oacc_xform\n\ pass. It should return true, if the functions should be deleted. The\n\ default hook returns true, if there is no RTL expanders for them.", -bool, (bool, gimple_stmt_iterator *, gimple), +bool, (gimple_stmt_iterator *, gimple, const int[], bool), default_goacc_fork_join) HOOK_VECTOR_END (goacc) Index: targhooks.h =================================================================== --- targhooks.h (revision 226813) +++ targhooks.h (working copy) @@ -109,7 +109,8 @@ extern void default_destroy_cost_data (v extern bool default_goacc_validate_dims (tree, int []); extern unsigned default_goacc_dim_limit (unsigned); -extern bool default_goacc_fork_join (bool, gimple_stmt_iterator *, gimple); +extern bool default_goacc_fork_join (gimple_stmt_iterator *, gimple, + const int [], bool); /* These are here, and not in hooks.[ch], because not all users of hooks.h include tm.h, and thus we don't have CUMULATIVE_ARGS. */ Index: tree-vrp.c =================================================================== --- tree-vrp.c (revision 226813) +++ tree-vrp.c (working copy) @@ -66,8 +66,8 @@ along with GCC; see the file COPYING3. #include "optabs.h" #include "tree-ssa-scopedtables.h" #include "tree-ssa-threadedge.h" - - +#include "omp-low.h" +#include "target.h" /* Range of values that can be associated with an SSA_NAME after VRP has executed. */ @@ -4126,7 +4126,9 @@ extract_range_basic (value_range_t *vr, else if (is_gimple_call (stmt) && gimple_call_internal_p (stmt)) { enum tree_code subcode = ERROR_MARK; - switch (gimple_call_internal_fn (stmt)) + unsigned ifn_code = gimple_call_internal_fn (stmt); + + switch (ifn_code) { case IFN_UBSAN_CHECK_ADD: subcode = PLUS_EXPR; @@ -4137,6 +4139,33 @@ extract_range_basic (value_range_t *vr, case IFN_UBSAN_CHECK_MUL: subcode = MULT_EXPR; break; + case IFN_GOACC_DIM_SIZE: + case IFN_GOACC_DIM_POS: + /* Optimizing these two internal functions helps the loop + optimizer elimitate outer comparisons. Size is [1,N] + and pos is [0,N-1]. */ + { + bool is_pos = ifn_code == IFN_GOACC_DIM_POS; + tree attr = get_oacc_fn_attrib (current_function_decl); + tree arg = gimple_call_arg (stmt, 0); + unsigned axis = (unsigned)TREE_INT_CST_LOW (arg); + tree dims = TREE_VALUE (attr); + + for (unsigned ix = axis; ix--;) + dims = TREE_CHAIN (dims); + int size = TREE_INT_CST_LOW (TREE_VALUE (dims)); + + if (!size) + size = targetm.goacc.dim_limit (axis); + if (size) + set_value_range (vr, VR_RANGE, + build_int_cst (integer_type_node, !is_pos), + build_int_cst (integer_type_node, + size - is_pos), NULL); + return; + } + break; + default: break; }