From patchwork Tue Oct 16 08:48:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Renlin Li X-Patchwork-Id: 984642 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-487627-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=foss.arm.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="b7DIVCXh"; dkim-atps=neutral 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 42Z9WM54Wsz9s0t for ; Tue, 16 Oct 2018 20:49:17 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :subject:to:message-id:date:mime-version:content-type; q=dns; s= default; b=S+QLsapKVtjkJot+2jU7oflavddks3QWP3yviQwvsl0KraCCB1RJg X8oc8S9NRuV/KqaXgCquLabkv0THzGT+sm2peUSDuF+vQp4PI80+ueuoLxmKcnL8 cgHSKONQiMZ5Dqj919It+H7yslIM2eMkXF5Vyzns1rTs1ZByeju5x0= 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 :subject:to:message-id:date:mime-version:content-type; s= default; bh=sDz65yhndwmcLfan/nSkXq37q3s=; b=b7DIVCXhlapD3d0WUJnO gj/O3ZKQ1JrdOfVNKuiOwreLxMhu07si9dj33SJYGjULeIyfLlUYjdX964gPoumG ocJ2FPMkrurOHYQ6OuNAwBkc6seN/AnmGOnS9yPKCMsf9FZqDFERxCjw7r+tcxs6 TpAPXVBgjP63UGsxC5Rmw48= Received: (qmail 88277 invoked by alias); 16 Oct 2018 09:49:10 -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 87946 invoked by uid 89); 16 Oct 2018 09:48:51 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, KAM_LOTSOFHASH, KAM_STOCKGEN autolearn=ham version=3.3.2 spammy=lp64, 2, 7 X-HELO: foss.arm.com Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 16 Oct 2018 09:48:45 +0000 Received: by usa-sjc-mx-foss1.foss.arm.com (Postfix, from userid 105) id A618D3576; Tue, 16 Oct 2018 03:04:50 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 93E363746; Tue, 16 Oct 2018 01:48:58 -0700 (PDT) Received: from [10.2.206.82] (unknown [10.2.206.82]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id CE9D53F71C; Tue, 16 Oct 2018 01:48:37 -0700 (PDT) From: Renlin Li Subject: [AARCH64]Don't force symbols which referencing per-function literal pool into memory To: "gcc-patches@gcc.gnu.org" , James Greenhalgh , Ramana Radhakrishnan , Wilco Dijkstra Message-ID: <40e6abea-0220-ce7b-ff89-7c22fc2df00a@foss.arm.com> Date: Tue, 16 Oct 2018 09:48:35 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 X-IsSubscribed: yes Hi all, "-mcmodel=large" and "-mpc-relative-loads" are used to avoid adrp+add to address symbols. When the combination is used, the original symbol is first forced into per-function literal pools. And a local symbol is created to reference it. In this case, the way to reference this local symbol is pc relative. According to the original logic, the local symbol will be forced into memory, and another local symbol will be created again. For example, during expand stage, (insn 5 2 6 2 (set (reg/f:DI 92) (mem/u/c:DI (symbol_ref/u:DI ("*.LC1") [flags 0x2]) [0 S8 A64])) "imm.c":5 -1 (expr_list:REG_EQUAL (symbol_ref/u:DI ("*.LC0") [flags 0x2]) (nil))) (insn 6 5 10 2 (set (reg:TI 90 [ ]) (mem/u/c:TI (reg/f:DI 92) [0 S16 A128])) "imm.c":5 -1 (expr_list:REG_EQUAL (const_wide_int 0x123456789abcdef0fedcba987654321) (nil))) However, later, the CSE will replace memory load in insn 5 with its equivalent value (symbol_ref/u:DI ("*.LC0"). So there is no issue in the final code-generation. However, if the CSE is not enabled, for example with -O0, a load will be generated. The patch here simplifies the rtx in expand stage. Instead of force the local symbol in the memory again, the symbol is classified as SYMBOL_TINY_ABSOLUTE. The following rtx is generated directly. (insn 5 2 6 2 (set (reg/f:DI 92) (symbol_ref/u:DI ("*.LC0") [flags 0x2])) "imm.c":5 -1 (nil)) (insn 6 5 10 2 (set (reg:TI 90 [ ]) (mem/u/c:TI (reg/f:DI 92) [0 S16 A128])) "imm.c":5 -1 (expr_list:REG_EQUAL (const_wide_int 0x123456789abcdef0fedcba987654321) (nil))) Similar change is added to handle literal pool referencing in small memory model when option "-mpc-relative-loads" is present. The symbol is classified as SYMBOL_TINY_ABSOLUTE, instead of SYMBOL_SMALL_ABSOLUTE. So that, in the final code-generation, a single ADR instruction could be used, instead of ADRP+ADD. A test case is added, which should be applicable at O0 optimization level for all memory models (tiny, small and large). Okay to commit? gcc/ChangeLog: 2018-10-15 Renlin Li * config/aarch64/aarch64.c (aarch64_classify_symbol): Direct address symbols referencing per function literl pool. gcc/testsuite/ChangeLog: 2018-10-15 Renlin Li * gcc.target/aarch64/pr79041-2.c: Skip when mcmodel is defined by dejagnu configuration. * gcc.target/aarch64/pr79041-3.c: New. diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c index 2f98a21acf16297bdd7c4742cbcfc695cdc4e5f9..bd6369ca08707cca59809bf970830238b05fa2bc 100644 --- a/gcc/config/aarch64/aarch64.c +++ b/gcc/config/aarch64/aarch64.c @@ -11845,7 +11845,13 @@ aarch64_classify_symbol (rtx x, HOST_WIDE_INT offset) || !IN_RANGE (offset, HOST_WIDE_INT_C (-4294967263), HOST_WIDE_INT_C (4294967264))) return SYMBOL_FORCE_TO_MEM; - return SYMBOL_SMALL_ABSOLUTE; + /* Use ADR when addressing per-function constant pool if + pcrelative_literal_loads is enabled. */ + else if (CONSTANT_POOL_ADDRESS_P (x) + && aarch64_pcrelative_literal_loads) + return SYMBOL_TINY_ABSOLUTE; + else + return SYMBOL_SMALL_ABSOLUTE; case AARCH64_CMODEL_TINY_PIC: if (!aarch64_symbol_binds_local_p (x)) @@ -11857,14 +11863,24 @@ aarch64_classify_symbol (rtx x, HOST_WIDE_INT offset) if (!aarch64_symbol_binds_local_p (x)) return (aarch64_cmodel == AARCH64_CMODEL_SMALL_SPIC ? SYMBOL_SMALL_GOT_28K : SYMBOL_SMALL_GOT_4G); - return SYMBOL_SMALL_ABSOLUTE; + /* Use ADR when addressing per-function constant pool if + pcrelative_literal_loads is enabled. */ + else if (CONSTANT_POOL_ADDRESS_P (x) + && aarch64_pcrelative_literal_loads) + return SYMBOL_TINY_ABSOLUTE; + else + return SYMBOL_SMALL_ABSOLUTE; case AARCH64_CMODEL_LARGE: - /* This is alright even in PIC code as the constant - pool reference is always PC relative and within - the same translation unit. */ - if (!aarch64_pcrelative_literal_loads && CONSTANT_POOL_ADDRESS_P (x)) - return SYMBOL_SMALL_ABSOLUTE; + if (CONSTANT_POOL_ADDRESS_P (x)) + { + /* Use ADR when addressing per-function constant pool if + pcrelative_literal_loads is enabled. */ + if (aarch64_pcrelative_literal_loads) + return SYMBOL_TINY_ABSOLUTE; + else + return SYMBOL_SMALL_ABSOLUTE; + } else return SYMBOL_FORCE_TO_MEM; diff --git a/gcc/testsuite/gcc.target/aarch64/pr79041-2.c b/gcc/testsuite/gcc.target/aarch64/pr79041-2.c index 4695b5c1b2b7c9b515995e242dd38e0519a48a2b..42695be127db454934d2791474d5f97fc5667403 100644 --- a/gcc/testsuite/gcc.target/aarch64/pr79041-2.c +++ b/gcc/testsuite/gcc.target/aarch64/pr79041-2.c @@ -2,6 +2,7 @@ /* { dg-options "-O2 -mcmodel=large -mpc-relative-literal-loads" } */ /* { dg-require-effective-target lp64 } */ /* { dg-skip-if "-mcmodel=large, no support for -fpic" { aarch64-*-* } { "-fpic" } { "" } } */ +/* { dg-skip-if "Code model already defined" { aarch64_tiny || aarch64_small } } */ __int128 t (void) diff --git a/gcc/testsuite/gcc.target/aarch64/pr79041-3.c b/gcc/testsuite/gcc.target/aarch64/pr79041-3.c new file mode 100644 index 0000000000000000000000000000000000000000..f4239713f962edca5d354cc62d0bea13c609ceec --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/pr79041-3.c @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* { dg-options "-O0 -mpc-relative-literal-loads" } */ +/* { dg-require-effective-target lp64 } */ +/* { dg-skip-if "-mcmodel=large, no support for -fpic" { aarch64-*-* } { "-fpic" "-mcmodel=large" } { "" } } */ + +__int128 +tiny_abs (void) +{ + return ((__int128)0x123456789abcdef << 64) | 0xfedcba987654321; +} + +/* { dg-final { scan-assembler "adr" } } */ +/* { dg-final { scan-assembler-not "adrp" } } */