[PATCH] D18700: [Inline asm][GCC compatibility] Handle %v-prefixed code in inline assembly

Denis Zobnin via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 1 10:16:40 PDT 2016


d.zobnin.bugzilla created this revision.
d.zobnin.bugzilla added a reviewer: echristo.
d.zobnin.bugzilla added a subscriber: cfe-commits.

Handle an inline assembly feature of GCC: code prefixed with "%v", e. g. "%vpcmpestri" is transformed into "vpcmpestri" instruction if target supports AVX and into "pcmpestri" otherwise.

Given the code:
```
void f(void* arg)
{
  __asm__ ("%vpcmpestri $0, (%1), %2"
           : "=c"(arg)
           : "r"(arg), "x"(arg));
}
```

"gcc -c test.c -o test.o" produces

```
movq   -0x10(%rbp),%xmm0
pcmpestri $0x0,(%rax),%xmm0
```

While "gcc -c -march=corei7-avx test.c -o test.o" produces

```
vmovq  %rdx,%xmm0
vpcmpestri $0x0,(%rax),%xmm0
```

http://reviews.llvm.org/D18700

Files:
  lib/AST/Stmt.cpp
  test/CodeGen/avx-inline-asm.c

Index: lib/AST/Stmt.cpp
===================================================================
--- lib/AST/Stmt.cpp
+++ lib/AST/Stmt.cpp
@@ -632,6 +632,14 @@
 
       CurPtr = NameEnd+1;
       continue;
+    } else if (*Begin == 'v') {
+      // GCC accepts code staring with "%v", e. g. "%vpcmpestri" and transforms
+      // it into "vpcmpestri" instruction if target processor supports AVX and
+      // into "pcmpestri" otherwise.
+      if (C.getTargetInfo().hasFeature("avx"))
+        CurStringPiece = "v" + CurStringPiece;
+      CurStringPiece += EscapedChar;
+      continue;
     }
 
     DiagOffs = CurPtr-StrStart-1;
Index: test/CodeGen/avx-inline-asm.c
===================================================================
--- test/CodeGen/avx-inline-asm.c
+++ test/CodeGen/avx-inline-asm.c
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -target-feature +avx -emit-llvm -S %s -o - | FileCheck %s -check-prefix=CHECK-AVX
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -emit-llvm -S %s -o - | FileCheck %s
+
+void f(void* arg)
+{
+  __asm__ ("%vpcmpestri $0, (%1), %2"
+           : "=c"(arg)
+           : "r"(arg), "x"(arg));
+
+  // CHECK: pcmpestri
+  // CHECK-AVX: vpcmpestri
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18700.52389.patch
Type: text/x-patch
Size: 1213 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160401/c3621033/attachment-0001.bin>


More information about the cfe-commits mailing list