[PATCH] [mips] [IAS] Fix expansion of LASym with negative offset.

Toma Tabacu toma.tabacu at imgtec.com
Mon May 18 05:46:03 PDT 2015


Rebased.


http://reviews.llvm.org/D9346

Files:
  lib/Target/Mips/AsmParser/MipsAsmParser.cpp
  test/MC/Mips/mips-expansions.s

Index: lib/Target/Mips/AsmParser/MipsAsmParser.cpp
===================================================================
--- lib/Target/Mips/AsmParser/MipsAsmParser.cpp
+++ lib/Target/Mips/AsmParser/MipsAsmParser.cpp
@@ -2570,8 +2570,21 @@
       return MipsMCExpr::Create(VK, Expr, getContext());
 
     const MCExpr *LExp = evaluateRelocExpr(BE->getLHS(), RelocStr);
-    const MCExpr *RExp = evaluateRelocExpr(BE->getRHS(), RelocStr);
-    Res = MCBinaryExpr::Create(BE->getOpcode(), LExp, RExp, getContext());
+    // If the RHS is a constant and we are subtracting it, switch the
+    // MCBinaryExpr to be the addition of the negated RHS constant with the
+    // unchanged LHS.
+    if (BE->getOpcode() == MCBinaryExpr::Sub &&
+        isa<MCConstantExpr>(BE->getRHS())) {
+      const MCConstantExpr *OldRExp = cast<MCConstantExpr>(BE->getRHS());
+      const MCExpr *NewRExp =
+          MCConstantExpr::Create(-OldRExp->getValue(), getContext());
+
+      const MCExpr *RExp = evaluateRelocExpr(NewRExp, RelocStr);
+      Res = MCBinaryExpr::Create(MCBinaryExpr::Add, LExp, RExp, getContext());
+    } else {
+      const MCExpr *RExp = evaluateRelocExpr(BE->getRHS(), RelocStr);
+      Res = MCBinaryExpr::Create(BE->getOpcode(), LExp, RExp, getContext());
+    }
     return Res;
   }
 
Index: test/MC/Mips/mips-expansions.s
===================================================================
--- test/MC/Mips/mips-expansions.s
+++ test/MC/Mips/mips-expansions.s
@@ -41,6 +41,22 @@
 # CHECK:                               #   fixup A - offset: 0, value: symbol at ABS_HI, kind: fixup_Mips_HI16
 # CHECK: ori $8, $8, %lo(symbol+4369)  # encoding: [0x11'A',0x11'A',0x08,0x35]
 # CHECK:                               #   fixup A - offset: 0, value: symbol at ABS_LO, kind: fixup_Mips_LO16
+# CHECK: lui $8, %hi(symbol)           # encoding: [A,A,0x08,0x3c]
+# CHECK:                               #   fixup A - offset: 0, value: symbol at ABS_HI, kind: fixup_Mips_HI16
+# CHECK: ori $8, $8, %lo(symbol-1)     # encoding: [0xff'A',0xff'A',0x08,0x35]
+# CHECK:                               #   fixup A - offset: 0, value: symbol at ABS_LO, kind: fixup_Mips_LO16
+# CHECK: lui $8, %hi(symbol-1)         # encoding: [0xff'A',0xff'A',0x08,0x3c]
+# CHECK:                               #   fixup A - offset: 0, value: symbol at ABS_HI, kind: fixup_Mips_HI16
+# CHECK: ori $8, $8, %lo(symbol+32766) # encoding: [0xfe'A',0x7f'A',0x08,0x35]
+# CHECK:                               #   fixup A - offset: 0, value: symbol at ABS_LO, kind: fixup_Mips_LO16
+# CHECK: lui $8, %hi(symbol-1)         # encoding: [0xff'A',0xff'A',0x08,0x3c]
+# CHECK:                               #   fixup A - offset: 0, value: symbol at ABS_HI, kind: fixup_Mips_HI16
+# CHECK: ori $8, $8, %lo(symbol-2)     # encoding: [0xfe'A',0xff'A',0x08,0x35]
+# CHECK:                               #   fixup A - offset: 0, value: symbol at ABS_LO, kind: fixup_Mips_LO16
+# CHECK: lui $8, %hi(symbol-1)         # encoding: [0xff'A',0xff'A',0x08,0x3c]
+# CHECK:                               #   fixup A - offset: 0, value: symbol at ABS_HI, kind: fixup_Mips_HI16
+# CHECK: ori $8, $8, %lo(symbol-4369)  # encoding: [0xef'A',0xee'A',0x08,0x35]
+# CHECK:                               #   fixup A - offset: 0, value: symbol at ABS_LO, kind: fixup_Mips_LO16
 
 # CHECK: lui     $10, %hi(symbol)        # encoding: [A,A,0x0a,0x3c]
 # CHECK:                                 #   fixup A - offset: 0, value: symbol at ABS_HI, kind: fixup_Mips_HI16
@@ -91,6 +107,10 @@
     la $8, symbol+32770
     la $8, symbol+65538
     la $8, symbol+0x11111
+    la $8, symbol-1
+    la $8, symbol-32770
+    la $8, symbol-65538
+    la $8, symbol-0x11111
 
     .set noat
     lw  $t2, symbol($a0)

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D9346.25958.patch
Type: text/x-patch
Size: 3711 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150518/852e7955/attachment.bin>


More information about the llvm-commits mailing list