r227861 - When generating llvm.used, we may need an addrspacecast instead of a bitcast.

Justin Holewinski jholewinski at nvidia.com
Mon Feb 2 13:05:49 PST 2015


Author: jholewinski
Date: Mon Feb  2 15:05:49 2015
New Revision: 227861

URL: http://llvm.org/viewvc/llvm-project?rev=227861&view=rev
Log:
When generating llvm.used, we may need an addrspacecast instead of a bitcast.

Summary:
This is especially important for targets that use multiple address spaces,
and commonly place global variables in address spaces other than zero.

Fixes PR22383

Test Plan: New test case added: llvm-used.cu

Reviewers: jingyue

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D7345

Added:
    cfe/trunk/test/CodeGenCUDA/llvm-used.cu
Modified:
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=227861&r1=227860&r2=227861&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Mon Feb  2 15:05:49 2015
@@ -935,8 +935,8 @@ static void emitUsed(CodeGenModule &CGM,
   UsedArray.resize(List.size());
   for (unsigned i = 0, e = List.size(); i != e; ++i) {
     UsedArray[i] =
-     llvm::ConstantExpr::getBitCast(cast<llvm::Constant>(&*List[i]),
-                                    CGM.Int8PtrTy);
+        llvm::ConstantExpr::getPointerBitCastOrAddrSpaceCast(
+            cast<llvm::Constant>(&*List[i]), CGM.Int8PtrTy);
   }
 
   if (UsedArray.empty())

Added: cfe/trunk/test/CodeGenCUDA/llvm-used.cu
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCUDA/llvm-used.cu?rev=227861&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCUDA/llvm-used.cu (added)
+++ cfe/trunk/test/CodeGenCUDA/llvm-used.cu Mon Feb  2 15:05:49 2015
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -emit-llvm %s -o - -fcuda-is-device -triple nvptx64-unknown-unknown | FileCheck %s
+
+
+// Make sure we emit the proper addrspacecast for llvm.used.  PR22383 exposed an
+// issue where we were generating a bitcast instead of an addrspacecast.
+
+// CHECK: @llvm.used = appending global [1 x i8*] [i8* addrspacecast (i8 addrspace(1)* bitcast ([0 x i32] addrspace(1)* @a to i8 addrspace(1)*) to i8*)], section "llvm.metadata"
+__attribute__((device)) __attribute__((__used__)) int a[] = {};





More information about the cfe-commits mailing list