Skip to content

Commit

Permalink
[X86][MS-InlineAsm] Use exact conditions to recognize MS global varia…
Browse files Browse the repository at this point in the history
…bles

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
  • Loading branch information
phoebewang committed Dec 23, 2021
1 parent da41cfd commit 682d01a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion clang/test/CodeGen/ms-inline-asm-functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions llvm/lib/Target/X86/AsmParser/X86Operand.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down

0 comments on commit 682d01a

Please sign in to comment.