diff options
| author | Chris Lattner <sabre@nondot.org> | 2005-09-26 05:34:07 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2005-09-26 05:34:07 +0000 |
| commit | 61ff32cd704632ad2c06cda032e58bf49395f313 (patch) | |
| tree | de7bfd3a5eeeaff0cd307d23c5e414625346b182 /llvm/lib/Transforms | |
| parent | 02ae21e1e0d5a2a6571005a0b593df41192f6837 (diff) | |
| download | bcm5719-llvm-61ff32cd704632ad2c06cda032e58bf49395f313.tar.gz bcm5719-llvm-61ff32cd704632ad2c06cda032e58bf49395f313.zip | |
Replace TraverseGEPInitializer with ConstantFoldLoadThroughGEPConstantExpr
llvm-svn: 23447
Diffstat (limited to 'llvm/lib/Transforms')
| -rw-r--r-- | llvm/lib/Transforms/IPO/GlobalOpt.cpp | 22 |
1 files changed, 5 insertions, 17 deletions
diff --git a/llvm/lib/Transforms/IPO/GlobalOpt.cpp b/llvm/lib/Transforms/IPO/GlobalOpt.cpp index 09e4928a1f9..4e081dd2057 100644 --- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp +++ b/llvm/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()) { |

