aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2005-09-26 05:34:07 +0000
committerChris Lattner <sabre@nondot.org>2005-09-26 05:34:07 +0000
commit0b142e39209677daa4e62cf0dbe6bae07d30e0f3 (patch)
tree2272e60169d8ef16f75a8302b9fe93a0143c6b38 /lib
parentebe61201d182123b699241e31d5123206836515c (diff)
Replace TraverseGEPInitializer with ConstantFoldLoadThroughGEPConstantExpr
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23447 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Transforms/IPO/GlobalOpt.cpp22
1 files changed, 5 insertions, 17 deletions
diff --git a/lib/Transforms/IPO/GlobalOpt.cpp b/lib/Transforms/IPO/GlobalOpt.cpp
index 09e4928a1f..4e081dd205 100644
--- a/lib/Transforms/IPO/GlobalOpt.cpp
+++ b/lib/Transforms/IPO/GlobalOpt.cpp
@@ -297,21 +297,6 @@ static Constant *getAggregateConstantElement(Constant *Agg, Constant *Idx) {
return 0;
}
-static Constant *TraverseGEPInitializer(User *GEP, Constant *Init) {
- if (Init == 0) return 0;
- if (GEP->getNumOperands() == 1 ||
- !isa<Constant>(GEP->getOperand(1)) ||
- !cast<Constant>(GEP->getOperand(1))->isNullValue())
- return 0;
-
- for (unsigned i = 2, e = GEP->getNumOperands(); i != e; ++i) {
- ConstantInt *Idx = dyn_cast<ConstantInt>(GEP->getOperand(i));
- if (!Idx) return 0;
- Init = getAggregateConstantElement(Init, Idx);
- if (Init == 0) return 0;
- }
- return Init;
-}
/// CleanupConstantGlobalUsers - We just marked GV constant. Loop over all
/// users of the global, cleaning up the obvious ones. This is largely just a
@@ -335,7 +320,7 @@ static bool CleanupConstantGlobalUsers(Value *V, Constant *Init) {
Changed = true;
} else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(U)) {
if (CE->getOpcode() == Instruction::GetElementPtr) {
- Constant *SubInit = TraverseGEPInitializer(CE, Init);
+ Constant *SubInit = ConstantFoldLoadThroughGEPConstantExpr(Init, CE);
Changed |= CleanupConstantGlobalUsers(CE, SubInit);
} else if (CE->getOpcode() == Instruction::Cast &&
isa<PointerType>(CE->getType())) {
@@ -348,7 +333,10 @@ static bool CleanupConstantGlobalUsers(Value *V, Constant *Init) {
Changed = true;
}
} else if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(U)) {
- Constant *SubInit = TraverseGEPInitializer(GEP, Init);
+ Constant *SubInit = 0;
+ ConstantExpr *CE = dyn_cast<ConstantExpr>(ConstantFoldInstruction(GEP));
+ if (CE && CE->getOpcode() == Instruction::GetElementPtr)
+ SubInit = ConstantFoldLoadThroughGEPConstantExpr(Init, CE);
Changed |= CleanupConstantGlobalUsers(GEP, SubInit);
if (GEP->use_empty()) {