From patchwork Mon Oct 23 17:27:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 116811 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp4891882qgn; Mon, 23 Oct 2017 10:27:49 -0700 (PDT) X-Received: by 10.98.245.153 with SMTP id b25mr13758454pfm.296.1508779668923; Mon, 23 Oct 2017 10:27:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508779668; cv=none; d=google.com; s=arc-20160816; b=AGSqly15+ERwPxhqezwTCYXAeVtSC0IQX1XobdJXDZPl5gs5tbi9/zfJnWLrLfO/u9 nRwWEwUwK7lR0l4iNhB8ImmevSB+09+DuhaqEzQx/G0vHuSDh+8s2Sw8Q0LQTKNpbPs7 W1/6cnk+z6sjhRf/t3wLRgk7UpifQA/yWXfNmQ2xB7WklpyAY7j0YJu0p0VisJTOzaYm YWqmhhoD7cJwr6UHKdaPyT9st3IX2Uw/L9ScoZHtOq50UNaYnpq+R8p8EmG28IZU8rNw g7ImbzT/xICp7w1dT04KfBcNthZbp9lWsp4zST2Gn3f3Ca9GqTEqn2cZIt7WC4aLVEku bhpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:message-id:in-reply-to:date:references :subject:mail-followup-to:to:from:delivered-to:sender:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :mailing-list:dkim-signature:domainkey-signature :arc-authentication-results; bh=5c7ae5dLzUJTXW24G3Nzwdi6oAFnhVHFSFH+1WWiG44=; b=W1xcU/E4cFi7W91HOTcwfH9eKli6VIpNpHSHRx3uF4OVxvPoxslmF6uSm/2X1uG5XR jLwa8Xeunwla960OSmy3M5VpVOvN3eXSsmqLBl5gvY+rP/lmPsxwf9pMPuVyqXKoKatn SpyzvOc7S5RE38P3TDDx4bPnu/wSHN+eEcKnOmbpqOkox/nVMTnlIxb6s0z8vCaIOt5V hsAH+CypuZy366tG3UPY2lD9v4b8GawJ+V8Ov+k8U6qlAukjrNcfWtgT1t1sC9wo2hd5 NOX9beX6EnKZMSysk66/TdJYUILvascz4+DoNb5dpPFucQSkY80EcwB9T/k2ueajQIrT aM5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=c2brn29M; spf=pass (google.com: domain of gcc-patches-return-464842-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-464842-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id f35si4253742plh.809.2017.10.23.10.27.48 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Oct 2017 10:27:48 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-464842-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=c2brn29M; spf=pass (google.com: domain of gcc-patches-return-464842-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-464842-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:references:date:in-reply-to:message-id:mime-version :content-type; q=dns; s=default; b=pLp1aBzutpoGdvtql6IKlsoQWiclO Iz2VHftauYPOnwlLMErkXkHquYHvdvMNlrMB0nB0ZQS1byBDWEjGuDOMuhfuzHS2 LmG/5CV9pT+pcNUn0efkxz7VuGzu0qzMnA8+dZIxEHBPYYYA4nGqBeGLZ6rdZFme HkmC4v9E31q20U= 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:from :to:subject:references:date:in-reply-to:message-id:mime-version :content-type; s=default; bh=/KUa+2cdF0gR6SMYwYhkJ65R/IU=; b=c2b rn29MKKRj/gAFrW8Kijg6VYRkTwHC20eXYYqD+6dVLyE4KliL5tWET0M+PwYfDDl OvzVt/PsZCyhVSxRInaMz/PsyJl/73d0YkcSEphyN1vjPIyvbjk2bzmFH7RLA7OF 8SxdtQJ1M6M7QAE1sLtp7PMpOtF1kXvLNYITJaGw= Received: (qmail 24772 invoked by alias); 23 Oct 2017 17:27:29 -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 24605 invoked by uid 89); 23 Oct 2017 17:27:28 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-wm0-f41.google.com Received: from mail-wm0-f41.google.com (HELO mail-wm0-f41.google.com) (74.125.82.41) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 23 Oct 2017 17:27:26 +0000 Received: by mail-wm0-f41.google.com with SMTP id u138so10967154wmu.5 for ; Mon, 23 Oct 2017 10:27:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:mail-followup-to:subject:references:date :in-reply-to:message-id:user-agent:mime-version; bh=5c7ae5dLzUJTXW24G3Nzwdi6oAFnhVHFSFH+1WWiG44=; b=KcX7x5nDpNCI5Mcw5rMAV9u4daQXgH/OyS4VDRqVgjQHVfkq+y/YTd3dVVB9AOYH8+ DbAD7V9JtbU/s2l+6Wb/0V0DsYCCQ6kxkbS4tQ27B+naIkB/Zwll47IUjxmBbupIa2w/ xjz3Vdns/wyKlh8bZZOZKOteZtGeOzqksYnruBe7dLIDuWKR46fnE+bnUVZYTiOQcejn bHa44c1cmUGJrOs0vKZwS6UadoHDvbkmIPL2A+luSoll3oP5IDNFmj0r2iWsHtLKA7Cr vETn1LP+VL8Gu78wzfROEXjLk9C3WSqnp/i8KbFkxKjBrvSBu/N4iKgxbiSqjHVmJ3v3 +A7Q== X-Gm-Message-State: AMCzsaW2ECtgOcCj2UTBMmLmI0bzo7xj1PDmy6kjfkgtHkEw+ShJsDyB mUJSiCxf4GGMj9HpkVK3z8QIIVmeFOE= X-Google-Smtp-Source: ABhQp+T+4DhI5tboOCzATvn3okqyGeXm/oUlXUIpg34F9WpLF5eRhNJkQY9X5at7WJN7YKfgI/2XvA== X-Received: by 10.28.17.77 with SMTP id 74mr5440980wmr.66.1508779644537; Mon, 23 Oct 2017 10:27:24 -0700 (PDT) Received: from localhost ([2.26.27.199]) by smtp.gmail.com with ESMTPSA id j2sm9453317wrj.82.2017.10.23.10.27.23 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 23 Oct 2017 10:27:23 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@linaro.org Subject: [066/nnn] poly_int: omp_max_vf References: <871sltvm7r.fsf@linaro.org> Date: Mon, 23 Oct 2017 18:27:23 +0100 In-Reply-To: <871sltvm7r.fsf@linaro.org> (Richard Sandiford's message of "Mon, 23 Oct 2017 17:54:32 +0100") Message-ID: <87y3o1ixl0.fsf@linaro.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 This patch makes omp_max_vf return a polynomial vectorization factor. We then need to be able to stash a polynomial value in OMP_CLAUSE_SAFELEN_EXPR too: /* If max_vf is non-zero, then we can use only a vectorization factor up to the max_vf we chose. So stick it into the safelen clause. */ For now the cfgloop safelen is still constant though. 2017-10-23 Richard Sandiford Alan Hayward David Sherwood gcc/ * omp-general.h (omp_max_vf): Return a poly_uint64 instead of an int. * omp-general.c (omp_max_vf): Likewise. * omp-expand.c (omp_adjust_chunk_size): Update call to omp_max_vf. (expand_omp_simd): Handle polynomial safelen. * omp-low.c (omplow_simd_context): Add a default constructor. (omplow_simd_context::max_vf): Change from int to poly_uint64. (lower_rec_simd_input_clauses): Update accordingly. (lower_rec_input_clauses): Likewise. Index: gcc/omp-general.h =================================================================== --- gcc/omp-general.h 2017-05-18 07:51:12.357753671 +0100 +++ gcc/omp-general.h 2017-10-23 17:22:29.881163047 +0100 @@ -78,7 +78,7 @@ extern tree omp_get_for_step_from_incr ( extern void omp_extract_for_data (gomp_for *for_stmt, struct omp_for_data *fd, struct omp_for_data_loop *loops); extern gimple *omp_build_barrier (tree lhs); -extern int omp_max_vf (void); +extern poly_uint64 omp_max_vf (void); extern int omp_max_simt_vf (void); extern tree oacc_launch_pack (unsigned code, tree device, unsigned op); extern void oacc_replace_fn_attrib (tree fn, tree dims); Index: gcc/omp-general.c =================================================================== --- gcc/omp-general.c 2017-08-10 14:36:08.449457108 +0100 +++ gcc/omp-general.c 2017-10-23 17:22:29.881163047 +0100 @@ -423,7 +423,7 @@ omp_build_barrier (tree lhs) /* Return maximum possible vectorization factor for the target. */ -int +poly_uint64 omp_max_vf (void) { if (!optimize Index: gcc/omp-expand.c =================================================================== --- gcc/omp-expand.c 2017-10-02 09:10:57.525659817 +0100 +++ gcc/omp-expand.c 2017-10-23 17:22:29.881163047 +0100 @@ -206,8 +206,8 @@ omp_adjust_chunk_size (tree chunk_size, if (!simd_schedule) return chunk_size; - int vf = omp_max_vf (); - if (vf == 1) + poly_uint64 vf = omp_max_vf (); + if (must_eq (vf, 1U)) return chunk_size; tree type = TREE_TYPE (chunk_size); @@ -4609,11 +4609,12 @@ expand_omp_simd (struct omp_region *regi if (safelen) { + poly_uint64 val; safelen = OMP_CLAUSE_SAFELEN_EXPR (safelen); - if (TREE_CODE (safelen) != INTEGER_CST) + if (!poly_int_tree_p (safelen, &val)) safelen_int = 0; - else if (tree_fits_uhwi_p (safelen) && tree_to_uhwi (safelen) < INT_MAX) - safelen_int = tree_to_uhwi (safelen); + else + safelen_int = MIN (constant_lower_bound (val), INT_MAX); if (safelen_int == 1) safelen_int = 0; } Index: gcc/omp-low.c =================================================================== --- gcc/omp-low.c 2017-10-23 17:17:01.432034493 +0100 +++ gcc/omp-low.c 2017-10-23 17:22:29.882163248 +0100 @@ -3487,11 +3487,12 @@ omp_clause_aligned_alignment (tree claus and lower_rec_input_clauses. */ struct omplow_simd_context { + omplow_simd_context () { memset (this, 0, sizeof (*this)); } tree idx; tree lane; vec simt_eargs; gimple_seq simt_dlist; - int max_vf; + poly_uint64_pod max_vf; bool is_simt; }; @@ -3502,28 +3503,30 @@ struct omplow_simd_context { lower_rec_simd_input_clauses (tree new_var, omp_context *ctx, omplow_simd_context *sctx, tree &ivar, tree &lvar) { - if (sctx->max_vf == 0) + if (known_zero (sctx->max_vf)) { sctx->max_vf = sctx->is_simt ? omp_max_simt_vf () : omp_max_vf (); - if (sctx->max_vf > 1) + if (may_gt (sctx->max_vf, 1U)) { tree c = omp_find_clause (gimple_omp_for_clauses (ctx->stmt), OMP_CLAUSE_SAFELEN); - if (c - && (TREE_CODE (OMP_CLAUSE_SAFELEN_EXPR (c)) != INTEGER_CST - || tree_int_cst_sgn (OMP_CLAUSE_SAFELEN_EXPR (c)) != 1)) - sctx->max_vf = 1; - else if (c && compare_tree_int (OMP_CLAUSE_SAFELEN_EXPR (c), - sctx->max_vf) == -1) - sctx->max_vf = tree_to_shwi (OMP_CLAUSE_SAFELEN_EXPR (c)); + if (c) + { + poly_uint64 safe_len; + if (!poly_int_tree_p (OMP_CLAUSE_SAFELEN_EXPR (c), &safe_len) + || may_lt (safe_len, 1U)) + sctx->max_vf = 1; + else + sctx->max_vf = lower_bound (sctx->max_vf, safe_len); + } } - if (sctx->max_vf > 1) + if (may_gt (sctx->max_vf, 1U)) { sctx->idx = create_tmp_var (unsigned_type_node); sctx->lane = create_tmp_var (unsigned_type_node); } } - if (sctx->max_vf == 1) + if (must_eq (sctx->max_vf, 1U)) return false; if (sctx->is_simt) @@ -3637,7 +3640,7 @@ lower_rec_input_clauses (tree clauses, g } /* Add a placeholder for simduid. */ - if (sctx.is_simt && sctx.max_vf != 1) + if (sctx.is_simt && may_ne (sctx.max_vf, 1U)) sctx.simt_eargs.safe_push (NULL_TREE); /* Do all the fixed sized types in the first pass, and the variable sized @@ -4527,7 +4530,7 @@ lower_rec_input_clauses (tree clauses, g } } - if (sctx.max_vf == 1) + if (must_eq (sctx.max_vf, 1U)) sctx.is_simt = false; if (sctx.lane || sctx.is_simt) @@ -4664,14 +4667,14 @@ lower_rec_input_clauses (tree clauses, g /* If max_vf is non-zero, then we can use only a vectorization factor up to the max_vf we chose. So stick it into the safelen clause. */ - if (sctx.max_vf) + if (maybe_nonzero (sctx.max_vf)) { tree c = omp_find_clause (gimple_omp_for_clauses (ctx->stmt), OMP_CLAUSE_SAFELEN); + poly_uint64 safe_len; if (c == NULL_TREE - || (TREE_CODE (OMP_CLAUSE_SAFELEN_EXPR (c)) == INTEGER_CST - && compare_tree_int (OMP_CLAUSE_SAFELEN_EXPR (c), - sctx.max_vf) == 1)) + || (poly_int_tree_p (OMP_CLAUSE_SAFELEN_EXPR (c), &safe_len) + && may_gt (safe_len, sctx.max_vf))) { c = build_omp_clause (UNKNOWN_LOCATION, OMP_CLAUSE_SAFELEN); OMP_CLAUSE_SAFELEN_EXPR (c) = build_int_cst (integer_type_node,