diff --git a/clang/test/CodeGen/ms-inline-asm-functions.c b/clang/test/CodeGen/ms-inline-asm-functions.c
--- a/clang/test/CodeGen/ms-inline-asm-functions.c
+++ b/clang/test/CodeGen/ms-inline-asm-functions.c
@@ -39,7 +39,7 @@
 int baz() {
   // CHECK-LABEL: _baz:
   __asm mov eax, k;
-  // CHECK: movl    k, %eax
+  // CHECK: movl    _k, %eax
   __asm mov eax, kptr;
   // CHECK: movl    _kptr, %eax
 }
diff --git a/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp b/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
--- a/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
+++ b/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
@@ -1759,7 +1759,8 @@
   // registers in a mmory expression, and though unaccessible via rip/eip.
   if (IsGlobalLV && (BaseReg || IndexReg)) {
     Operands.push_back(X86Operand::CreateMem(getPointerWidth(), Disp, Start,
-                                             End, Size, Identifier, Decl));
+                                             End, Size, Identifier, Decl,
+                                             FrontendSize));
     return false;
   }
   // Otherwise, we set the base register to a non-zero value
diff --git a/llvm/lib/Target/X86/AsmParser/X86Operand.h b/llvm/lib/Target/X86/AsmParser/X86Operand.h
--- a/llvm/lib/Target/X86/AsmParser/X86Operand.h
+++ b/llvm/lib/Target/X86/AsmParser/X86Operand.h
@@ -286,10 +286,9 @@
   bool isOffsetOfLocal() const override { return isImm() && Imm.LocalRef; }
 
   bool isMemPlaceholder(const MCInstrDesc &Desc) const override {
-    // Add more restrictions to avoid the use of global symbols. This helps
-    // with reducing the code size.
-    return !Desc.isRematerializable() && !Desc.isCall() && isMem() &&
-           !Mem.BaseReg && !Mem.IndexReg;
+    // Only MS InlineAsm uses global variables with registers rather than
+    // rip/eip.
+    return !Mem.DefaultBaseReg && Mem.FrontendSize;
   }
 
   bool needAddressOf() const override { return AddressOf; }