From patchwork Fri Apr 22 16:15:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wilco Dijkstra X-Patchwork-Id: 613780 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3qs12F3r6gz9s0M for ; Sat, 23 Apr 2016 02:16:05 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=KOtlcRic; dkim-atps=neutral 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 :content-transfer-encoding; q=dns; s=default; b=vs7DBOjDwGdxvOXa SjmpTkgcAt+yWnK1wbtpzq7PYjLyahHv9wXqV6d+r261kNp8Zi52vVyP8MvMNcph 83Tr7dkgG3MUT4friWODkqF39A5htptUhmRGb2JoV2yrBnVUUNPwuV7KHkm3BN4Q pIv0XRtLRW83xfYLm2NWiqSWGds= 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 :content-transfer-encoding; s=default; bh=v61rC4/wYzOnUBu78aOp1G PMIgQ=; b=KOtlcRicvhSuTU+OqFdyS1ZuUuvmNCN+3G646zNBqbaKUtu1R6GlhX APoEhv1Swy9SgbZMIe16BR/lwOtOO8l9QrbkeJu/34ksttEgSzTWKHzZVPrXWNyT wofYQ1hM7KJTAZn8pqrdR8oRk7hnq+hhAp/izOLifYoplGYfVPkII= Received: (qmail 125441 invoked by alias); 22 Apr 2016 16:15: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 125428 invoked by uid 89); 22 Apr 2016 16:15:55 -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=1-2, H*MI:outlook, H*MI:prod 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; Fri, 22 Apr 2016 16:15:45 +0000 Received: from emea01-am1-obe.outbound.protection.outlook.com (mail-am1lrp0011.outbound.protection.outlook.com [213.199.154.11]) (Using TLS) by eu-smtp-1.mimecast.com with ESMTP id uk-mta-28-iiYOQSzJQFukLJb0is6wjA-1; Fri, 22 Apr 2016 17:15:39 +0100 Received: from AM3PR08MB0088.eurprd08.prod.outlook.com (2a01:111:e400:8847::18) by AM3PR08MB0085.eurprd08.prod.outlook.com (2a01:111:e400:8847::15) with Microsoft SMTP Server (TLS) id 15.1.466.19; Fri, 22 Apr 2016 16:15:38 +0000 Received: from AM3PR08MB0088.eurprd08.prod.outlook.com ([fe80::d0af:2d98:cf1b:e43e]) by AM3PR08MB0088.eurprd08.prod.outlook.com ([fe80::d0af:2d98:cf1b:e43e%17]) with mapi id 15.01.0466.023; Fri, 22 Apr 2016 16:15:38 +0000 From: Wilco Dijkstra To: "gcc-patches@gcc.gnu.org" CC: nd Subject: [PATCH][AArch64] Improve aarch64_case_values_threshold setting Date: Fri, 22 Apr 2016 16:15:38 +0000 Message-ID: x-ms-office365-filtering-correlation-id: c8489333-9c1d-42e0-f381-08d36ac957b7 x-microsoft-exchange-diagnostics: 1; AM3PR08MB0085; 5:0e5MKgt46BXELJMB9mpRhRWzsgDAz5X8YJXX31RRBwMRhz5G7r4GLPmO6Dxhn6PC57c0S3lh8BM62zcxMPE9HBSgI13T+P7kPrVIGt93If3ifsd5+PQ4IZ9n0lRdxOZSvze437iJw2JW0qYC6ah4/B/R+sEplTQsUaBdssWKXL58sGQQvTcz+1B4piiO7j9h; 24:pw1PQK32c82+ib2yn6oEFgR6QbmMgNJuG5V6hq6XAjydkHtrjscLf8jgi3fg5ZUy/73ChiULdeuYEHcbsKBCx0lSRo6iyBAw3xMjn9H+TsI=; 7:1iti0b9euyycxiIIhhwdszN8CufKodFoIbAuM2Eutwif3Dmie6GWLqGbrfJwX34MgclczRbVRTZdJd20DkyaHAq2J69v77hfjBVmQ0iA/oQimTDuk2QPtPCR2WXkM4C8RHqxPMJT3o2pKmfItW7Z3WLr3CbcJrEHw4z16mDZ4O28BPB0tDE5qZRPKy/syu9fv2KB2beX5mmmsMzsoUexVFOlasagXjSWybf2eks+QQw=; 20:bi6Ne7r9qDDsLOhyL8IBLe3+P9TyuXyCgctYN6L4vLLs11x4ZYR8bMlxV5rvMV0deanW2YG1ULJoAVcgS5oQTP0b8sfoMhgte1CqqMmIAWg4nCNXrHQBy0A6dscBfSKc0kRRF0KCvFL6tFtg488w5TtDjy+233i5+c+GZ9NnnMc= x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:AM3PR08MB0085; nodisclaimer: True x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(9101521026)(601004)(2401047)(5005006)(8121501046)(10201501046)(3002001); SRVR:AM3PR08MB0085; BCL:0; PCL:0; RULEID:; SRVR:AM3PR08MB0085; x-forefront-prvs: 0920602B08 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(6009001)(377424004)(3660700001)(5250100002)(229853001)(5008740100001)(87936001)(2351001)(1220700001)(189998001)(86362001)(2501003)(76576001)(4326007)(81166005)(6116002)(74316001)(102836003)(3280700002)(3846002)(1096002)(5002640100001)(11100500001)(54356999)(106116001)(50986999)(92566002)(19580395003)(2906002)(9686002)(5003600100002)(19580405001)(110136002)(33656002)(5004730100002)(450100001)(586003)(66066001)(2900100001)(15760500001); DIR:OUT; SFP:1101; SCL:1; SRVR:AM3PR08MB0085; H:AM3PR08MB0088.eurprd08.prod.outlook.com; FPR:; SPF:None; MLV:sfv; LANG:en; spamdiagnosticoutput: 1:23 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-originalarrivaltime: 22 Apr 2016 16:15:38.0922 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM3PR08MB0085 X-MC-Unique: iiYOQSzJQFukLJb0is6wjA-1 GCC expands switch statements in a very simplistic way and tries to use a table expansion even when it is a bad idea for performance or codesize. GCC typically emits extremely sparse tables that contain mostly default entries (something which currently cannot be tuned by backends). Additionally the computation of the minimum/maximum label offsets is too simplistic so the tables are often twice as large as necessary. The cost of a table switch is significant due to the setup overhead, the table lookup (which due to being sparse and large adds unnecessary cachemisses) and hard to predict indirect jump. Therefore it is best to avoid using a table unless there are many real case labels. This patch fixes that by setting the default aarch64_case_values_threshold to 16 when the per-CPU tuning is not set. On SPEC2006 this improves the switch heavy benchmarks GCC and perlbench both in performance (1-2%) as well as size (0.5-1% smaller). OK for trunk? ChangeLog: 2016-04-22 Wilco Dijkstra gcc/ * config/aarch64/aarch64.c (aarch64_case_values_threshold): Return a better case_values_threshold when optimizing. diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c index 0620f1e..a240635 100644 --- a/gcc/config/aarch64/aarch64.c +++ b/gcc/config/aarch64/aarch64.c @@ -3546,7 +3546,12 @@ aarch64_cannot_force_const_mem (machine_mode mode ATTRIBUTE_UNUSED, rtx x) return aarch64_tls_referenced_p (x); } -/* Implement TARGET_CASE_VALUES_THRESHOLD. */ +/* Implement TARGET_CASE_VALUES_THRESHOLD. + The expansion for a table switch is quite expensive due to the number + of instructions, the table lookup and hard to predict indirect jump. + When optimizing for speed, with -O3 use the per-core tuning if set, + otherwise use tables for > 16 cases as a tradeoff between size and + performance. */ static unsigned int aarch64_case_values_threshold (void) @@ -3557,7 +3562,7 @@ aarch64_case_values_threshold (void) && selected_cpu->tune->max_case_values != 0) return selected_cpu->tune->max_case_values; else - return default_case_values_threshold (); + return optimize_size ? default_case_values_threshold () : 17; }