[lld] r222470 - [Mips] Simplify the code calculates HI16/LO16 relocations

Simon Atanasyan simon at atanasyan.com
Thu Nov 20 14:29:55 PST 2014


Author: atanasyan
Date: Thu Nov 20 16:29:55 2014
New Revision: 222470

URL: http://llvm.org/viewvc/llvm-project?rev=222470&view=rev
Log:
[Mips] Simplify the code calculates HI16/LO16 relocations

No functional changes.

Modified:
    lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp

Modified: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp?rev=222470&r1=222469&r2=222470&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp Thu Nov 20 16:29:55 2014
@@ -59,14 +59,8 @@ static void reloc26ext(uint32_t &ins, ui
 /// _gp_disp      : hi16 (AHL + GP - P) - (short)(AHL + GP - P) (verify)
 static void relocHi16(uint32_t &ins, uint64_t P, uint64_t S, int64_t AHL,
                       bool isGPDisp) {
-  int32_t result = 0;
-
-  if (isGPDisp)
-    result = (AHL + S - P) - (int16_t)(AHL + S - P);
-  else
-    result = (AHL + S) - (int16_t)(AHL + S);
-
-  applyReloc(ins, result >> 16, 0xffff);
+  int32_t result = isGPDisp ? AHL + S - P : AHL + S;
+  applyReloc(ins, (result + 0x8000) >> 16, 0xffff);
 }
 
 /// \brief R_MIPS_LO16, R_MIPS_TLS_DTPREL_LO16, R_MIPS_TLS_TPREL_LO16,
@@ -75,13 +69,7 @@ static void relocHi16(uint32_t &ins, uin
 /// _gp_disp      : lo16 AHL + GP - P + 4 (verify)
 static void relocLo16(uint32_t &ins, uint64_t P, uint64_t S, int64_t AHL,
                       bool isGPDisp) {
-  int32_t result = 0;
-
-  if (isGPDisp)
-    result = AHL + S - P + 4;
-  else
-    result = AHL + S;
-
+  int32_t result = isGPDisp ? AHL + S - P + 4 : AHL + S;
   applyReloc(ins, result, 0xffff);
 }
 





More information about the llvm-commits mailing list