]> git.ipfire.org Git - thirdparty/gcc.git/commit
LoongArch: Don't split the instructions containing relocs for extreme code model.
authorXi Ruoyao <xry111@xry111.site>
Mon, 29 Jan 2024 07:20:07 +0000 (15:20 +0800)
committerLulu Cheng <chenglulu@loongson.cn>
Fri, 2 Feb 2024 01:16:24 +0000 (09:16 +0800)
commitf72586e5b9cbb91a099cb6970480eedcbce9f0c7
tree5c1dc7430380a3eeaf9164627a34d8cc41f6b9c5
parent3932899a833f82537f96826daa5af8568b66adfc
LoongArch: Don't split the instructions containing relocs for extreme code model.

The ABI mandates the pcalau12i/addi.d/lu32i.d/lu52i.d instructions for
addressing a symbol to be adjacent.  So model them as "one large
instruction", i.e. define_insn, with two output registers.  The real
address is the sum of these two registers.

The advantage of this approach is the RTL passes can still use ldx/stx
instructions to skip an addi.d instruction.

gcc/ChangeLog:

* config/loongarch/loongarch.md (unspec): Add
UNSPEC_LA_PCREL_64_PART1 and UNSPEC_LA_PCREL_64_PART2.
(la_pcrel64_two_parts): New define_insn.
* config/loongarch/loongarch.cc (loongarch_tls_symbol): Fix a
typo in the comment.
(loongarch_call_tls_get_addr): If -mcmodel=extreme
-mexplicit-relocs={always,auto}, use la_pcrel64_two_parts for
addressing the TLS symbol and __tls_get_addr.  Emit an REG_EQUAL
note to allow CSE addressing __tls_get_addr.
(loongarch_legitimize_tls_address): If -mcmodel=extreme
-mexplicit-relocs={always,auto}, address TLS IE symbols with
la_pcrel64_two_parts.
(loongarch_split_symbol): If -mcmodel=extreme
-mexplicit-relocs={always,auto}, address symbols with
la_pcrel64_two_parts.
(loongarch_output_mi_thunk): Clean up unreachable code.  If
-mcmodel=extreme -mexplicit-relocs={always,auto}, address the MI
thunks with la_pcrel64_two_parts.

gcc/testsuite/ChangeLog:

* gcc.target/loongarch/func-call-extreme-1.c (dg-options):
Use -O2 instead of -O0 to ensure the pcalau12i/addi/lu32i/lu52i
instruction sequences are not reordered by the compiler.
(NOIPA): Disallow interprocedural optimizations.
* gcc.target/loongarch/func-call-extreme-2.c: Remove the content
duplicated from func-call-extreme-1.c, include it instead.
(dg-options): Likewise.
* gcc.target/loongarch/func-call-extreme-3.c (dg-options):
Likewise.
* gcc.target/loongarch/func-call-extreme-4.c (dg-options):
Likewise.
* gcc.target/loongarch/cmodel-extreme-1.c: New test.
* gcc.target/loongarch/cmodel-extreme-2.c: New test.
* g++.target/loongarch/cmodel-extreme-mi-thunk-1.C: New test.
* g++.target/loongarch/cmodel-extreme-mi-thunk-2.C: New test.
* g++.target/loongarch/cmodel-extreme-mi-thunk-3.C: New test.
gcc/config/loongarch/loongarch.cc
gcc/config/loongarch/loongarch.md
gcc/testsuite/g++.target/loongarch/cmodel-extreme-mi-thunk-1.C [new file with mode: 0644]
gcc/testsuite/g++.target/loongarch/cmodel-extreme-mi-thunk-2.C [new file with mode: 0644]
gcc/testsuite/g++.target/loongarch/cmodel-extreme-mi-thunk-3.C [new file with mode: 0644]
gcc/testsuite/gcc.target/loongarch/cmodel-extreme-1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/loongarch/cmodel-extreme-2.c [new file with mode: 0644]
gcc/testsuite/gcc.target/loongarch/func-call-extreme-1.c
gcc/testsuite/gcc.target/loongarch/func-call-extreme-2.c
gcc/testsuite/gcc.target/loongarch/func-call-extreme-3.c
gcc/testsuite/gcc.target/loongarch/func-call-extreme-4.c