llvm.org GIT mirror llvm / 0040725
Don't assume that external global variables are aligned at their preferred alignment. Only the minimum alignment guaranteed by the ABI may be assumed. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78668 91177308-0d34-0410-b5e6-96231b3b80d8 Dan Gohman 10 years ago
2 changed file(s) with 32 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
8080 // The address of an aligned GlobalValue has trailing zeros.
8181 if (GlobalValue *GV = dyn_cast(V)) {
8282 unsigned Align = GV->getAlignment();
83 if (Align == 0 && TD && GV->getType()->getElementType()->isSized())
84 Align = TD->getPrefTypeAlignment(GV->getType()->getElementType());
83 if (Align == 0 && TD && GV->getType()->getElementType()->isSized()) {
84 const Type *ObjectType = GV->getType()->getElementType();
85 // If the object is defined in the current Module, we'll be giving
86 // it the preferred alignment. Otherwise, we have to assume that it
87 // may only have the minimum ABI alignment.
88 if (!GV->isDeclaration() && !GV->mayBeOverridden())
89 Align = TD->getPrefTypeAlignment(ObjectType);
90 else
91 Align = TD->getABITypeAlignment(ObjectType);
92 }
8593 if (Align > 0)
8694 KnownZero = Mask & APInt::getLowBitsSet(BitWidth,
8795 CountTrailingZeros_32(Align));
0 ; RUN: llvm-as < %s | opt -instcombine | llvm-dis | FileCheck %s
1
2 ; Don't assume that external global variables have their preferred
3 ; alignment. They may only have the ABI minimum alignment.
4
5 ; CHECK: %s = shl i64 %a, 3
6 ; CHECK: %r = or i64 %s, ptrtoint (i32* @A to i64)
7 ; CHECK: %q = add i64 %r, 1
8 ; CHECK: ret i64 %q
9
10 target datalayout = "-i32:8:32"
11
12 @A = external global i32
13 @B = external global i32
14
15 define i64 @foo(i64 %a) {
16 %t = ptrtoint i32* @A to i64
17 %s = shl i64 %a, 3
18 %r = or i64 %t, %s
19 %q = add i64 %r, 1
20 ret i64 %q
21 }