From patchwork Fri Nov 3 16:35:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 117952 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp3670906qgn; Fri, 3 Nov 2017 09:36:15 -0700 (PDT) X-Google-Smtp-Source: ABhQp+TI6izPiG0QLD52Ni8cSnnhLhN62TvsIKF2n6JmXfLzQU4Xd+gb+RpHrz/Pzxyg+P/WI6h3 X-Received: by 10.98.19.212 with SMTP id 81mr8260153pft.46.1509726975727; Fri, 03 Nov 2017 09:36:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509726975; cv=none; d=google.com; s=arc-20160816; b=ZN2S0Qv6N70jjAmzgrVMHwBcMLLr/lMyYejIQ7nKIhTDlW3qPCjisIXdk3Uugutwsv qlnulMGRE6k8bzVs2BevnJaMst/Avw8Lke7qhowxPqhGZA37lj53ITiWcfWz3WWRO2Eg poloCN+r9Dl1zCq7pOttG14LwDQ9aI9kH76SwLJif25hvKqypV3lB0oHGQlAYWM6sgsy vdLZIaBERKPOmvaD8IH+G7fL5gIt3XVjWcQP1HCIfSI8P7Hyq4JkWiCfVLdo4j8sDkHm jWRI66CaIS/24brcTuNtOqM+eJAkrbrgy5EHLJmn4YEYYe8n/a/4Ich87Tup1KMJ/4V0 t3dw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:message-id:date:subject:mail-followup-to:to :from:delivered-to:sender:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mailing-list:dkim-signature :domainkey-signature:arc-authentication-results; bh=sDn/zCqUgGn8DSVEmAIcAgmjBtnexKLYnIUiaOijZeI=; b=FRf4+lkcrqUUqtUCD9UOPB7wo0CQQI0kMYNqV8G/JMOxotrT8ZoyowqWngcbI9m6EN n3upFVRvn5kO4KlSjAAaM6H9WawVUke40A6tk9LODFZvZ20CSnAAxA4XXPJkjrvIDciN 6K8tJZymDaVDmvDjS00uYjINBOt06XDt6V1stpqkgw+gam+bL1nJ2bA4COYFqOeQayyW 0c/gnS8FqiFzReVsfdcV5Y9iuu8sBL2V1FlUX7x3OGo9AILXMljVOg438LuFqGEsBw1S U9OPGrHHA6OmcLP1FNC+SFZujDZXcXSeKvoP6ipwKyvX0TR4M4vRGMkZkc6ng/bs0rLR IlBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=YrVc1J+1; spf=pass (google.com: domain of gcc-patches-return-465886-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-465886-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id a10si6511343pgu.656.2017.11.03.09.36.15 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 Nov 2017 09:36:15 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-465886-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 header.s=default header.b=YrVc1J+1; spf=pass (google.com: domain of gcc-patches-return-465886-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-465886-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.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:subject:date:message-id:mime-version:content-type; q=dns; s= default; b=UB0AXr+qGxx8OYYW+R+iMozmb+S59iWRsX8fdTT1AURmwyTSpbUUg n3SW1bEGa+/z7biBNG2vD20gQus7ruVwPi6McmeZSbzqi/CJU+6cVb+ELic/WJ4E JJjhPzvh0YJsH7WTiJNC33M3L4jdWBKkqSGleyVRCa2/2EbYb8ONLk= 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:subject:date:message-id:mime-version:content-type; s= default; bh=RnX9InF8+LjmuCT/ftwrLhu3odU=; b=YrVc1J+19R3IFkjOZmYJ 0QgWEHc9+gmf7kIhD3vMeZQdkJsSyt98z1x5zLwL5zqTcRN1WSQKa72rMdecA5CH O67e/6oWhgIsYub0O20lKUs8D/pppGJMpvDwOoAKvaJmpeYTzpYp1mAH854DliQq wZDtRYGVhUkBWGtp1aK7J28= Received: (qmail 47336 invoked by alias); 3 Nov 2017 16:36:04 -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 47324 invoked by uid 89); 3 Nov 2017 16:36:03 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-wr0-f179.google.com Received: from mail-wr0-f179.google.com (HELO mail-wr0-f179.google.com) (209.85.128.179) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 03 Nov 2017 16:36:02 +0000 Received: by mail-wr0-f179.google.com with SMTP id z55so3025233wrz.1 for ; Fri, 03 Nov 2017 09:36:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:mail-followup-to:subject:date:message-id :user-agent:mime-version; bh=sDn/zCqUgGn8DSVEmAIcAgmjBtnexKLYnIUiaOijZeI=; b=qyUYAY+M9qRvvyscRHlh0XFfE4px448wK/j3qHo0xSpMDxnblIiCiZo8y0Oh4rjcJD ZWTi+y4xYMWwwFQpJEt6hFTtVsnZykGybAirtBqzCe5X+SHVrQ1n34aeHE3IbclRkoqH uI1yrJnAxIBEV0+Bm2qMVxJp49OsFverUwvg2zKsggwx9IBLITVvUxWeZilo9n7y4hSM JNIDubb3XUVWj2N9ztSperjX1w1Yl2+cFvIk7K0enSRy8ZORPes1amXdw3+ccLxeeIXf LpTeRFSxO0IzFtx2ZeHfg9Jzx3+licKZRtEkvAS/3or7XovieOU7SgGVHe1SCT7bJtsv 10vQ== X-Gm-Message-State: AMCzsaURvjIIcXqkVr7Q2zPKM+QsnFm5UuiuFLrlsjWpOxTqH37Lo/tG 0YwXgHvRHJwyiA+H5+pWBmEQMoiuPbk= X-Received: by 10.223.172.3 with SMTP id v3mr6724605wrc.195.1509726960276; Fri, 03 Nov 2017 09:36:00 -0700 (PDT) Received: from localhost (188.29.164.162.threembb.co.uk. [188.29.164.162]) by smtp.gmail.com with ESMTPSA id e131sm6669421wmg.1.2017.11.03.09.35.58 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 03 Nov 2017 09:35:59 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@linaro.org Subject: Improve spilling for variable-size slots Date: Fri, 03 Nov 2017 16:35:56 +0000 Message-ID: <87po8znwur.fsf@linaro.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 Once SVE is enabled, a general AArch64 spill slot offset will be A + B * VL where A is a constant and B is a multiple of the SVE vector length. The offsets in SVE load and store instructions are a multiple of VL (and so can encode some values of B), while offsets for base AArch64 load and store instructions aren't (and encode some values of A). We therefore get better spill code if variable-sized slots are grouped together separately from constant-sized slots, and if variable-sized slots are not reused for constant-sized data. Then, spills to the constant-sized slots can add B * VL to the offset first, creating a common anchor point for spills with the same B component but different A components. Spills to variable-sized slots can likewise add A to the offset first, creating a common anchor point for spills with the same A component but different B components. This patch implements the sorting and grouping side of the optimisation. A later patch creates the anchor points. The patch is a no-op on other targets. Tested on aarch64-linux-gnu, x86_64-linux-gnu and powerpc64-linux-gnu. OK to install? Richard 2017-11-03 Richard Sandiford Alan Hayward David Sherwood gcc/ * lra-spills.c (pseudo_reg_slot_compare): Sort slots by whether they are variable or constant sized. (assign_stack_slot_num_and_sort_pseudos): Don't reuse variable-sized slots for constant-sized data. Index: gcc/lra-spills.c =================================================================== --- gcc/lra-spills.c 2017-11-03 12:15:45.033032920 +0000 +++ gcc/lra-spills.c 2017-11-03 12:22:34.003396358 +0000 @@ -174,9 +174,17 @@ regno_freq_compare (const void *v1p, con } /* Sort pseudos according to their slots, putting the slots in the order - that they should be allocated. Slots with lower numbers have the highest - priority and should get the smallest displacement from the stack or - frame pointer (whichever is being used). + that they should be allocated. + + First prefer to group slots with variable sizes together and slots + with constant sizes together, since that usually makes them easier + to address from a common anchor point. E.g. loads of polynomial-sized + registers tend to take polynomial offsets while loads of constant-sized + registers tend to take constant (non-polynomial) offsets. + + Next, slots with lower numbers have the highest priority and should + get the smallest displacement from the stack or frame pointer + (whichever is being used). The first allocated slot is always closest to the frame pointer, so prefer lower slot numbers when frame_pointer_needed. If the stack @@ -194,6 +202,10 @@ pseudo_reg_slot_compare (const void *v1p slot_num1 = pseudo_slots[regno1].slot_num; slot_num2 = pseudo_slots[regno2].slot_num; + diff = (int (slots[slot_num1].size.is_constant ()) + - int (slots[slot_num2].size.is_constant ())); + if (diff != 0) + return diff; if ((diff = slot_num1 - slot_num2) != 0) return (frame_pointer_needed || (!FRAME_GROWS_DOWNWARD) == STACK_GROWS_DOWNWARD ? diff : -diff); @@ -356,8 +368,17 @@ assign_stack_slot_num_and_sort_pseudos ( j = slots_num; else { + machine_mode mode + = wider_subreg_mode (PSEUDO_REGNO_MODE (regno), + lra_reg_info[regno].biggest_mode); for (j = 0; j < slots_num; j++) if (slots[j].hard_regno < 0 + /* Although it's possible to share slots between modes + with constant and non-constant widths, we usually + get better spill code by keeping the constant and + non-constant areas separate. */ + && (GET_MODE_SIZE (mode).is_constant () + == slots[j].size.is_constant ()) && ! (lra_intersected_live_ranges_p (slots[j].live_ranges, lra_reg_info[regno].live_ranges)))