From patchwork Fri Oct 15 11:08:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tamar Christina X-Patchwork-Id: 46269 Return-Path: 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 39F533857815 for ; Fri, 15 Oct 2021 11:09:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 39F533857815 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1634296163; bh=z7BxL3uONvOMmv/oNTkzWWgHQoMcJqaVkMFiKeXdFzs=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=UPGQKV82BZ7AymXl0b4Q3FuxVFkKKq3r86Twm2nZwnnPTDrbiFLwyRdYoYOhv75pc +Nv4x9Fhi6emybrG8xrIB74U/T8dHkE9GR5/+AKJ9dgpA7Vf3Tc/8UFFKOn6HJAdSl HI2CbUndq26+HePuQ5qGNY+MpHO3MQYfIw51kUGg= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-eopbgr130087.outbound.protection.outlook.com [40.107.13.87]) by sourceware.org (Postfix) with ESMTPS id 47C70385802D for ; Fri, 15 Oct 2021 11:08:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 47C70385802D Received: from AM6P194CA0068.EURP194.PROD.OUTLOOK.COM (2603:10a6:209:84::45) by DB6PR0802MB2391.eurprd08.prod.outlook.com (2603:10a6:4:a0::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.25; Fri, 15 Oct 2021 11:08:37 +0000 Received: from AM5EUR03FT014.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:84:cafe::45) by AM6P194CA0068.outlook.office365.com (2603:10a6:209:84::45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.15 via Frontend Transport; Fri, 15 Oct 2021 11:08:37 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; gcc.gnu.org; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;gcc.gnu.org; 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; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM5EUR03FT014.mail.protection.outlook.com (10.152.16.130) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.15 via Frontend Transport; Fri, 15 Oct 2021 11:08:37 +0000 Received: ("Tessian outbound d5def7722ff7:v103"); Fri, 15 Oct 2021 11:08:37 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 5bb4f91b9ca725b6 X-CR-MTA-TID: 64aa7808 Received: from 988a6e2d1264.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 0949F4FD-A38E-4CBC-B0F1-0CAAA3C67D0A.1; Fri, 15 Oct 2021 11:08:30 +0000 Received: from EUR04-HE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 988a6e2d1264.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 15 Oct 2021 11:08:30 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=naQj8pek2eIKA4a0/x5oqd3WxoX2ddTMPRY9CyUztZ9AnWvFDaYYaJWjzR49HkYkJxA7HSD/GBc2Lx1XtrKCWXc6rVA7TxoFHw7XfrHzYw+y/Z00j/0svHTMwg6OAOzKGdMI1XdUEtYlN/zRMMB5WAZTqfe/U347xnRvvVHQF/1gynkonmpz605YPNJOVIcX3JxiP4eBC7Wf5rgYPziBNapdwa6DgZpQEW/SoCfQUlMuCB8zwsGieyT+iHWPTO7LMWHI1QYtZwHAxg2dWy7MF5RfYXMoBuGpfgOVpF6bdlbMsu1TAsYq3wuatQIGj8ES6ehIP35IZFHTjVieKiUavQ== 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=z7BxL3uONvOMmv/oNTkzWWgHQoMcJqaVkMFiKeXdFzs=; b=ZxsOG+OuztlSuaUGau5D5TrlcUVLpRluicXSymFsGG6HIRc5KlSfP7vW5tydSrDf32Wxhis+zCBb7eOKdnJW8/Ei474Yk2yHAqCSSEssywRes0NASxrix83Y6DpecH2/SVigxMo6W8CdxVfOKTdI2g+KStZIWOzMgY0xfbH/M9A+ouX+OTuDAafIdjvViQZTn9LxfGKot47s3IqJ81e1FcjeDLCg1JiiA8S4ftqy8Be22z05CXJU4jyUsoigzJfeEl/CiZtzi7My98NiS69YaLC1tslft1cfuPhk2CYhLBLwVAjfl1uWBJbElSMT2DPlvlWapH8iwx3vaBSVMQ7uZA== 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: gcc.gnu.org; dkim=none (message not signed) header.d=none;gcc.gnu.org; dmarc=none action=none header.from=arm.com; Received: from VI1PR08MB5325.eurprd08.prod.outlook.com (2603:10a6:803:13e::17) by VI1PR0801MB2126.eurprd08.prod.outlook.com (2603:10a6:800:51::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.17; Fri, 15 Oct 2021 11:08:26 +0000 Received: from VI1PR08MB5325.eurprd08.prod.outlook.com ([fe80::bd45:5ad5:f666:272a]) by VI1PR08MB5325.eurprd08.prod.outlook.com ([fe80::bd45:5ad5:f666:272a%4]) with mapi id 15.20.4608.016; Fri, 15 Oct 2021 11:08:26 +0000 Date: Fri, 15 Oct 2021 12:08:24 +0100 To: gcc-patches@gcc.gnu.org Subject: [PATCH] middle-end: fix de-optimizations with bitclear patterns on signed values Message-ID: Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) X-ClientProxiedBy: LO4P123CA0356.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:18d::19) To VI1PR08MB5325.eurprd08.prod.outlook.com (2603:10a6:803:13e::17) MIME-Version: 1.0 Received: from arm.com (217.140.106.55) by LO4P123CA0356.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:18d::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.14 via Frontend Transport; Fri, 15 Oct 2021 11:08:26 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ddc84c2f-86aa-43b0-f11a-08d98fcc22f3 X-MS-TrafficTypeDiagnostic: VI1PR0801MB2126:|DB6PR0802MB2391: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:2150;OLM:2150; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: F0S8/GFUuezO8/lh3lVRAUFp/Ty7x4qDZXBfx08kXoVAbe01G9kk12f2lL9USrxbFF2NLPBQ2DqIuhbh/D/sFGOPAqJCSjxb4U/uwzM6baUtiVm1iWDotSX1f+tGoMErdVcdiX5LVvdzdUztHlLV25AWszCAVWs9vn0va/5KDO0Dr+PfJ4l1tvvokAtkfCnTrIwYU9HRAEM44nwBy8gVdxOevdxP4XutQxR5ToYsUXyJRBe89HfDsaQzp5s2bYPoPTP6Y9j5oUdnAIp1yOFdhNjBOZPMdcgQadL4zO60ATXXa4ZBUs2is+cxnEmWWA7qw4jPcjqn1He2Y5YbmtvpY4M+QfE0xTkKhcZuDUwY5aVbrzEBfG43qieJTqlS4MzaLzMuxjMpFRKTxPZkimXAXebASVBaNp6f1q2w4LSISxI/pZijWGD6z7/BgclDm52MiLWNAJccN9D+7Ao7yKC/K0Pr4IWG+tzl5YFoZxIzyrB/qiUjHh2dRcNbXCzHymP3L7ppJALSZq+w3NBdWrgHgdXXe817ZKgbJof3lYSB+4MfZlE5lUY58piwDReCVQJSEKTBGM4UFEEImYq5JoIBEtVsAKeT7aODJx0ETvlVx5WwTVQvUzoy9FHY3Agio5kApmumZyGYBeg3aAwpNfHtqoe2xYpEBKSHnE2y6Atqobb1VnMR6q4h2CYs8GWVllJpRU1Eq+s6zHOPg+uttYe52sAi4YbP0u8uX2aN2HgfIMXo1pg5JQ/oOWijAQfhS1t1 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:(4636009)(366004)(36756003)(316002)(52116002)(86362001)(508600001)(26005)(5660300002)(7696005)(8936002)(44144004)(8676002)(33964004)(6916009)(66556008)(66946007)(186003)(66476007)(2616005)(235185007)(83380400001)(956004)(4326008)(44832011)(2906002)(38350700002)(55016002)(38100700002)(8886007)(4216001)(2700100001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-Forked: True X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0801MB2126 Original-Authentication-Results: gcc.gnu.org; dkim=none (message not signed) header.d=none;gcc.gnu.org; dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT014.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 38aa38a5-75cb-4708-1023-08d98fcc1c9f X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3WwnJgSS2ZhiO1a8cLKvwkyKrDuOhmMweKLEysJlxKDLk3FnpQ9heVYyttFrF7SyFxA5jkVzJPSLCI9VuajnaJ8lHQ0wPX2wPErMswCeGrQXlyXFf/Qd28s8Cjjm41Ul9T0um4OyXaSlMsNp85whDw1qFUDaQPQnlhuFgQIwGqRYN8nf8YB+2ZUO6oLUtfQPa6HRkb5gu0CnJCb3P2Y2QXUNx+S3kzDkq8mblZiLY51h5VIUXx0yaPn05r4J96/x0TX6C11/5CDI/TTHbtTc+4zkdut4uRWUKjwcl7pebCNtjk283YSoVGhck/YFtdWQLqjF0YxSGTsgVlxCD90/mQEe/bLzxktUXpjwtWtVQ36F2+kL0B3BdNjPBS0L3xRfHqPqBw9Fyddr/bioeYGlK9CDnHuKzV7puFHOyL8GQ2713TN/vOJrqC1tHJ1SutfRhq/ez5zXLLP2Nt2r3KFI5ic9PWtKKcGtMyk/v3udiL8dzMubFhi7c/3UTCQten9s2CkXvvWIauT6k4/ToaqR/QHGUfZGxvAvCnyRD5lDhNmyEpvebpDfVEX5Ky5crILxslbycy/QuoaBrWdJS8Wryc2DJYFWxts5OZDgCW7fMh2+0MV0nTUY79yZ1HoYGiGbhHivOeprp2QTiThMRPuD57glJr1XvmAcR/iWyYhGpzqjZytHOGUmc/7xq8YN2d06ovYYWTyvCqi390SAkrFGPgfPuPPVkqfwzxBkyYh4URaThHuYY4oThWmwGPDD93UT 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:(4636009)(46966006)(36840700001)(36756003)(82310400003)(86362001)(956004)(2906002)(2616005)(36860700001)(44832011)(47076005)(81166007)(356005)(336012)(235185007)(26005)(508600001)(6916009)(44144004)(70586007)(70206006)(7696005)(8936002)(8676002)(33964004)(83380400001)(186003)(107886003)(5660300002)(8886007)(316002)(4326008)(55016002)(4216001)(2700100001); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Oct 2021 11:08:37.1488 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ddc84c2f-86aa-43b0-f11a-08d98fcc22f3 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: AM5EUR03FT014.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0802MB2391 X-Spam-Status: No, score=-13.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tamar Christina via Gcc-patches From: Tamar Christina Reply-To: Tamar Christina Cc: nd@arm.com, rguenther@suse.de Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Hi All, During testing after rebasing to commit I noticed a failing testcase with the bitmask compare patch. Consider the following C++ testcase: #include #define A __attribute__((noipa)) A bool f5 (double i, double j) { auto c = i <=> j; return c >= 0; } This turns into a comparison against chars, on systems where chars are signed the pattern inserts an unsigned convert such that it's able to do the transformation. i.e.: # RANGE [-1, 2] # c$_M_value_22 = PHI <-1(3), 0(2), 2(5), 1(4)> # RANGE ~[3, 254] _11 = (unsigned char) c$_M_value_22; _19 = _11 <= 1; # .MEM_24 = VDEF <.MEM_6(D)> D.10434 ={v} {CLOBBER}; # .MEM_14 = VDEF <.MEM_24> D.10407 ={v} {CLOBBER}; # VUSE <.MEM_14> return _19; instead of: # RANGE [-1, 2] # c$_M_value_5 = PHI <-1(3), 0(2), 2(5), 1(4)> # RANGE [-2, 2] _3 = c$_M_value_5 & -2; _19 = _3 == 0; # .MEM_24 = VDEF <.MEM_6(D)> D.10440 ={v} {CLOBBER}; # .MEM_14 = VDEF <.MEM_24> D.10413 ={v} {CLOBBER}; # VUSE <.MEM_14> return _19; This causes much worse codegen under -ffast-math due to phiops no longer recognizing the pattern. It turns out that phiopts spaceship_replacement is looking for the exact form that was just changed. Trying to get it to recognize the new form is not trivial as the transformation doesn't look to work when the thing it's pointing to is itself a phi-node. Because of these issues this change delays the replacements until after loop opts. This fixes the failing C++ testcase. Bootstrapped Regtested on aarch64-none-linux-gnu, x86_64-pc-linux-gnu and no regressions. Ok for master? Thanks, Tamar gcc/ChangeLog: * match.pd: Delay bitmask compare pattern till after loop opts. --- inline copy of patch -- diff --git a/gcc/match.pd b/gcc/match.pd index 9532cae582e152cae6e22fcce95a9744a844e3c2..d26e498447fc25a327a42cc6a119c6153d09ba03 100644 diff --git a/gcc/match.pd b/gcc/match.pd index 9532cae582e152cae6e22fcce95a9744a844e3c2..d26e498447fc25a327a42cc6a119c6153d09ba03 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -4945,7 +4945,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) icmp (le le gt le gt) (simplify (cmp (bit_and:c@2 @0 cst@1) integer_zerop) - (with { tree csts = bitmask_inv_cst_vector_p (@1); } + (if (canonicalize_math_after_vectorization_p ()) + (with { tree csts = bitmask_inv_cst_vector_p (@1); } (switch (if (csts && TYPE_UNSIGNED (TREE_TYPE (@1)) && (VECTOR_TYPE_P (TREE_TYPE (@1)) || single_use (@2))) @@ -4954,7 +4955,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) && (cmp == EQ_EXPR || cmp == NE_EXPR) && (VECTOR_TYPE_P (TREE_TYPE (@1)) || single_use (@2))) (with { tree utype = unsigned_type_for (TREE_TYPE (@1)); } - (icmp (convert:utype @0) { csts; })))))))) + (icmp (convert:utype @0) { csts; }))))))))) /* -A CMP -B -> B CMP A. */ (for cmp (tcc_comparison)