[llvm-commits] [llvm] r90850 - in /llvm/trunk: lib/Transforms/IPO/GlobalOpt.cpp test/Transforms/GlobalOpt/2009-02-15-ResolveAlias.ll
Duncan Sands
baldrick at free.fr
Tue Dec 8 02:10:21 PST 2009
Author: baldrick
Date: Tue Dec 8 04:10:20 2009
New Revision: 90850
URL: http://llvm.org/viewvc/llvm-project?rev=90850&view=rev
Log:
Teach GlobalOpt to delete aliases with internal linkage (after
forwarding any uses). GlobalDCE can also do this, but is only
run at -O3.
Modified:
llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp
llvm/trunk/test/Transforms/GlobalOpt/2009-02-15-ResolveAlias.ll
Modified: llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp?rev=90850&r1=90849&r2=90850&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp Tue Dec 8 04:10:20 2009
@@ -2493,29 +2493,28 @@
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;
-
- // 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);
+ // 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;
+
+ // 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);
Modified: llvm/trunk/test/Transforms/GlobalOpt/2009-02-15-ResolveAlias.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GlobalOpt/2009-02-15-ResolveAlias.ll?rev=90850&r1=90849&r2=90850&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/GlobalOpt/2009-02-15-ResolveAlias.ll (original)
+++ llvm/trunk/test/Transforms/GlobalOpt/2009-02-15-ResolveAlias.ll Tue Dec 8 04:10:20 2009
@@ -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 @@
call void()* @a()
ret void
}
+
+ at b = alias internal void ()* @g
+; CHECK-NOT: @b
+
+define void @h() {
+ call void()* @b()
+; CHECK: call void @g
+ ret void
+}
+
More information about the llvm-commits
mailing list