From patchwork Thu Jun 2 16:53:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Greenhalgh X-Patchwork-Id: 69197 Delivered-To: patch@linaro.org Received: by 10.140.106.246 with SMTP id e109csp217312qgf; Thu, 2 Jun 2016 09:55:59 -0700 (PDT) X-Received: by 10.66.246.234 with SMTP id xz10mr6953714pac.24.1464886559028; Thu, 02 Jun 2016 09:55:59 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id d8si23903666paz.87.2016.06.02.09.55.58 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 02 Jun 2016 09:55:59 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-428927-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-428927-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-428927-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=dlIwMIza/eb9Xcjo +u1x4S6B1Zr6cUrUY95/jaVftgtaQmQDV7qQAfb1SdyYd1WEeJLsAX6A3veZrm0y Ur+ogKR+ERV6M12rJ1qwcIgjhNAvBqARL3NBcncakrvPkMCMkVtv2icV84d6/+Ec kL7ydJiEy7vmYAB+8LB/N4QJllA= 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=xl0skB0rY3yOUJ0USs4Y+v YGCC0=; b=DhpBlc5YqJkCct2fwyrc5p/+htWBMvAinTXbLfy3NqBfGu0LHzzO/3 KKlYFiCJfbKi2XAX3rVoY4p+spTqhiI4wOJ8zQI0BY4tnoFaqUPp2uEWX7Cevmyy BNszWBqsUhy8brpWBEAfEepj+3mmZZA2mmXkdesc29iq+QWkSYmGc= Received: (qmail 26113 invoked by alias); 2 Jun 2016 16:55:45 -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 26096 invoked by uid 89); 2 Jun 2016 16:55:44 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.5 required=5.0 tests=AWL, BAYES_00, SPF_PASS autolearn=unavailable version=3.3.2 spammy= 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; Thu, 02 Jun 2016 16:55:33 +0000 Received: from emea01-am1-obe.outbound.protection.outlook.com (mail-am1lrp0010.outbound.protection.outlook.com [213.199.154.10]) (Using TLS) by eu-smtp-1.mimecast.com with ESMTP id uk-mta-20-LSAXtM5NSSuqbWAXMyClIg-1; Thu, 02 Jun 2016 17:54:17 +0100 Received: from DB4PR08CA0007.eurprd08.prod.outlook.com (10.161.12.17) by AM2PR08MB0018.eurprd08.prod.outlook.com (10.161.21.18) with Microsoft SMTP Server (TLS) id 15.1.506.9; Thu, 2 Jun 2016 16:54:15 +0000 Received: from DB3FFO11FD045.protection.gbl (2a01:111:f400:7e04::191) by DB4PR08CA0007.outlook.office365.com (2a01:111:e400:9853::17) with Microsoft SMTP Server (TLS) id 15.1.506.9 via Frontend Transport; Thu, 2 Jun 2016 16:54:15 +0000 Received: from nebula.arm.com (217.140.96.140) by DB3FFO11FD045.mail.protection.outlook.com (10.47.217.76) with Microsoft SMTP Server (TLS) id 15.1.497.8 via Frontend Transport; Thu, 2 Jun 2016 16:54:15 +0000 Received: from e107456-lin.cambridge.arm.com (10.1.2.79) by mail.arm.com (10.1.106.66) with Microsoft SMTP Server id 14.3.294.0; Thu, 2 Jun 2016 17:54:13 +0100 From: James Greenhalgh To: CC: , , , , , Subject: [RFC: Patch 2/6] Factor out the comparisons against magic numbers in ifcvt Date: Thu, 2 Jun 2016 17:53:54 +0100 Message-ID: <1464886438-17892-3-git-send-email-james.greenhalgh@arm.com> In-Reply-To: <1464886438-17892-1-git-send-email-james.greenhalgh@arm.com> References: <5617A4DE.6020004@redhat.com> <1464886438-17892-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)(2980300002)(438002)(377424004)(199003)(189002)(5008740100001)(104016004)(8936002)(19580395003)(19580405001)(50986999)(11100500001)(76176999)(6806005)(92566002)(8676002)(4610100001)(84326002)(568964002)(4326007)(586003)(189998001)(110136002)(2906002)(87936001)(2476003)(5003600100002)(2351001)(86362001)(77096005)(2950100001)(229853001)(50226002)(33646002)(5890100001)(512874002)(36756003)(106466001); DIR:OUT; SFP:1101; SCL:1; SRVR:AM2PR08MB0018; H:nebula.arm.com; FPR:; SPF:Pass; MLV:sfv; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; DB3FFO11FD045; 1:PPLp4TZEr2vEa1H8LxE2I1LJg8CjkRIZsmdzZUWmxqMVLuNIEWelItirn1DxiSSJ9kzWNIRbpcY/poS+/ForRwqNOzUZVmpAec03FBHMkcgDS51akgHduTJvowt9qtheVWqNfrkiGA/U31r9YaG4rsyU2vMK3cOrKTH3hlTYNBcS8Oy+/+Dzrb+v6lkZds/l2P2Lf75WU+Hl+J07tCAg6XlCZWAlskJfFMbEvBicCmIBZmN6SZrUqQ7ZG33B/259xjv+iYR3pwjyv4zeZ+65A4O4xcnbknLV7+w1tkZJiYMIRyw0ji+fCTBm5l9MHHVdfW1lYIxCRJPwFKQ8/8nYnohbFIeTdgDsjujEiqPBzer6K6Ld0wSw9xvzGMCXIsgym2KN8Mlify0kGorkYAAScFNxKyIhLOi8BDrMFtUFX7kaYfJGxoH1XNJDY++EwfRqEJ7sPfhwSwpcQb203RAWVPnX/bVoZESqgoWsibOjF9OayEq3iCKo5gA+WM2qP1zJl+No/NCIywy7e1mgRmnCGWs+PW0ASta6OWesYaRAKKeZTdqy0ROSzqtTUaQDJWLb X-MS-Office365-Filtering-Correlation-Id: 7ded6df2-83fd-4a77-2852-08d38b0687dd X-Microsoft-Exchange-Diagnostics: 1; AM2PR08MB0018; 2:6D7zHUwjz51nzXPx61pg5XgIHk/LUyAMzhetvNSkgfC3fV9QbEnE2M954i2pl1JtJkqXnGB+UFRJNCMFdMGkCpFEzWU76TenGM1mCMBeQqVMVWn72/m1XYYJq1YPm7NV28MoF5zDk7j5Zc+zN2TQZPd95S8isU0T2K0F29gwlkA3z5tYtKX3nyoRT2lMVRMn; 3:qFT8rANu8kFFv0FidKrPVmUIjQiK7VoTiQWWpffvpCy3Rei0qlfvlZ3+Jh4IO1mTGxdXjuzHqSWpS/slaPnrvhHKnuuJ/8s3WhNFJV2KUkkhcE3J29vglyUxHyxYBduSFKLtdhxZyW5N6qp/LlZycQySWQe23Z+va5AytVSAvZTb2ZolP23sR1s8eShNaAH8S2kFqcZJ/YGZdMKGzquip6fy2iP+oBUzaIPfefo0jJ4ioHK9+1RcH7cxoyJbyTAGllNseWw0fQ1SicJVD6oQDg== X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(8251501002); SRVR:AM2PR08MB0018; X-Microsoft-Exchange-Diagnostics: 1; AM2PR08MB0018; 25:As4ZjHc8+dXORhdkVrSUb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dRSAe9eFILftHLXvAelLT0IQAFlgipY2btouBLFfVJQcvECZ69y1jR5qum6uT8zOgFfqf9oa+VWRgJcwWARD9D2ywErZxiE772rSQl2iuHQJ/6N0k3bfkhgVqUyi7B+vaeBgtVjuKbmrV7Du6kEkcZgpDcnd0bODTRKlDoB01rFHXN; 4:ZdqyMZFq4kdqjwjWaJ8Tfj2ndy6ZZB/kezdrYPDu+MxeF4FKyp5nZ+vh8KJColgqDjhmQksv3lThl0C44HmRXhrhyhbSmkL2lTEVQHb4kIBEU3Yfa8t8uxHXv1YQVKiY1qTXjcJHKUeZnjG9KWLZO+6IM+MtKt4SYMkAuKAoNQNQwTvxpbOe89qboQU7Eh462yN0mMV3fmYcVAivxmJCe5MBjxcjZGqUF55/4/WUQ0sIsbZqSxXTlOBU5U9lfnBSWrrEYRmL38fOuzPWN3orWewli6isaEA8ZUq9lFGrp6u6/sXDZv9TmcQJrKLIkgichmmRXAp0gznIlw6ytNeEfDHXohGkzWRqkFic0RQu80mpESL2H1m0CptAc1zbTHPL8w7u6o0lWXOeGvTDyiTaBJkPHu0LZRjFY0CqiJvPXScoPwq3qmVgrrnaI6hmwMMNgph91X7TwxRYGjJxggnGo9IAZm4CgQtFfgtR5XjDbx7MWYq2DhQKthq6k5ysS6Pgh2x4lBiahEHb3HEFnkHVCw== 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)(8121501046)(5005006)(13013025)(13024025)(13023025)(13020025)(3002001)(10201501046)(6055026); SRVR:AM2PR08MB0018; BCL:0; PCL:0; RULEID:; SRVR:AM2PR08MB0018; X-Forefront-PRVS: 0961DF5286 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; AM2PR08MB0018; 23:A8nNK8UA0sgMTJnunmlTXvZtTDzA1dvd63IjEoBTD?= =?us-ascii?Q?ULHqo0TDGoR2i0MYNzGmPOdkh+O5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PJq6WLPw97/H3v04fjhybLHJQBCOt0vLw22PqaQBj1w59C34?= =?us-ascii?Q?V2Gb5NiGFvLCQaCVsZW6QHB41kc+42faX2B5ixmP5ZiMw=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1; AM2PR08MB0018; 5:wG4iEf2OL2CizgT7JSZujiS5tU4Z5SsKSMMW9eCfiOt6dTELCWmGhV9RTWq6ksgixUJ0JVZFxI9xmA+FHypFpaYIye9bnNypJCVpO9Qjycy1VZfUEiRUQAe0oRaAIf4PDe1SHXyVVtQ1pgzbl5Tgww==; 24:2TCI908P3OJRJdpa7gFrSEWIkM4y6Oj9hsnw1sCRjvj31LzmdrMVKPxMkLNyxjyjSZp1jxOlrg3hAchfCGrTBc4ZYOAvfVotexvB5LEsSN8=; 7:YvTv1leGeiReplxlet9f8OteEk0gih8W3LQLBVz022qSaAzK05ExHPS4WzzkR7vX06x7b1k952h5D141RIzvXmYNBMRNZOouY1IWZaEW5IyU/IVMBSx+Hi6GgzEpumNvqedS8VFthaqiRAsIqRCZfKFj0WSxs3ZFJU78LTNSQvsV2fa5l8HdwXiyjDcT6nKl; 20:i64jT/6tevUsyIA5Bamms+8NgG2XC9dGBnDuCVvDQkorSraQbkiuJv49RxsV0N8IF7RecDJQ2Soo12EtxkeN0jbUoXN98kES8yaadL04hjvL+XIhu3BQlJnv8VLWegTshqK+tjwzZlqN9QTYvgUO9uLjMAXLAV0xX+8+i1LUWm8= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jun 2016 16:54:15.2202 (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: AM2PR08MB0018 X-MC-Unique: LSAXtM5NSSuqbWAXMyClIg-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). This isn't the great revolution in ifcvt costs I hoped for when I sat down to take on the work. But, it looks like the best I can do short of constructing ADD and SUB rtx all over the place just to get back a judgement from the target that they are "cheap". The nicest thing about doing it this way is that it mostly preserves behaviour, and by factoring it out we have an upgrade path to a more detailed cost model should we want it. OK? Thanks, James --- 2016-06-02 James Greenhalgh * ifcvt.c (noce_if_info): New field: rtx_edge_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.rtx_edge_cost. diff --git a/gcc/ifcvt.c b/gcc/ifcvt.c index 44ae020..22cb5e7 100644 --- a/gcc/ifcvt.c +++ b/gcc/ifcvt.c @@ -813,6 +813,7 @@ struct noce_if_info /* Estimated cost of the particular branch instruction. */ unsigned int branch_cost; + unsigned int rtx_edge_cost; }; static rtx noce_emit_store_flag (struct noce_if_info *, rtx, int, int); @@ -830,6 +831,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->rtx_edge_cost >= ninsns * COSTS_N_INSNS (1)); +} + /* Helper function for noce_try_store_flag*. */ static rtx @@ -1279,7 +1291,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); @@ -1352,22 +1365,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; @@ -1519,8 +1542,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)) { @@ -1575,7 +1598,9 @@ noce_try_store_flag_mask (struct noce_if_info *if_info) return FALSE; reversep = 0; - if ((if_info->branch_cost >= 2 + + /* Two insns, AND, NEG. */ + if ((noce_estimate_conversion_profitable_p (if_info, 2) || STORE_FLAG_VALUE == -1) && ((if_info->a == const0_rtx && rtx_equal_p (if_info->b, if_info->x)) @@ -1778,8 +1803,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); @@ -2031,7 +2059,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); @@ -3967,6 +3995,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.rtx_edge_cost + = targetm.rtx_branch_cost (optimize_bb_for_speed_p (test_bb), + predictable_edge_p (then_edge)); /* Do the real work. */