From patchwork Thu Feb 8 11:54:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 127285 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp1408085ljc; Thu, 8 Feb 2018 03:55:16 -0800 (PST) X-Google-Smtp-Source: AH8x2241Ppg0g7q5qpwx9okFp4KnBgmD7Manh0AjwFzGKxhN9rttAaRNQDFMVKAVNV8ABe07M+Tt X-Received: by 2002:a17:902:8646:: with SMTP id y6-v6mr424026plt.406.1518090916547; Thu, 08 Feb 2018 03:55:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518090916; cv=none; d=google.com; s=arc-20160816; b=wIJEwPz1pAqMc5mKhUx3dpRe3u3QRdSulDqpl2S9JMKmazHBm5HtauBeoEKJB36eFQ 4B1LgrdiqYgsQubqpu1UuFISb3a2dqOhCArLDgX4dntcYjG+GMMlIHbzz4VihPPyqoV2 VMSacn2tgl+Punn7c5pwegVcQbNHZEw6v7vGsbcVMbL/qVwVXjdmAebl0Mgd0t/y2gnQ GIswi6JBCeFVFh9/bdqT5eKuIx/IInQ30doa85EI4lH2aP3nIH1GyK1fLnhe/jrYYUDg c9HnEMV+vCNuz51GD8IH9tUefgA2cxULscDF+8q/8tXYxBnxnNCGbTYtqN2q62z6bVQR XzGQ== 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:cc: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=y/hj5/6JD1qdCtkJbkzk/nLmMXFebgLUFkHdj8vpSNw=; b=sG1XSpmPMYNjSuxq7YPIXwhETZzGiQqw8HoPNbSAQmuQexfLJ0WYGPTrhHrrh+0WSO 7C0OW0HoR3oaDuqbsOq7EOdQHw+swXTp/8SJyp81ojug+NyUmAlZPLXKs4HU3VZAQ/yt 78CMmFH8drMD54/9zJgHzC8ywDx5M/X9yX8QhTRMdjaQElw/64fzVxcbNxeUAl712jHo vdqhewq2Xcde2QbrG/vz7xIiMAs1RavyekdHObh97/ptwfJ5SKsqoDla9OMNxaVqCG8/ /OzEsKAj3s5pq4JksxPsXasZ9UJutvA/Aq5avpSol1NFBIbipMkOhjxMlL26KZuHYvHi cuhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ABMOO43m; spf=pass (google.com: domain of gcc-patches-return-472840-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-472840-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 3-v6si1142459plo.446.2018.02.08.03.55.16 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Feb 2018 03:55:16 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-472840-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=ABMOO43m; spf=pass (google.com: domain of gcc-patches-return-472840-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-472840-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:cc:subject:date:message-id:mime-version:content-type; q=dns; s=default; b=Yb3k77fqzThCy9DwWpVWTF2ri3DgTSFigQs3OXXiC1qwX0sgx8 VZ8GEx+Femb2h4wJxpDR62Lxz/rzmrOxMSe9eRGxtkHLMuHcQCE7rYVinll6IFxv T8Dmc7JQwAtBs1GXq7ED1o1EwP6nLgZmwVhpKJ5UTfxjYGdr9wKDmYKcs= 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=dKpHb7jv9KKZhppbLcjqIuV/QZ4=; b=ABMOO43m+vH3v5OeeZQT PcX8GPjuD1tHWjYG8QOL3xojzOVvMu44JAuyU9kOXgSXv7R6J6aLDs8CzxXiZ4K1 2koIYhKiYYUR5DIBHcvOmWMiRfaSycsJTegEr+4Sy7dxh7KpOAe+y45j0/dwTBHK KylNgbZaIjqSigKJ+Kd5gCQ= Received: (qmail 92391 invoked by alias); 8 Feb 2018 11:55: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 91607 invoked by uid 89); 8 Feb 2018 11:55:03 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=0s X-HELO: mail-wr0-f174.google.com Received: from mail-wr0-f174.google.com (HELO mail-wr0-f174.google.com) (209.85.128.174) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 08 Feb 2018 11:55:01 +0000 Received: by mail-wr0-f174.google.com with SMTP id o76so1273368wrb.7 for ; Thu, 08 Feb 2018 03:55:00 -0800 (PST) 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:cc:subject:date :message-id:user-agent:mime-version; bh=y/hj5/6JD1qdCtkJbkzk/nLmMXFebgLUFkHdj8vpSNw=; b=E2GBvTXpIHOVHUeDtc7oZrY7Dh3ag81pMMubiAi8kT7i+OIp1nxBLWVu1zqQK9KA7U fA1P5ODO7TUymdq6R6IIoSYStlGTOiGwLO4RBfkWI/O23vtRaG6MWbMpRnbmoQhXleT+ fiuhGNkQB6ztFEurTKPx0SBgwPyZ41Luoaw6UcgsT2QL5FewDqPtX/TkU157s5LlICYN nvuv2B/hyPd0vI4TAAePuSKdYg2AG70bgitzrCITQug6ncCgICviK8JRJX22XQjv0Jqh PbYOKh2WXoQ09nbM96RLCPUPvAfnwDR1YBfsFBVEIAAhVYGrhCN4tRUIoRIQhVgmHY3j LRrA== X-Gm-Message-State: APf1xPBFYaVZcCWCKhynUBkXBuZGEV/Fs/Z3KiCV6bqAppub5LOuGYQK Sok//I14REP+dhTx77M3Nz1eyw== X-Received: by 10.223.155.136 with SMTP id d8mr499456wrc.161.1518090899084; Thu, 08 Feb 2018 03:54:59 -0800 (PST) Received: from localhost (188.29.164.130.threembb.co.uk. [188.29.164.130]) by smtp.gmail.com with ESMTPSA id l2sm3741190wre.6.2018.02.08.03.54.57 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 08 Feb 2018 03:54:58 -0800 (PST) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.earnshaw@arm.com, james.greenhalgh@arm.com, marcus.shawcroft@arm.com, richard.sandiford@linaro.org Cc: richard.earnshaw@arm.com, james.greenhalgh@arm.com, marcus.shawcroft@arm.com Subject: [AArch64] Add a tlsdesc call pattern for SVE Date: Thu, 08 Feb 2018 11:54:56 +0000 Message-ID: <87h8qry9v3.fsf@linaro.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 tlsdesc calls are guaranteed to preserve all Advanced SIMD registers, but are not guaranteed to preserve the SVE extension of them. The calls also don't preserve the SVE predicate registers. The long-term plan for handling the SVE vector registers is CLOBBER_HIGH, which adds a clobber equivalent of TARGET_HARD_REGNO_CALL_PART_CLOBBERED. The pattern can then directly model the fact that the low 128 bits are preserved and the upper bits are clobbered. However, it's too late now for that to be included in GCC 8, so this patch conservatively treats the whole vector register as being clobbered. This has the obvious disadvantage that compiling for SVE can make NEON code worse, but I don't think there's much we can do about that until CLOBBER_HIGH is in. Tested on aarch64-linux-gnu and aarch64_be-elf. OK to install? Richard 2018-02-08 Richard Sandiford gcc/ * config/aarch64/aarch64.md (V4_REGNUM, V8_REGNUM, V12_REGNUM) (V20_REGNUM, V24_REGNUM, V28_REGNUM, P1_REGNUM, P2_REGNUM, P3_REGNUM) (P4_REGNUM, P5_REGNUM, P6_REGNUM, P8_REGNUM, P9_REGNUM, P10_REGNUM) (P11_REGNUM, P12_REGNUM, P13_REGNUM, P14_REGNUM): New define_constants. (tlsdesc_small_): Turn a define_expand and use tlsdesc_small_sve_ for SVE. Rename original define_insn to... (tlsdesc_small_advsimd_): ...this. (tlsdesc_small_sve_): New pattern. gcc/testsuite/ * gcc.target/aarch64/sve/tls_1.c: New test. * gcc.target/aarch64/sve/tls_2.C: Likewise. Index: gcc/config/aarch64/aarch64.md =================================================================== --- gcc/config/aarch64/aarch64.md 2018-02-01 11:04:16.726191903 +0000 +++ gcc/config/aarch64/aarch64.md 2018-02-08 11:51:37.226675644 +0000 @@ -57,7 +57,14 @@ (define_constants (LR_REGNUM 30) (SP_REGNUM 31) (V0_REGNUM 32) + (V4_REGNUM 36) + (V8_REGNUM 40) + (V12_REGNUM 44) (V15_REGNUM 47) + (V16_REGNUM 48) + (V20_REGNUM 52) + (V24_REGNUM 56) + (V28_REGNUM 60) (V31_REGNUM 63) (LAST_SAVED_REGNUM 63) (SFP_REGNUM 64) @@ -66,7 +73,20 @@ (define_constants ;; Defined only to make the DWARF description simpler. (VG_REGNUM 67) (P0_REGNUM 68) + (P1_REGNUM 69) + (P2_REGNUM 70) + (P3_REGNUM 71) + (P4_REGNUM 72) + (P5_REGNUM 73) + (P6_REGNUM 74) (P7_REGNUM 75) + (P8_REGNUM 76) + (P9_REGNUM 77) + (P10_REGNUM 78) + (P11_REGNUM 79) + (P12_REGNUM 80) + (P13_REGNUM 81) + (P14_REGNUM 82) (P15_REGNUM 83) ] ) @@ -5786,14 +5806,68 @@ (define_insn "tlsle48_" (set_attr "length" "12")] ) -(define_insn "tlsdesc_small_" +(define_expand "tlsdesc_small_" + [(unspec:PTR [(match_operand 0 "aarch64_valid_symref")] UNSPEC_TLSDESC)] + "TARGET_TLS_DESC" + { + if (TARGET_SVE) + emit_insn (gen_tlsdesc_small_sve_ (operands[0])); + else + emit_insn (gen_tlsdesc_small_advsimd_ (operands[0])); + DONE; + } +) + +;; tlsdesc calls preserve all core and Advanced SIMD registers except +;; R0 and LR. +(define_insn "tlsdesc_small_advsimd_" [(set (reg:PTR R0_REGNUM) (unspec:PTR [(match_operand 0 "aarch64_valid_symref" "S")] - UNSPEC_TLSDESC)) + UNSPEC_TLSDESC)) (clobber (reg:DI LR_REGNUM)) (clobber (reg:CC CC_REGNUM)) (clobber (match_scratch:DI 1 "=r"))] - "TARGET_TLS_DESC" + "TARGET_TLS_DESC && !TARGET_SVE" + "adrp\\tx0, %A0\;ldr\\t%1, [x0, #%L0]\;add\\t0, 0, %L0\;.tlsdesccall\\t%0\;blr\\t%1" + [(set_attr "type" "call") + (set_attr "length" "16")]) + +;; For SVE, model tlsdesc calls as clobbering all vector and predicate +;; registers, on top of the usual R0 and LR. In reality the calls +;; preserve the low 128 bits of the vector registers, but we don't +;; yet have a way of representing that in the instruction pattern. +(define_insn "tlsdesc_small_sve_" + [(set (reg:PTR R0_REGNUM) + (unspec:PTR [(match_operand 0 "aarch64_valid_symref" "S")] + UNSPEC_TLSDESC)) + (clobber (reg:DI LR_REGNUM)) + (clobber (reg:CC CC_REGNUM)) + (clobber (reg:XI V0_REGNUM)) + (clobber (reg:XI V4_REGNUM)) + (clobber (reg:XI V8_REGNUM)) + (clobber (reg:XI V12_REGNUM)) + (clobber (reg:XI V16_REGNUM)) + (clobber (reg:XI V20_REGNUM)) + (clobber (reg:XI V24_REGNUM)) + (clobber (reg:XI V28_REGNUM)) + (clobber (reg:VNx2BI P0_REGNUM)) + (clobber (reg:VNx2BI P1_REGNUM)) + (clobber (reg:VNx2BI P2_REGNUM)) + (clobber (reg:VNx2BI P3_REGNUM)) + (clobber (reg:VNx2BI P4_REGNUM)) + (clobber (reg:VNx2BI P5_REGNUM)) + (clobber (reg:VNx2BI P6_REGNUM)) + (clobber (reg:VNx2BI P7_REGNUM)) + (clobber (reg:VNx2BI P8_REGNUM)) + (clobber (reg:VNx2BI P9_REGNUM)) + (clobber (reg:VNx2BI P10_REGNUM)) + (clobber (reg:VNx2BI P11_REGNUM)) + (clobber (reg:VNx2BI P12_REGNUM)) + (clobber (reg:VNx2BI P13_REGNUM)) + (clobber (reg:VNx2BI P14_REGNUM)) + (clobber (reg:VNx2BI P15_REGNUM)) + (clobber (match_scratch:DI 1 "=r"))] + "TARGET_TLS_DESC && TARGET_SVE" "adrp\\tx0, %A0\;ldr\\t%1, [x0, #%L0]\;add\\t0, 0, %L0\;.tlsdesccall\\t%0\;blr\\t%1" [(set_attr "type" "call") (set_attr "length" "16")]) Index: gcc/testsuite/gcc.target/aarch64/sve/tls_1.c =================================================================== --- /dev/null 2018-02-08 11:17:10.862716283 +0000 +++ gcc/testsuite/gcc.target/aarch64/sve/tls_1.c 2018-02-08 11:51:37.229675401 +0000 @@ -0,0 +1,17 @@ +/* { dg-options "-O2 -fPIC -msve-vector-bits=256" } */ + +typedef unsigned int v8si __attribute__((vector_size(32))); + +extern __thread int y; + +void +f (int *a) +{ + v8si x; + asm volatile ("dup %0.s, #0x11" : "=w" (x) :: "memory"); + if (*a) + asm volatile ("insr %0.s, %w2" : "=w" (x) : "0" (x), "r" (y)); +} + +/* { dg-final { scan-assembler {\tst(r|1.)\tz[0-9]} } } */ +/* { dg-final { scan-assembler {\tld(r|1.)\tz[0-9]} } } */ Index: gcc/testsuite/gcc.target/aarch64/sve/tls_2.C =================================================================== --- /dev/null 2018-02-08 11:17:10.862716283 +0000 +++ gcc/testsuite/gcc.target/aarch64/sve/tls_2.C 2018-02-08 11:51:37.229675401 +0000 @@ -0,0 +1,30 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fPIC -msve-vector-bits=256" } */ + +#include + +typedef int8_t v32qi __attribute__((vector_size (32))); + +extern __thread int z; + +void +foo (v32qi *a, int *b) +{ + v32qi x = a[0], y = a[1]; + asm volatile ("" :: "w" ((v32qi) { -1, 0, 0, -1, -1, -1, 0, 0, + -1, -1, -1, -1, 0, 0, 0, 0, + -1, -1, -1, -1, -1, -1, -1, -1, + 0, 0, 0, 0, 0, 0, 0, 0 } ? x : y) + : "memory"); + if (*b) + { + x = a[2], y = a[3]; + asm volatile ("" :: "w" ((v32qi) { -1, 0, 0, -1, -1, -1, 0, 0, + -1, -1, -1, -1, 0, 0, 0, 0, + -1, -1, -1, -1, -1, -1, -1, -1, + 0, 0, 0, 0, 0, 0, 0, 0 } ? x : y), + "r" (z)); + } +} + +/* { dg-final { scan-assembler-times {\tldr\tp[0-9]} 2 } } */