[PATCH] Optimize long branch for MIPS64 by removing calculation of %higher and %highest

Sasa Stankovic Sasa.Stankovic at imgtec.com
Thu May 15 09:42:12 PDT 2014


================
Comment at: lib/Target/Mips/MipsLongBranch.cpp:345
@@ +344,3 @@
+      //
+      //   lui $at, %highest($tgt - $baltgt)
+      //   daddiu $at, $at, %higher($tgt - $baltgt)
----------------
Mark Seaborn wrote:
> Including this snippet seems a bit too verbose to me.  You don't need to document what the code used to do -- we have version control for that. :-)
> 
> Just say you assume the jump is within-function, so the offset is within +/- 2GB.
Done

================
Comment at: lib/Target/Mips/MipsLongBranch.cpp:352
@@ +351,3 @@
+      // values only when the offset is greater than 4GB, which is highly
+      // unlikely, if not impossible when compiling a single function.
+      //
----------------
Mark Seaborn wrote:
> I don't think you answered dsanders' question about why it's valid to assume that the jump is within-function.
> 
> I was wondering whether tail calls to other functions would become jumps that would need handling via MipsLongBranch.  The answer seems to be that LLVM always compiles function calls to indirect jumps on MIPS.  (However, GCC does compile tail calls to direct jumps.)  That answer seems a bit crazy, so I'm not sure if it's right.  You should check.  Does the MIPS linker insert veneers to handle long direct jumps the same way ARM linkers do?
> I don't think you answered dsanders' question about why it's valid to assume that the
> jump is within-function.

I didn't answer because I wasn't aware of the cases where jumps are outside of a function. I just suggested that we can add assert that the branch target is within function.

> I was wondering whether tail calls to other functions would become jumps that would > need handling via MipsLongBranch. The answer seems to be that LLVM always 
> compiles function calls to indirect jumps on MIPS. (However, GCC does compile tail > calls to direct jumps.) That answer seems a bit crazy, so I'm not sure if it's right. You > should check. Does the MIPS linker insert veneers to handle long direct jumps the 
> same way ARM linkers do?

I checked tail calls on LLVM and GCC, and they generate similar code when given explicit relocation model on the command line. When relocation model is omitted the code differs because default for MIPS GCC is non-pic, and for MIPS LLVM is pic. For pic code (which this patch handles) tail calls are replaced by load from GOT and indirect jump:

lw      $t9, %call16(func)($gp)
jr      $t9

and this doesn't need long branch.

As for veneers, MIPS GNU ld linker doesn't insert them.

http://reviews.llvm.org/D3281






More information about the llvm-commits mailing list