From patchwork Fri Jan 5 07:44:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: chenglulu X-Patchwork-Id: 185256 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp6077359dyb; Thu, 4 Jan 2024 23:45:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IFGFHE7Cz1ll+EdqSp7f4//+xf9yHhmbg7naA1jlGLk1CI30df697ks27MqgqF5XCLi59ba X-Received: by 2002:a05:620a:24c7:b0:781:baa1:ca86 with SMTP id m7-20020a05620a24c700b00781baa1ca86mr2090544qkn.157.1704440738847; Thu, 04 Jan 2024 23:45:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1704440738; cv=pass; d=google.com; s=arc-20160816; b=cajBnY2yJC810AdaxBlXfdp2CFtkfZmBV2BFtOarfpB+FQxA7oETdxZkxJXL641Mv0 lytGlXtlJzdATTu2OtUjOf1Ua/+MWEFTK3Jml4dsaCYsGUstnbhzonHPfyNVkVqM7EdY HMY6ANyxAJaycuccP8kvPLuLPn+RN5gKECclI0XxhjO854cxHSO4D/451AdGYBUUGtxI NdpaxhqbE+xkM8QL0EWjsMghaVdb4usR7CsmJ0hO8pmtmM3iGVxZhda56wtwYta/KVxc TKUE5mM10r5AszhgNxfacWOp/H/ZP4SQx2fTkdu+TllNEAadtocLCDc8fhdGuq5HdidB Dsug== 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=5aHamOr/0amsjPZdSKpR91HfbDisDymZ9RFj0Fix7JA=; fh=wYRiZnn9nDBltyuQH1H/s7FMOEBgw7D5UzXRQ9Hnwic=; b=VyBMeglUljSrNDfmGFldLebg5CroTibvM6Sal5EpKe2eh0OfFPapXRtKry2V9sED83 ytWv6Ct0javzcunb7JSFJ05kvi/PtgAcs4fsqNsuWrHDALbyuu/2G3EVeVeKVhXdIIw2 i08UhxGyp2FNSKwbPt36vw1tB++Li7We32UyWMHOBRAOeifrS04Orv7o+36ZAMT7038l b3Qe8pvP3rE9WE9KpuE9qdUH635ixvf43yC2HrEcvOQkbNrZSiInXqk4iqdIYCdNYfCQ pyDXE9iiJw5kUZLJOUPvlw9rKs2TXoSuL9xkP5gLC404WG+wnBMlIFR9DrUvSb74hJZ/ 5RfA== 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 bm21-20020a05620a199500b00781477fdeadsi1285689qkb.467.2024.01.04.23.45.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 23:45:38 -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 8949E385E02F for ; Fri, 5 Jan 2024 07:45:38 +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 2CE77385DC3E for ; Fri, 5 Jan 2024 07:44:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2CE77385DC3E 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 2CE77385DC3E 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=1704440680; cv=none; b=COAX1rjcSnrZheYdaRw7NzC8Rliulu9v2z/nxw+F3Ab8o1QMwk09W25ufZiEO60Ic5blL9/5jt57FIZlwjmPwRnFnnEP8MfI7rUEq5G/YGarjTd1vmRYX2Rt7B5VkWtuGGDWFGSNQhVe31fHaHU6dEgE1+VHZf6YXV4cmrv4M2w= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704440680; c=relaxed/simple; bh=V+zl26TSf2aSM30BJM1Lrsew3m92hVXoTTrt1wfqSSo=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=WzKfiGK5yDWz/BRpzFA6o7IbCc06AwOpbiXR/TqpG6ok3CnalqKuA1zxrKLNGKBFQURKWa4etDPOBrAe4YzOFFKGVvvPp2Dm1dru5kvq+TUXIzCVZuhqwEBv+8zdSmAn/Y1oovDOOx4GFrKXoRW0HX9UTo0UBUNvOXLHgZSCbIU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from loongson.cn (unknown [10.20.4.107]) by gateway (Coremail) with SMTP id _____8BxXbtes5dlzD4CAA--.98S3; Fri, 05 Jan 2024 15:44:30 +0800 (CST) Received: from loongson-pc.loongson.cn (unknown [10.20.4.107]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Cxyt1Xs5dlkhIDAA--.7970S3; Fri, 05 Jan 2024 15:44:26 +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 v3 1/2] LoongArch: Add the macro implementation of mcmodel=extreme. Date: Fri, 5 Jan 2024 15:44:11 +0800 Message-Id: <20240105074412.14096-2-chenglulu@loongson.cn> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20240105074412.14096-1-chenglulu@loongson.cn> References: <20240105074412.14096-1-chenglulu@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Cxyt1Xs5dlkhIDAA--.7970S3 X-CM-SenderInfo: xfkh0wpoxo3qxorr0wxvrqhubq/ X-Coremail-Antispam: 1Uk129KBj93XoWxtFWrJF1xJw43JF4kZFy8tFc_yoW3KrW8pr W7uw1UKF4rJrn7K3s7Ja47XrsrJrsFgF429asxtrWIkF47WryxXFy8K3yaqa45Wa1Yqryf Z3WS93WUWa15G3gCm3ZEXasCq-sJn29KB7ZKAUJUUUU5529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUk2b4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r106r15M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Gr0_Xr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVCY1x0267AK xVW8Jr0_Cr1UM2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12xvs2x26I8E6xACxx 1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r126r1DMcIj6I8E87Iv 67AKxVW8JVWxJwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2 Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s02 6x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0x vE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r1j6r4UMIIF0xvE 42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8JVWxJwCI42IY6I8E87Iv6x kF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjxUcsjjDUUUU X-Spam-Status: No, score=-11.7 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: 1787235652277670802 X-GMAIL-MSGID: 1787235652277670802 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..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"