aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDuncan Sands <baldrick@free.fr>2009-12-08 10:10:20 +0000
committerDuncan Sands <baldrick@free.fr>2009-12-08 10:10:20 +0000
commit7a154cf22830857bc184566102abd8a2ada8df94 (patch)
tree4e6b970eab49558cd0573695b5fd256f7a6d0103
parent34f849098bfb8850fa34fbd115ba9b2e55c85a32 (diff)
downloadexternal_llvm-7a154cf22830857bc184566102abd8a2ada8df94.zip
external_llvm-7a154cf22830857bc184566102abd8a2ada8df94.tar.gz
external_llvm-7a154cf22830857bc184566102abd8a2ada8df94.tar.bz2
Teach GlobalOpt to delete aliases with internal linkage (after
forwarding any uses). GlobalDCE can also do this, but is only run at -O3. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@90850 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Transforms/IPO/GlobalOpt.cpp41
-rw-r--r--test/Transforms/GlobalOpt/2009-02-15-ResolveAlias.ll14
2 files changed, 33 insertions, 22 deletions
diff --git a/lib/Transforms/IPO/GlobalOpt.cpp b/lib/Transforms/IPO/GlobalOpt.cpp
index 4635d0e..1793bbf 100644
--- a/lib/Transforms/IPO/GlobalOpt.cpp
+++ b/lib/Transforms/IPO/GlobalOpt.cpp
@@ -2493,29 +2493,28 @@ bool GlobalOpt::OptimizeGlobalAliases(Module &M) {
Changed = true;
}
- // If the aliasee has internal linkage, give it the name and linkage
- // of the alias, and delete the alias. This turns:
- // define internal ... @f(...)
- // @a = alias ... @f
- // into:
- // define ... @a(...)
- if (!Target->hasLocalLinkage())
- continue;
-
- // The transform is only useful if the alias does not have internal linkage.
- if (J->hasLocalLinkage())
- continue;
+ // If the alias is externally visible, we may still be able to simplify it.
+ if (!J->hasLocalLinkage()) {
+ // If the aliasee has internal linkage, give it the name and linkage
+ // of the alias, and delete the alias. This turns:
+ // define internal ... @f(...)
+ // @a = alias ... @f
+ // into:
+ // define ... @a(...)
+ if (!Target->hasLocalLinkage())
+ continue;
- // Do not perform the transform if multiple aliases potentially target the
- // aliasee. This check also ensures that it is safe to replace the section
- // and other attributes of the aliasee with those of the alias.
- if (!hasOneUse)
- continue;
+ // Do not perform the transform if multiple aliases potentially target the
+ // aliasee. This check also ensures that it is safe to replace the section
+ // and other attributes of the aliasee with those of the alias.
+ if (!hasOneUse)
+ continue;
- // Give the aliasee the name, linkage and other attributes of the alias.
- Target->takeName(J);
- Target->setLinkage(J->getLinkage());
- Target->GlobalValue::copyAttributesFrom(J);
+ // Give the aliasee the name, linkage and other attributes of the alias.
+ Target->takeName(J);
+ Target->setLinkage(J->getLinkage());
+ Target->GlobalValue::copyAttributesFrom(J);
+ }
// Delete the alias.
M.getAliasList().erase(J);
diff --git a/test/Transforms/GlobalOpt/2009-02-15-ResolveAlias.ll b/test/Transforms/GlobalOpt/2009-02-15-ResolveAlias.ll
index 5e639fd..a5be2b1 100644
--- a/test/Transforms/GlobalOpt/2009-02-15-ResolveAlias.ll
+++ b/test/Transforms/GlobalOpt/2009-02-15-ResolveAlias.ll
@@ -1,6 +1,8 @@
-; RUN: opt < %s -globalopt -S | grep {define void @a}
+; RUN: opt < %s -globalopt -S | FileCheck %s
define internal void @f() {
+; CHECK-NOT: @f
+; CHECK: define void @a
ret void
}
@@ -10,3 +12,13 @@ define void @g() {
call void()* @a()
ret void
}
+
+@b = alias internal void ()* @g
+; CHECK-NOT: @b
+
+define void @h() {
+ call void()* @b()
+; CHECK: call void @g
+ ret void
+}
+