From patchwork Fri Jan 26 07:37:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: chenglulu X-Patchwork-Id: 192423 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:e09d:b0:103:945f:af90 with SMTP id gm29csp501525dyb; Thu, 25 Jan 2024 23:39:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IE3Lf0uo1iB0DgGHO6HYScQ3SyQQaCrj0V08mHRNXzN19SKfb6ksUXqDZZBRxFVgA78Fsnb X-Received: by 2002:ad4:4eec:0:b0:686:ac5a:fbcd with SMTP id dv12-20020ad44eec000000b00686ac5afbcdmr1172029qvb.31.1706254782201; Thu, 25 Jan 2024 23:39:42 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706254782; cv=pass; d=google.com; s=arc-20160816; b=SIDgmNtGeYqqFaJ+CRnfUErGLXspzWhHMJuExg1UDpVVgEBGchkmsdCRUpK90Ti4e/ juFnj/GCYsQQmtfh7mwGr5IEJ+4N6Iqrg+Qkfw3nEcGNLtPPoiiJhiRwr3DmbivqQy/Z r7u6fDLgNSVzEb4pyDLPefDnfm6ZwmVRwmWNFFSLMO9XHxYyaVQmFaVF/eEZsK6ufcgQ kU3jRsAKB+6xKSf83d7rDj54q/KRll8zTz9lUH3uX+iI+dAjJKVkPsJ+4ldZF0q7zqX9 XTdDzFFMLaRqkiMq6w7PPVja4VnEyOD3HJazwVF4D8nu8hlZbo0T+5JUweOYaoOTjQiV 1NMg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to; bh=oWxNGiXRTwV2ABo+jT/sKhaXmWk2QVVHXsacGEBbwNo=; fh=kLXYvQYlFoGM+V705nfHVJAr1G8Exwjn4Aw52UExiO4=; b=bMY433gwH1QU1Sbhcyj1XkugcHACXdpir9PWCbvU1rUT+1fc63n+XNn82UTNAKCC5g nBSSy+NqH72oAvLo+Yb+x0+SSHJydMzT3IO5sBU0jLdawWjbcCMvPGoaYvJRaVbrLlig XMBC4ZPirq4UcqEmlrojdGn1KeRP4eyVr3J4DvwqJg8nu5p6DN5zYIagk6Zb3iGFtDR4 KimEo9svc2Nq/csdS+Q8RdkLPo4ftwR9CrIX6T6cIl/qEi+q2yGUps5/SwAZBNA1TMdW Nz307uVwEyuOxgZaU5kWr35rAKcn05uQsvyq5I4yxuSQ7/BQ1/eF96j2t8vSesrxEn6H W68A== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id 11-20020a0562140d6b00b0067f7820cfebsi740983qvs.390.2024.01.25.23.39.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 23:39:42 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DAEAE3858018 for ; Fri, 26 Jan 2024 07:39:41 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by sourceware.org (Postfix) with ESMTP id C461838582A5 for ; Fri, 26 Jan 2024 07:38:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C461838582A5 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=loongson.cn ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C461838582A5 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=114.242.206.163 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706254718; cv=none; b=NjrVyu2ibHn5A3rrVGTNb1ZMOffil5ErDfHRQEOOd4Yh5l5yy3i02IrHM+loUlYwRh2D0V4J0F1C0q3sjhymm19ud088BvsvB4xOiXn/fSUzCr4q3ni7u1ow2G5VDtQ3lqIQAIwyG7y2KwzD0cawaqIDR+6jkH1QEGtg43fHZW8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706254718; c=relaxed/simple; bh=K4lXlgqVVUEjFaiEmeNT8cp8t/zc+jwgx6+aFm8+hp4=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=P31PUcVC26Kn/COQyROYEmgYbrXl8gAE7VWrBiH9a8TjM4lAhYBzxPLKPVUw+m1yloU9N5PyS9iLWmbGoVZ7Ssu0HqZRpogfTD7VDzFZQdVyUV/pj3lK+H8zNkwXDMSAPHXb319wVNqVL+EON45XNSjeiGLCuJ8MFEwOIA6wuKY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from loongson.cn (unknown [10.20.4.107]) by gateway (Coremail) with SMTP id _____8DxbOl2YbNliSYGAA--.11559S3; Fri, 26 Jan 2024 15:38:30 +0800 (CST) Received: from loongson-pc.loongson.cn (unknown [10.20.4.107]) by localhost.localdomain (Coremail) with SMTP id AQAAf8AxRMxeYbNlPpUbAA--.44775S4; Fri, 26 Jan 2024 15:38:24 +0800 (CST) From: Lulu Cheng To: gcc-patches@gcc.gnu.org Cc: xry111@xry111.site, i@xen0n.name, xuchenghua@loongson.cn, Lulu Cheng Subject: [PATCH v4 2/4] LoongArch: Add the macro implementation of mcmodel=extreme. Date: Fri, 26 Jan 2024 15:37:43 +0800 Message-Id: <20240126073745.13252-3-chenglulu@loongson.cn> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20240126073745.13252-1-chenglulu@loongson.cn> References: <20240126073745.13252-1-chenglulu@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8AxRMxeYbNlPpUbAA--.44775S4 X-CM-SenderInfo: xfkh0wpoxo3qxorr0wxvrqhubq/ X-Coremail-Antispam: 1Uk129KBj9fXoW3tF17ZrW3Gr1xJw1rXr4DKFX_yoW8WrW5Wo WrAFWUJw4xGr12krs8KrsxXry0yF10yrWxAa9Fvw1rCan7Ar15Ary3Gw45Z3sxXr9rXry5 u347WFnrJ3y7Xrs8l-sFpf9Il3svdjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8wcxFpf 9Il3svdxBIdaVrn0xqx4xG64xvF2IEw4CE5I8CrVC2j2Jv73VFW2AGmfu7bjvjm3AaLaJ3 UjIYCTnIWjp_UUUY17kC6x804xWl14x267AKxVWUJVW8JwAFc2x0x2IEx4CE42xK8VAvwI 8IcIk0rVWrJVCq3wAFIxvE14AKwVWUGVWUXwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xG Y2AK021l84ACjcxK6xIIjxv20xvE14v26r1I6r4UM28EF7xvwVC0I7IYx2IY6xkF7I0E14 v26r4j6F4UM28EF7xvwVC2z280aVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIEc7CjxVAF wI0_Gr1j6F4UJwAS0I0E0xvYzxvE52x082IY62kv0487Mc804VCY07AIYIkI8VC2zVCFFI 0UMc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUAVWUtwAv7VC2z280 aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JMxAIw28Icx kI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2Iq xVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUAVWUtwCIc40Y0x0EwIxGrwCI42 IY6xIIjxv20xvE14v26r1I6r4UMIIF0xvE2Ix0cI8IcVCY1x0267AKxVWUJVW8JwCI42IY 6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aV CY1x0267AKxVWUJVW8JbIYCTnIWIevJa73UjIFyTuYvjxU7MmhUUUUU X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_SHORT, KAM_STOCKGEN, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789137814459748555 X-GMAIL-MSGID: 1789137814459748555 gcc/ChangeLog: * config/loongarch/loongarch-protos.h (loongarch_symbol_extreme_p): Add function declaration. * config/loongarch/loongarch.cc (loongarch_symbolic_constant_p): For SYMBOL_PCREL64, non-zero addend of "la.local $rd,$rt,sym+addend" is not allowed (loongarch_load_tls): Added macro support in extreme mode. (loongarch_call_tls_get_addr): Likewise. (loongarch_legitimize_tls_address): Likewise. (loongarch_force_address): Likewise. (loongarch_legitimize_move): Likewise. (loongarch_output_mi_thunk): Likewise. (loongarch_option_override_internal): Remove the code that detects explicit relocs status. (loongarch_handle_model_attribute): Likewise. * config/loongarch/loongarch.md (movdi_symbolic_off64): New template. * config/loongarch/predicates.md (symbolic_off64_operand): New predicate. (symbolic_off64_or_reg_operand): Likewise. gcc/testsuite/ChangeLog: * gcc.target/loongarch/attr-model-5.c: New test. * gcc.target/loongarch/func-call-extreme-5.c: New test. * gcc.target/loongarch/func-call-extreme-6.c: New test. * gcc.target/loongarch/tls-extreme-macro.c: New test. --- gcc/config/loongarch/loongarch-protos.h | 1 + gcc/config/loongarch/loongarch.cc | 108 +++++++++++------- gcc/config/loongarch/loongarch.md | 42 +++++++ gcc/config/loongarch/predicates.md | 12 ++ .../gcc.target/loongarch/attr-model-5.c | 8 ++ .../loongarch/func-call-extreme-5.c | 7 ++ .../loongarch/func-call-extreme-6.c | 7 ++ .../gcc.target/loongarch/tls-extreme-macro.c | 35 ++++++ 8 files changed, 177 insertions(+), 43 deletions(-) create mode 100644 gcc/testsuite/gcc.target/loongarch/attr-model-5.c create mode 100644 gcc/testsuite/gcc.target/loongarch/func-call-extreme-5.c create mode 100644 gcc/testsuite/gcc.target/loongarch/func-call-extreme-6.c create mode 100644 gcc/testsuite/gcc.target/loongarch/tls-extreme-macro.c diff --git a/gcc/config/loongarch/loongarch-protos.h b/gcc/config/loongarch/loongarch-protos.h index 9ffc92afead..1fdfda9af01 100644 --- a/gcc/config/loongarch/loongarch-protos.h +++ b/gcc/config/loongarch/loongarch-protos.h @@ -222,4 +222,5 @@ extern rtx loongarch_build_signbit_mask (machine_mode, bool, bool); extern void loongarch_emit_swrsqrtsf (rtx, rtx, machine_mode, bool); extern void loongarch_emit_swdivsf (rtx, rtx, rtx, machine_mode); extern bool loongarch_explicit_relocs_p (enum loongarch_symbol_type); +extern bool loongarch_symbol_extreme_p (enum loongarch_symbol_type); #endif /* ! GCC_LOONGARCH_PROTOS_H */ diff --git a/gcc/config/loongarch/loongarch.cc b/gcc/config/loongarch/loongarch.cc index 2f7de6f94d3..4c64742f78b 100644 --- a/gcc/config/loongarch/loongarch.cc +++ b/gcc/config/loongarch/loongarch.cc @@ -1935,8 +1935,13 @@ loongarch_symbolic_constant_p (rtx x, enum loongarch_symbol_type *symbol_type) relocations. */ switch (*symbol_type) { - case SYMBOL_PCREL: case SYMBOL_PCREL64: + /* When the code model is extreme, the non-zero offset situation + has not been handled well, so it is disabled here now. */ + if (!loongarch_explicit_relocs_p (SYMBOL_PCREL64)) + return false; + /* fall through */ + case SYMBOL_PCREL: /* GAS rejects offsets outside the range [-2^31, 2^31-1]. */ return sext_hwi (INTVAL (offset), 32) == INTVAL (offset); @@ -2739,9 +2744,15 @@ static GTY (()) rtx loongarch_tls_symbol; /* Load an entry for a TLS access. */ static rtx -loongarch_load_tls (rtx dest, rtx sym) +loongarch_load_tls (rtx dest, rtx sym, enum loongarch_symbol_type type) { - return gen_load_tls (Pmode, dest, sym); + /* TLS LE gets a 32 or 64 bit offset here, so one register can do it. */ + if (type == SYMBOL_TLS_LE) + return gen_load_tls (Pmode, dest, sym); + + return loongarch_symbol_extreme_p (type) ? + gen_movdi_symbolic_off64 (dest, sym, gen_reg_rtx (DImode)) + : gen_load_tls (Pmode, dest, sym); } /* Return an instruction sequence that calls __tls_get_addr. SYM is @@ -2773,8 +2784,6 @@ loongarch_call_tls_get_addr (rtx sym, enum loongarch_symbol_type type, rtx v0) if (TARGET_CMODEL_EXTREME) { - gcc_assert (TARGET_EXPLICIT_RELOCS); - rtx tmp1 = gen_reg_rtx (Pmode); emit_insn (gen_tls_low (Pmode, tmp1, gen_rtx_REG (Pmode, 0), loc)); emit_insn (gen_lui_h_lo20 (tmp1, tmp1, loc)); @@ -2785,7 +2794,7 @@ loongarch_call_tls_get_addr (rtx sym, enum loongarch_symbol_type type, rtx v0) emit_insn (gen_tls_low (Pmode, a0, high, loc)); } else - emit_insn (loongarch_load_tls (a0, loc)); + emit_insn (loongarch_load_tls (a0, loc, type)); if (flag_plt) { @@ -2852,22 +2861,26 @@ loongarch_call_tls_get_addr (rtx sym, enum loongarch_symbol_type type, rtx v0) case CMODEL_EXTREME: { - gcc_assert (TARGET_EXPLICIT_RELOCS); - - rtx tmp1 = gen_reg_rtx (Pmode); - rtx high = gen_reg_rtx (Pmode); - - loongarch_emit_move (high, - gen_rtx_HIGH (Pmode, loongarch_tls_symbol)); - loongarch_emit_move (tmp1, gen_rtx_LO_SUM (Pmode, - gen_rtx_REG (Pmode, 0), - loongarch_tls_symbol)); - emit_insn (gen_lui_h_lo20 (tmp1, tmp1, loongarch_tls_symbol)); - emit_insn (gen_lui_h_hi12 (tmp1, tmp1, loongarch_tls_symbol)); - loongarch_emit_move (dest, - gen_rtx_MEM (Pmode, - gen_rtx_PLUS (Pmode, - high, tmp1))); + if (loongarch_explicit_relocs_p (SYMBOL_GOT_DISP)) + { + rtx tmp1 = gen_reg_rtx (Pmode); + rtx high = gen_reg_rtx (Pmode); + + loongarch_emit_move (high, + gen_rtx_HIGH (Pmode, loongarch_tls_symbol)); + loongarch_emit_move (tmp1, gen_rtx_LO_SUM (Pmode, + gen_rtx_REG (Pmode, 0), + loongarch_tls_symbol)); + emit_insn (gen_lui_h_lo20 (tmp1, tmp1, loongarch_tls_symbol)); + emit_insn (gen_lui_h_hi12 (tmp1, tmp1, loongarch_tls_symbol)); + loongarch_emit_move (dest, + gen_rtx_MEM (Pmode, + gen_rtx_PLUS (Pmode, + high, tmp1))); + } + else + emit_insn (gen_movdi_symbolic_off64 (dest, loongarch_tls_symbol, + gen_reg_rtx (DImode))); } break; @@ -2932,8 +2945,6 @@ loongarch_legitimize_tls_address (rtx loc) if (TARGET_CMODEL_EXTREME) { - gcc_assert (TARGET_EXPLICIT_RELOCS); - rtx tmp3 = gen_reg_rtx (Pmode); emit_insn (gen_tls_low (Pmode, tmp3, gen_rtx_REG (Pmode, 0), tmp2)); @@ -2948,7 +2959,7 @@ loongarch_legitimize_tls_address (rtx loc) emit_insn (gen_ld_from_got (Pmode, tmp1, high, tmp2)); } else - emit_insn (loongarch_load_tls (tmp1, tmp2)); + emit_insn (loongarch_load_tls (tmp1, tmp2, SYMBOL_TLS_IE)); emit_insn (gen_add3_insn (dest, tmp1, tp)); } break; @@ -3005,14 +3016,12 @@ loongarch_legitimize_tls_address (rtx loc) if (TARGET_CMODEL_EXTREME) { - gcc_assert (TARGET_EXPLICIT_RELOCS); - emit_insn (gen_lui_h_lo20 (tmp1, tmp1, tmp2)); emit_insn (gen_lui_h_hi12 (tmp1, tmp1, tmp2)); } } else - emit_insn (loongarch_load_tls (tmp1, tmp2)); + emit_insn (loongarch_load_tls (tmp1, tmp2, SYMBOL_TLS_LE)); emit_insn (gen_add3_insn (dest, tmp1, tp)); } break; @@ -3085,7 +3094,7 @@ loongarch_force_address (rtx x, machine_mode mode) return x; } -static bool +bool loongarch_symbol_extreme_p (enum loongarch_symbol_type type) { switch (type) @@ -3363,6 +3372,21 @@ loongarch_legitimize_move (machine_mode mode, rtx dest, rtx src) return true; } + /* Obtain the address of the symbol through the macro instruction + of two registers. */ + enum loongarch_symbol_type symbol_type; + if (TARGET_64BIT && register_operand (dest, mode) + && loongarch_symbolic_constant_p (src, &symbol_type) + && loongarch_symbol_extreme_p (symbol_type)) + { + gcc_assert (can_create_pseudo_p ()); + rtx tmp_reg = gen_reg_rtx (DImode); + emit_insn (gen_movdi_symbolic_off64 (dest, src, tmp_reg)); + set_unique_reg_note (get_last_insn (), REG_UNUSED, tmp_reg); + set_unique_reg_note (get_last_insn (), REG_EQUAL, src); + return true; + } + return false; } @@ -7419,12 +7443,22 @@ loongarch_output_mi_thunk (FILE *file, tree thunk_fndecl ATTRIBUTE_UNUSED, allowed, otherwise load the address into a register first. */ if (use_sibcall_p) { - insn = emit_call_insn (gen_sibcall_internal (fnaddr, const0_rtx)); + if (TARGET_CMODEL_EXTREME) + { + emit_insn (gen_movdi_symbolic_off64 (temp1, fnaddr, temp2)); + insn = emit_call_insn (gen_sibcall_internal (temp1, const0_rtx)); + } + else + insn = emit_call_insn (gen_sibcall_internal (fnaddr, const0_rtx)); SIBLING_CALL_P (insn) = 1; } else { - loongarch_emit_move (temp1, fnaddr); + if (TARGET_CMODEL_EXTREME) + emit_insn (gen_movdi_symbolic_off64 (temp1, fnaddr, temp2)); + else + loongarch_emit_move (temp1, fnaddr); + emit_jump_insn (gen_indirect_jump (temp1)); } @@ -7529,10 +7563,6 @@ loongarch_option_override_internal (struct gcc_options *opts, switch (la_target.cmodel) { case CMODEL_EXTREME: - if (la_opt_explicit_relocs == EXPLICIT_RELOCS_NONE) - error ("code model %qs is not compatible with %s", - "extreme", "-mexplicit-relocs=none"); - if (opts->x_flag_plt) { if (global_options_set.x_flag_plt) @@ -7950,14 +7980,6 @@ loongarch_handle_model_attribute (tree *node, tree name, tree arg, int, *no_add_attrs = true; return NULL_TREE; } - if (la_opt_explicit_relocs == EXPLICIT_RELOCS_NONE) - { - error_at (DECL_SOURCE_LOCATION (decl), - "%qE attribute is not compatible with %s", name, - "-mexplicit-relocs=none"); - *no_add_attrs = true; - return NULL_TREE; - } arg = TREE_VALUE (arg); if (TREE_CODE (arg) != STRING_CST) diff --git a/gcc/config/loongarch/loongarch.md b/gcc/config/loongarch/loongarch.md index 0b61b013798..5a2b181716a 100644 --- a/gcc/config/loongarch/loongarch.md +++ b/gcc/config/loongarch/loongarch.md @@ -82,6 +82,8 @@ (define_c_enum "unspec" [ UNSPEC_SIBCALL_VALUE_MULTIPLE_INTERNAL_1 UNSPEC_CALL_VALUE_MULTIPLE_INTERNAL_1 + + UNSPEC_LOAD_SYMBOL_OFFSET64 ]) (define_c_enum "unspecv" [ @@ -2182,6 +2184,46 @@ (define_insn_and_split "*movdi_64bit" [(set_attr "move_type" "move,const,load,store,mgtf,fpload,mftg,fpstore") (set_attr "mode" "DI")]) +;; Use two registers to get the global symbol address from the got table. +;; la.global rd, rt, sym + +(define_insn_and_split "movdi_symbolic_off64" + [(set (match_operand:DI 0 "register_operand" "=r,r") + (match_operand:DI 1 "symbolic_off64_or_reg_operand" "Yd,r")) + (unspec:DI [(const_int 0)] + UNSPEC_LOAD_SYMBOL_OFFSET64) + (clobber (match_operand:DI 2 "register_operand" "=&r,r"))] + "TARGET_64BIT && TARGET_CMODEL_EXTREME" +{ + if (which_alternative == 1) + return "#"; + + enum loongarch_symbol_type symbol_type; + gcc_assert (loongarch_symbolic_constant_p (operands[1], &symbol_type)); + + switch (symbol_type) + { + case SYMBOL_PCREL64: + return "la.local\t%0,%2,%1"; + case SYMBOL_GOT_DISP: + return "la.global\t%0,%2,%1"; + case SYMBOL_TLS_IE: + return "la.tls.ie\t%0,%2,%1"; + case SYMBOL_TLSGD: + return "la.tls.gd\t%0,%2,%1"; + case SYMBOL_TLSLDM: + return "la.tls.ld\t%0,%2,%1"; + + default: + gcc_unreachable (); + } +} + "&& REG_P (operands[1]) && find_reg_note (insn, REG_UNUSED, operands[2]) != 0" + [(set (match_dup 0) (match_dup 1))] + "" + [(set_attr "mode" "DI") + (set_attr "length" "5")]) + ;; 32-bit Integer moves (define_expand "movsi" diff --git a/gcc/config/loongarch/predicates.md b/gcc/config/loongarch/predicates.md index 01aad8dc631..eba7f246c84 100644 --- a/gcc/config/loongarch/predicates.md +++ b/gcc/config/loongarch/predicates.md @@ -576,6 +576,18 @@ (define_predicate "mem_simple_ldst_operand" || symbolic_pcrel_offset_operand (op, Pmode)); }) +(define_predicate "symbolic_off64_operand" + (match_code "const,symbol_ref,label_ref") +{ + enum loongarch_symbol_type type; + return loongarch_symbolic_constant_p (op, &type) + && loongarch_symbol_extreme_p (type); +}) + +(define_predicate "symbolic_off64_or_reg_operand" + (ior (match_operand 0 "register_operand") + (match_operand 0 "symbolic_off64_operand"))) + (define_predicate "equality_operator" (match_code "eq,ne")) diff --git a/gcc/testsuite/gcc.target/loongarch/attr-model-5.c b/gcc/testsuite/gcc.target/loongarch/attr-model-5.c new file mode 100644 index 00000000000..5f2c3ec9e44 --- /dev/null +++ b/gcc/testsuite/gcc.target/loongarch/attr-model-5.c @@ -0,0 +1,8 @@ +/* { dg-do compile } */ +/* { dg-options "-mexplicit-relocs=none -mcmodel=extreme -O2 -fno-pic" } */ +/* { dg-final { scan-assembler "la.local\t\\\$r\[0-9\]+,\\\$r\[0-9\]+,x" } } */ +/* { dg-final { scan-assembler "la.local\t\\\$r\[0-9\]+,y" } } */ +/* { dg-final { scan-assembler "la.local\t\\\$r\[0-9\]+,\\\$r\[0-9\]+,counter" } } */ + +#define ATTR_MODEL_TEST +#include "attr-model-test.c" diff --git a/gcc/testsuite/gcc.target/loongarch/func-call-extreme-5.c b/gcc/testsuite/gcc.target/loongarch/func-call-extreme-5.c new file mode 100644 index 00000000000..b1bd9d236ea --- /dev/null +++ b/gcc/testsuite/gcc.target/loongarch/func-call-extreme-5.c @@ -0,0 +1,7 @@ +/* { dg-do compile } */ +/* { dg-options "-mabi=lp64d -O0 -fpic -fno-plt -mexplicit-relocs=none -mcmodel=extreme" } */ +/* { dg-final { scan-assembler "test:.*la.global\t\\\$r\[0-9\]+,\\\$r\[0-9\]+,g" } } */ +/* { dg-final { scan-assembler "test1:.*la.global\t\\\$r\[0-9\]+,\\\$r\[0-9\]+,f" } } */ +/* { dg-final { scan-assembler "test2:.*la.local\t\\\$r\[0-9\]+,\\\$r\[0-9\]+,l" } } */ + +#include "func-call-extreme-1.c" diff --git a/gcc/testsuite/gcc.target/loongarch/func-call-extreme-6.c b/gcc/testsuite/gcc.target/loongarch/func-call-extreme-6.c new file mode 100644 index 00000000000..6e6ad5c9f5c --- /dev/null +++ b/gcc/testsuite/gcc.target/loongarch/func-call-extreme-6.c @@ -0,0 +1,7 @@ +/* { dg-do compile } */ +/* { dg-options "-mabi=lp64d -O0 -fno-pic -fno-plt -mexplicit-relocs=none -mcmodel=extreme" } */ +/* { dg-final { scan-assembler "test:.*la.global\t\\\$r\[0-9\]+,\\\$r\[0-9\]+,g" } } */ +/* { dg-final { scan-assembler "test1:.*la.local\t\\\$r\[0-9\]+,\\\$r\[0-9\]+,f" } } */ +/* { dg-final { scan-assembler "test2:.*la.local\t\\\$r\[0-9\]+,\\\$r\[0-9\]+,l" } } */ + +#include "func-call-extreme-1.c" diff --git a/gcc/testsuite/gcc.target/loongarch/tls-extreme-macro.c b/gcc/testsuite/gcc.target/loongarch/tls-extreme-macro.c new file mode 100644 index 00000000000..4341f82129c --- /dev/null +++ b/gcc/testsuite/gcc.target/loongarch/tls-extreme-macro.c @@ -0,0 +1,35 @@ +/* { dg-do compile } */ +/* { dg-options "-march=loongarch64 -mabi=lp64d -O2 -mcmodel=extreme -fno-plt -mexplicit-relocs=none" } */ +/* { dg-final { scan-assembler "test_le:.*la.tls.le\t\\\$r\[0-9\]+,\\\.L" { target tls_native } } } */ +/* { dg-final { scan-assembler "test_ie:.*la.tls.ie\t\\\$r\[0-9\]+,\\\$r\[0-9\]+,\\\.L" { target tls_native } } } */ +/* { dg-final { scan-assembler "test_ld:.*la.tls.ld\t\\\$r\[0-9\]+,\\\$r\[0-9\]+,\\\.L.*la.global\t\\\$r\[0-9\]+,\\\$r\[0-9\]+,__tls_get_addr" { target tls_native } } } */ +/* { dg-final { scan-assembler "test_le:.*la.tls.gd\t\\\$r\[0-9\]+,\\\$r\[0-9\]+,\\\.L.*la.global\t\\\$r\[0-9\]+,\\\$r\[0-9\]+,__tls_get_addr" { target tls_native } } } */ + +__thread int c __attribute__ ((tls_model ("local-exec"))); +__thread int d __attribute__ ((tls_model ("initial-exec"))); +__thread int e __attribute__ ((tls_model ("local-dynamic"))); +__thread int f __attribute__ ((tls_model ("global-dynamic"))); + +int +test_le (void) +{ + return c; +} + +int +test_ie (void) +{ + return d; +} + +int +test_ld (void) +{ + return e; +} + +int +test_gd (void) +{ + return f; +}