Skip to content

Commit fa12285

Browse files
committed
[X86] Move ABS8 special case to fixupNeedsRelaxationAdvanced
And add a test that X86MCCodeEmitter doesn't utilize a 1-byte immediate for `cmp (3+$foo)@abs8, %edi`
1 parent 35cd6a4 commit fa12285

File tree

3 files changed

+29
-10
lines changed

3 files changed

+29
-10
lines changed

llvm/lib/MC/MCAssembler.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,10 +1050,6 @@ bool MCAssembler::fixupNeedsRelaxation(const MCFixup &Fixup,
10501050
bool WasForced;
10511051
bool Resolved = evaluateFixup(Fixup, DF, Target, DF->getSubtargetInfo(),
10521052
Value, WasForced);
1053-
if (Target.getSymA() &&
1054-
Target.getSymA()->getKind() == MCSymbolRefExpr::VK_X86_ABS8 &&
1055-
Fixup.getKind() == FK_Data_1)
1056-
return false;
10571053
return getBackend().fixupNeedsRelaxationAdvanced(*this, Fixup, Resolved,
10581054
Value, DF, WasForced);
10591055
}

llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,11 @@ class X86AsmBackend : public MCAsmBackend {
176176
bool mayNeedRelaxation(const MCInst &Inst,
177177
const MCSubtargetInfo &STI) const override;
178178

179-
bool fixupNeedsRelaxation(const MCFixup &Fixup,
180-
uint64_t Value) const override;
179+
bool fixupNeedsRelaxationAdvanced(const MCAssembler &Asm,
180+
const MCFixup &Fixup, bool Resolved,
181+
uint64_t Value,
182+
const MCRelaxableFragment *DF,
183+
const bool WasForced) const override;
181184

182185
void relaxInstruction(MCInst &Inst,
183186
const MCSubtargetInfo &STI) const override;
@@ -729,10 +732,24 @@ bool X86AsmBackend::mayNeedRelaxation(const MCInst &MI,
729732
MI.getOperand(MI.getNumOperands() - 1 - SkipOperands).isExpr());
730733
}
731734

732-
bool X86AsmBackend::fixupNeedsRelaxation(const MCFixup &Fixup,
733-
uint64_t Value) const {
734-
// Relax if the value is too big for a (signed) i8.
735-
return !isInt<8>(Value);
735+
bool X86AsmBackend::fixupNeedsRelaxationAdvanced(const MCAssembler &Asm,
736+
const MCFixup &Fixup,
737+
bool Resolved, uint64_t Value,
738+
const MCRelaxableFragment *DF,
739+
const bool WasForced) const {
740+
// If resolved, relax if the value is too big for a (signed) i8.
741+
if (Resolved)
742+
return !isInt<8>(Value);
743+
744+
// Otherwise, relax unless there is a @ABS8 specifier.
745+
if (Fixup.getKind() == FK_Data_1) {
746+
MCValue Target;
747+
if (Fixup.getValue()->evaluateAsRelocatable(Target, &Asm) &&
748+
Target.getSymA() &&
749+
Target.getSymA()->getKind() == MCSymbolRefExpr::VK_X86_ABS8)
750+
return false;
751+
}
752+
return true;
736753
}
737754

738755
// FIXME: Can tblgen help at all here to verify there aren't other instructions

llvm/test/MC/X86/abs8.s

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,10 @@
55
// X86: 00000002: R_386_8 foo
66
// X64: 0: 83 ff 00 cmpl $0, %edi
77
// X64: 0000000000000002: R_X86_64_8 foo
8+
// X64-NEXT: 3: 3b 3c 25 00 00 00 00 cmpl 0, %edi
9+
// X64-NEXT: 0000000000000006: R_X86_64_32 $foo+0x3
10+
// X64-NEXT: a: 3b 04 25 00 00 00 00 cmpl 0, %eax
11+
// X64-NEXT: 000000000000000d: R_X86_64_32 $foo-0x4
812
cmp $foo@ABS8, %edi
13+
cmp (3+$foo)@ABS8, %edi
14+
cmp ($foo-4)@ABS8, %eax

0 commit comments

Comments
 (0)