summaryrefslogtreecommitdiffstats
path: root/llvm/lib/VMCore/ConstantFold.cpp
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2009-08-12 00:32:55 +0000
committerDan Gohman <gohman@apple.com>2009-08-12 00:32:55 +0000
commit76733748e1e7bfe22731de2c5a812c0e59cedbe2 (patch)
treeb359b624cdab514e6e3bf96a0f9842241067e948 /llvm/lib/VMCore/ConstantFold.cpp
parent0738468322f26b547ed43dae429e427201c5f85f (diff)
downloadbcm5719-llvm-76733748e1e7bfe22731de2c5a812c0e59cedbe2.tar.gz
bcm5719-llvm-76733748e1e7bfe22731de2c5a812c0e59cedbe2.zip
Simplify this code, and use an in-bounds GEP.
llvm-svn: 78755
Diffstat (limited to 'llvm/lib/VMCore/ConstantFold.cpp')
-rw-r--r--llvm/lib/VMCore/ConstantFold.cpp12
1 files changed, 7 insertions, 5 deletions
diff --git a/llvm/lib/VMCore/ConstantFold.cpp b/llvm/lib/VMCore/ConstantFold.cpp
index da9b6aa9784..e30f144658f 100644
--- a/llvm/lib/VMCore/ConstantFold.cpp
+++ b/llvm/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
OpenPOWER on IntegriCloud