aboutsummaryrefslogtreecommitdiff
path: root/lib/Analysis/InstructionSimplify.cpp
diff options
context:
space:
mode:
authorDuncan Sands <baldrick@free.fr>2010-11-22 13:42:49 +0000
committerDuncan Sands <baldrick@free.fr>2010-11-22 13:42:49 +0000
commit85bbff6c94695f07cc1a9765b4d384ed18d2fd7c (patch)
tree58bd5686e76c5bba4aeab38795eade78bf4e916d /lib/Analysis/InstructionSimplify.cpp
parentad8aaa069cfdb3bdc32b1becc8881f67b5272e14 (diff)
Move the "gep undef" -> "undef" transform from instcombine to
InstructionSimplify. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119970 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/InstructionSimplify.cpp')
-rw-r--r--lib/Analysis/InstructionSimplify.cpp15
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/Analysis/InstructionSimplify.cpp b/lib/Analysis/InstructionSimplify.cpp
index 6b51b222e2..e617ff2980 100644
--- a/lib/Analysis/InstructionSimplify.cpp
+++ b/lib/Analysis/InstructionSimplify.cpp
@@ -691,13 +691,20 @@ Value *llvm::SimplifySelectInst(Value *CondVal, Value *TrueVal, Value *FalseVal,
/// fold the result. If not, this returns null.
Value *llvm::SimplifyGEPInst(Value *const *Ops, unsigned NumOps,
const TargetData *TD, const DominatorTree *) {
+ // The type of the GEP pointer operand.
+ const PointerType *PtrTy = cast<PointerType>(Ops[0]->getType());
+
// getelementptr P -> P.
if (NumOps == 1)
return Ops[0];
- // TODO.
- //if (isa<UndefValue>(Ops[0]))
- // return UndefValue::get(GEP.getType());
+ if (isa<UndefValue>(Ops[0])) {
+ // Compute the (pointer) type returned by the GEP instruction.
+ const Type *LastType = GetElementPtrInst::getIndexedType(PtrTy, &Ops[1],
+ NumOps-1);
+ const Type *GEPTy = PointerType::get(LastType, PtrTy->getAddressSpace());
+ return UndefValue::get(GEPTy);
+ }
if (NumOps == 2) {
// getelementptr P, 0 -> P.
@@ -706,7 +713,7 @@ Value *llvm::SimplifyGEPInst(Value *const *Ops, unsigned NumOps,
return Ops[0];
// getelementptr P, N -> P if P points to a type of zero size.
if (TD) {
- const Type *Ty = cast<PointerType>(Ops[0]->getType())->getElementType();
+ const Type *Ty = PtrTy->getElementType();
if (Ty->isSized() && !TD->getTypeAllocSize(Ty))
return Ops[0];
}