[llvm] r208103 - Special case aliases in GlobalValue::getAlignment.
Rafael Espindola
rafael.espindola at gmail.com
Tue May 6 09:48:59 PDT 2014
Author: rafael
Date: Tue May 6 11:48:58 2014
New Revision: 208103
URL: http://llvm.org/viewvc/llvm-project?rev=208103&view=rev
Log:
Special case aliases in GlobalValue::getAlignment.
An alias has the address of what it points to, so it also has the same
alignment.
This allows a few optimizations to see past aliases for free.
Modified:
llvm/trunk/include/llvm/IR/GlobalValue.h
llvm/trunk/lib/IR/Globals.cpp
llvm/trunk/lib/IR/Verifier.cpp
llvm/trunk/test/CodeGen/AArch64/global-alignment.ll
Modified: llvm/trunk/include/llvm/IR/GlobalValue.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/GlobalValue.h?rev=208103&r1=208102&r2=208103&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/GlobalValue.h (original)
+++ llvm/trunk/include/llvm/IR/GlobalValue.h Tue May 6 11:48:58 2014
@@ -81,9 +81,7 @@ public:
removeDeadConstantUsers(); // remove any dead constants using this.
}
- unsigned getAlignment() const {
- return (1u << Alignment) >> 1;
- }
+ unsigned getAlignment() const;
void setAlignment(unsigned Align);
bool hasUnnamedAddr() const { return UnnamedAddr; }
Modified: llvm/trunk/lib/IR/Globals.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Globals.cpp?rev=208103&r1=208102&r2=208103&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Globals.cpp (original)
+++ llvm/trunk/lib/IR/Globals.cpp Tue May 6 11:48:58 2014
@@ -63,6 +63,13 @@ void GlobalValue::copyAttributesFrom(con
setDLLStorageClass(Src->getDLLStorageClass());
}
+unsigned GlobalValue::getAlignment() const {
+ if (auto *GA = dyn_cast<GlobalAlias>(this))
+ return GA->getAliasedGlobal()->getAlignment();
+
+ return (1u << Alignment) >> 1;
+}
+
void GlobalValue::setAlignment(unsigned Align) {
assert((!isa<GlobalAlias>(this)) &&
"GlobalAlias should not have an alignment!");
Modified: llvm/trunk/lib/IR/Verifier.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Verifier.cpp?rev=208103&r1=208102&r2=208103&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Verifier.cpp (original)
+++ llvm/trunk/lib/IR/Verifier.cpp Tue May 6 11:48:58 2014
@@ -477,7 +477,6 @@ void Verifier::visitGlobalAlias(const Gl
"Alias and aliasee types should match!", &GA);
Assert1(!GA.hasUnnamedAddr(), "Alias cannot have unnamed_addr!", &GA);
Assert1(!GA.hasSection(), "Alias cannot have a section!", &GA);
- Assert1(!GA.getAlignment(), "Alias connot have an alignment", &GA);
const Constant *Aliasee = GA.getAliasee();
const GlobalValue *GV = dyn_cast<GlobalValue>(Aliasee);
Modified: llvm/trunk/test/CodeGen/AArch64/global-alignment.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AArch64/global-alignment.ll?rev=208103&r1=208102&r2=208103&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/AArch64/global-alignment.ll (original)
+++ llvm/trunk/test/CodeGen/AArch64/global-alignment.ll Tue May 6 11:48:58 2014
@@ -4,6 +4,7 @@
@var32 = global [3 x i32] zeroinitializer
@var64 = global [3 x i64] zeroinitializer
@var32_align64 = global [3 x i32] zeroinitializer, align 8
+ at alias = alias [3 x i32]* @var32_align64
define i64 @test_align32() {
; CHECK-LABEL: test_align32:
@@ -46,6 +47,19 @@ define i64 @test_var32_align64() {
ret i64 %val
}
+
+define i64 @test_var32_alias() {
+; CHECK-LABEL: test_var32_alias:
+ %addr = bitcast [3 x i32]* @alias to i64*
+
+ ; Test that we can find the alignment for aliases.
+ %val = load i64* %addr
+; CHECK: adrp x[[HIBITS:[0-9]+]], alias
+; CHECK-NOT: add x[[HIBITS]]
+; CHECK: ldr x0, [x[[HIBITS]], {{#?}}:lo12:alias]
+
+ ret i64 %val
+}
@yet_another_var = external global {i32, i32}
More information about the llvm-commits
mailing list