From 5f776793567cb8d7c55e27a5b4d8e5e75f7f9616 Mon Sep 17 00:00:00 2001 From: Marina Yatsina Date: Mon, 7 Mar 2016 18:10:25 +0000 Subject: [PATCH] [ms-inline-asm][AVX512] Add ability to use k registers in MS inline asm + fix bag with curly braces Until now curly braces could only be used in MS inline assembly to mark block start/end. All curly braces were removed completely at a very early stage. This approach caused bugs like: "m{o}v eax, ebx" turned into "mov eax, ebx" without any error. In addition, AVX-512 added special operands (e.g., k registers), which are also surrounded by curly braces that mark them as such. Now, we need to keep the curly braces and identify at a later stage if they are marking block start/end (if so, ignore them), or surrounding special AVX-512 operands (if so, parse them as such). This patch fixes the bug described above and enables the use of AVX-512 special operands. This commit is the the clang part of the patch. The clang part of the review is: http://reviews.llvm.org/D17766 The llvm part of the review is: http://reviews.llvm.org/D17767 Differential Revision: http://reviews.llvm.org/D17766 llvm-svn: 262842 --- clang/lib/Parse/ParseStmtAsm.cpp | 6 ++++++ clang/test/CodeGen/ms-inline-asm-avx512.c | 10 ++++++++++ clang/test/CodeGen/ms-inline-asm.c | 2 +- clang/test/Parser/ms-inline-asm.c | 4 ++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/clang/lib/Parse/ParseStmtAsm.cpp b/clang/lib/Parse/ParseStmtAsm.cpp index 7acf324bbe2b..99b164d9738f 100644 --- a/clang/lib/Parse/ParseStmtAsm.cpp +++ b/clang/lib/Parse/ParseStmtAsm.cpp @@ -390,6 +390,7 @@ StmtResult Parser::ParseMicrosoftAsmStatement(SourceLocation AsmLoc) { if (!InAsmComment && Tok.is(tok::l_brace)) { // Consume the opening brace. SkippedStartOfLine = Tok.isAtStartOfLine(); + AsmToks.push_back(Tok); EndLoc = ConsumeBrace(); BraceNesting++; LBraceLocs.push_back(EndLoc); @@ -442,6 +443,11 @@ StmtResult Parser::ParseMicrosoftAsmStatement(SourceLocation AsmLoc) { BraceCount == (savedBraceCount + BraceNesting)) { // Consume the closing brace. SkippedStartOfLine = Tok.isAtStartOfLine(); + // Don't want to add the closing brace of the whole asm block + if (SingleLineMode || BraceNesting > 1) { + Tok.clearFlag(Token::LeadingSpace); + AsmToks.push_back(Tok); + } EndLoc = ConsumeBrace(); BraceNesting--; // Finish if all of the opened braces in the inline asm section were diff --git a/clang/test/CodeGen/ms-inline-asm-avx512.c b/clang/test/CodeGen/ms-inline-asm-avx512.c index 4f401e286a30..c1b783a2107c 100644 --- a/clang/test/CodeGen/ms-inline-asm-avx512.c +++ b/clang/test/CodeGen/ms-inline-asm-avx512.c @@ -9,3 +9,13 @@ void t1() { vaddpd zmm8, zmm27, zmm6 } } + + +void t2() { +// CHECK: @t2 +// CHECK: call void asm sideeffect inteldialect "vaddpd zmm8 {k1}, zmm27, zmm6", "~{zmm8},~{dirflag},~{fpsr},~{flags}"() +// CHECK: ret void + __asm { + vaddpd zmm8 {k1}, zmm27, zmm6 + } +} diff --git a/clang/test/CodeGen/ms-inline-asm.c b/clang/test/CodeGen/ms-inline-asm.c index e4d9756191d3..ad9e4f361b70 100644 --- a/clang/test/CodeGen/ms-inline-asm.c +++ b/clang/test/CodeGen/ms-inline-asm.c @@ -86,7 +86,7 @@ void t9() { __asm { pop ebx } } // CHECK: t9 -// CHECK: call void asm sideeffect inteldialect "push ebx\0A\09mov ebx, $$0x07\0A\09pop ebx", "~{ebx},~{esp},~{dirflag},~{fpsr},~{flags}"() +// CHECK: call void asm sideeffect inteldialect "push ebx\0A\09mov ebx, $$0x07\0A\09pop ebx\0A\09", "~{ebx},~{esp},~{dirflag},~{fpsr},~{flags}"() } unsigned t10(void) { diff --git a/clang/test/Parser/ms-inline-asm.c b/clang/test/Parser/ms-inline-asm.c index 5b0cabf7e6a3..e3c392406957 100644 --- a/clang/test/Parser/ms-inline-asm.c +++ b/clang/test/Parser/ms-inline-asm.c @@ -53,6 +53,10 @@ void t11() { void t12() { __asm jmp label // expected-error {{use of undeclared label 'label'}} } +void t13() { + __asm m{o}v eax, ebx // expected-error {{expected identifier}} expected-error {{use of undeclared label '{o}v eax, ebx'}} +} + int t_fail() { // expected-note {{to match this}} __asm __asm { // expected-error 3 {{expected}} expected-note {{to match this}}