[PATCH] D18713: [OpenCL] Generate bitcast when target address space does not change.
Yaxun Liu via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 12 12:09:18 PDT 2016
This revision was automatically updated to reflect the committed changes.
Closed by commit rL266107: [OpenCL] Handle AddressSpaceConversion when target address space does not… (authored by yaxunl).
Changed prior to commit:
http://reviews.llvm.org/D18713?vs=52800&id=53439#toc
Repository:
rL LLVM
http://reviews.llvm.org/D18713
Files:
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
cfe/trunk/test/CodeGenOpenCL/address-spaces-conversions.cl
Index: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
===================================================================
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp
+++ cfe/trunk/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:
Index: cfe/trunk/test/CodeGenOpenCL/address-spaces-conversions.cl
===================================================================
--- cfe/trunk/test/CodeGenOpenCL/address-spaces-conversions.cl
+++ cfe/trunk/test/CodeGenOpenCL/address-spaces-conversions.cl
@@ -1,23 +1,41 @@
// RUN: %clang_cc1 %s -triple x86_64-unknown-linux-gnu -O0 -ffake-address-space-map -cl-std=CL2.0 -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 %s -triple x86_64-unknown-linux-gnu -O0 -cl-std=CL2.0 -emit-llvm -o - | FileCheck --check-prefix=CHECK-NOFAKE %s
+// When -ffake-address-space-map is not used, all addr space mapped to 0 for x86_64.
// test that we generate address space casts everywhere we need conversions of
// pointers to different address spaces
void test(global int *arg_glob, generic int *arg_gen) {
int var_priv;
arg_gen = arg_glob; // implicit cast global -> generic
// CHECK: %{{[0-9]+}} = addrspacecast i32 addrspace(1)* %{{[0-9]+}} to i32 addrspace(4)*
+ // CHECK-NOFAKE-NOT: addrspacecast
arg_gen = &var_priv; // implicit cast with obtaining adr, private -> generic
// CHECK: %{{[0-9]+}} = addrspacecast i32* %var_priv to i32 addrspace(4)*
+ // CHECK-NOFAKE-NOT: addrspacecast
+
arg_glob = (global int *)arg_gen; // explicit cast
// CHECK: %{{[0-9]+}} = addrspacecast i32 addrspace(4)* %{{[0-9]+}} to i32 addrspace(1)*
+ // CHECK-NOFAKE-NOT: addrspacecast
+
global int *var_glob =
(global int *)arg_glob; // explicit cast in the same address space
// CHECK-NOT: %{{[0-9]+}} = addrspacecast i32 addrspace(1)* %{{[0-9]+}} to i32 addrspace(1)*
+ // CHECK-NOFAKE-NOT: addrspacecast
+
var_priv = arg_gen - arg_glob; // arithmetic operation
// CHECK: %{{.*}} = ptrtoint i32 addrspace(4)* %{{.*}} to i64
// CHECK: %{{.*}} = ptrtoint i32 addrspace(1)* %{{.*}} to i64
+ // CHECK-NOFAKE: %{{.*}} = ptrtoint i32* %{{.*}} to i64
+ // CHECK-NOFAKE: %{{.*}} = ptrtoint i32* %{{.*}} to i64
+
var_priv = arg_gen > arg_glob; // comparison
// CHECK: %{{[0-9]+}} = addrspacecast i32 addrspace(1)* %{{[0-9]+}} to i32 addrspace(4)*
+
+ generic void *var_gen_v = arg_glob;
+ // CHECK: addrspacecast
+ // CHECK-NOT: bitcast
+ // CHECK-NOFAKE: bitcast
+ // CHECK-NOFAKE-NOT: addrspacecast
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18713.53439.patch
Type: text/x-patch
Size: 2977 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160412/1cb87c17/attachment.bin>
More information about the cfe-commits
mailing list