[llvm-commits] [llvm] r50256 - /llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp
Nate Begeman
natebegeman at mac.com
Thu Apr 24 23:37:06 PDT 2008
Author: sampo
Date: Fri Apr 25 01:37:06 2008
New Revision: 50256
URL: http://llvm.org/viewvc/llvm-project?rev=50256&view=rev
Log:
Teach the PruningFunctionCloner how to look through loads with
ConstantExpression GEPs pointing into constant globals.
Modified:
llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp
Modified: llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp?rev=50256&r1=50255&r2=50256&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp Fri Apr 25 01:37:06 2008
@@ -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 @@
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,
More information about the llvm-commits
mailing list