[1/2] middle-end: Simplify subtract where both arguments are being bitwise inverted.
Message ID | patch-15840-tamar@arm.com |
---|---|
State | Committed |
Headers |
Return-Path: <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4546A3856954 for <patchwork@sourceware.org>; Thu, 16 Jun 2022 11:09:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4546A3856954 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1655377791; bh=nCwQvYPEyKXJ+F6zStyucz2x6L/t/NCuKDdcTh08koY=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=atV/t4+LrtCokjH9Y56YArNt8tmRXqiz/q/OZ/GUGM5uRb/uUE4heYEn8wRlqnlGN RVnOkA+1EgWufUkHNgc5tGUr2bQEEtagC+Nim7cTIm8n42ts9+RlrRMTPt1kS9077v GFG/BXZuPd3sDc+Pa7yvXg73TE27XBIcDyK5DUCQ= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from EUR02-AM5-obe.outbound.protection.outlook.com (mail-eopbgr00058.outbound.protection.outlook.com [40.107.0.58]) by sourceware.org (Postfix) with ESMTPS id 308823856949 for <gcc-patches@gcc.gnu.org>; Thu, 16 Jun 2022 11:09:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 308823856949 ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=khKbCvBwloKkelhsUzv883SEpzMCErBf2Y8bubK9rYMSllgV52OXgowAmjyxQHfjHTUk5Tj2NuuvuDlTK4RJSQiCYu/W++qPbB/6wuISKqqqC8QSNGATgs9oiRJKzOjEKwYObyLWXcSwdlWXaMsKqy9KB5uympjg3qr6j1YaJuzJAK9BUAQvnVU3BL/DoF7BKf1YM6RgwhxfXmhtZua+SwFYWoOumtQ0I9rOuYBy2QSR9UY46bFmu2xdwuBAHiKOclos4ltqwuv4c3fLhxtGmtybD99hCqU0uiLcTR/eeEKdAJjm5QCGxl9mMBbxYiWuIzAKwDgJCh8U0AFGpXEzuQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=nCwQvYPEyKXJ+F6zStyucz2x6L/t/NCuKDdcTh08koY=; b=bI7QbXK/vQIE0D7Hsj0AfgTduBl8V9YEER7GFAj6yJRTG3QrtT2yqbLBmLWt9MlgoeHEESVWnIP5V8nXnFxUeSdoBq+2tWnvkMd171u/79Liw9OS64Gg/InzCo0a49XtS6uuG969ibttG/V+al4n7OVyxpnrQfkOqA7c9nn8H3toxhxrvLLOEULKk29ugC7r99aCzdlVk0Sng5IVrYAIF1J+WBo9zz9trzE1AueGb2pB/kT02tu2lCCtkOGpg6nxGF9vUOVZjPT5M8RAjN4UU6d4oARI3JUXb3bNtGSg9/Ou8Hnq+FO1ATi2dcQmrO6u8prM2jL1IKdLM6Tjf3H4mQ== ARC-Authentication-Results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=gcc.gnu.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com]) Received: from AM5PR0701CA0067.eurprd07.prod.outlook.com (2603:10a6:203:2::29) by DB9PR08MB6809.eurprd08.prod.outlook.com (2603:10a6:10:2ae::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5332.13; Thu, 16 Jun 2022 11:09:19 +0000 Received: from VE1EUR03FT053.eop-EUR03.prod.protection.outlook.com (2603:10a6:203:2:cafe::6a) by AM5PR0701CA0067.outlook.office365.com (2603:10a6:203:2::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.9 via Frontend Transport; Thu, 16 Jun 2022 11:09:19 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by VE1EUR03FT053.mail.protection.outlook.com (10.152.19.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5353.14 via Frontend Transport; Thu, 16 Jun 2022 11:09:18 +0000 Received: ("Tessian outbound e40990bc24d7:v120"); Thu, 16 Jun 2022 11:09:18 +0000 X-CR-MTA-TID: 64aa7808 Received: from f65efd3e5381.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 2EB0AD88-EC44-4B74-884D-CC48DCC12698.1; Thu, 16 Jun 2022 11:08:53 +0000 Received: from EUR04-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id f65efd3e5381.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Thu, 16 Jun 2022 11:08:53 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OkZDi5WYUomGRVfxKLQJNCd5Y8yldts+YpU+i89c1zxs7bleqoUfAdoHjp/Sv4Jcp4pAxE3SB39sSeoAaeA2lGU0HpddaqL8ZYp8rn/ImgOmP5wzXBEMafphCneHbIKUdn6rdsNqeMTVka5d3iOpwTfAE9OiSQVaqy6DIFxMg+plyoGUdYPLQz4rGmpaiqa4Lrl8nHJZNdIdpnamHyTcCL8kifCh7km7z/UvwKvjJ4CzJ/qsN9G9Yhb51BT+gjWfjO6kpAEp0kB21cVjvrK+MSKcYFL/5N0m87Dl176O8kb8NJ2As4OFJWImEydl3NlSBjog9ZHmQ8SlrpmSAUV93Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=nCwQvYPEyKXJ+F6zStyucz2x6L/t/NCuKDdcTh08koY=; b=D2rthKiZg9jzeaH74Y+Vink9RV624VCXtYxP+CpEMFpvvuwvKXF2X5/VmzgEY2givmnvsDQ3I5+57930eFNH+vp7XsKFHiPo5ZgaeavDQv6yHGP5to7+ETcbGL/fm+QP5Ot5hrrTGD6HNLTeacC6QRplPXOtpkxz9YswxNJtBQiSTyUHWX13J8bViZvEAPEHqk78Z8MqtzFp9zzctliSK6H8+sARmhsswOjHKyEnZsUKqMfSnkiDmu6KtnFaRarcEuCaL00PCbevPS/88LC5zpa1eI1O88wnwzZKV9POpC9bTAaxA3njlJIWhZCiJ130pUXPyUUmxaySWydaiDCf8A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from VI1PR08MB5325.eurprd08.prod.outlook.com (2603:10a6:803:13e::17) by DB9PR08MB6779.eurprd08.prod.outlook.com (2603:10a6:10:2a1::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5353.15; Thu, 16 Jun 2022 11:08:50 +0000 Received: from VI1PR08MB5325.eurprd08.prod.outlook.com ([fe80::54e5:594b:e5fd:a9b4]) by VI1PR08MB5325.eurprd08.prod.outlook.com ([fe80::54e5:594b:e5fd:a9b4%8]) with mapi id 15.20.5353.014; Thu, 16 Jun 2022 11:08:49 +0000 Date: Thu, 16 Jun 2022 12:08:47 +0100 To: gcc-patches@gcc.gnu.org Subject: [PATCH 1/2]middle-end: Simplify subtract where both arguments are being bitwise inverted. Message-ID: <patch-15840-tamar@arm.com> Content-Type: multipart/mixed; boundary="mY9BxVWv3Y4xjvJo" Content-Disposition: inline X-ClientProxiedBy: LO4P123CA0002.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:150::7) To VI1PR08MB5325.eurprd08.prod.outlook.com (2603:10a6:803:13e::17) MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: 6e41db09-34ac-4b7e-36ac-08da4f88a88c X-MS-TrafficTypeDiagnostic: DB9PR08MB6779:EE_|VE1EUR03FT053:EE_|DB9PR08MB6809:EE_ X-Microsoft-Antispam-PRVS: <DB9PR08MB68093D274FEF201B8F44723DFFAC9@DB9PR08MB6809.eurprd08.prod.outlook.com> x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: VxvSPynopVByKvUJxQSufE8BUgYki9XJcktuUtJyBeTfrjIhuceLV7Ls9fD7c/3hWyyJkwI75nwG+U1mXdwHe5bHVGxo3yWg4Q4dS6RJa6bN3TlX/lycx9kJQYBtRpS3QXp5qdAGJxMYv018kMj6xarHtjOEug9jJmwIHkqpuZLWuVwYJBisqnlpUM0Qp6npKmhCxXY7mqMlnsrTJa49t7H676oK9YADZCpDn55Tm8AJaVw9XP7P7xDEIk71/syFpC9rg4CdIOAwPhVjkzl580ErFvL9rP4JMogDJChV/JzNVzpVqPQg/wZiqJ9OuwxTIMSh/mmRm7Ig9O31Ga8QOCklSZjc9xDKwesX6Ie5ydczKn76Aa/bmAdrPLNY+oXhZPfZIYsKUipdMkDGEFIxPf1AcYQs1rPZ4Er7WaEBRFgkY/1z5n4py+fuhHg+yymjxE3Y4IJYMhsj2R6bT8CAZpyrTKXyASVg2brznt5v+GQpvB4Mj35MD+do2xaddPTRaHlDIJ9SazkDTbwAeqLyRZxATIMLZI6cW/yPgywMqpQZZRCAFEOq1y+U+w5OUX/rb2KGDKdvabEqraRs+UVu8c0Zpgp/MasZvTM5dpSvFh/4nZocTYZlaBpC8aUMIOWSUX/UjoBw7ozRHRDu86bQw1y/XrSFhsH7BfHboYLtrR+Ea/E2oyq/yA+5FR+A+UViiud43fiG0rpxRH8C1ilciVlB9Xo2bV8l1zF1E1JtDprtu3TW6QdOVJlHTt0F8dBUHt5CR7l4rZRvg7m7YkH1btj5IjO6BiRoqb/T/oOxXxJrmZCSEnehlvA2CnjjyOMQ X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1PR08MB5325.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230016)(4636009)(366004)(44144004)(33964004)(186003)(6506007)(26005)(4743002)(2616005)(6512007)(84970400001)(38100700002)(83380400001)(235185007)(4326008)(8676002)(44832011)(8936002)(86362001)(5660300002)(2906002)(6916009)(6486002)(316002)(66556008)(508600001)(66476007)(66946007)(36756003)(4216001)(2700100001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR08MB6779 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: VE1EUR03FT053.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 354040a6-51be-438b-6ef1-08da4f88970e X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 69iS+2mhE4RMmHEPqA3zHFJeiKee+FoYfwgil1aP4M4wdwPxI7BzcTMfWGqcRVdv180ob9Cl8qczh2dYZQZdJ7eHayH88+quNWMuY6Ghmle0QLZ223/+yprKnnr/dwkRH3gZCzFiUPAVfCYssVCK6S4IesYZ3uDlxrWc7ItMSRc640vbFvRtXvb3Kr/Mz6VKRgDbsGXoo8RTdYHqV+NPDrKl9gn2r2VrkIRryS38N2icuXGN0bKMQpKg2Sa0J8GoeZr2sUSy1bPYgUSzoLM9t1BzmmO8XeyCbWfmgcdQiJxgCJcai/TZcmjKxjcTfWK51qeQba8bQ7dCMIIOnaxBlE5HKLC37Php99lAYVpKDcZZ1AMB/CwGxY/QQ9ymEQp3ySgILiHxBnCh/BQ8RCGDJgTC4VzI0NkTbgebKQuMHM3qV9IhQpLcAj6Fxk4W0Z0H8/CFH3spZhYduwkpfAdO9ZJanpZOmlNUu3xDQUuWxsC/oDqzA97y4h6DHhEMOo0kg+1yqF1W1Et7zxZToJ13AsKEfXpu8bKIq8Pfv7enBc4m7DHU6EbPWUQQKIoTsMlkrwx3xSMc2A74s/XhaLrgLafuyUrFuHCH/PwU30jdTNzDAVWqtNyf4L6YHgq3RVyAvjqdH+jH5a1zbkAD+DGjghqRSeCrMCHDPJ6vUPt2Cqz3mlqPSLIxXC2mFZ7OQ89n7yAlZZLP1Bft5eZJeb6EhqoLAQLYBOkdt4TlB2eBOHYVFVibTqLnP+4o7D984etRQmz3INERoMuPjk8i4nD8Wnw6ijnjGgfCBFFxUa6hVm5fTMnwG02Acrh5FGyXoldy X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(13230016)(4636009)(40470700004)(46966006)(36840700001)(84970400001)(26005)(6512007)(36860700001)(86362001)(4743002)(81166007)(336012)(6506007)(47076005)(33964004)(2616005)(40460700003)(107886003)(186003)(70586007)(36756003)(4326008)(8936002)(6916009)(8676002)(5660300002)(2906002)(316002)(235185007)(70206006)(508600001)(6486002)(44832011)(82310400005)(44144004)(356005)(83380400001)(4216001)(2700100001); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jun 2022 11:09:18.7160 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6e41db09-34ac-4b7e-36ac-08da4f88a88c X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: VE1EUR03FT053.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR08MB6809 X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FORGED_SPF_HELO, GIT_PATCH_0, KAM_DMARC_NONE, KAM_LOTSOFHASH, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> From: Tamar Christina via Gcc-patches <gcc-patches@gcc.gnu.org> Reply-To: Tamar Christina <tamar.christina@arm.com> Cc: nd@arm.com, rguenther@suse.de Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> |
Series |
[1/2] middle-end: Simplify subtract where both arguments are being bitwise inverted.
|
|
Commit Message
Tamar Christina
June 16, 2022, 11:08 a.m. UTC
Hi All, This adds a match.pd rule that drops the bitwwise nots when both arguments to a subtract is inverted. i.e. for: float g(float a, float b) { return ~(int)a - ~(int)b; } we instead generate float g(float a, float b) { return (int)a - (int)b; } We already do a limited version of this from the fold_binary fold functions but this makes a more general version in match.pd that applies more often. Bootstrapped Regtested on aarch64-none-linux-gnu and no issues. Ok for master? Thanks, Tamar gcc/ChangeLog: * match.pd: New bit_not rule. gcc/testsuite/ChangeLog: * gcc.dg/subnot.c: New test. --- inline copy of patch -- diff --git a/gcc/match.pd b/gcc/match.pd index a59b6778f661cf9121dd3503f43472871e4da445..51b0a1b562409af535e53828a10c30b8a3e1ae2e 100644 -- diff --git a/gcc/match.pd b/gcc/match.pd index a59b6778f661cf9121dd3503f43472871e4da445..51b0a1b562409af535e53828a10c30b8a3e1ae2e 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -1258,6 +1258,10 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (simplify (bit_not (plus:c (bit_not @0) @1)) (minus @0 @1)) +/* (~X - ~Y) -> X - Y. */ +(simplify + (minus (bit_not @0) (bit_not @1)) + (minus @0 @1)) /* ~(X - Y) -> ~X + Y. */ (simplify diff --git a/gcc/testsuite/gcc.dg/subnot.c b/gcc/testsuite/gcc.dg/subnot.c new file mode 100644 index 0000000000000000000000000000000000000000..d621bacd27bd3d19a010e4c9f831aa77d28bd02d --- /dev/null +++ b/gcc/testsuite/gcc.dg/subnot.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-O -fdump-tree-optimized" } */ + +float g(float a, float b) +{ + return ~(int)a - ~(int)b; +} + +/* { dg-final { scan-tree-dump-not "~" "optimized" } } */
Comments
On Thu, Jun 16, 2022 at 1:10 PM Tamar Christina via Gcc-patches <gcc-patches@gcc.gnu.org> wrote: > > Hi All, > > This adds a match.pd rule that drops the bitwwise nots when both arguments to a > subtract is inverted. i.e. for: > > float g(float a, float b) > { > return ~(int)a - ~(int)b; > } > > we instead generate > > float g(float a, float b) > { > return (int)a - (int)b; > } > > We already do a limited version of this from the fold_binary fold functions but > this makes a more general version in match.pd that applies more often. > > Bootstrapped Regtested on aarch64-none-linux-gnu and no issues. > > Ok for master? > > Thanks, > Tamar > > gcc/ChangeLog: > > * match.pd: New bit_not rule. > > gcc/testsuite/ChangeLog: > > * gcc.dg/subnot.c: New test. > > --- inline copy of patch -- > diff --git a/gcc/match.pd b/gcc/match.pd > index a59b6778f661cf9121dd3503f43472871e4da445..51b0a1b562409af535e53828a10c30b8a3e1ae2e 100644 > --- a/gcc/match.pd > +++ b/gcc/match.pd > @@ -1258,6 +1258,10 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) > (simplify > (bit_not (plus:c (bit_not @0) @1)) > (minus @0 @1)) > +/* (~X - ~Y) -> X - Y. */ > +(simplify > + (minus (bit_not @0) (bit_not @1)) > + (minus @0 @1)) It doesn't seem correct. (gdb) p/x ~-1 - ~0x80000000 $3 = 0x80000001 (gdb) p/x -1 - 0x80000000 $4 = 0x7fffffff where I was looking for a case exposing undefined integer overflow. Richard. > > /* ~(X - Y) -> ~X + Y. */ > (simplify > diff --git a/gcc/testsuite/gcc.dg/subnot.c b/gcc/testsuite/gcc.dg/subnot.c > new file mode 100644 > index 0000000000000000000000000000000000000000..d621bacd27bd3d19a010e4c9f831aa77d28bd02d > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/subnot.c > @@ -0,0 +1,9 @@ > +/* { dg-do compile } */ > +/* { dg-options "-O -fdump-tree-optimized" } */ > + > +float g(float a, float b) > +{ > + return ~(int)a - ~(int)b; > +} > + > +/* { dg-final { scan-tree-dump-not "~" "optimized" } } */ > > > > > --
Richard Biener via Gcc-patches <gcc-patches@gcc.gnu.org> writes: > On Thu, Jun 16, 2022 at 1:10 PM Tamar Christina via Gcc-patches > <gcc-patches@gcc.gnu.org> wrote: >> >> Hi All, >> >> This adds a match.pd rule that drops the bitwwise nots when both arguments to a >> subtract is inverted. i.e. for: >> >> float g(float a, float b) >> { >> return ~(int)a - ~(int)b; >> } >> >> we instead generate >> >> float g(float a, float b) >> { >> return (int)a - (int)b; >> } >> >> We already do a limited version of this from the fold_binary fold functions but >> this makes a more general version in match.pd that applies more often. >> >> Bootstrapped Regtested on aarch64-none-linux-gnu and no issues. >> >> Ok for master? >> >> Thanks, >> Tamar >> >> gcc/ChangeLog: >> >> * match.pd: New bit_not rule. >> >> gcc/testsuite/ChangeLog: >> >> * gcc.dg/subnot.c: New test. >> >> --- inline copy of patch -- >> diff --git a/gcc/match.pd b/gcc/match.pd >> index a59b6778f661cf9121dd3503f43472871e4da445..51b0a1b562409af535e53828a10c30b8a3e1ae2e 100644 >> --- a/gcc/match.pd >> +++ b/gcc/match.pd >> @@ -1258,6 +1258,10 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) >> (simplify >> (bit_not (plus:c (bit_not @0) @1)) >> (minus @0 @1)) >> +/* (~X - ~Y) -> X - Y. */ >> +(simplify >> + (minus (bit_not @0) (bit_not @1)) >> + (minus @0 @1)) > > It doesn't seem correct. > > (gdb) p/x ~-1 - ~0x80000000 > $3 = 0x80000001 > (gdb) p/x -1 - 0x80000000 > $4 = 0x7fffffff > > where I was looking for a case exposing undefined integer overflow. Yeah, shouldn't it be folding to (minus @1 @0) instead? ~X = (-X - 1) -Y = (-Y - 1) so: ~X - ~Y = (-X - 1) - (-Y - 1) = -X - 1 + Y + 1 = Y - X Richard > Richard. > >> >> /* ~(X - Y) -> ~X + Y. */ >> (simplify >> diff --git a/gcc/testsuite/gcc.dg/subnot.c b/gcc/testsuite/gcc.dg/subnot.c >> new file mode 100644 >> index 0000000000000000000000000000000000000000..d621bacd27bd3d19a010e4c9f831aa77d28bd02d >> --- /dev/null >> +++ b/gcc/testsuite/gcc.dg/subnot.c >> @@ -0,0 +1,9 @@ >> +/* { dg-do compile } */ >> +/* { dg-options "-O -fdump-tree-optimized" } */ >> + >> +float g(float a, float b) >> +{ >> + return ~(int)a - ~(int)b; >> +} >> + >> +/* { dg-final { scan-tree-dump-not "~" "optimized" } } */ >> >> >> >> >> --
> -----Original Message----- > From: Richard Sandiford <richard.sandiford@arm.com> > Sent: Monday, June 20, 2022 9:19 AM > To: Richard Biener via Gcc-patches <gcc-patches@gcc.gnu.org> > Cc: Tamar Christina <Tamar.Christina@arm.com>; Richard Biener > <richard.guenther@gmail.com>; Richard Guenther <rguenther@suse.de>; > nd <nd@arm.com> > Subject: Re: [PATCH 1/2]middle-end: Simplify subtract where both > arguments are being bitwise inverted. > > Richard Biener via Gcc-patches <gcc-patches@gcc.gnu.org> writes: > > On Thu, Jun 16, 2022 at 1:10 PM Tamar Christina via Gcc-patches > > <gcc-patches@gcc.gnu.org> wrote: > >> > >> Hi All, > >> > >> This adds a match.pd rule that drops the bitwwise nots when both > >> arguments to a subtract is inverted. i.e. for: > >> > >> float g(float a, float b) > >> { > >> return ~(int)a - ~(int)b; > >> } > >> > >> we instead generate > >> > >> float g(float a, float b) > >> { > >> return (int)a - (int)b; > >> } > >> > >> We already do a limited version of this from the fold_binary fold > >> functions but this makes a more general version in match.pd that applies > more often. > >> > >> Bootstrapped Regtested on aarch64-none-linux-gnu and no issues. > >> > >> Ok for master? > >> > >> Thanks, > >> Tamar > >> > >> gcc/ChangeLog: > >> > >> * match.pd: New bit_not rule. > >> > >> gcc/testsuite/ChangeLog: > >> > >> * gcc.dg/subnot.c: New test. > >> > >> --- inline copy of patch -- > >> diff --git a/gcc/match.pd b/gcc/match.pd index > >> > a59b6778f661cf9121dd3503f43472871e4da445..51b0a1b562409af535e53828a1 > 0 > >> c30b8a3e1ae2e 100644 > >> --- a/gcc/match.pd > >> +++ b/gcc/match.pd > >> @@ -1258,6 +1258,10 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) > >> (simplify > >> (bit_not (plus:c (bit_not @0) @1)) > >> (minus @0 @1)) > >> +/* (~X - ~Y) -> X - Y. */ > >> +(simplify > >> + (minus (bit_not @0) (bit_not @1)) > >> + (minus @0 @1)) > > > > It doesn't seem correct. > > > > (gdb) p/x ~-1 - ~0x80000000 > > $3 = 0x80000001 > > (gdb) p/x -1 - 0x80000000 > > $4 = 0x7fffffff > > > > where I was looking for a case exposing undefined integer overflow. > > Yeah, shouldn't it be folding to (minus @1 @0) instead? > > ~X = (-X - 1) > -Y = (-Y - 1) > > so: > > ~X - ~Y = (-X - 1) - (-Y - 1) > = -X - 1 + Y + 1 > = Y - X > You're right, sorry, I should have paid more attention when I wrote the patch. Tamar > Richard > > > > Richard. > > > >> > >> /* ~(X - Y) -> ~X + Y. */ > >> (simplify > >> diff --git a/gcc/testsuite/gcc.dg/subnot.c > >> b/gcc/testsuite/gcc.dg/subnot.c new file mode 100644 index > >> > 0000000000000000000000000000000000000000..d621bacd27bd3d19a010e4c9f > 83 > >> 1aa77d28bd02d > >> --- /dev/null > >> +++ b/gcc/testsuite/gcc.dg/subnot.c > >> @@ -0,0 +1,9 @@ > >> +/* { dg-do compile } */ > >> +/* { dg-options "-O -fdump-tree-optimized" } */ > >> + > >> +float g(float a, float b) > >> +{ > >> + return ~(int)a - ~(int)b; > >> +} > >> + > >> +/* { dg-final { scan-tree-dump-not "~" "optimized" } } */ > >> > >> > >> > >> > >> --
On Mon, Jun 20, 2022 at 10:49 AM Tamar Christina <Tamar.Christina@arm.com> wrote: > > > -----Original Message----- > > From: Richard Sandiford <richard.sandiford@arm.com> > > Sent: Monday, June 20, 2022 9:19 AM > > To: Richard Biener via Gcc-patches <gcc-patches@gcc.gnu.org> > > Cc: Tamar Christina <Tamar.Christina@arm.com>; Richard Biener > > <richard.guenther@gmail.com>; Richard Guenther <rguenther@suse.de>; > > nd <nd@arm.com> > > Subject: Re: [PATCH 1/2]middle-end: Simplify subtract where both > > arguments are being bitwise inverted. > > > > Richard Biener via Gcc-patches <gcc-patches@gcc.gnu.org> writes: > > > On Thu, Jun 16, 2022 at 1:10 PM Tamar Christina via Gcc-patches > > > <gcc-patches@gcc.gnu.org> wrote: > > >> > > >> Hi All, > > >> > > >> This adds a match.pd rule that drops the bitwwise nots when both > > >> arguments to a subtract is inverted. i.e. for: > > >> > > >> float g(float a, float b) > > >> { > > >> return ~(int)a - ~(int)b; > > >> } > > >> > > >> we instead generate > > >> > > >> float g(float a, float b) > > >> { > > >> return (int)a - (int)b; > > >> } > > >> > > >> We already do a limited version of this from the fold_binary fold > > >> functions but this makes a more general version in match.pd that applies > > more often. > > >> > > >> Bootstrapped Regtested on aarch64-none-linux-gnu and no issues. > > >> > > >> Ok for master? > > >> > > >> Thanks, > > >> Tamar > > >> > > >> gcc/ChangeLog: > > >> > > >> * match.pd: New bit_not rule. > > >> > > >> gcc/testsuite/ChangeLog: > > >> > > >> * gcc.dg/subnot.c: New test. > > >> > > >> --- inline copy of patch -- > > >> diff --git a/gcc/match.pd b/gcc/match.pd index > > >> > > a59b6778f661cf9121dd3503f43472871e4da445..51b0a1b562409af535e53828a1 > > 0 > > >> c30b8a3e1ae2e 100644 > > >> --- a/gcc/match.pd > > >> +++ b/gcc/match.pd > > >> @@ -1258,6 +1258,10 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) > > >> (simplify > > >> (bit_not (plus:c (bit_not @0) @1)) > > >> (minus @0 @1)) > > >> +/* (~X - ~Y) -> X - Y. */ > > >> +(simplify > > >> + (minus (bit_not @0) (bit_not @1)) > > >> + (minus @0 @1)) > > > > > > It doesn't seem correct. > > > > > > (gdb) p/x ~-1 - ~0x80000000 > > > $3 = 0x80000001 > > > (gdb) p/x -1 - 0x80000000 > > > $4 = 0x7fffffff > > > > > > where I was looking for a case exposing undefined integer overflow. > > > > Yeah, shouldn't it be folding to (minus @1 @0) instead? > > > > ~X = (-X - 1) > > -Y = (-Y - 1) > > > > so: > > > > ~X - ~Y = (-X - 1) - (-Y - 1) > > = -X - 1 + Y + 1 > > = Y - X > > > > You're right, sorry, I should have paid more attention when I wrote the patch. You still need to watch out for undefined overflow cases in the result that were well-defined in the original expression I think. Richard. > Tamar > > Richard > > > > > > > Richard. > > > > > >> > > >> /* ~(X - Y) -> ~X + Y. */ > > >> (simplify > > >> diff --git a/gcc/testsuite/gcc.dg/subnot.c > > >> b/gcc/testsuite/gcc.dg/subnot.c new file mode 100644 index > > >> > > 0000000000000000000000000000000000000000..d621bacd27bd3d19a010e4c9f > > 83 > > >> 1aa77d28bd02d > > >> --- /dev/null > > >> +++ b/gcc/testsuite/gcc.dg/subnot.c > > >> @@ -0,0 +1,9 @@ > > >> +/* { dg-do compile } */ > > >> +/* { dg-options "-O -fdump-tree-optimized" } */ > > >> + > > >> +float g(float a, float b) > > >> +{ > > >> + return ~(int)a - ~(int)b; > > >> +} > > >> + > > >> +/* { dg-final { scan-tree-dump-not "~" "optimized" } } */ > > >> > > >> > > >> > > >> > > >> --
> -----Original Message----- > From: Richard Biener <richard.guenther@gmail.com> > Sent: Tuesday, June 21, 2022 8:43 AM > To: Tamar Christina <Tamar.Christina@arm.com> > Cc: Richard Sandiford <Richard.Sandiford@arm.com>; Richard Biener via Gcc- > patches <gcc-patches@gcc.gnu.org>; Richard Guenther > <rguenther@suse.de>; nd <nd@arm.com> > Subject: Re: [PATCH 1/2]middle-end: Simplify subtract where both > arguments are being bitwise inverted. > > On Mon, Jun 20, 2022 at 10:49 AM Tamar Christina > <Tamar.Christina@arm.com> wrote: > > > > > -----Original Message----- > > > From: Richard Sandiford <richard.sandiford@arm.com> > > > Sent: Monday, June 20, 2022 9:19 AM > > > To: Richard Biener via Gcc-patches <gcc-patches@gcc.gnu.org> > > > Cc: Tamar Christina <Tamar.Christina@arm.com>; Richard Biener > > > <richard.guenther@gmail.com>; Richard Guenther > <rguenther@suse.de>; > > > nd <nd@arm.com> > > > Subject: Re: [PATCH 1/2]middle-end: Simplify subtract where both > > > arguments are being bitwise inverted. > > > > > > Richard Biener via Gcc-patches <gcc-patches@gcc.gnu.org> writes: > > > > On Thu, Jun 16, 2022 at 1:10 PM Tamar Christina via Gcc-patches > > > > <gcc-patches@gcc.gnu.org> wrote: > > > >> > > > >> Hi All, > > > >> > > > >> This adds a match.pd rule that drops the bitwwise nots when both > > > >> arguments to a subtract is inverted. i.e. for: > > > >> > > > >> float g(float a, float b) > > > >> { > > > >> return ~(int)a - ~(int)b; > > > >> } > > > >> > > > >> we instead generate > > > >> > > > >> float g(float a, float b) > > > >> { > > > >> return (int)a - (int)b; > > > >> } > > > >> > > > >> We already do a limited version of this from the fold_binary fold > > > >> functions but this makes a more general version in match.pd that > > > >> applies > > > more often. > > > >> > > > >> Bootstrapped Regtested on aarch64-none-linux-gnu and no issues. > > > >> > > > >> Ok for master? > > > >> > > > >> Thanks, > > > >> Tamar > > > >> > > > >> gcc/ChangeLog: > > > >> > > > >> * match.pd: New bit_not rule. > > > >> > > > >> gcc/testsuite/ChangeLog: > > > >> > > > >> * gcc.dg/subnot.c: New test. > > > >> > > > >> --- inline copy of patch -- > > > >> diff --git a/gcc/match.pd b/gcc/match.pd index > > > >> > > > > a59b6778f661cf9121dd3503f43472871e4da445..51b0a1b562409af535e53828a1 > > > 0 > > > >> c30b8a3e1ae2e 100644 > > > >> --- a/gcc/match.pd > > > >> +++ b/gcc/match.pd > > > >> @@ -1258,6 +1258,10 @@ DEFINE_INT_AND_FLOAT_ROUND_FN > (RINT) > > > >> (simplify > > > >> (bit_not (plus:c (bit_not @0) @1)) > > > >> (minus @0 @1)) > > > >> +/* (~X - ~Y) -> X - Y. */ > > > >> +(simplify > > > >> + (minus (bit_not @0) (bit_not @1)) (minus @0 @1)) > > > > > > > > It doesn't seem correct. > > > > > > > > (gdb) p/x ~-1 - ~0x80000000 > > > > $3 = 0x80000001 > > > > (gdb) p/x -1 - 0x80000000 > > > > $4 = 0x7fffffff > > > > > > > > where I was looking for a case exposing undefined integer overflow. > > > > > > Yeah, shouldn't it be folding to (minus @1 @0) instead? > > > > > > ~X = (-X - 1) > > > -Y = (-Y - 1) > > > > > > so: > > > > > > ~X - ~Y = (-X - 1) - (-Y - 1) > > > = -X - 1 + Y + 1 > > > = Y - X > > > > > > > You're right, sorry, I should have paid more attention when I wrote the > patch. > > You still need to watch out for undefined overflow cases in the result that > were well-defined in the original expression I think. The only special thing we do for signed numbers if to do the subtract as unsigned. As I mentioned before GCC already does this transformation as part of the fold machinery, but that only only happens when a very simple tree is matched and only when single use. i.e. https://godbolt.org/z/EWsdhfrKj I'm only attempting to make it apply more generally as the result is always beneficial. I've respun the patch to the same as we already do. Bootstrapped Regtested on aarch64-none-linux-gnu and no issues. Ok for master? Thanks, Tamar gcc/ChangeLog: * match.pd: New bit_not rule. gcc/testsuite/ChangeLog: * gcc.dg/subnot.c: New test. --- inline copy of patch --- diff --git a/gcc/match.pd b/gcc/match.pd index 330c1db0c8e12b0fb010b1958729444672403866..00b3e07b2a5216b19ed58500923680d83c67d8cf 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -1308,6 +1308,11 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (simplify (bit_not (plus:c (bit_not @0) @1)) (minus @0 @1)) +/* (~X - ~Y) -> Y - X. */ +(simplify + (minus (bit_not @0) (bit_not @1)) + (with { tree utype = unsigned_type_for (type); } + (convert (minus (convert:utype @1) (convert:utype @0))))) /* ~(X - Y) -> ~X + Y. */ (simplify diff --git a/gcc/testsuite/gcc.dg/subnot.c b/gcc/testsuite/gcc.dg/subnot.c new file mode 100644 index 0000000000000000000000000000000000000000..d621bacd27bd3d19a010e4c9f831aa77d28bd02d --- /dev/null +++ b/gcc/testsuite/gcc.dg/subnot.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-O -fdump-tree-optimized" } */ + +float g(float a, float b) +{ + return ~(int)a - ~(int)b; +} + +/* { dg-final { scan-tree-dump-not "~" "optimized" } } */
On Wed, 3 Aug 2022, Tamar Christina wrote: > > -----Original Message----- > > From: Richard Biener <richard.guenther@gmail.com> > > Sent: Tuesday, June 21, 2022 8:43 AM > > To: Tamar Christina <Tamar.Christina@arm.com> > > Cc: Richard Sandiford <Richard.Sandiford@arm.com>; Richard Biener via Gcc- > > patches <gcc-patches@gcc.gnu.org>; Richard Guenther > > <rguenther@suse.de>; nd <nd@arm.com> > > Subject: Re: [PATCH 1/2]middle-end: Simplify subtract where both > > arguments are being bitwise inverted. > > > > On Mon, Jun 20, 2022 at 10:49 AM Tamar Christina > > <Tamar.Christina@arm.com> wrote: > > > > > > > -----Original Message----- > > > > From: Richard Sandiford <richard.sandiford@arm.com> > > > > Sent: Monday, June 20, 2022 9:19 AM > > > > To: Richard Biener via Gcc-patches <gcc-patches@gcc.gnu.org> > > > > Cc: Tamar Christina <Tamar.Christina@arm.com>; Richard Biener > > > > <richard.guenther@gmail.com>; Richard Guenther > > <rguenther@suse.de>; > > > > nd <nd@arm.com> > > > > Subject: Re: [PATCH 1/2]middle-end: Simplify subtract where both > > > > arguments are being bitwise inverted. > > > > > > > > Richard Biener via Gcc-patches <gcc-patches@gcc.gnu.org> writes: > > > > > On Thu, Jun 16, 2022 at 1:10 PM Tamar Christina via Gcc-patches > > > > > <gcc-patches@gcc.gnu.org> wrote: > > > > >> > > > > >> Hi All, > > > > >> > > > > >> This adds a match.pd rule that drops the bitwwise nots when both > > > > >> arguments to a subtract is inverted. i.e. for: > > > > >> > > > > >> float g(float a, float b) > > > > >> { > > > > >> return ~(int)a - ~(int)b; > > > > >> } > > > > >> > > > > >> we instead generate > > > > >> > > > > >> float g(float a, float b) > > > > >> { > > > > >> return (int)a - (int)b; > > > > >> } > > > > >> > > > > >> We already do a limited version of this from the fold_binary fold > > > > >> functions but this makes a more general version in match.pd that > > > > >> applies > > > > more often. > > > > >> > > > > >> Bootstrapped Regtested on aarch64-none-linux-gnu and no issues. > > > > >> > > > > >> Ok for master? > > > > >> > > > > >> Thanks, > > > > >> Tamar > > > > >> > > > > >> gcc/ChangeLog: > > > > >> > > > > >> * match.pd: New bit_not rule. > > > > >> > > > > >> gcc/testsuite/ChangeLog: > > > > >> > > > > >> * gcc.dg/subnot.c: New test. > > > > >> > > > > >> --- inline copy of patch -- > > > > >> diff --git a/gcc/match.pd b/gcc/match.pd index > > > > >> > > > > > > a59b6778f661cf9121dd3503f43472871e4da445..51b0a1b562409af535e53828a1 > > > > 0 > > > > >> c30b8a3e1ae2e 100644 > > > > >> --- a/gcc/match.pd > > > > >> +++ b/gcc/match.pd > > > > >> @@ -1258,6 +1258,10 @@ DEFINE_INT_AND_FLOAT_ROUND_FN > > (RINT) > > > > >> (simplify > > > > >> (bit_not (plus:c (bit_not @0) @1)) > > > > >> (minus @0 @1)) > > > > >> +/* (~X - ~Y) -> X - Y. */ > > > > >> +(simplify > > > > >> + (minus (bit_not @0) (bit_not @1)) (minus @0 @1)) > > > > > > > > > > It doesn't seem correct. > > > > > > > > > > (gdb) p/x ~-1 - ~0x80000000 > > > > > $3 = 0x80000001 > > > > > (gdb) p/x -1 - 0x80000000 > > > > > $4 = 0x7fffffff > > > > > > > > > > where I was looking for a case exposing undefined integer overflow. > > > > > > > > Yeah, shouldn't it be folding to (minus @1 @0) instead? > > > > > > > > ~X = (-X - 1) > > > > -Y = (-Y - 1) > > > > > > > > so: > > > > > > > > ~X - ~Y = (-X - 1) - (-Y - 1) > > > > = -X - 1 + Y + 1 > > > > = Y - X > > > > > > > > > > You're right, sorry, I should have paid more attention when I wrote the > > patch. > > > > You still need to watch out for undefined overflow cases in the result that > > were well-defined in the original expression I think. > > The only special thing we do for signed numbers if to do the subtract as unsigned. As I mentioned > before GCC already does this transformation as part of the fold machinery, but that only only happens > when a very simple tree is matched and only when single use. i.e. https://godbolt.org/z/EWsdhfrKj > > I'm only attempting to make it apply more generally as the result is always beneficial. > > I've respun the patch to the same as we already do. > > Bootstrapped Regtested on aarch64-none-linux-gnu and no issues. > > Ok for master? OK. > Thanks, > Tamar > > gcc/ChangeLog: > > * match.pd: New bit_not rule. > > gcc/testsuite/ChangeLog: > > * gcc.dg/subnot.c: New test. > > --- inline copy of patch --- > > diff --git a/gcc/match.pd b/gcc/match.pd > index 330c1db0c8e12b0fb010b1958729444672403866..00b3e07b2a5216b19ed58500923680d83c67d8cf 100644 > --- a/gcc/match.pd > +++ b/gcc/match.pd > @@ -1308,6 +1308,11 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) > (simplify > (bit_not (plus:c (bit_not @0) @1)) > (minus @0 @1)) > +/* (~X - ~Y) -> Y - X. */ > +(simplify > + (minus (bit_not @0) (bit_not @1)) > + (with { tree utype = unsigned_type_for (type); } > + (convert (minus (convert:utype @1) (convert:utype @0))))) > > /* ~(X - Y) -> ~X + Y. */ > (simplify > diff --git a/gcc/testsuite/gcc.dg/subnot.c b/gcc/testsuite/gcc.dg/subnot.c > new file mode 100644 > index 0000000000000000000000000000000000000000..d621bacd27bd3d19a010e4c9f831aa77d28bd02d > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/subnot.c > @@ -0,0 +1,9 @@ > +/* { dg-do compile } */ > +/* { dg-options "-O -fdump-tree-optimized" } */ > + > +float g(float a, float b) > +{ > + return ~(int)a - ~(int)b; > +} > + > +/* { dg-final { scan-tree-dump-not "~" "optimized" } } */ >
--- a/gcc/match.pd +++ b/gcc/match.pd @@ -1258,6 +1258,10 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (simplify (bit_not (plus:c (bit_not @0) @1)) (minus @0 @1)) +/* (~X - ~Y) -> X - Y. */ +(simplify + (minus (bit_not @0) (bit_not @1)) + (minus @0 @1)) /* ~(X - Y) -> ~X + Y. */ (simplify diff --git a/gcc/testsuite/gcc.dg/subnot.c b/gcc/testsuite/gcc.dg/subnot.c new file mode 100644 index 0000000000000000000000000000000000000000..d621bacd27bd3d19a010e4c9f831aa77d28bd02d --- /dev/null +++ b/gcc/testsuite/gcc.dg/subnot.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-O -fdump-tree-optimized" } */ + +float g(float a, float b) +{ + return ~(int)a - ~(int)b; +} + +/* { dg-final { scan-tree-dump-not "~" "optimized" } } */