mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-23 01:24:30 +00:00
Make ConstantFoldConstantExpression recursively visit the entire
ConstantExpr, not just the top-level operator. This allows it to fold many more constants. Also, make GlobalOpt call ConstantFoldConstantExpression on GlobalVariable initializers. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@89659 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -1898,6 +1898,15 @@ bool GlobalOpt::OptimizeGlobalVars(Module &M) {
|
||||
// Global variables without names cannot be referenced outside this module.
|
||||
if (!GV->hasName() && !GV->isDeclaration())
|
||||
GV->setLinkage(GlobalValue::InternalLinkage);
|
||||
// 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);
|
||||
}
|
||||
// Do more involved optimizations if the global is internal.
|
||||
if (!GV->isConstant() && GV->hasLocalLinkage() &&
|
||||
GV->hasInitializer())
|
||||
Changed |= ProcessInternalGlobal(GV, GVI);
|
||||
|
Reference in New Issue
Block a user