From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04on2084.outbound.protection.outlook.com [40.107.8.84]) by sourceware.org (Postfix) with ESMTPS id BEFF13858D37 for ; Tue, 9 May 2023 09:50:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BEFF13858D37 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=pL+kVxc47ENlLn+nVwHIj6XVR6Eaj/t0IruaZyntfAk=; b=7BHqw5mnpQrV4blcJlYX8vlnGmo0EcCE+JJfmznPtFTe/SuGRxHwIiE6b3AQkVAlg6ho2/YRYpxVNId9HPWQlVifrymxtc/r9hTFsMrcUGiRzi/FrNlv05REfxjmaPBOW96rpvc+NhwVjY/v+Oj1hYa1DrQKpfc0Gu2QNaw2ONk= Received: from AS9PR01CA0029.eurprd01.prod.exchangelabs.com (2603:10a6:20b:542::10) by AS8PR08MB5880.eurprd08.prod.outlook.com (2603:10a6:20b:29f::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.33; Tue, 9 May 2023 09:50:04 +0000 Received: from AM7EUR03FT023.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:542:cafe::22) by AS9PR01CA0029.outlook.office365.com (2603:10a6:20b:542::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.33 via Frontend Transport; Tue, 9 May 2023 09:50:03 +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 AM7EUR03FT023.mail.protection.outlook.com (100.127.140.73) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.18 via Frontend Transport; Tue, 9 May 2023 09:50:03 +0000 Received: ("Tessian outbound 3570909035da:v136"); Tue, 09 May 2023 09:50:03 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: cf3b3a534a629699 X-CR-MTA-TID: 64aa7808 Received: from 700b18886e13.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 120D430A-0281-4914-9792-99F1B4927132.1; Tue, 09 May 2023 09:49:56 +0000 Received: from EUR04-HE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 700b18886e13.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 09 May 2023 09:49:56 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=I2PjPahd25fdffTye/lXWndu2YJps8XWBlRtmqSQ28yFd/cMjbYCg3hO6yFvcsJShf452xcbA3rCJD/3XOOZs4rONmT18k/Q08zTRbx5Yz01fgdED6dodq/KcKIoCdbxAGYkt5eKIaTc2GzCfbvfvzZ8d+2+ml7PZ4eTiFxjgOcWpSYTbtnFNCRtDu6KGAa9OQa7ru3MomD/XH2xbI8P3gH2zmj+6BCRsVNldpaoJPP96Usxz4QZfkimFM04I2Mkamd8vv9tjhRteg6oJkEofKZ+rbBFKP04gKWYE2/FZSQyw6aO/tEB9PMQzhAV9SyaaX/UZ6BvIO7HowJz2y7gig== 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=pL+kVxc47ENlLn+nVwHIj6XVR6Eaj/t0IruaZyntfAk=; b=BEOCCOYGOFeC8WfJiyrAETBvffyAhe9gE5uUPdDZ21w/snNFFWSFQH6lgo4dMHPsIFnkVqUHZF0HLfcF41wVc8Ocqnnb2HZwW54HRh/O6CTRvd++if5PSdVCw/iWNzwKwX9iYKKsJv06DIzv0fVp8HdjRI3w2hy/73u0l108+rHfcchwhRmueFAyliLDdld3qh+cU/CoXeg10TyKS/UXXYnpZ5oXumKGSbV47VQLgLmGxK4rU07OXyYL+XLfPqXnaIdTX3pRmKew2+x6J+f1aq6biHWAk0S9OUFbhboBsfrxUR64JHue4/OtURG4LparqlbdYEZbY65M+08avBSl0w== 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=pL+kVxc47ENlLn+nVwHIj6XVR6Eaj/t0IruaZyntfAk=; b=7BHqw5mnpQrV4blcJlYX8vlnGmo0EcCE+JJfmznPtFTe/SuGRxHwIiE6b3AQkVAlg6ho2/YRYpxVNId9HPWQlVifrymxtc/r9hTFsMrcUGiRzi/FrNlv05REfxjmaPBOW96rpvc+NhwVjY/v+Oj1hYa1DrQKpfc0Gu2QNaw2ONk= Received: from PAXPR08MB6926.eurprd08.prod.outlook.com (2603:10a6:102:138::24) by VE1PR08MB5662.eurprd08.prod.outlook.com (2603:10a6:800:1a9::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.32; Tue, 9 May 2023 09:49:54 +0000 Received: from PAXPR08MB6926.eurprd08.prod.outlook.com ([fe80::db73:66ba:ae70:1ff1]) by PAXPR08MB6926.eurprd08.prod.outlook.com ([fe80::db73:66ba:ae70:1ff1%3]) with mapi id 15.20.6363.032; Tue, 9 May 2023 09:49:53 +0000 From: Kyrylo Tkachov To: Benjamin Minguez , "gcc-help@gcc.gnu.org" Subject: RE: Condition execution optimization with gcc 7.5 Thread-Topic: Condition execution optimization with gcc 7.5 Thread-Index: Adl/TMBSKMw/jWBlR02Ebyaz76pGRwDDZEEg Date: Tue, 9 May 2023 09:49:53 +0000 Message-ID: References: <5847ae4810754a6dbff4cf212a83eb8a@huawei.com> In-Reply-To: <5847ae4810754a6dbff4cf212a83eb8a@huawei.com> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; x-ms-traffictypediagnostic: PAXPR08MB6926:EE_|VE1PR08MB5662:EE_|AM7EUR03FT023:EE_|AS8PR08MB5880:EE_ X-MS-Office365-Filtering-Correlation-Id: 5a945895-088b-416b-6f00-08db5072c384 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: dkKzETYT8eoPzfE0WqUZwlkrTtbfLh04f7fPlZf82oYuPnGlnX38XIzGhj81bbLIcUYBwEk9TEi6QayROFe6mf1RmokCNXC4daddh3lRE/nMrT+eCDjIVY387tyqG0Tpmovg6zZ8LLwRVWLcgHvDqe6zRFd/oYfvXrk2YgcEQWqa//frUstIz302I3fC6Y5NjhLSYHwcxxPiN2T2qnrlAH8/QQt9oLjAx2HG50bx3KNmhusewJZaii5kuFQ9C2bofPOlsn3sl3T0dFXOiBhOAOipPRzCK1drv2zi0yApCMsjc/ULprepXqcMfWr8q2o3cJka46OUmw/tSNwjgldbeTGSuGXSMM19lZqr+k21bng3zHbMwSe+RJVyJDuMYF/H84053gFQ0fnRecI3otf62TTWPa8jzmbiMZBOYNmyj+IkknzIqIFhI1iooBVy98tWYJ3NqllVGVt1Dl4VBZcMLr4N8kuJDKRd+Y/S9BnCawANK5fz4F4CnDWA36cPTUt3HF47i4hrx3RfM3ESEZDNiNcnnVWYvcGF+JTi/GV4q/0liOa7WMNyjSYFQBO9wtNjpcY3M40JCMQbD5Ab00i8Y8EUaRA5YwaIRj+QiYPByNLtAVAfri50s2p3yafYD7up X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR08MB6926.eurprd08.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(136003)(396003)(39850400004)(346002)(376002)(366004)(451199021)(110136005)(66446008)(5660300002)(76116006)(66476007)(8676002)(8936002)(478600001)(66556008)(64756008)(66946007)(2906002)(71200400001)(316002)(41300700001)(52536014)(7696005)(53546011)(6506007)(9686003)(26005)(83380400001)(186003)(55016003)(38070700005)(33656002)(38100700002)(122000001)(86362001);DIR:OUT;SFP:1101; Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR08MB5662 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: AM7EUR03FT023.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 09353bb5-5ab9-443f-bf34-08db5072bd6f X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 24TV1u4kTtn3QDSPxFYG/Dlc+k6gdEUli8BebXdOBtY1FvJPCYvkYaMBhtGfX/nfv9eouxuXnB6NMtzOJf5yWA+8A6BzBiOsUndjA8uPjn6xxsO1OXInU7v+LUjeTgX0wQgwZxnk4R4vPh2azBj5mHjRFo8RnKEOOzSsQR5NIEmb+HhnUMev7C+qpDwfILEyLmPVJO05vF9IM41umr0F9ap3js/atalXHkxt3YXODDGb3lC65K/P21Dmqo+10K/uGtZMyqKhuE/17429dAAiDTxd9FAwz71OYpzj9bTqS6NCL6YBwlBc4XPnIVrgWvMfJRtRCGDPOhQrQii5Spr56YlNThPPRRQczhqt6efHZpgdpjJ9sHWMFgnG5Cx92yqfc5mOmAxUkLApT+9l9Z+VZF8+2yIl6nD4PrsGbzHz0Bmu5PSykJ3dsHLuXVCtI6S51vkYlpYOQbqFZN8nf/vng8gjDUyCB+nejWEoYmywQboDgZcyTxeEr8pv/xYcsC+xxKE1qHPgW3n0fGgLGN+24AhvhjZywOk+nkyyg5MFmfeNd/wZACcl9fZtykmgn+aT/AHf6lzU0A17oCvhgpIIdCsTYzmwdNf9eUCAiiee2u06LZn8zxYIvuHn4nDAE55vQkr63pXQI2IJmBEnHIQKSi/pmVWSa5KANlkmaTiqi0nBvwCcrIOC4Mcbgqod3kMQvXYSwCV8ecLkqYHYCia2gA== 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:(13230028)(4636009)(376002)(346002)(136003)(396003)(39860400002)(451199021)(40470700004)(36840700001)(46966006)(40460700003)(2906002)(26005)(53546011)(9686003)(6506007)(33656002)(186003)(336012)(40480700001)(83380400001)(36860700001)(55016003)(47076005)(81166007)(82740400003)(356005)(316002)(41300700001)(70206006)(70586007)(7696005)(110136005)(86362001)(478600001)(82310400005)(52536014)(5660300002)(8676002)(8936002);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 May 2023 09:50:03.8849 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5a945895-088b-416b-6f00-08db5072c384 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: AM7EUR03FT023.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB5880 X-Spam-Status: No, score=-5.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,FORGED_SPF_HELO,KAM_DMARC_NONE,KAM_NUMSUBJECT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hi Benjamin, > -----Original Message----- > From: Gcc-help > On Behalf Of Benjamin Minguez via Gcc-help > Sent: Tuesday, May 9, 2023 8:54 AM > To: gcc-help@gcc.gnu.org > Subject: Condition execution optimization with gcc 7.5 >=20 > Hello everyone, >=20 > I'm trying to optimize an application that contains a lot of branches. I'= m > targeting armv8 processors and I'm using GCC 7.5.0 for compatibility reas= on. Of course GCC 7.5 is quite old now but if you're forced to use it... > As the original application is similar to NGINX, I investigated on NGINX.= I'm > focusing on the HTTP header parsing. Basically, the algorithm parse byte = per > byte and based on the value stores some variables. > Here is an example, /src/http/ngx_http_parse.c: ngx_http_parse_header_lin= e > if (c) { > hash =3D ngx_hash(0, c); > r->lowcase_header[0] =3D c; > i =3D 1; > break; > } >=20 > if (ch =3D=3D '_') { > if (allow_underscores) { > hash =3D ngx_hash(0, ch); > r->lowcase_header[0] =3D ch; > i =3D 1; >=20 > } else { > r->invalid_header =3D 1; > } >=20 > break; > } > Also, most of branches are not predictable because it compares against da= ta > coming from the network. > From these observations, I looked at the conditional execution optimizati= on > step in GCC and I found this function that should do the work: > cond_exec_find_if_block. And how to customize the decision to use > conditional instructions: ... This relates to the arm port i.e. the 32-bit target in Armv8-a, is that= what you're targeting? AArch64 has had more tuning work put into it over the years so may do bette= r performance-wise if your processor and environment supports it. If you're indeed looking at arm... > #define MAX_CONDITIONAL_EXECUTE > arm_max_conditional_execute () > int > arm_max_conditional_execute (void) > { > return max_insns_skipped; > } > static int max_insns_skipped =3D 5; >=20 > I tried to compile NGNIX in -O2 (that should enable if-conversion2) but I= did > not noticed any change in the code. I enable GCC debug (-da) and also add > some debug in this function and I figure out that > targetm.have_conditional_execution is set to false. >=20 > First, do you how to switch this variable to true. I guess it is an optio= n during > the configuration step of GCC. It's definition on that branch is: /* Only thumb1 can't support conditional execution, so return true if the target is not thumb1. */ static bool arm_have_conditional_execution (void) { return !TARGET_THUMB1; } So it looks like you're maybe not setting the right -march or -mcpu option = to enable the full armv8-a features? Thanks, Kyrill > Then, I know that the decision to use conditional execution is based on = the > extra cost added to compute both branches compare to the cost of a branch= . > In this specific case, branches are miss predicted and the cost is, indee= d, high. > Do you think that increasing the max_insns_skipped will be enough to help > GCC to use conditional execution? >=20 > Thank you in advance for your answers. >=20 > Best, > Benjamin Minguez