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 | f60137501ff75b7400bb6f2e53dc03e9fb29e54d (patch) | |
| tree | 83cd3dbdbd832b83f5f6994e38cdd9b602a709d8 /llvm | |
| parent | 107c15c33dd5ad7194bc43759a7ce31882283a51 (diff) | |
| download | bcm5719-llvm-f60137501ff75b7400bb6f2e53dc03e9fb29e54d.tar.gz bcm5719-llvm-f60137501ff75b7400bb6f2e53dc03e9fb29e54d.zip | |
fold gep undef, ... -> undef
This comes up many times in perlbmk and probably others.
llvm-svn: 17100
Diffstat (limited to 'llvm')
| -rw-r--r-- | llvm/lib/VMCore/ConstantFolding.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/llvm/lib/VMCore/ConstantFolding.cpp b/llvm/lib/VMCore/ConstantFolding.cpp index b56366ea663..d224afefc5c 100644 --- a/llvm/lib/VMCore/ConstantFolding.cpp +++ b/llvm/lib/VMCore/ConstantFolding.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) |

