[clang] f3e6a61 - [OpenCL] Handle address space conversions for constexpr (PR44177)

Sven van Haastregt via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 9 03:09:53 PST 2019


Author: Sven van Haastregt
Date: 2019-12-09T11:09:16Z
New Revision: f3e6a61232640f2ec78b97d44cc0b5ba12676a0d

URL: https://github.com/llvm/llvm-project/commit/f3e6a61232640f2ec78b97d44cc0b5ba12676a0d
DIFF: https://github.com/llvm/llvm-project/commit/f3e6a61232640f2ec78b97d44cc0b5ba12676a0d.diff

LOG: [OpenCL] Handle address space conversions for constexpr (PR44177)

The AST for the constexpr.cl test contains address space conversion
nodes to cast through the implicit generic address space.  These
caused the evaluator to reject the input as constexpr in C++ for
OpenCL mode, whereas the input was considered constexpr in plain C++
mode as the AST won't have address space cast nodes then.

Fixes PR44177.

Differential Revision: https://reviews.llvm.org/D71015

Added: 
    clang/test/CodeGenOpenCLCXX/constexpr.cl

Modified: 
    clang/lib/AST/ExprConstant.cpp
    clang/test/CodeGenOpenCLCXX/address-space-deduction.cl

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 5aa151984e51..fbc706b25d15 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -7118,6 +7118,13 @@ class ExprEvaluatorBase
         return false;
       return DerivedSuccess(DestValue, E);
     }
+
+    case CK_AddressSpaceConversion: {
+      APValue Value;
+      if (!Evaluate(Value, Info, E->getSubExpr()))
+        return false;
+      return DerivedSuccess(Value, E);
+    }
     }
 
     return Error(E);

diff  --git a/clang/test/CodeGenOpenCLCXX/address-space-deduction.cl b/clang/test/CodeGenOpenCLCXX/address-space-deduction.cl
index a6ae5af01eba..58502e9eecc4 100644
--- a/clang/test/CodeGenOpenCLCXX/address-space-deduction.cl
+++ b/clang/test/CodeGenOpenCLCXX/address-space-deduction.cl
@@ -12,17 +12,15 @@
 //COMMON: @glob = addrspace(1) global i32
 int glob;
 //PTR: @glob_p = addrspace(1) global i32 addrspace(4)* addrspacecast (i32 addrspace(1)* @glob to i32 addrspace(4)*)
-//REF: @glob_p = addrspace(1) global i32 addrspace(4)* null
+//REF: @glob_p = addrspace(1) constant i32 addrspace(4)* addrspacecast (i32 addrspace(1)* @glob to i32 addrspace(4)*)
 int PTR glob_p = ADR(glob);
 
 //COMMON: @_ZZ3fooi{{P|R}}U3AS4iE6loc_st = internal addrspace(1) global i32
 //PTR: @_ZZ3fooiPU3AS4iE8loc_st_p = internal addrspace(1) global i32 addrspace(4)* addrspacecast (i32 addrspace(1)* @_ZZ3fooiPU3AS4iE6loc_st to i32 addrspace(4)*)
-//REF: @_ZZ3fooiRU3AS4iE8loc_st_p = internal addrspace(1) global i32 addrspace(4)* null
+//REF: @_ZZ3fooiRU3AS4iE8loc_st_p = internal addrspace(1) constant i32 addrspace(4)* addrspacecast (i32 addrspace(1)* @_ZZ3fooiRU3AS4iE6loc_st to i32 addrspace(4)*)
 //COMMON: @loc_ext_p = external addrspace(1) {{global|constant}} i32 addrspace(4)*
 //COMMON: @loc_ext = external addrspace(1) global i32
 
-//REF: store i32 addrspace(4)* addrspacecast (i32 addrspace(1)* @glob to i32 addrspace(4)*), i32 addrspace(4)* addrspace(1)* @glob_p
-
 //COMMON: define spir_func i32 @_Z3fooi{{P|R}}U3AS4i(i32 %par, i32 addrspace(4)*{{.*}} %par_p)
 int foo(int par, int PTR par_p){
   //COMMON: %loc = alloca i32
@@ -37,7 +35,6 @@ int foo(int par, int PTR par_p){
 
   // CHECK directives for the following code are located above.
   static int loc_st;
-  //REF: store i32 addrspace(4)* addrspacecast (i32 addrspace(1)* @_ZZ3fooiRU3AS4iE6loc_st to i32 addrspace(4)*), i32 addrspace(4)* addrspace(1)* @_ZZ3fooiRU3AS4iE8loc_st_p
   static int PTR loc_st_p = ADR(loc_st);
   extern int loc_ext;
   extern int PTR loc_ext_p;

diff  --git a/clang/test/CodeGenOpenCLCXX/constexpr.cl b/clang/test/CodeGenOpenCLCXX/constexpr.cl
new file mode 100644
index 000000000000..b7175020b814
--- /dev/null
+++ b/clang/test/CodeGenOpenCLCXX/constexpr.cl
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=clc++ -O0 -emit-llvm -o - | FileCheck %s
+
+struct Storage final {
+  constexpr const float& operator[](const int index) const noexcept {
+    return InternalStorage[index];
+  }
+
+  const float InternalStorage[1];
+};
+
+constexpr Storage getStorage() {
+  return Storage{{1.0f}};
+}
+
+constexpr float compute() {
+  constexpr auto s = getStorage();
+  return 2.0f / (s[0]);
+}
+
+constexpr float FloatConstant = compute();
+
+// CHECK-LABEL: define spir_kernel void @foo
+// CHECK: store float 2.000000e+00
+kernel void foo(global float *x) {
+  *x = FloatConstant;
+}


        


More information about the cfe-commits mailing list