diff options
author | Duncan Sands <baldrick@free.fr> | 2008-10-01 15:25:41 +0000 |
---|---|---|
committer | Duncan Sands <baldrick@free.fr> | 2008-10-01 15:25:41 +0000 |
commit | d65a4daeead235fbe3a66b9afcf8044df7f53bff (patch) | |
tree | 6bc0bc389541126b281b3a13ab60e2ee07d3bb9f /llvm/lib/Transforms/Scalar/InstructionCombining.cpp | |
parent | 94798d31ddf28976048688699de008397b5e0d2a (diff) | |
download | bcm5719-llvm-d65a4daeead235fbe3a66b9afcf8044df7f53bff.tar.gz bcm5719-llvm-d65a4daeead235fbe3a66b9afcf8044df7f53bff.zip |
Factorize code: remove variants of "strip off
pointer bitcasts and GEP's", and centralize the
logic in Value::getUnderlyingObject. The
difference with stripPointerCasts is that
stripPointerCasts only strips GEPs if all
indices are zero, while getUnderlyingObject
strips GEPs no matter what the indices are.
llvm-svn: 56922
Diffstat (limited to 'llvm/lib/Transforms/Scalar/InstructionCombining.cpp')
-rw-r--r-- | llvm/lib/Transforms/Scalar/InstructionCombining.cpp | 24 |
1 files changed, 1 insertions, 23 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index 6cac395405b..4f489718f6f 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp @@ -10367,28 +10367,6 @@ static bool isSafeToLoadUnconditionally(Value *V, Instruction *ScanFrom) { return false; } -/// GetUnderlyingObject - Trace through a series of getelementptrs and bitcasts -/// until we find the underlying object a pointer is referring to or something -/// we don't understand. Note that the returned pointer may be offset from the -/// input, because we ignore GEP indices. -static Value *GetUnderlyingObject(Value *Ptr) { - while (1) { - if (ConstantExpr *CE = dyn_cast<ConstantExpr>(Ptr)) { - if (CE->getOpcode() == Instruction::BitCast || - CE->getOpcode() == Instruction::GetElementPtr) - Ptr = CE->getOperand(0); - else - return Ptr; - } else if (BitCastInst *BCI = dyn_cast<BitCastInst>(Ptr)) { - Ptr = BCI->getOperand(0); - } else if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(Ptr)) { - Ptr = GEP->getOperand(0); - } else { - return Ptr; - } - } -} - Instruction *InstCombiner::visitLoadInst(LoadInst &LI) { Value *Op = LI.getOperand(0); @@ -10479,7 +10457,7 @@ Instruction *InstCombiner::visitLoadInst(LoadInst &LI) { // If this load comes from anywhere in a constant global, and if the global // is all undef or zero, we know what it loads. - if (GlobalVariable *GV = dyn_cast<GlobalVariable>(GetUnderlyingObject(Op))) { + if (GlobalVariable *GV = dyn_cast<GlobalVariable>(Op->getUnderlyingObject())){ if (GV->isConstant() && GV->hasInitializer()) { if (GV->getInitializer()->isNullValue()) return ReplaceInstUsesWith(LI, Constant::getNullValue(LI.getType())); |