diff options
author | Nate Begeman <natebegeman@mac.com> | 2008-04-25 06:37:06 +0000 |
---|---|---|
committer | Nate Begeman <natebegeman@mac.com> | 2008-04-25 06:37:06 +0000 |
commit | c368b5b8837742f0deb68664e2701162b166d67b (patch) | |
tree | 28886b668d212c25cd64398907e3bd8dfa4b7cf9 /lib | |
parent | cfbb27280a8218c8d7984a16b2a6792a4a24d52b (diff) | |
download | external_llvm-c368b5b8837742f0deb68664e2701162b166d67b.zip external_llvm-c368b5b8837742f0deb68664e2701162b166d67b.tar.gz external_llvm-c368b5b8837742f0deb68664e2701162b166d67b.tar.bz2 |
Teach the PruningFunctionCloner how to look through loads with
ConstantExpression GEPs pointing into constant globals.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@50256 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Transforms/Utils/CloneFunction.cpp | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/lib/Transforms/Utils/CloneFunction.cpp b/lib/Transforms/Utils/CloneFunction.cpp index ba9b57d..ca63399 100644 --- a/lib/Transforms/Utils/CloneFunction.cpp +++ b/lib/Transforms/Utils/CloneFunction.cpp @@ -17,6 +17,7 @@ #include "llvm/Constants.h" #include "llvm/DerivedTypes.h" #include "llvm/Instructions.h" +#include "llvm/GlobalVariable.h" #include "llvm/Function.h" #include "llvm/Support/CFG.h" #include "llvm/Support/Compiler.h" @@ -308,13 +309,20 @@ ConstantFoldMappedInstruction(const Instruction *I) { else return 0; // All operands not constant! - if (const CmpInst *CI = dyn_cast<CmpInst>(I)) return ConstantFoldCompareInstOperands(CI->getPredicate(), &Ops[0], Ops.size(), TD); - else - return ConstantFoldInstOperands(I->getOpcode(), I->getType(), - &Ops[0], Ops.size(), TD); + + if (ConstantExpr *CE = dyn_cast<ConstantExpr>(Ops[0])) + if (const LoadInst *LI = dyn_cast<LoadInst>(I)) + if (!LI->isVolatile() && CE->getOpcode() == Instruction::GetElementPtr) + if (GlobalVariable *GV = dyn_cast<GlobalVariable>(CE->getOperand(0))) + if (GV->isConstant() && !GV->isDeclaration()) + return ConstantFoldLoadThroughGEPConstantExpr(GV->getInitializer(), + CE); + + return ConstantFoldInstOperands(I->getOpcode(), I->getType(), &Ops[0], + Ops.size(), TD); } /// CloneAndPruneFunctionInto - This works exactly like CloneFunctionInto, |