[PATCH] D18713: [OpenCL] Generate bitcast when target address space does not change.
Yaxun Liu via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 6 08:08:47 PDT 2016
yaxunl updated the summary for this revision.
yaxunl updated this revision to Diff 52800.
yaxunl added a comment.
Add more checks for w/o -ffake-address-space-map to the test.
http://reviews.llvm.org/D18713
Files:
lib/CodeGen/CGExprScalar.cpp
test/CodeGenOpenCL/address-spaces-conversions.cl
Index: test/CodeGenOpenCL/address-spaces-conversions.cl
===================================================================
--- test/CodeGenOpenCL/address-spaces-conversions.cl
+++ test/CodeGenOpenCL/address-spaces-conversions.cl
@@ -1,4 +1,6 @@
// 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
@@ -7,16 +9,33 @@
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
}
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.52800.patch
Type: text/x-patch
Size: 2874 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160406/7ef5e346/attachment.bin>
More information about the cfe-commits
mailing list