From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 128923 invoked by alias); 2 May 2016 13:52:08 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 128913 invoked by uid 89); 2 May 2016 13:52:08 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.1 required=5.0 tests=AWL,BAYES_00,KAM_ASCII_DIVIDERS,KAM_LAZY_DOMAIN_SECURITY,KAM_STOCKGEN,RCVD_IN_DNSWL_NONE,RP_MATCHES_RCVD autolearn=no version=3.3.2 spammy=sk:CONSTAN, fname, tjl, pcl X-HELO: smtprelay.synopsys.com Received: from smtprelay4.synopsys.com (HELO smtprelay.synopsys.com) (198.182.47.9) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Mon, 02 May 2016 13:51:55 +0000 Received: from dc8secmta2.synopsys.com (dc8secmta2.synopsys.com [10.13.218.202]) by smtprelay.synopsys.com (Postfix) with ESMTP id 4130824E1EA9; Mon, 2 May 2016 06:51:52 -0700 (PDT) Received: from dc8secmta2.internal.synopsys.com (dc8secmta2.internal.synopsys.com [127.0.0.1]) by dc8secmta2.internal.synopsys.com (Service) with ESMTP id 2C95CA4112; Mon, 2 May 2016 06:51:52 -0700 (PDT) Received: from mailhost.synopsys.com (unknown [10.13.184.66]) by dc8secmta2.internal.synopsys.com (Service) with ESMTP id EFE3DA4102; Mon, 2 May 2016 06:51:51 -0700 (PDT) Received: from mailhost.synopsys.com (localhost [127.0.0.1]) by mailhost.synopsys.com (Postfix) with ESMTP id DCFAB1BD; Mon, 2 May 2016 06:51:51 -0700 (PDT) Received: from US01WEHTC2.internal.synopsys.com (us01wehtc2.internal.synopsys.com [10.12.239.237]) by mailhost.synopsys.com (Postfix) with ESMTP id AB30E1BC; Mon, 2 May 2016 06:51:51 -0700 (PDT) Received: from IN01WEHTCB.internal.synopsys.com (10.144.199.106) by US01WEHTC2.internal.synopsys.com (10.12.239.237) with Microsoft SMTP Server (TLS) id 14.3.195.1; Mon, 2 May 2016 06:51:51 -0700 Received: from IN01WEHTCA.internal.synopsys.com (10.144.199.103) by IN01WEHTCB.internal.synopsys.com (10.144.199.105) with Microsoft SMTP Server (TLS) id 14.3.195.1; Mon, 2 May 2016 19:21:48 +0530 Received: from nl20droid1.internal.synopsys.com (10.100.24.228) by IN01WEHTCA.internal.synopsys.com (10.144.199.243) with Microsoft SMTP Server (TLS) id 14.3.195.1; Mon, 2 May 2016 19:21:48 +0530 From: Claudiu Zissulescu To: CC: , , , Subject: [PATCH] [ARC] Use GOTOFFPC relocation for pc-relative accesses. Date: Mon, 02 May 2016 13:52:00 -0000 Message-ID: <1462197018-29185-1-git-send-email-claziss@synopsys.com> MIME-Version: 1.0 Content-Type: text/plain X-SW-Source: 2016-05/txt/msg00099.txt.bz2 This patch makes the pc-relative access to be more safe by using @pcl syntax. This new syntax generates a pc-relative relocation which will be handled by assembler. OK to apply? Claudiu gcc/ 2016-05-02 Claudiu Zissulescu Joern Rennecke * config/arc/arc.c (arc_print_operand_address): Handle pc-relative addresses. (arc_needs_pcl_p): Add GOTOFFPC. (arc_legitimate_pic_addr_p): Likewise. (arc_output_pic_addr_const): Likewise. (arc_legitimize_pic_address): Generate a pc-relative address using GOTOFFPC. (arc_output_libcall): Use @pcl syntax. (arc_delegitimize_address_0): Delegitimize ARC_UNSPEC_GOTOFFPC. * config/arc/arc.md ("unspec"): Add ARC_UNSPEC_GOTOFFPC. (*movsi_insn): Use @pcl syntax. (doloop_begin_i): Likewise. --- gcc/config/arc/arc.c | 53 ++++++++++++++++++++++++++++----------------------- gcc/config/arc/arc.md | 6 ++++-- 2 files changed, 33 insertions(+), 26 deletions(-) diff --git a/gcc/config/arc/arc.c b/gcc/config/arc/arc.c index 49edc0a..c0aa075 100644 --- a/gcc/config/arc/arc.c +++ b/gcc/config/arc/arc.c @@ -3528,7 +3528,8 @@ arc_print_operand_address (FILE *file , rtx addr) || XINT (c, 1) == UNSPEC_TLS_IE)) || (GET_CODE (c) == PLUS && GET_CODE (XEXP (c, 0)) == UNSPEC - && (XINT (XEXP (c, 0), 1) == UNSPEC_TLS_OFF))) + && (XINT (XEXP (c, 0), 1) == UNSPEC_TLS_OFF + || XINT (XEXP (c, 0), 1) == ARC_UNSPEC_GOTOFFPC))) { arc_output_pic_addr_const (file, c, 0); break; @@ -4636,6 +4637,7 @@ arc_needs_pcl_p (rtx x) switch (XINT (x, 1)) { case ARC_UNSPEC_GOT: + case ARC_UNSPEC_GOTOFFPC: case UNSPEC_TLS_GD: case UNSPEC_TLS_IE: return true; @@ -4698,9 +4700,10 @@ arc_legitimate_pic_addr_p (rtx addr) || XVECLEN (addr, 0) != 1) return false; - /* Must be one of @GOT, @GOTOFF, @tlsgd, tlsie. */ + /* Must be one of @GOT, @GOTOFF, @GOTOFFPC, @tlsgd, tlsie. */ if (XINT (addr, 1) != ARC_UNSPEC_GOT && XINT (addr, 1) != ARC_UNSPEC_GOTOFF + && XINT (addr, 1) != ARC_UNSPEC_GOTOFFPC && XINT (addr, 1) != UNSPEC_TLS_GD && XINT (addr, 1) != UNSPEC_TLS_IE) return false; @@ -4917,26 +4920,15 @@ arc_legitimize_pic_address (rtx orig, rtx oldx) else if (!flag_pic) return orig; else if (CONSTANT_POOL_ADDRESS_P (addr) || SYMBOL_REF_LOCAL_P (addr)) - { - /* This symbol may be referenced via a displacement from the - PIC base address (@GOTOFF). */ + return gen_rtx_CONST (Pmode, + gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), + ARC_UNSPEC_GOTOFFPC)); - /* FIXME: if we had a way to emit pc-relative adds that - don't create a GOT entry, we could do without the use of - the gp register. */ - crtl->uses_pic_offset_table = 1; - pat = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), ARC_UNSPEC_GOTOFF); - pat = gen_rtx_CONST (Pmode, pat); - pat = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, pat); - } - else - { - /* This symbol must be referenced via a load from the - Global Offset Table (@GOTPC). */ - pat = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), ARC_UNSPEC_GOT); - pat = gen_rtx_CONST (Pmode, pat); - pat = gen_const_mem (Pmode, pat); - } + /* This symbol must be referenced via a load from the Global + Offset Table (@GOTPC). */ + pat = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), ARC_UNSPEC_GOT); + pat = gen_rtx_CONST (Pmode, pat); + pat = gen_const_mem (Pmode, pat); if (oldx == NULL) oldx = gen_reg_rtx (Pmode); @@ -4952,6 +4944,7 @@ arc_legitimize_pic_address (rtx orig, rtx oldx) if (GET_CODE (addr) == UNSPEC) { /* Check that the unspec is one of the ones we generate? */ + return orig; } else gcc_assert (GET_CODE (addr) == PLUS); @@ -5105,6 +5098,9 @@ arc_output_pic_addr_const (FILE * file, rtx x, int code) case ARC_UNSPEC_GOTOFF: suffix = "@gotoff"; break; + case ARC_UNSPEC_GOTOFFPC: + suffix = "@pcl", pcrel = true; + break; case ARC_UNSPEC_PLT: suffix = "@plt"; break; @@ -5389,6 +5385,7 @@ arc_legitimate_constant_p (machine_mode mode, rtx x) { case ARC_UNSPEC_PLT: case ARC_UNSPEC_GOTOFF: + case ARC_UNSPEC_GOTOFFPC: case ARC_UNSPEC_GOT: case UNSPEC_TLS_GD: case UNSPEC_TLS_IE: @@ -7648,7 +7645,7 @@ arc_output_libcall (const char *fname) || (TARGET_MEDIUM_CALLS && arc_ccfsm_cond_exec_p ())) { if (flag_pic) - sprintf (buf, "add r12,pcl,@%s-(.&-4)\n\tjl%%!%%* [r12]", fname); + sprintf (buf, "add r12,pcl,@%s@pcl\n\tjl%%!%%* [r12]", fname); else sprintf (buf, "jl%%! @%s", fname); } @@ -8578,13 +8575,21 @@ arc_legitimize_address (rtx orig_x, rtx oldx, machine_mode mode) static rtx arc_delegitimize_address_0 (rtx x) { - rtx u, gp; + rtx u, gp, p; if (GET_CODE (x) == CONST && GET_CODE (u = XEXP (x, 0)) == UNSPEC) { - if (XINT (u, 1) == ARC_UNSPEC_GOT) + if (XINT (u, 1) == ARC_UNSPEC_GOT + || XINT (u, 1) == ARC_UNSPEC_GOTOFFPC) return XVECEXP (u, 0, 0); } + else if (GET_CODE (x) == CONST && GET_CODE (p = XEXP (x, 0)) == PLUS + && GET_CODE (u = XEXP (p, 0)) == UNSPEC + && (XINT (u, 1) == ARC_UNSPEC_GOT + || XINT (u, 1) == ARC_UNSPEC_GOTOFFPC)) + return gen_rtx_CONST + (GET_MODE (x), + gen_rtx_PLUS (GET_MODE (p), XVECEXP (u, 0, 0), XEXP (p, 1))); else if (GET_CODE (x) == PLUS && ((REG_P (gp = XEXP (x, 0)) && REGNO (gp) == PIC_OFFSET_TABLE_REGNUM) diff --git a/gcc/config/arc/arc.md b/gcc/config/arc/arc.md index a4ee084..1102c53 100644 --- a/gcc/config/arc/arc.md +++ b/gcc/config/arc/arc.md @@ -102,6 +102,7 @@ ;; UNSPEC_GOT 4 symbol to be rerenced through the GOT ;; UNSPEC_GOTOFF 5 Local symbol.To be referenced relative to the ;; GOTBASE.(Referenced as @GOTOFF) +;; UNSPEC_GOTOFFPC 6 Local symbol. To be referenced pc-relative. ;; ---------------------------------------------------------------------------- (define_c_enum "unspec" [ @@ -111,6 +112,7 @@ ARC_UNSPEC_PLT ARC_UNSPEC_GOT ARC_UNSPEC_GOTOFF + ARC_UNSPEC_GOTOFFPC UNSPEC_TLS_GD UNSPEC_TLS_LD UNSPEC_TLS_IE @@ -725,7 +727,7 @@ * return INTVAL (operands[1]) & 0xffffff ? \"movbi.cl %0,%1 >> %p1,%p1,8;8\" : \"movbi.cl %0,%L1 >> 24,24,8;9\"; mov%? %0,%1 ;10 add %0,%S1 ;11 - * return arc_get_unalign () ? \"add %0,pcl,%1-.+2\" : \"add %0,pcl,%1-.\"; + add %0,pcl,%1@pcl ;12 mov%? %0,%S1%& ;13 mov%? %0,%S1 ;14 ld%? %0,%1%& ;15 @@ -5155,7 +5157,7 @@ /* ??? Can do better for when a scratch register is known. But that would require extra testing. */ arc_clear_unalign (); - return ".p2align 2\;push_s r0\;add r0,pcl,24\;sr r0,[2]; LP_START\;add r0,pcl,.L__GCC__LP%1-.+2\;sr r0,[3]; LP_END\;pop_s r0"; + return ".p2align 2\;push_s r0\;add r0,pcl,24\;sr r0,[2]; LP_START\;add r0,pcl,.L__GCC__LP%1@pcl\;sr r0,[3]; LP_END\;pop_s r0"; } output_asm_insn ((size < 2048 ? "lp .L__GCC__LP%1" : "sr .L__GCC__LP%1,[3]; LP_END"), -- 1.9.1