From patchwork Tue Oct 17 16:30:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wilco Dijkstra X-Patchwork-Id: 827119 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-464349-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="CzS5/WdM"; 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 3yGgfs4DXtz9t2Z for ; Wed, 18 Oct 2017 03:31:01 +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:cc:subject:date:message-id:content-type :content-transfer-encoding:mime-version; q=dns; s=default; b=lWk dB7n+qsr5e4Tlwu191zITDTv62M1WMVm6rLhq2cv8EGEeG0AHTHLcadDmf46V8vK shUGuOuVvCJD+8dCrOWjpiJ3zB7hMt/1TzgpvPIHv5JiSOatUz+G7AO8VeSpZ1kZ Qkk8E3xjD+IL6b3xzFZlcRkcjLlIziaJ/j+uEZ5c= 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 :content-transfer-encoding:mime-version; s=default; bh=Q++WAQmm/ uhkrwQRYBHk7PdTXvk=; b=CzS5/WdMX2Qw9YrGdDIEJQWKZnmT1/8G4NmLaWvvP s8Z7RD5ZHNfxVJrz5AWbRyYBT/YZnk7iMNvbtdPUe3O6SC2ZrLGWaSp4snb7RdTI 4LMz7H97ChvFqhO4+aEVz/84l+muN6xxkXuUTU1DtBMZT3OWJGyOeV1kAhyRdmVC ug= Received: (qmail 34474 invoked by alias); 17 Oct 2017 16:30:53 -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 34457 invoked by uid 89); 17 Oct 2017 16:30:52 -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=Hx-languages-length:1559 X-HELO: EUR03-DB5-obe.outbound.protection.outlook.com Received: from mail-eopbgr40053.outbound.protection.outlook.com (HELO EUR03-DB5-obe.outbound.protection.outlook.com) (40.107.4.53) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 17 Oct 2017 16:30:50 +0000 Received: from DB6PR0801MB2053.eurprd08.prod.outlook.com (10.168.86.22) by DB6PR0801MB2055.eurprd08.prod.outlook.com (10.168.86.136) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.77.7; Tue, 17 Oct 2017 16:30:47 +0000 Received: from DB6PR0801MB2053.eurprd08.prod.outlook.com ([fe80::4106:9fa0:b29a:d31e]) by DB6PR0801MB2053.eurprd08.prod.outlook.com ([fe80::4106:9fa0:b29a:d31e%18]) with mapi id 15.20.0077.022; Tue, 17 Oct 2017 16:30:47 +0000 From: Wilco Dijkstra To: GCC Patches CC: nd Subject: [PATCH] Canonicalize negates in division Date: Tue, 17 Oct 2017 16:30:47 +0000 Message-ID: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Wilco.Dijkstra@arm.com; x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DB6PR0801MB2055; 6:hMSolsJl7Y0epJ3mVQ8mx9uPFpiVEhgSu25LxCPnxN1GXZ5YnNXUtOg9pL53xJaHdE+9eo/NdUZt4m6AXpCCye1OrMalgNWODuwTpcef+4fGAwNyO8l8KJHgqWMiSMhv+DIPoWssBNZdpsYL7pws47QemSWfe8vIArfvhj4gtwuUvvUvAC3oIuuzNC+VdHNMViDydn0oe7aiuH8BQ09aOaxaFwhBrRLPr4HTAlJYsVnyIuYzTo+zlkNc2cHXnXuvXWR5hZ3Hh+7jJaG2yh0cXgpqp2vQZqJKuO2u6MLeu3QEsonjpesQHLJH6o89WfIWZTv/+RnBqnB7b+BC3SxNUw==; 5:qtMsufDWqPrNmABCb6Rs5DnyKdvcGFOcZLvIKyU3OpxwvnIdyUrx68ldel/Rl2wTD6te/5WwiahIrZTdonilrYzKT6a5Q/+XHBOBd53/fg6SaM8kjXhflOf2Bk9sm1kqD9VJ9eMRLnfjos5sRzHd7w2HjMo1HHrIbJfG688R43s=; 24:qS62JiYXGVQ+p9tV+i14bljDYCA7yU9+IMo6jo5O1yhQGwb27NlTjVVlQoUOxzsvxxxsGYXA0wpXBCqd2loNbqZY33OMWS5OW3VL+v5nzq4=; 7:5u8BbPouoX5BokeOyNomjDpKtA6QiKWNX79/rBqzXx2A3g6ORrlYQUdSdD0oGissikHj44Im3vpuxvCQ7T+sP5bWXUkUFBAbkpsnpvWgXNhFz4Ff4zf3vzCfiL0P2cYiCprrXaFM6rsnuMYtHN+col3NnOzHHcu+0ac5KY16AkhfFlHzEgeN6qvD6p6qrLWuemOP2XdSkRAyQXFhkAy1xYig9LedMoNYZjc2h89HMCM= x-ms-exchange-antispam-srfa-diagnostics: SSOS; x-ms-office365-filtering-correlation-id: 130f0784-f615-47c9-b7e0-08d5157c6c38 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(2017030254152)(48565401081)(2017052603199)(201703131423075)(201703031133081)(201702281549075); SRVR:DB6PR0801MB2055; x-ms-traffictypediagnostic: DB6PR0801MB2055: nodisclaimer: True x-exchange-antispam-report-test: UriScan:(180628864354917)(22074186197030)(183786458502308); x-microsoft-antispam-prvs: x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(2401047)(5005006)(8121501046)(10201501046)(3002001)(100000703101)(100105400095)(93006095)(93001095)(6055026)(6041248)(20161123564025)(20161123562025)(20161123558100)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123560025)(20161123555025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:DB6PR0801MB2055; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:DB6PR0801MB2055; x-forefront-prvs: 04631F8F77 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(6009001)(376002)(346002)(54534003)(377424004)(199003)(189002)(106356001)(8936002)(54356999)(50986999)(3846002)(6116002)(102836003)(101416001)(33656002)(4326008)(2906002)(3660700001)(8676002)(53936002)(6306002)(3280700002)(81166006)(68736007)(5250100002)(99286003)(7696004)(55016002)(5660300001)(6506006)(9686003)(81156014)(6436002)(66066001)(74316002)(25786009)(2900100001)(575784001)(4001150100001)(14454004)(189998001)(316002)(97736004)(7736002)(72206003)(86362001)(105586002)(478600001)(966005)(6916009)(305945005); DIR:OUT; SFP:1101; SCL:1; SRVR:DB6PR0801MB2055; H:DB6PR0801MB2053.eurprd08.prod.outlook.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-originalarrivaltime: 17 Oct 2017 16:30:47.7952 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0801MB2055 This patch implements some of the optimizations discussed in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71026. Canonicalize x / (- y) into (-x) / y. This moves negates out of the RHS of a division in order to allow further simplifications and potentially more reciprocal CSEs. OK for commit? ChangeLog 2017-10-17 Wilco Dijkstra Jackson Woodruff gcc/ PR 71026/tree-optimization * match.pd: Canonicalize negate in division. gcc/testsuite/ PR 71026/tree-optimization * gcc.dg/div_neg: New test. diff --git a/gcc/match.pd b/gcc/match.pd index cb48f079b4a310272e49cc319a1b3b0ff2023ba4..ade851f78fb9ac6ce03b752f63e03f3b5a19cda9 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -352,6 +352,11 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (rdiv @0 (rdiv:s @1 @2)) (mult (rdiv @0 @1) @2))) +/* Simplify x / (- y) to -x / y. */ +(simplify + (rdiv @0 (negate @1)) + (rdiv (negate @0) @1)) + (if (flag_unsafe_math_optimizations) /* Simplify (C / x op 0.0) to x op 0.0 for C > 0. */ (for op (lt le gt ge) diff --git a/gcc/testsuite/gcc.dg/div_neg.c b/gcc/testsuite/gcc.dg/div_neg.c new file mode 100644 index 0000000000000000000000000000000000000000..da499cda2fba6c943ec99c55cae2ea389f9e1cca --- /dev/null +++ b/gcc/testsuite/gcc.dg/div_neg.c @@ -0,0 +1,10 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +float +div_neg (float x, float y) +{ + return (-x / y) * (x / -y); +} + +/* { dg-final { scan-tree-dump-times " / " 1 "optimized" } } */