From patchwork Tue Jun 21 15:50:27 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Greenhalgh X-Patchwork-Id: 70571 Delivered-To: patch@linaro.org Received: by 10.140.28.4 with SMTP id 4csp2086662qgy; Tue, 21 Jun 2016 08:52:03 -0700 (PDT) X-Received: by 10.36.127.80 with SMTP id r77mr6882362itc.6.1466524323479; Tue, 21 Jun 2016 08:52:03 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id t125si30415698pfb.123.2016.06.21.08.52.03 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Jun 2016 08:52:03 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-430238-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-430238-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-430238-patch=linaro.org@gcc.gnu.org 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:in-reply-to:references :mime-version:content-type; q=dns; s=default; b=sRRN03ArEMRE+xYb 21L2WBjNE8IfdHXK3IkG/T6SOrAKiZNnknYk5FnRJTs9iHnS1fEUUFPK8FovT9uu iUuF7/lsEqRnRJ19SU6U6uup+21uGZuENSHMo99lV03oDUwuND13bgrxtxPFJD3F WfK0dGrxNcpaH2uiS48FoRLpszk= 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:in-reply-to:references :mime-version:content-type; s=default; bh=qxBmLq5RuhN1XY8OkGwU0w aORvk=; b=N4Y+eX1uzrm5/wXCUm0a3hDkol9h+8k44xlP++krCDDZUElsyKNSYx hpEdvH0ePl5MDwkdecGwLP1q2IfHtx71zU3DmU1uUBQSCumQjrIXI68ZaOAMQMgd VvT+0xRYBUVPziZ8s8PZmbzrNMsrl7x98efuMJUjaPNBKOPY3Nl48= Received: (qmail 130701 invoked by alias); 21 Jun 2016 15:51:27 -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 130537 invoked by uid 89); 21 Jun 2016 15:51:26 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.6 required=5.0 tests=AWL, BAYES_00, SPF_PASS autolearn=ham version=3.3.2 spammy=sk:targetm, PLUS, H*Ad:D*t-online.de, Helper X-HELO: eu-smtp-delivery-143.mimecast.com Received: from eu-smtp-delivery-143.mimecast.com (HELO eu-smtp-delivery-143.mimecast.com) (207.82.80.143) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 21 Jun 2016 15:51:10 +0000 Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-ve1eur01lp0245.outbound.protection.outlook.com [213.199.154.245]) (Using TLS) by eu-smtp-1.mimecast.com with ESMTP id uk-mta-62-UDQyqYL6N7Oj70zjCiSMNA-1; Tue, 21 Jun 2016 16:51:04 +0100 Received: from AM3PR08CA0052.eurprd08.prod.outlook.com (10.163.23.148) by HE1PR08MB1195.eurprd08.prod.outlook.com (10.166.96.19) with Microsoft SMTP Server (TLS) id 15.1.523.12; Tue, 21 Jun 2016 15:51:00 +0000 Received: from AM1FFO11FD012.protection.gbl (2a01:111:f400:7e00::162) by AM3PR08CA0052.outlook.office365.com (2a01:111:e400:8854::20) with Microsoft SMTP Server (TLS) id 15.1.523.12 via Frontend Transport; Tue, 21 Jun 2016 15:51:00 +0000 Received: from nebula.arm.com (217.140.96.140) by AM1FFO11FD012.mail.protection.outlook.com (10.174.65.101) with Microsoft SMTP Server (TLS) id 15.1.517.7 via Frontend Transport; Tue, 21 Jun 2016 15:51:00 +0000 Received: from e107456-lin.cambridge.arm.com (10.1.2.79) by mail.arm.com (10.1.105.66) with Microsoft SMTP Server id 14.3.294.0; Tue, 21 Jun 2016 16:50:44 +0100 From: James Greenhalgh To: CC: , , , , , , Subject: [RFC: Patch 2/6 v2] Factor out the comparisons against magic numbers in ifcvt Date: Tue, 21 Jun 2016 16:50:27 +0100 Message-ID: <1466524231-17412-2-git-send-email-james.greenhalgh@arm.com> In-Reply-To: <1466524231-17412-1-git-send-email-james.greenhalgh@arm.com> References: <1466524231-17412-1-git-send-email-james.greenhalgh@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:217.140.96.140; IPV:CAL; SCL:-1; CTRY:GB; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(7916002)(2980300002)(438002)(199003)(189002)(377424004)(110136002)(76176999)(11100500001)(189998001)(8936002)(106466001)(568964002)(356003)(2351001)(2950100001)(6806005)(50226002)(26826002)(104016004)(5890100001)(19580395003)(2476003)(7696003)(8676002)(229853001)(2906002)(19580405001)(246002)(7846002)(50986999)(586003)(84326002)(33646002)(86362001)(36756003)(92566002)(4326007)(87936001)(4610100001)(512874002)(77096005)(5003600100003); DIR:OUT; SFP:1101; SCL:1; SRVR:HE1PR08MB1195; H:nebula.arm.com; FPR:; SPF:Pass; PTR:fw-tnat.cambridge.arm.com; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; AM1FFO11FD012; 1:2Ej7Qx0u6vMEX5i4sr+ahq9/Av8Uz6TETrdkKWDq43aVvOfukklEuOphNe8CGdvO70PcpxuwvG2oiHpchd7zD6XRNSbrtn0MdbbgxIBNswqt/d1AhjVQOUqntC4XWbJJsLisdw7ieegfTbwClbtaul40xI3/kli3Vzyfb7+VwwZNprPPJIW6THjhBcQ2iNHwEVcygK332wTo1VwFmbrZsuNR7+PJfjzZ6TcEx9HWX8qlWlA6GxVxIC9I1R2Gt9opXE4va4+7TRZ8o/nG0FPgfzj84ihBokB3djd2aVMUzXFfKLktbFx8x0k8khVkz6xzaRxTAyTOZ1uDh1GOLt+sQMv5XaS1kqpiEkaDmFzzvNB47CLsv8PnyaMFyDTIiyNLdMtudsxEG1CCWNlgtTKUp5t+uJ0AWKJ0XZzwgtPR3nA8MtRSZ/n0wbV0BCl8uWjRWXKZGdlW5GCl18KYUjvmHDwA4gFBuspWqQh0AtfYTHxEgnEQxSbPcovn/y1jihm9b9SGeQNArgWdyqrRAx18x1yea9+V5A5HWjBYjkV62xq1cf9tm2XoOFgx6EY+shLO X-MS-Office365-Filtering-Correlation-Id: d21d35b5-e001-4bdd-3f94-08d399ebd7b4 X-Microsoft-Exchange-Diagnostics: 1; HE1PR08MB1195; 2:DVYpbnIRmdvlNac7QuKZTKF6rwsSxAC/T2R0baYSHVHjtI4BLv7qEnLD7Q5FH/zoeWehZcITagAjV972OYEo07QxGNB4IYOU5HTJ5U7aPHKwaT272rdwwfN9S9KlhNkh74gPg8elOEO/DCA2wZXI9JemY/94H288gmNh1vAIfV7iG3c2ICCPZrI6lyR2rD7A; 3:SeAsw0gBpIyjlpCWYUxwXJulxU3dRjjmSn6Hj3Z3wI0Uwe54tOlhtIy94ZUa2AIIwSn0C8a1JnIY6PmSwcUwpBUIdEU+8FDfSB7XreeSjDXBgtKRGBFLHp43I+wdfCvGwp3AnCaOM+TZdmxCXMjcbAmE0LQlpwV7tNRdEkJs8Xhu/ZekfdqPwz857UlebpY5zqvXbpw/Us2ZHkF+tryvOvEQjiss1dxf877iVqk8hpfb5aZm9NN4V0vvfUxplDyQiordrP3uYmk7shrXLe3Qvg== X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(8251501002); SRVR:HE1PR08MB1195; X-Microsoft-Exchange-Diagnostics: 1; HE1PR08MB1195; 25:c9vHNJcdISQMKqk6MqHmMNxPKY/K8QbEP0ML3eVZT/ylAOcbNMj1nGXpqvYIxdgBdyo5hhrupFZIoFKm8I5wpj7CO0pTaY2gA58J22Qnkg4Rsxgd+ayv2LnWJOeJAErviUYsohQoAVInTC/NVbIqsFgWkumnmurJrvc5aFsnElTROvJk/zHRJHCdxEnLDPaJCLTCyA6IoUdRvmmX1TLmLX15da+zf1phZ4kLI5rz1cX0tC7HfWUuNMZB5XjUZ4x0DiL/CAX2enAN/35nE9wN/Tma4TIsL0Aq01arsjvuOeok9f089FJgeNhIwAW54ydiMVETr5wE4AjMvjygHfPXVJ0Rn5jCbhNebusVyvtjq5vD70w7YHh7lwnrugqqSiIHSQO/QfQgxGNPL6pg9efSCKd/FC9YIo0o7gpV7V2Bt0D6+KWOL/cXvYEIwAZFP1EhkAwfqWzxl2ncq7ngEKcKd2Clagamb8seNa8HpfEZ/ozm3+AwBEDt70vsf8xa4d4T; 20:Gmt3uQF+3qrIkP12iWYWR7SB0wOGNsv95HgCsBQKpnSoDxnlGwkhHIIJQf9xWk58w5NWTOYMgaw5fv5BdfOAz4lahyrPYEBabZbOcc99pD47QnacAXapFIs0Wkc1O3ZYj4EA5/vbNB2S5psrLQ3+lgAPMGqJhl8OTVJnZYE65fgahPXpo74eZxD/+HTJh44EIDZAMMRrEpKwKJXU7UPnG/MUKwo5P3RcyDsGIzPn36w1Zy59DL1dfGiTeRiAEwGy NoDisclaimer: True X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(180628864354917); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(102415321)(601004)(2401047)(13020025)(13013025)(13024025)(13023025)(5005006)(8121501046)(10201501046)(3002001)(6055026); SRVR:HE1PR08MB1195; BCL:0; PCL:0; RULEID:; SRVR:HE1PR08MB1195; X-Microsoft-Exchange-Diagnostics: 1; HE1PR08MB1195; 4:ZoSwXnrWwK5kP0sOE1TFWqGZi+TK/V3JWhWfK+gaXAtkwVYLbZbGA8+tpnvw0TYu+PMar2YLk7nrhynlgspY82I6tqsOqGSMyQSmVomyDCHN3WG3S4hRl2JE1wyxs7eeckHQB7LumF8oxCrvxCjjFUWM9qARqlDC9q51puMr4r3Rvqxx6uQimyrag+Jeq5RrErQiAB95r7v9V0Cg2XIHIJwYhfynpbVYVW5G8mr+y5odKo9sNInE771PHeRam0EQ2VHpmfg1rHzro2dvuk/Xbb43n543EJ03PgQv0WS7DSuZPE0krB8ecKT+BezTvZb7495+BOaY56LdpOnLk6N1PyeOpi6UWGRgoN/Z3eWb0sxtYw9hlV8w/8jz8zZBxi2SzBXAfR4cyaFEyt7sCGcnJsNTjgImJLmoRJUFoSV0yiFX554k46KcZEy6OHbqUjIRVQuT2yq7zO8/vKYgv8Kv1ghnCgwxJZhnAVblTAqUaOhHk/sLtJ0+80htYhBcmcWB+oCGEOFuh5E4p8II5ircAA== X-Forefront-PRVS: 098076C36C X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; HE1PR08MB1195; 23:oM3KV71XcWkq/mI50I9HWctL7dRrKWXPOys7UUwb5?= =?us-ascii?Q?5/H75KEVZo/TVnGzQwpOPsz7Slbp82ab7nfWKRBAvxlOzuQGsfQxb22FycFB?= =?us-ascii?Q?6Af0pHafpHg2WF8kE0DCN4kafgooldpTLQRHiJtDCqbpIQz8qQVePCwM29zj?= =?us-ascii?Q?TJic8U7cUTNsbPn/D+Zmj6zEMXqLqX2qGBi5hZ8kJXAxbS4/AvK334v3RDRX?= =?us-ascii?Q?0P729wCG5IjyakSialDpY6mPwGx31382FdriZPo/Pad45p/O3dGXfLQHIr5g?= =?us-ascii?Q?iTwWgzUYWYkxI5FgVuN29eHSptiQldzhZC2cc+JeE8Qhi2sYmN2rPuWvPzOF?= =?us-ascii?Q?k0bWrF1BNcOU70+MVwq238uyKypMowetHRQvPmy+BfvCe1Zp2O7PFV1LSC8w?= =?us-ascii?Q?3hXbi+OViOCbkk0Z3GLYj4HzLvYizE6aMcplH/f4A3haG2i62JpyPySYh+tZ?= =?us-ascii?Q?pWjELjcs2VXeqOWxTRts9X384gz6dRfBpJsEMwGii2c2heGIWnixZ/pr8E3d?= =?us-ascii?Q?p089LEQBnoxe/oLhRORLDX1hjhk8/Y5JMpeU2RJoPctcdwOg3VxrR9ySweOk?= =?us-ascii?Q?NYP7WBhqzF1PMK4zp89q96EoHNpqZHjL4Rt1qi3CiLMvzSB4xXZ5hYcggB7v?= =?us-ascii?Q?/QAiYSor4mK61iWLDnnS/nvDUMQp6uXzi2hKjVUDn1ZfaPv3wnR1QzSnMs09?= =?us-ascii?Q?nVrbr7UOZaapGFmDG9hL95fw8Dn4TxdxXZDKX12Q+xItj+Yol76uwYHxlqu0?= =?us-ascii?Q?bTluree4vlR0p18h0jCG72tNouNPnelby/GJVecG3A4/TZuw+/dtkuTBksqP?= =?us-ascii?Q?Usc3TWJTeWskU/E2uKojAXcUZ03W5ZvJpV3WGhV5lQNFTw335aGqFDQoqtsV?= =?us-ascii?Q?t/Nl+PAsbXxLtnP0eiwUaHJo7mYnFBCY1dkYzolNVxcmoT4EtwvoBxHd95qh?= =?us-ascii?Q?Mpd75SeYGRYl61brK2KV43gYmL/Jr1DgCU4r5e4EHxs3LIp67aEchetBJs6K?= =?us-ascii?Q?ruRoesqeP/7Is4A7PPUpc5mhLaa67Yzh47Lap4na3FQ0qrPJNUID/L3kiN6K?= =?us-ascii?Q?1YwtNr9Iu2iwn2F5e7QAwxnM3ScUNLppH76cI1p1vf794YqmRRL4mjwrJqob?= =?us-ascii?Q?MVhWX9EMJg=3D?= X-Microsoft-Exchange-Diagnostics: 1; HE1PR08MB1195; 6:vzY/DFrciP/KJnfzowRY0wCLFuonkX71e/UGt0siQeyLLNwOtRjkdy+ASb+S6JDfVO7JtrcTu5pWIxEzRJCD1uSnJ9rXOic2hN/xMm2edCieSPbZqLBe7lf8QqyO6uw3XU2oRksl4m9/5K3+3ZIUoRhNINl1J7AgG7hInm6LOOP5Qb0xyqLJQohQK7frE98gVuHAUbapaRMUEIenE+UzPCs4zHBA5pRq2kawFY/PXl5q37LQHMOo1knH8j5ilUlb5rwq4EhkKf5uLhJRs+P506DTDVp4nRjPXIbpVKJBiVfNEesRC0fuxsyFJ0UylK3TRjodQma0HluQ4abTIrYL7g==; 5:/x9CDUkyyHXn6QiHcn9Gj3VNnRqtZZmFk+zzTsoOBf2wtL5LTQ4rEEwPZ1SSh8NzvpJ+bJ6mcPJ42oqhpkdI/M1/wk/D06QMze60XUUuhh+MNKHBuCOd0dEfb1OzYHk21QMTNS7eySiH6g+J0MOaHA==; 24:Ant5ZzkWIojnq7vx3Q2C0yA1vPF/Vkb+cdtlK4bIU2Q0uNuDhF52STXmKQ47wWeieR/fFv/33SMvCDHwY9KuNthyZfXqmK6jVUSKuDV/oCw=; 7:g9I+O6RxjD9rcrlblibeQbK3CMmt9uIyYFkFTKaY+iRKFOb7V5jir6bZ2Gpz76fV/M54wmuM60IJLRsJz/TM2EbR27ngvOUx4/eoAyLmycfM7SMIEcTKXkid8Ft9j1q+mGjkKjAxexuiDNGjw5WsGLEwt/+kNFsjebqf0bFnMFJ+wqqcbt6Hy5kLEO1ty4bu3oTS3GVOnBJst9d3P7noBLg6E35BeD43TcvJSBbYQBr7fpjmXbihMGdQ6YnStub+ SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; HE1PR08MB1195; 20:l65SfMKu+RbUeI9yQzDSlZyZxId3dmczp4Xs8ZWj40UItZAre25Bc8aC3p2vlYooZU6yi1VpFMllDq7bXZB9gYpFR7e+3BSAvEBVyuvORH335AkbBNgQuo2cStnJYZuP80809paFKaAR9fowVBgh8wqzYL1HI8UibPKZ4wFNs8o= X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jun 2016 15:51:00.2310 (UTC) X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[217.140.96.140]; Helo=[nebula.arm.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR08MB1195 X-MC-Unique: UDQyqYL6N7Oj70zjCiSMNA-1 X-IsSubscribed: yes Hi, This patch pulls the comparisons between if_info->branch_cost and a magic number representing an instruction count to a common function. While I'm doing it, I've documented the instructions that the magic numbers relate to, and updated them where they were inconsistent. If our measure of the cost of a branch is now in rtx costs units, we can get to an estimate for the cost of an expression from the number of instructions by multiplying through by COSTS_N_INSNS (1). Alternatively, we could actually construct the cheap sequences and check the sequence. But in these cases we're expecting to if-convert on almost all targets, the transforms in this patch are almost universally a good idea, even for targets with a very powerful branch predictor, eliminating the branch eliminates a basic block boundary so might be helpful for scheduling, combine, and other RTL optimizers. Bootstrapped on x86-64 and aarch64 as part of the full sequence. OK? Thanks, James --- 2016-06-21 James Greenhalgh * ifcvt.c (noce_if_info): New field: max_seq_cost. (noce_estimate_conversion_profitable_p): New. (noce_try_store_flag_constants): Use it. (noce_try_addcc): Likewise. (noce_try_store_flag_mask): Likewise. (noce_try_cmove): Likewise. (noce_try_cmove_arith): Likewise. (noce_find_if_block): Record targetm.max_noce_ifcvt_seq_cost. diff --git a/gcc/ifcvt.c b/gcc/ifcvt.c index fd29516..0b97114 100644 --- a/gcc/ifcvt.c +++ b/gcc/ifcvt.c @@ -814,6 +814,10 @@ struct noce_if_info /* Estimated cost of the particular branch instruction. */ unsigned int branch_cost; + /* Maximum permissible cost for the unconditional sequence we should + generate to replace this branch. */ + unsigned int max_seq_cost; + /* The name of the noce transform that succeeded in if-converting this structure. Used for debugging. */ const char *transform_name; @@ -835,6 +839,17 @@ static int noce_try_minmax (struct noce_if_info *); static int noce_try_abs (struct noce_if_info *); static int noce_try_sign_mask (struct noce_if_info *); +/* This function is always called when we would expand a number of "cheap" + instructions. Multiply NINSNS by COSTS_N_INSNS (1) to approximate the + RTX cost of those cheap instructions. */ + +inline static bool +noce_estimate_conversion_profitable_p (struct noce_if_info *if_info, + unsigned int ninsns) +{ + return if_info->max_seq_cost >= ninsns * COSTS_N_INSNS (1); +} + /* Helper function for noce_try_store_flag*. */ static rtx @@ -1320,7 +1335,8 @@ noce_try_store_flag_constants (struct noce_if_info *if_info) && (REG_P (XEXP (a, 0)) || (noce_operand_ok (XEXP (a, 0)) && ! reg_overlap_mentioned_p (if_info->x, XEXP (a, 0)))) - && if_info->branch_cost >= 2) + /* We need one instruction, the ADD of the store flag. */ + && noce_estimate_conversion_profitable_p (if_info, 1)) { common = XEXP (a, 0); a = XEXP (a, 1); @@ -1393,22 +1409,32 @@ noce_try_store_flag_constants (struct noce_if_info *if_info) else gcc_unreachable (); } + /* Is this (cond) ? 2^n : 0? */ else if (ifalse == 0 && exact_log2 (itrue) >= 0 && (STORE_FLAG_VALUE == 1 - || if_info->branch_cost >= 2)) + /* We need ASHIFT, IOR. */ + || noce_estimate_conversion_profitable_p (if_info, 2))) normalize = 1; + /* Is this (cond) ? 0 : 2^n? */ else if (itrue == 0 && exact_log2 (ifalse) >= 0 && can_reverse - && (STORE_FLAG_VALUE == 1 || if_info->branch_cost >= 2)) + && (STORE_FLAG_VALUE == 1 + /* We need ASHIFT, IOR. */ + || noce_estimate_conversion_profitable_p (if_info, 2))) { normalize = 1; reversep = true; } + /* Is this (cond) ? -1 : x? */ else if (itrue == -1 && (STORE_FLAG_VALUE == -1 - || if_info->branch_cost >= 2)) + /* Just an IOR. */ + || noce_estimate_conversion_profitable_p (if_info, 1))) normalize = -1; + /* Is this (cond) ? x : -1? */ else if (ifalse == -1 && can_reverse - && (STORE_FLAG_VALUE == -1 || if_info->branch_cost >= 2)) + && (STORE_FLAG_VALUE == -1 + /* Just an IOR. */ + || noce_estimate_conversion_profitable_p (if_info, 1))) { normalize = -1; reversep = true; @@ -1564,8 +1590,8 @@ noce_try_addcc (struct noce_if_info *if_info) } /* If that fails, construct conditional increment or decrement using - setcc. */ - if (if_info->branch_cost >= 2 + setcc. We'd only need an ADD/SUB for this. */ + if (noce_estimate_conversion_profitable_p (if_info, 1) && (XEXP (if_info->a, 1) == const1_rtx || XEXP (if_info->a, 1) == constm1_rtx)) { @@ -1621,7 +1647,9 @@ noce_try_store_flag_mask (struct noce_if_info *if_info) return FALSE; reversep = 0; - if ((if_info->branch_cost >= 2 + + /* One instruction, AND. */ + if ((noce_estimate_conversion_profitable_p (if_info, 1) || STORE_FLAG_VALUE == -1) && ((if_info->a == const0_rtx && rtx_equal_p (if_info->b, if_info->x)) @@ -1828,8 +1856,11 @@ noce_try_cmove (struct noce_if_info *if_info) approach. */ else if (!targetm.have_conditional_execution () && CONST_INT_P (if_info->a) && CONST_INT_P (if_info->b) - && ((if_info->branch_cost >= 2 && STORE_FLAG_VALUE == -1) - || if_info->branch_cost >= 3)) + /* If STORE_FLAG_VALUE is -1, we need SUB, AND, PLUS. */ + && ((noce_estimate_conversion_profitable_p (if_info, 3) + && STORE_FLAG_VALUE == -1) + /* Otherwise, we need NEG, SUB, AND, PLUS. */ + || noce_estimate_conversion_profitable_p (if_info, 4))) { machine_mode mode = GET_MODE (if_info->x); HOST_WIDE_INT ifalse = INTVAL (if_info->a); @@ -2082,7 +2113,7 @@ noce_try_cmove_arith (struct noce_if_info *if_info) if (cse_not_expected && MEM_P (a) && MEM_P (b) && MEM_ADDR_SPACE (a) == MEM_ADDR_SPACE (b) - && if_info->branch_cost >= 5) + && noce_estimate_conversion_profitable_p (if_info, 5)) { machine_mode address_mode = get_address_mode (a); @@ -4041,6 +4072,9 @@ noce_find_if_block (basic_block test_bb, edge then_edge, edge else_edge, if_info.then_else_reversed = then_else_reversed; if_info.branch_cost = BRANCH_COST (optimize_bb_for_speed_p (test_bb), predictable_edge_p (then_edge)); + if_info.max_seq_cost + = targetm.max_noce_ifcvt_seq_cost (optimize_bb_for_speed_p (test_bb), + then_edge); /* Do the real work. */