Re: [pushed][PATCH v2] LoongArch: Add code generation support for call36 function calls.

2023-11-18 Thread chenglulu

Pushed to r14-5567.

在 2023/11/16 下午3:27, Lulu Cheng 写道:

When compiling with '-mcmodel=medium', the function call is made through
'pcaddu18i+jirl' if binutils supports call36, otherwise the
native implementation 'pcalau12i+jirl' is used.

gcc/ChangeLog:

* config.in: Regenerate.
* config/loongarch/loongarch-opts.h (HAVE_AS_SUPPORT_CALL36): Define 
macro.
* config/loongarch/loongarch.cc (loongarch_legitimize_call_address):
If binutils supports call36, the function call is not split over expand.
* config/loongarch/loongarch.md: Add call36 generation code.
* config/loongarch/predicates.md: Likewise.
* configure: Regenerate.
* configure.ac: Check whether binutils supports call36.

gcc/testsuite/ChangeLog:

* gcc.target/loongarch/func-call-medium-5.c: If the assembler supports 
call36,
the test is abandoned.
* gcc.target/loongarch/func-call-medium-6.c: Likewise.
* gcc.target/loongarch/func-call-medium-7.c: Likewise.
* gcc.target/loongarch/func-call-medium-8.c: Likewise.
* lib/target-supports.exp: Added a function to see if the assembler 
supports
the call36 relocation.
* gcc.target/loongarch/func-call-medium-call36-1.c: New test.
* gcc.target/loongarch/func-call-medium-call36.c: New test.

Co-authored-by: Xi Ruoyao 

---
v1 -> v2:
   1. Add '(clobber (reg:P 12))' instead of '-fno-ipa-ra' in sibcall 
implementation.
   2. Add test cases.

---
  gcc/config.in |   6 +
  gcc/config/loongarch/loongarch-opts.h |   4 +
  gcc/config/loongarch/loongarch.cc |  12 +-
  gcc/config/loongarch/loongarch.md | 171 +++---
  gcc/config/loongarch/predicates.md|   7 +-
  gcc/configure |  32 
  gcc/configure.ac  |   6 +
  .../gcc.target/loongarch/func-call-medium-5.c |   1 +
  .../gcc.target/loongarch/func-call-medium-6.c |   1 +
  .../gcc.target/loongarch/func-call-medium-7.c |   1 +
  .../gcc.target/loongarch/func-call-medium-8.c |   1 +
  .../loongarch/func-call-medium-call36-1.c |  21 +++
  .../loongarch/func-call-medium-call36.c   |  32 
  gcc/testsuite/lib/target-supports.exp |   9 +
  14 files changed, 268 insertions(+), 36 deletions(-)
  create mode 100644 
gcc/testsuite/gcc.target/loongarch/func-call-medium-call36-1.c
  create mode 100644 
gcc/testsuite/gcc.target/loongarch/func-call-medium-call36.c

diff --git a/gcc/config.in b/gcc/config.in
index 866f9fff101..e100c20dcd0 100644
--- a/gcc/config.in
+++ b/gcc/config.in
@@ -781,6 +781,12 @@
  #endif
  
  
+/* Define if your assembler supports call36 relocation. */

+#ifndef USED_FOR_TARGET
+#undef HAVE_AS_SUPPORT_CALL36
+#endif
+
+
  /* Define if your assembler and linker support thread-local storage. */
  #ifndef USED_FOR_TARGET
  #undef HAVE_AS_TLS
