[PATCH] D116090: [X86][MS-InlineAsm] Use exact conditions to recognize MS global variables

Phoebe Wang via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 20 23:31:18 PST 2021

pengfei created this revision.
pengfei added reviewers: skan, xiangzhangllvm, craig.topper, coby.
Herald added subscribers: ChuanqiXu, hiraditya.
pengfei requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

D115225 <https://reviews.llvm.org/D115225> tried to roll back the effects on symbols of MS inline asm
introduced by D113096 <https://reviews.llvm.org/D113096>. But the combination of the conditions cannot
match all the changes. As a result, there are still fails after the

This patch fixes the problem by checking the exact conditions for MS
global variables, i.e., variable (by FrontendSize != 0) + non rip/eip
(by DefaultBaseReg == 0), so that we can fully roll back for D113096 <https://reviews.llvm.org/D113096>.

  rG LLVM Github Monorepo



Index: llvm/lib/Target/X86/AsmParser/X86Operand.h
--- llvm/lib/Target/X86/AsmParser/X86Operand.h
+++ 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; }
Index: llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
--- llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
+++ 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
Index: clang/test/CodeGen/ms-inline-asm-functions.c
--- clang/test/CodeGen/ms-inline-asm-functions.c
+++ 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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D116090.395604.patch
Type: text/x-patch
Size: 1980 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211221/a3cceff6/attachment.bin>

More information about the cfe-commits mailing list