From: Lulu Cheng <chenglulu@loongson.cn>
To: gcc-patches@gcc.gnu.org
Cc: xry111@xry111.site, i@xen0n.name, xuchenghua@loongson.cn,
chenglulu@loongson.cn
Subject: [PATCH 1/2] LoongArch: Add the macro implementation of mcmodel=extreme.
Date: Wed, 27 Dec 2023 16:46:53 +0800 [thread overview]
Message-ID: <20231227084654.20614-2-chenglulu@loongson.cn> (raw)
In-Reply-To: <20231227084654.20614-1-chenglulu@loongson.cn>
gcc/ChangeLog:
* config/loongarch/loongarch.cc (loongarch_symbolic_constant_p):
Remove the sym+addend form from the SYMBOL_PCREL64 type symbol.
(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 | 14 +-----
gcc/config/loongarch/loongarch.md | 47 ++++++++++++++++++-
gcc/config/loongarch/predicates.md | 14 ++++++
.../loongarch/func-call-extreme-5.c | 7 +++
.../loongarch/func-call-extreme-6.c | 7 +++
5 files changed, 75 insertions(+), 14 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 578b9bc3f09..e33b9db5981 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;
@@ -7526,10 +7526,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)
@@ -7894,14 +7890,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 2b0609f2f31..72abf180b1b 100644
--- a/gcc/config/loongarch/loongarch.md
+++ b/gcc/config/loongarch/loongarch.md
@@ -84,6 +84,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" [
@@ -123,6 +126,7 @@ (define_constants
(TP_REGNUM 2)
(T0_REGNUM 12)
(T1_REGNUM 13)
+ (T3_REGNUM 15)
(S0_REGNUM 23)
;; Return path styles
@@ -2056,8 +2060,22 @@ (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)
+ {
+ emit_insn (gen_movdi_pcrel64 (operands[0], operands[1]));
+ DONE;
+ }
+ else if (TARGET_CMODEL_EXTREME && symbol_type == SYMBOL_GOT_DISP)
+ {
+ emit_insn (gen_movdi_got_disp (operands[0], operands[1]));
+ DONE;
+ }
+ }
+})
(define_insn_and_split "*movdi_32bit"
[(set (match_operand:DI 0 "nonimmediate_operand" "=r,r,r,w,*f,*f,*r,*m")
(match_operand:DI 1 "move_operand" "r,i,w,r,*J*r,*m,*f,*f"))]
@@ -2096,6 +2114,33 @@ (define_insn_and_split "*movdi_64bit"
[(set_attr "move_type" "move,const,load,store,mgtf,fpload,mftg,fpstore")
(set_attr "mode" "DI")])
+;; $t0 and $t1 are used in loongarch_output_mi_thunk. If $t0 or $t1 is used
+;; here, then when cmodel is extreme, C++ THUNK will error. So $t3 is selected
+;; here.
+(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)
+ (use (reg:DI T3_REGNUM))
+ (clobber (reg:DI T3_REGNUM))]
+ "TARGET_64BIT"
+ "la.local %0,$r15,%1"
+ [(set_attr "mode" "DI")
+ (set_attr "length" "5")])
+
+(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)
+ (use (reg:DI T3_REGNUM))
+ (clobber (reg:DI T3_REGNUM))]
+ "TARGET_64BIT && TARGET_CMODEL_EXTREME"
+ "la.global %0,$r15,%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 83fea08315c..409a6e754a7 100644
--- a/gcc/config/loongarch/predicates.md
+++ b/gcc/config/loongarch/predicates.md
@@ -579,6 +579,20 @@ (define_predicate "symbolic_pcrel_operand"
return loongarch_symbolic_constant_p (op, &type) && type == SYMBOL_PCREL;
})
+(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"
--
2.39.3
next prev parent reply other threads:[~2023-12-27 8:47 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-27 8:46 [PATCH 0/2] When cmodel=extreme, add macro support and only Lulu Cheng
2023-12-27 8:46 ` Lulu Cheng [this message]
2024-01-04 3:51 ` [PATCH 1/2] LoongArch: Add the macro implementation of mcmodel=extreme Xi Ruoyao
2024-01-04 3:58 ` chenglulu
2024-01-04 4:05 ` Xi Ruoyao
2024-01-04 9:05 ` chenglulu
2024-01-04 9:33 ` chenglulu
2023-12-27 8:46 ` [PATCH 2/2] LoongArch: When the code model is extreme, the symbol address is obtained through macro instructions regardless of the value of -mexplicit-relocs Lulu Cheng
2023-12-27 9:18 ` [PATCH 0/2] When cmodel=extreme, add macro support and only chenglulu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231227084654.20614-2-chenglulu@loongson.cn \
--to=chenglulu@loongson.cn \
--cc=gcc-patches@gcc.gnu.org \
--cc=i@xen0n.name \
--cc=xry111@xry111.site \
--cc=xuchenghua@loongson.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).