diff options
-rw-r--r-- | include/llvm/IR/GlobalValue.h | 4 | ||||
-rw-r--r-- | lib/IR/Globals.cpp | 7 | ||||
-rw-r--r-- | lib/IR/Verifier.cpp | 1 | ||||
-rw-r--r-- | test/CodeGen/AArch64/global-alignment.ll | 14 |
4 files changed, 22 insertions, 4 deletions
diff --git a/include/llvm/IR/GlobalValue.h b/include/llvm/IR/GlobalValue.h index 7c4dd0796c..5d0e3791e8 100644 --- a/include/llvm/IR/GlobalValue.h +++ b/include/llvm/IR/GlobalValue.h @@ -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; } diff --git a/lib/IR/Globals.cpp b/lib/IR/Globals.cpp index 76baa6202a..2265e4c2b7 100644 --- a/lib/IR/Globals.cpp +++ b/lib/IR/Globals.cpp @@ -63,6 +63,13 @@ void GlobalValue::copyAttributesFrom(const GlobalValue *Src) { 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!"); diff --git a/lib/IR/Verifier.cpp b/lib/IR/Verifier.cpp index 0bc5c509eb..bc378aed16 100644 --- a/lib/IR/Verifier.cpp +++ b/lib/IR/Verifier.cpp @@ -477,7 +477,6 @@ void Verifier::visitGlobalAlias(const GlobalAlias &GA) { "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); diff --git a/test/CodeGen/AArch64/global-alignment.ll b/test/CodeGen/AArch64/global-alignment.ll index 24e6618e98..36b74e5a57 100644 --- a/test/CodeGen/AArch64/global-alignment.ll +++ b/test/CodeGen/AArch64/global-alignment.ll @@ -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 +@alias = alias [3 x i32]* @var32_align64 define i64 @test_align32() { ; CHECK-LABEL: test_align32: @@ -47,6 +48,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} define i64 @test_yet_another_var() { |