From patchwork Tue Apr 18 10:53:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bin Cheng X-Patchwork-Id: 751791 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 3w6hp45Rx7z9s78 for ; Tue, 18 Apr 2017 20:54:04 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="wsRWqWY5"; 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:content-type:mime-version; q=dns; s=default; b=C2PMXTpYaT67t7Njv1AAjMqOU5TZcX7wprXzVzrVLR8iMy4KMY /DTDgqH1xTIS13y8/bctCo0JruW6fc7Zr1m7jDP9jOg+GuA5H4sRI4BX2rU/kKVY 7mlkgxENOVCkXbtqjjKVtEdTs+gjzHZTSqkb+i2xSjOvLG3tryyMnWGLg= 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:content-type:mime-version; s= default; bh=FOW3IbVJ+vjH/zn5LMM2muOHApE=; b=wsRWqWY5Xz1T93yF56sm x2QifaFp9J4TsBuS1AyvlZ7HsmxRdES8E4V2SpVu07j01eRBXW0TdnDiHkIGjA+I UZAxRLvtPL5PSaQ0CaGSjL16HhW7iOc4gu2BDYg3S51nbe2EaWphCU62MvLEP4fX awFLJjccmxUaUGSQBEEN/QA= Received: (qmail 33984 invoked by alias); 18 Apr 2017 10:53:46 -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 33772 invoked by uid 89); 18 Apr 2017 10:53:43 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.3 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= X-HELO: EUR03-VE1-obe.outbound.protection.outlook.com Received: from mail-eopbgr50087.outbound.protection.outlook.com (HELO EUR03-VE1-obe.outbound.protection.outlook.com) (40.107.5.87) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 18 Apr 2017 10:53:41 +0000 Received: from VI1PR0802MB2176.eurprd08.prod.outlook.com (10.172.12.21) by VI1PR0802MB2173.eurprd08.prod.outlook.com (10.172.12.18) 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:53:40 +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:53:40 +0000 From: Bin Cheng To: "gcc-patches@gcc.gnu.org" CC: nd Subject: [PATCH GCC8][30/33]Fold more type conversion into binary arithmetic operations Date: Tue, 18 Apr 2017 10:53:40 +0000 Message-ID: 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; VI1PR0802MB2173; 7:uLp6q25eZu3KVG88p6nym07yjn2A7IpRlu8EiUZeJxFbcLPQuD+1zIhITGWgvTaghxkpl+cdoNRbfNje6/Jh9N8EmH/alNXENbHHb/77jRGX/qjfzA3WwfsR5qV3qDtyrV0IMUj7Q4aSq8IeYUrlV6k7n+Qozpc4y70B9/GbXB3sqkoNbmV4PbnO0fbqQ599Wq6Pb5Ml31WfaCNdWQGy5e3fRkKGKtNhZWdwyoSV5Se2y6wOyn28SzrOcb+MGO+p33gn/nICL/cZixXJKAC/ySVGawKLzQ3cKZHrsZNd5bG3qXGlIC/gCYJ7tQ3FmUz6RJLSlzf1tUBEVoIwrUifMg== x-ms-office365-filtering-correlation-id: 930f4d28-a21b-49fa-00df-08d486492c7f x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(2017030254075)(48565401081)(201703131423075)(201703031133081)(201702281549075); SRVR:VI1PR0802MB2173; 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)(5005006)(8121501046)(10201501046)(3002001)(93006095)(93001095)(6055026)(6041248)(201703131423075)(201702281528075)(201703061421075)(20161123564025)(20161123555025)(20161123562025)(20161123560025)(6072148); SRVR:VI1PR0802MB2173; BCL:0; PCL:0; RULEID:; SRVR:VI1PR0802MB2173; x-forefront-prvs: 028166BF91 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(6009001)(39410400002)(39450400003)(39840400002)(39860400002)(39400400002)(39850400002)(5640700003)(9686003)(2906002)(3846002)(33656002)(54356999)(3280700002)(305945005)(7736002)(50986999)(38730400002)(55016002)(6116002)(99286003)(102836003)(8936002)(81166006)(122556002)(66066001)(74316002)(86362001)(53936002)(4326008)(6436002)(110136004)(189998001)(99936001)(6506006)(8676002)(2351001)(3660700001)(25786009)(5660300001)(2900100001)(2501003)(6916009)(7696004)(77096006); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR0802MB2173; 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:53:40.1746 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0802MB2173 X-IsSubscribed: yes Hi, Simplification of (T1)(X *+- CST) is already implemented in aff_combination_expand, this patch moves it to tree_to_aff_combination. It also supports unsigned types if range information allows the transformation, as well as special case (T1)(X + X). Is it OK? Thanks, bin 2017-04-11 Bin Cheng * tree-affine.c: Include header file. (aff_combination_expand): Move (T1)(X *+- CST) simplification to ... (tree_to_aff_combination): ... here. Support (T1)(X + X) case, and unsigned type case if range information allows. From c3d37447c529793bfdab319574a8a065e7871292 Mon Sep 17 00:00:00 2001 From: Bin Cheng Date: Wed, 15 Mar 2017 13:59:09 +0000 Subject: [PATCH 30/33] affine-fold-conversion-to-bin_op-20170224.txt --- gcc/tree-affine.c | 82 ++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 60 insertions(+), 22 deletions(-) diff --git a/gcc/tree-affine.c b/gcc/tree-affine.c index 13c477d..6efd1e4 100644 --- a/gcc/tree-affine.c +++ b/gcc/tree-affine.c @@ -24,6 +24,7 @@ along with GCC; see the file COPYING3. If not see #include "rtl.h" #include "tree.h" #include "gimple.h" +#include "ssa.h" #include "tree-pretty-print.h" #include "fold-const.h" #include "tree-affine.h" @@ -363,6 +364,61 @@ tree_to_aff_combination (tree expr, tree type, aff_tree *comb) aff_combination_add (comb, &tmp); return; + CASE_CONVERT: + { + tree otype = TREE_TYPE (expr); + tree inner = TREE_OPERAND (expr, 0); + tree itype = TREE_TYPE (inner); + enum tree_code icode = TREE_CODE (inner); + + /* In principle this is a valid folding, but it isn't necessarily + an optimization, so do it here and not in fold_unary. */ + if ((icode == PLUS_EXPR || icode == MINUS_EXPR || icode == MULT_EXPR) + && TREE_CODE (itype) == INTEGER_TYPE + && TREE_CODE (otype) == INTEGER_TYPE + && TYPE_PRECISION (otype) > TYPE_PRECISION (itype)) + { + tree op0 = TREE_OPERAND (inner, 0), op1 = TREE_OPERAND (inner, 1); + + /* Convert (T1)(X *+- CST) into (T1)X *+- (T1)CST if X's type has + undefined overflow behavior. Convert (T1)(X + X) as well. */ + if (TYPE_OVERFLOW_UNDEFINED (itype) + && (TREE_CODE (op1) == INTEGER_CST + || (icode == PLUS_EXPR && operand_equal_p (op0, op1, 0)))) + { + op0 = fold_convert (otype, op0); + op1 = fold_convert (otype, op1); + expr = fold_build2 (icode, otype, op0, op1); + tree_to_aff_combination (expr, type, comb); + return; + } + wide_int minv, maxv; + /* In case X's type has wrapping overflow behavior, we can still + convert (T1)(X - CST) into (T1)X - (T1)CST if X - CST doesn't + overflow by range information. Also Convert (T1)(X + CST) as + if it's (T1)(X - (-CST)). */ + if (TYPE_UNSIGNED (itype) + && TYPE_OVERFLOW_WRAPS (itype) + && TREE_CODE (op0) == SSA_NAME + && TREE_CODE (op1) == INTEGER_CST + && (icode == PLUS_EXPR || icode == MINUS_EXPR) + && get_range_info (op0, &minv, &maxv) == VR_RANGE) + { + if (icode == PLUS_EXPR) + op1 = fold_build1 (NEGATE_EXPR, itype, op1); + if (wi::geu_p (minv, op1)) + { + op0 = fold_convert (otype, op0); + op1 = fold_convert (otype, op1); + expr = fold_build2 (MINUS_EXPR, otype, op0, op1); + tree_to_aff_combination (expr, type, comb); + return; + } + } + } + } + break; + default: break; } @@ -639,28 +695,10 @@ aff_combination_expand (aff_tree *comb ATTRIBUTE_UNUSED, exp = XNEW (struct name_expansion); exp->in_progress = 1; *slot = exp; - /* In principle this is a generally valid folding, but - it is not unconditionally an optimization, so do it - here and not in fold_unary. */ - /* Convert (T1)(X *+- CST) into (T1)X *+- (T1)CST if T1 is wider - than the type of X and overflow for the type of X is - undefined. */ - if (e != name - && INTEGRAL_TYPE_P (type) - && INTEGRAL_TYPE_P (TREE_TYPE (name)) - && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (name)) - && TYPE_PRECISION (type) > TYPE_PRECISION (TREE_TYPE (name)) - && (code == PLUS_EXPR || code == MINUS_EXPR || code == MULT_EXPR) - && TREE_CODE (gimple_assign_rhs2 (def)) == INTEGER_CST) - rhs = fold_build2 (code, type, - fold_convert (type, gimple_assign_rhs1 (def)), - fold_convert (type, gimple_assign_rhs2 (def))); - else - { - rhs = gimple_assign_rhs_to_tree (def); - if (e != name) - rhs = fold_convert (type, rhs); - } + rhs = gimple_assign_rhs_to_tree (def); + if (e != name) + rhs = fold_convert (type, rhs); + tree_to_aff_combination_expand (rhs, comb->type, ¤t, cache); exp->expansion = current; exp->in_progress = 0;