From patchwork Fri Jan 5 03:40:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lulu Cheng X-Patchwork-Id: 1882724 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4T5q4k31Zwz1ydb for ; Fri, 5 Jan 2024 14:41:26 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 68C983857BA3 for ; Fri, 5 Jan 2024 03:41:24 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from eggs.gnu.org (eggs.gnu.org [IPv6:2001:470:142:3::10]) by sourceware.org (Postfix) with ESMTPS id BF4453858036 for ; Fri, 5 Jan 2024 03:40:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BF4453858036 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=loongson.cn ARC-Filter: OpenARC Filter v1.0.0 sourceware.org BF4453858036 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2001:470:142:3::10 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704426060; cv=none; b=tm3/y70v6ZvZT5CqhnBV4WGEzFSF5f6gJTWvKWD1LhNCSTpjhyGjtTX/d6fLfk0/yIDRMWsMfiu6R7nsd0qi5bS+lnChPssSZG7+EpV9kUbVnV5Hj33xJhArLchNV7WCGdKL0ICyNbkYYT/DabDe0r/lB/0ejIxId0IVJfPH4Jg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704426060; c=relaxed/simple; bh=pKBQStmLQVl8VICvny4nxK8rkFjMgxzEc3IfDvf1F3U=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=IGJurQz04sDxB33CVeHHgSQBYHqGGNHxjXzfrR27dK8ifSXFsmoyoZyZWTuimBBXbvQiK35wZsbd5qVj21VSl4tpmSKzLghCKKAVQZ02pf35Ndl2Y8SqOlZF4EIv2t/iut0zGLqbByDfUfGCKFHnH6GB4sAk9NeqaFjMkAgKJy4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from mail.loongson.cn ([114.242.206.163]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rLb4n-0001lk-69 for gcc-patches@gcc.gnu.org; Thu, 04 Jan 2024 22:40:56 -0500 Received: from loongson.cn (unknown [10.20.4.107]) by gateway (Coremail) with SMTP id _____8DxPOs9epdlFS0CAA--.8311S3; Fri, 05 Jan 2024 11:40:45 +0800 (CST) Received: from loongson-pc.loongson.cn (unknown [10.20.4.107]) by localhost.localdomain (Coremail) with SMTP id AQAAf8BxbNw1epdlcMkCAA--.7338S3; Fri, 05 Jan 2024 11:40:44 +0800 (CST) From: Lulu Cheng To: gcc-patches@gcc.gnu.org Cc: xry111@xry111.site, i@xen0n.name, xuchenghua@loongson.cn, chenglulu@loongson.cn Subject: [PATCH v2 1/2] LoongArch: Add the macro implementation of mcmodel=extreme. Date: Fri, 5 Jan 2024 11:40:20 +0800 Message-Id: <20240105034021.30177-2-chenglulu@loongson.cn> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20240105034021.30177-1-chenglulu@loongson.cn> References: <20240105034021.30177-1-chenglulu@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8BxbNw1epdlcMkCAA--.7338S3 X-CM-SenderInfo: xfkh0wpoxo3qxorr0wxvrqhubq/ X-Coremail-Antispam: 1Uk129KBj93XoWxtFWrJF1xJw43JF4kZFy8tFc_yoW3tr4fp3 y7Cw1UKr4rJrn7K34kJa45XrsrJrsFgF429asxtrWIkF47Xr1xXFy0krWaqa45Ga1Yqry7 Z3WS93WUW3W5C3gCm3ZEXasCq-sJn29KB7ZKAUJUUUU8529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUkYb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_JFI_Gr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Jr0_Gr1l84ACjcxK6I8E87Iv67AKxVWxJVW8Jr1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6r4UJVWxJr1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqjxCEc2xF0cIa020Ex4CE44I27w Aqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_JF0_Jw1lYx0Ex4A2jsIE 14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwCF04k20xvY0x 0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E 7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw1lIxkGc2Ij64vIr41lIxAIcV C0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Jr0_Gr1lIxAIcVCF 04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7 CjxVAFwI0_Jr0_GrUvcSsGvfC2KfnxnUUI43ZEXa7IU1LiSJUUUUU== Received-SPF: pass client-ip=114.242.206.163; envelope-from=chenglulu@loongson.cn; helo=mail.loongson.cn X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_SHORT, KAM_STOCKGEN, SPF_FAIL, SPF_HELO_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+incoming=patchwork.ozlabs.org@gcc.gnu.org gcc/ChangeLog: * config/loongarch/loongarch.cc (loongarch_symbolic_constant_p): Remove the sym+addend form from the SYMBOL_PCREL64 type symbol. (loongarch_output_mi_thunk): Add code model extreme support. (loongarch_option_override_internal): Supports option combinations of -cmodel=extreme and -mexplicit-relocs=none. (loongarch_handle_model_attribute): Remove detection code. * config/loongarch/loongarch.md (movdi_pcrel64): New templated. (movdi_got_disp): Likewise. * config/loongarch/predicates.md (symbolic_got_operand): Determine whether the symbol type is SYMBOL_GOT_DISP. (symbolic_pcrel64_operand): Determine whether the symbol type is SYMBOL_PCREL64. gcc/testsuite/ChangeLog: * gcc.target/loongarch/func-call-extreme-5.c: New test. * gcc.target/loongarch/func-call-extreme-6.c: New test. --- gcc/config/loongarch/loongarch.cc | 28 +++++------ gcc/config/loongarch/loongarch.md | 50 +++++++++++++++++++ gcc/config/loongarch/predicates.md | 14 ++++++ .../loongarch/func-call-extreme-5.c | 7 +++ .../loongarch/func-call-extreme-6.c | 7 +++ 5 files changed, 91 insertions(+), 15 deletions(-) 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 diff --git a/gcc/config/loongarch/loongarch.cc b/gcc/config/loongarch/loongarch.cc index 28d64135c54..6a3321327ea 100644 --- a/gcc/config/loongarch/loongarch.cc +++ b/gcc/config/loongarch/loongarch.cc @@ -1944,10 +1944,10 @@ loongarch_symbolic_constant_p (rtx x, enum loongarch_symbol_type *symbol_type) case SYMBOL_TLSGD: case SYMBOL_TLSLDM: case SYMBOL_PCREL: - case SYMBOL_PCREL64: /* GAS rejects offsets outside the range [-2^31, 2^31-1]. */ return sext_hwi (INTVAL (offset), 32) == INTVAL (offset); + case SYMBOL_PCREL64: case SYMBOL_GOT_DISP: case SYMBOL_TLS: return false; @@ -7450,12 +7450,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_pcrel64 (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_pcrel64 (temp1, fnaddr, temp2)); + else + loongarch_emit_move (temp1, fnaddr); + emit_jump_insn (gen_indirect_jump (temp1)); } @@ -7583,10 +7593,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) @@ -7951,14 +7957,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 d1f5b94f5d6..c0365dc9e99 100644 --- a/gcc/config/loongarch/loongarch.md +++ b/gcc/config/loongarch/loongarch.md @@ -85,6 +85,9 @@ (define_c_enum "unspec" [ UNSPEC_SIBCALL_VALUE_MULTIPLE_INTERNAL_1 UNSPEC_CALL_VALUE_MULTIPLE_INTERNAL_1 + + UNSPEC_MOV_PCREL64 + UNSPEC_MOV_GOT_DISP ]) (define_c_enum "unspecv" [ @@ -2057,6 +2060,25 @@ (define_expand "movdi" { if (loongarch_legitimize_move (DImode, operands[0], operands[1])) DONE; + + enum loongarch_symbol_type symbol_type; + if (loongarch_symbolic_constant_p (operands[1], &symbol_type)) + { + if (symbol_type == SYMBOL_PCREL64) + { + gcc_assert (can_create_pseudo_p ()); + emit_insn (gen_movdi_pcrel64 (operands[0], operands[1], + gen_reg_rtx (DImode))); + DONE; + } + else if (TARGET_CMODEL_EXTREME && symbol_type == SYMBOL_GOT_DISP) + { + gcc_assert (can_create_pseudo_p ()); + emit_insn (gen_movdi_got_disp (operands[0], operands[1], + gen_reg_rtx (DImode))); + DONE; + } + } }) (define_insn_and_split "*movdi_32bit" @@ -2097,6 +2119,34 @@ (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 local symbol address. +;; la.local rd, rt, sym + +(define_insn "movdi_pcrel64" + [(set (match_operand:DI 0 "register_operand" "=r") + (match_operand:DI 1 "symbolic_pcrel64_operand")) + (unspec:DI [(const_int 0)] + UNSPEC_MOV_PCREL64) + (clobber (match_operand:DI 2 "register_operand" "=&r"))] + "TARGET_64BIT" + "la.local\t%0,%2,%1" + [(set_attr "mode" "DI") + (set_attr "length" "5")]) + +;; Use two registers to get the global symbol address from the got table. +;; la.global rd, rt, sym + +(define_insn "movdi_got_disp" + [(set (match_operand:DI 0 "register_operand" "=r") + (match_operand:DI 1 "symbolic_got_operand")) + (unspec:DI [(const_int 0)] + UNSPEC_MOV_GOT_DISP) + (clobber (match_operand:DI 2 "register_operand" "=&r"))] + "TARGET_64BIT && TARGET_CMODEL_EXTREME" + "la.global\t%0,%2,%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 ba5336cfb3e..d136dcc1c03 100644 --- a/gcc/config/loongarch/predicates.md +++ b/gcc/config/loongarch/predicates.md @@ -592,6 +592,20 @@ (define_predicate "mem_simple_ldst_operand" || symbolic_pcrel_offset_operand (op, Pmode)); }) +(define_predicate "symbolic_got_operand" + (match_code "const,symbol_ref,label_ref") +{ + enum loongarch_symbol_type type; + return loongarch_symbolic_constant_p (op, &type) && type == SYMBOL_GOT_DISP; +}) + +(define_predicate "symbolic_pcrel64_operand" + (match_code "const,symbol_ref,label_ref") +{ + enum loongarch_symbol_type type; + return loongarch_symbolic_constant_p (op, &type) && type == SYMBOL_PCREL64; +}) + (define_predicate "equality_operator" (match_code "eq,ne")) 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..8ecf5bc7525 --- /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.*,\\\$r15,g" } } */ +/* { dg-final { scan-assembler "test1:.*la.global.*,\\\$r15,f" } } */ +/* { dg-final { scan-assembler "test2:.*la.local.*,\\\$r15,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..81830d4d215 --- /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.*,\\\$r15,g" } } */ +/* { dg-final { scan-assembler "test1:.*la.local.*,\\\$r15,f" } } */ +/* { dg-final { scan-assembler "test2:.*la.local.*,\\\$r15,l" } } */ + +#include "func-call-extreme-1.c" From patchwork Fri Jan 5 03:40:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lulu Cheng X-Patchwork-Id: 1882723 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4T5q4c1wRQz23dn for ; Fri, 5 Jan 2024 14:41:20 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4A8683857BAE for ; Fri, 5 Jan 2024 03:41:18 +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 CD0A23858C53 for ; Fri, 5 Jan 2024 03:40:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CD0A23858C53 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 CD0A23858C53 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=1704426052; cv=none; b=ujofhg3UYrhmhNN9oqHc08JfH3ldof0uMVIVkq9eEs3TStliZ+a7Gw6XrINPSqMtoVR6MFHvwIV/MwrQ7vSAZkiv2Vn6y9M96eUDq2FQRnEMnoiZnVTCMalTpPNWw/3zFfU7ba+TORXDbo26WL07SYbOJx/mFqoNiKqdthjO/EM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704426052; c=relaxed/simple; bh=NqxsTc2QdcJxu8BHu1TiLd74wE7q2CR+D4Eeh73TNMk=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=DA6JmcCXMwT/3Ifp++l0b/wlGpjPlj2rJOPFtjDyecDSOJowOx8BOB+59Z0+hESEGd7z/n7RhlefWwtO4BkOOjU6WKkgAxv/G7w12N1tdN81VZs76xmxp0CVHhKRUqcmGiGXr4fFro6vFvE7B1GGkDsBGantMu5ekGwRwS+xP5s= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from loongson.cn (unknown [10.20.4.107]) by gateway (Coremail) with SMTP id _____8Cx7+s_epdlGC0CAA--.8317S3; Fri, 05 Jan 2024 11:40:47 +0800 (CST) Received: from loongson-pc.loongson.cn (unknown [10.20.4.107]) by localhost.localdomain (Coremail) with SMTP id AQAAf8BxbNw1epdlcMkCAA--.7338S4; Fri, 05 Jan 2024 11:40:45 +0800 (CST) From: Lulu Cheng To: gcc-patches@gcc.gnu.org Cc: xry111@xry111.site, i@xen0n.name, xuchenghua@loongson.cn, chenglulu@loongson.cn Subject: [PATCH v2 2/2] LoongArch: When the code model is extreme, the symbol address is obtained through macro instructions regardless of the value of -mexplicit-relocs. Date: Fri, 5 Jan 2024 11:40:21 +0800 Message-Id: <20240105034021.30177-3-chenglulu@loongson.cn> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20240105034021.30177-1-chenglulu@loongson.cn> References: <20240105034021.30177-1-chenglulu@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8BxbNw1epdlcMkCAA--.7338S4 X-CM-SenderInfo: xfkh0wpoxo3qxorr0wxvrqhubq/ X-Coremail-Antispam: 1Uk129KBj93XoW3Cr15Ww13CFyDGrWfZw4DWrX_yoWDKr48pa y7Ar1Yqr4rGa97K3WkXa4rJrZ3Za1DKrWa9wnxJryxZF4jq3sFqaykKa9rtF4UJF1UtryS vr1I9w17XFsaq3cCm3ZEXasCq-sJn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUkYb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1Y6r17M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_JFI_Gr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Jr0_Gr1l84ACjcxK6I8E87Iv67AKxVWxJVW8Jr1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6r4UJVWxJr1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqjxCEc2xF0cIa020Ex4CE44I27w Aqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_JF0_Jw1lYx0Ex4A2jsIE 14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwCF04k20xvY0x 0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E 7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw1lIxkGc2Ij64vIr41lIxAIcV C0I7IYx2IY67AKxVWUCVW8JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Jr0_Gr1lIxAIcVCF 04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7 CjxVAFwI0_Jr0_GrUvcSsGvfC2KfnxnUUI43ZEXa7IU82g43UUUUU== X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_SHORT, 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Instructions pcalau12i, addi.d, lu32i.d and lu52i.d must be adjancent so that the linker can infer the PC of pcalau12i to apply relocations to lu32i.d and lu52i.d. Otherwise, the results would be incorrect if these four instructions are not in the same 4KiB page. See the link for details: https://github.com/loongson/la-abi-specs/blob/release/laelf.adoc#extreme-code-model. gcc/ChangeLog: * config/loongarch/loongarch.cc (loongarch_symbol_extreme_p): Add function declaration. (loongarch_explicit_relocs_p): Use the macro instruction to get the symbol address when loongarch_symbol_extreme_p returns true. gcc/testsuite/ChangeLog: * gcc.target/loongarch/attr-model-1.c: Modify the content of the search string in the test case. * gcc.target/loongarch/attr-model-2.c: Likewise. * gcc.target/loongarch/attr-model-3.c: Likewise. * gcc.target/loongarch/attr-model-4.c: Likewise. * gcc.target/loongarch/func-call-extreme-1.c: Likewise. * gcc.target/loongarch/func-call-extreme-2.c: Likewise. * gcc.target/loongarch/func-call-extreme-3.c: Likewise. * gcc.target/loongarch/func-call-extreme-4.c: Likewise. --- gcc/config/loongarch/loongarch.cc | 11 +++++++++++ gcc/testsuite/gcc.target/loongarch/attr-model-1.c | 2 +- gcc/testsuite/gcc.target/loongarch/attr-model-2.c | 2 +- gcc/testsuite/gcc.target/loongarch/attr-model-3.c | 2 +- gcc/testsuite/gcc.target/loongarch/attr-model-4.c | 2 +- .../gcc.target/loongarch/func-call-extreme-1.c | 6 +++--- .../gcc.target/loongarch/func-call-extreme-2.c | 6 +++--- .../gcc.target/loongarch/func-call-extreme-3.c | 6 +++--- .../gcc.target/loongarch/func-call-extreme-4.c | 6 +++--- 9 files changed, 27 insertions(+), 16 deletions(-) diff --git a/gcc/config/loongarch/loongarch.cc b/gcc/config/loongarch/loongarch.cc index 6a3321327ea..3b4b28f3bcc 100644 --- a/gcc/config/loongarch/loongarch.cc +++ b/gcc/config/loongarch/loongarch.cc @@ -264,6 +264,9 @@ const char *const loongarch_fp_conditions[16]= {LARCH_FP_CONDITIONS (STRINGIFY)}; #undef STRINGIFY +static bool +loongarch_symbol_extreme_p (enum loongarch_symbol_type type); + /* Size of guard page. */ #define STACK_CLASH_PROTECTION_GUARD_SIZE \ (1 << param_stack_clash_protection_guard_size) @@ -1963,6 +1966,14 @@ loongarch_symbolic_constant_p (rtx x, enum loongarch_symbol_type *symbol_type) bool loongarch_explicit_relocs_p (enum loongarch_symbol_type type) { + /* Instructions pcalau12i, addi.d, lu32i.d and lu52i.d must be adjancent + so that the linker can infer the PC of pcalau12i to apply relocations + to lu32i.d and lu52i.d. Otherwise, the results would be incorrect if + these four instructions are not in the same 4KiB page. + Therefore, macro instructions are used when cmodel=extreme. */ + if (loongarch_symbol_extreme_p (type)) + return false; + if (la_opt_explicit_relocs != EXPLICIT_RELOCS_AUTO) return la_opt_explicit_relocs == EXPLICIT_RELOCS_ALWAYS; diff --git a/gcc/testsuite/gcc.target/loongarch/attr-model-1.c b/gcc/testsuite/gcc.target/loongarch/attr-model-1.c index 916d715b98b..65acb29162c 100644 --- a/gcc/testsuite/gcc.target/loongarch/attr-model-1.c +++ b/gcc/testsuite/gcc.target/loongarch/attr-model-1.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-options "-mexplicit-relocs -mcmodel=normal -O2" } */ -/* { dg-final { scan-assembler-times "%pc64_hi12" 2 } } */ +/* { dg-final { scan-assembler-times "la\.local\t\\\$r\[0-9\]+,\\\$r15," 2 } } */ #define ATTR_MODEL_TEST #include "attr-model-test.c" diff --git a/gcc/testsuite/gcc.target/loongarch/attr-model-2.c b/gcc/testsuite/gcc.target/loongarch/attr-model-2.c index a74c795ac3e..cf0f079e39a 100644 --- a/gcc/testsuite/gcc.target/loongarch/attr-model-2.c +++ b/gcc/testsuite/gcc.target/loongarch/attr-model-2.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-options "-mexplicit-relocs -mcmodel=extreme -O2" } */ -/* { dg-final { scan-assembler-times "%pc64_hi12" 3 } } */ +/* { dg-final { scan-assembler-times "la\.local\t\\\$r\[0-9\]+,\\\$r15," 3 } } */ #define ATTR_MODEL_TEST #include "attr-model-test.c" diff --git a/gcc/testsuite/gcc.target/loongarch/attr-model-3.c b/gcc/testsuite/gcc.target/loongarch/attr-model-3.c index 5622d508678..7c270d462f7 100644 --- a/gcc/testsuite/gcc.target/loongarch/attr-model-3.c +++ b/gcc/testsuite/gcc.target/loongarch/attr-model-3.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-options "-mexplicit-relocs=auto -mcmodel=normal -O2" } */ -/* { dg-final { scan-assembler-times "%pc64_hi12" 2 } } */ +/* { dg-final { scan-assembler-times "la\.local\t\\\$r\[0-9\]+,\\\$r15," 2 } } */ #define ATTR_MODEL_TEST #include "attr-model-test.c" diff --git a/gcc/testsuite/gcc.target/loongarch/attr-model-4.c b/gcc/testsuite/gcc.target/loongarch/attr-model-4.c index 482724bb974..627d630c36d 100644 --- a/gcc/testsuite/gcc.target/loongarch/attr-model-4.c +++ b/gcc/testsuite/gcc.target/loongarch/attr-model-4.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-options "-mexplicit-relocs=auto -mcmodel=extreme -O2" } */ -/* { dg-final { scan-assembler-times "%pc64_hi12" 3 } } */ +/* { dg-final { scan-assembler-times "la\.local\t\\\$r\[0-9\]+,\\\$r15," 3 } } */ #define ATTR_MODEL_TEST #include "attr-model-test.c" diff --git a/gcc/testsuite/gcc.target/loongarch/func-call-extreme-1.c b/gcc/testsuite/gcc.target/loongarch/func-call-extreme-1.c index db1e0f85396..46318f3d23f 100644 --- a/gcc/testsuite/gcc.target/loongarch/func-call-extreme-1.c +++ b/gcc/testsuite/gcc.target/loongarch/func-call-extreme-1.c @@ -1,8 +1,8 @@ /* { dg-do compile } */ /* { dg-options "-mabi=lp64d -O0 -fno-pic -fno-plt -mexplicit-relocs -mcmodel=extreme" } */ -/* { dg-final { scan-assembler "test:.*pcalau12i.*%got_pc_hi20.*\n\taddi\.d.*%got_pc_lo12.*\n\tlu32i\.d.*%got64_pc_lo20.*\n\tlu52i\.d.*%got64_pc_hi12.*\n\tldx\.d" } } */ -/* { dg-final { scan-assembler "test1:.*pcalau12i.*%pc_hi20.*\n\taddi\.d.*%pc_lo12.*\n\tlu32i\.d.*%pc64_lo20.*\n\tlu52i\.d.*pc64_hi12.*\n\tadd\.d" } } */ -/* { dg-final { scan-assembler "test2:.*pcalau12i.*%pc_hi20.*\n\taddi\.d.*%pc_lo12.*\n\tlu32i\.d.*%pc64_lo20.*\n\tlu52i\.d.*pc64_hi12.*\n\tadd\.d" } } */ +/* { dg-final { scan-assembler "test:.*la\.global.*,\\\$r15," } } */ +/* { dg-final { scan-assembler "test1:.*la\.local.*,\\\$r15," } } */ +/* { dg-final { scan-assembler "test2:.*la\.local.*,\\\$r15," } } */ extern void g (void); void diff --git a/gcc/testsuite/gcc.target/loongarch/func-call-extreme-2.c b/gcc/testsuite/gcc.target/loongarch/func-call-extreme-2.c index 21bf81ae837..14b6e658ca1 100644 --- a/gcc/testsuite/gcc.target/loongarch/func-call-extreme-2.c +++ b/gcc/testsuite/gcc.target/loongarch/func-call-extreme-2.c @@ -1,8 +1,8 @@ /* { dg-do compile } */ /* { dg-options "-mabi=lp64d -O0 -fpic -fno-plt -mexplicit-relocs -mcmodel=extreme" } */ -/* { dg-final { scan-assembler "test:.*pcalau12i.*%got_pc_hi20.*\n\taddi\.d.*%got_pc_lo12.*\n\tlu32i\.d.*%got64_pc_lo20.*\n\tlu52i\.d.*%got64_pc_hi12.*\n\tldx\.d" } } */ -/* { dg-final { scan-assembler "test1:.*pcalau12i.*%got_pc_hi20.*\n\taddi\.d.*%got_pc_lo12.*\n\tlu32i\.d.*%got64_pc_lo20.*\n\tlu52i\.d.*%got64_pc_hi12.*\n\tldx\.d" } } */ -/* { dg-final { scan-assembler "test2:.*pcalau12i.*%pc_hi20.*\n\taddi\.d.*%pc_lo12.*\n\tlu32i\.d.*%pc64_lo20.*\n\tlu52i\.d.*pc64_hi12.*\n\tadd\.d" } } */ +/* { dg-final { scan-assembler "test:.*la\.global.*,\\\$r15," } } */ +/* { dg-final { scan-assembler "test1:.*la\.global.*,\\\$r15," } } */ +/* { dg-final { scan-assembler "test2:.*la\.local.*,\\\$r15," } } */ extern void g (void); void diff --git a/gcc/testsuite/gcc.target/loongarch/func-call-extreme-3.c b/gcc/testsuite/gcc.target/loongarch/func-call-extreme-3.c index a4da44b4a3d..2ccbd2deb7c 100644 --- a/gcc/testsuite/gcc.target/loongarch/func-call-extreme-3.c +++ b/gcc/testsuite/gcc.target/loongarch/func-call-extreme-3.c @@ -1,7 +1,7 @@ /* { dg-do compile } */ /* { dg-options "-mabi=lp64d -O0 -fno-pic -fno-plt -mexplicit-relocs=auto -mcmodel=extreme" } */ -/* { dg-final { scan-assembler "test:.*pcalau12i.*%got_pc_hi20.*\n\taddi\.d.*%got_pc_lo12.*\n\tlu32i\.d.*%got64_pc_lo20.*\n\tlu52i\.d.*%got64_pc_hi12.*\n\tldx\.d" } } */ -/* { dg-final { scan-assembler "test1:.*pcalau12i.*%pc_hi20.*\n\taddi\.d.*%pc_lo12.*\n\tlu32i\.d.*%pc64_lo20.*\n\tlu52i\.d.*pc64_hi12.*\n\tadd\.d" } } */ -/* { dg-final { scan-assembler "test2:.*pcalau12i.*%pc_hi20.*\n\taddi\.d.*%pc_lo12.*\n\tlu32i\.d.*%pc64_lo20.*\n\tlu52i\.d.*pc64_hi12.*\n\tadd\.d" } } */ +/* { dg-final { scan-assembler "test:.*la\.global.*,\\\$r15," } } */ +/* { dg-final { scan-assembler "test1:.*la\.local.*,\\\$r15," } } */ +/* { dg-final { scan-assembler "test2:.*la\.local.*,\\\$r15," } } */ #include "func-call-extreme-1.c" diff --git a/gcc/testsuite/gcc.target/loongarch/func-call-extreme-4.c b/gcc/testsuite/gcc.target/loongarch/func-call-extreme-4.c index 16b00f4c5f2..0067024ef7d 100644 --- a/gcc/testsuite/gcc.target/loongarch/func-call-extreme-4.c +++ b/gcc/testsuite/gcc.target/loongarch/func-call-extreme-4.c @@ -1,7 +1,7 @@ /* { dg-do compile } */ /* { dg-options "-mabi=lp64d -O0 -fpic -fno-plt -mexplicit-relocs=auto -mcmodel=extreme" } */ -/* { dg-final { scan-assembler "test:.*pcalau12i.*%got_pc_hi20.*\n\taddi\.d.*%got_pc_lo12.*\n\tlu32i\.d.*%got64_pc_lo20.*\n\tlu52i\.d.*%got64_pc_hi12.*\n\tldx\.d" } } */ -/* { dg-final { scan-assembler "test1:.*pcalau12i.*%got_pc_hi20.*\n\taddi\.d.*%got_pc_lo12.*\n\tlu32i\.d.*%got64_pc_lo20.*\n\tlu52i\.d.*%got64_pc_hi12.*\n\tldx\.d" } } */ -/* { dg-final { scan-assembler "test2:.*pcalau12i.*%pc_hi20.*\n\taddi\.d.*%pc_lo12.*\n\tlu32i\.d.*%pc64_lo20.*\n\tlu52i\.d.*pc64_hi12.*\n\tadd\.d" } } */ +/* { dg-final { scan-assembler "test:.*la\.global.*,\\\$r15," } } */ +/* { dg-final { scan-assembler "test1:.*la\.global.*,\\\$r15," } } */ +/* { dg-final { scan-assembler "test2:.*la\.local.*,\\\$r15," } } */ #include "func-call-extreme-1.c"