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 +}
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 +}
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits