[llvm-commits] [llvm] r78755 - /llvm/trunk/lib/VMCore/ConstantFold.cpp
Dan Gohman
gohman at apple.com
Tue Aug 11 17:32:55 PDT 2009
Author: djg
Date: Tue Aug 11 19:32:55 2009
New Revision: 78755
URL: http://llvm.org/viewvc/llvm-project?rev=78755&view=rev
Log:
Simplify this code, and use an in-bounds GEP.
Modified:
llvm/trunk/lib/VMCore/ConstantFold.cpp
Modified: llvm/trunk/lib/VMCore/ConstantFold.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/ConstantFold.cpp?rev=78755&r1=78754&r2=78755&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/ConstantFold.cpp (original)
+++ llvm/trunk/lib/VMCore/ConstantFold.cpp Tue Aug 11 19:32:55 2009
@@ -103,26 +103,28 @@
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
More information about the llvm-commits
mailing list