diff --git a/gcc/config/loongarch/loongarch-opts.h 
b/gcc/config/loongarch/loongarch-opts.h
index 8de41bbc4f7..6dd309aad96 100644
--- a/gcc/config/loongarch/loongarch-opts.h
+++ b/gcc/config/loongarch/loongarch-opts.h
@@ -97,6 +97,10 @@ loongarch_update_gcc_opt_status (struct loongarch_target 
*target,
  #define HAVE_AS_EXPLICIT_RELOCS 0
  #endif
  
+#ifndef HAVE_AS_SUPPORT_CALL36

+#define HAVE_AS_SUPPORT_CALL36 0
+#endif
+
  #ifndef HAVE_AS_MRELAX_OPTION
  #define HAVE_AS_MRELAX_OPTION 0
  #endif
diff --git a/gcc/config/loongarch/loongarch.cc 
b/gcc/config/loongarch/loongarch.cc
index 738911661d7..0bd416255be 100644
--- a/gcc/config/loongarch/loongarch.cc
+++ b/gcc/config/loongarch/loongarch.cc
@@ -3006,12 +3006,16 @@ loongarch_legitimize_call_address (rtx addr)
  
enum loongarch_symbol_type symbol_type = loongarch_classify_symbol (addr);
  
-  /* Split function call insn 'bl sym' or 'bl %plt(sym)' to :

- pcalau12i $rd, %pc_hi20(sym)
- jr $rd, %pc_lo12(sym).  */
+  /* If add the compilation option '-cmodel=medium', and the assembler does
+ not support call36.  The following sequence of instructions will be
+ used for the function call:
+   pcalau12i $rd, %pc_hi20(sym)
+   jr $rd, %pc_lo12(sym)
+  */
  
if (TARGET_CMODEL_MEDIUM

-  && TARGET_EXPLICIT_RELOCS
+  && !HAVE_AS_SUPPORT_CALL36
+  && (la_opt_explicit_relocs != EXPLICIT_RELOCS_NONE)
&& (SYMBOL_REF_P (addr) || LABEL_REF_P (addr))
&& (symbol_type == SYMBOL_PCREL
  || (symbol_type == SYMBOL_GOT_DISP && flag_plt)))
diff --git a/gcc/config/loongarch/loongarch.md 
b/gcc/config/loongarch/loongarch.md
index 22814a3679c..f0b6ae3e2a2 100644
--- a/gcc/config/loongarch/loongarch.md
+++ b/gcc/config/loongarch/loongarch.md
@@ -3274,7 +3274,13 @@ (define_expand "sibcall"
XEXP (target, 1),
operands[1]));
else
-emit_call_insn (gen_sibcall_internal (target, operands[1]));
+{
+  rtx call = emit_call_insn (gen_sibca

Re: [pushed][PATCH v2] LoongArch: Add code generation support for call36 function calls.

2023-11-18 Thread Xi Ruoyao
On Sat, 2023-11-18 at 16:16 +0800, chenglulu wrote:
> Pushed to r14-5567.
> 
> 在 2023/11/16 下午3:27, Lulu Cheng 写道:
> > When compiling with '-mcmodel=medium', the function call is made through
> > 'pcaddu18i+jirl' if binutils supports call36, otherwise the
> > native implementation 'pcalau12i+jirl' is used.
> > 
> > gcc/ChangeLog:
> > 
> > * config.in: Regenerate.
> > * config/loongarch/loongarch-opts.h (HAVE_AS_SUPPORT_CALL36): Define 
> > macro.
> > * config/loongarch/loongarch.cc (loongarch_legitimize_call_address):
> > If binutils supports call36, the function call is not split over expand.
> > * config/loongarch/loongarch.md: Add call36 generation code.
> > * config/loongarch/predicates.md: Likewise.
> > * configure: Regenerate.
> > * configure.ac: Check whether binutils supports call36.

With this change I get some test failures with "old" Binutils 2.41:

FAIL: gcc.target/loongarch/func-call-medium-1.c scan-assembler 
test:.*la.global\\t.*g\\n\\tjirl
FAIL: gcc.target/loongarch/func-call-medium-1.c scan-assembler 
test1:.*la.global\\t.*f\\n\\tjirl
FAIL: gcc.target/loongarch/func-call-medium-1.c scan-assembler 
test2:.*la.local\\t.*l\\n\\tjirl
FAIL: gcc.target/loongarch/func-call-medium-2.c scan-assembler 
test:.*la.global\\t.*g\\n\\tjirl
FAIL: gcc.target/loongarch/func-call-medium-2.c scan-assembler 
test1:.*la.local\\t.*f\\n\\tjirl
FAIL: gcc.target/loongarch/func-call-medium-2.c scan-assembler 
test2:.*la.local\\t.*l\\n\\tjirl
FAIL: gcc.target/loongarch/func-call-medium-3.c scan-assembler 
test2:.*la.local\\t.*l\\n\\tjirl
FAIL: gcc.target/loongarch/func-call-medium-4.c scan-assembler 
test1:.*la.local\\t.*f\\n\\tjirl
FAIL: gcc.target/loongarch/func-call-medium-4.c scan-assembler 
test2:.*la.local\\t.*l\\n\\tjirl

Some strange thing is happening: with -mexplicit-relocs=auto or always I
get pcalau12i + jirl as expected, but with -mexplicit-relocs=none I get
"pcaddu18i $r1,%call36(g)" and jirl.  This seems irony (!).

-- 
Xi Ruoyao 
School of Aerospace Science and Technology, Xidian University


Re: [pushed][PATCH v2] LoongArch: Add code generation support for call36 function calls.

2023-11-19 Thread chenglulu



在 2023/11/19 上午1:24, Xi Ruoyao 写道:

On Sat, 2023-11-18 at 16:16 +0800, chenglulu wrote:

Pushed to r14-5567.

在 2023/11/16 下午3:27, Lulu Cheng 写道:

When compiling with '-mcmodel=medium', the function call is made through
'pcaddu18i+jirl' if binutils supports call36, otherwise the
native implementation 'pcalau12i+jirl' is used.

gcc/ChangeLog:

* config.in: Regenerate.
* config/loongarch/loongarch-opts.h (HAVE_AS_SUPPORT_CALL36): Define 
macro.
* config/loongarch/loongarch.cc (loongarch_legitimize_call_address):
If binutils supports call36, the function call is not split over expand.
* config/loongarch/loongarch.md: Add call36 generation code.
* config/loongarch/predicates.md: Likewise.
* configure: Regenerate.
* configure.ac: Check whether binutils supports call36.

With this change I get some test failures with "old" Binutils 2.41:

FAIL: gcc.target/loongarch/func-call-medium-1.c scan-assembler 
test:.*la.global\\t.*g\\n\\tjirl
FAIL: gcc.target/loongarch/func-call-medium-1.c scan-assembler 
test1:.*la.global\\t.*f\\n\\tjirl
FAIL: gcc.target/loongarch/func-call-medium-1.c scan-assembler 
test2:.*la.local\\t.*l\\n\\tjirl
FAIL: gcc.target/loongarch/func-call-medium-2.c scan-assembler 
test:.*la.global\\t.*g\\n\\tjirl
FAIL: gcc.target/loongarch/func-call-medium-2.c scan-assembler 
test1:.*la.local\\t.*f\\n\\tjirl
FAIL: gcc.target/loongarch/func-call-medium-2.c scan-assembler 
test2:.*la.local\\t.*l\\n\\tjirl
FAIL: gcc.target/loongarch/func-call-medium-3.c scan-assembler 
test2:.*la.local\\t.*l\\n\\tjirl
FAIL: gcc.target/loongarch/func-call-medium-4.c scan-assembler 
test1:.*la.local\\t.*f\\n\\tjirl
FAIL: gcc.target/loongarch/func-call-medium-4.c scan-assembler 
test2:.*la.local\\t.*l\\n\\tjirl

Some strange thing is happening: with -mexplicit-relocs=auto or always I
get pcalau12i + jirl as expected, but with -mexplicit-relocs=none I get
"pcaddu18i $r1,%call36(g)" and jirl.  This seems irony (!).


Thank you for the revision.



Re: [pushed][PATCH v2] LoongArch: Add code generation support for call36 function calls.

2023-11-19 Thread Xi Ruoyao
On Mon, 2023-11-20 at 09:09 +0800, chenglulu wrote:
> 
> 在 2023/11/19 上午1:24, Xi Ruoyao 写道:
> > On Sat, 2023-11-18 at 16:16 +0800, chenglulu wrote:
> > > Pushed to r14-5567.
> > > 
> > > 在 2023/11/16 下午3:27, Lulu Cheng 写道:
> > > > When compiling with '-mcmodel=medium', the function call is made through
> > > > 'pcaddu18i+jirl' if binutils supports call36, otherwise the
> > > > native implementation 'pcalau12i+jirl' is used.
> > > > 
> > > > gcc/ChangeLog:
> > > > 
> > > > * config.in: Regenerate.
> > > > * config/loongarch/loongarch-opts.h (HAVE_AS_SUPPORT_CALL36): 
> > > > Define macro.
> > > > * config/loongarch/loongarch.cc 
> > > > (loongarch_legitimize_call_address):
> > > > If binutils supports call36, the function call is not split 
> > > > over expand.
> > > > * config/loongarch/loongarch.md: Add call36 generation code.
> > > > * config/loongarch/predicates.md: Likewise.
> > > > * configure: Regenerate.
> > > > * configure.ac: Check whether binutils supports call36.
> > With this change I get some test failures with "old" Binutils 2.41:
> > 
> > FAIL: gcc.target/loongarch/func-call-medium-1.c scan-assembler 
> > test:.*la.global\\t.*g\\n\\tjirl
> > FAIL: gcc.target/loongarch/func-call-medium-1.c scan-assembler 
> > test1:.*la.global\\t.*f\\n\\tjirl
> > FAIL: gcc.target/loongarch/func-call-medium-1.c scan-assembler 
> > test2:.*la.local\\t.*l\\n\\tjirl
> > FAIL: gcc.target/loongarch/func-call-medium-2.c scan-assembler 
> > test:.*la.global\\t.*g\\n\\tjirl
> > FAIL: gcc.target/loongarch/func-call-medium-2.c scan-assembler 
> > test1:.*la.local\\t.*f\\n\\tjirl
> > FAIL: gcc.target/loongarch/func-call-medium-2.c scan-assembler 
> > test2:.*la.local\\t.*l\\n\\tjirl
> > FAIL: gcc.target/loongarch/func-call-medium-3.c scan-assembler 
> > test2:.*la.local\\t.*l\\n\\tjirl
> > FAIL: gcc.target/loongarch/func-call-medium-4.c scan-assembler 
> > test1:.*la.local\\t.*f\\n\\tjirl
> > FAIL: gcc.target/loongarch/func-call-medium-4.c scan-assembler 
> > test2:.*la.local\\t.*l\\n\\tjirl
> > 
> > Some strange thing is happening: with -mexplicit-relocs=auto or always I
> > get pcalau12i + jirl as expected, but with -mexplicit-relocs=none I get
> > "pcaddu18i $r1,%call36(g)" and jirl.  This seems irony (!).
> > 
> Thank you for the revision.

Then I'll push
https://gcc.gnu.org/pipermail/gcc-patches/2023-November/637153.html if
this is an approval?

-- 
Xi Ruoyao 
School of Aerospace Science and Technology, Xidian University


Re: [pushed][PATCH v2] LoongArch: Add code generation support for call36 function calls.

2023-11-19 Thread chenglulu



在 2023/11/20 上午9:51, Xi Ruoyao 写道:

On Mon, 2023-11-20 at 09:09 +0800, chenglulu wrote:

在 2023/11/19 上午1:24, Xi Ruoyao 写道:

On Sat, 2023-11-18 at 16:16 +0800, chenglulu wrote:

Pushed to r14-5567.

在 2023/11/16 下午3:27, Lulu Cheng 写道:

When compiling with '-mcmodel=medium', the function call is made through
'pcaddu18i+jirl' if binutils supports call36, otherwise the
native implementation 'pcalau12i+jirl' is used.

gcc/ChangeLog:

* config.in: Regenerate.
* config/loongarch/loongarch-opts.h (HAVE_AS_SUPPORT_CALL36): Define 
macro.
* config/loongarch/loongarch.cc (loongarch_legitimize_call_address):
If binutils supports call36, the function call is not split over expand.
* config/loongarch/loongarch.md: Add call36 generation code.
* config/loongarch/predicates.md: Likewise.
* configure: Regenerate.
* configure.ac: Check whether binutils supports call36.

With this change I get some test failures with "old" Binutils 2.41:

FAIL: gcc.target/loongarch/func-call-medium-1.c scan-assembler 
test:.*la.global\\t.*g\\n\\tjirl
FAIL: gcc.target/loongarch/func-call-medium-1.c scan-assembler 
test1:.*la.global\\t.*f\\n\\tjirl
FAIL: gcc.target/loongarch/func-call-medium-1.c scan-assembler 
test2:.*la.local\\t.*l\\n\\tjirl
FAIL: gcc.target/loongarch/func-call-medium-2.c scan-assembler 
test:.*la.global\\t.*g\\n\\tjirl
FAIL: gcc.target/loongarch/func-call-medium-2.c scan-assembler 
test1:.*la.local\\t.*f\\n\\tjirl
FAIL: gcc.target/loongarch/func-call-medium-2.c scan-assembler 
test2:.*la.local\\t.*l\\n\\tjirl
FAIL: gcc.target/loongarch/func-call-medium-3.c scan-assembler 
test2:.*la.local\\t.*l\\n\\tjirl
FAIL: gcc.target/loongarch/func-call-medium-4.c scan-assembler 
test1:.*la.local\\t.*f\\n\\tjirl
FAIL: gcc.target/loongarch/func-call-medium-4.c scan-assembler 
test2:.*la.local\\t.*l\\n\\tjirl

Some strange thing is happening: with -mexplicit-relocs=auto or always I
get pcalau12i + jirl as expected, but with -mexplicit-relocs=none I get
"pcaddu18i $r1,%call36(g)" and jirl.  This seems irony (!).


Thank you for the revision.

Then I'll push
https://gcc.gnu.org/pipermail/gcc-patches/2023-November/637153.html if
this is an approval?


OK. Thanks.