LoongArch: Replace -mexplicit-relocs=auto simple-used address peephole2 with combine
The problem with peephole2 is it uses a naive sliding-window algorithm and misses many cases. For example: float a[10000]; float t() { return a[0] + a[8000]; } is compiled to: la.local $r13,a la.local $r12,a+32768 fld.s $f1,$r13,0 fld.s $f0,$r12,-768 fadd.s $f0,$f1,$f0 by trunk. But as we've explained in r14-4851, the following would be better with -mexplicit-relocs=auto: pcalau12i $r13,%pc_hi20(a) pcalau12i $r12,%pc_hi20(a+32000) fld.s $f1,$r13,%pc_lo12(a) fld.s $f0,$r12,%pc_lo12(a+32000) fadd.s $f0,$f1,$f0 However the sliding-window algorithm just won't detect the pcalau12i/fld pair to be optimized. Use a define_insn_and_rewrite in combine pass will work around the issue. gcc/ChangeLog: * config/loongarch/predicates.md (symbolic_pcrel_offset_operand): New define_predicate. (mem_simple_ldst_operand): Likewise. * config/loongarch/loongarch-protos.h (loongarch_rewrite_mem_for_simple_ldst): Declare. * config/loongarch/loongarch.cc (loongarch_rewrite_mem_for_simple_ldst): Implement. * config/loongarch/loongarch.md (simple_load<mode>): New define_insn_and_rewrite. (simple_load_<su>ext<SUBDI:mode><GPR:mode>): Likewise. (simple_store<mode>): Likewise. (define_peephole2): Remove la.local/[f]ld peepholes. gcc/testsuite/ChangeLog: * gcc.target/loongarch/explicit-relocs-auto-single-load-store-2.c: New test. * gcc.target/loongarch/explicit-relocs-auto-single-load-store-3.c: New test.
Showing
- gcc/config/loongarch/loongarch-protos.h 1 addition, 0 deletionsgcc/config/loongarch/loongarch-protos.h
- gcc/config/loongarch/loongarch.cc 16 additions, 0 deletionsgcc/config/loongarch/loongarch.cc
- gcc/config/loongarch/loongarch.md 27 additions, 87 deletionsgcc/config/loongarch/loongarch.md
- gcc/config/loongarch/predicates.md 13 additions, 0 deletionsgcc/config/loongarch/predicates.md
- gcc/testsuite/gcc.target/loongarch/explicit-relocs-auto-single-load-store-2.c 11 additions, 0 deletions...rget/loongarch/explicit-relocs-auto-single-load-store-2.c
- gcc/testsuite/gcc.target/loongarch/explicit-relocs-auto-single-load-store-3.c 18 additions, 0 deletions...rget/loongarch/explicit-relocs-auto-single-load-store-3.c
Loading
Please register or sign in to comment