Index: llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
--- llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp.orig
+++ llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
@@ -993,56 +993,22 @@ unsigned X86AsmBackend::getMaximumNopSize(const MCSubt
 /// \return - true on success, false on failure
 bool X86AsmBackend::writeNopData(raw_ostream &OS, uint64_t Count,
                                  const MCSubtargetInfo *STI) const {
-  static const char Nops32Bit[10][11] = {
-      // nop
-      "\x90",
-      // xchg %ax,%ax
-      "\x66\x90",
-      // nopl (%[re]ax)
-      "\x0f\x1f\x00",
-      // nopl 0(%[re]ax)
-      "\x0f\x1f\x40\x00",
-      // nopl 0(%[re]ax,%[re]ax,1)
-      "\x0f\x1f\x44\x00\x00",
-      // nopw 0(%[re]ax,%[re]ax,1)
-      "\x66\x0f\x1f\x44\x00\x00",
-      // nopl 0L(%[re]ax)
-      "\x0f\x1f\x80\x00\x00\x00\x00",
-      // nopl 0L(%[re]ax,%[re]ax,1)
-      "\x0f\x1f\x84\x00\x00\x00\x00\x00",
-      // nopw 0L(%[re]ax,%[re]ax,1)
-      "\x66\x0f\x1f\x84\x00\x00\x00\x00\x00",
-      // nopw %cs:0L(%[re]ax,%[re]ax,1)
-      "\x66\x2e\x0f\x1f\x84\x00\x00\x00\x00\x00",
-  };
-
-  // 16-bit mode uses different nop patterns than 32-bit.
-  static const char Nops16Bit[4][11] = {
-      // nop
-      "\x90",
-      // xchg %eax,%eax
-      "\x66\x90",
-      // lea 0(%si),%si
-      "\x8d\x74\x00",
-      // lea 0w(%si),%si
-      "\x8d\xb4\x00\x00",
-  };
-
-  const char(*Nops)[11] =
-      STI->hasFeature(X86::Is16Bit) ? Nops16Bit : Nops32Bit;
-
-  uint64_t MaxNopLength = (uint64_t)getMaximumNopSize(*STI);
-
-  // Emit as many MaxNopLength NOPs as needed, then emit a NOP of the remaining
-  // length.
+  // Write 1 or 2 byte NOP sequences, or a longer trapsled, until
+  // we have written Count bytes
   do {
-    const uint8_t ThisNopLength = (uint8_t) std::min(Count, MaxNopLength);
-    const uint8_t Prefixes = ThisNopLength <= 10 ? 0 : ThisNopLength - 10;
-    for (uint8_t i = 0; i < Prefixes; i++)
-      OS << '\x66';
-    const uint8_t Rest = ThisNopLength - Prefixes;
-    if (Rest != 0)
-      OS.write(Nops[Rest - 1], Rest);
+    const uint8_t ThisNopLength = (uint8_t) std::min(Count, (uint64_t)127);
+    switch (ThisNopLength) {
+      case 0: break;
+      case 1: OS << '\x90';
+              break;
+      case 2: OS << '\x66';
+              OS << '\x90';
+              break;
+      default: OS << '\xEB';
+               OS << (uint8_t)(ThisNopLength - 2);
+               for(uint8_t i = 2; i < ThisNopLength; ++i)
+                 OS << '\xCC';
+    }
     Count -= ThisNopLength;
   } while (Count != 0);
 
