diff options
author | Chris Lattner <sabre@nondot.org> | 2004-10-17 21:54:55 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2004-10-17 21:54:55 +0000 |
commit | cfbf9faaa4f1c92a746c8681ecd3bc52ad5313e8 (patch) | |
tree | 72f68da394351bf0acdfcd75c5f4713dad454d4c /lib/VMCore/ConstantFold.cpp | |
parent | ca45930548ed377fac6124c818c5efd80f1aab3e (diff) |
fold gep undef, ... -> undef
This comes up many times in perlbmk and probably others.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@17100 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/ConstantFold.cpp')
-rw-r--r-- | lib/VMCore/ConstantFold.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp index b56366ea66..d224afefc5 100644 --- a/lib/VMCore/ConstantFold.cpp +++ b/lib/VMCore/ConstantFold.cpp @@ -1011,8 +1011,15 @@ Constant *llvm::ConstantFoldGetElementPtr(const Constant *C, if (IdxList.size() == 0 || (IdxList.size() == 1 && cast<Constant>(IdxList[0])->isNullValue())) return const_cast<Constant*>(C); - Constant *Idx0 = cast<Constant>(IdxList[0]); + if (isa<UndefValue>(C)) { + const Type *Ty = GetElementPtrInst::getIndexedType(C->getType(), IdxList, + true); + assert(Ty != 0 && "Invalid indices for GEP!"); + return UndefValue::get(PointerType::get(Ty)); + } + + Constant *Idx0 = cast<Constant>(IdxList[0]); if (C->isNullValue()) { bool isNull = true; for (unsigned i = 0, e = IdxList.size(); i != e; ++i) |