From patchwork Fri Dec 18 13:52:41 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Greenhalgh X-Patchwork-Id: 58665 Delivered-To: patch@linaro.org Received: by 10.112.89.199 with SMTP id bq7csp1039243lbb; Fri, 18 Dec 2015 05:53:09 -0800 (PST) X-Received: by 10.98.11.7 with SMTP id t7mr5332926pfi.51.1450446789526; Fri, 18 Dec 2015 05:53:09 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id y75si15643134pfa.45.2015.12.18.05.53.09 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Dec 2015 05:53:09 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-417700-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; spf=pass (google.com: domain of gcc-patches-return-417700-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-417700-patch=linaro.org@gcc.gnu.org; dkim=pass header.i=@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:mime-version:content-type; q=dns; s=default; b=RjBuDUG11R8kuAPhtSw3XqvQsQVEoyDUrtpIIbfef8PLkx6TKZ y+MaG1tdEVzexCDxnAslA/vg9BUgiOAmgqdFFuhFHUzt/AsSihNp4cV88ga7qUrm OUXRR17s4ek7lnTAcx+QINjg7RBa52UN6KT8HUzWKR9tqhcSfRMZwNDtY= 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:mime-version:content-type; s= default; bh=6rMsbJo9ptklP0yMekE6dIuxjWM=; b=jeHeb0TObgXal1w74P+i eQUWz+toiwJYVWrEkdPNdJzggOGdFojRAodYcQsvBFomXTyeTkY3xf5NCZ/eDpHc 8DRpuviqcl+CrXuGl31TA5PvUUIFbL3IHaqY0Wny+bWzvHfzrTM1Qjw4TlDpzXI7 Q/benxkaUKkol/drW1bTfq8= Received: (qmail 46601 invoked by alias); 18 Dec 2015 13:52:57 -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 46575 invoked by uid 89); 18 Dec 2015 13:52:56 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL, BAYES_00, SPF_PASS autolearn=ham version=3.3.2 spammy=327, UD:cfganal.h, cfganal.h, cfganalh X-HELO: eu-smtp-delivery-143.mimecast.com Received: from eu-smtp-delivery-143.mimecast.com (HELO eu-smtp-delivery-143.mimecast.com) (146.101.78.143) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 18 Dec 2015 13:52:55 +0000 Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-db5eur01lp0175.outbound.protection.outlook.com [213.199.154.175]) (Using TLS) by eu-smtp-1.mimecast.com with ESMTP id uk-mta-15-K0JJeS6ZS3yPb0Kxugqh0g-1; Fri, 18 Dec 2015 13:52:49 +0000 Received: from VI1PR08CA0036.eurprd08.prod.outlook.com (10.164.95.46) by DB5PR08MB0856.eurprd08.prod.outlook.com (10.164.43.22) with Microsoft SMTP Server (TLS) id 15.1.361.13; Fri, 18 Dec 2015 13:52:48 +0000 Received: from AM1FFO11FD048.protection.gbl (2a01:111:f400:7e00::154) by VI1PR08CA0036.outlook.office365.com (2a01:111:e400:597a::46) with Microsoft SMTP Server (TLS) id 15.1.361.13 via Frontend Transport; Fri, 18 Dec 2015 13:52:47 +0000 Received: from nebula.arm.com (217.140.96.140) by AM1FFO11FD048.mail.protection.outlook.com (10.174.65.211) with Microsoft SMTP Server (TLS) id 15.1.355.15 via Frontend Transport; Fri, 18 Dec 2015 13:52:47 +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.266.1; Fri, 18 Dec 2015 13:52:42 +0000 From: James Greenhalgh To: CC: , , , , , , Subject: [Patch ifcvt] Add a new parameter to limit if-conversion Date: Fri, 18 Dec 2015 13:52:41 +0000 Message-ID: <1450446761-5209-1-git-send-email-james.greenhalgh@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1; AM1FFO11FD048; 1:Zm0mwywTUNy/25uw/G24emDed2SDvrIT64yASG99i/vBMYn2IvudT0g3Q6IgatKC7cplNwB0Yan2DnUaDNtv6Ew0sL2+PNYX2DTKTadf0O4PBypo/QQSQ4eQ8Qb0jZliuk3w4PFRpYH26yg1SeX7id3081GTcKztFzvXGR50mm9qB6BkFmQdQ3OW21BNALPxLBbbmpzSt1sTvdJlLp7otvBFgS0cMX/ln7USwc2VaQ66clMoed+z7oq4OB4NUkEdhejPrA8lFDwE2QGtSo7s/BPbE3tcVzczyXIvsIRkm5NbXB0JX5YVMyu0qDf3OQVxsz9d4Y/jECkJfXm4cZy90cBZhhQJapog6Qss0nZBE9n/U+StyVUTxpul2uhomIZAplcOruAGJsZ1Fa3F1OwZ9Q== X-Forefront-Antispam-Report: CIP:217.140.96.140; CTRY:GB; IPV:CAL; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(2980300002)(438002)(199003)(164054003)(189002)(377424004)(4610100001)(77096005)(106466001)(104016004)(86362001)(87936001)(26826002)(19580395003)(33646002)(2351001)(1096002)(19580405001)(229853001)(512874002)(36756003)(2476003)(84326002)(5008740100001)(1220700001)(110136002)(5000100001)(5003600100002)(6806005)(5890100001)(50226001)(11100500001)(586003)(50986999)(4001150100001)(92566002)(189998001)(568964002); DIR:OUT; SFP:1101; SCL:1; SRVR:DB5PR08MB0856; H:nebula.arm.com; FPR:; SPF:Pass; PTR:fw-tnat.cambridge.arm.com; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; DB5PR08MB0856; 2:5sfG3IfzHqckx14xWMWglyBpCxKbv0HoPMrSp8gSRKpxXUtWvzt1xIQ9ZQtklEEqm3WxQtxvYNy1l94950S+hBCbyO79DCne43KOK8jEC+rbWn80r9rwNS6POPxNlJA0XsVEke04vILzN5r2Z4nPhQ==; 3:7qS2gXft9+jG/p9PpjKhdApgMTr2g8j8Z0+NxCEmMmcmqkeco98GRK98ILXoy118NoDDpWr2VIR37rrhMKZsjR+nLL2/sm0fcJLWmyGfXZA+kp9Vf8Nozg7O3oBGuM/8kE+jfFuHar+l1V8xqfGVnEL1ztu1ERg7hPWu/3gCH+yRB029LGY0deO/A9epVdGI5S+tAdy/lTBJ0YfGuINBcvUZ1e/JhtCaAX47voofnuQnh464O7WyLfMjXe79VBmojmejeSDQB0Cn1vrUcTrP8A==; 25:SXh9mMEIslLmc8KTnRPRFQwjCHCyVlaphQUpLL/1M6vNENLmY36aZVJoHXPfpYNCCBIgGdqwCLIh2nJ8R2wuICIGjOcKur7ojslN7K5OXBW7LDSfpbUAHGs9Hu8RBBt1EHOIt9d7yIGbvcZDJ8q1RfawawhOmEvwgIvXA658WQEEkanj7+OeDGlqpT0QFbLQSHcjmrs8al0KZQnLPzcLj+fYUR3hyC7bN2oRYq1YS/zmgpsSwuQB11eY9YONMQo4Bi69QIS65sqnjoWcvx1NWg==; 20:dGiZUOOrwyBIwuX04kjWKwC9gvDL5xVVxOagZvyXcI6/0zFtDq4NG95zrtSZLUbTrkX/IJtLPWQxHhWSNIBkHRBc4+yMciQcQhZhhxTcTOmLTq+2o7StidrAmC7VZ+L81mTQXOz3eEGWZzTrKvgySv5HtfroVHPmxvbhPO3BQ/Y= X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(8251501001); SRVR:DB5PR08MB0856; NoDisclaimer: True X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(180628864354917); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(520078)(8121501046)(5005006)(10201501046)(3002001); SRVR:DB5PR08MB0856; BCL:0; PCL:0; RULEID:; SRVR:DB5PR08MB0856; X-Microsoft-Exchange-Diagnostics: 1; DB5PR08MB0856; 4:gIYA3ROET3DbtSMz3IEm0gFw95arXNCDqlaF+tHjxjF3SzcDsz9Z58FHtxChKAolpx6YUFXVETKlvPP/Dy3aOoDTBgyBnMRySphQCYQ7DT0+mrOUTYwpi/YBhwobSP2UbAgd7SIq6BxK4G1w3rXHWvmr1RbEBocG45d0er/T/Sp93M+C4Gv7K4cp86ERXvt6pV6HKAGQ6MAHZdtAC5EcWxjQQqc4UfXdrDbA88SUaF6h2eTX/hMP0rzAz39MnEfCf8b8yghw3k45L3ZIk6k9dg9QJpMAL6OqNGx8KgAJXltoZ4gF+tj1jJ4mPFgtoF6/6zEmQZCqPIwV8jnosRR8r1uOIR4hEnhqcVw+AZ6Ls3hIGMTYGJDroRy2BcrblQKPiF2Z0lRDrF8ain2O/IV5Bsj4yNN8CIafErmuSL/AattVxMp8qmK03exKYXsvJihg X-Forefront-PRVS: 07943272E1 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DB5PR08MB0856; 23:Q/y6Bd4hmSIIGS7Ib8g74+FXPGxpk1EsSvCAngoGH?= =?us-ascii?Q?rveShT2ym17Uy8T/HcOiCKRBeeQTQ+YTpA68Y6g2IsfLE1oOjnpHz8toNd+y?= =?us-ascii?Q?m2WatxVNiRZLSxcIr+8Vs/6LRhK1wdAtDGk1BQy5onJpnCKDNjk/VaY//V/j?= =?us-ascii?Q?yn3UoscIaVa4yItgqvTze/EjnJS+JUbRH2hjQTMRV9C+iVShEXTB7VKYdhwY?= =?us-ascii?Q?udWH9VT0gbBpr9ygk7YqwuHCw+++7qx/E9gXejqZOMqs6rKxT7OM7W54iY/O?= =?us-ascii?Q?whnDXHCcrYDuF4rnmlrPUEJ3uk7PxBVy9ialAWFNVezJiOSwn6uUtJLAnPHg?= =?us-ascii?Q?IyU3M+tRuup9WRi+qp5w2wHOaLJZnJIk0dfpwBgNrdUxfP3f2Yz64XYullyW?= =?us-ascii?Q?lwo/hjGNFac4lIcfIvsN75ftxdoMdOFqpPkckywT5UThNVbfO5w72n3hsUoo?= =?us-ascii?Q?1IKp7XYqsgC19oCz02/Qa2GSbEPI75qqM/zxVwJvjOLnq1SN/vczU+/uS49R?= =?us-ascii?Q?h7v5fYhtPebLmc1xdd5fkK0T9rD4kWT3/2iedGYx49AWerZtsyj+Je1CpA0p?= =?us-ascii?Q?5DrBlhT21MzqLKZdP0PC77kZiMJayq2BgXIdxQ30EE2mJc3h31Az09wIZs0/?= =?us-ascii?Q?TWfMC5d7tlcOPA9wajPrMhVlW7ReKssQUtBv3EkIDAHqA7OePiEttCRP08Da?= =?us-ascii?Q?haeJmksP5k4w6bAFIvm60D1rsE8h/q6uWqJVJB26jW3n1/CbohofTzJhL/Q6?= =?us-ascii?Q?iXUg2C8ZCIKV90vkfpIEVNpwEBpBJDsMz1IChmZTsFNe3NrjbqFmxpoPlHHA?= =?us-ascii?Q?E55tnp4pLWvGWWW8TiFsKJdpEYnS6poUC6+rsnDhWkLme73KSlskwe2V/Bey?= =?us-ascii?Q?T4Lx6aXqsqK4vJnW/gGnZs6uBYFIZ8Gz7d7gps1qIH1zIipMfHL29cSm2EkK?= =?us-ascii?Q?/9+GgOLcF4ZOe/GeC76DEAMEn47nYbm+n3ihbWgeo8hUR75Vr1/vCHGO5Bbn?= =?us-ascii?Q?EZv/ieP0ukUTC7EAptMgDjv9Di7YD79XaijDMYpzg35sJmu6Hv7xgCdS+yan?= =?us-ascii?Q?tG7ZUw=3D?= X-Microsoft-Exchange-Diagnostics: 1; DB5PR08MB0856; 5:U9mlNWWnxVeUqcXHKMqr7kBlnDq2uZKq0GV9EXieInMp11BmvFIKCNJ6d/LJRj3s5eds+cM+9UGXx5/RgcbYr3sDDMmZI17lvszLWGLDnIW7cJO+EDovC2KsAhWrPtSMTIZtU7baLuF/iR6mK0ZDww==; 24:H1NW0tSz74mRFJOJWB155m/Ij1UEQanKrc2LG4x5DfGZ2nqCba8MsnRqlMVOA71SpeTnFH2TNjG3NcOkUXa7bJg0xEwUqedSY22SvG6riVw=; 20:vb7yUJmNyl2VH2oUf+PpOGjTRe4/tDutxVd3DGMYwhCbESG5AmMWUdKAJq1cfhGjZMAPiAwfe4mGzGjHmX3p/3Kg3jFf+ZLMsM1oXB5ltRRL7nTub+Mp4i/oAQZne4mHqaJSuqy0nZYyCXUbBJYor0U/dSekChx0lvaU+ICzx8o= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Dec 2015 13:52:47.4670 (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: DB5PR08MB0856 X-MC-Unique: K0JJeS6ZS3yPb0Kxugqh0g-1 X-IsSubscribed: yes Hi, PR68920 talks about undesirable if-conversion in the x86 back-end. The if-conversion cost model simply uses BRANCH_COST (I want to revisit this for GCC 7), but BRANCH_COST is overloaded in the compiler and reducing it causes other optimisations to be disabled. Consequently, to fix the PR we want something new that the target can set to override BRANCH_COST and reduce the number of instructions that get if-converted. This patch adds this mechanism through a param. Bootstrapped on x86_64-none-linux-gnu and aarch64-none-linux-gnu. OK for trunk? Thanks, James --- gcc/ 2015-12-17 James Greenhalgh PR rtl-optimization/68920 * params.def (PARAM_MAX_RTL_IF_CONVERSION_INSNS): New. * ifcvt.c (noce_find_if_block): Limit by new param. * doc/invoke.texi (max-rtl-if-conversion-insns): Document it. gcc/testsuite/ 2015-12-17 James Greenhalgh PR rtl-optimization/68920 * gcc.deg/ifcvt-5.c: New. diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 9b3e2fe..1f9b0fe 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -10341,6 +10341,14 @@ In each case, the @var{value} is an integer. The allowable choices for When branch is predicted to be taken with probability lower than this threshold (in percent), then it is considered well predictable. The default is 10. +@item max-rtl-if-conversion-insns +RTL if-conversion tries to remove conditional branches around a block and +replace them with conditionally executed instructions. This parameter +gives the maximum number of instructions in a block which should be +considered for if-conversion. The default is 10, though the compiler will +also use other heuristics to decide whether if-conversion is likely to be +profitable. + @item max-crossjump-edges The maximum number of incoming edges to consider for cross-jumping. The algorithm used by @option{-fcrossjumping} is @math{O(N^2)} in diff --git a/gcc/ifcvt.c b/gcc/ifcvt.c index 6164232..2674baa 100644 --- a/gcc/ifcvt.c +++ b/gcc/ifcvt.c @@ -32,6 +32,7 @@ #include "regs.h" #include "emit-rtl.h" #include "recog.h" +#include "params.h" #include "cfgrtl.h" #include "cfganal.h" @@ -3944,6 +3945,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.branch_cost + = MIN (if_info.branch_cost, + (unsigned int) PARAM_VALUE (PARAM_MAX_RTL_IF_CONVERSION_INSNS)); /* Do the real work. */ diff --git a/gcc/params.def b/gcc/params.def index 41fd8a8..a0d9787 100644 --- a/gcc/params.def +++ b/gcc/params.def @@ -49,6 +49,15 @@ DEFPARAM (PARAM_PREDICTABLE_BRANCH_OUTCOME, "Maximal estimated outcome of branch considered predictable.", 2, 0, 50) +/* The maximum number of insns in a basic block to consider for + RTL if-conversion. A target might use BRANCH_COST to further limit the + number of insns considered. */ +DEFPARAM (PARAM_MAX_RTL_IF_CONVERSION_INSNS, + "max-rtl-if-conversion-insns", + "Maximum number of insns in a basic block to consider for RTL " + "if-conversion.", + 10, 0, 10) + DEFPARAM (PARAM_INLINE_MIN_SPEEDUP, "inline-min-speedup", "The minimal estimated speedup allowing inliner to ignore inline-insns-single and inline-isnsns-auto.", diff --git a/gcc/testsuite/gcc.dg/ifcvt-5.c b/gcc/testsuite/gcc.dg/ifcvt-5.c new file mode 100644 index 0000000..fc6a2ca --- /dev/null +++ b/gcc/testsuite/gcc.dg/ifcvt-5.c @@ -0,0 +1,19 @@ +/* Check that multi-insn if-conversion is not done if the override + parameter would not allow it. */ + +/* { dg-options "-fdump-rtl-ce1 -O2 --param max-rtl-if-conversion-insns=1" } */ +int +foo (int x, int y, int a) +{ + int i = x; + int j = y; + /* Try to make taking the branch likely. */ + __builtin_expect (x > y, 1); + if (x > y) + { + i = a; + j = i; + } + return i * j; +} +/* { dg-final { scan-rtl-dump "0 true changes made" "ce1" } } */