[llvm] d4a8e97 - Revert "[NVPTX] Use .common linkage for common globals (#84416)"

Sterling Augustine via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 15 14:28:11 PDT 2024


Author: Sterling Augustine
Date: 2024-03-15T21:27:46Z
New Revision: d4a8e979e4bd6c282e2b3645353f84a189bb4a9a

URL: https://github.com/llvm/llvm-project/commit/d4a8e979e4bd6c282e2b3645353f84a189bb4a9a
DIFF: https://github.com/llvm/llvm-project/commit/d4a8e979e4bd6c282e2b3645353f84a189bb4a9a.diff

LOG: Revert "[NVPTX] Use .common linkage for common globals (#84416)"

This reverts commit 8f0012d3dc2ae6d40e9f812cae111ca7a6eb2a2d.

The common-linkage.ll test fails with ptxas enabled.

Added: 
    

Modified: 
    llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
    llvm/test/CodeGen/NVPTX/weak-global.ll

Removed: 
    llvm/test/CodeGen/NVPTX/common-linkage.ll


################################################################################
diff  --git a/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp b/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
index a6df4b32fbb6e8..2219d9f6619aaf 100644
--- a/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
+++ b/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
@@ -1019,6 +1019,7 @@ void NVPTXAsmPrinter::printModuleLevelGV(const GlobalVariable *GVar,
   const DataLayout &DL = getDataLayout();
 
   // GlobalVariables are always constant pointers themselves.
+  PointerType *PTy = GVar->getType();
   Type *ETy = GVar->getValueType();
 
   if (GVar->hasExternalLinkage()) {
@@ -1026,9 +1027,6 @@ void NVPTXAsmPrinter::printModuleLevelGV(const GlobalVariable *GVar,
       O << ".visible ";
     else
       O << ".extern ";
-  } else if (GVar->hasCommonLinkage() &&
-             GVar->getAddressSpace() == ADDRESS_SPACE_GLOBAL) {
-    O << ".common ";
   } else if (GVar->hasLinkOnceLinkage() || GVar->hasWeakLinkage() ||
              GVar->hasAvailableExternallyLinkage() ||
              GVar->hasCommonLinkage()) {
@@ -1140,7 +1138,7 @@ void NVPTXAsmPrinter::printModuleLevelGV(const GlobalVariable *GVar,
   }
 
   O << ".";
-  emitPTXAddressSpace(GVar->getAddressSpace(), O);
+  emitPTXAddressSpace(PTy->getAddressSpace(), O);
 
   if (isManaged(*GVar)) {
     if (STI.getPTXVersion() < 40 || STI.getSmVersion() < 30) {
@@ -1169,8 +1167,8 @@ void NVPTXAsmPrinter::printModuleLevelGV(const GlobalVariable *GVar,
     // Ptx allows variable initilization only for constant and global state
     // spaces.
     if (GVar->hasInitializer()) {
-      if ((GVar->getAddressSpace() == ADDRESS_SPACE_GLOBAL) ||
-          (GVar->getAddressSpace() == ADDRESS_SPACE_CONST)) {
+      if ((PTy->getAddressSpace() == ADDRESS_SPACE_GLOBAL) ||
+          (PTy->getAddressSpace() == ADDRESS_SPACE_CONST)) {
         const Constant *Initializer = GVar->getInitializer();
         // 'undef' is treated as there is no value specified.
         if (!Initializer->isNullValue() && !isa<UndefValue>(Initializer)) {
@@ -1185,7 +1183,7 @@ void NVPTXAsmPrinter::printModuleLevelGV(const GlobalVariable *GVar,
             !isa<UndefValue>(GVar->getInitializer())) {
           report_fatal_error("initial value of '" + GVar->getName() +
                              "' is not allowed in addrspace(" +
-                             Twine(GVar->getAddressSpace()) + ")");
+                             Twine(PTy->getAddressSpace()) + ")");
         }
       }
     }
@@ -1204,8 +1202,8 @@ void NVPTXAsmPrinter::printModuleLevelGV(const GlobalVariable *GVar,
       ElementSize = DL.getTypeStoreSize(ETy);
       // Ptx allows variable initilization only for constant and
       // global state spaces.
-      if (((GVar->getAddressSpace() == ADDRESS_SPACE_GLOBAL) ||
-           (GVar->getAddressSpace() == ADDRESS_SPACE_CONST)) &&
+      if (((PTy->getAddressSpace() == ADDRESS_SPACE_GLOBAL) ||
+           (PTy->getAddressSpace() == ADDRESS_SPACE_CONST)) &&
           GVar->hasInitializer()) {
         const Constant *Initializer = GVar->getInitializer();
         if (!isa<UndefValue>(Initializer) && !Initializer->isNullValue()) {

diff  --git a/llvm/test/CodeGen/NVPTX/common-linkage.ll b/llvm/test/CodeGen/NVPTX/common-linkage.ll
deleted file mode 100644
index ac16d9a6d7c763..00000000000000
--- a/llvm/test/CodeGen/NVPTX/common-linkage.ll
+++ /dev/null
@@ -1,26 +0,0 @@
-; RUN: llc < %s -march=nvptx -mcpu=sm_20 | FileCheck %s
-; RUN: %if ptxas %{ llc < %s -march=nvptx64 -mcpu=sm_20 | %ptxas-verify %}
-
-; CHECK: .common .global .align 4 .u32 g
- at g = common addrspace(1) global i32 0, align 4
-
-; CHECK: .weak .const .align 4 .u32 c
- at c = common addrspace(4) global i32 0, align 4
-
-; CHECK: .weak .shared .align 4 .u32 s
- at s = common addrspace(3) global i32 0, align 4
-
-define i32 @f1() {
-  %1 = load i32, ptr addrspace(1) @g
-  ret i32 %1
-}
-
-define i32 @f4() {
-  %1 = load i32, ptr addrspace(4) @c
-  ret i32 %1
-}
-
-define i32 @f3() {
-  %1 = load i32, ptr addrspace(3) @s
-  ret i32 %1
-}

diff  --git a/llvm/test/CodeGen/NVPTX/weak-global.ll b/llvm/test/CodeGen/NVPTX/weak-global.ll
index 781ecb9b149567..dd0160d1c0a654 100644
--- a/llvm/test/CodeGen/NVPTX/weak-global.ll
+++ b/llvm/test/CodeGen/NVPTX/weak-global.ll
@@ -1,7 +1,7 @@
 ; RUN: llc < %s -march=nvptx64 -mcpu=sm_20 | FileCheck %s
 ; RUN: %if ptxas %{ llc < %s -march=nvptx64 -mcpu=sm_20 | %ptxas-verify %}
 
-; CHECK: .common .global .align 4 .u32 g
+; CHECK: .weak .global .align 4 .u32 g
 @g = common addrspace(1) global i32 zeroinitializer
 
 define i32 @func0() {


        


More information about the llvm-commits mailing list