[llvm] 6e00e3f - [AMDGPU] Preserve original symbol during attribute propagation
Stanislav Mekhanoshin via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 25 15:26:44 PDT 2020
Author: Stanislav Mekhanoshin
Date: 2020-03-25T15:26:30-07:00
New Revision: 6e00e3fcb082c3f19309ebc6f184ab326eec3328
URL: https://github.com/llvm/llvm-project/commit/6e00e3fcb082c3f19309ebc6f184ab326eec3328
DIFF: https://github.com/llvm/llvm-project/commit/6e00e3fcb082c3f19309ebc6f184ab326eec3328.diff
LOG: [AMDGPU] Preserve original symbol during attribute propagation
AMDGPUPropagateAttributes can swap names while cloning a function.
Only do it if original symbol was not externally visible.
Differential Revision: https://reviews.llvm.org/D76789
Added:
Modified:
llvm/lib/Target/AMDGPU/AMDGPUPropagateAttributes.cpp
llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
llvm/test/CodeGen/AMDGPU/propagate-attributes-clone.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUPropagateAttributes.cpp b/llvm/lib/Target/AMDGPU/AMDGPUPropagateAttributes.cpp
index 68fa5bafa97b..154a4eae8ce2 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUPropagateAttributes.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUPropagateAttributes.cpp
@@ -269,17 +269,15 @@ AMDGPUPropagateAttributes::cloneWithFeatures(Function &F,
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;
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
index f4cdfea877d3..86cfe6a11010 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
@@ -437,11 +437,11 @@ void AMDGPUTargetMachine::adjustPassManager(PassManagerBuilder &Builder) {
}
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));
});
diff --git a/llvm/test/CodeGen/AMDGPU/propagate-attributes-clone.ll b/llvm/test/CodeGen/AMDGPU/propagate-attributes-clone.ll
index cb0406c5b1f8..b55a87de4be2 100644
--- a/llvm/test/CodeGen/AMDGPU/propagate-attributes-clone.ll
+++ b/llvm/test/CodeGen/AMDGPU/propagate-attributes-clone.ll
@@ -1,15 +1,23 @@
-; 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-prefixes=OPT,OPT-EXT %s
+; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -O1 --amdgpu-internalize-symbols < %s | FileCheck -check-prefixes=OPT,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: define internal fastcc void @0() 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: define internal fastcc void @1() 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" }
@@ -29,6 +37,8 @@
; LLC: foo2 at gotpcrel32@hi+4
; LLC: foo1 at gotpcrel32@lo+4
; LLC: foo1 at gotpcrel32@hi+4
+; LLC: __unnamed_1 at gotpcrel32@lo+4
+; LLC: __unnamed_1 at gotpcrel32@hi+4
; LLC: kernel1:
; LLC: foo1 at gotpcrel32@lo+4
; LLC: foo1 at gotpcrel32@hi+4
@@ -41,6 +51,12 @@
declare void @foo4() #1
+define void @0() #1 {
+entry:
+ call void asm sideeffect "; sample asm", ""()
+ ret void
+}
+
define void @foo3() #1 {
entry:
call void asm sideeffect "; sample asm", ""()
@@ -60,6 +76,7 @@ entry:
tail call void @foo2()
tail call void @foo2()
tail call void @foo1()
+ tail call void @0()
ret void
}
More information about the llvm-commits
mailing list