From patchwork Tue Aug 25 03:29:41 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Hurugalawadi, Naveen" X-Patchwork-Id: 510370 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 1574B1401F0 for ; Tue, 25 Aug 2015 13:29:57 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=E0ZsM9VD; 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=HGm762BWe1fGB98quUm+qdoL9l/MVyIlMNSsVKWPsOWjg4P4vC MS4JdmjttTQuj6SQqX90/aGxAPMju9qJMZrMus/KjhqXNGBdeew4X2581QvdQwVi TcoMtPcajXV4cl6hVsC5ioapYv9ggdsQjJgFeu5p9FjjphBVanl9cEaBo= 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=V0FsLa2pXppVwIThU34owM5kBug=; b=E0ZsM9VDwaWq9OW+h4Zk U3fZS/jpqLLnL5spPcvUGR5pcIUMVCHqXkVkKgKytjpIImyOlZvxzNd7UjPuZor7 xeZ5cAJ+E6j2TZubPG9NjDbThAw38sb2Jstbk7LVnIeZHBMRDxkjtqceZV1d1/IU uW8koBVnmvQx0sh/ZWqQGKg= Received: (qmail 20263 invoked by alias); 25 Aug 2015 03:29:49 -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 20251 invoked by uid 89); 25 Aug 2015 03:29:48 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.4 required=5.0 tests=AWL, BAYES_05, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=no version=3.3.2 X-HELO: na01-bn1-obe.outbound.protection.outlook.com Received: from mail-bn1on0091.outbound.protection.outlook.com (HELO na01-bn1-obe.outbound.protection.outlook.com) (157.56.110.91) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA256 encrypted) ESMTPS; Tue, 25 Aug 2015 03:29:46 +0000 Received: from SN2PR0701MB1024.namprd07.prod.outlook.com (10.160.57.150) by SN2PR0701MB1024.namprd07.prod.outlook.com (10.160.57.150) with Microsoft SMTP Server (TLS) id 15.1.243.23; Tue, 25 Aug 2015 03:29:42 +0000 Received: from SN2PR0701MB1024.namprd07.prod.outlook.com ([10.160.57.150]) by SN2PR0701MB1024.namprd07.prod.outlook.com ([10.160.57.150]) with mapi id 15.01.0243.020; Tue, 25 Aug 2015 03:29:42 +0000 From: "Hurugalawadi, Naveen" To: "gcc-patches@gcc.gnu.org" CC: Richard Biener Subject: Move remaining flag_unsafe_math_optimizations using simplify and match Date: Tue, 25 Aug 2015 03:29:41 +0000 Message-ID: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Naveen.Hurugalawadi@caviumnetworks.com; x-microsoft-exchange-diagnostics: 1; SN2PR0701MB1024; 5:5Tq2f8poPTdl6jQe0sbKYw7JvZHJ4nIxOu+jPurNnJfRGXSVEuXF/6IFblA9a9ntauyWEdmLvJapgHBsKylRTCEFYcoIn9Jbl+Eehs5J2pgr8uPDYMxNCv2mJua8WNv2BrPhnsgwjKYYm6rUPwsBiw==; 24:OnlZiV7KJwQAN8ePshceTnLTeVawSL9IbWsKUQCaQZ18C4JNABBQxo3VpLco5yF2VdAhi7iefyM6XWO3/D2JSoCrRSy7qRf45Lb4LsXHdn8=; 20:zgkcKg9zO+y6UUFMTC9lc6jFGkra35b19dYfPs9SFOz0nyXCjsi8G6v4CO54I3utm1les2QvADP1JVijBwMaUA== x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:SN2PR0701MB1024; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(601004)(5005006)(8121501046)(3002001); SRVR:SN2PR0701MB1024; BCL:0; PCL:0; RULEID:; SRVR:SN2PR0701MB1024; x-forefront-prvs: 06793E740F x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(6009001)(164054003)(54534003)(199003)(189002)(377424004)(99286002)(5890100001)(122556002)(2501003)(68736005)(2900100001)(106356001)(76576001)(102836002)(106116001)(92566002)(40100003)(10400500002)(229853001)(105586002)(2351001)(5002640100001)(5007970100001)(77156002)(62966003)(5003600100002)(77096005)(46102003)(5004730100002)(87936001)(5001830100001)(74316001)(5001960100002)(19580395003)(33656002)(19580405001)(86362001)(101416001)(4001540100001)(97736004)(64706001)(54356999)(81156007)(110136002)(5001860100001)(66066001)(50986999)(99936001)(2656002)(189998001); DIR:OUT; SFP:1101; SCL:1; SRVR:SN2PR0701MB1024; H:SN2PR0701MB1024.namprd07.prod.outlook.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; received-spf: None (protection.outlook.com: caviumnetworks.com does not designate permitted sender hosts) spamdiagnosticoutput: 1:23 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-originalarrivaltime: 25 Aug 2015 03:29:41.5754 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN2PR0701MB1024 Hi, Please find attached the remaining part of patch. Tested the patch on AArch64 and X86 without any regressions. Please review the patch and let me know if any modifications are required. Thanks, Naveen ChangeLog 2015-08-25 Naveen H.S * fold-const.c (fold_binary_loc) : Move Optimize root(x)*root(y) as root(x*y) to match.pd. Move Optimize expN(x)*expN(y) as expN(x+y) to match.pd. Move Optimize pow(x,y)*pow(x,z) as pow(x,y+z) to match.pd. Move Optimize a/root(b/c) into a*root(c/b) to match.pd. Move Optimize x/expN(y) into x*expN(-y) to match.pd. * match.pd (mult (root:s @0) (root:s @1)): New simplifier. (mult (POW:s @0 @1) (POW:s @0 @2)) : New simplifier. (mult (exps:s @0) (exps:s @1)) : New simplifier. (rdiv @0 (root:s (rdiv:s @1 @2))) : New simplifier. (rdiv @0 (exps:s @1)) : New simplifier. diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 1e01726..c826e67 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -9947,51 +9947,6 @@ fold_binary_loc (location_t loc, if (flag_unsafe_math_optimizations) { - enum built_in_function fcode0 = builtin_mathfn_code (arg0); - enum built_in_function fcode1 = builtin_mathfn_code (arg1); - - /* Optimizations of root(...)*root(...). */ - if (fcode0 == fcode1 && BUILTIN_ROOT_P (fcode0)) - { - tree rootfn, arg; - tree arg00 = CALL_EXPR_ARG (arg0, 0); - tree arg10 = CALL_EXPR_ARG (arg1, 0); - - /* Optimize root(x)*root(y) as root(x*y). */ - rootfn = TREE_OPERAND (CALL_EXPR_FN (arg0), 0); - arg = fold_build2_loc (loc, MULT_EXPR, type, arg00, arg10); - return build_call_expr_loc (loc, rootfn, 1, arg); - } - - /* Optimize expN(x)*expN(y) as expN(x+y). */ - if (fcode0 == fcode1 && BUILTIN_EXPONENT_P (fcode0)) - { - tree expfn = TREE_OPERAND (CALL_EXPR_FN (arg0), 0); - tree arg = fold_build2_loc (loc, PLUS_EXPR, type, - CALL_EXPR_ARG (arg0, 0), - CALL_EXPR_ARG (arg1, 0)); - return build_call_expr_loc (loc, expfn, 1, arg); - } - - /* Optimizations of pow(...)*pow(...). */ - if ((fcode0 == BUILT_IN_POW && fcode1 == BUILT_IN_POW) - || (fcode0 == BUILT_IN_POWF && fcode1 == BUILT_IN_POWF) - || (fcode0 == BUILT_IN_POWL && fcode1 == BUILT_IN_POWL)) - { - tree arg00 = CALL_EXPR_ARG (arg0, 0); - tree arg01 = CALL_EXPR_ARG (arg0, 1); - tree arg10 = CALL_EXPR_ARG (arg1, 0); - tree arg11 = CALL_EXPR_ARG (arg1, 1); - - /* Optimize pow(x,y)*pow(x,z) as pow(x,y+z). */ - if (operand_equal_p (arg00, arg10, 0)) - { - tree powfn = TREE_OPERAND (CALL_EXPR_FN (arg0), 0); - tree arg = fold_build2_loc (loc, PLUS_EXPR, type, - arg01, arg11); - return build_call_expr_loc (loc, powfn, 2, arg00, arg); - } - } /* Canonicalize x*x as pow(x,2.0), which is expanded as x*x. */ if (!in_gimple_form @@ -10403,40 +10358,6 @@ fold_binary_loc (location_t loc, TREE_OPERAND (arg1, 0)); } - if (flag_unsafe_math_optimizations) - { - enum built_in_function fcode1 = builtin_mathfn_code (arg1); - - /* Optimize a/root(b/c) into a*root(c/b). */ - if (BUILTIN_CBRT_P (fcode1)) - { - tree rootarg = CALL_EXPR_ARG (arg1, 0); - - if (TREE_CODE (rootarg) == RDIV_EXPR) - { - tree rootfn = TREE_OPERAND (CALL_EXPR_FN (arg1), 0); - tree b = TREE_OPERAND (rootarg, 0); - tree c = TREE_OPERAND (rootarg, 1); - - tree tmp = fold_build2_loc (loc, RDIV_EXPR, type, c, b); - - tmp = build_call_expr_loc (loc, rootfn, 1, tmp); - return fold_build2_loc (loc, MULT_EXPR, type, arg0, tmp); - } - } - - /* Optimize x/expN(y) into x*expN(-y). */ - if (BUILTIN_EXPONENT_P (fcode1)) - { - tree expfn = TREE_OPERAND (CALL_EXPR_FN (arg1), 0); - tree arg = negate_expr (CALL_EXPR_ARG (arg1, 0)); - arg1 = build_call_expr_loc (loc, - expfn, 1, - fold_convert_loc (loc, type, arg)); - return fold_build2_loc (loc, MULT_EXPR, type, arg0, arg1); - } - - } return NULL_TREE; case TRUNC_DIV_EXPR: diff --git a/gcc/match.pd b/gcc/match.pd index eb0ba9d..289bc5c 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -2014,11 +2014,28 @@ along with GCC; see the file COPYING3. If not see (if (!HONOR_SNANS (type)) @0)) + /* Simplify sqrt(x) * sqrt(y) -> sqrt(x*y). */ + (for root (SQRT CBRT) + (simplify + (mult (root:s @0) (root:s @1)) + (root (mult @0 @1)))) + + /* Simplify pow(x,y) * pow(x,z) -> pow(x,y+z). */ + (simplify + (mult (POW:s @0 @1) (POW:s @0 @2)) + (POW @0 (plus @1 @2))) + /* Simplify pow(x,y) * pow(z,y) -> pow(x*z,y). */ (simplify (mult (POW:s @0 @1) (POW:s @2 @1)) (POW (mult @0 @2) @1)) + /* Simplify expN(x) * expN(y) -> expN(x+y). */ + (for exps (EXP EXP2 EXP10 POW10) + (simplify + (mult (exps:s @0) (exps:s @1)) + (exps (plus @0 @1)))) + /* Simplify tan(x) * cos(x) -> sin(x). */ (simplify (mult:c (TAN:s @0) (COS:s @0)) @@ -2061,9 +2078,16 @@ along with GCC; see the file COPYING3. If not see (POW @0 (minus @1 { build_one_cst (type); })))) /* Simplify a/root(b/c) into a*root(c/b). */ - (simplify - (rdiv @0 (SQRT:s (rdiv:s @1 @2))) - (mult @0 (SQRT (rdiv @2 @1)))) + (for root (SQRT CBRT) + (simplify + (rdiv @0 (root:s (rdiv:s @1 @2))) + (mult @0 (root (rdiv @2 @1))))) + + /* Simplify x/expN(y) into x*expN(-y). */ + (for exps (EXP EXP2 EXP10 POW10) + (simplify + (rdiv @0 (exps:s @1)) + (mult @0 (exps (negate @1))))) /* Simplify x / pow (y,z) -> x * pow(y,-z). */ (simplify