Author: Shengchen Kan Date: 2021-11-05T09:11:41+08:00 New Revision: be08e452f36602cd73f816787bf16d1a0405ff09
URL: https://github.com/llvm/llvm-project/commit/be08e452f36602cd73f816787bf16d1a0405ff09 DIFF: https://github.com/llvm/llvm-project/commit/be08e452f36602cd73f816787bf16d1a0405ff09.diff LOG: [X86][MS-InlineAsm] Add constraint *m for memory access w/ global var Constraint `*m` should be used when the address of a variable is passed as a value. And the constraint is missing for MS inline assembly when sth is written to the address of the variable. The missing would cause FE delete the definition of the static varible, and then result in "undefined reference to xxx" issue. Reviewed By: xiangzhangllvm Differential Revision: https://reviews.llvm.org/D113096 Added: clang/test/CodeGen/ms-inline-asm-static-variable.c llvm/test/CodeGen/X86/ms-inline-asm-array.ll Modified: clang/test/CodeGen/X86/ms_fmul.c clang/test/CodeGen/ms-inline-asm-variables.c llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp Removed: ################################################################################ diff --git a/clang/test/CodeGen/X86/ms_fmul.c b/clang/test/CodeGen/X86/ms_fmul.c index a0a1be9e217c5..d1cfcef814625 100644 --- a/clang/test/CodeGen/X86/ms_fmul.c +++ b/clang/test/CodeGen/X86/ms_fmul.c @@ -18,4 +18,4 @@ void __attribute__ ((naked)) foo(void) }} // CHECK-LABEL: foo -// CHECK: call void asm sideeffect inteldialect "fmul qword ptr static_const_table[edx + $$240]\0A\09ret" +// CHECK: call void asm sideeffect inteldialect "fmul qword ptr $0[edx + $$240]\0A\09ret" diff --git a/clang/test/CodeGen/ms-inline-asm-static-variable.c b/clang/test/CodeGen/ms-inline-asm-static-variable.c new file mode 100644 index 0000000000000..fb80bf7b2f74f --- /dev/null +++ b/clang/test/CodeGen/ms-inline-asm-static-variable.c @@ -0,0 +1,10 @@ +// REQUIRES: x86-registered-target +// Check the constraint "*m" of operand arr and the definition of arr is not removed by FE +// RUN: %clang_cc1 %s -fasm-blocks -triple i386-apple-darwin10 -emit-llvm -o - | FileCheck %s + +static int arr[10]; +void t1() { + // CHECK: @arr = internal global [10 x i32] + // CHECK: call void asm sideeffect inteldialect "mov dword ptr $0[edx * $$4],edx", "=*m,{{.*}}([10 x i32]* @arr) + __asm mov dword ptr arr[edx*4],edx +} diff --git a/clang/test/CodeGen/ms-inline-asm-variables.c b/clang/test/CodeGen/ms-inline-asm-variables.c index f8fd227610b64..7d0cb3fbcc8f8 100644 --- a/clang/test/CodeGen/ms-inline-asm-variables.c +++ b/clang/test/CodeGen/ms-inline-asm-variables.c @@ -3,19 +3,19 @@ int gVar; void t1() { - // CHECK: add eax, dword ptr gVar[eax] + // CHECK: add eax, dword ptr ${{[0-9]}}[eax] __asm add eax, dword ptr gVar[eax] - // CHECK: add dword ptr gVar[eax], eax + // CHECK: add dword ptr ${{[0-9]}}[eax], eax __asm add dword ptr [eax+gVar], eax - // CHECK: add ebx, dword ptr gVar[ebx + $$270] + // CHECK: add ebx, dword ptr ${{[0-9]}}[ebx + $$270] __asm add ebx, dword ptr gVar[271 - 82 + 81 + ebx] - // CHECK: add dword ptr gVar[ebx + $$828], ebx + // CHECK: add dword ptr ${{[0-9]}}[ebx + $$828], ebx __asm add dword ptr [ebx + gVar + 828], ebx - // CHECK: add ecx, dword ptr gVar[ecx + ecx * $$4 + $$4590] + // CHECK: add ecx, dword ptr ${{[0-9]}}[ecx + ecx * $$4 + $$4590] __asm add ecx, dword ptr gVar[4590 + ecx + ecx*4] - // CHECK: add dword ptr gVar[ecx + ecx * $$8 + $$73], ecx + // CHECK: add dword ptr ${{[0-9]}}[ecx + ecx * $$8 + $$73], ecx __asm add dword ptr [gVar + ecx + 45 + 23 - 53 + 60 - 2 + ecx*8], ecx - // CHECK: add gVar[ecx + ebx + $$7], eax + // CHECK: add ${{[0-9]}}[ecx + ebx + $$7], eax __asm add 1 + 1 + 2 + 3[gVar + ecx + ebx], eax } @@ -32,4 +32,3 @@ void t2() { // CHECK: mov ${{[0-9]}}[ebx + $$47], eax __asm mov 5 + 8 + 13 + 21[lVar + ebx], eax } - diff --git a/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp b/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp index 511d263abbaab..88b993fb827c8 100644 --- a/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp +++ b/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp @@ -1758,8 +1758,8 @@ bool X86AsmParser::CreateMemForMSInlineAsm( // It is widely common for MS InlineAsm to use a global variable and one/two // 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)); + Operands.push_back(X86Operand::CreateMem(getPointerWidth(), Disp, Start, + End, Size, Identifier, Decl)); return false; } // Otherwise, we set the base register to a non-zero value @@ -2551,6 +2551,8 @@ bool X86AsmParser::ParseIntelOperand(OperandVector &Operands) { StringRef ErrMsg; unsigned BaseReg = SM.getBaseReg(); unsigned IndexReg = SM.getIndexReg(); + if (IndexReg && BaseReg == X86::RIP) + BaseReg = 0; unsigned Scale = SM.getScale(); if (!PtrInOperand) Size = SM.getElementSize() << 3; diff --git a/llvm/test/CodeGen/X86/ms-inline-asm-array.ll b/llvm/test/CodeGen/X86/ms-inline-asm-array.ll new file mode 100644 index 0000000000000..a1e7e31b0b287 --- /dev/null +++ b/llvm/test/CodeGen/X86/ms-inline-asm-array.ll @@ -0,0 +1,22 @@ +; RUN: llc < %s -mcpu=x86-64 | FileCheck %s + +@arr = internal global [10 x i32] zeroinitializer, align 16 + +; CHECK: movl %edx, arr(,%rdx,4) +define dso_local i32 @main() #0 { +entry: + call void asm sideeffect inteldialect "mov dword ptr $0[rdx * $$4],edx", "=*m,~{dirflag},~{fpsr},~{flags}"([10 x i32]* @arr) #1, !srcloc !4 + ret i32 0 +} + +attributes #0 = { noinline nounwind optnone uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } +attributes #1 = { nounwind } + +!llvm.module.flags = !{!0, !1, !2} +!llvm.ident = !{!3} + +!0 = !{i32 1, !"wchar_size", i32 4} +!1 = !{i32 7, !"uwtable", i32 1} +!2 = !{i32 7, !"frame-pointer", i32 2} +!3 = !{!"clang"} +!4 = !{i64 63} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits