From a5888a730dfb4c11e4386ee56c65df65d706cf7e Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Mon, 13 Nov 2017 22:40:55 +0000 Subject: [PATCH] OpenCL: Assume inline asm is convergent Already done for CUDA. llvm-svn: 318098 --- clang/lib/CodeGen/CGStmt.cpp | 9 +++++---- clang/test/CodeGenOpenCL/convergent.cl | 7 +++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp index 6a78865..7b1afab 100644 --- a/clang/lib/CodeGen/CGStmt.cpp +++ b/clang/lib/CodeGen/CGStmt.cpp @@ -2149,10 +2149,11 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) { llvm::ConstantAsMetadata::get(Loc))); } - if (getLangOpts().CUDA && getLangOpts().CUDAIsDevice) { - // Conservatively, mark all inline asm blocks in CUDA as convergent - // (meaning, they may call an intrinsically convergent op, such as bar.sync, - // and so can't have certain optimizations applied around them). + if (getLangOpts().assumeFunctionsAreConvergent()) { + // Conservatively, mark all inline asm blocks in CUDA or OpenCL as + // convergent (meaning, they may call an intrinsically convergent op, such + // as bar.sync, and so can't have certain optimizations applied around + // them). Result->addAttribute(llvm::AttributeList::FunctionIndex, llvm::Attribute::Convergent); } diff --git a/clang/test/CodeGenOpenCL/convergent.cl b/clang/test/CodeGenOpenCL/convergent.cl index c46205b..285b637 100644 --- a/clang/test/CodeGenOpenCL/convergent.cl +++ b/clang/test/CodeGenOpenCL/convergent.cl @@ -126,6 +126,13 @@ void test_not_unroll() { // CHECK: declare spir_func void @nodupfun(){{[^#]*}} #[[attr3:[0-9]+]] +// CHECK-LABEL: @assume_convergent_asm +// CHECK: tail call void asm sideeffect "s_barrier", ""() #4 +kernel void assume_convergent_asm() +{ + __asm__ volatile("s_barrier"); +} + // CHECK: attributes #0 = { noinline norecurse nounwind " // CHECK: attributes #1 = { {{[^}]*}}convergent{{[^}]*}} } // CHECK: attributes #2 = { {{[^}]*}}convergent{{[^}]*}} } -- 2.7.4