Anastasia created this revision.

After the change of constant address space function scope variable in 6e34f0e 
("[OpenCL] Emit function-scope variable in constant address space as static 
variable", 2017-05-15)  a bug has been introduced that triggered unreachable 
during generation of samplers.

This is because sampler in global scope has not to be generated. The 
initialization function has to be used instead of a variable everywhere the 
sampler variable is being referenced.

This patch fixes the bug and adds missing test case.


https://reviews.llvm.org/D39129

Files:
  lib/CodeGen/CGDecl.cpp
  test/CodeGenOpenCL/sampler.cl


Index: test/CodeGenOpenCL/sampler.cl
===================================================================
--- test/CodeGenOpenCL/sampler.cl
+++ test/CodeGenOpenCL/sampler.cl
@@ -33,6 +33,10 @@
   // CHECK: [[SAMP:%[0-9]+]] = call %opencl.sampler_t addrspace(2)* 
@__translate_sampler_initializer(i32 19)
   // CHECK: store %opencl.sampler_t addrspace(2)* [[SAMP]], %opencl.sampler_t 
addrspace(2)** [[smp_ptr]]
 
+  // Initialising constant AS sampler will be handled as global (we won't 
generate local alloca for it)
+  // CHECK-NOT: alloca %opencl.sampler_t addrspace(2)*
+  constant sampler_t smp_const_as = 11;
+
   // Case 1b
   fnc4smp(smp);
   // CHECK-NOT: call %opencl.sampler_t addrspace(2)* 
@__translate_sampler_initializer(i32 19)
@@ -58,4 +62,8 @@
   fnc4smp(5);
   // CHECK: [[SAMP:%[0-9]+]] = call %opencl.sampler_t addrspace(2)* 
@__translate_sampler_initializer(i32 5)
   // CHECK: call spir_func void @fnc4smp(%opencl.sampler_t addrspace(2)* 
[[SAMP]])
+
+  fnc4smp(smp_const_as);
+  // CHECK: [[SAMP:%[0-9]+]] = call %opencl.sampler_t addrspace(2)* 
@__translate_sampler_initializer(i32 11)
+  // CHECK: call spir_func void @fnc4smp(%opencl.sampler_t addrspace(2)* 
[[SAMP]])
 }
Index: lib/CodeGen/CGDecl.cpp
===================================================================
--- lib/CodeGen/CGDecl.cpp
+++ lib/CodeGen/CGDecl.cpp
@@ -158,6 +158,13 @@
     // Don't emit it now, allow it to be emitted lazily on its first use.
     return;
 
+   // Samplers in constant address space are handled as a special case
+   // unlike other variables they are not generated as globals
+   // and their initialiser will be used everywhere it is being referenced.
+   if (D.getType().getAddressSpace() == LangAS::opencl_constant &&
+       D.getType().getTypePtr()->isSamplerT())
+     return;
+
   // Some function-scope variable does not have static storage but still
   // needs to be emitted like a static variable, e.g. a function-scope
   // variable in constant address space in OpenCL.


Index: test/CodeGenOpenCL/sampler.cl
===================================================================
--- test/CodeGenOpenCL/sampler.cl
+++ test/CodeGenOpenCL/sampler.cl
@@ -33,6 +33,10 @@
   // CHECK: [[SAMP:%[0-9]+]] = call %opencl.sampler_t addrspace(2)* @__translate_sampler_initializer(i32 19)
   // CHECK: store %opencl.sampler_t addrspace(2)* [[SAMP]], %opencl.sampler_t addrspace(2)** [[smp_ptr]]
 
+  // Initialising constant AS sampler will be handled as global (we won't generate local alloca for it)
+  // CHECK-NOT: alloca %opencl.sampler_t addrspace(2)*
+  constant sampler_t smp_const_as = 11;
+
   // Case 1b
   fnc4smp(smp);
   // CHECK-NOT: call %opencl.sampler_t addrspace(2)* @__translate_sampler_initializer(i32 19)
@@ -58,4 +62,8 @@
   fnc4smp(5);
   // CHECK: [[SAMP:%[0-9]+]] = call %opencl.sampler_t addrspace(2)* @__translate_sampler_initializer(i32 5)
   // CHECK: call spir_func void @fnc4smp(%opencl.sampler_t addrspace(2)* [[SAMP]])
+
+  fnc4smp(smp_const_as);
+  // CHECK: [[SAMP:%[0-9]+]] = call %opencl.sampler_t addrspace(2)* @__translate_sampler_initializer(i32 11)
+  // CHECK: call spir_func void @fnc4smp(%opencl.sampler_t addrspace(2)* [[SAMP]])
 }
Index: lib/CodeGen/CGDecl.cpp
===================================================================
--- lib/CodeGen/CGDecl.cpp
+++ lib/CodeGen/CGDecl.cpp
@@ -158,6 +158,13 @@
     // Don't emit it now, allow it to be emitted lazily on its first use.
     return;
 
+   // Samplers in constant address space are handled as a special case
+   // unlike other variables they are not generated as globals
+   // and their initialiser will be used everywhere it is being referenced.
+   if (D.getType().getAddressSpace() == LangAS::opencl_constant &&
+       D.getType().getTypePtr()->isSamplerT())
+     return;
+
   // Some function-scope variable does not have static storage but still
   // needs to be emitted like a static variable, e.g. a function-scope
   // variable in constant address space in OpenCL.
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to