From: Yaxun Liu Date: Fri, 23 Mar 2018 19:43:42 +0000 (+0000) Subject: [AMDGPU] Fix codegen for inline assembly X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cbbdeee837d1bae21273a59e85c1b084c97e06cb;p=clang [AMDGPU] Fix codegen for inline assembly Need to override convertConstraint to recognise amdgpu specific register names. Differential Revision: https://reviews.llvm.org/D44533 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@328359 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Basic/Targets/AMDGPU.h b/lib/Basic/Targets/AMDGPU.h index 603c9b2d54..f7c477659d 100644 --- a/lib/Basic/Targets/AMDGPU.h +++ b/lib/Basic/Targets/AMDGPU.h @@ -285,6 +285,19 @@ public: return true; } + // \p Constraint will be left pointing at the last character of + // the constraint. In practice, it won't be changed unless the + // constraint is longer than one character. + std::string convertConstraint(const char *&Constraint) const override { + const char *Begin = Constraint; + TargetInfo::ConstraintInfo Info("", ""); + if (validateAsmConstraint(Constraint, Info)) + return std::string(Begin).substr(0, Constraint - Begin + 1); + + Constraint = Begin; + return std::string(1, *Constraint); + } + bool initFeatureMap(llvm::StringMap &Features, DiagnosticsEngine &Diags, StringRef CPU, diff --git a/lib/CodeGen/CGStmt.cpp b/lib/CodeGen/CGStmt.cpp index b1d1bf874d..b89d9f0929 100644 --- a/lib/CodeGen/CGStmt.cpp +++ b/lib/CodeGen/CGStmt.cpp @@ -1926,7 +1926,7 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) { // Simplify the output constraint. std::string OutputConstraint(S.getOutputConstraint(i)); OutputConstraint = SimplifyConstraint(OutputConstraint.c_str() + 1, - getTarget()); + getTarget(), &OutputConstraintInfos); const Expr *OutExpr = S.getOutputExpr(i); OutExpr = OutExpr->IgnoreParenNoopCasts(getContext()); diff --git a/test/CodeGenOpenCL/inline-asm-amdgcn.cl b/test/CodeGenOpenCL/inline-asm-amdgcn.cl new file mode 100644 index 0000000000..ccd98210d3 --- /dev/null +++ b/test/CodeGenOpenCL/inline-asm-amdgcn.cl @@ -0,0 +1,8 @@ +// REQUIRES: amdgpu-registered-target +// RUN: %clang_cc1 -emit-llvm -o - -triple amdgcn %s | FileCheck %s + +kernel void test_long(int arg0) { + long v15_16; + // CHECK: tail call i64 asm sideeffect "v_lshlrev_b64 v[15:16], 0, $0", "={v[15:16]},v"(i32 %arg0) + __asm volatile("v_lshlrev_b64 v[15:16], 0, %0" : "={v[15:16]}"(v15_16) : "v"(arg0)); +} diff --git a/test/Sema/inline-asm-validate-amdgpu.cl b/test/Sema/inline-asm-validate-amdgpu.cl index bc2580c573..51009ecb3f 100644 --- a/test/Sema/inline-asm-validate-amdgpu.cl +++ b/test/Sema/inline-asm-validate-amdgpu.cl @@ -74,3 +74,8 @@ test_double(const __global double *a, const __global double *b, __global double c[i] = ci; } + +void test_long(int arg0) { + long v15_16; + __asm volatile("v_lshlrev_b64 v[15:16], 0, %0" : "={v[15:16]}"(v15_16) : "v"(arg0)); +}