From 2460bada567e0bb9213640d53f417dfd4e23a954 Mon Sep 17 00:00:00 2001 From: Michael Zuckerman Date: Mon, 31 Oct 2016 15:27:54 +0000 Subject: [PATCH] [x86][inline-asm] Add support for curly brackets escape using "%" in extended inline asm. Commit on behalf of mharoush After LGTM and check all: This patch is a compatibility fix for clang, matching GCC support for charter escape when using extended in-line assembly (i.e, "%{" ,"%}" --> "{" ,"}" ). It is meant to enable support for advanced features such as AVX512 conditional\masked vector instructions/broadcast assembly syntax. Reviewer: 1. rnk Differential Revision: https://reviews.llvm.org/D25012 llvm-svn: 285585 --- clang/lib/AST/Stmt.cpp | 16 +++++++++------- clang/test/CodeGen/x86_inlineasm_curly_bracket_escape.c | 8 ++++++++ 2 files changed, 17 insertions(+), 7 deletions(-) create mode 100644 clang/test/CodeGen/x86_inlineasm_curly_bracket_escape.c diff --git a/clang/lib/AST/Stmt.cpp b/clang/lib/AST/Stmt.cpp index 89fbdf9..697cdc3 100644 --- a/clang/lib/AST/Stmt.cpp +++ b/clang/lib/AST/Stmt.cpp @@ -533,15 +533,17 @@ unsigned GCCAsmStmt::AnalyzeAsmString(SmallVectorImpl&Pieces, DiagOffs = CurPtr-StrStart-1; return diag::err_asm_invalid_escape; } - + // Handle escaped char and continue looping over the asm string. char EscapedChar = *CurPtr++; - if (EscapedChar == '%') { // %% -> % - // Escaped percentage sign. - CurStringPiece += '%'; + switch (EscapedChar) { + default: + break; + case '%': // %% -> % + case '{': // %{ -> { + case '}': // %} -> } + CurStringPiece += EscapedChar; continue; - } - - if (EscapedChar == '=') { // %= -> Generate an unique ID. + case '=': // %= -> Generate a unique ID. CurStringPiece += "${:uid}"; continue; } diff --git a/clang/test/CodeGen/x86_inlineasm_curly_bracket_escape.c b/clang/test/CodeGen/x86_inlineasm_curly_bracket_escape.c new file mode 100644 index 0000000..503c13e --- /dev/null +++ b/clang/test/CodeGen/x86_inlineasm_curly_bracket_escape.c @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin -target-cpu skylake-avx512 -O0 -S -emit-llvm -o - -Wall -Werror | FileCheck %s +// This test checks validity of inline assembly using curly brackets syntax +// for extended inline asm. + +void test_curly_brackets() { + //CHECK: %xmm1,%xmm0,%xmm1 {%k1}{z} + asm("vpaddb\t %%xmm1,%%xmm0,%%xmm1 %{%%k1%}%{z%}\t":::); +} \ No newline at end of file -- 2.7.4