diff options
author | Dan Gohman <gohman@apple.com> | 2009-08-12 00:32:55 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2009-08-12 00:32:55 +0000 |
commit | c752064894630565bdef503f6001e849a1fcfc3f (patch) | |
tree | 01b7ef8a22a24b122538b1bc4ca124a3900cda3c | |
parent | 9f817031f1011d75cbd8ab5c833547ac42500268 (diff) | |
download | external_llvm-c752064894630565bdef503f6001e849a1fcfc3f.zip external_llvm-c752064894630565bdef503f6001e849a1fcfc3f.tar.gz external_llvm-c752064894630565bdef503f6001e849a1fcfc3f.tar.bz2 |
Simplify this code, and use an in-bounds GEP.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78755 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/VMCore/ConstantFold.cpp | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp index da9b6aa..e30f144 100644 --- a/lib/VMCore/ConstantFold.cpp +++ b/lib/VMCore/ConstantFold.cpp @@ -103,26 +103,28 @@ static Constant *FoldBitCast(LLVMContext &Context, if (const PointerType *DPTy = dyn_cast<PointerType>(DestTy)) if (PTy->getAddressSpace() == DPTy->getAddressSpace()) { SmallVector<Value*, 8> IdxList; - IdxList.push_back(Constant::getNullValue(Type::Int32Ty)); + Value *Zero = Constant::getNullValue(Type::Int32Ty); + IdxList.push_back(Zero); const Type *ElTy = PTy->getElementType(); while (ElTy != DPTy->getElementType()) { if (const StructType *STy = dyn_cast<StructType>(ElTy)) { if (STy->getNumElements() == 0) break; ElTy = STy->getElementType(0); - IdxList.push_back(Constant::getNullValue(Type::Int32Ty)); + IdxList.push_back(Zero); } else if (const SequentialType *STy = dyn_cast<SequentialType>(ElTy)) { if (isa<PointerType>(ElTy)) break; // Can't index into pointers! ElTy = STy->getElementType(); - IdxList.push_back(IdxList[0]); + IdxList.push_back(Zero); } else { break; } } if (ElTy == DPTy->getElementType()) - return ConstantExpr::getGetElementPtr(V, &IdxList[0], - IdxList.size()); + // This GEP is inbounds because all indices are zero. + return ConstantExpr::getInBoundsGetElementPtr(V, &IdxList[0], + IdxList.size()); } // Handle casts from one vector constant to another. We know that the src |