echuraev created this revision.
echuraev added a reviewer: Anastasia.
echuraev added subscribers: bader, yaxunl, cfe-commits.
Enabling the compression of CLK_NULL_QUEUE to variable of type queue_t.


https://reviews.llvm.org/D27569

Files:
  lib/Sema/SemaExpr.cpp
  test/CodeGenOpenCL/null_queue.cl


Index: test/CodeGenOpenCL/null_queue.cl
===================================================================
--- /dev/null
+++ test/CodeGenOpenCL/null_queue.cl
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -O0 -cl-std=CL2.0  -emit-llvm %s -o - | FileCheck %s
+extern queue_t get_default_queue();
+
+#define CLK_NULL_QUEUE 0
+
+bool f() {
+  return CLK_NULL_QUEUE == get_default_queue() &&
+         get_default_queue() == CLK_NULL_QUEUE;
+  // CHECK: icmp eq %opencl.queue_t* null, %{{.*}}
+}
+
Index: lib/Sema/SemaExpr.cpp
===================================================================
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -9621,6 +9621,18 @@
     return ResultTy;
   }
 
+  if (getLangOpts().OpenCL && getLangOpts().OpenCLVersion >= 200) {
+    if (LHSIsNull && RHSType->isQueueT()) {
+      LHS = ImpCastExprToType(LHS.get(), RHSType, CK_NullToPointer);
+      return ResultTy;
+    }
+
+    if (LHSType->isQueueT() && RHSIsNull) {
+      RHS = ImpCastExprToType(RHS.get(), LHSType, CK_NullToPointer);
+      return ResultTy;
+    }
+  }
+
   return InvalidOperands(Loc, LHS, RHS);
 }
 


Index: test/CodeGenOpenCL/null_queue.cl
===================================================================
--- /dev/null
+++ test/CodeGenOpenCL/null_queue.cl
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -O0 -cl-std=CL2.0  -emit-llvm %s -o - | FileCheck %s
+extern queue_t get_default_queue();
+
+#define CLK_NULL_QUEUE 0
+
+bool f() {
+  return CLK_NULL_QUEUE == get_default_queue() &&
+         get_default_queue() == CLK_NULL_QUEUE;
+  // CHECK: icmp eq %opencl.queue_t* null, %{{.*}}
+}
+
Index: lib/Sema/SemaExpr.cpp
===================================================================
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -9621,6 +9621,18 @@
     return ResultTy;
   }
 
+  if (getLangOpts().OpenCL && getLangOpts().OpenCLVersion >= 200) {
+    if (LHSIsNull && RHSType->isQueueT()) {
+      LHS = ImpCastExprToType(LHS.get(), RHSType, CK_NullToPointer);
+      return ResultTy;
+    }
+
+    if (LHSType->isQueueT() && RHSIsNull) {
+      RHS = ImpCastExprToType(RHS.get(), LHSType, CK_NullToPointer);
+      return ResultTy;
+    }
+  }
+
   return InvalidOperands(Loc, LHS, RHS);
 }
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to