forked from OSchip/llvm-project
Make globalopt refine global variable alignment.
llvm-svn: 100160
This commit is contained in:
parent
cdf40bed1b
commit
c671347fcb
|
@ -1880,6 +1880,7 @@ bool GlobalOpt::OptimizeFunctions(Module &M) {
|
|||
|
||||
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++;
|
||||
|
@ -1889,11 +1890,16 @@ bool GlobalOpt::OptimizeGlobalVars(Module &M) {
|
|||
// 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())
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
; 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 ]
|
Loading…
Reference in New Issue