[PATCH] D76789: [AMDGPU] Preserve original symbol during attribute propagation

Stanislav Mekhanoshin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 25 11:21:20 PDT 2020


rampitec created this revision.
rampitec added a reviewer: arsenm.
Herald added subscribers: kerbowa, hiraditya, t-tye, tpr, dstuttard, yaxunl, nhaehnle, wdng, jvesely, kzhuravl.

AMDGPUPropagateAttributes can swap names while cloning a function.
Only do it if original symbol was not externally visible.


https://reviews.llvm.org/D76789

Files:
  llvm/lib/Target/AMDGPU/AMDGPUPropagateAttributes.cpp
  llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
  llvm/test/CodeGen/AMDGPU/propagate-attributes-clone.ll


Index: llvm/test/CodeGen/AMDGPU/propagate-attributes-clone.ll
===================================================================
--- llvm/test/CodeGen/AMDGPU/propagate-attributes-clone.ll
+++ llvm/test/CodeGen/AMDGPU/propagate-attributes-clone.ll
@@ -1,15 +1,21 @@
-; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -O1 < %s | FileCheck -check-prefix=OPT %s
+; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -O1 < %s | FileCheck -check-prefix=OPT-EXT %s
+; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -O1 --amdgpu-internalize-symbols < %s | FileCheck -check-prefix=OPT-INT %s
 ; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx1010 -verify-machineinstrs < %s | FileCheck -check-prefix=LLC %s
 
 ; OPT: declare void @foo4() local_unnamed_addr #0
-; OPT: define internal fastcc void @foo3.2() unnamed_addr #1
-; OPT: define void @foo2() local_unnamed_addr #1
-; OPT: define internal fastcc void @foo1.1() unnamed_addr #1
+; OPT-EXT: define void @foo3() local_unnamed_addr #1
+; OPT-INT: define internal fastcc void @foo3.2() unnamed_addr #1
+; OPT-EXT: define void @foo2() local_unnamed_addr #1
+; OPT-INT: define internal fastcc void @foo2() unnamed_addr #1
+; OPT-EXT: define void @foo1() local_unnamed_addr #1
+; OPT-INT: define internal fastcc void @foo1.1() unnamed_addr #1
 ; OPT: define amdgpu_kernel void @kernel1() local_unnamed_addr #2
 ; OPT: define amdgpu_kernel void @kernel2() local_unnamed_addr #3
 ; OPT: define amdgpu_kernel void @kernel3() local_unnamed_addr #3
-; OPT: define void @foo1() local_unnamed_addr #4
-; OPT: define void @foo3() local_unnamed_addr #4
+; OPT-EXT: define internal fastcc void @foo1.1() unnamed_addr #4
+; OPT-INT: define internal fastcc void @foo1() unnamed_addr #4
+; OPT-EXT: define internal fastcc void @foo3.2() unnamed_addr #4
+; OPT-INT: define internal fastcc void @foo3() unnamed_addr #4
 ; OPT: attributes #0 = { {{.*}} "target-features"="+wavefrontsize64" }
 ; OPT: attributes #1 = { {{.*}} "target-features"="{{.*}},-wavefrontsize16,-wavefrontsize32,+wavefrontsize64{{.*}}" }
 ; OPT: attributes #2 = { {{.*}} "target-features"="+wavefrontsize32" }
Index: llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
===================================================================
--- llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
+++ llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
@@ -437,11 +437,11 @@
       }
       PM.add(createAMDGPUUnifyMetadataPass());
       PM.add(createAMDGPUPrintfRuntimeBinding());
-      PM.add(createAMDGPUPropagateAttributesLatePass(this));
-      if (Internalize) {
+      if (Internalize)
         PM.add(createInternalizePass(mustPreserveGV));
+      PM.add(createAMDGPUPropagateAttributesLatePass(this));
+      if (Internalize)
         PM.add(createGlobalDCEPass());
-      }
       if (EarlyInline)
         PM.add(createAMDGPUAlwaysInlinePass(false));
   });
Index: llvm/lib/Target/AMDGPU/AMDGPUPropagateAttributes.cpp
===================================================================
--- llvm/lib/Target/AMDGPU/AMDGPUPropagateAttributes.cpp
+++ llvm/lib/Target/AMDGPU/AMDGPUPropagateAttributes.cpp
@@ -269,17 +269,15 @@
   ValueToValueMapTy dummy;
   Function *NewF = CloneFunction(&F, dummy);
   setFeatures(*NewF, NewFeatures);
+  NewF->setVisibility(GlobalValue::DefaultVisibility);
+  NewF->setLinkage(GlobalValue::InternalLinkage);
 
   // Swap names. If that is the only clone it will retain the name of now
-  // dead value.
-  if (F.hasName()) {
+  // dead value. Preserve original name for externally visible functions.
+  if (F.hasName() && F.hasLocalLinkage()) {
     std::string NewName = std::string(NewF->getName());
     NewF->takeName(&F);
     F.setName(NewName);
-
-    // Name has changed, it does not need an external symbol.
-    F.setVisibility(GlobalValue::DefaultVisibility);
-    F.setLinkage(GlobalValue::InternalLinkage);
   }
 
   return NewF;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D76789.252629.patch
Type: text/x-patch
Size: 3835 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200325/d85d6517/attachment-0001.bin>


More information about the llvm-commits mailing list