From patchwork Mon Oct 23 17:24:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 116804 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp4889592qgn; Mon, 23 Oct 2017 10:25:10 -0700 (PDT) X-Received: by 10.84.193.129 with SMTP id f1mr3541153pld.248.1508779510698; Mon, 23 Oct 2017 10:25:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508779510; cv=none; d=google.com; s=arc-20160816; b=hKELdY77cFzETNJ8TyD519825hIqDj0lwxrtWb16rVlPeqDYmIfm09x+ONbxWVfAiY iEYzi0yM9bWFqtYn76zZNHoxys7KM6FEWSXEvNV416GeEf0KfVF45eTgi7wJxlkyjVhG 0nlJjjTVJhFrpv65wjDZLn0yTtwFR5J1eS74otOL5MxucYUSjHzXutRZHHHT2foiAgS+ mbEwOIgMfmXRJk1G8OGmigKFAKJfF8PGrdBMQkQAbZPcCl8cORQ9RezRsr95v0EqhHG2 Lu6Mwr6it2yBkUbK2TQlXLgsu6fzgS99iRyTJUmbMKaBu+3ZMz0+G6Vaoe8m5HmoisZz C41A== 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=hXfKIw/r6cNcSHuE6Oqm8LUezypGCRlyS8Nmb0vyVFY=; b=PNMW2kYcN0i8tMBRCtPWydo+jhTMncVd5nlF3J3npFEyBYWSxzE1Qlp4Wif2nw2ft3 Kn0cc43ChMjJb0CeOq1zagwRWz0PU9qjb7xym21O3+5hKEzTjjr6WGD06NSLXYkqG4xo Ea7Z2GCUrcq8TFujCilNKs1jWhwCiHECB1URlmBNUJXmdPnN+lt2F+YswQcPfDTGizM6 8aEE321NdIp+WoOJ8LUQi9f4/YyQJ68jPgjcjJii319Wp9UB5roI6av91k1JRGbwBDUE puwIBdMVcqQiAVcrGYEgjTiJuh1rAC3qSnpRti+mRfMmfzU+fQs6E31UoXYFBdv09HzN aY1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=cB+NAV8E; spf=pass (google.com: domain of gcc-patches-return-464835-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-464835-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 g8si4175980plt.739.2017.10.23.10.25.10 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Oct 2017 10:25:10 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-464835-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=cB+NAV8E; spf=pass (google.com: domain of gcc-patches-return-464835-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-464835-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=FEO4z9VOV7l41NMfYnnQ1mht50/X/ faDHG+7HpG7DJrt5QRrNnE+t1YJa4DhuelHy6lrOJCwYm9YvGzhIg/OjTtNpyDaH HCrDxWg6yYmr7or04ByS77FJoIbxRFcWmgk47q0bxI3zilttvAWsRa820++w+bfv t86upHWiQAjo5I= 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=wsvVzuNALL3MaXO5JxSdyQrTTRw=; b=cB+ NAV8ElIKUDaxF4sdWVgmg1g6yCtNIz4apZ+0lAAvYKolbjqnWKEX1EwgkI/neFNM HodP/bpt2QwmUoaCxBUjpq017PWOcolIIXqTl7i6meNUy/OmDT1mUDtCy0FR7nvx YCjJxvZNAJyy5v2x9ef5lAmqo3eoj6VFZ6m0RDsY= Received: (qmail 58627 invoked by alias); 23 Oct 2017 17:24:47 -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 58566 invoked by uid 89); 23 Oct 2017 17:24:46 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=059, 28436 X-HELO: mail-wr0-f176.google.com Received: from mail-wr0-f176.google.com (HELO mail-wr0-f176.google.com) (209.85.128.176) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 23 Oct 2017 17:24:45 +0000 Received: by mail-wr0-f176.google.com with SMTP id l8so5304613wre.12 for ; Mon, 23 Oct 2017 10:24:44 -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=hXfKIw/r6cNcSHuE6Oqm8LUezypGCRlyS8Nmb0vyVFY=; b=r+OuUlfrAhssMh9qOPXkQQWGurROCxyW42Qzro97S3AFFizA44axNn75I4YdHv+LNP Rbwpvgolz6lZLmU86rFXtErTP8LbfVmUcoWLsbXI5WBFViTiXf4LQMt7kbfalKYL39dy BmZydlRPaOiC/VIeHD9aNHL5r6gFL5mTQIoP7Yt0a2mRbu+TdgT1Kv27x4Gm294no65W EdXCIKO+uJjJKmp87jmcOo/J5mlxOcmLM62lny88CtiqpEhWhBHqix7adAzlrqJBMpeh qp+yC25JparANNgptr5/BNsyvZUcXyQQCRwwAIuALq5a5tybyLn6MbzUiV4QT7kB2fj/ u3mA== X-Gm-Message-State: AMCzsaVRlH9KDMhD6sLX+WCSZPBT5nsjJdER1Ne/EAyfSGnFMcMJfok6 LFmhp21aoGFjeC5GF49np3TBfN7/n4k= X-Google-Smtp-Source: ABhQp+Svn22Tz3ANsX50E92q8tbZ+SlTh+ZaRDtZ4/ebseFpdCNhGF6YHaRSupcNAMXiijRlZCE9+Q== X-Received: by 10.223.157.137 with SMTP id p9mr62970wre.98.1508779482608; Mon, 23 Oct 2017 10:24:42 -0700 (PDT) Received: from localhost ([2.26.27.199]) by smtp.gmail.com with ESMTPSA id n30sm4920386wra.39.2017.10.23.10.24.41 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 23 Oct 2017 10:24:41 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@linaro.org Subject: [059/nnn] poly_int: tree-ssa-loop-ivopts.c:iv_use References: <871sltvm7r.fsf@linaro.org> Date: Mon, 23 Oct 2017 18:24:41 +0100 In-Reply-To: <871sltvm7r.fsf@linaro.org> (Richard Sandiford's message of "Mon, 23 Oct 2017 17:54:32 +0100") Message-ID: <87she9kc9y.fsf@linaro.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 This patch makes ivopts handle polynomial address offsets when recording potential IV uses. 2017-10-23 Richard Sandiford Alan Hayward David Sherwood gcc/ * tree-ssa-loop-ivopts.c (iv_use::addr_offset): Change from an unsigned HOST_WIDE_INT to a poly_uint64_pod. (group_compare_offset): Update accordingly. (split_small_address_groups_p): Likewise. (record_use): Take addr_offset as a poly_uint64 rather than an unsigned HOST_WIDE_INT. (strip_offset): Return the offset as a poly_uint64 rather than an unsigned HOST_WIDE_INT. (record_group_use, split_address_groups): Track polynomial offsets. (add_iv_candidate_for_use): Likewise. (addr_offset_valid_p): Take the offset as a poly_int64 rather than a HOST_WIDE_INT. (strip_offset_1): Return the offset as a poly_int64 rather than a HOST_WIDE_INT. Index: gcc/tree-ssa-loop-ivopts.c =================================================================== --- gcc/tree-ssa-loop-ivopts.c 2017-10-23 17:17:03.208794553 +0100 +++ gcc/tree-ssa-loop-ivopts.c 2017-10-23 17:22:22.298641645 +0100 @@ -367,7 +367,7 @@ struct iv_use tree *op_p; /* The place where it occurs. */ tree addr_base; /* Base address with const offset stripped. */ - unsigned HOST_WIDE_INT addr_offset; + poly_uint64_pod addr_offset; /* Const offset stripped from base address. */ }; @@ -1508,7 +1508,7 @@ find_induction_variables (struct ivopts_ static struct iv_use * record_use (struct iv_group *group, tree *use_p, struct iv *iv, gimple *stmt, enum use_type type, tree addr_base, - unsigned HOST_WIDE_INT addr_offset) + poly_uint64 addr_offset) { struct iv_use *use = XCNEW (struct iv_use); @@ -1553,7 +1553,7 @@ record_invariant (struct ivopts_data *da } static tree -strip_offset (tree expr, unsigned HOST_WIDE_INT *offset); +strip_offset (tree expr, poly_uint64 *offset); /* Record a group of TYPE. */ @@ -1580,7 +1580,7 @@ record_group_use (struct ivopts_data *da { tree addr_base = NULL; struct iv_group *group = NULL; - unsigned HOST_WIDE_INT addr_offset = 0; + poly_uint64 addr_offset = 0; /* Record non address type use in a new group. */ if (type == USE_ADDRESS && iv->base_object) @@ -2514,7 +2514,7 @@ find_interesting_uses_outside (struct iv static GTY (()) vec *addr_list; static bool -addr_offset_valid_p (struct iv_use *use, HOST_WIDE_INT offset) +addr_offset_valid_p (struct iv_use *use, poly_int64 offset) { rtx reg, addr; unsigned list_index; @@ -2548,10 +2548,7 @@ group_compare_offset (const void *a, con const struct iv_use *const *u1 = (const struct iv_use *const *) a; const struct iv_use *const *u2 = (const struct iv_use *const *) b; - if ((*u1)->addr_offset != (*u2)->addr_offset) - return (*u1)->addr_offset < (*u2)->addr_offset ? -1 : 1; - else - return 0; + return compare_sizes_for_sort ((*u1)->addr_offset, (*u2)->addr_offset); } /* Check if small groups should be split. Return true if no group @@ -2582,7 +2579,8 @@ split_small_address_groups_p (struct ivo gcc_assert (group->type == USE_ADDRESS); if (group->vuses.length () == 2) { - if (group->vuses[0]->addr_offset > group->vuses[1]->addr_offset) + if (compare_sizes_for_sort (group->vuses[0]->addr_offset, + group->vuses[1]->addr_offset) > 0) std::swap (group->vuses[0], group->vuses[1]); } else @@ -2594,7 +2592,7 @@ split_small_address_groups_p (struct ivo distinct = 1; for (pre = group->vuses[0], j = 1; j < group->vuses.length (); j++) { - if (group->vuses[j]->addr_offset != pre->addr_offset) + if (may_ne (group->vuses[j]->addr_offset, pre->addr_offset)) { pre = group->vuses[j]; distinct++; @@ -2635,13 +2633,13 @@ split_address_groups (struct ivopts_data for (j = 1; j < group->vuses.length ();) { struct iv_use *next = group->vuses[j]; - HOST_WIDE_INT offset = next->addr_offset - use->addr_offset; + poly_int64 offset = next->addr_offset - use->addr_offset; /* Split group if aksed to, or the offset against the first use can't fit in offset part of addressing mode. IV uses having the same offset are still kept in one group. */ - if (offset != 0 && - (split_p || !addr_offset_valid_p (use, offset))) + if (maybe_nonzero (offset) + && (split_p || !addr_offset_valid_p (use, offset))) { if (!new_group) new_group = record_group (data, group->type); @@ -2702,12 +2700,13 @@ find_interesting_uses (struct ivopts_dat static tree strip_offset_1 (tree expr, bool inside_addr, bool top_compref, - HOST_WIDE_INT *offset) + poly_int64 *offset) { tree op0 = NULL_TREE, op1 = NULL_TREE, tmp, step; enum tree_code code; tree type, orig_type = TREE_TYPE (expr); - HOST_WIDE_INT off0, off1, st; + poly_int64 off0, off1; + HOST_WIDE_INT st; tree orig_expr = expr; STRIP_NOPS (expr); @@ -2718,14 +2717,6 @@ strip_offset_1 (tree expr, bool inside_a switch (code) { - case INTEGER_CST: - if (!cst_and_fits_in_hwi (expr) - || integer_zerop (expr)) - return orig_expr; - - *offset = int_cst_value (expr); - return build_int_cst (orig_type, 0); - case POINTER_PLUS_EXPR: case PLUS_EXPR: case MINUS_EXPR: @@ -2843,6 +2834,8 @@ strip_offset_1 (tree expr, bool inside_a break; default: + if (ptrdiff_tree_p (expr, offset) && maybe_nonzero (*offset)) + return build_int_cst (orig_type, 0); return orig_expr; } @@ -2872,9 +2865,9 @@ strip_offset_1 (tree expr, bool inside_a /* Strips constant offsets from EXPR and stores them to OFFSET. */ static tree -strip_offset (tree expr, unsigned HOST_WIDE_INT *offset) +strip_offset (tree expr, poly_uint64 *offset) { - HOST_WIDE_INT off; + poly_int64 off; tree core = strip_offset_1 (expr, false, false, &off); *offset = off; return core; @@ -3401,7 +3394,7 @@ add_iv_candidate_derived_from_uses (stru static void add_iv_candidate_for_use (struct ivopts_data *data, struct iv_use *use) { - unsigned HOST_WIDE_INT offset; + poly_uint64 offset; tree base; tree basetype; struct iv *iv = use->iv; @@ -3420,7 +3413,7 @@ add_iv_candidate_for_use (struct ivopts_ /* Record common candidate with constant offset stripped in base. Like the use itself, we also add candidate directly for it. */ base = strip_offset (iv->base, &offset); - if (offset || base != iv->base) + if (maybe_nonzero (offset) || base != iv->base) { record_common_cand (data, base, iv->step, use); add_candidate (data, base, iv->step, false, use); @@ -3439,7 +3432,7 @@ add_iv_candidate_for_use (struct ivopts_ record_common_cand (data, base, step, use); /* Also record common candidate with offset stripped. */ base = strip_offset (base, &offset); - if (offset) + if (maybe_nonzero (offset)) record_common_cand (data, base, step, use); }