From patchwork Tue Sep 19 13:53:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tamar Christina X-Patchwork-Id: 1836734 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-armh-onmicrosoft-com header.b=79+i1fsq; dkim=pass (1024-bit key) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-armh-onmicrosoft-com header.b=79+i1fsq; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Rqjnw0bn3z1ynZ for ; Tue, 19 Sep 2023 23:54:26 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2C34B3857351 for ; Tue, 19 Sep 2023 13:54:24 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04on2080.outbound.protection.outlook.com [40.107.8.80]) by sourceware.org (Postfix) with ESMTPS id 911213858D39 for ; Tue, 19 Sep 2023 13:54:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 911213858D39 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ROLQazeXtYMul3qB6HKEv1YVYAKEPdnEwKygsE+tou0=; b=79+i1fsqEq+uDKRHpjf7ggxgo+yfh4Zne8pZfyMx7FeZXyp/UQ2w/dcr6fDEludU0sK6/dZC0Y9xKr/Hxw/saM4IQyJyzuBmuylOkjCQ5rJ34FMBe+wrJw6Va9TzvmlqkLP3fzufBlHmOiq3NX2RziQj56zVTDtMOlVoNFihge0= Received: from AS9P251CA0014.EURP251.PROD.OUTLOOK.COM (2603:10a6:20b:50f::18) by AS4PR08MB7556.eurprd08.prod.outlook.com (2603:10a6:20b:4fe::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.19; Tue, 19 Sep 2023 13:54:07 +0000 Received: from AM7EUR03FT047.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:50f:cafe::fd) by AS9P251CA0014.outlook.office365.com (2603:10a6:20b:50f::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.28 via Frontend Transport; Tue, 19 Sep 2023 13:54:05 +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 AM7EUR03FT047.mail.protection.outlook.com (100.127.140.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6813.16 via Frontend Transport; Tue, 19 Sep 2023 13:54:05 +0000 Received: ("Tessian outbound b5a0f4347031:v175"); Tue, 19 Sep 2023 13:54:05 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 1a8cfef8a268075b X-CR-MTA-TID: 64aa7808 Received: from 795dea235eb4.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 342FF241-37D0-459F-8EF3-479B46F34CE8.1; Tue, 19 Sep 2023 13:53:59 +0000 Received: from EUR04-HE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 795dea235eb4.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 19 Sep 2023 13:53:59 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RfsDCTeL2ouagTccjOL1MF9nh/X6/U1ZVNWg7V+kFsf/bQlRbCGjrSKbjS02YF+zEa1GcSiyuHn+AoWb7dW48cJIhjGdf/K4lQQABuzS6MKjY2q5d9HRxRj10f09TBE4DLQMaQXAo3dOZFkxY1vlwM60DvulxmOwFu8g/Ujz8fNv+JVULebX30+L3QPr6xuV3tJdG4NmnDqx+HVgWa91kaHsDT31cs91ihPnTKFXr3ABaVZelhXZ0ZIfZjWI3HX69gB7uFAI1mhx5EfJjboZHevk3eG4ZtRbGfGUwtnE8PNZMklqs+9efuWig+l5IG8mTgisdfTa4u0VHNj7SpxgXw== 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=ROLQazeXtYMul3qB6HKEv1YVYAKEPdnEwKygsE+tou0=; b=ACemMFGQR42rs4pTLHHJ2U00bc6JBE1vOLESemUtTyPKoU2rmc7KLvpYstYxI8QkDEVJ6Db2eWQF2G5Pos6wSEHZp1LzumQgGcqCE3HVaDekxrrt+iKqpBMJNM17S3U+DowicwvQB0KUC+xw+HUa8cVXpslkMPB/Ep+L15BWVCjR/C1QvlXf+AkrFj4OkWtTUudIcC6x2QlQQMbjN3KZjFl1E+I6xfweXVM6S0UGqEyhUPQy5sTZOinKOo/Lo/Av84KI3Actl3OMOfxYuB9KmHnmgjjygf95nJZM4BUE4cXRlbmPFzyoaqvFAaDRdHx+Qn3WpqcJHaXU445F6pDTtA== 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ROLQazeXtYMul3qB6HKEv1YVYAKEPdnEwKygsE+tou0=; b=79+i1fsqEq+uDKRHpjf7ggxgo+yfh4Zne8pZfyMx7FeZXyp/UQ2w/dcr6fDEludU0sK6/dZC0Y9xKr/Hxw/saM4IQyJyzuBmuylOkjCQ5rJ34FMBe+wrJw6Va9TzvmlqkLP3fzufBlHmOiq3NX2RziQj56zVTDtMOlVoNFihge0= 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 PA4PR08MB6079.eurprd08.prod.outlook.com (2603:10a6:102:ee::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.27; Tue, 19 Sep 2023 13:53:54 +0000 Received: from VI1PR08MB5325.eurprd08.prod.outlook.com ([fe80::662f:8e26:1bf8:aaa1]) by VI1PR08MB5325.eurprd08.prod.outlook.com ([fe80::662f:8e26:1bf8:aaa1%6]) with mapi id 15.20.6792.026; Tue, 19 Sep 2023 13:53:53 +0000 Date: Tue, 19 Sep 2023 14:53:51 +0100 From: Tamar Christina To: gcc-patches@gcc.gnu.org Cc: nd@arm.com, rguenther@suse.de, jlaw@ventanamicro.com Subject: [PATCH]middle-end ifcvt: replace C++ sort with vec::qsort [PR109154] Message-ID: Content-Disposition: inline X-ClientProxiedBy: LO4P123CA0640.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:296::21) To VI1PR08MB5325.eurprd08.prod.outlook.com (2603:10a6:803:13e::17) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: VI1PR08MB5325:EE_|PA4PR08MB6079:EE_|AM7EUR03FT047:EE_|AS4PR08MB7556:EE_ X-MS-Office365-Filtering-Correlation-Id: 57d352b1-a8e1-4852-abe9-08dbb917e39c 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: LGXXYEbcP7SZclTndrIIbZIG1rq4O9vW2UyZ13F0JaIyNqZWwUNlMGM6vJQ8FUk7DUxpQf7KUYbQL0pt7i0RQUoXHRnEC8QbrtatUcsHhcZ6kFXqJUMAMvX3APU5eZ0wsuIc+09Th99VbZo5F2YrRUMvSKiAlhWLGuAuabote89SUFu/Mb5OnyPeynAY7iR8Xp8JQvS+yE5DJUF0BkUi8ing5MoWe61vN5zEhb22CeNrvkZXyL+ArE8I+kuD2F93oD3HNQuPlImKoECr1OSIXVjUkGyucgYWfAKXwcXPyEP2j/wy6fXaSqRZsFc7zOliJitXw2ww/frm6pwn45QiWi4k4FusBHxDieiveH49NdmYjd2sDZiYevxhiZmJVgnFftgx3bsOuSxMU5XdJw5nKIjsn4igZI729ULYvlm6Uf7JsVyPN5DdzC+KOuuMWLRQw1nIrf5TA62gRCakv2sN9etKtR5dWbUjRIgCemi3IeTa2ZPYwcf+g/hcH2pyq5s6knFdlHCMdPyoanptNkhVqr0FJ5VBGWRL1lBFH0gvSRBaQqHzq13Kb7nxR8+vAZ4q/z9RcEJpaHhW1fAfPIVLbfj1zm2syebtu1AXZxozxvOciRukPgWIBYAoiyYwWVIDTwk9xeI7VM08BOfVSunV/w== 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:(13230031)(136003)(366004)(39860400002)(346002)(376002)(396003)(451199024)(1800799009)(186009)(2616005)(83380400001)(6512007)(26005)(316002)(6916009)(41300700001)(235185007)(66946007)(66476007)(66556008)(8676002)(5660300002)(8936002)(2906002)(4326008)(6486002)(6506007)(478600001)(44144004)(33964004)(86362001)(36756003)(38100700002)(44832011)(4216001)(2700100001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR08MB6079 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: AM7EUR03FT047.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 57f493ea-22b0-46b6-c1a5-08dbb917dc6d X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: XTb4kU0DetGqzzPHSTLLx9PkpD+dQcJgS8KA9a7qdAvAc8BDM/mCZXhcocXz348uO9lc74xY2EclOlzvgvJamEP7ojHN5akHCKTrvy72jKFr/Cw0ES7vSylSbRlpGTRb7TQH3uWf7UKiYEXWpqhFE0gyQZyZ7es4lhk6Gp9lB0cuKxVooysZ69Q8N+zcei3nCJ95p4adSX6PaALYVFAANFWzOOhpB2TuHYAjr6hwLszr3p+sUOzKZwJyUgubEqaPJWv/OsKgO51OeL4sfIcaUSKV4xrqv0dtwtk5yTwFHwK76c7mpY2DgwgH+n//LyzLxpHYTpw+qwgwqbViQl/JaqHP7EJ2jzgGChMUur8EEW698nL5muyouxBnotl6NnygBacBfWVBlZfK3pfZi4dKHSiyW4xPHTcYU7JAtLCs1pg29D0YFhMAAkE3p06bokvpHmLIoaHt4O/h0wj0ex1dRpLXJfUgYeT132zW6pHIyekb1kNicuGL+pSvev5bZYZgRaamANk49ytzwZaoTJLWvYJiV2yFuTOMDFySDk2OcWuK0cF/mW2J72twA8a5pk+64d+fFohg49MVcqQDeUXEljDzbACJAqZ6+RvsgSz0mLWlQjByzdlYlVI6u41Iz3UignXitLIbuLXH+V3Sf3P5WAxns6ylvZnEFCvN2TRarlAzRBbutdNl976La2CwjkjXOcglcvPraga4Dfa1+7ikWfwsluOHsZlDQa9B5hLhKg4j/L7zlyR0TJHbjmlioRNWQDb5ScN6PY1YlwmvRm0iuNIwEqPvg0qVwByj8f+sPL0= 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:(13230031)(4636009)(346002)(39860400002)(376002)(396003)(136003)(186009)(1800799009)(82310400011)(451199024)(36840700001)(46966006)(40470700004)(316002)(70206006)(336012)(70586007)(26005)(83380400001)(6916009)(40480700001)(2616005)(6486002)(33964004)(6506007)(6512007)(36756003)(44144004)(356005)(81166007)(47076005)(36860700001)(40460700003)(478600001)(86362001)(107886003)(2906002)(235185007)(4326008)(82740400003)(41300700001)(8936002)(8676002)(5660300002)(44832011)(4216001)(2700100001); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Sep 2023 13:54:05.6514 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 57d352b1-a8e1-4852-abe9-08dbb917e39c 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: AM7EUR03FT047.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS4PR08MB7556 X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FORGED_SPF_HELO, GIT_PATCH_0, KAM_DMARC_NONE, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NONE, TXREP, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Hi All, As requested later on, this replaces the C++ sort with vec::qsort. Bootstrapped Regtested on aarch64-none-linux-gnu and no issues. Ok for master? Thanks, Tamar gcc/ChangeLog: PR tree-optimization/109154 * tree-if-conv.cc (INCLUDE_ALGORITHM): Remove. (cmp_arg_entry): New. (predicate_scalar_phi): Use it. --- inline copy of patch -- diff --git a/gcc/tree-if-conv.cc b/gcc/tree-if-conv.cc index 799f071965e5c41eb352b5530cf1d9c7ecf7bf25..0d7ac82986f399f1c5ff91c04ddb524813ab27de 100644 --- diff --git a/gcc/tree-if-conv.cc b/gcc/tree-if-conv.cc index 799f071965e5c41eb352b5530cf1d9c7ecf7bf25..0d7ac82986f399f1c5ff91c04ddb524813ab27de 100644 --- a/gcc/tree-if-conv.cc +++ b/gcc/tree-if-conv.cc @@ -80,7 +80,6 @@ along with GCC; see the file COPYING3. If not see :; */ -#define INCLUDE_ALGORITHM #include "config.h" #include "system.h" #include "coretypes.h" @@ -2045,6 +2044,28 @@ gen_phi_nest_statement (gphi *phi, gimple_stmt_iterator *gsi, return lhs; } +typedef std::pair > ArgEntry; +static int +cmp_arg_entry (const void *p1, const void *p2) +{ + const ArgEntry sval1 = *(const ArgEntry *)p1; + const ArgEntry sval2 = *(const ArgEntry *)p2; + auto x1 = sval1.second; + auto x2 = sval2.second; + + if (x1.first < x2.first) + return -1; + else if (x1.first > x2.first) + return 1; + + if (x1.second < x2.second) + return -1; + else if (x1.second > x2.second) + return 1; + + return 0; +} + /* Replace a scalar PHI node with a COND_EXPR using COND as condition. This routine can handle PHI nodes with more than two arguments. @@ -2186,7 +2207,6 @@ predicate_scalar_phi (gphi *phi, gimple_stmt_iterator *gsi) /* Determine element with max number of occurrences and complexity. Looking at only number of occurrences as a measure for complexity isn't enough as all usages can be unique but the comparisons to reach the PHI node differ per branch. */ - typedef std::pair > ArgEntry; auto_vec argsKV; for (i = 0; i < args.length (); i++) { @@ -2204,10 +2224,7 @@ predicate_scalar_phi (gphi *phi, gimple_stmt_iterator *gsi) } /* Sort elements based on rankings ARGS. */ - std::sort(argsKV.begin(), argsKV.end(), [](const ArgEntry &left, - const ArgEntry &right) { - return left.second < right.second; - }); + argsKV.qsort (cmp_arg_entry); for (i = 0; i < args.length (); i++) args[i] = argsKV[i].first; --- a/gcc/tree-if-conv.cc +++ b/gcc/tree-if-conv.cc @@ -80,7 +80,6 @@ along with GCC; see the file COPYING3. If not see :; */ -#define INCLUDE_ALGORITHM #include "config.h" #include "system.h" #include "coretypes.h" @@ -2045,6 +2044,28 @@ gen_phi_nest_statement (gphi *phi, gimple_stmt_iterator *gsi, return lhs; } +typedef std::pair > ArgEntry; +static int +cmp_arg_entry (const void *p1, const void *p2) +{ + const ArgEntry sval1 = *(const ArgEntry *)p1; + const ArgEntry sval2 = *(const ArgEntry *)p2; + auto x1 = sval1.second; + auto x2 = sval2.second; + + if (x1.first < x2.first) + return -1; + else if (x1.first > x2.first) + return 1; + + if (x1.second < x2.second) + return -1; + else if (x1.second > x2.second) + return 1; + + return 0; +} + /* Replace a scalar PHI node with a COND_EXPR using COND as condition. This routine can handle PHI nodes with more than two arguments. @@ -2186,7 +2207,6 @@ predicate_scalar_phi (gphi *phi, gimple_stmt_iterator *gsi) /* Determine element with max number of occurrences and complexity. Looking at only number of occurrences as a measure for complexity isn't enough as all usages can be unique but the comparisons to reach the PHI node differ per branch. */ - typedef std::pair > ArgEntry; auto_vec argsKV; for (i = 0; i < args.length (); i++) { @@ -2204,10 +2224,7 @@ predicate_scalar_phi (gphi *phi, gimple_stmt_iterator *gsi) } /* Sort elements based on rankings ARGS. */ - std::sort(argsKV.begin(), argsKV.end(), [](const ArgEntry &left, - const ArgEntry &right) { - return left.second < right.second; - }); + argsKV.qsort (cmp_arg_entry); for (i = 0; i < args.length (); i++) args[i] = argsKV[i].first;