[clang] 682d01a - [X86][MS-InlineAsm] Use exact conditions to recognize MS global variables

Phoebe Wang via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 22 19:46:24 PST 2021


Author: Phoebe Wang
Date: 2021-12-23T11:46:03+08:00
New Revision: 682d01a1c1c52bd95d3d06267d6017395770256b

URL: https://github.com/llvm/llvm-project/commit/682d01a1c1c52bd95d3d06267d6017395770256b
DIFF: https://github.com/llvm/llvm-project/commit/682d01a1c1c52bd95d3d06267d6017395770256b.diff

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

D115225 tried to roll back the effects on symbols of MS inline asm
introduced by D113096. But the combination of the conditions cannot
match all the changes. As a result, there are still fails after the
patch.

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.

Reviewed By: skan

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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang/test/CodeGen/ms-inline-asm-functions.c b/clang/test/CodeGen/ms-inline-asm-functions.c
index c958d8803871..1a6ead9286df 100644
--- a/clang/test/CodeGen/ms-inline-asm-functions.c
+++ b/clang/test/CodeGen/ms-inline-asm-functions.c
@@ -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
 }

diff  --git a/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp b/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
index 6bae55695f3d..2ba0b97229cc 100644
--- a/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
+++ b/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
@@ -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

diff  --git a/llvm/lib/Target/X86/AsmParser/X86Operand.h b/llvm/lib/Target/X86/AsmParser/X86Operand.h
index 6d20c6af5fd2..0116c081541b 100644
--- a/llvm/lib/Target/X86/AsmParser/X86Operand.h
+++ b/llvm/lib/Target/X86/AsmParser/X86Operand.h
@@ -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 !Mem.DefaultBaseReg && Mem.FrontendSize;
   }
 
   bool needAddressOf() const override { return AddressOf; }


        


More information about the cfe-commits mailing list