Skip to content

Commit

Permalink
[X86] Merge X86MCInstLowering's maxLongNopLength into emitNop and rem…
Browse files Browse the repository at this point in the history
…ove check for FeatureNOPL.

The switch in emitNop uses 64-bit registers for nops exceeding
2 bytes. This isn't valid outside 64-bit mode. We could fix this
easily enough, but there are no users that ask for more than 2
bytes outside 64-bit mode.

Inlining the method to make the coupling between the two methods
more explicit.
  • Loading branch information
topperc committed Jul 26, 2020
1 parent 14c59b4 commit 1a1448e
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions llvm/lib/Target/X86/X86MCInstLower.cpp
Expand Up @@ -1079,29 +1079,27 @@ void X86AsmPrinter::LowerTlsAddr(X86MCInstLower &MCInstLowering,
}
}

/// Return the longest nop which can be efficiently decoded for the given
/// target cpu. 15-bytes is the longest single NOP instruction, but some
/// platforms can't decode the longest forms efficiently.
static unsigned maxLongNopLength(const X86Subtarget *Subtarget) {
if (Subtarget->getFeatureBits()[X86::FeatureFast7ByteNOP])
return 7;
if (Subtarget->getFeatureBits()[X86::FeatureFast15ByteNOP])
return 15;
if (Subtarget->getFeatureBits()[X86::FeatureFast11ByteNOP])
return 11;
if (Subtarget->getFeatureBits()[X86::FeatureNOPL] || Subtarget->is64Bit())
return 10;
if (Subtarget->is32Bit())
return 2;
return 1;
}

/// Emit the largest nop instruction smaller than or equal to \p NumBytes
/// bytes. Return the size of nop emitted.
static unsigned emitNop(MCStreamer &OS, unsigned NumBytes,
const X86Subtarget *Subtarget) {
unsigned MaxNopLength = 1;
if (Subtarget->is64Bit()) {
// FIXME: We can use NOOPL on 32-bit targets with FeatureNOPL, but the
// IndexReg/BaseReg below need to be updated.
if (Subtarget->hasFeature(X86::FeatureFast7ByteNOP))
MaxNopLength = 7;
else if (Subtarget->hasFeature(X86::FeatureFast15ByteNOP))
MaxNopLength = 15;
else if (Subtarget->hasFeature(X86::FeatureFast11ByteNOP))
MaxNopLength = 11;
else
MaxNopLength = 10;
} if (Subtarget->is32Bit())
MaxNopLength = 2;

// Cap a single nop emission at the profitable value for the target
NumBytes = std::min(NumBytes, maxLongNopLength(Subtarget));
NumBytes = std::min(NumBytes, MaxNopLength);

unsigned NopSize;
unsigned Opc, BaseReg, ScaleVal, IndexReg, Displacement, SegmentReg;
Expand Down

0 comments on commit 1a1448e

Please sign in to comment.