[PATCH] D18713: [OpenCL] Generate bitcast when target address space does not change.

Yaxun Liu via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 1 15:03:00 PDT 2016


yaxunl updated the summary for this revision.
yaxunl updated this revision to Diff 52431.
yaxunl added a comment.

Use CreatePointerBitCastOrAddrSpaceCast as John suggested.


http://reviews.llvm.org/D18713

Files:
  lib/CodeGen/CGExprScalar.cpp
  test/CodeGenOpenCL/2016-04-01-addrcast.cl

Index: test/CodeGenOpenCL/2016-04-01-addrcast.cl
===================================================================
--- /dev/null
+++ test/CodeGenOpenCL/2016-04-01-addrcast.cl
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 %s -triple x86_64-unknown-linux-gnu -O0 -cl-std=CL2.0 -emit-llvm -o - | FileCheck %s
+
+// When -ffake-address-space-map is not used, all address space mapped to 0 for x86/x86-64, a bitcast should be generated instead of addrspacecast.
+void foo() {
+  global int *a;
+  generic void *b = a;
+  // CHECK: bitcast 
+  // CHECK-NOT: addrspacecast
+}
Index: lib/CodeGen/CGExprScalar.cpp
===================================================================
--- lib/CodeGen/CGExprScalar.cpp
+++ lib/CodeGen/CGExprScalar.cpp
@@ -1411,7 +1411,10 @@
   }
   case CK_AddressSpaceConversion: {
     Value *Src = Visit(const_cast<Expr*>(E));
-    return Builder.CreateAddrSpaceCast(Src, ConvertType(DestTy));
+    // Since target may map different address spaces in AST to the same address
+    // space, an address space conversion may end up as a bitcast.
+    return Builder.CreatePointerBitCastOrAddrSpaceCast(Src,
+                                                       ConvertType(DestTy));
   }
   case CK_AtomicToNonAtomic:
   case CK_NonAtomicToAtomic:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18713.52431.patch
Type: text/x-patch
Size: 1263 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160401/e19cd31f/attachment.bin>


More information about the cfe-commits mailing list