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: 829491 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-464842-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="vB4DWvdp"; dkim-atps=neutral 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 3yLNdW1bJsz9t6C for ; Tue, 24 Oct 2017 04:27:43 +1100 (AEDT) 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=R/SXCV8LlNbao61jK07B98nl66+ZA D4qFGt7HXUOf6Aw+sacJIFwMQMHl5ecBMcCv+n1Yq7BE8rwISMEn2ZdM/An8xJaI 5iGC7VELYWWJagHLv8FjE2j8iCcIMhezB+OgAKUuKmgm8CupRlmK2oTMtsOie8VK 5K1keaOpua/KFY= 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=vB4 DWvdpXUW4GuAWPnkB22/onRhsx5cdXnb80Ne3xhkqRfwbFr8qKPvZm0uIia82wkC jpqO/m0yAiwwdIhnC8t7aQTz7jRKLGvdyTHQaslJnIl9V9c2gV0v6sTT7mh7rUJb b4ntwlRjFZMObOD8TtWDpXbVxWM1l0RssdEDjRZM= 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,