From patchwork Tue Apr 18 10:49:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Bin Cheng X-Patchwork-Id: 751782 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 3w6hhy0kl3z9s78 for ; Tue, 18 Apr 2017 20:49:35 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="CuY8Q77L"; 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:from :to:cc:subject:date:message-id:references:in-reply-to :content-type:mime-version; q=dns; s=default; b=V1y01vFe0iIIFway P4EI+mXJnTPG68X8PZOm8hkYTeHbHjo7MZS7WsxFnysd38ZR/RgysdFd7u4l3gXC 9oIECkcaYJ5i8ymiyetIdfBKwV5m4otQTvx4SEwA5nMIarOZhQiWX3jksKfg8Dly UJpmq5Dm9GxHHJMfP/xFO6nk19Y= 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:cc:subject:date:message-id:references:in-reply-to :content-type:mime-version; s=default; bh=uNTw5wODitw+4uG5scy3DN 9BiJU=; b=CuY8Q77LLEm8IzOhfFVIpnP/J6bptvcQ97CJDwrXuJ9w9quTmWhoWu B06hNcgvZuCykQ7H9lxhLWlj9mUq+kqMr2lMBT4NflY3Jv9xQPL5W3xWGpbDeypQ eRyzAR41mNdLRmNZvWgaIJKestbwHKSmgb9Id73waO6KCa+lkibXg= Received: (qmail 14424 invoked by alias); 18 Apr 2017 10:49:13 -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 14408 invoked by uid 89); 18 Apr 2017 10:49:13 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 spammy=optimal, H*f:sk:VI1PR08, H*i:sk:VI1PR08 X-HELO: EUR03-DB5-obe.outbound.protection.outlook.com Received: from mail-eopbgr40080.outbound.protection.outlook.com (HELO EUR03-DB5-obe.outbound.protection.outlook.com) (40.107.4.80) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 18 Apr 2017 10:49:11 +0000 Received: from VI1PR0802MB2176.eurprd08.prod.outlook.com (10.172.12.21) by VI1PR0802MB2175.eurprd08.prod.outlook.com (10.172.12.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1034.10; Tue, 18 Apr 2017 10:49:09 +0000 Received: from VI1PR0802MB2176.eurprd08.prod.outlook.com ([10.172.12.21]) by VI1PR0802MB2176.eurprd08.prod.outlook.com ([10.172.12.21]) with mapi id 15.01.1034.013; Tue, 18 Apr 2017 10:49:09 +0000 From: Bin Cheng To: "gcc-patches@gcc.gnu.org" CC: nd Subject: [PATCH GCC8][21/33]Support compare iv_use which both sides of comparison are IVs Date: Tue, 18 Apr 2017 10:49:09 +0000 Message-ID: References: In-Reply-To: authentication-results: arm.com; dkim=none (message not signed) header.d=none; arm.com; dmarc=none action=none header.from=arm.com; x-microsoft-exchange-diagnostics: 1; VI1PR0802MB2175; 7:9N5oGJYGG0XCaCJMPpKU+3qIqteYfgrPuCBji5OpwgE+11h85xPLt3lCThp/0287/VqNfgNMVOV0OTDkcMgO9v52k/bZAbhqWwSKE/2ztIWfMYtiOuHWxAGYbjsKqYwSG3tbsIGgWRC8lkCqtq3gPGOc/qPcmoMJEoxxkeFAbpAg+oZSC2Yevm0ecRohEKs2JdanZJS4o8PCEUCz+AvGs7oMkSPgVtjo3H4F4d5XlEhjsVfDh9KcYjlreBWN3ITAV6WmgvYtd4vtNxtMF32XXaqOoWZW7yPJV9NlGebfpDPnoPG/kOpXJRD+ZCYXNsh/i0oby1rkllxCtMpWxZO4Tg== x-ms-office365-filtering-correlation-id: c595485a-95ae-4608-b003-08d486488b58 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(2017030254075)(48565401081)(201703131423075)(201703031133081); SRVR:VI1PR0802MB2175; nodisclaimer: True x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(180628864354917); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(102415395)(6040450)(601004)(2401047)(8121501046)(5005006)(3002001)(93006095)(93001095)(10201501046)(6055026)(6041248)(20161123560025)(20161123562025)(20161123555025)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(6072148); SRVR:VI1PR0802MB2175; BCL:0; PCL:0; RULEID:; SRVR:VI1PR0802MB2175; x-forefront-prvs: 028166BF91 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(6009001)(39860400002)(39400400002)(39850400002)(39410400002)(39450400003)(39840400002)(3280700002)(189998001)(7736002)(33656002)(102836003)(86362001)(4326008)(6916009)(8936002)(25786009)(305945005)(7696004)(5660300001)(8676002)(77096006)(2950100002)(6506006)(74316002)(99936001)(2906002)(5640700003)(6116002)(53936002)(3846002)(81166006)(38730400002)(54356999)(2900100001)(110136004)(99286003)(55016002)(76176999)(6436002)(9686003)(50986999)(122556002)(2351001)(3660700001)(2501003)(66066001); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR0802MB2175; H:VI1PR0802MB2176.eurprd08.prod.outlook.com; FPR:; SPF:None; MLV:sfv; LANG:en; spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-originalarrivaltime: 18 Apr 2017 10:49:09.8043 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0802MB2175 X-IsSubscribed: yes Hi, This patch supports compare iv_use for comparison whose both sides are IVs. With this patch, optimal code is generated for PR53090. Is it OK? Thanks, bin 2017-04-11  Bin Cheng          PR tree-optimization/53090         * tree-ssa-loop-ivopts.c (enum comp_iv_rewrite): New enum value         COMP_IV_EXPR_2.         (extract_cond_operands): Detect condition with IV on both sides         and return COMP_IV_EXPR_2.         (find_interesting_uses_cond): Add iv_use for both IVs in condition.         (rewrite_use_compare): Simplify by removing call to function         extract_cond_operands. From e1037de191416b437f6b1709dd70bb42606d8400 Mon Sep 17 00:00:00 2001 From: Bin Cheng Date: Mon, 10 Apr 2017 12:06:25 +0100 Subject: [PATCH 21/33] iv-comparing-against-another-iv-20170313.txt --- gcc/tree-ssa-loop-ivopts.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/gcc/tree-ssa-loop-ivopts.c b/gcc/tree-ssa-loop-ivopts.c index 08b6245..21761e2 100644 --- a/gcc/tree-ssa-loop-ivopts.c +++ b/gcc/tree-ssa-loop-ivopts.c @@ -1651,6 +1651,9 @@ enum comp_iv_rewrite COMP_IV_NA, /* We may rewrite compare type iv_use by expressing value of the iv_use. */ COMP_IV_EXPR, + /* We may rewrite compare type iv_uses on both sides of comparison by + expressing value of each iv_use. */ + COMP_IV_EXPR_2, /* We may rewrite compare type iv_use by expressing value of the iv_use or by eliminating it with other iv_cand. */ COMP_IV_ELIM @@ -1696,9 +1699,12 @@ extract_cond_operands (struct ivopts_data *data, gimple *stmt, if (TREE_CODE (*op1) == SSA_NAME) iv1 = get_iv (data, *op1); - /* If both sides of comparison are IVs. */ + /* If both sides of comparison are IVs. We can express ivs on both end. */ if (iv0 && iv1 && !integer_zerop (iv0->step) && !integer_zerop (iv1->step)) - goto end; + { + rewrite_type = COMP_IV_EXPR_2; + goto end; + } /* If none side of comparison is IV. */ if ((!iv0 || integer_zerop (iv0->step)) @@ -1738,10 +1744,11 @@ static void find_interesting_uses_cond (struct ivopts_data *data, gimple *stmt) { tree *var_p, *bound_p; - struct iv *var_iv; + struct iv *var_iv, *bound_iv; enum comp_iv_rewrite ret; - ret = extract_cond_operands (data, stmt, &var_p, &bound_p, &var_iv, NULL); + ret = extract_cond_operands (data, stmt, + &var_p, &bound_p, &var_iv, &bound_iv); if (ret == COMP_IV_NA) { find_interesting_uses_op (data, *var_p); @@ -1750,6 +1757,9 @@ find_interesting_uses_cond (struct ivopts_data *data, gimple *stmt) } record_group_use (data, var_p, var_iv, stmt, USE_COMPARE); + /* Record compare type iv_use for iv on the other side of comparison. */ + if (ret == COMP_IV_EXPR_2) + record_group_use (data, bound_p, bound_iv, stmt, USE_COMPARE); } /* Returns the outermost loop EXPR is obviously invariant in @@ -6953,12 +6963,11 @@ static void rewrite_use_compare (struct ivopts_data *data, struct iv_use *use, struct iv_cand *cand) { - tree comp, *var_p, op, bound; + tree comp, op, bound; gimple_stmt_iterator bsi = gsi_for_stmt (use->stmt); enum tree_code compare; struct iv_group *group = data->vgroups[use->group_id]; struct cost_pair *cp = get_group_iv_cost (data, group, cand); - enum comp_iv_rewrite rewrite_type; bound = cp->value; if (bound) @@ -6991,13 +7000,10 @@ rewrite_use_compare (struct ivopts_data *data, giv. */ comp = get_computation_at (data->current_loop, use->stmt, use, cand); gcc_assert (comp != NULL_TREE); - - rewrite_type = extract_cond_operands (data, use->stmt, - &var_p, NULL, NULL, NULL); - gcc_assert (rewrite_type != COMP_IV_NA); - - *var_p = force_gimple_operand_gsi (&bsi, comp, true, SSA_NAME_VAR (*var_p), - true, GSI_SAME_STMT); + gcc_assert (use->op_p != NULL); + *use->op_p = force_gimple_operand_gsi (&bsi, comp, true, + SSA_NAME_VAR (*use->op_p), + true, GSI_SAME_STMT); } /* Rewrite the groups using the selected induction variables. */