Reland "[X86][MS-InlineAsm] Use exact conditions to recognize MS global variables"
authorPhoebe Wang <phoebe.wang@intel.com>
Fri, 24 Dec 2021 09:12:56 +0000 (17:12 +0800)
committerPhoebe Wang <phoebe.wang@intel.com>
Fri, 24 Dec 2021 09:42:51 +0000 (17:42 +0800)
This reverts commit a954558e878ed9e97e99036229e99af8c6b6c881.

Thanks Yuanfang's help. I think I found the root cause of the buildbot
fail.

The failed test has both Memory and Immediate X86Operand. All data of
different operand kinds share the same memory space by a union
definition. So it has chance we get the wrong result if we don't check
the operand kind.

It's probably it happen to be the correct value in my local environment
so that I can't reproduce the fail.

Differential Revision: https://reviews.llvm.org/D116090

clang/test/CodeGen/ms-inline-asm-functions.c
llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
llvm/lib/Target/X86/AsmParser/X86Operand.h

index c958d88..1a6ead9 100644 (file)
@@ -39,7 +39,7 @@ int bar() {
 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
 }
index 6bae556..2ba0b97 100644 (file)
@@ -1759,7 +1759,8 @@ bool X86AsmParser::CreateMemForMSInlineAsm(
   // 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
index 6d20c6a..67b1244 100644 (file)
@@ -286,10 +286,9 @@ struct X86Operand final : public MCParsedAsmOperand {
   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 isMem() && !Mem.DefaultBaseReg && Mem.FrontendSize;
   }
 
   bool needAddressOf() const override { return AddressOf; }