[PATCH] [mips] [IAS] Fix expansion of LASym with negative offset.
Daniel Sanders
daniel.sanders at imgtec.com
Mon Jun 1 05:49:59 PDT 2015
================
Comment at: lib/Target/Mips/AsmParser/MipsAsmParser.cpp:2573-2584
@@ -2572,3 +2572,14 @@
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);
----------------
At first glance, this doesn't seem like the right thing to do. Could you explain why we can't support 'Sym - Constant'?
I suspect you may be trying to work around problems caused by the broken code on lines 2530-2555. If that's the case then we should fix the root cause instead.
================
Comment at: test/MC/Mips/mips-expansions.s:44-59
@@ -43,2 +43,18 @@
# 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
----------------
The expression should be the same for both %hi and %lo. What happens when a carry bit crosses between bit 16 and bit 15?
http://reviews.llvm.org/D9346
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
More information about the llvm-commits
mailing list