This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Patch] MIPS: Optimize virtual thunks for LOADGP_ABSOLUTE case.


In my hacking around I noticed that the mips port is emitting useless code in virtual thunks when the -mno-shared option is specified (the default for non -fPIC code in the o32 ABI).

Before the patch a typical thunk is:
       lui     $28,%hi(__gnu_local_gp)
       addiu   $28,$28,%lo(__gnu_local_gp)
       addiu   $4,$4,-4
       lui     $25,%hi($LTHUNK0)
       addiu   $25,$25,%lo($LTHUNK0)
       j       $25

Note that $28 (the gp register) is initialized but never used.

After the patch we have:
       addiu   $4,$4,-4
       lui     $25,%hi($LTHUNK0)
       addiu   $25,$25,%lo($LTHUNK0)
       j       $25

A savings of 2 instructions.

Tested with a mipsel-linux cross compiler with no regressions with --enable-languages=c,c++

OK to commit?

2007-05-31 David Daney <ddaney@avtrex.com>

   * config/mips/mips.c (mips_output_mi_thunk): Only load gp if not
   LOADGP_ABSOLUTE.


Index: config/mips/mips.c
===================================================================
--- config/mips/mips.c	(revision 125214)
+++ config/mips/mips.c	(working copy)
@@ -7335,8 +7335,11 @@ mips_output_mi_thunk (FILE *file, tree t
       = REGNO (pic_offset_table_rtx)
       = TARGET_CALL_SAVED_GP ? 15 : GLOBAL_POINTER_REGNUM;
 
-  /* Set up the global pointer for n32 or n64 abicalls.  */
-  mips_emit_loadgp ();
+  /* Set up the global pointer for n32 or n64 abicalls.  If
+     LOADGP_ABSOLUTE then the thunk does not use the gp and there is
+     no need to load it.*/
+  if (mips_current_loadgp_style () != LOADGP_ABSOLUTE)
+    mips_emit_loadgp ();
 
   /* We need two temporary registers in some cases.  */
   temp1 = gen_rtx_REG (Pmode, 2);

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]