]> granicus.if.org Git - clang/commitdiff
OpenCL: Assume inline asm is convergent
authorMatt Arsenault <Matthew.Arsenault@amd.com>
Mon, 13 Nov 2017 22:40:55 +0000 (22:40 +0000)
committerMatt Arsenault <Matthew.Arsenault@amd.com>
Mon, 13 Nov 2017 22:40:55 +0000 (22:40 +0000)
Already done for CUDA.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@318098 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGStmt.cpp
test/CodeGenOpenCL/convergent.cl

index 6a78865fc9440af21324e8a813eba3294b913590..7b1afab5f2c1b202365e2d69c369ce134bb34196 100644 (file)
@@ -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);
   }
index c46205bb9b12df0acef3bdb0825a565ae1c32677..285b637ca687957cdff8c9e97c5674d2a9db0b46 100644 (file)
@@ -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{{[^}]*}} }