]> git.ipfire.org Git - thirdparty/gcc.git/commit
LoongArch: Use explicit relocs for addresses only used for one load or store with...
authorXi Ruoyao <xry111@xry111.site>
Sun, 1 Oct 2023 03:14:29 +0000 (11:14 +0800)
committerXi Ruoyao <xry111@xry111.site>
Mon, 23 Oct 2023 07:30:19 +0000 (15:30 +0800)
commit83e24e8c1e5eb3366e35d5b8494a4cd9a2395b59
tree6b73e1ce098ba5ca2d38656d00dfa9c1e89c2cbb
parent95db62f4ad4cfce30b7683a7e3e9f06330e84878
LoongArch: Use explicit relocs for addresses only used for one load or store with -mexplicit-relocs=auto and -mcmodel={normal,medium}

In these cases, if we use explicit relocs, we end up with 2
instructions:

    pcalau12i    t0, %pc_hi20(x)
    ld.d         t0, t0, %pc_lo12(x)

If we use la.local pseudo-op, in the best scenario (x is in +/- 2MiB
range) we still have 2 instructions:

    pcaddi       t0, %pcrel_20(x)
    ld.d         t0, t0, 0

If x is out of the range we'll have 3 instructions.  So for these cases
just emit machine instructions with explicit relocs.

gcc/ChangeLog:

* config/loongarch/predicates.md (symbolic_pcrel_operand): New
predicate.
* config/loongarch/loongarch.md (define_peephole2): Optimize
la.local + ld/st to pcalau12i + ld/st if the address is only used
once if -mexplicit-relocs=auto and -mcmodel=normal or medium.

gcc/testsuite/ChangeLog:

* gcc.target/loongarch/explicit-relocs-auto-single-load-store.c:
New test.
* gcc.target/loongarch/explicit-relocs-auto-single-load-store-no-anchor.c:
New test.
gcc/config/loongarch/loongarch.md
gcc/config/loongarch/predicates.md
gcc/testsuite/gcc.target/loongarch/explicit-relocs-auto-single-load-store-no-anchor.c [new file with mode: 0644]
gcc/testsuite/gcc.target/loongarch/explicit-relocs-auto-single-load-store.c [new file with mode: 0644]