in particular, they end up aligning strings at 16-byte boundaries, and
there's no way for GlobalOpt to check OptForSize.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@100172
91177308-0d34-0410-b5e6-
96231b3b80d8
if (Alignment < 16) {
// If the global is not external, see if it is large. If so, give it a
// larger alignment.
- if (getTypeSizeInBits(ElemType) >= 128)
+ if (getTypeSizeInBits(ElemType) > 128)
Alignment = 16; // 16-byte alignment.
}
}
bool GlobalOpt::OptimizeGlobalVars(Module &M) {
bool Changed = false;
- TargetData *TD = getAnalysisIfAvailable<TargetData>();
for (Module::global_iterator GVI = M.global_begin(), E = M.global_end();
GVI != E; ) {
GlobalVariable *GV = GVI++;
// Simplify the initializer.
if (GV->hasInitializer())
if (ConstantExpr *CE = dyn_cast<ConstantExpr>(GV->getInitializer())) {
+ TargetData *TD = getAnalysisIfAvailable<TargetData>();
Constant *New = ConstantFoldConstantExpression(CE, TD);
if (New && New != CE)
GV->setInitializer(New);
}
- // Refine the alignment value.
- if (TD && GV->hasDefinitiveInitializer()) {
- unsigned Align = TD->getPreferredAlignment(GV);
- if (Align > GV->getAlignment())
- GV->setAlignment(Align);
- }
// Do more involved optimizations if the global is internal.
if (!GV->isConstant() && GV->hasLocalLinkage() &&
GV->hasInitializer())
; DARWIN: .globl _G9
; DARWIN: _G9:
-; LINUX: .section .rodata.str4.16,"aMS",@progbits,4
+; LINUX: .section .rodata.str4.4,"aMS",@progbits,4
; LINUX: .globl G9
; LINUX:G9
; RUN: grep movups %t | count 2
target triple = "i686-apple-darwin"
-@x = external global [4 x i32]
+@x = global [4 x i32] [ i32 1, i32 2, i32 3, i32 4 ] ; <[4 x i32]*> [#uses=4]
define <2 x i64> @test1() {
%tmp = load i32* getelementptr ([4 x i32]* @x, i32 0, i32 0) ; <i32> [#uses=1]
+++ /dev/null
-; RUN: opt -globalopt -S < %s | grep {, align 16}
-
-; Globalopt should refine the alignment for global variables.
-
-target datalayout = "e-p:64:64:64"
-@a = global [4 x i32] [i32 2, i32 3, i32 4, i32 5 ]